From 73e43115ad778562fde78ea9ef345bffc1e206d8 Mon Sep 17 00:00:00 2001 From: DaxPay Date: Fri, 31 May 2024 17:45:39 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E5=90=84=E7=A7=8D=E5=88=86=E8=B4=A6?= =?UTF-8?q?=E5=90=84=E7=A7=8D=E9=97=AE=E9=A2=98=E8=A7=A3=E5=86=B3=E5=92=8C?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- _doc/ChangeLog.md | 4 + _doc/Task.md | 9 +- daxpay-single-demo/pom.xml | 2 +- daxpay-single-sdk/pom.xml | 2 +- daxpay-single-start/pom.xml | 2 +- .../src/main/resources/application-dev.yml | 2 +- .../src/main/resources/application-prod.yml | 2 +- daxpay-single/daxpay-single-admin/pom.xml | 2 +- .../allocation/AllocationOrderController.java | 2 +- daxpay-single/daxpay-single-core/pom.xml | 2 +- daxpay-single/daxpay-single-gateway/pom.xml | 2 +- .../PayNoticeReceiverController.java | 19 ++-- daxpay-single/daxpay-single-service/pom.xml | 2 +- .../single/service/code/AliPayCode.java | 4 +- .../service/AliPayAllocationService.java | 8 +- .../service/AliPayNoticeReceiverService.java | 95 +++++++++++++++++++ .../WeChatPayAllocationReceiverService.java | 3 +- .../service/WeChatPayAllocationService.java | 9 +- .../service/AllocationCallbackService.java | 24 +++++ .../allocation/service/AllocationService.java | 28 +++++- daxpay-single/pom.xml | 4 +- pom.xml | 2 +- 23 files changed, 188 insertions(+), 43 deletions(-) create mode 100644 daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/channel/alipay/service/AliPayNoticeReceiverService.java create mode 100644 daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/payment/allocation/service/AllocationCallbackService.java diff --git a/README.md b/README.md index b1cef581e..1656e5848 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@

star - Build Status + Build Status Build Status Downloads diff --git a/_doc/ChangeLog.md b/_doc/ChangeLog.md index c361fe5fb..a66da9a64 100644 --- a/_doc/ChangeLog.md +++ b/_doc/ChangeLog.md @@ -1,4 +1,8 @@ # CHANGELOG +## [v2.0.7] +- 新增: +- 优化: +- fix: ## [v2.0.6] - 新增: 下载原始对账单功能,转换为指定格式进行下载 - 新增: 增加对账结果计算和显示,以及对单差异数据查看功能 diff --git a/_doc/Task.md b/_doc/Task.md index 178974565..eaca2702a 100644 --- a/_doc/Task.md +++ b/_doc/Task.md @@ -16,8 +16,11 @@ - [x] 分账同步 - [x] 保存分账同步记录 - [x] SDK支持分账相关接口 -- [ ] 分账回调处理 -- [ ] 分账重试支持完结失败 +- [ ] 分账结果通知处理 + - [ ] 支付宝通知 + - [ ] 微信通知 + - [ ] 通知记录保存 +- [x] 分账重试支持完结失败 - [x] 分账通知发送功能 - [x] 分账支持手动和自动分账两种 - [x] 金额过小不进行分账, 增加新状态, 金额小于0.01元直接忽略 @@ -27,6 +30,8 @@ - [x] 系统中金额分转元精度异常问题 - [x] 同步回调处理参数订单号接收失败 - [x] 支付和退款消息签名值不一致问题 +- [x] 分账发起时错误的使用订单号作为分账号 +- [x] 支付宝发起时使用 2.0.7: 对账完善和系统优化 - [ ] DEMO增加获取微信OpenID和支付宝OpenId功能 diff --git a/daxpay-single-demo/pom.xml b/daxpay-single-demo/pom.xml index d4864550b..7bd842814 100644 --- a/daxpay-single-demo/pom.xml +++ b/daxpay-single-demo/pom.xml @@ -21,7 +21,7 @@ 1.3.6.2 - 2.0.6 + 2.0.7 diff --git a/daxpay-single-sdk/pom.xml b/daxpay-single-sdk/pom.xml index 37b97fed4..1a3151403 100644 --- a/daxpay-single-sdk/pom.xml +++ b/daxpay-single-sdk/pom.xml @@ -6,7 +6,7 @@ cn.daxpay.single daxpay-single-sdk - 2.0.6 + 2.0.7 jar diff --git a/daxpay-single-start/pom.xml b/daxpay-single-start/pom.xml index 7d2dc24d3..8a4983c8b 100644 --- a/daxpay-single-start/pom.xml +++ b/daxpay-single-start/pom.xml @@ -17,7 +17,7 @@ 1.3.6.2 - 2.0.6 + 2.0.7 diff --git a/daxpay-single-start/src/main/resources/application-dev.yml b/daxpay-single-start/src/main/resources/application-dev.yml index 4bde957f7..6f66a712d 100644 --- a/daxpay-single-start/src/main/resources/application-dev.yml +++ b/daxpay-single-start/src/main/resources/application-dev.yml @@ -69,7 +69,7 @@ bootx: swagger: enabled: true author: bootx - version: 2.0.6 + version: 2.0.7 title: 开源支付平台-单商户 description: 开源支付平台-单商户版 # 多模块扫码 diff --git a/daxpay-single-start/src/main/resources/application-prod.yml b/daxpay-single-start/src/main/resources/application-prod.yml index a03808ba8..9468898ef 100644 --- a/daxpay-single-start/src/main/resources/application-prod.yml +++ b/daxpay-single-start/src/main/resources/application-prod.yml @@ -65,7 +65,7 @@ bootx: swagger: enabled: false author: bootx - version: 2.0.6 + version: 2.0.7 title: 开源支付平台-单商户 description: 开源支付平台-单商户版 # 缓存 diff --git a/daxpay-single/daxpay-single-admin/pom.xml b/daxpay-single/daxpay-single-admin/pom.xml index 79bba4a51..bff5f318b 100644 --- a/daxpay-single/daxpay-single-admin/pom.xml +++ b/daxpay-single/daxpay-single-admin/pom.xml @@ -6,7 +6,7 @@ cn.daxpay.single daxpay-single - 2.0.6 + 2.0.7 daxpay-single-admin 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 6508bb3b4..11aad17e9 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 @@ -95,7 +95,7 @@ public class AllocationOrderController { return Res.ok(); } - @InitPaymentContext(PaymentApiCode.SYNC_REFUND) + @InitPaymentContext(PaymentApiCode.ALLOCATION_FINISH) @Operation(summary = "分账完结") @PostMapping("/finish") public ResResult finish(String allocationNo){ diff --git a/daxpay-single/daxpay-single-core/pom.xml b/daxpay-single/daxpay-single-core/pom.xml index 44c0bf689..b65ca6223 100644 --- a/daxpay-single/daxpay-single-core/pom.xml +++ b/daxpay-single/daxpay-single-core/pom.xml @@ -6,7 +6,7 @@ cn.daxpay.single daxpay-single - 2.0.6 + 2.0.7 daxpay-single-core diff --git a/daxpay-single/daxpay-single-gateway/pom.xml b/daxpay-single/daxpay-single-gateway/pom.xml index 9e1679d50..96f1ab411 100644 --- a/daxpay-single/daxpay-single-gateway/pom.xml +++ b/daxpay-single/daxpay-single-gateway/pom.xml @@ -6,7 +6,7 @@ cn.daxpay.single daxpay-single - 2.0.6 + 2.0.7 daxpay-single-gateway diff --git a/daxpay-single/daxpay-single-gateway/src/main/java/cn/daxpay/single/gateway/controller/PayNoticeReceiverController.java b/daxpay-single/daxpay-single-gateway/src/main/java/cn/daxpay/single/gateway/controller/PayNoticeReceiverController.java index 43178f920..31d45acc0 100644 --- a/daxpay-single/daxpay-single-gateway/src/main/java/cn/daxpay/single/gateway/controller/PayNoticeReceiverController.java +++ b/daxpay-single/daxpay-single-gateway/src/main/java/cn/daxpay/single/gateway/controller/PayNoticeReceiverController.java @@ -1,6 +1,7 @@ package cn.daxpay.single.gateway.controller; import cn.bootx.platform.common.core.annotation.IgnoreAuth; +import cn.daxpay.single.service.core.channel.alipay.service.AliPayNoticeReceiverService; import com.ijpay.alipay.AliPayApi; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; @@ -15,33 +16,29 @@ import java.util.Map; import java.util.Objects; /** - * 网关消息通知 + * 支付通道消息通知 * @author xxm * @since 2024/4/16 */ @IgnoreAuth -@Tag(name = "三方支付网关消息通知") +@Tag(name = "执法通道网关消息通知") @RestController -@RequestMapping("/gateway/notice") +@RequestMapping("/callback/notice") @RequiredArgsConstructor public class PayNoticeReceiverController { + private final AliPayNoticeReceiverService aliPayNoticeReceiverService; + @Operation(summary = "支付宝消息通知") @PostMapping("/alipay") public String aliPayNotice(HttpServletRequest request) { Map map = AliPayApi.toMap(request); - // 通过 msg_method 获取消息类型 - String msgMethod = map.get("msg_method"); - // 通过 biz_content 获取值 - String bizContent = map.get("biz_content"); - - return "success"; + return aliPayNoticeReceiverService.noticeReceiver(map); } @Operation(summary = "微信消息通知") @PostMapping("/wechat") - public Map wechatPayNotice() { + public Map wechatPayNotice(HttpServletRequest request) { return new HashMap<>(); } - } diff --git a/daxpay-single/daxpay-single-service/pom.xml b/daxpay-single/daxpay-single-service/pom.xml index 3d5397bc8..e3917bed8 100644 --- a/daxpay-single/daxpay-single-service/pom.xml +++ b/daxpay-single/daxpay-single-service/pom.xml @@ -6,7 +6,7 @@ cn.daxpay.single daxpay-single - 2.0.6 + 2.0.7 daxpay-single-service diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/code/AliPayCode.java b/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/code/AliPayCode.java index 67230a441..a28f0ef16 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/code/AliPayCode.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/code/AliPayCode.java @@ -113,7 +113,7 @@ public interface AliPayCode { String ALLOC_FAIL = "FAIL"; /** 异步分账 */ - String ALLOC_ASYNC = "ASYNC"; + String ALLOC_ASYNC = "async"; /** 同步分账 */ - String ALLOC_SYNC = "SYNC"; + String ALLOC_SYNC = "sync"; } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/channel/alipay/service/AliPayAllocationService.java b/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/channel/alipay/service/AliPayAllocationService.java index b13c0d472..314b22c63 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/channel/alipay/service/AliPayAllocationService.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/channel/alipay/service/AliPayAllocationService.java @@ -49,7 +49,7 @@ public class AliPayAllocationService { public void allocation(AllocationOrder allocationOrder, List orderDetails){ // 分账主体参数 AlipayTradeOrderSettleModel model = new AlipayTradeOrderSettleModel(); - model.setOutRequestNo(allocationOrder.getOrderNo()); + model.setOutRequestNo(allocationOrder.getAllocationNo()); model.setTradeNo(allocationOrder.getOutOrderNo()); model.setRoyaltyMode(AliPayCode.ALLOC_ASYNC); @@ -79,12 +79,12 @@ public class AliPayAllocationService { public void finish(AllocationOrder allocationOrder, List orderDetails ){ // 分账主体参数 AlipayTradeOrderSettleModel model = new AlipayTradeOrderSettleModel(); - model.setOutRequestNo(String.valueOf(allocationOrder.getOrderNo())); + model.setOutRequestNo(String.valueOf(allocationOrder.getAllocationNo())); model.setTradeNo(allocationOrder.getOutOrderNo()); model.setRoyaltyMode(AliPayCode.ALLOC_ASYNC); // 分账完结参数 SettleExtendParams extendParams = new SettleExtendParams(); - extendParams.setRoyaltyFinish("true"); + extendParams.setRoyaltyFinish(Boolean.TRUE.toString()); model.setExtendParams(extendParams); // 分账子参数 根据Id排序 @@ -109,7 +109,7 @@ public class AliPayAllocationService { public AllocRemoteSyncResult sync(AllocationOrder allocationOrder, List allocationOrderDetails){ AlipayTradeOrderSettleQueryModel model = new AlipayTradeOrderSettleQueryModel(); model.setTradeNo(allocationOrder.getOutOrderNo()); - model.setOutRequestNo(allocationOrder.getOrderNo()); + model.setOutRequestNo(allocationOrder.getAllocationNo()); AlipayTradeOrderSettleQueryRequest request = new AlipayTradeOrderSettleQueryRequest(); request.setBizModel(model); AlipayTradeOrderSettleQueryResponse response = AliPayApi.execute(request); diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/channel/alipay/service/AliPayNoticeReceiverService.java b/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/channel/alipay/service/AliPayNoticeReceiverService.java new file mode 100644 index 000000000..111874f5e --- /dev/null +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/channel/alipay/service/AliPayNoticeReceiverService.java @@ -0,0 +1,95 @@ +package cn.daxpay.single.service.core.channel.alipay.service; + +import cn.bootx.platform.common.core.util.CertUtil; +import cn.daxpay.single.service.core.channel.alipay.entity.AliPayConfig; +import cn.daxpay.single.service.core.payment.allocation.service.AllocationCallbackService; +import cn.hutool.core.util.CharsetUtil; +import cn.hutool.core.util.StrUtil; +import cn.hutool.json.JSONUtil; +import com.alipay.api.AlipayApiException; +import com.alipay.api.AlipayConstants; +import com.alipay.api.internal.util.AlipaySignature; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import java.util.Map; +import java.util.Objects; + +import static cn.daxpay.single.service.code.AliPayCode.APP_ID; +import static cn.daxpay.single.service.code.AliPayCode.AUTH_TYPE_KEY; + +/** + * 支付宝通知消息接收 + * @author xxm + * @since 2024/5/31 + */ +@Slf4j +@Service +@RequiredArgsConstructor +public class AliPayNoticeReceiverService { + + private final AllocationCallbackService allocationCallbackService; + + private final AliPayConfigService aliPayConfigService; + + /** + * 消息通知处理 + */ + public String noticeReceiver(Map map) { + + // 首先进行验签 + if (!this.verifyNotify(map)){ + log.error("支付宝消息通知验签失败"); + return "fail"; + } + + // 通过 msg_method 获取消息类型 + String msgMethod = map.get("msg_method"); + // 通过 biz_content 获取值 + String bizContent = map.get("biz_content"); + + // 分账结果通知 + if ("alipay.trade.order.settle.notify".equals(msgMethod)) { + // 转换成对象 + + // 获取分账号 + + // 调用统一分账回调处理 + + // 分账完成 + + } + // 返回处理成功 + return "success"; + } + + /** + * 校验消息通知 + */ + private boolean verifyNotify(Map params) { + String callReq = JSONUtil.toJsonStr(params); + log.info("支付宝消息通知报文: {}", callReq); + String appId = params.get(APP_ID); + if (StrUtil.isBlank(appId)) { + log.error("支付宝消息通知报文appId为空"); + return false; + } + AliPayConfig alipayConfig = aliPayConfigService.getConfig(); + if (Objects.isNull(alipayConfig)) { + log.error("支付宝支付配置不存在"); + return false; + } + try { + if (Objects.equals(alipayConfig.getAuthType(), AUTH_TYPE_KEY)) { + return AlipaySignature.rsaCheckV1(params, alipayConfig.getAlipayPublicKey(), CharsetUtil.UTF_8, AlipayConstants.SIGN_TYPE_RSA2); + } + else { + return AlipaySignature.verifyV1(params, CertUtil.getCertByContent(alipayConfig.getAlipayCert()), CharsetUtil.UTF_8, AlipayConstants.SIGN_TYPE_RSA2); + } + } catch (AlipayApiException e) { + log.error("支付宝验签失败", e); + return false; + } + } +} diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/channel/wechat/service/WeChatPayAllocationReceiverService.java b/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/channel/wechat/service/WeChatPayAllocationReceiverService.java index bca35211e..9f26cdc48 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/channel/wechat/service/WeChatPayAllocationReceiverService.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/channel/wechat/service/WeChatPayAllocationReceiverService.java @@ -21,6 +21,7 @@ import java.util.List; import java.util.Map; import static cn.daxpay.single.code.AllocReceiverTypeEnum.WX_MERCHANT; +import static cn.daxpay.single.code.AllocReceiverTypeEnum.WX_PERSONAL; /** * @@ -36,7 +37,7 @@ public class WeChatPayAllocationReceiverService { * 校验参数是否合法 */ public boolean validation(AllocationReceiver allocationReceiver){ - List list = Arrays.asList(WX_MERCHANT.getCode(), WX_MERCHANT.getCode()); + List list = Arrays.asList(WX_PERSONAL.getCode(), WX_MERCHANT.getCode()); String receiverType = allocationReceiver.getReceiverType(); return list.contains(receiverType); } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/channel/wechat/service/WeChatPayAllocationService.java b/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/channel/wechat/service/WeChatPayAllocationService.java index 23d3e9eb4..ab0e47b6b 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/channel/wechat/service/WeChatPayAllocationService.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/channel/wechat/service/WeChatPayAllocationService.java @@ -75,7 +75,7 @@ public class WeChatPayAllocationService { .appid(config.getWxAppId()) .nonce_str(WxPayKit.generateStr()) .transaction_id(allocationOrder.getOutOrderNo()) - .out_order_no(allocationOrder.getOrderNo()) + .out_order_no(allocationOrder.getAllocationNo()) .receivers(JSON.toJSONString(list)) .build() .createSign(config.getApiKeyV2(), SignType.HMACSHA256); @@ -96,8 +96,9 @@ public class WeChatPayAllocationService { .appid(config.getWxAppId()) .nonce_str(WxPayKit.generateStr()) .transaction_id(allocationOrder.getOutOrderNo()) - .out_order_no(allocationOrder.getOrderNo()) - .description("分账完成") + // 分账要使用单独的的流水号, 不能与分账号相同 + .out_order_no(allocationOrder.getAllocationNo()+'F') + .description("分账已完成") .build() .createSign(config.getApiKeyV2(), SignType.HMACSHA256); @@ -117,7 +118,7 @@ public class WeChatPayAllocationService { .mch_id(config.getWxMchId()) .nonce_str(WxPayKit.generateStr()) .transaction_id(allocationOrder.getOutOrderNo()) - .out_order_no(allocationOrder.getOrderNo()) + .out_order_no(allocationOrder.getAllocationNo()) .build() .createSign(config.getApiKeyV2(), SignType.HMACSHA256); String xmlResult = WxPayApi.profitSharingQuery(params); diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/payment/allocation/service/AllocationCallbackService.java b/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/payment/allocation/service/AllocationCallbackService.java new file mode 100644 index 000000000..85efcfe36 --- /dev/null +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/payment/allocation/service/AllocationCallbackService.java @@ -0,0 +1,24 @@ +package cn.daxpay.single.service.core.payment.allocation.service; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +/** + * 分账回调处理 + * @author xxm + * @since 2024/5/31 + */ +@Slf4j +@Service +@RequiredArgsConstructor +public class AllocationCallbackService { + + + /** + * + */ + public void callback(String allocationNo){ + + } +} 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 a775e218c..5c9332b85 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 @@ -3,6 +3,7 @@ package cn.daxpay.single.service.core.payment.allocation.service; 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.AllocOrderStatusEnum; import cn.daxpay.single.code.PayOrderAllocStatusEnum; import cn.daxpay.single.exception.pay.PayFailureException; @@ -35,11 +36,15 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; +import java.time.LocalDateTime; import java.util.Arrays; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; +import static cn.daxpay.single.code.AllocOrderStatusEnum.ALLOCATION_END; +import static cn.daxpay.single.code.AllocOrderStatusEnum.FINISH_FAILED; + /** * 分账服务 * @author xxm @@ -151,13 +156,13 @@ public class AllocationService { } try { // 需要是分账中分账中或者完成状态才能重新分账 - List list = Arrays.asList(AllocOrderStatusEnum.ALLOCATION_END.getCode(), + List list = Arrays.asList(ALLOCATION_END.getCode(), AllocOrderStatusEnum.ALLOCATION_FAILED.getCode(), AllocOrderStatusEnum.ALLOCATION_PROCESSING.getCode()); if (!list.contains(order.getStatus())){ throw new PayFailureException("分账单状态错误,无法重试"); } - List details = allocationOrderDetailManager.findAllByOrderId(order.getId()); + List details = this.getDetails(order.getId()); // 创建分账策略并初始化 AbsAllocationStrategy allocationStrategy = AllocationFactory.create(order.getChannel()); allocationStrategy.initParam(order, details); @@ -209,10 +214,11 @@ public class AllocationService { */ public AllocationResult finish(AllocationOrder allocationOrder) { // 只有分账结束后才可以完结 - if (!AllocOrderStatusEnum.ALLOCATION_END.getCode().equals(allocationOrder.getStatus())){ + if (!Arrays.asList(ALLOCATION_END.getCode(),FINISH_FAILED.getCode()).contains(allocationOrder.getStatus())) { throw new PayFailureException("分账单状态错误"); } - List details = allocationOrderDetailManager.findAllByOrderId(allocationOrder.getId()); + List details = this.getDetails(allocationOrder.getId()); + // 创建分账策略并初始化 AbsAllocationStrategy allocationStrategy = AllocationFactory.create(allocationOrder.getChannel()); allocationStrategy.initParam(allocationOrder, details); @@ -224,11 +230,12 @@ public class AllocationService { allocationStrategy.finish(); // 完结状态 allocationOrder.setStatus(AllocOrderStatusEnum.FINISH.getCode()) + .setFinishTime(LocalDateTime.now()) .setErrorMsg(null); } catch (Exception e) { log.error("分账完结错误:", e); // 失败 - allocationOrder.setStatus(AllocOrderStatusEnum.FINISH_FAILED.getCode()) + allocationOrder.setStatus(FINISH_FAILED.getCode()) .setErrorMsg(e.getMessage()); } allocationOrderManager.updateById(allocationOrder); @@ -293,4 +300,15 @@ public class AllocationService { } return orderAndDetail; } + + /** + * 获取发起分账或完结的明细 + */ + private List getDetails(Long allocOrderId){ + List details = allocationOrderDetailManager.findAllByOrderId(allocOrderId); + // 过滤掉忽略的条目 + return details.stream() + .filter(detail -> !Objects.equals(detail.getResult(), AllocDetailResultEnum.IGNORE.getCode())) + .collect(Collectors.toList()); + } } diff --git a/daxpay-single/pom.xml b/daxpay-single/pom.xml index 3fb77060a..3b43462f8 100644 --- a/daxpay-single/pom.xml +++ b/daxpay-single/pom.xml @@ -13,7 +13,7 @@ cn.daxpay.single daxpay-single pom - 2.0.6 + 2.0.7 UTF-8 @@ -22,7 +22,7 @@ 1.3.6.2 - 2.0.6 + 2.0.7 1.7.30 3.16.8 diff --git a/pom.xml b/pom.xml index 7e625743b..d975eea4d 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ cn.daxpay.single dax-pay pom - 2.0.6 + 2.0.7 daxpay-single