From f375432e7d2fdd126f5b64d4d4d1e96657ba5049 Mon Sep 17 00:00:00 2001 From: paulGao Date: Tue, 13 Sep 2022 11:33:39 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=B8=BA=E9=83=A8=E5=88=86=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E6=8D=95=E6=8D=89=E6=B7=BB=E5=8A=A0=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../limit/interceptor/LimitInterceptor.java | 16 ++++++++-------- .../PreventDuplicateSubmissionsInterceptor.java | 1 + .../service/impl/VerificationServiceImpl.java | 1 + 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/framework/src/main/java/cn/lili/cache/limit/interceptor/LimitInterceptor.java b/framework/src/main/java/cn/lili/cache/limit/interceptor/LimitInterceptor.java index 402f165d..1be580ce 100644 --- a/framework/src/main/java/cn/lili/cache/limit/interceptor/LimitInterceptor.java +++ b/framework/src/main/java/cn/lili/cache/limit/interceptor/LimitInterceptor.java @@ -45,21 +45,20 @@ public class LimitInterceptor { @Before("@annotation(limitPointAnnotation)") public void interceptor(LimitPoint limitPointAnnotation) { LimitTypeEnums limitTypeEnums = limitPointAnnotation.limitType(); - String name = limitPointAnnotation.name(); + String key; int limitPeriod = limitPointAnnotation.period(); int limitCount = limitPointAnnotation.limit(); - switch (limitTypeEnums) { - case CUSTOMER: - key = limitPointAnnotation.key(); - break; - default: - key = limitPointAnnotation.key() + IpUtils - .getIpAddress(((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest()); + if (limitTypeEnums == LimitTypeEnums.CUSTOMER) { + key = limitPointAnnotation.key(); + } else { + key = limitPointAnnotation.key() + IpUtils + .getIpAddress(((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest()); } ImmutableList keys = ImmutableList.of(StringUtils.join(limitPointAnnotation.prefix(), key)); try { Number count = redisTemplate.execute(limitScript, keys, limitCount, limitPeriod); + assert count != null; log.info("限制请求{}, 当前请求{},缓存key{}", limitCount, count.intValue(), key); //如果缓存里没有值,或者他的值小于限制频率 if (count.intValue() >= limitCount) { @@ -72,6 +71,7 @@ public class LimitInterceptor { } catch (ServiceException e) { throw e; } catch (Exception e) { + log.error("限流异常", e); throw new ServiceException(ResultCode.ERROR); } } diff --git a/framework/src/main/java/cn/lili/common/aop/interceptor/PreventDuplicateSubmissionsInterceptor.java b/framework/src/main/java/cn/lili/common/aop/interceptor/PreventDuplicateSubmissionsInterceptor.java index 8f6decfe..9a860444 100644 --- a/framework/src/main/java/cn/lili/common/aop/interceptor/PreventDuplicateSubmissionsInterceptor.java +++ b/framework/src/main/java/cn/lili/common/aop/interceptor/PreventDuplicateSubmissionsInterceptor.java @@ -47,6 +47,7 @@ public class PreventDuplicateSubmissionsInterceptor { } catch (ServiceException e) { throw e; } catch (Exception e) { + log.error("防重复提交拦截器异常", e); throw new ServiceException(ResultCode.ERROR); } } diff --git a/framework/src/main/java/cn/lili/modules/verification/service/impl/VerificationServiceImpl.java b/framework/src/main/java/cn/lili/modules/verification/service/impl/VerificationServiceImpl.java index dd4b5894..edf3c9f5 100644 --- a/framework/src/main/java/cn/lili/modules/verification/service/impl/VerificationServiceImpl.java +++ b/framework/src/main/java/cn/lili/modules/verification/service/impl/VerificationServiceImpl.java @@ -96,6 +96,7 @@ public class VerificationServiceImpl implements VerificationService { } catch (ServiceException e) { throw e; } catch (Exception e) { + log.error("生成验证码失败", e); throw new ServiceException(ResultCode.ERROR); } }