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

namespace Edu.Repository.EduTask
{
    /// <summary>
    /// 订单转班、分拆仓储层
    /// </summary>
    public class RB_Order_ChangeRepository:BaseRepository<RB_Order_Change>
    {
        /// <summary>
        /// 获取订单转班、分拆列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_Order_Change_ViewModel> GetOrderChangeListRepository(RB_Order_Change_ViewModel query)
        {
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat(@"
SELECT A.*,IFNULL(B.GuestName,'') AS GuestName,IFNULL(c.ClassName,'') AS ClassName,IFNULL(c.ClassNo,'') AS ClassNo,IFNULL(D.CourseName,'') AS CourseName
      ,IFNULL(E.TeacherName,'') AS TeacherName
FROM RB_Order_Change AS A LEFT JOIN rb_order_guest AS B ON (A.OrderGuestId=B.Id)
     LEFT JOIN rb_class AS C ON A.NewClassId=C.ClassId
     LEFT JOIN rb_course AS D ON A.NewCourseId=D.CourseId
     LEFT JOIN rb_teacher AS E ON c.Teacher_Id=E.TId
WHERE 1=1
");
            if (query != null)
            {
                if (query.Group_Id > 0)
                {
                    builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_Order_Change_ViewModel.Group_Id), query.Group_Id);
                }
                if (query.Id > 0)
                {
                    builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_Order_Change_ViewModel.Id), query.Id);
                }
                if (!string.IsNullOrEmpty(query.QIds))
                {
                    builder.AppendFormat(" AND A.{0} IN({1}) ", nameof(RB_Order_Change_ViewModel.Id), query.QIds);
                }
                if (query.ChangeType > 0)
                {
                    builder.AppendFormat(" AND A.{0}={1} ", nameof(RB_Order_Change_ViewModel.ChangeType), query.ChangeType);
                }
            }
            return Get<RB_Order_Change_ViewModel>(builder.ToString()).ToList();
        }
    }
}
