mirror of
https://gitee.com/dromara/dax-pay
synced 2026-08-11 07:05:33 +08:00
ref 分账优化
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
2.0.7: 分账完善和基础架构优化
|
||||
- [x] 新增资金流水
|
||||
- [x] 增加对超时订单进行处理(数据库同步)
|
||||
- [ ] 支持分账组分账和自己传接收方进行分账
|
||||
- [x] 支持分账组分账和自己传接收方进行分账
|
||||
- [ ] 分账组管理提供接口调用
|
||||
- [ ] 添加分账接收方
|
||||
- [ ] 查询分账接收方
|
||||
@@ -23,9 +23,10 @@
|
||||
- [ ] 下载系统账单
|
||||
- [ ] 增加资金对账单功能
|
||||
- [ ] 支付通道两个独立的配置进行合并为一个
|
||||
|
||||
- [ ] 撤销接口
|
||||
2.1.x 版本内容
|
||||
- [ ] 对账回退及退款
|
||||
- [ ] 差错单据处理
|
||||
- [ ] 特殊退款接口
|
||||
- [ ] 统计报表功能
|
||||
- [ ] 微信新增V3版本接口
|
||||
- [ ] 支付宝新增V3版本接口
|
||||
|
||||
@@ -5,9 +5,9 @@ import cn.bootx.platform.common.core.rest.Res;
|
||||
import cn.bootx.platform.common.core.rest.ResResult;
|
||||
import cn.bootx.platform.common.core.rest.dto.LabelValue;
|
||||
import cn.bootx.platform.common.core.rest.param.PageParam;
|
||||
import cn.daxpay.single.param.payment.allocation.AllocationStartParam;
|
||||
import cn.daxpay.single.param.payment.allocation.AllocationSyncParam;
|
||||
import cn.daxpay.single.param.payment.allocation.AllocationFinishParam;
|
||||
import cn.daxpay.single.param.payment.allocation.AllocStartParam;
|
||||
import cn.daxpay.single.param.payment.allocation.AllocSyncParam;
|
||||
import cn.daxpay.single.param.payment.allocation.AllocFinishParam;
|
||||
import cn.daxpay.single.service.core.order.allocation.service.AllocationOrderService;
|
||||
import cn.daxpay.single.service.core.payment.allocation.service.AllocationService;
|
||||
import cn.daxpay.single.service.dto.order.allocation.AllocationOrderDetailDto;
|
||||
@@ -72,7 +72,7 @@ public class AllocationOrderController {
|
||||
@Operation(summary = "同步分账结果")
|
||||
@PostMapping("/sync")
|
||||
public ResResult<Void> sync(String allocationNo){
|
||||
AllocationSyncParam param = new AllocationSyncParam();
|
||||
AllocSyncParam param = new AllocSyncParam();
|
||||
param.setAllocationNo(allocationNo);
|
||||
allocationService.sync(param);
|
||||
return Res.ok();
|
||||
@@ -81,7 +81,7 @@ public class AllocationOrderController {
|
||||
@Operation(summary = "分账完结")
|
||||
@PostMapping("/finish")
|
||||
public ResResult<Void> finish(String allocationNo){
|
||||
AllocationFinishParam param = new AllocationFinishParam();
|
||||
AllocFinishParam param = new AllocFinishParam();
|
||||
param.setAllocationNo(allocationNo);
|
||||
allocationService.finish(param);
|
||||
return Res.ok();
|
||||
@@ -90,7 +90,7 @@ public class AllocationOrderController {
|
||||
@Operation(summary = "重新发起分账")
|
||||
@PostMapping("/retry")
|
||||
public ResResult<Void> retryAllocation(String bizAllocationNo){
|
||||
AllocationStartParam param = new AllocationStartParam();
|
||||
AllocStartParam param = new AllocStartParam();
|
||||
param.setBizAllocationNo(bizAllocationNo);
|
||||
allocationService.allocation(param);
|
||||
return Res.ok();
|
||||
|
||||
@@ -7,8 +7,8 @@ import cn.bootx.platform.common.core.rest.dto.LabelValue;
|
||||
import cn.bootx.platform.common.core.rest.param.PageParam;
|
||||
import cn.daxpay.single.service.core.payment.allocation.service.AllocationReceiverService;
|
||||
import cn.daxpay.single.service.dto.allocation.AllocationReceiverDto;
|
||||
import cn.daxpay.single.service.param.allocation.group.AllocationReceiverParam;
|
||||
import cn.daxpay.single.service.param.allocation.group.AllocationReceiverQuery;
|
||||
import cn.daxpay.single.service.param.allocation.receiver.AllocationReceiverParam;
|
||||
import cn.daxpay.single.service.param.allocation.receiver.AllocationReceiverQuery;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@@ -5,7 +5,7 @@ import cn.bootx.platform.common.core.rest.PageResult;
|
||||
import cn.bootx.platform.common.core.rest.Res;
|
||||
import cn.bootx.platform.common.core.rest.ResResult;
|
||||
import cn.bootx.platform.common.core.rest.param.PageParam;
|
||||
import cn.daxpay.single.param.payment.allocation.AllocationStartParam;
|
||||
import cn.daxpay.single.param.payment.allocation.AllocStartParam;
|
||||
import cn.daxpay.single.param.payment.pay.PayCloseParam;
|
||||
import cn.daxpay.single.param.payment.pay.PaySyncParam;
|
||||
import cn.daxpay.single.result.pay.SyncResult;
|
||||
@@ -99,7 +99,7 @@ public class PayOrderController {
|
||||
@Operation(summary = "发起分账")
|
||||
@PostMapping("/allocation")
|
||||
public ResResult<Void> allocation(String orderNo){
|
||||
AllocationStartParam param = new AllocationStartParam();
|
||||
AllocStartParam param = new AllocStartParam();
|
||||
param.setOrderNo(orderNo);
|
||||
param.setBizAllocationNo(OrderNoGenerateUtil.allocation());
|
||||
allocationService.allocation(param);
|
||||
|
||||
@@ -13,7 +13,7 @@ import lombok.EqualsAndHashCode;
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@Schema(title = "分账请求参数")
|
||||
public class AllocationFinishParam extends PaymentCommonParam {
|
||||
public class AllocFinishParam extends PaymentCommonParam {
|
||||
|
||||
@Schema(description = "商户分账单号")
|
||||
private String bizAllocationNo;
|
||||
@@ -0,0 +1,62 @@
|
||||
package cn.daxpay.single.param.payment.allocation;
|
||||
|
||||
import cn.daxpay.single.code.AllocReceiverTypeEnum;
|
||||
import cn.daxpay.single.code.AllocRelationTypeEnum;
|
||||
import cn.daxpay.single.code.PayChannelEnum;
|
||||
import cn.daxpay.single.param.PaymentCommonParam;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 分账接收者添加参数
|
||||
* @author xxm
|
||||
* @since 2024/5/20
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@Schema(title = "分账接收者添加参数")
|
||||
public class AllocReceiverAddParam extends PaymentCommonParam {
|
||||
|
||||
@Schema(description = "接收者编号, 需要保证唯一")
|
||||
private String receiverNo;
|
||||
|
||||
/** 账号别名 */
|
||||
@Schema(description = "账号别名")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 所属通道
|
||||
* @see PayChannelEnum
|
||||
*/
|
||||
@Schema(description = "所属通道")
|
||||
private String channel;
|
||||
|
||||
/**
|
||||
* 分账接收方类型 个人/商户
|
||||
* @see AllocReceiverTypeEnum
|
||||
*/
|
||||
@Schema(description = "分账接收方类型")
|
||||
private String receiverType;
|
||||
|
||||
/** 接收方账号 */
|
||||
@Schema(description = "接收方账号")
|
||||
private String receiverAccount;
|
||||
|
||||
/** 接收方姓名 */
|
||||
@Schema(description = "接收方姓名")
|
||||
private String receiverName;
|
||||
|
||||
/**
|
||||
* 分账关系类型
|
||||
* @see AllocRelationTypeEnum
|
||||
*/
|
||||
@Schema(description = "分账关系类型")
|
||||
private String relationType;
|
||||
|
||||
/** 关系名称 关系类型为自定义是填写 */
|
||||
@Schema(description = "关系名称")
|
||||
private String relationName;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package cn.daxpay.single.param.payment.allocation;
|
||||
|
||||
import cn.daxpay.single.param.PaymentCommonParam;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 分账接收者删除参数
|
||||
* @author xxm
|
||||
* @since 2024/5/20
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@Schema(title = "分账接收者删除参数")
|
||||
public class AllocReceiverRemoveParam extends PaymentCommonParam {
|
||||
|
||||
@Schema(description = "接收者编号")
|
||||
private String receiverNo;
|
||||
|
||||
}
|
||||
@@ -15,7 +15,7 @@ import javax.validation.constraints.NotBlank;
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@Schema(title = "开始分账请求参数")
|
||||
public class AllocationStartParam extends PaymentCommonParam {
|
||||
public class AllocStartParam extends PaymentCommonParam {
|
||||
|
||||
/** 商户分账单号 */
|
||||
@Schema(description = "商户分账单号")
|
||||
@@ -10,7 +10,7 @@ import lombok.Data;
|
||||
*/
|
||||
@Data
|
||||
@Schema(title = "分账同步请求参数")
|
||||
public class AllocationSyncParam {
|
||||
public class AllocSyncParam {
|
||||
|
||||
@Schema(description = "分账号")
|
||||
private String allocationNo;
|
||||
@@ -0,0 +1,19 @@
|
||||
package cn.daxpay.single.param.payment.allocation;
|
||||
|
||||
import cn.daxpay.single.param.PaymentCommonParam;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 查询分账接收者参数
|
||||
* @author xxm
|
||||
* @since 2024/5/20
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@Schema(title = "查询分账接收者参数")
|
||||
public class QueryAllocReceiverParam extends PaymentCommonParam {
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package cn.daxpay.single.result.allocation;
|
||||
|
||||
import cn.daxpay.single.result.PaymentCommonResult;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 分账同步接口
|
||||
* @author xxm
|
||||
* @since 2024/5/20
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@Schema(title = "分账同步接口")
|
||||
public class AllocationSyncResult extends PaymentCommonResult {
|
||||
}
|
||||
@@ -1,15 +1,13 @@
|
||||
package cn.daxpay.single.gateway.controller;
|
||||
|
||||
import cn.daxpay.single.code.PaymentApiCode;
|
||||
import cn.daxpay.single.param.payment.allocation.AllocationFinishParam;
|
||||
import cn.daxpay.single.param.payment.allocation.AllocationStartParam;
|
||||
import cn.daxpay.single.param.payment.allocation.AllocationSyncParam;
|
||||
import cn.daxpay.single.param.payment.allocation.*;
|
||||
import cn.daxpay.single.result.DaxResult;
|
||||
import cn.daxpay.single.result.allocation.AllocationResult;
|
||||
import cn.daxpay.single.result.allocation.AllocationSyncResult;
|
||||
import cn.daxpay.single.service.annotation.PaymentApi;
|
||||
import cn.daxpay.single.service.core.payment.allocation.service.AllocationReceiverService;
|
||||
import cn.daxpay.single.service.core.payment.allocation.service.AllocationService;
|
||||
import cn.daxpay.single.service.param.allocation.group.AllocationReceiverParam;
|
||||
import cn.daxpay.single.util.DaxRes;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@@ -37,54 +35,51 @@ public class UniAllocationController {
|
||||
@PaymentApi(PaymentApiCode.ALLOCATION)
|
||||
@Operation(summary = "触发分账")
|
||||
@PostMapping("/open")
|
||||
public DaxResult<AllocationResult> open(@RequestBody AllocationStartParam param){
|
||||
public DaxResult<AllocationResult> open(@RequestBody AllocStartParam param){
|
||||
return DaxRes.ok(allocationService.allocation(param));
|
||||
}
|
||||
|
||||
@PaymentApi(PaymentApiCode.ALLOCATION_FINISH)
|
||||
@Operation(summary = "分账完结接口")
|
||||
@PostMapping("/finish")
|
||||
public DaxResult<Void> finish(@RequestBody AllocationFinishParam param){
|
||||
allocationService.finish(param);
|
||||
return DaxRes.ok();
|
||||
public DaxResult<AllocationResult> finish(@RequestBody AllocFinishParam param){
|
||||
return DaxRes.ok(allocationService.finish(param));
|
||||
}
|
||||
|
||||
@PaymentApi(PaymentApiCode.SYNC_ALLOCATION)
|
||||
@Operation(summary = "分账同步接口")
|
||||
@PostMapping("/sync")
|
||||
public DaxResult<Void> sync(@RequestBody AllocationSyncParam param){
|
||||
allocationService.sync(param);
|
||||
return DaxRes.ok();
|
||||
public DaxResult<AllocationSyncResult> sync(@RequestBody AllocSyncParam param){
|
||||
return DaxRes.ok(allocationService.sync(param));
|
||||
}
|
||||
|
||||
@PaymentApi(PaymentApiCode.QUERY_ALLOCATION_ORDER)
|
||||
@Operation(summary = "分账查询接口")
|
||||
@PostMapping("/query")
|
||||
public DaxResult<Void> query(@RequestBody AllocationFinishParam param){
|
||||
// allocationService.query(param);
|
||||
public DaxResult<Void> query(@RequestBody AllocFinishParam param){
|
||||
allocationService.query(param);
|
||||
return DaxRes.ok();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@PaymentApi(PaymentApiCode.ALLOCATION_RECEIVER_ADD)
|
||||
@Operation(summary = "添加分账接收方接口")
|
||||
@PostMapping("/receiver/add")
|
||||
public DaxResult<Void> receiverAdd(@RequestBody AllocationReceiverParam param){
|
||||
public DaxResult<Void> receiverAdd(@RequestBody AllocReceiverAddParam param){
|
||||
receiverService.addAndSync(param);
|
||||
return DaxRes.ok();
|
||||
}
|
||||
|
||||
@PaymentApi(PaymentApiCode.ALLOCATION_RECEIVER_REMOVE)
|
||||
@Operation(summary = "删除分账接收方接口")
|
||||
@PostMapping("/receiver/remove")
|
||||
public DaxResult<Void> receiverRemove(@RequestBody AllocationReceiverParam param){
|
||||
public DaxResult<Void> receiverRemove(@RequestBody AllocReceiverRemoveParam param){
|
||||
return DaxRes.ok();
|
||||
}
|
||||
|
||||
@PaymentApi(PaymentApiCode.ALLOCATION_RECEIVER_QUERY)
|
||||
@Operation(summary = "查询分账接收方接口")
|
||||
@PostMapping("/receiver/query")
|
||||
public DaxResult<Void> receiveQuery(@RequestBody AllocationReceiverParam param){
|
||||
public DaxResult<Void> receiveQuery(@RequestBody QueryAllocReceiverParam param){
|
||||
return DaxRes.ok();
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import cn.daxpay.single.code.AllocDetailResultEnum;
|
||||
import cn.daxpay.single.code.AllocOrderStatusEnum;
|
||||
import cn.daxpay.single.code.PayChannelEnum;
|
||||
import cn.daxpay.single.code.PayOrderAllocStatusEnum;
|
||||
import cn.daxpay.single.param.payment.allocation.AllocationStartParam;
|
||||
import cn.daxpay.single.param.payment.allocation.AllocStartParam;
|
||||
import cn.daxpay.single.service.core.order.allocation.dao.AllocationOrderDetailManager;
|
||||
import cn.daxpay.single.service.core.order.allocation.dao.AllocationOrderManager;
|
||||
import cn.daxpay.single.service.core.order.allocation.entity.AllocationOrder;
|
||||
@@ -92,7 +92,7 @@ public class AllocationOrderService {
|
||||
* 生成分账订单
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public OrderAndDetail createAndUpdate(AllocationStartParam param, PayOrder payOrder, int orderAmount, List<AllocationGroupReceiverResult> receiversByGroups){
|
||||
public OrderAndDetail createAndUpdate(AllocStartParam param, PayOrder payOrder, int orderAmount, List<AllocationGroupReceiverResult> receiversByGroups){
|
||||
long orderId = IdUtil.getSnowflakeNextId();
|
||||
|
||||
// 订单明细
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package cn.daxpay.single.service.core.payment.allocation.convert;
|
||||
|
||||
import cn.daxpay.single.param.payment.allocation.AllocReceiverAddParam;
|
||||
import cn.daxpay.single.service.core.payment.allocation.entity.AllocationReceiver;
|
||||
import cn.daxpay.single.service.dto.allocation.AllocationReceiverDto;
|
||||
import cn.daxpay.single.service.param.allocation.group.AllocationReceiverParam;
|
||||
import cn.daxpay.single.service.param.allocation.receiver.AllocationReceiverParam;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@@ -18,4 +19,6 @@ public interface AllocationReceiverConvert {
|
||||
AllocationReceiverDto convert(AllocationReceiver in);
|
||||
|
||||
AllocationReceiver convert(AllocationReceiverParam in);
|
||||
|
||||
AllocationReceiver convert(AllocReceiverAddParam in);
|
||||
}
|
||||
|
||||
@@ -38,4 +38,9 @@ public class AllocationGroupReceiverManager extends BaseManager<AllocationGroupR
|
||||
public void deleteByGroupId(Long groupId){
|
||||
deleteByField(AllocationGroupReceiver::getGroupId, groupId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否存在分账接收者
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import cn.bootx.platform.common.mybatisplus.impl.BaseManager;
|
||||
import cn.bootx.platform.common.mybatisplus.util.MpUtil;
|
||||
import cn.bootx.platform.common.query.generator.QueryGenerator;
|
||||
import cn.daxpay.single.service.core.payment.allocation.entity.AllocationReceiver;
|
||||
import cn.daxpay.single.service.param.allocation.group.AllocationReceiverQuery;
|
||||
import cn.daxpay.single.service.param.allocation.receiver.AllocationReceiverQuery;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@@ -29,6 +29,10 @@ import lombok.experimental.Accessors;
|
||||
@TableName(value = "pay_allocation_receiver",autoResultMap = true)
|
||||
public class AllocationReceiver extends MpBaseEntity implements EntityBaseFunction<AllocationReceiverDto> {
|
||||
|
||||
/** 分账接收方编号, 需要保证唯一 */
|
||||
@DbColumn(comment = "分账接收方编号")
|
||||
private String receiverNo;
|
||||
|
||||
@DbColumn(comment = "账号别名")
|
||||
private String name;
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import cn.bootx.platform.common.mybatisplus.util.MpUtil;
|
||||
import cn.daxpay.single.code.AllocReceiverTypeEnum;
|
||||
import cn.daxpay.single.code.PayChannelEnum;
|
||||
import cn.daxpay.single.exception.pay.PayFailureException;
|
||||
import cn.daxpay.single.param.payment.allocation.AllocReceiverAddParam;
|
||||
import cn.daxpay.single.service.core.payment.allocation.convert.AllocationReceiverConvert;
|
||||
import cn.daxpay.single.service.core.payment.allocation.dao.AllocationGroupReceiverManager;
|
||||
import cn.daxpay.single.service.core.payment.allocation.dao.AllocationReceiverManager;
|
||||
@@ -16,9 +17,11 @@ import cn.daxpay.single.service.core.payment.allocation.entity.AllocationReceive
|
||||
import cn.daxpay.single.service.core.payment.allocation.factory.AllocationReceiverFactory;
|
||||
import cn.daxpay.single.service.dto.allocation.AllocationReceiverDto;
|
||||
import cn.daxpay.single.service.func.AbsAllocationReceiverStrategy;
|
||||
import cn.daxpay.single.service.param.allocation.group.AllocationReceiverParam;
|
||||
import cn.daxpay.single.service.param.allocation.group.AllocationReceiverQuery;
|
||||
import cn.daxpay.single.service.param.allocation.receiver.AllocationReceiverParam;
|
||||
import cn.daxpay.single.service.param.allocation.receiver.AllocationReceiverQuery;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.baomidou.lock.LockInfo;
|
||||
import com.baomidou.lock.LockTemplate;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -42,6 +45,8 @@ public class AllocationReceiverService {
|
||||
|
||||
private final AllocationGroupReceiverManager groupReceiverManager;
|
||||
|
||||
private final LockTemplate lockTemplate;
|
||||
|
||||
/**
|
||||
* 分页
|
||||
*/
|
||||
@@ -175,10 +180,29 @@ public class AllocationReceiverService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 接口添加
|
||||
* 添加分账接收方并同步到三方支付系统中
|
||||
*/
|
||||
public void add(){
|
||||
public void addAndSync(AllocReceiverAddParam param){
|
||||
// 判断是否已经添加
|
||||
AllocationReceiver receiver = AllocationReceiverConvert.CONVERT.convert(param);
|
||||
|
||||
// 获取策略
|
||||
PayChannelEnum channelEnum = PayChannelEnum.findByCode(param.getChannel());
|
||||
AbsAllocationReceiverStrategy receiverStrategy = AllocationReceiverFactory.create(channelEnum);
|
||||
// 校验
|
||||
receiverStrategy.setAllocationReceiver(receiver);
|
||||
if (!receiverStrategy.validation()){
|
||||
throw new PayFailureException("接收方信息校验失败");
|
||||
}
|
||||
LockInfo lock = lockTemplate.lock("payment:receiver:" + param.getReceiverNo(),10000,200);
|
||||
try {
|
||||
// 先添加到三方支付系统中, 然后保存到本地
|
||||
receiverStrategy.doBeforeHandler();
|
||||
receiverStrategy.bind();
|
||||
manager.save(receiver);
|
||||
} finally {
|
||||
lockTemplate.releaseLock(lock);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,10 +7,11 @@ 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;
|
||||
import cn.daxpay.single.param.payment.allocation.AllocationFinishParam;
|
||||
import cn.daxpay.single.param.payment.allocation.AllocationStartParam;
|
||||
import cn.daxpay.single.param.payment.allocation.AllocationSyncParam;
|
||||
import cn.daxpay.single.param.payment.allocation.AllocFinishParam;
|
||||
import cn.daxpay.single.param.payment.allocation.AllocStartParam;
|
||||
import cn.daxpay.single.param.payment.allocation.AllocSyncParam;
|
||||
import cn.daxpay.single.result.allocation.AllocationResult;
|
||||
import cn.daxpay.single.result.allocation.AllocationSyncResult;
|
||||
import cn.daxpay.single.service.common.local.PaymentContextLocal;
|
||||
import cn.daxpay.single.service.core.order.allocation.dao.AllocationOrderDetailManager;
|
||||
import cn.daxpay.single.service.core.order.allocation.dao.AllocationOrderManager;
|
||||
@@ -65,7 +66,7 @@ public class AllocationService {
|
||||
/**
|
||||
* 开启分账, 使用分账组进行分账
|
||||
*/
|
||||
public AllocationResult allocation(AllocationStartParam param) {
|
||||
public AllocationResult allocation(AllocStartParam param) {
|
||||
// 判断是否已经有分账订单
|
||||
AllocationOrder allocationOrder = allocationOrderManager.findByBizAllocationNo(param.getBizAllocationNo())
|
||||
.orElse(null);
|
||||
@@ -83,7 +84,7 @@ public class AllocationService {
|
||||
/**
|
||||
* 开启分账, 未传输分账组号, 则使用默认该通道默认分账组
|
||||
*/
|
||||
public AllocationResult allocation(AllocationStartParam param,PayOrder payOrder) {
|
||||
public AllocationResult allocation(AllocStartParam param, PayOrder payOrder) {
|
||||
LockInfo lock = lockTemplate.lock("payment:allocation:" + payOrder.getId(),10000,200);
|
||||
if (Objects.isNull(lock)){
|
||||
throw new RepetitiveOperationException("分账发起处理中,请勿重复操作");
|
||||
@@ -183,7 +184,7 @@ public class AllocationService {
|
||||
/**
|
||||
* 分账完结
|
||||
*/
|
||||
public void finish(AllocationFinishParam param) {
|
||||
public AllocationResult finish(AllocFinishParam param) {
|
||||
AllocationOrder allocationOrder;
|
||||
if (Objects.nonNull(param.getAllocationNo())){
|
||||
allocationOrder = allocationOrderManager.findByAllocationNo(param.getAllocationNo())
|
||||
@@ -192,13 +193,13 @@ public class AllocationService {
|
||||
allocationOrder = allocationOrderManager.findByBizAllocationNo(param.getBizAllocationNo())
|
||||
.orElseThrow(() -> new DataNotExistException("未查询到分账单信息"));
|
||||
}
|
||||
this.finish(allocationOrder);
|
||||
return this.finish(allocationOrder);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分账完结
|
||||
*/
|
||||
public void finish(AllocationOrder allocationOrder) {
|
||||
public AllocationResult finish(AllocationOrder allocationOrder) {
|
||||
// 只有分账结束后才可以完结
|
||||
if (!AllocOrderStatusEnum.ALLOCATION_END.getCode().equals(allocationOrder.getStatus())){
|
||||
throw new PayFailureException("分账单状态错误");
|
||||
@@ -224,13 +225,16 @@ public class AllocationService {
|
||||
.setErrorMsg(e.getMessage());
|
||||
}
|
||||
allocationOrderManager.updateById(allocationOrder);
|
||||
return new AllocationResult()
|
||||
.setAllocationNo(allocationOrder.getAllocationNo())
|
||||
.setStatus(allocationOrder.getStatus());
|
||||
}
|
||||
|
||||
/**
|
||||
* 分账同步, 开启一个新的事务, 不受外部抛出异常的影响
|
||||
*/
|
||||
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
|
||||
public void sync(AllocationSyncParam param) {
|
||||
public AllocationSyncResult sync(AllocSyncParam param) {
|
||||
// 获取分账订单
|
||||
AllocationOrder allocationOrder = null;
|
||||
if (Objects.nonNull(param.getAllocationNo())){
|
||||
@@ -242,6 +246,7 @@ public class AllocationService {
|
||||
.orElseThrow(() -> new DataNotExistException("分账单不存在"));
|
||||
}
|
||||
this.sync(allocationOrder);
|
||||
return new AllocationSyncResult();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -315,7 +320,7 @@ public class AllocationService {
|
||||
/**
|
||||
* 获取并检查支付订单
|
||||
*/
|
||||
private PayOrder getAndCheckPayOrder(AllocationStartParam param) {
|
||||
private PayOrder getAndCheckPayOrder(AllocStartParam param) {
|
||||
// 查询支付单
|
||||
PayOrder payOrder = payOrderQueryService.findByBizOrOrderNo(param.getOrderNo(), param.getBizOrderNo())
|
||||
.orElseThrow(() -> new DataNotExistException("支付单不存在"));
|
||||
@@ -329,4 +334,13 @@ public class AllocationService {
|
||||
}
|
||||
return payOrder;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询分账结果
|
||||
*/
|
||||
public void query(AllocFinishParam param) {
|
||||
// 查询分账单
|
||||
|
||||
// 查询分账单明细
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package cn.daxpay.single.service.param.allocation.group;
|
||||
package cn.daxpay.single.service.param.allocation.receiver;
|
||||
|
||||
import cn.daxpay.single.code.AllocReceiverTypeEnum;
|
||||
import cn.daxpay.single.code.AllocRelationTypeEnum;
|
||||
@@ -1,4 +1,4 @@
|
||||
package cn.daxpay.single.service.param.allocation.group;
|
||||
package cn.daxpay.single.service.param.allocation.receiver;
|
||||
|
||||
import cn.bootx.platform.common.core.annotation.QueryParam;
|
||||
import cn.daxpay.single.code.AllocRelationTypeEnum;
|
||||
@@ -1,6 +1,6 @@
|
||||
package cn.daxpay.single.service.task;
|
||||
|
||||
import cn.daxpay.single.param.payment.allocation.AllocationStartParam;
|
||||
import cn.daxpay.single.param.payment.allocation.AllocStartParam;
|
||||
import cn.daxpay.single.service.core.order.pay.dao.PayOrderManager;
|
||||
import cn.daxpay.single.service.core.order.pay.entity.PayOrder;
|
||||
import cn.daxpay.single.service.core.payment.allocation.service.AllocationService;
|
||||
@@ -27,7 +27,7 @@ public class AllocationAutoStartTask implements Job {
|
||||
@Override
|
||||
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
|
||||
for (PayOrder payOrder : payOrderManager.findAutoAllocation()) {
|
||||
AllocationStartParam param = new AllocationStartParam();
|
||||
AllocStartParam param = new AllocStartParam();
|
||||
param.setBizAllocationNo(OrderNoGenerateUtil.allocation());
|
||||
try {
|
||||
allocationService.allocation(param, payOrder);
|
||||
|
||||
Reference in New Issue
Block a user