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

namespace Edu.Repository.DataStatistics
{
    /// <summary>
    /// 课程顾问部月目标仓储层
    /// </summary>
    public class RB_Consultant_GoalRepository : BaseRepository<RB_Consultant_Goal>
    {
        /// <summary>
        /// 获取课程顾问部目标分页列表
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="rowsCount"></param>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_Consultant_Goal_Extend> GetConsultantGoalPageRepository(int pageIndex, int pageSize, out long rowsCount, RB_Consultant_Goal_Extend query)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append(@"
SELECT A.*
FROM RB_Consultant_Goal AS A
WHERE 1=1
");
            builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_Consultant_Goal_Extend.Status), (int)DateStateEnum.Normal);
            if (query != null)
            {
                if (query.Group_Id > 0)
                {
                    builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_Consultant_Goal_Extend.Group_Id), query.Group_Id);
                }
                if (query.YearStr > 0)
                {
                    builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_Consultant_Goal_Extend.YearStr), query.YearStr);
                }
                if (query.MonthStr > 0)
                {
                    builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_Consultant_Goal_Extend.MonthStr), query.MonthStr);
                }
            }
            builder.Append(" ORDER BY A.YearStr,A.MonthStr ");
            return GetPage<RB_Consultant_Goal_Extend>(pageIndex, pageSize, out rowsCount, builder.ToString()).ToList();
        }

        /// <summary>
        /// 获取课程顾问部目标列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_Consultant_Goal_Extend> GetConsultantGoalListRepository(RB_Consultant_Goal_Extend query)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append(@"
SELECT A.*
FROM RB_Consultant_Goal AS A
WHERE 1=1
");
            builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_Consultant_Goal_Extend.Status), (int)DateStateEnum.Normal);
            if (query != null)
            {
                if (query.Group_Id > 0)
                {
                    builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_Consultant_Goal_Extend.Group_Id), query.Group_Id);
                }
                if (query.YearStr > 0)
                {
                    builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_Consultant_Goal_Extend.YearStr), query.YearStr);
                }
                if (query.MonthStr > 0)
                {
                    builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_Consultant_Goal_Extend.MonthStr), query.MonthStr);
                }
                if (query.Dept_Id > 0)
                {
                    builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_Consultant_Goal_Extend.Dept_Id), query.Dept_Id);
                }
            }
            return Get<RB_Consultant_Goal_Extend>(builder.ToString()).ToList();
        }
    }
}
