|
|
@@ -20,6 +20,8 @@ import jakarta.servlet.http.HttpServletRequest;
|
|
|
import jakarta.validation.Valid;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
@@ -30,6 +32,7 @@ import java.text.SimpleDateFormat;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
|
|
|
/**
|
|
|
* 威富通支付服务
|
|
|
@@ -800,7 +803,7 @@ public class WFTOrderService {
|
|
|
|
|
|
if (canRefundMoney.compareTo(refundMoney) >= 0) {
|
|
|
//可退款金额大于等于待退款金额,则直接退全部待退款金额
|
|
|
- refundOrder(userOrderInfo, refundMoney, "账户退款", type);
|
|
|
+ Long refundOrderId = refundOrder(userOrderInfo, refundMoney, "账户退款", type);
|
|
|
|
|
|
//计算本次退款后的累计退款金额
|
|
|
BigDecimal totalRefundMoney = alreadyRefundMoney.add(refundMoney);
|
|
|
@@ -812,7 +815,7 @@ public class WFTOrderService {
|
|
|
refundMoney,
|
|
|
SystemConstants.CHANGE_TYPE_REDUCE,
|
|
|
SystemConstants.ACCOUNT_LOG_REFUND_NOTE,
|
|
|
- userOrderInfo.getId()
|
|
|
+ refundOrderId
|
|
|
);
|
|
|
|
|
|
//修改订单状态(判断是全额退款还是部分退款)
|
|
|
@@ -854,7 +857,7 @@ public class WFTOrderService {
|
|
|
return "账户退款,预计3个工作日内分一笔或多笔退还!到期如未收到,请联系客服处理!";
|
|
|
}
|
|
|
|
|
|
- public void refundOrder(UserOrderInfo userOrderInfo, BigDecimal refundAmount, String reason, Integer type) throws Exception {
|
|
|
+ public Long refundOrder(UserOrderInfo userOrderInfo, BigDecimal refundAmount, String reason, Integer type) throws Exception {
|
|
|
log.info("进入退款接口------>");
|
|
|
log.info("执行操作的 原支付交易对应的商户订单号:{}", userOrderInfo.getOrderNo());
|
|
|
|
|
|
@@ -873,7 +876,12 @@ public class WFTOrderService {
|
|
|
|
|
|
SortedMap<String, String> params = new TreeMap<>();
|
|
|
|
|
|
- params.put("out_trade_no", userOrderInfo.getOrderNo());//商户订单号
|
|
|
+ if (ObjectUtil.isNotEmpty(userOrderInfo.getTransactionId())) {
|
|
|
+ params.put("transaction_id", userOrderInfo.getTransactionId());
|
|
|
+ params.put("out_trade_no", userOrderInfo.getOrderNo());//商户订单号
|
|
|
+ }else {
|
|
|
+ params.put("out_trade_no", userOrderInfo.getOutTradeNo());//1.0的商户订单号
|
|
|
+ }
|
|
|
params.put("out_refund_no", out_refund_no);//商户退款单号
|
|
|
params.put("attach", reason);//退款原因
|
|
|
params.put("total_fee", amount_fee(userOrderInfo.getOrderMoney()));//原订单金额
|
|
|
@@ -905,12 +913,15 @@ public class WFTOrderService {
|
|
|
userOrderInfo.setRefundMoney(totalRefundMoney);
|
|
|
userOrderInfo.setRefundTime(LocalDateTime.now());
|
|
|
userOrderInfoMapper.updateById(userOrderInfo);
|
|
|
+ userRefundsOrderInfo.setStatus("SUCCESS");
|
|
|
+ userRefundsOrderInfo.setSuccessTime(LocalDateTime.now());
|
|
|
} else {
|
|
|
log.info("退款处理中");
|
|
|
//修改订单状态
|
|
|
BigDecimal currentRefundMoney = userOrderInfo.getRefundMoney() == null ? BigDecimal.ZERO : userOrderInfo.getRefundMoney();
|
|
|
userOrderInfo.setRefundMoney(currentRefundMoney.add(refundAmount));
|
|
|
userOrderInfoMapper.updateById(userOrderInfo);
|
|
|
+ userRefundsOrderInfo.setStatus("PROCESSING");
|
|
|
}
|
|
|
//退款信息补充
|
|
|
userRefundsOrderInfo.setRefundId(refund.get("refund_id"));
|
|
|
@@ -918,8 +929,34 @@ public class WFTOrderService {
|
|
|
userRefundsOrderInfo.setTransactionId(userOrderInfo.getTransactionId());
|
|
|
userRefundsOrderInfo.setAcceptedTime(LocalDateTime.now());
|
|
|
userRefundsOrderInfoMapper.insert(userRefundsOrderInfo);
|
|
|
+
|
|
|
+ //异步执行查询退款订单,修改退款记录
|
|
|
+ executeTaskQueryRefundOrder(userRefundsOrderInfo,userRefundsOrderInfo.getRefundId());
|
|
|
}
|
|
|
+ return userRefundsOrderInfo.getId();
|
|
|
+ }
|
|
|
|
|
|
+ @Autowired
|
|
|
+ @Qualifier("businessTaskExecutor")
|
|
|
+ private ThreadPoolTaskExecutor businessTaskExecutor;
|
|
|
+
|
|
|
+ public CompletableFuture<Void> executeTaskQueryRefundOrder(UserRefundsOrderInfo userRefundsOrderInfo,String refundId) {
|
|
|
+ // 使用 runAsync 并指定自定义线程池
|
|
|
+ return CompletableFuture.runAsync(() -> {
|
|
|
+
|
|
|
+ log.info("进入查询退款接口------>执行线程: " + Thread.currentThread().getName());
|
|
|
+
|
|
|
+ // 异步任务逻辑
|
|
|
+ Map<String, Object> map = queryRefund(null, null, null, refundId);
|
|
|
+ List<Map<String, Object>> refundList= (List<Map<String, Object>>)map.get("refund_list");
|
|
|
+ String refundStatus = refundList.get(0).get("refund_status").toString();
|
|
|
+ userRefundsOrderInfo.setStatus(refundStatus);
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
|
|
|
+ LocalDateTime dateTime = LocalDateTime.parse(refundList.get(0).get("refund_time").toString(), formatter);
|
|
|
+ userRefundsOrderInfo.setSuccessTime(dateTime);
|
|
|
+ userRefundsOrderInfoMapper.updateById(userRefundsOrderInfo);
|
|
|
+ log.info("退款金额:{},退款状态:{}",refundList.get(0).get("refund_fee").toString(),refundStatus);
|
|
|
+ }, businessTaskExecutor);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -1074,11 +1111,12 @@ public class WFTOrderService {
|
|
|
public static void main(String[] args) throws IOException {
|
|
|
SortedMap<String, String> params = new TreeMap<>();
|
|
|
SwiftpassConfig swiftpassConfig = new SwiftpassConfig();
|
|
|
- params.put("transaction_id", "2301202601062012554389");//商户订单号
|
|
|
- params.put("out_refund_no", "TK2301202601062012554389");//商户退款单号
|
|
|
+ params.put("transaction_id", "2301202601062012757716");//商户订单号
|
|
|
+// params.put("out_trade_no", "ZSWL20251201000000201343");//商户订单号
|
|
|
+ params.put("out_refund_no", "TK2301202601062012757716");//商户退款单号
|
|
|
params.put("attach", "");//退款原因
|
|
|
- params.put("total_fee", "5000");//原订单金额
|
|
|
- params.put("refund_fee", "2000");//退款金额
|
|
|
+ params.put("total_fee", "3000");//原订单金额
|
|
|
+ params.put("refund_fee", "1566");//退款金额
|
|
|
params.put("sign_type", "RSA_1_256");
|
|
|
PayUtill payUtill = new PayUtill();
|
|
|
swiftpassConfig.setKey("f5131b3f07acb965a59041b690a29911");
|