using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XYY.Common.Standard;
using XYY.Core.Standard.Data.Infrastructure;
using XYY.Model.Standard.Finance;
using Dapper;
namespace XYY.Data.Standard.Finance
{
    public interface IFinance_Customer_RemittanceRepository : IBaseRepository<Finance_Customer_Remittance>
    {
        Task<PageResult<View_Finance_Customer_Remittance>> GetPageResult(QueryModel queryModel);
        /// <summary>
        /// 获取帐单检验信息
        /// </summary>
        /// <returns></returns>
        Task<IEnumerable<dynamic>> GetCollectionFlowEndTime();
    }
    public class Finance_Customer_RemittanceRepository : BaseRepository<Finance_Customer_Remittance>, IFinance_Customer_RemittanceRepository
    {
        public Finance_Customer_RemittanceRepository(IUnitOfWork unitOfWork) : base(unitOfWork)
        {

        }

        public async Task<PageResult<View_Finance_Customer_Remittance>> GetPageResult(QueryModel queryModel)
        {
            string sql = @"select a.*,b.CompanyName as CustomerName from 
                    Finance_Customer_Remittance(nolock)a join User_Customer(nolock)b on a.CustomerId=b.Id";
            return await _unitOfWork.GetPagingListAsync<View_Finance_Customer_Remittance>(queryModel, sql);
        }
        public async Task<IEnumerable<dynamic>> GetCollectionFlowEndTime()
        {
            string sql = @"select a.CustomerNumber,a.Id,b.EndTime from User_Customer a
outer apply(select top 1 EndTime from Finance_CustomerDeliveryBill where CustomerId=a.Id order by EndTime desc)b ";
            return await _unitOfWork.QueryBySqlAsync<dynamic>(sql);
        }
    }
}
