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

namespace Edu.Repository.Course
{
    /// <summary>
    /// 订单备注仓储层
    /// </summary>
    public class RB_Order_RemarkRepository : BaseRepository<RB_Order_Remark>
    {
        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="demodel"></param>
        /// <param name="orderIds"></param>
        /// <returns></returns>
        public List<RB_Order_Remark_ViewModel> GetList(RB_Order_Remark_ViewModel demodel,string orderIds)
        {
            string where = $@" 1=1";
            
            if (demodel.OrderId > 0)
            {
                where += $@" and r.{nameof(RB_Order_Remark.OrderId)} ={demodel.OrderId}";
            }
            if (!string.IsNullOrEmpty(orderIds))
            {
                where += $@" and r.{nameof(RB_Order_Remark.OrderId)} in({orderIds})";
            }
            if (demodel.Type > 0)
            {
                where += $@" and r.{nameof(RB_Order_Remark.Type)} ={demodel.Type}";
            }

            string sql = $@" select r.*,e.EmName as CreateByName from RB_Order_Remark r
left join rb_employee e on r.CreateBy = e.EmployeeId 
where {where} order by r.Id desc";
            return Get<RB_Order_Remark_ViewModel>(sql).ToList();
        }

        /// <summary>
        /// 获取分页列表
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="rowsCount"></param>
        /// <param name="demodel"></param>
        /// <param name="orderIds"></param>
        /// <returns></returns>
        public List<RB_Order_Remark_ViewModel> GetPageList(int pageIndex, int pageSize, out long rowsCount, RB_Order_Remark_ViewModel demodel, string orderIds)
        {
            string where = $@" 1=1";

            if (demodel.OrderId > 0)
            {
                where += $@" and {nameof(RB_Order_Remark.OrderId)} ={demodel.OrderId}";
            }
            if (!string.IsNullOrEmpty(orderIds))
            {
                where += $@" and {nameof(RB_Order_Remark.OrderId)} in({orderIds})";
            }
            if (demodel.Type > 0)
            {
                where += $@" and {nameof(RB_Order_Remark.Type)} ={demodel.Type}";
            }

            string sql = $@" select * from RB_Order_Remark where {where} order by Id desc";
            return GetPage<RB_Order_Remark_ViewModel>(pageIndex, pageSize, out rowsCount, sql).ToList();
        }

    }
}
