超时关闭的订单,检查一下汇付是否存在支付单,一起退款

This commit is contained in:
2024-03-26 09:18:09 +08:00
parent 1045d73690
commit e0d80912fd
6 changed files with 132 additions and 75 deletions

View File

@@ -40,6 +40,7 @@ import com.jsowell.pile.dto.PayOrderDTO;
import com.jsowell.pile.service.*;
import com.jsowell.pile.vo.base.MerchantInfoVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cglib.beans.BeanMap;
@@ -88,10 +89,10 @@ public class AdapayService {
// log.info("===============使用汇付支付-获取支付参数");
// 相同参数重复请求,返回同一个支付对象
String redisKey = CacheConstants.ADAPAY_ORDER_PARAM + dto.getOrderCode();
Map<String, Object> cacheObject = redisCache.getCacheObject(redisKey);
if (cacheObject != null) {
Map<String, Object> resultMap = redisCache.getCacheObject(redisKey);
if (resultMap != null) {
// 表示已经获取到支付参数了,后续再有支付请求就拒绝
return cacheObject;
return resultMap;
}
// 获取支付配置
@@ -148,21 +149,21 @@ public class AdapayService {
}
JSONObject expend = JSONObject.parseObject(response.get("expend").toString());
JSONObject pay_info = expend.getJSONObject("pay_info");
Map<String, Object> resultMap = JSONObject.parseObject(pay_info.toJSONString(), new TypeReference<Map<String, Object>>() {
});
if (resultMap != null) {
// 请求参数放入缓存15分钟以内返回同一个支付参数
redisCache.setCacheObject(redisKey, resultMap, 15, TimeUnit.MINUTES);
// 请求订单号放redis
redisCache.setCacheObject(CacheConstants.ORDER_WECHAT_PAY_PARAMETERS + dto.getOrderCode(), orderNo, 30, TimeUnit.MINUTES);
}
return resultMap;
resultMap = JSONObject.parseObject(pay_info.toJSONString(), new TypeReference<Map<String, Object>>() {});
}
} catch (BaseAdaPayException e) {
log.error("汇付-获取支付对象发生异常", e);
log.error("汇付-获取支付对象发生异常, orderCode:{}", dto.getOrderCode(), e);
}
return null;
// 放缓存
if (resultMap != null) {
// 请求参数放入缓存15分钟以内返回同一个支付参数
redisCache.setCacheObject(redisKey, resultMap, 15, TimeUnit.MINUTES);
// 请求订单号放redis
redisCache.setCacheObject(CacheConstants.ORDER_WECHAT_PAY_PARAMETERS + dto.getOrderCode(), orderNo, 30, TimeUnit.MINUTES);
}
return resultMap;
}
/**
@@ -1192,10 +1193,29 @@ public class AdapayService {
return resultList;
}
/**
* 根据请求号,查询支付信息列表
*/
public List<PaymentInfo> queryPaymentInfosByOrderNo(String orderNo, String wechatAppId) throws BaseAdaPayException {
List<PaymentInfo> resultList = Lists.newArrayList();
List<AdaPayment> adaPayments = queryPaymentsByOrderNo(orderNo, wechatAppId);
if (CollectionUtils.isEmpty(adaPayments)) {
return resultList;
}
for (AdaPayment adaPayment : adaPayments) {
PaymentInfo paymentInfo = PaymentInfo.builder()
.paymentId(adaPayment.getId())
.amount(adaPayment.getPay_amt())
.build();
resultList.add(paymentInfo);
}
return resultList;
}
/**
* 查询支付列表
*/
public List<AdaPayment> queryPaymentByOrderNo(String orderNo, String wechatAppId) throws BaseAdaPayException {
public List<AdaPayment> queryPaymentsByOrderNo(String orderNo, String wechatAppId) throws BaseAdaPayException {
List<AdaPayment> resultList = Lists.newArrayList();
AbstractAdapayConfig config = AdapayConfigFactory.getConfig(wechatAppId);
if (config == null) {
@@ -1215,13 +1235,13 @@ public class AdapayService {
queryListParam.put("page_size", pageSize);
queryListParam.put("order_no", orderNo);
System.out.println("查询支付对象列表请求参数:" + JSON.toJSONString(queryListParam));
// System.out.println("查询支付对象列表请求参数:" + JSON.toJSONString(queryListParam));
Map<String, Object> paymentListResult = Payment.queryList(queryListParam, wechatAppId);
if (paymentListResult == null) {
break;
}
String jsonString = JSON.toJSONString(paymentListResult);
System.out.println("查询支付对象列表result" + jsonString);
// System.out.println("查询支付对象列表result" + jsonString);
JSONObject jsonObject = JSON.parseObject(jsonString);
List<AdaPayment> list = jsonObject.getList("payments", AdaPayment.class, JSONReader.Feature.FieldBased);

View File

@@ -1,14 +1,34 @@
package com.jsowell.adapay.vo;
import lombok.Getter;
import lombok.Setter;
import lombok.*;
import java.util.Objects;
/**
* 付款信息对象
*/
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class PaymentInfo {
// 支付id
private String paymentId;
// 金额
private String amount;
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
PaymentInfo that = (PaymentInfo) o;
return paymentId.equals(that.paymentId);
}
@Override
public int hashCode() {
return Objects.hash(paymentId);
}
}