From bca3381ec31f66599b5d04b30801f7f17c2ae567 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=89=9B=E5=8F=89=E9=97=AA=E9=97=AA?= <18322780655@163.com> Date: Thu, 5 Sep 2024 11:06:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../interceptor/LimitSubmitAspect.java | 57 ++++++++++++++++++- .../interceptor/WebAppConfigurer.java | 5 +- src/main/resources/application-dev.yml | 6 +- 3 files changed, 61 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/interceptor/LimitSubmitAspect.java b/src/main/java/com/chaozhanggui/system/cashierservice/interceptor/LimitSubmitAspect.java index 886b09c..f0fae54 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/interceptor/LimitSubmitAspect.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/interceptor/LimitSubmitAspect.java @@ -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)o).get(0).getOrderId().toString(); + } + } + + return orderId; + } } \ No newline at end of file diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/interceptor/WebAppConfigurer.java b/src/main/java/com/chaozhanggui/system/cashierservice/interceptor/WebAppConfigurer.java index 0977774..ff4c376 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/interceptor/WebAppConfigurer.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/interceptor/WebAppConfigurer.java @@ -27,6 +27,9 @@ public class WebAppConfigurer implements WebMvcConfigurer { .excludePathPatterns("/qrcode/getscanCode") .excludePathPatterns("/order/sendMessage") .excludePathPatterns("/order/getOrderById") - .excludePathPatterns("/data/handoverprint"); + .excludePathPatterns("/data/handoverprint") + ; + + } } diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index b49645c..8ceb21e 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -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