Merge remote-tracking branch 'origin/hph' into test

This commit is contained in:
牛叉闪闪 2024-09-05 11:07:13 +08:00
commit 3234ba957f
2 changed files with 58 additions and 4 deletions

View File

@ -1,7 +1,10 @@
package com.chaozhanggui.system.cashierservice.interceptor;
import com.chaozhanggui.system.cashierservice.annotation.LimitSubmit;
import com.chaozhanggui.system.cashierservice.entity.TbOrderDetail;
import com.chaozhanggui.system.cashierservice.entity.dto.VipPayDTO;
import com.chaozhanggui.system.cashierservice.exception.MsgException;
import com.chaozhanggui.system.cashierservice.model.PaymentReq;
import com.chaozhanggui.system.cashierservice.util.RedisUtils;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
@ -13,6 +16,7 @@ import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
import org.springframework.stereotype.Component;
import java.lang.reflect.Method;
import java.util.List;
@Component
@Aspect
@ -36,6 +40,7 @@ public class LimitSubmitAspect {
Method method = ((MethodSignature) joinPoint.getSignature()).getMethod();
Object[] args= joinPoint.getArgs();
String orderId=orderId(method,args);
//获取注解信息
LimitSubmit limitSubmit = method.getAnnotation(LimitSubmit.class);
@ -44,7 +49,7 @@ public class LimitSubmitAspect {
int submitTimeLimiter = limitSubmit.limit();
String key = getRedisKey(joinPoint, redisKey, String.valueOf(args[0]));
String key = getRedisKey(joinPoint, redisKey, orderId);
Object result = redisUtil.get(key);
log.info("开始锁定资源信息" + key);
@ -79,9 +84,18 @@ public class LimitSubmitAspect {
Method method = ((MethodSignature) joinPoint.getSignature()).getMethod();
Object[] args= joinPoint.getArgs();
String orderId=orderId(method,args);
LimitSubmit limitSubmit = method.getAnnotation(LimitSubmit.class);
String redisKey = limitSubmit.key();
String key = getRedisKey1(joinPoint, redisKey, String.valueOf(args[0]));
String key = getRedisKey1(joinPoint, redisKey,orderId);
log.info("正常释放了锁资源" + key);
// 延时 1s 释放
try {
@ -104,7 +118,8 @@ public class LimitSubmitAspect {
LimitSubmit limitSubmit = method.getAnnotation(LimitSubmit.class);
String redisKey = limitSubmit.key();
Object[] args= joinPoint.getArgs();
String key = getRedisKey1(joinPoint, redisKey, String.valueOf(args[0]));
String orderId=orderId(method,args);
String key = getRedisKey1(joinPoint, redisKey, orderId);
log.info("发生异常释放了锁资源" + key);
// 延时 1s 释放
try {
@ -158,4 +173,40 @@ public class LimitSubmitAspect {
}
return key.toString();
}
private String orderId(Method method,Object[] args){
String orderId=null;
if("scanpay".equals(method.getName())||
"accountPay".equals(method.getName())||
"memberScanPay".equals(method.getName())||
"cashPay".equals(method.getName())||
"bankPay".equals(method.getName())){
Object o=args[3];
if(o instanceof PaymentReq){
orderId=((PaymentReq)o).getOrderId();
}
}else if("vipPay".equals(method.getName())){
Object o=args[3];
if(o instanceof VipPayDTO){
orderId=((VipPayDTO)o).getOrderId().toString();
}
}else if("quickPay".equals(method.getName())) {
Object o=args[4];
if(o instanceof String){
orderId=o.toString();
}
}else if ("returnOrder".equals(method.getName())) {
Object o=args[3];
if(o instanceof List){
orderId= ((List<TbOrderDetail>)o).get(0).getOrderId().toString();
}
}
return orderId;
}
}

View File

@ -27,6 +27,9 @@ public class WebAppConfigurer implements WebMvcConfigurer {
.excludePathPatterns("/qrcode/getscanCode")
.excludePathPatterns("/order/sendMessage")
.excludePathPatterns("/order/getOrderById")
.excludePathPatterns("/data/handoverprint");
.excludePathPatterns("/data/handoverprint")
;
}
}