mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-21 03:25:12 +08:00
update
This commit is contained in:
@@ -20,12 +20,15 @@ import com.jsowell.adapay.response.PaymentReverseResponse;
|
||||
import com.jsowell.adapay.response.QueryPaymentConfirmDetailResponse;
|
||||
import com.jsowell.adapay.service.AdapayService;
|
||||
import com.jsowell.adapay.vo.OrderSplitResult;
|
||||
import com.jsowell.common.constant.CacheConstants;
|
||||
import com.jsowell.common.constant.Constants;
|
||||
import com.jsowell.common.core.redis.RedisCache;
|
||||
import com.jsowell.common.enums.ykc.ScenarioEnum;
|
||||
import com.jsowell.common.util.AdapayUtil;
|
||||
import com.jsowell.common.util.StringUtils;
|
||||
import com.jsowell.pile.domain.AdapayMemberAccount;
|
||||
import com.jsowell.pile.service.OrderBasicInfoService;
|
||||
import com.jsowell.pile.service.OrderUnsplitRecordService;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -33,6 +36,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@@ -40,9 +44,8 @@ import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 专用处理汇付支付相关
|
||||
@@ -52,13 +55,18 @@ import java.util.Map;
|
||||
@RunWith(SpringRunner.class)
|
||||
public class PaymentTestController {
|
||||
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
String wechatAppId1 = "wxbb3e0d474569481d"; // 万车充
|
||||
|
||||
String wechatAppId2 = "wx20abc5210391649c"; // 嘉佳充电
|
||||
|
||||
String adapayAppId = "app_d0c80cb1-ffc8-48cb-a030-fe9bec823aaa";
|
||||
|
||||
@Autowired
|
||||
private RedisCache redisCache;
|
||||
|
||||
@Autowired
|
||||
private OrderUnsplitRecordService orderUnsplitRecordService;
|
||||
|
||||
@Autowired
|
||||
private AdapayService adapayService;
|
||||
|
||||
@@ -242,6 +250,67 @@ public class PaymentTestController {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 执行分账并处理重试
|
||||
// for (PaymentConfirmParam param : paramList) {
|
||||
// executeWithRetry(param, 0); // 初始重试次数为0
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行分账并处理重试逻辑
|
||||
*/
|
||||
private void executeWithRetry(PaymentConfirmParam param, int retryCount) {
|
||||
PaymentConfirmResponse response = adapayService.createPaymentConfirmRequest(param);
|
||||
if (!response.isFailed()) {
|
||||
logger.info("分账成功: paymentId={}", param.getPaymentId());
|
||||
return;
|
||||
}
|
||||
|
||||
// 失败时记录日志
|
||||
logger.error("分账失败: paymentId={}, 重试次数={}, 错误信息={}", param.getPaymentId(), retryCount, response.getError_msg());
|
||||
|
||||
// 如果未达到最大重试次数,将任务放入延迟队列
|
||||
if (retryCount < 3) {
|
||||
retryCount++;
|
||||
logger.info("将分账任务放入延迟队列: paymentId={}, 重试次数={}", param.getPaymentId(), retryCount);
|
||||
redisCache.setCacheObject(
|
||||
CacheConstants.DELAYED_PAYMENT_CONFIRM_QUEUE + param.getPaymentId(),
|
||||
param,
|
||||
60, // 延迟1分钟
|
||||
TimeUnit.SECONDS
|
||||
);
|
||||
} else {
|
||||
logger.error("分账失败超过最大重试次数: paymentId={}", param.getPaymentId());
|
||||
// 记录最终失败的任务,便于后续处理
|
||||
recordFailedPayment(param);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录最终失败的分账任务
|
||||
*/
|
||||
private void recordFailedPayment(PaymentConfirmParam param) {
|
||||
String failedKey = CacheConstants.FAILED_PAYMENT_CONFIRM_LIST;
|
||||
redisCache.setCacheList(failedKey, Lists.newArrayList(param));
|
||||
logger.error("记录最终失败的分账任务: paymentId={}", param.getPaymentId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理延迟队列中的分账任务
|
||||
*/
|
||||
@Scheduled(fixedDelay = 60000) // 每分钟执行一次
|
||||
public void processDelayedPaymentConfirm() {
|
||||
String delayedQueueKey = CacheConstants.DELAYED_PAYMENT_CONFIRM_QUEUE + "*";
|
||||
Collection<String> keys = redisCache.keys(delayedQueueKey);
|
||||
for (String key : keys) {
|
||||
PaymentConfirmParam param = redisCache.getCacheObject(key);
|
||||
if (param != null) {
|
||||
int retryCount = Integer.parseInt(key.split("_")[key.split("_").length - 1]);
|
||||
executeWithRetry(param, retryCount);
|
||||
redisCache.deleteObject(key); // 处理完成后删除任务
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user