diff --git a/README.md b/README.md index 00833f26b..e94c2f586 100644 --- a/README.md +++ b/README.md @@ -196,6 +196,9 @@ QQ扫码加入QQ交流群 微信图片_20240226144703

+## Star History + +[![Stargazers over time](https://starchart.cc/dromara/dax-pay.svg?variant=adaptive)](https://starchart.cc/dromara/dax-pay) ## 🍻 鸣谢 diff --git a/daxpay-single/daxpay-single-admin/src/main/java/cn/bootx/platform/daxpay/admin/controller/allocation/AllocationOrderController.java b/daxpay-single/daxpay-single-admin/src/main/java/cn/bootx/platform/daxpay/admin/controller/allocation/AllocationOrderController.java index b66532511..391f94fe2 100644 --- a/daxpay-single/daxpay-single-admin/src/main/java/cn/bootx/platform/daxpay/admin/controller/allocation/AllocationOrderController.java +++ b/daxpay-single/daxpay-single-admin/src/main/java/cn/bootx/platform/daxpay/admin/controller/allocation/AllocationOrderController.java @@ -5,8 +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.bootx.platform.daxpay.param.pay.AllocationSyncParam; import cn.bootx.platform.daxpay.service.core.order.allocation.service.AllocationOrderService; -import cn.bootx.platform.daxpay.service.core.payment.allocation.service.AllocationService; +import cn.bootx.platform.daxpay.service.core.payment.allocation.service.AllocationSyncService; import cn.bootx.platform.daxpay.service.dto.order.allocation.AllocationOrderDetailDto; import cn.bootx.platform.daxpay.service.dto.order.allocation.AllocationOrderDto; import cn.bootx.platform.daxpay.service.param.order.AllocationOrderQuery; @@ -14,6 +15,7 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -32,7 +34,7 @@ public class AllocationOrderController { private final AllocationOrderService allocationOrderService; - private final AllocationService allocationService; + private final AllocationSyncService allocationSyncService; @Operation(summary = "分页") @GetMapping("/page") @@ -65,4 +67,12 @@ public class AllocationOrderController { return Res.ok(allocationOrderService.findChannels()); } + @Operation(summary = "同步分账结果") + @PostMapping("/sync") + public ResResult sync(Long id){ + AllocationSyncParam param = new AllocationSyncParam(); + param.setAllocationId(id); + allocationSyncService.sync(param); + return Res.ok(); + } } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/code/AllocationStatusEnum.java b/daxpay-single/daxpay-single-core/src/main/java/cn/bootx/platform/daxpay/code/AllocationStatusEnum.java similarity index 93% rename from daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/code/AllocationStatusEnum.java rename to daxpay-single/daxpay-single-core/src/main/java/cn/bootx/platform/daxpay/code/AllocationStatusEnum.java index d35d00539..acb85e317 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/code/AllocationStatusEnum.java +++ b/daxpay-single/daxpay-single-core/src/main/java/cn/bootx/platform/daxpay/code/AllocationStatusEnum.java @@ -1,4 +1,4 @@ -package cn.bootx.platform.daxpay.service.code; +package cn.bootx.platform.daxpay.code; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/daxpay-single/daxpay-single-core/src/main/java/cn/bootx/platform/daxpay/param/pay/AllocationSyncParam.java b/daxpay-single/daxpay-single-core/src/main/java/cn/bootx/platform/daxpay/param/pay/AllocationSyncParam.java new file mode 100644 index 000000000..b49314d21 --- /dev/null +++ b/daxpay-single/daxpay-single-core/src/main/java/cn/bootx/platform/daxpay/param/pay/AllocationSyncParam.java @@ -0,0 +1,20 @@ +package cn.bootx.platform.daxpay.param.pay; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +/** + * 分账同步请求参数 + * @author xxm + * @since 2024/4/12 + */ +@Data +@Schema(title = "分账同步请求参数") +public class AllocationSyncParam { + + @Schema(description = "分账单ID") + private Long allocationId; + + @Schema(description = "分账单号") + private String allocationNo; +} diff --git a/daxpay-single/daxpay-single-core/src/main/java/cn/bootx/platform/daxpay/result/pay/RefundSyncResult.java b/daxpay-single/daxpay-single-core/src/main/java/cn/bootx/platform/daxpay/result/pay/RefundSyncResult.java deleted file mode 100644 index dbafb5c86..000000000 --- a/daxpay-single/daxpay-single-core/src/main/java/cn/bootx/platform/daxpay/result/pay/RefundSyncResult.java +++ /dev/null @@ -1,28 +0,0 @@ -package cn.bootx.platform.daxpay.result.pay; - -import cn.bootx.platform.daxpay.result.CommonResult; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.experimental.Accessors; - -/** - * 退款同步结果 - * @author xxm - * @since 2024/1/29 - */ -@EqualsAndHashCode(callSuper = true) -@Data -@Accessors(chain = true) -@Schema(title = "退款同步结果") -public class RefundSyncResult extends CommonResult { - - @Schema(description = "是否进行了修复") - private boolean repair; - - @Schema(description = "支付单修复ID") - private Long repairId; - - @Schema(description = "失败原因") - private String errorMsg; -} diff --git a/daxpay-single/daxpay-single-core/src/main/java/cn/bootx/platform/daxpay/result/pay/SyncResult.java b/daxpay-single/daxpay-single-core/src/main/java/cn/bootx/platform/daxpay/result/pay/SyncResult.java index 115064b1f..8dc8a3431 100644 --- a/daxpay-single/daxpay-single-core/src/main/java/cn/bootx/platform/daxpay/result/pay/SyncResult.java +++ b/daxpay-single/daxpay-single-core/src/main/java/cn/bootx/platform/daxpay/result/pay/SyncResult.java @@ -1,5 +1,6 @@ package cn.bootx.platform.daxpay.result.pay; +import cn.bootx.platform.daxpay.code.AllocationStatusEnum; import cn.bootx.platform.daxpay.code.RefundSyncStatusEnum; import cn.bootx.platform.daxpay.code.PaySyncStatusEnum; import cn.bootx.platform.daxpay.result.CommonResult; @@ -11,7 +12,7 @@ import lombok.experimental.Accessors; import static cn.bootx.platform.daxpay.code.PaySyncStatusEnum.FAIL; /** - * 支付单同步结果 + * 各种单据同步结果 * @author xxm * @since 2023/12/27 */ @@ -25,6 +26,7 @@ public class SyncResult extends CommonResult { * 支付网关同步状态 * @see PaySyncStatusEnum * @see RefundSyncStatusEnum + * @see AllocationStatusEnum */ @Schema(description = "支付网关同步状态") private String gatewayStatus = FAIL.getCode(); diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/alipay/service/AliPayAllocationService.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/alipay/service/AliPayAllocationService.java index 0ac092282..5c37c0569 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/alipay/service/AliPayAllocationService.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/alipay/service/AliPayAllocationService.java @@ -82,7 +82,7 @@ public class AliPayAllocationService { * 分账状态查询 */ @SneakyThrows - public void query(AllocationOrder allocationOrder){ + public void queryStatus(AllocationOrder allocationOrder){ AlipayTradeOrderSettleQueryModel model = new AlipayTradeOrderSettleQueryModel(); model.setTradeNo(allocationOrder.getGatewayPayOrderNo()); model.setOutRequestNo(allocationOrder.getOrderNo()); @@ -95,6 +95,13 @@ public class AliPayAllocationService { System.out.println(royaltyDetailList); } + /** + * 分账剩余金额查询 + */ + public void queryAmount(AllocationOrder allocationOrder){ + + } + /** * 验证错误信息 */ diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/wechat/service/WeChatPayAllocationService.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/wechat/service/WeChatPayAllocationService.java index 88b5a21bf..6a63defd9 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/wechat/service/WeChatPayAllocationService.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/wechat/service/WeChatPayAllocationService.java @@ -92,6 +92,24 @@ public class WeChatPayAllocationService { this.verifyErrorMsg(result); } + /** + * 查询分账状态 + */ + public void queryStatus(AllocationOrder allocationOrder, WeChatPayConfig config){ + Map params = ProfitSharingModel.builder() + .mch_id(config.getWxMchId()) + .appid(config.getWxAppId()) + .nonce_str(WxPayKit.generateStr()) + .transaction_id(allocationOrder.getGatewayPayOrderNo()) + .out_order_no(allocationOrder.getOrderNo()) + .build() + .createSign(config.getApiKeyV2(), SignType.HMACSHA256); + String xmlResult = WxPayApi.profitSharingQuery(params); + Map result = WxPayKit.xmlToMap(xmlResult); + this.verifyErrorMsg(result); + } + + /** * 验证错误信息 */ diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/order/allocation/entity/AllocationOrder.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/order/allocation/entity/AllocationOrder.java index 032d1cad9..abbebefc5 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/order/allocation/entity/AllocationOrder.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/order/allocation/entity/AllocationOrder.java @@ -2,8 +2,8 @@ package cn.bootx.platform.daxpay.service.core.order.allocation.entity; import cn.bootx.platform.common.core.function.EntityBaseFunction; import cn.bootx.platform.common.mybatisplus.base.MpBaseEntity; +import cn.bootx.platform.daxpay.code.AllocationStatusEnum; import cn.bootx.platform.daxpay.code.PayChannelEnum; -import cn.bootx.platform.daxpay.service.code.AllocationStatusEnum; import cn.bootx.platform.daxpay.service.core.order.allocation.convert.AllocationConvert; import cn.bootx.platform.daxpay.service.dto.order.allocation.AllocationOrderDto; import cn.bootx.table.modify.annotation.DbColumn; @@ -33,11 +33,19 @@ import java.time.LocalDateTime; public class AllocationOrder extends MpBaseEntity implements EntityBaseFunction { /** - * 分账订单号 + * 分账订单号(传输给三方支付系统做关联) */ @DbColumn(comment = "分账订单号") private String orderNo; + /** + * 分账单号 + */ + @DbMySqlIndex(comment = "分账单号索引", type = MySqlIndexType.UNIQUE) + @DbColumn(comment = "分账单号") + private String allocationNo; + + /** * 支付订单ID */ @@ -62,14 +70,6 @@ public class AllocationOrder extends MpBaseEntity implements EntityBaseFunction< @DbColumn(comment = "网关分账单号") private String gatewayAllocationNo; - /** - * 分账单号 - */ - @DbMySqlIndex(comment = "分账单号索引", type = MySqlIndexType.UNIQUE) - @DbColumn(comment = "分账单号") - private String allocationNo; - - /** * 所属通道 * @see PayChannelEnum diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/order/allocation/service/AllocationOrderService.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/order/allocation/service/AllocationOrderService.java index 32d1b8245..c4bd59d1b 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/order/allocation/service/AllocationOrderService.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/order/allocation/service/AllocationOrderService.java @@ -8,7 +8,7 @@ import cn.bootx.platform.common.core.util.ResultConvertUtil; import cn.bootx.platform.common.mybatisplus.util.MpUtil; import cn.bootx.platform.daxpay.code.PayChannelEnum; import cn.bootx.platform.daxpay.param.pay.allocation.AllocationStartParam; -import cn.bootx.platform.daxpay.service.code.AllocationStatusEnum; +import cn.bootx.platform.daxpay.code.AllocationStatusEnum; import cn.bootx.platform.daxpay.service.core.order.allocation.dao.AllocationOrderDetailManager; import cn.bootx.platform.daxpay.service.core.order.allocation.dao.AllocationOrderManager; import cn.bootx.platform.daxpay.service.core.order.allocation.entity.AllocationOrder; diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/order/pay/entity/PayOrder.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/order/pay/entity/PayOrder.java index 295d61bb2..658ebfed3 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/order/pay/entity/PayOrder.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/order/pay/entity/PayOrder.java @@ -4,7 +4,7 @@ import cn.bootx.platform.common.core.function.EntityBaseFunction; import cn.bootx.platform.common.mybatisplus.base.MpBaseEntity; import cn.bootx.platform.daxpay.code.PayChannelEnum; import cn.bootx.platform.daxpay.code.PayStatusEnum; -import cn.bootx.platform.daxpay.service.code.AllocationStatusEnum; +import cn.bootx.platform.daxpay.code.AllocationStatusEnum; import cn.bootx.platform.daxpay.service.core.order.pay.convert.PayOrderConvert; import cn.bootx.platform.daxpay.service.dto.order.pay.PayOrderDto; import cn.bootx.table.modify.annotation.DbColumn; diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/allocation/factory/AllocationSyncFactory.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/allocation/factory/AllocationSyncFactory.java new file mode 100644 index 000000000..7280c257b --- /dev/null +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/allocation/factory/AllocationSyncFactory.java @@ -0,0 +1,39 @@ +package cn.bootx.platform.daxpay.service.core.payment.allocation.factory; + +import cn.bootx.platform.daxpay.code.PayChannelEnum; +import cn.bootx.platform.daxpay.exception.pay.PayUnsupportedMethodException; +import cn.bootx.platform.daxpay.service.core.payment.sync.strategy.allocation.AliPayAllocationSyncStrategy; +import cn.bootx.platform.daxpay.service.core.payment.sync.strategy.allocation.WechatPayAllocationSyncStrategy; +import cn.bootx.platform.daxpay.service.func.AbsAllocationSyncStrategy; +import cn.hutool.extra.spring.SpringUtil; +import lombok.experimental.UtilityClass; + +/** + * 分账同步策略工厂 + * @author xxm + * @since 2024/4/12 + */ +@UtilityClass +public class AllocationSyncFactory { + + /** + * 根据传入的支付通道创建策略 + * @return 支付策略 + */ + public static AbsAllocationSyncStrategy create(String channel) { + PayChannelEnum channelEnum = PayChannelEnum.findByCode(channel); + + AbsAllocationSyncStrategy strategy; + switch (channelEnum) { + case ALI: + strategy = SpringUtil.getBean(AliPayAllocationSyncStrategy.class); + break; + case WECHAT: + strategy = SpringUtil.getBean(WechatPayAllocationSyncStrategy.class); + break; + default: + throw new PayUnsupportedMethodException(); + } + return strategy; + } +} diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/allocation/service/AllocationService.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/allocation/service/AllocationService.java index eb8ff7166..37503ad2d 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/allocation/service/AllocationService.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/allocation/service/AllocationService.java @@ -5,7 +5,7 @@ import cn.bootx.platform.daxpay.exception.pay.PayFailureException; import cn.bootx.platform.daxpay.param.pay.allocation.AllocationFinishParam; import cn.bootx.platform.daxpay.param.pay.allocation.AllocationStartParam; import cn.bootx.platform.daxpay.result.allocation.AllocationResult; -import cn.bootx.platform.daxpay.service.code.AllocationStatusEnum; +import cn.bootx.platform.daxpay.code.AllocationStatusEnum; import cn.bootx.platform.daxpay.service.core.order.allocation.dao.AllocationOrderManager; import cn.bootx.platform.daxpay.service.core.order.allocation.entity.AllocationOrder; import cn.bootx.platform.daxpay.service.core.order.allocation.entity.AllocationOrderDetail; diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/allocation/service/AllocationSyncService.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/allocation/service/AllocationSyncService.java new file mode 100644 index 000000000..64c47a85b --- /dev/null +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/allocation/service/AllocationSyncService.java @@ -0,0 +1,50 @@ +package cn.bootx.platform.daxpay.service.core.payment.allocation.service; + +import cn.bootx.platform.common.core.exception.DataNotExistException; +import cn.bootx.platform.daxpay.param.pay.AllocationSyncParam; +import cn.bootx.platform.daxpay.result.pay.SyncResult; +import cn.bootx.platform.daxpay.service.core.order.allocation.dao.AllocationOrderManager; +import cn.bootx.platform.daxpay.service.core.order.allocation.entity.AllocationOrder; +import cn.bootx.platform.daxpay.service.core.payment.allocation.factory.AllocationSyncFactory; +import cn.bootx.platform.daxpay.service.func.AbsAllocationSyncStrategy; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Objects; + +/** + * 分账状态同步 + * @author xxm + * @since 2024/4/12 + */ +@Slf4j +@Service +@RequiredArgsConstructor +public class AllocationSyncService { + private final AllocationOrderManager allocationOrderManager; + + /** + * 支付同步, 开启一个新的事务, 不受外部抛出异常的影响 + */ + @Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class) + public SyncResult sync(AllocationSyncParam param) { + // 获取分账订单 + AllocationOrder allocationOrder = null; + if (Objects.nonNull(param.getAllocationId())){ + allocationOrder = allocationOrderManager.findById(param.getAllocationId()) + .orElseThrow(() -> new DataNotExistException("分账单不存在")); + } + if (Objects.isNull(allocationOrder)){ + allocationOrder = allocationOrderManager.findByAllocationNo(param.getAllocationNo()) + .orElseThrow(() -> new DataNotExistException("分账单不存在")); + } + // 获取分账策略 + AbsAllocationSyncStrategy allocationSyncStrategy = AllocationSyncFactory.create(allocationOrder.getChannel()); + allocationSyncStrategy.initPayParam(allocationOrder); + allocationSyncStrategy.doSyncStatus(); + return new SyncResult(); + } +} diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/allocation/strategy/allocation/WeChatPayAllocationStrategy.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/allocation/strategy/allocation/WeChatPayAllocationStrategy.java index 645843308..ebd649d79 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/allocation/strategy/allocation/WeChatPayAllocationStrategy.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/allocation/strategy/allocation/WeChatPayAllocationStrategy.java @@ -68,4 +68,5 @@ public class WeChatPayAllocationStrategy extends AbsAllocationStrategy { weChatPayAllocationService.finish(getAllocationOrder(), weChatPayConfig); } + } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/pay/service/PayService.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/pay/service/PayService.java index 7a675bf3e..369580435 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/pay/service/PayService.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/pay/service/PayService.java @@ -7,7 +7,7 @@ import cn.bootx.platform.daxpay.param.pay.PayChannelParam; import cn.bootx.platform.daxpay.param.pay.PayParam; import cn.bootx.platform.daxpay.param.pay.SimplePayParam; import cn.bootx.platform.daxpay.result.pay.PayResult; -import cn.bootx.platform.daxpay.service.code.AllocationStatusEnum; +import cn.bootx.platform.daxpay.code.AllocationStatusEnum; import cn.bootx.platform.daxpay.service.common.context.PayLocal; import cn.bootx.platform.daxpay.service.common.local.PaymentContextLocal; import cn.bootx.platform.daxpay.service.core.order.pay.builder.PayBuilder; diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/sync/strategy/allocation/AliPayAllocationSyncStrategy.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/sync/strategy/allocation/AliPayAllocationSyncStrategy.java new file mode 100644 index 000000000..7c3a5c0ed --- /dev/null +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/sync/strategy/allocation/AliPayAllocationSyncStrategy.java @@ -0,0 +1,44 @@ +package cn.bootx.platform.daxpay.service.core.payment.sync.strategy.allocation; + +import cn.bootx.platform.daxpay.code.PayChannelEnum; +import cn.bootx.platform.daxpay.service.core.channel.alipay.entity.AliPayConfig; +import cn.bootx.platform.daxpay.service.core.channel.alipay.service.AliPayAllocationService; +import cn.bootx.platform.daxpay.service.core.channel.alipay.service.AliPayConfigService; +import cn.bootx.platform.daxpay.service.func.AbsAllocationSyncStrategy; +import lombok.RequiredArgsConstructor; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import static org.springframework.beans.factory.config.BeanDefinition.SCOPE_PROTOTYPE; + +/** + * 支付宝分账状态同步策略 + * @author xxm + * @since 2024/4/12 + */ +@Scope(SCOPE_PROTOTYPE) +@Component +@RequiredArgsConstructor +public class AliPayAllocationSyncStrategy extends AbsAllocationSyncStrategy { + private final AliPayConfigService aliPayConfigService; + + private final AliPayAllocationService aliPayAllocationService; + /** + * 策略标识 + */ + @Override + public PayChannelEnum getChannel() { + return PayChannelEnum.ALI; + } + + /** + * 同步状态 + */ + @Override + public void doSyncStatus() { + AliPayConfig aliPayConfig = aliPayConfigService.getAndCheckConfig(); + aliPayConfigService.initConfig(aliPayConfig); + aliPayAllocationService.queryStatus(this.getAllocationOrder()); + } + +} diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/sync/strategy/allocation/WechatPayAllocationSyncStrategy.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/sync/strategy/allocation/WechatPayAllocationSyncStrategy.java new file mode 100644 index 000000000..cd4e8bb73 --- /dev/null +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/payment/sync/strategy/allocation/WechatPayAllocationSyncStrategy.java @@ -0,0 +1,45 @@ +package cn.bootx.platform.daxpay.service.core.payment.sync.strategy.allocation; + +import cn.bootx.platform.daxpay.code.PayChannelEnum; +import cn.bootx.platform.daxpay.service.core.channel.wechat.entity.WeChatPayConfig; +import cn.bootx.platform.daxpay.service.core.channel.wechat.service.WeChatPayAllocationService; +import cn.bootx.platform.daxpay.service.core.channel.wechat.service.WeChatPayConfigService; +import cn.bootx.platform.daxpay.service.func.AbsAllocationSyncStrategy; +import lombok.RequiredArgsConstructor; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +import static org.springframework.beans.factory.config.BeanDefinition.SCOPE_PROTOTYPE; + +/** + * 微信分账状态同步策略 + * @author xxm + * @since 2024/4/12 + */ +@Scope(SCOPE_PROTOTYPE) +@Component +@RequiredArgsConstructor +public class WechatPayAllocationSyncStrategy extends AbsAllocationSyncStrategy { + + private final WeChatPayAllocationService weChatPayAllocationService; + + private final WeChatPayConfigService weChatPayConfigService; + + + /** + * 同步状态 + */ + @Override + public void doSyncStatus() { + WeChatPayConfig wechatPayConfig = weChatPayConfigService.getAndCheckConfig(); + weChatPayAllocationService.queryStatus(this.getAllocationOrder(),wechatPayConfig); + } + + /** + * 策略标识 + */ + @Override + public PayChannelEnum getChannel() { + return PayChannelEnum.WECHAT; + } +} diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/dto/order/allocation/AllocationOrderDto.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/dto/order/allocation/AllocationOrderDto.java index 2e5595685..3d6bfcfc3 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/dto/order/allocation/AllocationOrderDto.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/dto/order/allocation/AllocationOrderDto.java @@ -1,6 +1,7 @@ package cn.bootx.platform.daxpay.service.dto.order.allocation; import cn.bootx.platform.common.core.rest.dto.BaseDto; +import cn.bootx.platform.daxpay.code.AllocationStatusEnum; import com.baomidou.mybatisplus.annotation.FieldStrategy; import com.baomidou.mybatisplus.annotation.TableField; import io.swagger.v3.oas.annotations.media.Schema; @@ -77,7 +78,7 @@ public class AllocationOrderDto extends BaseDto { /** * 状态 - * @see cn.bootx.platform.daxpay.service.code.AllocationStatusEnum + * @see AllocationStatusEnum */ @Schema(description = "状态") private String status; diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/dto/order/pay/PayOrderDto.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/dto/order/pay/PayOrderDto.java index a758a81d0..ea497acc8 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/dto/order/pay/PayOrderDto.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/dto/order/pay/PayOrderDto.java @@ -3,7 +3,7 @@ package cn.bootx.platform.daxpay.service.dto.order.pay; import cn.bootx.platform.common.core.rest.dto.BaseDto; import cn.bootx.platform.daxpay.code.PayChannelEnum; import cn.bootx.platform.daxpay.code.PayStatusEnum; -import cn.bootx.platform.daxpay.service.code.AllocationStatusEnum; +import cn.bootx.platform.daxpay.code.AllocationStatusEnum; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import lombok.EqualsAndHashCode; diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/func/AbsAllocationSyncStrategy.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/func/AbsAllocationSyncStrategy.java new file mode 100644 index 000000000..28fdc52ac --- /dev/null +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/func/AbsAllocationSyncStrategy.java @@ -0,0 +1,33 @@ +package cn.bootx.platform.daxpay.service.func; + +import cn.bootx.platform.daxpay.service.core.order.allocation.entity.AllocationOrder; +import lombok.Getter; +import lombok.Setter; +import lombok.extern.slf4j.Slf4j; + +/** + * 抽象的分账状态同步策略 + * @author xxm + * @since 2024/4/12 + */ +@Slf4j +@Getter +@Setter +public abstract class AbsAllocationSyncStrategy implements PayStrategy{ + + private AllocationOrder allocationOrder; + + /** + * 初始化参数 + */ + public void initPayParam(AllocationOrder allocationOrder) { + this.allocationOrder = allocationOrder; + } + + /** + * 同步状态 + */ + public abstract void doSyncStatus(); + + +}