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

namespace Edu.Repository.Finance
{
    /// <summary>
    /// 教育轧账仓储层
    /// </summary>
    public class RB_RollingAccountRepository : BaseRepository<RB_RollingAccount>
    {

        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public List<RB_RollingAccount_Extend> GetList(RB_RollingAccount_Extend model)
        {
            string where = " WHERE 1=1 ";
            if (model.GroupId > 0)
            {
                where += string.Format(" AND " + nameof(RB_RollingAccount_Extend.GroupId) + "={0} ", model.GroupId);
            }
            if (model.State > 0)
            {
                where += string.Format(" AND " + nameof(RB_RollingAccount_Extend.State) + "={0} ", model.State);
            }
            if (!string.IsNullOrEmpty(model.Month))
            {
                where += string.Format(" AND " + nameof(RB_RollingAccount_Extend.Month) + "='{0}' ", model.Month);
            }
            if (model.SchoolId >= 0)
            {
                where += string.Format(" AND FIND_IN_SET('{0}',"+ nameof(RB_RollingAccount_Extend.SchoolIds) + ") ", model.SchoolId);
            }
            string sql = "select * from RB_RollingAccount " + where +" order by Id desc";

            return Get<RB_RollingAccount_Extend>(sql).ToList();
        }

        /// <summary>
        /// 分页列表
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="count"></param>
        /// <param name="model"></param>
        /// <returns></returns>
        public List<RB_RollingAccount_Extend> GetPageList(int pageIndex,int pageSize,out long count,RB_RollingAccount_Extend model)
        {
            string where = " WHERE 1=1 ";
            if (model.GroupId > 0)
            {
                where += string.Format(" AND " + nameof(RB_RollingAccount_Extend.GroupId) + "={0} ", model.GroupId);
            }
            if (model.State > 0)
            {
                where += string.Format(" AND " + nameof(RB_RollingAccount_Extend.State) + "={0} ", model.State);
            }
            if (!string.IsNullOrEmpty(model.Month))
            {
                where += string.Format(" AND " + nameof(RB_RollingAccount_Extend.Month) + "='{0}' ", model.Month);
            }
            if (model.SchoolId >= 0)
            {
                where += string.Format(" AND FIND_IN_SET('{0}'," + nameof(RB_RollingAccount_Extend.SchoolIds) + ") ", model.SchoolId);
            }
            string sql = "select * from RB_RollingAccount " + where + " order by Id desc";

            return GetPage<RB_RollingAccount_Extend>(pageIndex, pageSize, out count, sql).ToList();
        }
    }
}