Commit 1ed494fe by 查志伟

订单支付商品名称查询优化

parent e3cf46d0
......@@ -31,9 +31,15 @@ public class KgdRedisKeyConstant {
public static final String ORDER_COMPLAIN_TYPE = "orderComplaintType";
/**
* 下单时 支付商品名称redis缓存key,懒加载方式,有效时间为24小时
* {0}:商户号
*
* value:hash结构
* hashKey:小程序id wxAppId
* hashValue: 支付商户名称
*/
public static final String PARTNER_PAYMENT_PRINCIPAL_NAME = "kgd:order:payment:principalName:{0}";
}
......@@ -3,6 +3,7 @@ package cn.freemud.service.impl;
import cn.freemud.adapter.OrderAdapter;
import cn.freemud.base.entity.BaseResponse;
import cn.freemud.base.util.DateUtil;
import cn.freemud.constant.KgdRedisKeyConstant;
import cn.freemud.constant.RedisKeyConstant;
import cn.freemud.constant.ResponseCodeConstant;
import cn.freemud.entities.dto.SvcComPayRequestDto;
......@@ -84,6 +85,7 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.text.MessageFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
......@@ -457,15 +459,21 @@ public class PayServiceImpl {
/**
* 处理定制化逻辑
* 查询支付配置
*/
private PaymentRequest orderBodyConvertToPaymentBody(String openId, String partnerId, String appId, String payCode, String storeId) {
PaymentRequest paymentRequest = this.orderBodyConvertToPaymentBody(openId, partnerId, appId, payCode);
// fisherman 2227 测试商户号, 下个版本需要删除
boolean isTrue = "2080".equals(partnerId);
if (isTrue) {
//设置支付信息
PaymentRequest paymentRequest = new PaymentRequest();
paymentRequest.setOpenId(openId);
paymentRequest.setWxAppId(appId);
paymentRequest.setReverseNotifyiDcUrl(reverseNotifyiDcUrl);
paymentRequest.setPayCode(payCode);
if ("2080".equals(partnerId)) {
//【ID1035981】【蜜雪冰城】订单C端,拼接order_body字段:蜜雪冰城+门店编号
paymentRequest.setPrincipalName("蜜雪冰城" + storeId + "店");
} else {
// saas 查询小程序配置
paymentRequest.setPrincipalName(this.getPaymentPrincipalName(partnerId, appId));
}
return paymentRequest;
}
......@@ -473,20 +481,28 @@ public class PayServiceImpl {
/**
* 查询支付配置
*/
private PaymentRequest orderBodyConvertToPaymentBody(String openId, String partnerId, String appId, String payCode) {
//设置支付信息
PaymentRequest paymentRequest = new PaymentRequest();
paymentRequest.setOpenId(openId);
paymentRequest.setWxAppId(appId);
private String getPaymentPrincipalName(String partnerId, String appId) {
String redisKey = MessageFormat.format(KgdRedisKeyConstant.PARTNER_PAYMENT_PRINCIPAL_NAME, partnerId);
// 先从redis中查询支付商户名称
String principalName = redisCache.hashGet(redisKey, appId);
if (StringUtils.isEmpty(principalName)) {
AssortmentOpenPlatformWxapp wxApp = openPlatformWxappManager.findByPartnerIdAndWxappId(partnerId, appId);
AssortmentOpenPlatformPartner platformPartner = null;
if (wxApp == null) {
platformPartner = assortmentOpenPlatformPartnerManager.selectOpenPlatformPartner(partnerId);
if (wxApp == null || StringUtils.isEmpty(wxApp.getPrincipalName())) {
// 小程序如果没有配置支付商户名称,则去商户名称替代
AssortmentOpenPlatformPartner platformPartner = assortmentOpenPlatformPartnerManager.selectOpenPlatformPartner(partnerId);
if (null != platformPartner) principalName = platformPartner.getCompanyName();
} else {
principalName = wxApp.getPrincipalName();
}
paymentRequest.setPrincipalName(wxApp != null ? wxApp.getPrincipalName() : platformPartner != null ? platformPartner.getCompanyName() : "上海非码网络科技有限公司");
paymentRequest.setReverseNotifyiDcUrl(reverseNotifyiDcUrl);
paymentRequest.setPayCode(payCode);
return paymentRequest;
if (StringUtils.isEmpty(principalName)) {
//如果还是没有查到,就用非码代替
principalName = "上海非码网络科技有限公司";
}
// 加载到redis,有效期一天
redisCache.hashPut(redisKey, appId, principalName);
redisCache.updateTTL(redisKey, 24, TimeUnit.HOURS);
}
return principalName;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment