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

namespace Edu.Repository.Log
{
    /// <summary>
    /// b2b同业学生信息通知仓储
    /// </summary>
    public class RB_B2B_StudentNoticeRepository : BaseRepository<RB_B2B_StudentNotice>
    {
        /// <summary>
        /// 获取分页列表
        /// </summary>
        /// <param name="pageIndex">当前页</param>
        /// <param name="pageSize">每页显示条数</param>
        /// <param name="rowsCount">总条数</param>
        /// <param name="query">查询条件</param>
        /// <returns></returns>
        public List<RB_B2B_StudentNotice_ViewModel> GetPageList(int pageIndex, int pageSize, out long rowsCount, RB_B2B_StudentNotice_ViewModel query)
        {
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat(@"
SELECT * 
FROM RB_B2B_StudentNotice
WHERE 1=1 
");
            if (query != null)
            {
                if (query.Group_Id > 0)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_B2B_StudentNotice_ViewModel.Group_Id), query.Group_Id);
                }
                if (query.Type > 0)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_B2B_StudentNotice_ViewModel.Type), query.Type);
                }
                if (query.CustomerId > 0)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_B2B_StudentNotice_ViewModel.CustomerId), query.CustomerId);
                }
                if (query.StudentId > 0)
                {
                    builder.AppendFormat(" AND {0}={1} ", nameof(RB_B2B_StudentNotice_ViewModel.StudentId), query.StudentId);
                }
            }
            builder.Append(" ORDER BY Id DESC ");
            return GetPage<RB_B2B_StudentNotice_ViewModel>(pageIndex, pageSize, out rowsCount, builder.ToString()).ToList();
        }
    }
}
