From 182c7edd7c70eddbf33e2358f1f1aba96eb58cb3 Mon Sep 17 00:00:00 2001
From: zhengyuxuan <zhengyuxuan1995>
Date: 星期五, 28 三月 2025 15:43:46 +0800
Subject: [PATCH] fix:查询优化
---
LifePayment/LifePayment.Application/LifePay/LifePayOrderService.cs | 97 ++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 89 insertions(+), 8 deletions(-)
diff --git a/LifePayment/LifePayment.Application/LifePay/LifePayOrderService.cs b/LifePayment/LifePayment.Application/LifePay/LifePayOrderService.cs
index 6b78d5e..5f7f622 100644
--- a/LifePayment/LifePayment.Application/LifePay/LifePayOrderService.cs
+++ b/LifePayment/LifePayment.Application/LifePay/LifePayOrderService.cs
@@ -11,17 +11,28 @@
using Volo.Abp.Domain.Repositories;
using Microsoft.EntityFrameworkCore;
using ZeroD.Util;
+using LifePayment.Domain;
+using static LifePayment.Domain.Shared.LifePaymentConstant;
namespace LifePayment.Application.LifePay
{
public class LifePayOrderService : ApplicationService, ILifePayOrderService
{
private readonly IRepository<LifePayRechargeReceipts, Guid> _lifePayRechargeReceiptsRepository;
+ private readonly IRepository<LifePayExpensesReceipts, Guid> _lifePayExpensesReceiptsRepository;
+ private readonly IAliPayApi _aliPayApi;
+ private readonly IWxPayApi _wxPayApi;
public LifePayOrderService(
- IRepository<LifePayRechargeReceipts, Guid> lifePayRechargeReceiptsRepository)
+ IRepository<LifePayRechargeReceipts, Guid> lifePayRechargeReceiptsRepository,
+ IRepository<LifePayExpensesReceipts, Guid> lifePayExpensesReceiptsRepository,
+ IAliPayApi aliPayApi,
+ IWxPayApi wxPayApi)
{
_lifePayRechargeReceiptsRepository = lifePayRechargeReceiptsRepository;
+ _lifePayExpensesReceiptsRepository = lifePayExpensesReceiptsRepository;
+ _aliPayApi = aliPayApi;
+ _wxPayApi = wxPayApi;
}
/// <summary>
@@ -29,10 +40,10 @@
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
- public async Task<PageOutput<LifePayRechargeReceiptsListOutput>> GetLifePayRechargeReceiptsPage(LifePayRechargeReceiptsPageInput input)
+ public async Task<LifePayRechargeReceiptsPageOutput<LifePayRechargeReceiptsListOutput>> GetLifePayRechargeReceiptsPage(LifePayRechargeReceiptsPageInput input)
{
var list = await _lifePayRechargeReceiptsRepository.Where(x => x.IsDeleted == false)
- .WhereIf(input.OrderNo.IsNotNullOrEmpty(), x => x.OrderNo.Contains(input.OrderNo))
+ .WhereIf(input.KeyWord.IsNotNullOrEmpty(), x => x.OrderNo.Contains(input.KeyWord))
.WhereIf(input.CreationTimeBegin.HasValue, x => x.CreationTime >= input.CreationTimeBegin)
.WhereIf(input.CreationTimeEnd.HasValue, x => x.CreationTime <= input.CreationTimeEnd)
.Select(x => new LifePayRechargeReceiptsListOutput()
@@ -42,16 +53,18 @@
RechargeAmount = x.RechargeAmount,
Remark = x.Remark,
Voucher = x.Voucher.GetOssPath(),
+ CreationTime = x.CreationTime,
})
.GetPageResult(input.PageModel);
- return list;
- }
- public async Task<decimal> GetTotalLifePayRechargeReceipts()
- {
- var result = await _lifePayRechargeReceiptsRepository.Where(x => x.IsDeleted == false).SumAsync(x => x.RechargeAmount);
+ var total = await _lifePayRechargeReceiptsRepository.Where(x => x.IsDeleted == false).SumAsync(x => x.RechargeAmount);
+ LifePayRechargeReceiptsPageOutput<LifePayRechargeReceiptsListOutput> result = new LifePayRechargeReceiptsPageOutput<LifePayRechargeReceiptsListOutput>();
+ result.Data = list.Data;
+ result.TotalRechargeAmount = total;
return result;
}
+
+
/// <summary>
/// 缂栬緫鍏呭�兼祦姘�
@@ -63,6 +76,8 @@
CheckExtensions.IfTrueThrowUserFriendlyException(input.OrderNo == null, "璇疯緭鍏ヤ笟鍔¤鍗曞彿");
CheckExtensions.IfTrueThrowUserFriendlyException(input.RechargeAmount <= 0, "鍏呭�奸噾棰濆簲澶т簬0");
CheckExtensions.IfTrueThrowUserFriendlyException(input.Voucher == null, "璇锋彁浜ゅ厖鍊煎嚟璇�");
+ var repeat = await _lifePayRechargeReceiptsRepository.Where(x => x.IsDeleted == false && x.OrderNo == input.OrderNo).FirstOrDefaultAsync();
+ CheckExtensions.IfTrueThrowUserFriendlyException(repeat != null && repeat.Id != input.Id, "涓氬姟璁㈠崟鍙烽噸澶�");
if (input.Id.HasValue)
{
var payRechargeReceipts = await _lifePayRechargeReceiptsRepository.Where(x => x.IsDeleted == false && x.Id == input.Id.Value).FirstOrDefaultAsync();
@@ -84,5 +99,71 @@
await _lifePayRechargeReceiptsRepository.InsertAsync(payRechargeReceipts);
}
}
+
+ /// <summary>
+ /// 鎻掑叆鏀舵敮娴佹按
+ /// </summary>
+ /// <param name="input"></param>
+ /// <returns></returns>
+ public async Task AddLifePayExpensesReceipts(AddLifePayExpensesReceiptsInput input)
+ {
+ var repeat = await _lifePayExpensesReceiptsRepository.Where(x => x.ExpensesReceiptsType == input.ExpensesReceiptsType
+ && x.OrderNo == input.OrderNo).FirstOrDefaultAsync();
+ if (repeat == null)
+ {
+ var data = new LifePayExpensesReceipts()
+ {
+ Id = Guid.NewGuid(),
+ OrderNo = input.OrderNo,
+ OutOrderNo = input.OutOrderNo,
+ LifePayType = input.LifePayType,
+ ExpensesReceiptsType = input.ExpensesReceiptsType,
+ Amount = input.Amount
+ };
+
+ switch (input.LifePayType)
+ {
+ case LifePayTypeEnum.AliPay:
+ if (input.ExpensesReceiptsType == ExpensesReceiptsTypeEnum.Expenses)
+ {
+ var query = await _aliPayApi.OrderInQuiry(new OrderInQuiryInput() { OutTradeNo = input.OrderNo });
+ if (query.Code == AlipayResultCode.Success && query.TradeStatus == AlipayStatus.TRADESUCCESS)
+ {
+ await _lifePayExpensesReceiptsRepository.InsertAsync(data);
+ }
+ }
+ else
+ {
+ var query = await _aliPayApi.QueryAlipayTradeRefund(new OrderInQuiryInput() { OutTradeNo = input.OrderNo });
+ if (query.Code == AlipayResultCode.Success && query.RefundStatus == AlipayRefundStatus.Success)
+ {
+ await _lifePayExpensesReceiptsRepository.InsertAsync(data);
+ }
+ }
+ break;
+ case LifePayTypeEnum.WxPay:
+ if (input.ExpensesReceiptsType == ExpensesReceiptsTypeEnum.Expenses)
+ {
+ var query = await _wxPayApi.WxPayTradeQuery(input.OrderNo);
+ if (query.Code == AlipayResultCode.Success && query.Status == WxPayStatus.鏀粯鎴愬姛)
+ {
+ await _lifePayExpensesReceiptsRepository.InsertAsync(data);
+ }
+ }
+ else
+ {
+ var query = await _wxPayApi.WxPayDomesticRefundsQuery(input.OrderNo);
+ if (query.Code == AlipayResultCode.Success && query.RefundStatus == WxPayRefundStatus.閫�娆炬垚鍔�)
+ {
+ await _lifePayExpensesReceiptsRepository.InsertAsync(data);
+ }
+ }
+ break;
+ default: break;
+ }
+
+
+ }
+ }
}
}
--
Gitblit v1.9.1