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

namespace Edu.Repository.Customer
{
    /// <summary>
    /// 客户完成任务和订单关联仓储层
    /// </summary>
    public class RB_Customer_FinishdetailsRepository : BaseRepository<RB_Customer_Finishdetails>
    {
        /// <summary>
        /// 获取任务和订单关联列表
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="RB_Customer_Finishdetails_Extend"></param>
        /// <param name=""></param>
        /// <returns></returns>
        public List<RB_Customer_Finishdetails_Extend> GetCustomerFinishdetailsPageRepository(int pageIndex,int pageSize,out long rowsCount, RB_Customer_Finishdetails_Extend query)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append(@"
SELECT A.*,B.GuestNum,B.ExchangeNum,B.Income,B.ExchangeMoney
FROM  RB_Customer_Finishdetails AS A LEFT JOIN rb_order AS B ON A.OrderId=B.OrderId
WHERE 1=1
");
            if (query != null)
            {
                if (query.TaskId > 0)
                {
                    builder.AppendFormat(@" AND A.{0}={1} ", nameof(RB_Customer_Finishdetails_Extend.TaskId), query.TaskId);
                }
                if (query.DetailId > 0)
                {
                    builder.AppendFormat(@" AND A.{0}={1} ", nameof(RB_Customer_Finishdetails_Extend.DetailId), query.DetailId);
                }
                if (query.OrderId > 0)
                {
                    builder.AppendFormat(@" AND A.{0}={1} ", nameof(RB_Customer_Finishdetails_Extend.OrderId), query.OrderId);
                }
                if (query.CustomerId > 0)
                {
                    builder.AppendFormat(@" AND A.{0}={1} ", nameof(RB_Customer_Finishdetails_Extend.CustomerId), query.CustomerId);
                }
                if (query.FinishId > 0)
                {
                    builder.AppendFormat(@" AND A.{0}={1} ", nameof(RB_Customer_Finishdetails_Extend.FinishId), query.FinishId);
                }
            }
            return GetPage<RB_Customer_Finishdetails_Extend>(pageIndex, pageSize, out rowsCount, builder.ToString()).ToList();
        }
    }
}
