This commit is contained in:
牛叉闪闪
2024-09-05 11:06:36 +08:00
parent 9f62cd4165
commit bca3381ec3
3 changed files with 61 additions and 7 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")
;
}
}

View File

@@ -4,9 +4,9 @@ spring:
application:
name: cashierService
datasource:
url: jdbc:mysql://101.37.12.135:3306/fycashier?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&useJDBCCompliantTimezoneShift=true&serverTimezone=Asia/Shanghai&useSSL=false&allowMultiQueries=true
username: fycashier
password: Twc6MrzzjBiWSsjh
url: jdbc:mysql://rm-bp1kn7h89nz62cno1ro.mysql.rds.aliyuncs.com:3306/fycashier_test?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&useJDBCCompliantTimezoneShift=true&serverTimezone=Asia/Shanghai&useSSL=false&allowMultiQueries=true
username: cashier
password: Cashier@1@
driver-class-name: com.mysql.cj.jdbc.Driver
initialSize: 5
minIdle: 5