mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-20 02:55:04 +08:00
定时任务处理未分帐订单
This commit is contained in:
@@ -89,7 +89,7 @@ spring:
|
||||
|
||||
# rabbitmq配置 sit
|
||||
rabbitmq:
|
||||
host: 127.0.0.1
|
||||
host: 192.168.2.2
|
||||
port: 5672
|
||||
username: admin
|
||||
password: admin
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<PaymentConfirmInfo> 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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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")) {
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user