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

namespace Edu.Repository.Sell
{
    /// <summary>
    /// 订单分拆关联信息仓储层
    /// </summary>
    public class RB_Order_SplitDetailsRepository : BaseRepository<RB_Order_SplitDetails>
    {
        /// <summary>
        /// 获取订单拆分关联列表
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public List<RB_Order_SplitDetails_ViewModel> GetOrderSplitDetailsListRepository(RB_Order_SplitDetails_ViewModel query)
        {
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat(@"
SELECT A.*,IFNULL(B.ClassName,'') AS S_ClassName,IFNULL(C.ClassName,'') AS T_ClassName
FROM RB_Order_SplitDetails AS A LEFT JOIN RB_class AS B ON A.S_ClassId=B.ClassId
     LEFT JOIN rb_class AS C ON A.T_ClassId=C.ClassId
WHERE 1=1
");
            if (query != null)
            {
                if (query.OldOrderId > 0)
                {
                    builder.AppendFormat(@" AND A.{0}={1} ", nameof(RB_Order_SplitDetails_ViewModel.OldOrderId), query.OldOrderId);
                }
                if (!string.IsNullOrEmpty(query.Q_OldOrderIds))
                {
                    builder.AppendFormat(@" AND A.{0} IN({1}) ", nameof(RB_Order_SplitDetails_ViewModel.OldOrderId), query.Q_OldOrderIds);
                }
            }
            return Get<RB_Order_SplitDetails_ViewModel>(builder.ToString()).ToList();
        }
    }
}
