using Edu.Common.Enum;
using Edu.Model.Entity.Course;
using Edu.Model.ViewModel.Course;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VT.FW.DB.Dapper;

namespace Edu.Repository.Course
{
    /// <summary>
    /// 销售提成抵扣仓储层
    /// </summary>
    public class RB_Sell_Commission_DeductionRepository : BaseRepository<RB_Sell_Commission_Deduction>
    {
        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="demodel"></param>
        /// <returns></returns>
        public List<RB_Sell_Commission_Deduction_ViewModel> GetList(RB_Sell_Commission_Deduction_ViewModel demodel)
        {
            string where = $@" 1=1";
            
            if (demodel.Group_Id > 0)
            {
                where += $@" and r.{nameof(RB_Sell_Commission_Deduction_ViewModel.Group_Id)} ={demodel.Group_Id}";
            }
            if (demodel.OrderId > 0)
            {
                where += $@" and r.{nameof(RB_Sell_Commission_Deduction_ViewModel.OrderId)} ={demodel.OrderId}";
            }
            if (demodel.SourceId > 0)
            {
                where += $@" and r.{nameof(RB_Sell_Commission_Deduction_ViewModel.SourceId)} ={demodel.SourceId}";
            }
            if (demodel.Type > 0)
            {
                where += $@" and r.{nameof(RB_Sell_Commission_Deduction_ViewModel.Type)} ={demodel.Type}";
            }
            if (!string.IsNullOrEmpty(demodel.OrderIds))
            {
                where += $@" and r.{nameof(RB_Sell_Commission_Deduction_ViewModel.OrderId)} in({demodel.OrderIds})";
            }
            if (!string.IsNullOrEmpty(demodel.SourceIds))
            {
                where += $@" and r.{nameof(RB_Sell_Commission_Deduction_ViewModel.SourceId)} in({demodel.SourceIds})";
            }


            string sql = $@" select r.* from RB_Sell_Commission_Deduction r where {where} order by r.Id desc";
            return Get<RB_Sell_Commission_Deduction_ViewModel>(sql).ToList();
        }
    }
}
