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

namespace Edu.Repository.Customer
{
    /// <summary>
    /// 课程顾问跟进仓储层
    /// </summary>
    public class RB_Student_AdvisorRepository : BaseRepository<RB_Student_Advisor>
    {
        /// <summary>
        /// 获取课程顾问跟进分页列表
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="rowsCount"></param>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_Student_Advisor_Extend> GetStudentAdvisorPageRepository(int pageIndex, int pageSize, out long rowsCount, RB_Student_Advisor_Extend query)
        {
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat(@"
SELECT A.*,B.Name AS AdvisorStatusName,B.Rate AS AdvisorRate
FROM RB_Student_Advisor AS A LEFT JOIN rb_student_advisorconfig AS B ON A.AdvisorStatus=B.Id
WHERE 1=1
");
            if (query != null)
            {
                if (query.StuId > 0)
                {
                    builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_Student_Advisor_Extend.StuId), query.StuId);
                }
                if (!string.IsNullOrEmpty(query.QStuIds))
                {
                    builder.AppendFormat(" AND A.{0} IN({1}) ", nameof(RB_Student_Advisor_Extend.StuId), query.QStuIds);
                }
            }
            builder.AppendFormat(" ORDER BY A.{0} DESC ", nameof(RB_Student_Advisor_Extend.Id));
            return GetPage<RB_Student_Advisor_Extend>(pageIndex, pageSize, out rowsCount, builder.ToString()).ToList();
        }

        /// <summary>
        /// 获取课程顾问跟进列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_Student_Advisor_Extend> GetStudentAdvisorListRepository(RB_Student_Advisor_Extend query)
        {
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat(@"
SELECT A.*,B.Name AS AdvisorStatusName,B.Rate AS AdvisorRate
FROM RB_Student_Advisor AS A LEFT JOIN rb_student_advisorconfig AS B ON A.AdvisorStatus=B.Id
WHERE 1=1
");
            if (query != null)
            {
                if (query.StuId > 0)
                {
                    builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_Student_Advisor_Extend.StuId), query.StuId);
                }
                if (!string.IsNullOrEmpty(query.QStuIds))
                {
                    builder.AppendFormat(" AND A.{0} IN({1}) ", nameof(RB_Student_Advisor_Extend.StuId), query.QStuIds);
                }
            }
            builder.AppendFormat(" ORDER BY A.{0} DESC ", nameof(RB_Student_Advisor_Extend.Id));
            return Get<RB_Student_Advisor_Extend>(builder.ToString()).ToList();
        }
    }
}
