Commit 5d0798c5 by 李学兴

opt@feature/20210810_callbackUrgentPlan_lxx:# 紧急方案打开直接调用callback 逻辑

parent 0b80707f
...@@ -17,10 +17,28 @@ import lombok.Getter; ...@@ -17,10 +17,28 @@ import lombok.Getter;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.List;
@Component @Component
@Getter @Getter
public class ConfigConstants { public class ConfigConstants {
@Value("${print-debug-log:false}") @Value("${print-debug-log:false}")
private boolean printDebug; private boolean printDebug;
/**
* 紧急方案 涉及配置:开关 true=打开,默认是false
*/
@Value("${order.callback.urgent.plan.open:false}")
private boolean urgentCallbackOpen;
/**
* 紧急方案 涉及配置:锁定分钟
*/
@Value("${order.callback.urgent.plan.open.lock.minutes:30}")
private long urgentCallbackLockMinutes;
/**
* 紧急方案 涉及配置:锁定涉及订单状态列表
* 2=下单(支付成功);3=接单;
*/
@Value("${order.callback.urgent.plan.open.status:2,3}")
private List<Integer> urgentStatus;
} }
...@@ -18,5 +18,10 @@ public class RedisKeyConstant { ...@@ -18,5 +18,10 @@ public class RedisKeyConstant {
* userInfoMap的redisKey前缀 * userInfoMap的redisKey前缀
*/ */
public final static String SAAS_USER_INFO_SESSIONID_KEY_PREFIX = "saas:user:info:sessionId:"; public final static String SAAS_USER_INFO_SESSIONID_KEY_PREFIX = "saas:user:info:sessionId:";
/**
* 紧急方案 涉及配置:锁定key
* requestVo.getOrderCode(), requestVo.getOrderState(), requestVo.getOperateType(), requestVo.getMsgType()
*/
public final static String URGENT_CALLBACK_LOCK_KEY = "saas:order:%s:%s:%s:%s";
} }
...@@ -14,18 +14,20 @@ package cn.freemud.service.impl; ...@@ -14,18 +14,20 @@ package cn.freemud.service.impl;
import cn.freemud.amp.service.OrderCallBackMQService; import cn.freemud.amp.service.OrderCallBackMQService;
import cn.freemud.base.entity.BaseResponse; import cn.freemud.base.entity.BaseResponse;
import cn.freemud.constant.ConfigConstants;
import cn.freemud.constant.RedisKeyConstant;
import cn.freemud.service.OrderCallBackService; import cn.freemud.service.OrderCallBackService;
import com.freemud.api.assortment.datamanager.util.RedisLock; import com.freemud.api.assortment.datamanager.util.RedisLock;
import com.freemud.application.sdk.api.log.ApiLog; import com.freemud.application.sdk.api.log.ApiLog;
import com.freemud.application.sdk.api.ordercenter.entities.vo.OrderCallBackRequestVo; import com.freemud.application.sdk.api.ordercenter.entities.vo.OrderCallBackRequestVo;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@Service @Service
public class OrderCallBackServiceImpl implements OrderCallBackService{ public class OrderCallBackServiceImpl implements OrderCallBackService{
...@@ -39,18 +41,15 @@ public class OrderCallBackServiceImpl implements OrderCallBackService{ ...@@ -39,18 +41,15 @@ public class OrderCallBackServiceImpl implements OrderCallBackService{
public static final String MSG_TYPE_1 = "1"; public static final String MSG_TYPE_1 = "1";
@Autowired @Autowired
private OrderCallBackMQService mqService; private OrderCallBackMQService mqService;
@Autowired
@Value("${order.callback.urgent.plan.open:false}") private ConfigConstants configConstants;
private boolean urgentCallbackOpen;
@Value("${order.callback.urgent.plan.open.lock.minutes:30}")
private long urgentCallbackLockMinutes;
@Autowired @Autowired
private RedisTemplate redisTemplate; private RedisTemplate redisTemplate;
@Override @Override
public BaseResponse orderCallBackHandle(OrderCallBackRequestVo requestVo) { public BaseResponse orderCallBackHandle(OrderCallBackRequestVo requestVo) {
//紧急方案打开 且是正向单时步入 锁控制代码 //紧急方案打开 且是正向单时步入 锁控制代码
if (urgentCallbackOpen && Objects.equals(OPERATE_TYPE_1, requestVo.getOperateType()) && if (configConstants.isUrgentCallbackOpen() && configConstants.getUrgentStatus().contains(requestVo.getOrderState()) && Objects.equals(OPERATE_TYPE_1, requestVo.getOperateType()) &&
Objects.equals(MSG_TYPE_1, requestVo.getMsgType())) { Objects.equals(MSG_TYPE_1, requestVo.getMsgType())) {
this.urgentCallbackHandle(requestVo); this.urgentCallbackHandle(requestVo);
} else { } else {
...@@ -61,11 +60,11 @@ public class OrderCallBackServiceImpl implements OrderCallBackService{ ...@@ -61,11 +60,11 @@ public class OrderCallBackServiceImpl implements OrderCallBackService{
private void urgentCallbackHandle(OrderCallBackRequestVo requestVo) { private void urgentCallbackHandle(OrderCallBackRequestVo requestVo) {
RedisLock redisLock = RedisLock.getInstance(redisTemplate); RedisLock redisLock = RedisLock.getInstance(redisTemplate);
String lockKey = new StringBuilder().append(requestVo.getOrderCode()).append("_").append(requestVo.getOperateType()) String lockKey = String.format(RedisKeyConstant.URGENT_CALLBACK_LOCK_KEY, requestVo.getOrderCode(),
.append("_").append(requestVo.getMsgType()).toString(); requestVo.getOrderState(), requestVo.getOperateType(), requestVo.getMsgType());
try { try {
//简单控制,不考虑解他锁问题 //简单控制,不考虑解他锁问题
if (!redisLock.lock(lockKey, Long.valueOf(TimeUnit.MINUTES.toSeconds(urgentCallbackLockMinutes)).intValue())) { if (!redisLock.lock(lockKey, Long.valueOf(TimeUnit.MINUTES.toSeconds(configConstants.getUrgentCallbackLockMinutes())).intValue())) {
ApiLog.infoMessage("订单orderCode:{} callback获取锁失败,lockKey:{}", requestVo.getOrderCode(), lockKey); ApiLog.infoMessage("订单orderCode:{} callback获取锁失败,lockKey:{}", requestVo.getOrderCode(), lockKey);
return; return;
} }
......
...@@ -349,6 +349,7 @@ public class SaasOrderHandle { ...@@ -349,6 +349,7 @@ public class SaasOrderHandle {
orderResp.setOrderState(orderState); orderResp.setOrderState(orderState);
} }
notifyDto.setContent(JSON.toJSONString(orderResp)); notifyDto.setContent(JSON.toJSONString(orderResp));
notifyDto.setOrderState(orderState);
notifyDto.setPartnerId(orderResp.getPartnerId()); notifyDto.setPartnerId(orderResp.getPartnerId());
notifyDto.setRequestId(UUID.randomUUID().toString().replaceAll("-", "")); notifyDto.setRequestId(UUID.randomUUID().toString().replaceAll("-", ""));
notifyDto.setOperateType(operateType != null ? operateType : 1); notifyDto.setOperateType(operateType != null ? operateType : 1);
......
...@@ -60,4 +60,9 @@ public class OrderCallBackRequestVo { ...@@ -60,4 +60,9 @@ public class OrderCallBackRequestVo {
* 请求ID * 请求ID
*/ */
private String requestId; private String requestId;
/**
* 默认为待支付状态,如需要则设置对应的值
*/
private Integer orderState;
} }
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