Commit 8a6b7d0b98bbe46918a9ba86e90f4de33dc72a4d
1 parent
3a6150f5
fix(pay):钱包流水汇总"累计支出"返回正值——selectPriceSum 对支出改 SUM(-price),与钱包 total_expense 正值语…
…义一致(修前直加负值流水返回负数,A84)
Showing
1 changed file
with
3 additions
and
2 deletions
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,9 +39,10 @@ public interface PayWalletTransactionMapper extends BaseMapperX<PayWalletTransac | ||
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | default Integer selectPriceSum(Long walletId, Integer type, LocalDateTime[] createTime) { | 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 | List<Map<String, Object>> result = selectMaps(new QueryWrapperX<PayWalletTransactionDO>() | 44 | List<Map<String, Object>> result = selectMaps(new QueryWrapperX<PayWalletTransactionDO>() |
| 44 | - .select("SUM(price) AS priceSum") | 45 | + .select(sumColumn) |
| 45 | .gt(Objects.equals(type, TYPE_INCOME), "price", 0) // 收入 | 46 | .gt(Objects.equals(type, TYPE_INCOME), "price", 0) // 收入 |
| 46 | .lt(Objects.equals(type, TYPE_EXPENSE), "price", 0) // 支出 | 47 | .lt(Objects.equals(type, TYPE_EXPENSE), "price", 0) // 支出 |
| 47 | .eq("wallet_id", walletId) | 48 | .eq("wallet_id", walletId) |