using Edu.Common.Enum;
using Edu.Model.Entity.Customer;
using Edu.Model.ViewModel.Customer;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VT.FW.DB.Dapper;

namespace Edu.Repository.Customer
{
    /// <summary>
    /// 课程顾问跟进配置仓储层
    /// </summary>
    public class RB_Student_AdvisorConfigRepository : BaseRepository<RB_Student_AdvisorConfig>
    {
        /// <summary>
        /// 获取课程顾问跟进配置分页列表
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="rowsCount"></param>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_Student_AdvisorConfig_Extend> GetStudentAdvisorConfigPageRepository(int pageIndex, int pageSize, out long rowsCount, RB_Student_AdvisorConfig_Extend query)
        {
            var parameters = new DynamicParameters();
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat(@"
SELECT A.* 
FROM RB_Student_AdvisorConfig AS A
WHERE 1=1
");
            builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_Student_AdvisorConfig_Extend.Status), (int)DateStateEnum.Normal);
            if (query != null)
            {
                if (query.Group_Id > 0)
                {
                    builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_Student_AdvisorConfig_Extend.Group_Id), query.Group_Id);
                }
                if (!string.IsNullOrEmpty(query.Name))
                {
                    builder.AppendFormat(" AND A.{0} LIKE @Name ", nameof(RB_Student_AdvisorConfig_Extend.Name));
                    parameters.Add("Name", "%" + query.Name.Trim() + "%");
                }
            }
            builder.AppendFormat(" ORDER BY A.{0} ASC ", nameof(RB_Student_AdvisorConfig_Extend.Num));
            return GetPage<RB_Student_AdvisorConfig_Extend>(pageIndex,pageSize,out rowsCount,builder.ToString(),parameters).ToList();
        }

        /// <summary>
        /// 获取课程顾问跟进配置列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_Student_AdvisorConfig_Extend> GetStudentAdvisorConfigListRepository(RB_Student_AdvisorConfig_Extend query)
        {
            var parameters = new DynamicParameters();
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat(@"
SELECT A.* 
FROM RB_Student_AdvisorConfig AS A
WHERE 1=1
");
            builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_Student_AdvisorConfig_Extend.Status), (int)DateStateEnum.Normal);
            if (query != null)
            {
                if (query.Group_Id > 0)
                {
                    builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_Student_AdvisorConfig_Extend.Group_Id), query.Group_Id);
                }
                if (!string.IsNullOrEmpty(query.Name))
                {
                    builder.AppendFormat(" AND A.{0} LIKE @Name ", nameof(RB_Student_AdvisorConfig_Extend.Name));
                    parameters.Add("Name", "%" + query.Name.Trim() + "%");
                }
            }
            builder.AppendFormat(" ORDER BY A.{0} ASC ", nameof(RB_Student_AdvisorConfig_Extend.Num));
            return Get<RB_Student_AdvisorConfig_Extend>(builder.ToString(),parameters).ToList();
        }
    }
}
