feat:校验申请的充值/扣款数据当前是否合法

This commit is contained in:
dzc committed 2026-03-31 16:26:04 +08:00
1 parent 0894e86d8c
commit eec07ac718
5 files changed
+131

No files matched your search

@@ -19,6 +19,11 @@ public enum WalletBizRechargeEnum {
private final String desc;
public static List<WalletBizRechargeEnum> reductionList = List.of(
REDUCTION,
RETURN_CANTEEN
);
public static List<String> reductionCodes() {
return Arrays.asList(REDUCTION.getCode(), RETURN_CANTEEN.getCode());
}
@@ -0,0 +1,52 @@
package com.bsd.pjcloud.wallet.api.vo.recharge;
import com.bsd.pjcloud.admin.api.vo.base.BaseUserInterface;
import lombok.Data;
import java.util.List;
@Data
public class WalletRechargeValidateErrorVo implements BaseUserInterface {
/**
* 用户相关
*/
private Long userId;
private String username;
private String userMobile;
private String userAvatar;
/**
* 饭卡类型id
*/
private Long walletTypeId;
/**
* 钱包余额
*/
private Integer walletBlance;
/**
* 操作类型
*/
private String bizType;
/**
* 操作金额
*/
private Integer price;
/**
* 操作后的金额
*/
private Integer afterPrice;
/**
* 错误信息
*/
private List<String> errorList;
}
@@ -20,6 +20,7 @@ import com.bsd.pjcloud.wallet.api.dto.recharge.excel.WalletRechargeExcelDto;
import com.bsd.pjcloud.wallet.api.entity.recharge.WalletRechargeApplyEntity;
import com.bsd.pjcloud.wallet.api.vo.recharge.WalletRechargeApplyCompareAceVo;
import com.bsd.pjcloud.wallet.api.vo.recharge.WalletRechargeImportVo;
import com.bsd.pjcloud.wallet.api.vo.recharge.WalletRechargeValidateErrorVo;
import com.bsd.pjcloud.wallet.api.vo.recharge.excel.WalletRechargeByApplyExcelVo;
import com.bsd.pjcloud.wallet.service.WalletRechargeApplyService;
import com.bsd.pjcloud.wallet.service.WalletRechargeApplyComposeService;
@@ -55,6 +56,12 @@ public class WalletRechargeApplyController {
}
/* ************************************* start callback start ************************************* */
@GetMapping("/validate-error")
@Operation(summary = "校验申请的充值/扣款数据当前是否合法")
public R<List<WalletRechargeValidateErrorVo>> validateError(@RequestParam Long applyId) {
return R.ok(walletRechargeApplyService.validateError(applyId));
}
@PostMapping("/save-topup")
@Operation(summary = "新增充值")
@Idempotent(expireTime = 3, key = "'/wallet-recharge-apply/save-topup' + #dto.getInvoiceId()", info = "正在充值中,请勿重复操作")
@@ -12,6 +12,7 @@ import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargeSaveTopupDto;
import com.bsd.pjcloud.wallet.api.dto.recharge.excel.WalletRechargeExcelDto;
import com.bsd.pjcloud.wallet.api.entity.recharge.WalletRechargeApplyEntity;
import com.bsd.pjcloud.wallet.api.vo.recharge.WalletRechargeApplyVo;
import com.bsd.pjcloud.wallet.api.vo.recharge.WalletRechargeValidateErrorVo;
import com.bsd.pjcloud.wallet.api.vo.recharge.excel.WalletRechargeByApplyExcelVo;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.validation.BindingResult;
@@ -72,4 +73,9 @@ public interface WalletRechargeApplyService extends IService<WalletRechargeApply
* 导出充值/扣款申请
*/
void export(HttpServletResponse response, WalletRechargeApplyDto dto);
/**
* 校验申请的充值/扣款数据当前是否合法
*/
List<WalletRechargeValidateErrorVo> validateError(Long applyId);
}
@@ -57,6 +57,7 @@ import com.bsd.pjcloud.wallet.api.utils.WalletDataUtil;
import com.bsd.pjcloud.wallet.api.vo.WalletManageVo;
import com.bsd.pjcloud.wallet.api.vo.recharge.WalletRechargeApplyVo;
import com.bsd.pjcloud.wallet.api.vo.recharge.WalletRechargeImportVo;
import com.bsd.pjcloud.wallet.api.vo.recharge.WalletRechargeValidateErrorVo;
import com.bsd.pjcloud.wallet.api.vo.recharge.excel.WalletRechargeByApplyExcelVo;
import com.bsd.pjcloud.wallet.mapper.WalletManageMapper;
import com.bsd.pjcloud.wallet.mapper.WalletTransactionMapper;
@@ -554,6 +555,66 @@ public class WalletRechargeApplyServiceImpl extends ServiceImpl<WalletRechargeAp
return result;
}
/**
* 校验申请的充值/扣款数据当前是否合法
*/
@Override
public List<WalletRechargeValidateErrorVo> validateError(Long applyId) {
List<WalletRechargeValidateErrorVo> resultList = new ArrayList<>();
WalletRechargeApplyEntity detail = baseMapper.selectById(applyId);
if (ObjectUtil.isEmpty(detail)) return null;
// 校验判断回不回出现扣减之后为负数的情况
List<String> reductionList = WalletBizRechargeEnum.reductionList.stream().map(WalletBizRechargeEnum::getCode).toList();
if (reductionList.contains(detail.getBizType())) {
List<WalletRechargeImportEntity> importList = rechargeImportService.list(new LambdaQueryWrapper<WalletRechargeImportEntity>().eq(WalletRechargeImportEntity::getApplyId, applyId));
if (ObjectUtil.isEmpty(importList)) {
return null;
}
List<Long> userIds = importList.stream().map(WalletRechargeImportEntity::getUserId).filter(ObjectUtil::isNotEmpty).distinct().toList();
// 查询现在这些用户的钱包余额
WalletManageDto walletQueryDto = new WalletManageDto();
walletQueryDto.setWalletTypeId(detail.getWalletTypeId());
walletQueryDto.setUserIds(userIds);
List<WalletManageEntity> walletList = walletManageMapper.list(walletQueryDto);
// 判断每一个人的每一个钱包余额是否满足扣减
for (WalletManageEntity wallet : walletList) {
List<WalletRechargeImportEntity> list = importList.stream().filter(v -> ObjectUtil.equals(v.getUserId(), wallet.getUserId())).toList();
if (ObjectUtil.isEmpty(list)) continue;
Integer reductionPrice = list.stream().map(WalletRechargeImportEntity::getPrice).reduce(Integer::sum).orElse(0);
int price = wallet.getBalance() - reductionPrice;
if (price < 0) {
WalletRechargeValidateErrorVo item = new WalletRechargeValidateErrorVo();
item.setUserId(wallet.getUserId());
item.setBizType(detail.getBizType());
item.setWalletTypeId(detail.getWalletTypeId());
item.setWalletBlance(wallet.getBalance());
item.setPrice(reductionPrice);
item.setAfterPrice(price);
item.setErrorList(new ArrayList<String>() {{
add("钱包余额不足以扣款,请尽快联系该用户");
}});
resultList.add(item);
}
}
}
// 处理`resultList`结果
if (ObjectUtil.isNotEmpty(resultList)) {
List<Long> userIds = resultList.stream().map(WalletRechargeValidateErrorVo::getUserId).filter(ObjectUtil::isNotEmpty).distinct().toList();
List<SysUser> userList = userService.getInnerUserById(userIds).getData();
if (ObjectUtil.isNotEmpty(userList)) {
DataUtil.convertUserList(resultList, CollectionUtils.convertMap(userList, SysUser::getUserId));
}
}
return resultList;
}
/**
* 导出充值/扣款申请
*/