update 查询支付回调记录加缓存

This commit is contained in:
2023-05-30 16:20:03 +08:00
parent 6e8b06b433
commit 53bb941e7c
6 changed files with 58 additions and 8 deletions

View File

@@ -1,6 +1,8 @@
package com.jsowell.pile.service.impl;
import com.alibaba.fastjson2.JSON;
import com.jsowell.common.constant.CacheConstants;
import com.jsowell.common.core.redis.RedisCache;
import com.jsowell.common.util.StringUtils;
import com.jsowell.pile.domain.AdapayCallbackRecord;
import com.jsowell.pile.mapper.AdapayCallbackRecordMapper;
import com.jsowell.pile.service.AdapayCallbackRecordService;
@@ -15,20 +17,39 @@ public class AdapayCallbackRecordServiceImpl implements AdapayCallbackRecordServ
@Autowired
private AdapayCallbackRecordMapper adapayCallbackRecordMapper;
@Autowired
private RedisCache redisCache;
@Override
public void saveAdapayCallbackRecord(AdapayCallbackRecord callbackRecord) {
adapayCallbackRecordMapper.insert(callbackRecord);
}
/**
* 根据订单号查询支付回调信息
* @param orderCode
* @return
*/
@Override
public AdapayCallbackRecord selectByOrderCode(String orderCode) {
AdapayCallbackRecord record = null;
if (StringUtils.isBlank(orderCode)) {
return null;
}
String redisKey = CacheConstants.QUERY_ORDER_CALLBACK + orderCode;
AdapayCallbackRecord record = redisCache.getCacheObject(redisKey);
if (record != null) {
return record;
}
// AdapayCallbackRecord record = null;
try {
record = adapayCallbackRecordMapper.selectByOrderCode(orderCode);
if (record != null) {
redisCache.setCacheObject(redisKey, record, CacheConstants.cache_expire_time_1d);
}
} catch (Exception e) {
log.error("查询汇付支付回调记录失败", e);
}
log.info("查询汇付支付回调记录 orderCode:{}, result:{}", orderCode, JSON.toJSONString(record));
// log.info("查询汇付支付回调记录 orderCode:{}, result:{}", orderCode, JSON.toJSONString(record));
return record;
}
}

View File

@@ -169,10 +169,11 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
if (CollectionUtils.isNotEmpty(orderListVOS)) {
for (OrderListVO orderListVO : orderListVOS) {
// 如果是微信支付,通过订单号查询微信支付单号
logger.info("如果是微信支付,通过订单号查询微信支付单号 orderListVO:{}", JSON.toJSONString(orderListVO));
if (StringUtils.equals(PaymentInstitutionsEnum.ADAPAY.getValue(), orderListVO.getPaymentInstitutions())) {
AdapayCallbackRecord adapayCallbackRecord = adapayCallbackRecordService.selectByOrderCode(orderListVO.getOrderCode());
orderListVO.setOutTradeNo(adapayCallbackRecord.getPaymentId());
} else {
} else if (StringUtils.equals(PaymentInstitutionsEnum.WECHAT_PAY.getValue(), orderListVO.getPaymentInstitutions())){
WxpayCallbackRecord wxpayCallbackRecord = wxpayCallbackRecordService.selectByOrderCode(orderListVO.getOrderCode());
orderListVO.setOutTradeNo(wxpayCallbackRecord.getOutTradeNo());
}

View File

@@ -1,9 +1,13 @@
package com.jsowell.pile.service.impl;
import com.jsowell.common.constant.CacheConstants;
import com.jsowell.common.core.redis.RedisCache;
import com.jsowell.common.util.StringUtils;
import com.jsowell.pile.domain.WxpayCallbackRecord;
import com.jsowell.pile.mapper.WxpayCallbackRecordMapper;
import com.jsowell.pile.service.WxpayCallbackRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@@ -19,6 +23,9 @@ public class WxpayCallbackRecordServiceImpl implements WxpayCallbackRecordServic
@Resource
private WxpayCallbackRecordMapper wxpayCallbackRecordMapper;
@Autowired
private RedisCache redisCache;
@Override
public int deleteByPrimaryKey(Integer id) {
return wxpayCallbackRecordMapper.deleteByPrimaryKey(id);
@@ -51,9 +58,20 @@ public class WxpayCallbackRecordServiceImpl implements WxpayCallbackRecordServic
@Override
public WxpayCallbackRecord selectByOrderCode(String orderCode) {
WxpayCallbackRecord wxpayCallbackRecord = null;
if (StringUtils.isBlank(orderCode)) {
return null;
}
String redisKey = CacheConstants.QUERY_ORDER_CALLBACK + orderCode;
WxpayCallbackRecord wxpayCallbackRecord = redisCache.getCacheObject(redisKey);
if (wxpayCallbackRecord != null) {
return wxpayCallbackRecord;
}
// WxpayCallbackRecord wxpayCallbackRecord = null;
try {
wxpayCallbackRecord = wxpayCallbackRecordMapper.selectByOrderCode(orderCode);
if (wxpayCallbackRecord != null) {
redisCache.setCacheObject(redisKey, wxpayCallbackRecord, CacheConstants.cache_expire_time_1d);
}
} catch (Exception e) {
log.error("根据订单号查询微信支付记录:{}", orderCode, e);
}

View File

@@ -5,6 +5,7 @@ import com.alibaba.fastjson2.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableMap;
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.ReturnCodeEnum;
@@ -78,7 +79,7 @@ public class WxAppletRemoteService {
// secret = properties.getAppSecret();
//查询token是否存在
String redisKey = "AccessToken_" + appid;
String redisKey = CacheConstants.ACCESS_TOKEN + appid;
// 使用缓存先查询AccessToken是否存在
String accessToken = redisCache.getCacheObject(redisKey);
// 存在直接返回不存在重新获取AccessToken