From 33c551e30f65dc2bdce798896e03c9acb5e70b03 Mon Sep 17 00:00:00 2001 From: dzc <2388224167@qq.com> Date: Wed, 16 Apr 2025 13:07:15 +0800 Subject: [PATCH] 11 --- .../WalletRechargeApplyServiceImpl.java | 85 +++++++++++++++++-- 1 file changed, 77 insertions(+), 8 deletions(-) diff --git a/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/service/impl/recharge/WalletRechargeApplyServiceImpl.java b/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/service/impl/recharge/WalletRechargeApplyServiceImpl.java index 37b45812b..ca5938efe 100644 --- a/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/service/impl/recharge/WalletRechargeApplyServiceImpl.java +++ b/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/service/impl/recharge/WalletRechargeApplyServiceImpl.java @@ -182,7 +182,8 @@ public class WalletRechargeApplyServiceImpl extends ServiceImpl v.setPrice(-1 * Math.abs(v.getPrice()))); + } // 如果是充值就充值到指定钱包 if (ObjectUtil.equals(detail.getBizType(), WalletBizRechargeEnum.ADD.getCode())) { - for (WalletRechargeImportEntity v : importList) { - // 查询每个人的钱包余额 - WalletManageEntity wallet = walletManageService.getWallet(v.getUserId(), detail.getWalletTypeId()); - if (ObjectUtil.isEmpty(wallet)) { - continue; - } - walletTransactionService.addWalletBalance(wallet.getId(), v.getPrice(), String.valueOf(v.getId()), WalletBizEnum.BATCH); + + } + for (WalletRechargeImportEntity v : importList) { + // 查询每个人的钱包余额 + WalletManageEntity wallet = walletManageService.getWallet(v.getUserId(), detail.getWalletTypeId()); + if (ObjectUtil.isEmpty(wallet)) { + continue; } + walletTransactionService.addWalletBalance(wallet.getId(), v.getPrice(), String.valueOf(v.getId()), WalletBizEnum.BATCH); } // 如果是记账扣款就先扣消费钱包,再扣饭卡钱包 if (ObjectUtil.equals(detail.getBizType(), WalletBizRechargeEnum.REDUCTION.getCode())) { @@ -520,6 +525,70 @@ public class WalletRechargeApplyServiceImpl extends ServiceImpl importList = rechargeImportService.list(new LambdaQueryWrapper() + .eq(WalletRechargeImportEntity::getApplyId, applyDto.getId()) + ); + List importUserIds = importList.stream().map(WalletRechargeImportEntity::getUserId).distinct().toList(); + // 查询用户 + List userList = userService.getUserDeptByIds(importUserIds).getData(); + // 错误信息 + StringBuilder errorMsg = new StringBuilder(); + // 查询用户余额 + WalletManageDto userWalletDto = new WalletManageDto(); + userWalletDto.setUserIds(importUserIds); + userWalletDto.setWalletTypeId(applyDto.getWalletTypeId()); + List userWalletList = walletManageMapper.list(userWalletDto); + for (WalletRechargeImportEntity i : importList) { + userWalletList.stream().filter(j -> ObjectUtil.equals(i.getUserId(), j.getUserId())).findFirst().ifPresent(wallet -> { + int discountPrice = wallet.getBalance() - i.getPrice(); + if (discountPrice < 0) { + // 查询用户名字 + UserVO userTarget = userList.stream().filter(j -> ObjectUtil.equals(i.getUserId(), j.getUserId())).findFirst().get(); + if (ObjectUtil.isEmpty(userTarget)) { + errorMsg.append("用户id<").append(wallet.getUserId()).append(">"); + } else { + errorMsg.append("用户名<").append(userTarget.getName()).append(">"); + } + errorMsg.append("记账扣款失败,"); + errorMsg.append("操作前的金额<").append(wallet.getBalance() / 100).append(">,"); + errorMsg.append("记账扣款的金额<").append(i.getPrice() / 100).append(">,"); + errorMsg.append("记账扣款后的金额<").append(discountPrice / 100).append(">\n"); + } + }); + } + String errorMsgString = errorMsg.toString(); + if (ObjectUtil.isNotEmpty(errorMsgString)) throw new RuntimeException(errorMsgString); + } + + public void updateAllWalletBalance(WalletRechargeApplyEntity applyDto, List importList) { + if (ObjectUtil.notEqual(applyDto.getBizType(), WalletBizRechargeEnum.REDUCTION.getCode())) return; + List importUserIds = importList.stream().map(WalletRechargeImportEntity::getUserId).distinct().toList(); + // 查询用户钱包 + WalletManageDto userWalletDto = new WalletManageDto(); + userWalletDto.setUserIds(importUserIds); + List userWalletList = walletManageMapper.joinList(userWalletDto); + for (WalletRechargeImportEntity i : importList) { + // 消费钱包 + WalletManageVo payWalletVo = userWalletList.stream() + .filter(j -> ObjectUtil.equals(i.getUserId(), j.getUserId()) && ObjectUtil.equals(j.getWalletTypeUniqueCode(), WalletTypeEnum.PAY.getCode())) + .findFirst().get(); + if (ObjectUtil.isEmpty(payWalletVo)) continue; + // 饭卡钱包 + WalletManageVo cardWalletVo = userWalletList.stream() + .filter(j -> ObjectUtil.equals(i.getUserId(), j.getUserId()) && ObjectUtil.equals(j.getWalletTypeUniqueCode(), WalletTypeEnum.EAT.getCode())) + .findFirst().get(); + if (ObjectUtil.isEmpty(cardWalletVo)) continue; + // 先判断消费钱包是不是够用 + int discountPrice = payWalletVo.getBalance() - i.getPrice(); + walletTransactionService.addWalletBalance(payWalletVo.getId(), payWalletVo.getBalance() * -1, String.valueOf(i.getId()), WalletBizEnum.BATCH); + if (discountPrice < 0) { + walletTransactionService.addWalletBalance(cardWalletVo.getId(), discountPrice, String.valueOf(i.getId()), WalletBizEnum.BATCH); + } + } + } + private WalletRechargeApplyServiceImpl getSelf() { return SpringUtil.getBean(getClass()); }