11
This commit is contained in:
1 parent
2fd5cd6ee1
commit
33c551e30f
1 file changed
+77
-8
+77
-8
@@ -182,7 +182,8 @@ public class WalletRechargeApplyServiceImpl extends ServiceImpl<WalletRechargeAp
|
||||
throw new RuntimeException("饭卡类型不存在");
|
||||
}
|
||||
// 判断申请下如果类型为记账扣款,余额是否够扣款
|
||||
validateWalletBalance(detail);
|
||||
// validateWalletBalance(detail);
|
||||
validateWalletBalanceByType(detail);
|
||||
// 发起审批
|
||||
WalletRechargeApplyFlowDto flowDto = new WalletRechargeApplyFlowDto();
|
||||
flowDto.setApplyUsername(user.getSysUser().getUsername());
|
||||
@@ -314,16 +315,20 @@ public class WalletRechargeApplyServiceImpl extends ServiceImpl<WalletRechargeAp
|
||||
return;
|
||||
}
|
||||
getSelf().updateBeforePrice(detail);
|
||||
if (ObjectUtil.equals(detail.getBizType(), WalletBizRechargeEnum.REDUCTION.getCode())) {
|
||||
importList.forEach(v -> 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<WalletRechargeAp
|
||||
if (ObjectUtil.isNotEmpty(errorMsgString)) throw new RuntimeException(errorMsgString);
|
||||
}
|
||||
|
||||
private void validateWalletBalanceByType(WalletRechargeApplyEntity applyDto) {
|
||||
if (ObjectUtil.notEqual(applyDto.getBizType(), WalletBizRechargeEnum.REDUCTION.getCode())) return;
|
||||
List<WalletRechargeImportEntity> importList = rechargeImportService.list(new LambdaQueryWrapper<WalletRechargeImportEntity>()
|
||||
.eq(WalletRechargeImportEntity::getApplyId, applyDto.getId())
|
||||
);
|
||||
List<Long> importUserIds = importList.stream().map(WalletRechargeImportEntity::getUserId).distinct().toList();
|
||||
// 查询用户
|
||||
List<UserVO> userList = userService.getUserDeptByIds(importUserIds).getData();
|
||||
// 错误信息
|
||||
StringBuilder errorMsg = new StringBuilder();
|
||||
// 查询用户余额
|
||||
WalletManageDto userWalletDto = new WalletManageDto();
|
||||
userWalletDto.setUserIds(importUserIds);
|
||||
userWalletDto.setWalletTypeId(applyDto.getWalletTypeId());
|
||||
List<WalletManageEntity> 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<WalletRechargeImportEntity> importList) {
|
||||
if (ObjectUtil.notEqual(applyDto.getBizType(), WalletBizRechargeEnum.REDUCTION.getCode())) return;
|
||||
List<Long> importUserIds = importList.stream().map(WalletRechargeImportEntity::getUserId).distinct().toList();
|
||||
// 查询用户钱包
|
||||
WalletManageDto userWalletDto = new WalletManageDto();
|
||||
userWalletDto.setUserIds(importUserIds);
|
||||
List<WalletManageVo> 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());
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user