using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Edu.Model.Entity.Log;

namespace Edu.Repository.Log
{
    public class RB_Notice_LogRepository : BaseRepository<RB_Notice_Log>
    {
        /// <summary>
        /// 获取公告日志分页列表
        /// </summary>
        /// <param name="pageIndex">当前页</param>
        /// <param name="pageSize">每页显示条数</param>
        /// <param name="rowsCount">总条数</param>
        /// <param name="query">查询条件</param>
        /// <returns></returns>
        public List<RB_Notice_Log> GetNoticeLogPageListRepository(int pageIndex, int pageSize, out long rowsCount, RB_Notice_Log query)
        {
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat(@"
SELECT * 
FROM RB_Notice_Log
WHERE 1=1 
");
            if (query != null)
            {
                if (query.Group_Id > 0)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_Notice_Log.Group_Id), query.Group_Id);
                }
                //if (query.School_Id > 0)
                //{
                //    builder.AppendFormat(" AND {0}={1} ", nameof(RB_Notice_Log.School_Id), query.School_Id);
                //}
                if (query.NoticeId > 0)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_Notice_Log.NoticeId), query.NoticeId);
                }
            }
            builder.Append(" ORDER BY CLogId DESC ");
            return GetPage<RB_Notice_Log>(pageIndex, pageSize, out rowsCount, builder.ToString()).ToList();
        }

        /// <summary>
        /// 新增公告日志
        /// </summary>
        /// <param name="logType">日志类型</param>
        /// <param name="LogContent">日志内容</param>
        /// <param name="NoticeId">公告编号</param>
        /// <param name="Group_Id">集团编号</param>
        /// <param name="School_Id">校区编号</param>
        /// <param name="CreateBy">创建人</param>
        /// <returns></returns>
        public bool AddNoticeLogRepository(RB_Notice_Log model)
        {
            var newmodel = new RB_Notice_Log()
            {
                LogContent = model.LogContent.TrimStart(',').TrimEnd(',').TrimStart('、').TrimEnd('、'),
                NoticeId = model.NoticeId,
                Group_Id = model.Group_Id,
                School_Id = model.School_Id,
                CreateBy = model.CreateBy,
                CreateTime = DateTime.Now,
                ReviewStatus = model.ReviewStatus
            };
            return base.Insert(newmodel) > 0;
        }
    }
}
