From ed98a6bebef2fefebc6446e4ffcf4f129b25e441 Mon Sep 17 00:00:00 2001 From: Guoqs <123@jsowell.com> Date: Thu, 17 Apr 2025 10:03:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1=E5=A4=84?= =?UTF-8?q?=E7=90=86=E6=9C=AA=E5=88=86=E5=B8=90=E8=AE=A2=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/application-sit.yml | 2 +- .../src/test/java/PaymentTestController.java | 35 ++++------- .../jsowell/adapay/service/AdapayService.java | 60 +++++++++++++++++++ .../com/jsowell/quartz/task/JsowellTask.java | 24 ++++++-- 4 files changed, 92 insertions(+), 29 deletions(-) diff --git a/jsowell-admin/src/main/resources/application-sit.yml b/jsowell-admin/src/main/resources/application-sit.yml index 50b4907db..b9b0b63c2 100644 --- a/jsowell-admin/src/main/resources/application-sit.yml +++ b/jsowell-admin/src/main/resources/application-sit.yml @@ -89,7 +89,7 @@ spring: # rabbitmq配置 sit rabbitmq: - host: 127.0.0.1 + host: 192.168.2.2 port: 5672 username: admin password: admin diff --git a/jsowell-admin/src/test/java/PaymentTestController.java b/jsowell-admin/src/test/java/PaymentTestController.java index 9d8b408ae..54ba3e22a 100644 --- a/jsowell-admin/src/test/java/PaymentTestController.java +++ b/jsowell-admin/src/test/java/PaymentTestController.java @@ -10,10 +10,8 @@ import com.jsowell.JsowellApplication; import com.jsowell.adapay.common.DivMember; import com.jsowell.adapay.common.PaymentConfirmInfo; import com.jsowell.adapay.dto.PaymentConfirmParam; -import com.jsowell.adapay.dto.QueryConfirmReverseDTO; import com.jsowell.adapay.dto.QueryPaymentConfirmDTO; import com.jsowell.adapay.operation.PaymentReverseOperation; -import com.jsowell.adapay.response.ConfirmReverseResponse; import com.jsowell.adapay.response.PaymentConfirmResponse; import com.jsowell.adapay.response.PaymentReverseResponse; import com.jsowell.adapay.response.QueryPaymentConfirmDetailResponse; @@ -349,6 +347,17 @@ public class PaymentTestController { } } + @Test + public void getTotalSplitAmountByPaymentIdTest() { + String paymentId = "002212023102523235110563274707384705024"; + try { + BigDecimal amount = adapayService.getTotalSplitAmountByPaymentId(paymentId); + System.out.println("分账金额: " + amount); + } catch (BaseAdaPayException e) { + throw new RuntimeException(e); + } + } + /** * 查询分账信息 @@ -385,7 +394,7 @@ public class PaymentTestController { } else { splitList.add(paymentId); for (PaymentConfirmInfo confirm : confirms) { - if (queryConfirmReverseStatus(confirm)) { + if (adapayService.queryConfirmReverseStatus(confirm)) { System.out.println("支付确认id:" + confirm.getId() + "撤销了。。。"); continue; } @@ -431,26 +440,6 @@ public class PaymentTestController { System.out.println("===================自己:" + JSON.toJSONString(selfList) + ", 数量:" + selfList.size()); } - /** - * 查询支付撤销状态 - * @param confirm - * @return - * @throws BaseAdaPayException - */ - private boolean queryConfirmReverseStatus(PaymentConfirmInfo confirm) throws BaseAdaPayException { - boolean result = false; - QueryConfirmReverseDTO dto = QueryConfirmReverseDTO.builder() - .paymentConfirmId(confirm.getId()) - .wechatAppId(wechatAppId1) - .build(); - ConfirmReverseResponse confirmReverseResponse = adapayService.queryConfirmReverse(dto); - if (confirmReverseResponse.isSuccess()) { - result = true; - } - - return result; - } - /** * 批量支付确认撤销 * @throws BaseAdaPayException diff --git a/jsowell-pile/src/main/java/com/jsowell/adapay/service/AdapayService.java b/jsowell-pile/src/main/java/com/jsowell/adapay/service/AdapayService.java index 218ea0c44..223acc20f 100644 --- a/jsowell-pile/src/main/java/com/jsowell/adapay/service/AdapayService.java +++ b/jsowell-pile/src/main/java/com/jsowell/adapay/service/AdapayService.java @@ -67,6 +67,8 @@ public class AdapayService { @Value("${adapay.callback}") private String ADAPAY_CALLBACK_URL; + String wechatAppId1 = "wxbb3e0d474569481d"; // 万车充 + @Autowired private AdapayMemberAccountService adapayMemberAccountService; @@ -1214,6 +1216,8 @@ public class AdapayService { /** * 查询支付确认对象列表 + * paymentId 必传 + * wechatAppId 必传 */ public QueryPaymentConfirmDetailResponse queryPaymentConfirmList(QueryPaymentConfirmDTO dto) { QueryPaymentConfirmDetailResponse response = null; @@ -1439,4 +1443,60 @@ public class AdapayService { settleAccountDTO.setAreaCode(dto.getAreaCode()); this.createSettleAccountRequest(settleAccountDTO, adapayMemberId, wechatAppId); } + + /** + * 查询支付撤销状态 + * @param confirm + * @return + * @throws BaseAdaPayException + */ + public boolean queryConfirmReverseStatus(PaymentConfirmInfo confirm) throws BaseAdaPayException { + boolean result = false; + QueryConfirmReverseDTO dto = QueryConfirmReverseDTO.builder() + .paymentConfirmId(confirm.getId()) + .wechatAppId(wechatAppId1) + .build(); + ConfirmReverseResponse confirmReverseResponse = this.queryConfirmReverse(dto); + if (confirmReverseResponse.isSuccess()) { + result = true; + } + return result; + } + + /** + * 根据paymentId查询总分账金额 + * 万车充专用 + * @param paymentId + * @return + * @throws BaseAdaPayException + */ + public BigDecimal getTotalSplitAmountByPaymentId(String paymentId) throws BaseAdaPayException { + BigDecimal totalSplitAmount = BigDecimal.ZERO; + // 查询支付确认id + QueryPaymentConfirmDTO dto = new QueryPaymentConfirmDTO(); + dto.setPaymentId(paymentId); + dto.setWechatAppId(wechatAppId1); + // 查询分账信息 + QueryPaymentConfirmDetailResponse response = this.queryPaymentConfirmList(dto); + if (response == null) { + return totalSplitAmount; + } + + List confirms = response.getPaymentConfirms(); + if (CollectionUtils.isEmpty(confirms)) { + return totalSplitAmount; + } + + for (PaymentConfirmInfo confirm : confirms) { + if (queryConfirmReverseStatus(confirm)) { + log.info("支付确认id:{}撤销了。。。", confirm.getId()); + continue; + } + BigDecimal confirmedAmt = new BigDecimal(confirm.getConfirmedAmt()); // 已确认金额 + // 汇总已确认金额 + totalSplitAmount = totalSplitAmount.add(confirmedAmt); + } + + return totalSplitAmount; + } } diff --git a/jsowell-quartz/src/main/java/com/jsowell/quartz/task/JsowellTask.java b/jsowell-quartz/src/main/java/com/jsowell/quartz/task/JsowellTask.java index 0de235694..4124bc2c2 100644 --- a/jsowell-quartz/src/main/java/com/jsowell/quartz/task/JsowellTask.java +++ b/jsowell-quartz/src/main/java/com/jsowell/quartz/task/JsowellTask.java @@ -1,6 +1,7 @@ package com.jsowell.quartz.task; import com.google.common.collect.Lists; +import com.huifu.adapay.core.exception.BaseAdaPayException; import com.jsowell.adapay.common.DivMember; import com.jsowell.adapay.dto.PaymentConfirmParam; import com.jsowell.adapay.dto.WithdrawDTO; @@ -345,6 +346,7 @@ public class JsowellTask { /** * 处理未分帐订单 + * jsowellTask.processUnSettledOrder() */ public void processUnSettledOrder() { String startTime = "2023-01-01 00:00:00"; @@ -385,21 +387,33 @@ public class JsowellTask { orderUnsplitRecordService.updateOrderUnsplitRecord(orderUnsplitRecord); log.info("processUnsplitOrders, 分账成功, paymentId:{}", paymentId); } else { - // 如果失败,打印日志 - log.info("processUnsplitOrders, 分账失败, paymentId:{}, 错误信息:{}", paymentId, paymentConfirmResponse.getError_msg()); - // error_type:api_error, error_code:confirm_amt_over_limit, error_msg当前确认金额 > 支付金额 - 已支付确认金额 - 已支付撤销金额 if (paymentConfirmResponse.getError_code().equals("confirm_amt_over_limit")) { - orderUnsplitRecord.setStatus(AdapayStatusEnum.SUCCEEDED.getValue()); - orderUnsplitRecordService.updateOrderUnsplitRecord(orderUnsplitRecord); + // TODO 查询paymentId的总分账金额 + BigDecimal totalSplitAmount = BigDecimal.ZERO; + try { + totalSplitAmount = adapayService.getTotalSplitAmountByPaymentId(paymentId); + } catch (BaseAdaPayException e) { + throw new RuntimeException(e); + } + if (totalSplitAmount.compareTo(confirmAmt) == 0) { + // 如果总分账金额等于当前分账金额,则更新订单状态为已分账 + orderUnsplitRecord.setStatus(AdapayStatusEnum.SUCCEEDED.getValue()); + orderUnsplitRecordService.updateOrderUnsplitRecord(orderUnsplitRecord); + log.info("processUnsplitOrders, 分账成功, paymentId:{}", paymentId); + } else { + log.info("processUnsplitOrders, 分账失败, paymentId:{}, 错误信息:{}", paymentId, paymentConfirmResponse.getError_msg()); + } } // error_type:invalid_request_error, error_code:payment_over_time_doing, error_msg:数据正在处理中,请稍后再试 if (paymentConfirmResponse.getError_code().equals("payment_over_time_doing")) { + log.info("processUnsplitOrders, 分账失败, paymentId:{}, 错误信息:{}", paymentId, paymentConfirmResponse.getError_msg()); break; } // error_type:invalid_request_error, error_code:refund_repeate_request, error_msg:请求过于频繁 if (paymentConfirmResponse.getError_code().equals("refund_repeate_request")) { + log.info("processUnsplitOrders, 分账失败, paymentId:{}, 错误信息:{}", paymentId, paymentConfirmResponse.getError_msg()); break; } }