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

namespace Edu.Repository.Bonus
{
    /// <summary>
    /// 人头奖金发放期数仓储层
    /// </summary>
    public class RB_Personnel_PeriodRepository : BaseRepository<RB_Personnel_Period>
    {
        /// <summary>
        /// 获取人头奖金期数分页列表
        /// </summary>
        /// <param name="pageIdex"></param>
        /// <param name="pageSize"></param>
        /// <param name="rowsCount"></param>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_Personnel_Period_Extend> GetPersonnelPeriodPageRepository(int pageIdex, int pageSize, out long rowsCount, RB_Personnel_Period_Extend query)
        {
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat(@"
SELECT A.*
FROM RB_Personnel_Period AS A
WHERE 1=1
");
            if (query != null)
            {
                if (query.Group_Id > 0)
                {
                    builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_Personnel_Period_Extend.Group_Id), query.Group_Id);
                }
            }
            builder.AppendFormat(" ORDER BY A.{0} DESC ", nameof(RB_Personnel_Period_Extend.Id));
            return GetPage<RB_Personnel_Period_Extend>(pageIdex, pageSize, out rowsCount, builder.ToString()).ToList();
        }
    }
}