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

namespace Edu.Repository.Exam
{
    /// <summary>
    /// 试卷自动组卷模板表仓储层
    /// </summary>
    public class RB_Examination_TemplateRepository : BaseRepository<RB_Examination_Template>
    {
        /// <summary>
        /// 获取试卷模板分页列表
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="rowsCount"></param>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_Examination_Template_ViewModel> GetExaminationTemplatePageRepository(int pageIndex, int pageSize, out long rowsCount, RB_Examination_Template_ViewModel query)
        {
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat(@"
SELECT A.*
FROM RB_Examination_Template AS A
WHERE 1=1

");
            builder.AppendFormat(@" AND A.{0}={1} ", nameof(RB_Examination_Template_ViewModel.Status), (int)DateStateEnum.Normal);
            if (query != null)
            {
                if (query.Group_Id > 0)
                {
                    builder.AppendFormat(@" AND A.{0}={1} ", nameof(RB_Examination_Template_ViewModel.Group_Id), query.Group_Id);
                }
                if (query.CreateBy > 0)
                {
                    builder.AppendFormat(@" AND A.{0}={1} ", nameof(RB_Examination_Template_ViewModel.CreateBy), query.CreateBy);
                }
            }
            return GetPage<RB_Examination_Template_ViewModel>(pageIndex, pageSize, out rowsCount, builder.ToString()).ToList();
        }
    }
}