mirror of
https://gitee.com/dromara/dax-pay.git
synced 2025-09-03 11:06:46 +00:00
fix 分账发起增加校验
This commit is contained in:
@@ -6,6 +6,7 @@ import lombok.experimental.Accessors;
|
||||
|
||||
import javax.validation.constraints.Min;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* 分账接收方列表
|
||||
@@ -24,7 +25,7 @@ public class AllocReceiverParam {
|
||||
|
||||
/** 分账金额 */
|
||||
@Schema(description = "分账金额")
|
||||
@NotEmpty(message = "分账金额必填")
|
||||
@NotNull(message = "分账金额必填")
|
||||
@Min(value = 1,message = "分账金额至少为0.01元")
|
||||
private Integer amount;
|
||||
}
|
||||
|
@@ -32,6 +32,7 @@ import java.math.RoundingMode;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -106,12 +107,19 @@ public class AllocationOrderService {
|
||||
Map<String, Integer> receiverNoMap = param.getReceivers()
|
||||
.stream()
|
||||
.collect(Collectors.toMap(AllocReceiverParam::getReceiverNo, AllocReceiverParam::getAmount));
|
||||
|
||||
// 查询分账接收方信息
|
||||
List<AllocationReceiver> receivers = receiverManager.findAllByReceiverNos(receiverNos);
|
||||
if (receivers.size() != receiverNos.size()){
|
||||
throw new PayFailureException("分账接收方列表存在无效的分账接收方");
|
||||
throw new PayFailureException("分账接收方列表存在重复或无效的数据");
|
||||
}
|
||||
// 判断分账接收方类型是否都与分账订单类型匹配
|
||||
boolean anyMatch = receivers.stream()
|
||||
.anyMatch(o -> !Objects.equals(o.getChannel(), payOrder.getChannel()));
|
||||
if (anyMatch){
|
||||
throw new PayFailureException("分账接收方列表存在非本通道的数据");
|
||||
}
|
||||
|
||||
|
||||
long allocId = IdUtil.getSnowflakeNextId();
|
||||
|
||||
// 订单明细
|
||||
|
@@ -4,6 +4,7 @@ import cn.bootx.platform.common.core.exception.DataNotExistException;
|
||||
import cn.bootx.platform.common.core.exception.RepetitiveOperationException;
|
||||
import cn.bootx.platform.common.core.util.CollUtil;
|
||||
import cn.daxpay.single.code.AllocDetailResultEnum;
|
||||
import cn.daxpay.single.code.AllocOrderResultEnum;
|
||||
import cn.daxpay.single.code.AllocOrderStatusEnum;
|
||||
import cn.daxpay.single.code.PayOrderAllocStatusEnum;
|
||||
import cn.daxpay.single.exception.pay.PayFailureException;
|
||||
@@ -103,7 +104,7 @@ public class AllocationService {
|
||||
}
|
||||
try {
|
||||
// 构建分账订单相关信息
|
||||
OrderAndDetail orderAndDetail = this.createAlloc(param, payOrder);
|
||||
OrderAndDetail orderAndDetail = this.checkAndCreateAlloc(param, payOrder);
|
||||
// 检查是否需要进行分账
|
||||
AllocationOrder order = orderAndDetail.getOrder();
|
||||
List<AllocationOrderDetail> details = orderAndDetail.getDetails();
|
||||
@@ -125,6 +126,7 @@ public class AllocationService {
|
||||
allocationStrategy.allocation();
|
||||
// 执行中
|
||||
order.setStatus(AllocOrderStatusEnum.ALLOCATION_PROCESSING.getCode())
|
||||
.setResult(AllocOrderResultEnum.PART_SUCCESS.getCode())
|
||||
.setErrorMsg(null);
|
||||
} catch (Exception e) {
|
||||
log.error("分账出现错误:", e);
|
||||
@@ -285,20 +287,26 @@ public class AllocationService {
|
||||
/**
|
||||
* 构建分账订单相关信息
|
||||
*/
|
||||
private OrderAndDetail createAlloc(AllocationParam param, PayOrder payOrder){
|
||||
private OrderAndDetail checkAndCreateAlloc(AllocationParam param, PayOrder payOrder){
|
||||
// 创建分账单和明细并保存, 同时更新支付订单状态 使用事务
|
||||
OrderAndDetail orderAndDetail;
|
||||
// 判断是否传输了分账接收方列表
|
||||
if (CollUtil.isNotEmpty(param.getReceivers())) {
|
||||
orderAndDetail = allocationOrderService.createAndUpdate(param, payOrder);
|
||||
} else if (Objects.nonNull(param.getGroupNo())){
|
||||
// 指定分账组
|
||||
AllocationGroup allocationGroup = groupManager.findByGroupNo(param.getGroupNo()).orElseThrow(() -> new DataNotExistException("未查询到分账组"));
|
||||
List<AllocationGroupReceiverResult> receiversByGroups = allocationGroupService.findReceiversByGroups(allocationGroup.getId());
|
||||
orderAndDetail = allocationOrderService.createAndUpdate(param ,payOrder, receiversByGroups);
|
||||
} else {
|
||||
// 默认分账组
|
||||
AllocationGroup allocationGroup = groupManager.findDefaultGroup(payOrder.getChannel()).orElseThrow(() -> new PayFailureException("未查询到默认分账组"));
|
||||
AllocationGroup allocationGroup;
|
||||
if (Objects.nonNull(param.getGroupNo())){
|
||||
// 指定分账组
|
||||
allocationGroup = groupManager.findByGroupNo(param.getGroupNo()).orElseThrow(() -> new DataNotExistException("未查询到分账组"));
|
||||
} else {
|
||||
// 默认分账组
|
||||
allocationGroup = groupManager.findDefaultGroup(payOrder.getChannel()).orElseThrow(() -> new PayFailureException("未查询到默认分账组"));
|
||||
}
|
||||
// 判断通道类型是否一致
|
||||
if (!Objects.equals(allocationGroup.getChannel(), payOrder.getChannel())){
|
||||
throw new PayFailureException("分账接收方列表存在非本通道的数据");
|
||||
}
|
||||
|
||||
List<AllocationGroupReceiverResult> receiversByGroups = allocationGroupService.findReceiversByGroups(allocationGroup.getId());
|
||||
orderAndDetail = allocationOrderService.createAndUpdate(param ,payOrder, receiversByGroups);
|
||||
}
|
||||
|
Reference in New Issue
Block a user