using Edu.Common.Enum.Course;
using Edu.Model.Entity.Log;
using Edu.Model.ViewModel.Course;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

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

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