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 Dapper;
namespace XYY.Service.Standard.Finance.Charging.Base
{
    public interface ITranscationService
    {
        Task<TranscationPager> QueryPager(QueryModel queryModel);
    }

    public class TranscationService : ITranscationService
    {
        private IUnitOfWork _unitOfWork;
        public TranscationService(IUnitOfWork unitOfWork)
        {
            this._unitOfWork = unitOfWork;
        }

        public async Task<TranscationPager> QueryPager(QueryModel queryModel)
        {
            var dto = await _unitOfWork.GetPagingListAsync<Finance_ChargesDetail>(queryModel);
            var result = dto.Copy<TranscationPager>();
            var searchWhere = queryModel.QueryParamer == null ? "" : _unitOfWork.GetWhere(queryModel.QueryParamer);
            result.TotalAmount =
                await _unitOfWork.Connection.QuerySingleAsync<double>("select isnull(sum(case when IncomeOrESxpense = '支出' then 0 - SettlementAmount else SettlementAmount end),0) from Finance_ChargesDetail(nolock) where 1=1 " + searchWhere);
            return result;

        }
    }
}
