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;

namespace Edu.Repository.Customer
{
    /// <summary>
    /// 学员协助人员仓储层
    /// </summary>
    public class RB_Student_AssistRepository : BaseRepository<RB_Student_Assist>
    {
        /// <summary>
        /// 获取学员协助人员列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_Student_Assist_Extend> GetStudentAssistListRepository(RB_Student_Assist_Extend query)
        {
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat(@"
SELECT A.*
FROM RB_Student_Assist AS A
WHERE 1=1 
");
            builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_Student_Assist_Extend.Status), (int)DateStateEnum.Normal);
            if (query != null)
            {
                if (query.StuId > 0)
                {
                    builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_Student_Assist_Extend.StuId), query.StuId);
                }
                if (!string.IsNullOrEmpty(query.QStuIds))
                {
                    builder.AppendFormat(" AND A.{0} IN({1}) ", nameof(RB_Student_Assist_Extend.StuId), query.QStuIds);
                }
            }
            return Get<RB_Student_Assist_Extend>(builder.ToString()).ToList();
        }


        /// <summary>
        /// 删除学员协同人员
        /// </summary>
        /// <param name="StuId"></param>
        /// <returns></returns>
        public bool DeleteStudentAssistRepository(int StuId)
        {
            string delSql = string.Format(" DELETE FROM RB_Student_Assist WHERE StuId={0} ", StuId);
            return base.Execute(delSql)>0;
        }
    }
}
