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_TaskDetailsRepository : BaseRepository<RB_TaskDetails>
    {
        /// <summary>
        /// 获取任务详情列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_TaskDetails_Extend> GetTaskDetailsListRepository(RB_TaskDetails_Extend query)
        {
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat(@"
SELECT A.*
FROM  RB_TaskDetails AS A 
WHERE 1=1
");
            if (query != null)
            {
                if (query.TaskId > 0)
                {
                    builder.AppendFormat(@" AND A.{0}={1} ", nameof(RB_TaskDetails_Extend.TaskId), query.TaskId);
                }
                if (!string.IsNullOrEmpty(query.QTaskIds))
                {
                    builder.AppendFormat(@" AND A.{0} IN({1}) ", nameof(RB_TaskDetails_Extend.TaskId), query.QTaskIds);
                }
            }
            return Get<RB_TaskDetails_Extend>(builder.ToString()).ToList();
        }


        /// <summary>
        /// 根本任务编号删除任务详情
        /// </summary>
        /// <param name="TaskId"></param>
        /// <returns></returns>
        public bool DeleteByTaskIdRepository(int TaskId)
        {
            string sql = string.Format(" DELETE FROM  RB_TaskDetails WHERE TaskId IN({0}) ", TaskId);
            return base.Execute(sql) > 0;
        }
    }
}
