Commit f93e2579f20f39214a992e32b2e0d882c101298f

Authored by 芋道源码
Committed by GitHub
2 parents 7e18819d 8a6b7d0b

Merge pull request #1323 from dadiyang/fix/pay-a84-expense-sum-positive

fix(pay):钱包流水汇总"累计支出"返回正值——selectPriceSum 对支出改 SUM(-price),与钱包级 total_expense 语义一致
yudao-module-pay/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletTransactionMapper.java
... ... @@ -39,9 +39,10 @@ public interface PayWalletTransactionMapper extends BaseMapperX<PayWalletTransac
39 39 }
40 40  
41 41 default Integer selectPriceSum(Long walletId, Integer type, LocalDateTime[] createTime) {
42   - // SQL sum 查询
  42 + // SQL sum 查询;支出流水的 price 为负值,汇总取正值(与钱包 total_expense 的正值语义一致)
  43 + String sumColumn = Objects.equals(type, TYPE_EXPENSE) ? "SUM(-price) AS priceSum" : "SUM(price) AS priceSum";
43 44 List<Map<String, Object>> result = selectMaps(new QueryWrapperX<PayWalletTransactionDO>()
44   - .select("SUM(price) AS priceSum")
  45 + .select(sumColumn)
45 46 .gt(Objects.equals(type, TYPE_INCOME), "price", 0) // 收入
46 47 .lt(Objects.equals(type, TYPE_EXPENSE), "price", 0) // 支出
47 48 .eq("wallet_id", walletId)
... ...