diff --git a/_doc/Task.md b/_doc/Task.md index c8125a26c..a482ece95 100644 --- a/_doc/Task.md +++ b/_doc/Task.md @@ -2,7 +2,7 @@ 2.0.7: 分账完善和基础架构优化 - [x] 新增资金流水 - [x] 增加对超时订单进行处理(数据库同步) -- [ ] 支持分账组分账和自己传接收方进行分账 +- [x] 支持分账组分账和自己传接收方进行分账 - [ ] 分账组管理提供接口调用 - [ ] 添加分账接收方 - [ ] 查询分账接收方 @@ -23,9 +23,10 @@ - [ ] 下载系统账单 - [ ] 增加资金对账单功能 - [ ] 支付通道两个独立的配置进行合并为一个 - +- [ ] 撤销接口 2.1.x 版本内容 -- [ ] 对账回退及退款 +- [ ] 差错单据处理 +- [ ] 特殊退款接口 - [ ] 统计报表功能 - [ ] 微信新增V3版本接口 - [ ] 支付宝新增V3版本接口 diff --git a/daxpay-single/daxpay-single-admin/src/main/java/cn/daxpay/single/admin/controller/allocation/AllocationOrderController.java b/daxpay-single/daxpay-single-admin/src/main/java/cn/daxpay/single/admin/controller/allocation/AllocationOrderController.java index 3a86f3bc1..2754c20d3 100644 --- a/daxpay-single/daxpay-single-admin/src/main/java/cn/daxpay/single/admin/controller/allocation/AllocationOrderController.java +++ b/daxpay-single/daxpay-single-admin/src/main/java/cn/daxpay/single/admin/controller/allocation/AllocationOrderController.java @@ -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 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 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 retryAllocation(String bizAllocationNo){ - AllocationStartParam param = new AllocationStartParam(); + AllocStartParam param = new AllocStartParam(); param.setBizAllocationNo(bizAllocationNo); allocationService.allocation(param); return Res.ok(); diff --git a/daxpay-single/daxpay-single-admin/src/main/java/cn/daxpay/single/admin/controller/allocation/AllocationReceiverController.java b/daxpay-single/daxpay-single-admin/src/main/java/cn/daxpay/single/admin/controller/allocation/AllocationReceiverController.java index cd3be8bd7..a6a1f063f 100644 --- a/daxpay-single/daxpay-single-admin/src/main/java/cn/daxpay/single/admin/controller/allocation/AllocationReceiverController.java +++ b/daxpay-single/daxpay-single-admin/src/main/java/cn/daxpay/single/admin/controller/allocation/AllocationReceiverController.java @@ -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; diff --git a/daxpay-single/daxpay-single-admin/src/main/java/cn/daxpay/single/admin/controller/order/PayOrderController.java b/daxpay-single/daxpay-single-admin/src/main/java/cn/daxpay/single/admin/controller/order/PayOrderController.java index 2732ceaa1..99d6444cb 100644 --- a/daxpay-single/daxpay-single-admin/src/main/java/cn/daxpay/single/admin/controller/order/PayOrderController.java +++ b/daxpay-single/daxpay-single-admin/src/main/java/cn/daxpay/single/admin/controller/order/PayOrderController.java @@ -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 allocation(String orderNo){ - AllocationStartParam param = new AllocationStartParam(); + AllocStartParam param = new AllocStartParam(); param.setOrderNo(orderNo); param.setBizAllocationNo(OrderNoGenerateUtil.allocation()); allocationService.allocation(param); diff --git a/daxpay-single/daxpay-single-core/src/main/java/cn/daxpay/single/param/payment/allocation/AllocationFinishParam.java b/daxpay-single/daxpay-single-core/src/main/java/cn/daxpay/single/param/payment/allocation/AllocFinishParam.java similarity index 88% rename from daxpay-single/daxpay-single-core/src/main/java/cn/daxpay/single/param/payment/allocation/AllocationFinishParam.java rename to daxpay-single/daxpay-single-core/src/main/java/cn/daxpay/single/param/payment/allocation/AllocFinishParam.java index aae37d27d..57b9bfe26 100644 --- a/daxpay-single/daxpay-single-core/src/main/java/cn/daxpay/single/param/payment/allocation/AllocationFinishParam.java +++ b/daxpay-single/daxpay-single-core/src/main/java/cn/daxpay/single/param/payment/allocation/AllocFinishParam.java @@ -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; diff --git a/daxpay-single/daxpay-single-core/src/main/java/cn/daxpay/single/param/payment/allocation/AllocReceiverAddParam.java b/daxpay-single/daxpay-single-core/src/main/java/cn/daxpay/single/param/payment/allocation/AllocReceiverAddParam.java new file mode 100644 index 000000000..99ef33aa2 --- /dev/null +++ b/daxpay-single/daxpay-single-core/src/main/java/cn/daxpay/single/param/payment/allocation/AllocReceiverAddParam.java @@ -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; +} diff --git a/daxpay-single/daxpay-single-core/src/main/java/cn/daxpay/single/param/payment/allocation/AllocReceiverRemoveParam.java b/daxpay-single/daxpay-single-core/src/main/java/cn/daxpay/single/param/payment/allocation/AllocReceiverRemoveParam.java new file mode 100644 index 000000000..d6c41b6d0 --- /dev/null +++ b/daxpay-single/daxpay-single-core/src/main/java/cn/daxpay/single/param/payment/allocation/AllocReceiverRemoveParam.java @@ -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; + +} diff --git a/daxpay-single/daxpay-single-core/src/main/java/cn/daxpay/single/param/payment/allocation/AllocationStartParam.java b/daxpay-single/daxpay-single-core/src/main/java/cn/daxpay/single/param/payment/allocation/AllocStartParam.java similarity index 93% rename from daxpay-single/daxpay-single-core/src/main/java/cn/daxpay/single/param/payment/allocation/AllocationStartParam.java rename to daxpay-single/daxpay-single-core/src/main/java/cn/daxpay/single/param/payment/allocation/AllocStartParam.java index 3cf5e8eae..7859d241a 100644 --- a/daxpay-single/daxpay-single-core/src/main/java/cn/daxpay/single/param/payment/allocation/AllocationStartParam.java +++ b/daxpay-single/daxpay-single-core/src/main/java/cn/daxpay/single/param/payment/allocation/AllocStartParam.java @@ -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 = "商户分账单号") diff --git a/daxpay-single/daxpay-single-core/src/main/java/cn/daxpay/single/param/payment/allocation/AllocationSyncParam.java b/daxpay-single/daxpay-single-core/src/main/java/cn/daxpay/single/param/payment/allocation/AllocSyncParam.java similarity index 91% rename from daxpay-single/daxpay-single-core/src/main/java/cn/daxpay/single/param/payment/allocation/AllocationSyncParam.java rename to daxpay-single/daxpay-single-core/src/main/java/cn/daxpay/single/param/payment/allocation/AllocSyncParam.java index 61e598d9b..2d53f3108 100644 --- a/daxpay-single/daxpay-single-core/src/main/java/cn/daxpay/single/param/payment/allocation/AllocationSyncParam.java +++ b/daxpay-single/daxpay-single-core/src/main/java/cn/daxpay/single/param/payment/allocation/AllocSyncParam.java @@ -10,7 +10,7 @@ import lombok.Data; */ @Data @Schema(title = "分账同步请求参数") -public class AllocationSyncParam { +public class AllocSyncParam { @Schema(description = "分账号") private String allocationNo; diff --git a/daxpay-single/daxpay-single-core/src/main/java/cn/daxpay/single/param/payment/allocation/QueryAllocReceiverParam.java b/daxpay-single/daxpay-single-core/src/main/java/cn/daxpay/single/param/payment/allocation/QueryAllocReceiverParam.java new file mode 100644 index 000000000..b096e833b --- /dev/null +++ b/daxpay-single/daxpay-single-core/src/main/java/cn/daxpay/single/param/payment/allocation/QueryAllocReceiverParam.java @@ -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 { +} diff --git a/daxpay-single/daxpay-single-core/src/main/java/cn/daxpay/single/result/allocation/AllocationSyncResult.java b/daxpay-single/daxpay-single-core/src/main/java/cn/daxpay/single/result/allocation/AllocationSyncResult.java new file mode 100644 index 000000000..621ca9bc8 --- /dev/null +++ b/daxpay-single/daxpay-single-core/src/main/java/cn/daxpay/single/result/allocation/AllocationSyncResult.java @@ -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 { +} diff --git a/daxpay-single/daxpay-single-gateway/src/main/java/cn/daxpay/single/gateway/controller/UniAllocationController.java b/daxpay-single/daxpay-single-gateway/src/main/java/cn/daxpay/single/gateway/controller/UniAllocationController.java index 0a5e0e413..477482e7e 100644 --- a/daxpay-single/daxpay-single-gateway/src/main/java/cn/daxpay/single/gateway/controller/UniAllocationController.java +++ b/daxpay-single/daxpay-single-gateway/src/main/java/cn/daxpay/single/gateway/controller/UniAllocationController.java @@ -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 open(@RequestBody AllocationStartParam param){ + public DaxResult open(@RequestBody AllocStartParam param){ return DaxRes.ok(allocationService.allocation(param)); } @PaymentApi(PaymentApiCode.ALLOCATION_FINISH) @Operation(summary = "分账完结接口") @PostMapping("/finish") - public DaxResult finish(@RequestBody AllocationFinishParam param){ - allocationService.finish(param); - return DaxRes.ok(); + public DaxResult finish(@RequestBody AllocFinishParam param){ + return DaxRes.ok(allocationService.finish(param)); } @PaymentApi(PaymentApiCode.SYNC_ALLOCATION) @Operation(summary = "分账同步接口") @PostMapping("/sync") - public DaxResult sync(@RequestBody AllocationSyncParam param){ - allocationService.sync(param); - return DaxRes.ok(); + public DaxResult sync(@RequestBody AllocSyncParam param){ + return DaxRes.ok(allocationService.sync(param)); } @PaymentApi(PaymentApiCode.QUERY_ALLOCATION_ORDER) @Operation(summary = "分账查询接口") @PostMapping("/query") - public DaxResult query(@RequestBody AllocationFinishParam param){ -// allocationService.query(param); + public DaxResult query(@RequestBody AllocFinishParam param){ + allocationService.query(param); return DaxRes.ok(); } - - @PaymentApi(PaymentApiCode.ALLOCATION_RECEIVER_ADD) @Operation(summary = "添加分账接收方接口") @PostMapping("/receiver/add") - public DaxResult receiverAdd(@RequestBody AllocationReceiverParam param){ + public DaxResult receiverAdd(@RequestBody AllocReceiverAddParam param){ + receiverService.addAndSync(param); return DaxRes.ok(); } @PaymentApi(PaymentApiCode.ALLOCATION_RECEIVER_REMOVE) @Operation(summary = "删除分账接收方接口") @PostMapping("/receiver/remove") - public DaxResult receiverRemove(@RequestBody AllocationReceiverParam param){ + public DaxResult receiverRemove(@RequestBody AllocReceiverRemoveParam param){ return DaxRes.ok(); } @PaymentApi(PaymentApiCode.ALLOCATION_RECEIVER_QUERY) @Operation(summary = "查询分账接收方接口") @PostMapping("/receiver/query") - public DaxResult receiveQuery(@RequestBody AllocationReceiverParam param){ + public DaxResult receiveQuery(@RequestBody QueryAllocReceiverParam param){ return DaxRes.ok(); } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/order/allocation/service/AllocationOrderService.java b/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/order/allocation/service/AllocationOrderService.java index dee6b9c19..24446bd8d 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/order/allocation/service/AllocationOrderService.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/order/allocation/service/AllocationOrderService.java @@ -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 receiversByGroups){ + public OrderAndDetail createAndUpdate(AllocStartParam param, PayOrder payOrder, int orderAmount, List receiversByGroups){ long orderId = IdUtil.getSnowflakeNextId(); // 订单明细 diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/payment/allocation/convert/AllocationReceiverConvert.java b/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/payment/allocation/convert/AllocationReceiverConvert.java index ef7606401..8e4c19a20 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/payment/allocation/convert/AllocationReceiverConvert.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/payment/allocation/convert/AllocationReceiverConvert.java @@ -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); } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/payment/allocation/dao/AllocationGroupReceiverManager.java b/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/payment/allocation/dao/AllocationGroupReceiverManager.java index 56488d844..2d2d03056 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/payment/allocation/dao/AllocationGroupReceiverManager.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/payment/allocation/dao/AllocationGroupReceiverManager.java @@ -38,4 +38,9 @@ public class AllocationGroupReceiverManager extends BaseManager { + /** 分账接收方编号, 需要保证唯一 */ + @DbColumn(comment = "分账接收方编号") + private String receiverNo; + @DbColumn(comment = "账号别名") private String name; diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/payment/allocation/service/AllocationReceiverService.java b/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/payment/allocation/service/AllocationReceiverService.java index 067db2eda..9f71719cb 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/payment/allocation/service/AllocationReceiverService.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/payment/allocation/service/AllocationReceiverService.java @@ -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); + } } /** diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/payment/allocation/service/AllocationService.java b/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/payment/allocation/service/AllocationService.java index 332d804ab..bc74e63e2 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/payment/allocation/service/AllocationService.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/payment/allocation/service/AllocationService.java @@ -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) { + // 查询分账单 + + // 查询分账单明细 + } } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/param/allocation/group/AllocationReceiverParam.java b/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/param/allocation/receiver/AllocationReceiverParam.java similarity index 95% rename from daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/param/allocation/group/AllocationReceiverParam.java rename to daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/param/allocation/receiver/AllocationReceiverParam.java index 19474847b..bdba6a630 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/param/allocation/group/AllocationReceiverParam.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/param/allocation/receiver/AllocationReceiverParam.java @@ -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; diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/param/allocation/group/AllocationReceiverQuery.java b/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/param/allocation/receiver/AllocationReceiverQuery.java similarity index 95% rename from daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/param/allocation/group/AllocationReceiverQuery.java rename to daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/param/allocation/receiver/AllocationReceiverQuery.java index 48814ef95..f6e8f7432 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/param/allocation/group/AllocationReceiverQuery.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/param/allocation/receiver/AllocationReceiverQuery.java @@ -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; diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/task/AllocationAutoStartTask.java b/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/task/AllocationAutoStartTask.java index eaa6e5127..9ac31aaea 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/task/AllocationAutoStartTask.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/task/AllocationAutoStartTask.java @@ -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);