using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Edu.Model.Entity.Course;
using Edu.Model.Entity.Grade;
using Edu.Model.ViewModel.Course;
using Edu.Model.ViewModel.Grade;

namespace Edu.Repository.Grade
{
    /// <summary>
    /// 班级备案评论仓储层
    /// </summary>
    public class RB_Class_LessonCommentRepository : BaseRepository<RB_Class_LessonComment>
    {
        /// <summary>
        /// 获取备案分页列表
        /// </summary>
        /// <param name="pageIndex">当前页</param>
        /// <param name="pageSize">每页显示条数</param>
        /// <param name="rowsCount">总条数</param>
        /// <param name="query">查询条件</param>
        /// <returns></returns>
        public List<RB_Class_LessonComment_ViewModel> GetLessonCommentList(RB_Class_LessonComment_ViewModel query)
        {
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat(@"SELECT *  FROM RB_Class_LessonComment  WHERE 1=1  AND Status=0");
            if (query != null)
            {
                if (query.Group_Id > 0)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_Class_LessonComment_ViewModel.Group_Id), query.Group_Id);
                }
                if (query.School_Id > 0)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_Class_LessonComment_ViewModel.School_Id), query.School_Id);
                }
                if (query.ClassId > 0)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_Class_LessonComment_ViewModel.ClassId), query.ClassId);
                }
                if (query.ClassPlanId > 0 && query.ClassDate.HasValue)
                {
                    builder.AppendFormat(" AND ({0}={1}   or DATE_FORMAT({2},'%y/%m/%d')= DATE_FORMAT('{3}','%y/%m/%d'))", nameof(RB_Class_LessonComment_ViewModel.ClassPlanId), query.ClassPlanId, nameof(RB_Class_LessonComment_ViewModel.ClassDate), query.ClassDate.Value);
                }
                else if (query.ClassPlanId > 0)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_Class_LessonComment_ViewModel.ClassPlanId), query.ClassPlanId);
                }
                if (query.LessonPlanId > 0)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_Class_LessonComment_ViewModel.LessonPlanId), query.LessonPlanId);
                }
                if (query.LessonCommentId > 0)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_Class_LessonComment_ViewModel.LessonCommentId), query.LessonCommentId);
                }
                if (query.CreateBy > 0)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_Class_LessonComment_ViewModel.CreateBy), query.CreateBy);
                }
            }
            builder.Append(" ORDER BY CreateTime DESC ");
            return Get<RB_Class_LessonComment_ViewModel>(builder.ToString()).ToList();
        }
    }
}
