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_TaskRepository : BaseRepository<RB_Task>
    {
        /// <summary>
        /// 获取任务分页列表
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="rowsCount"></param>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_Task_Extend> GetTaskPageRepository(int pageIndex, int pageSize, out long rowsCount, RB_Task_Extend query)
        {
            var parameters = new DynamicParameters();
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat(@"
SELECT A.*
FROM  RB_Task AS A
WHERE 1=1
");
            builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_Task_Extend.Status), (int)DateStateEnum.Normal);
            if (query != null)
            {
                if (query.Group_Id > 0)
                {
                    builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_Task_Extend.Group_Id), query.Group_Id);
                }
                if (!string.IsNullOrEmpty(query.TaskName))
                {
                    builder.AppendFormat(" AND A.{0} LIKE @TaskName ", nameof(RB_Task_Extend.TaskName));
                    parameters.Add("TaskName", "%" + query.TaskName.Trim() + "%");
                }
            }
            return GetPage<RB_Task_Extend>(pageIndex, pageSize, out rowsCount, builder.ToString(), parameters).ToList();
        }
    }
}
