修改
This commit is contained in:
@@ -1,7 +1,10 @@
|
|||||||
package com.chaozhanggui.system.cashierservice.interceptor;
|
package com.chaozhanggui.system.cashierservice.interceptor;
|
||||||
|
|
||||||
import com.chaozhanggui.system.cashierservice.annotation.LimitSubmit;
|
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.exception.MsgException;
|
||||||
|
import com.chaozhanggui.system.cashierservice.model.PaymentReq;
|
||||||
import com.chaozhanggui.system.cashierservice.util.RedisUtils;
|
import com.chaozhanggui.system.cashierservice.util.RedisUtils;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.aspectj.lang.JoinPoint;
|
import org.aspectj.lang.JoinPoint;
|
||||||
@@ -13,6 +16,7 @@ import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
|
|||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
@Aspect
|
@Aspect
|
||||||
@@ -36,6 +40,7 @@ public class LimitSubmitAspect {
|
|||||||
Method method = ((MethodSignature) joinPoint.getSignature()).getMethod();
|
Method method = ((MethodSignature) joinPoint.getSignature()).getMethod();
|
||||||
|
|
||||||
Object[] args= joinPoint.getArgs();
|
Object[] args= joinPoint.getArgs();
|
||||||
|
String orderId=orderId(method,args);
|
||||||
|
|
||||||
//获取注解信息
|
//获取注解信息
|
||||||
LimitSubmit limitSubmit = method.getAnnotation(LimitSubmit.class);
|
LimitSubmit limitSubmit = method.getAnnotation(LimitSubmit.class);
|
||||||
@@ -44,7 +49,7 @@ public class LimitSubmitAspect {
|
|||||||
|
|
||||||
|
|
||||||
int submitTimeLimiter = limitSubmit.limit();
|
int submitTimeLimiter = limitSubmit.limit();
|
||||||
String key = getRedisKey(joinPoint, redisKey, String.valueOf(args[0]));
|
String key = getRedisKey(joinPoint, redisKey, orderId);
|
||||||
Object result = redisUtil.get(key);
|
Object result = redisUtil.get(key);
|
||||||
log.info("开始锁定资源信息" + key);
|
log.info("开始锁定资源信息" + key);
|
||||||
|
|
||||||
@@ -79,9 +84,18 @@ public class LimitSubmitAspect {
|
|||||||
Method method = ((MethodSignature) joinPoint.getSignature()).getMethod();
|
Method method = ((MethodSignature) joinPoint.getSignature()).getMethod();
|
||||||
|
|
||||||
Object[] args= joinPoint.getArgs();
|
Object[] args= joinPoint.getArgs();
|
||||||
|
String orderId=orderId(method,args);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
LimitSubmit limitSubmit = method.getAnnotation(LimitSubmit.class);
|
LimitSubmit limitSubmit = method.getAnnotation(LimitSubmit.class);
|
||||||
String redisKey = limitSubmit.key();
|
String redisKey = limitSubmit.key();
|
||||||
String key = getRedisKey1(joinPoint, redisKey, String.valueOf(args[0]));
|
String key = getRedisKey1(joinPoint, redisKey,orderId);
|
||||||
log.info("正常释放了锁资源" + key);
|
log.info("正常释放了锁资源" + key);
|
||||||
// 延时 1s 释放
|
// 延时 1s 释放
|
||||||
try {
|
try {
|
||||||
@@ -104,7 +118,8 @@ public class LimitSubmitAspect {
|
|||||||
LimitSubmit limitSubmit = method.getAnnotation(LimitSubmit.class);
|
LimitSubmit limitSubmit = method.getAnnotation(LimitSubmit.class);
|
||||||
String redisKey = limitSubmit.key();
|
String redisKey = limitSubmit.key();
|
||||||
Object[] args= joinPoint.getArgs();
|
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);
|
log.info("发生异常释放了锁资源" + key);
|
||||||
// 延时 1s 释放
|
// 延时 1s 释放
|
||||||
try {
|
try {
|
||||||
@@ -158,4 +173,40 @@ public class LimitSubmitAspect {
|
|||||||
}
|
}
|
||||||
return key.toString();
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -27,6 +27,9 @@ public class WebAppConfigurer implements WebMvcConfigurer {
|
|||||||
.excludePathPatterns("/qrcode/getscanCode")
|
.excludePathPatterns("/qrcode/getscanCode")
|
||||||
.excludePathPatterns("/order/sendMessage")
|
.excludePathPatterns("/order/sendMessage")
|
||||||
.excludePathPatterns("/order/getOrderById")
|
.excludePathPatterns("/order/getOrderById")
|
||||||
.excludePathPatterns("/data/handoverprint");
|
.excludePathPatterns("/data/handoverprint")
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ spring:
|
|||||||
application:
|
application:
|
||||||
name: cashierService
|
name: cashierService
|
||||||
datasource:
|
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
|
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: fycashier
|
username: cashier
|
||||||
password: Twc6MrzzjBiWSsjh
|
password: Cashier@1@
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
initialSize: 5
|
initialSize: 5
|
||||||
minIdle: 5
|
minIdle: 5
|
||||||
|
|||||||
Reference in New Issue
Block a user