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> GetOrderRemarkListRepository(RB_Order_Remark_ViewModel demodel)
        {
            string where = $@" 1=1";
            if (demodel.OrderId > 0)
            {
                where += $@" and r.{nameof(RB_Order_Remark.OrderId)} ={demodel.OrderId}";
            }
            if (!string.IsNullOrEmpty(demodel.QOrderIds))
            {
                where += $@" and r.{nameof(RB_Order_Remark.OrderId)} in({demodel.QOrderIds})";
            }
            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> GetOrderRemarkPageRepository(int pageIndex, int pageSize, out long rowsCount, RB_Order_Remark_ViewModel demodel)
        {
            string where = $@" 1=1";

            if (demodel.OrderId > 0)
            {
                where += $@" and {nameof(RB_Order_Remark.OrderId)} ={demodel.OrderId}";
            }
            if (!string.IsNullOrEmpty(demodel.QOrderIds))
            {
                where += $@" and {nameof(RB_Order_Remark.OrderId)} in({demodel.QOrderIds})";
            }
            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();
        }

    }
}
