From 6ab3c82b1cea30811d8a2763fa2e273b468823a6 Mon Sep 17 00:00:00 2001 From: Rui_Li <877258667@qq.com> Date: Tue, 22 Feb 2022 13:13:51 +0800 Subject: [PATCH] =?UTF-8?q?=E9=98=B2=E9=87=8D=E5=A4=8D=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/annotation/RepeatSubmit.java | 25 ++++++ .../gaotao/common/aop/RepeatSubmitAspect.java | 76 +++++++++++++++++++ .../controller/ScheduleController.java | 3 + .../service/impl/ScheduleServiceImpl.java | 14 +++- 4 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/gaotao/common/annotation/RepeatSubmit.java create mode 100644 src/main/java/com/gaotao/common/aop/RepeatSubmitAspect.java diff --git a/src/main/java/com/gaotao/common/annotation/RepeatSubmit.java b/src/main/java/com/gaotao/common/annotation/RepeatSubmit.java new file mode 100644 index 0000000..9ea1ac3 --- /dev/null +++ b/src/main/java/com/gaotao/common/annotation/RepeatSubmit.java @@ -0,0 +1,25 @@ +package com.gaotao.common.annotation; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * @ClassName: RepeatSubmit + * @Description: 自定义重复提交的注解 + * @author LR + * @date 2020年4月16日 + * @version V1.0 + */ +@Target(value = {ElementType.METHOD}) +@Retention(value = RetentionPolicy.RUNTIME) +@Inherited +@Documented +public @interface RepeatSubmit { + +} + + diff --git a/src/main/java/com/gaotao/common/aop/RepeatSubmitAspect.java b/src/main/java/com/gaotao/common/aop/RepeatSubmitAspect.java new file mode 100644 index 0000000..d226e5b --- /dev/null +++ b/src/main/java/com/gaotao/common/aop/RepeatSubmitAspect.java @@ -0,0 +1,76 @@ +package com.gaotao.common.aop; + +import java.util.concurrent.TimeUnit; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import com.gaotao.modules.sys.entity.SysUserEntity; +import org.apache.commons.lang3.StringUtils; +import org.apache.shiro.SecurityUtils; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Pointcut; +import org.springframework.stereotype.Component; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; + +import com.google.common.cache.Cache; +import com.google.common.cache.CacheBuilder; + +/** + * @ClassName: RepeatSubmitAspect + * @Description: 自定义注释切点 + * @author LR + * @date 2020年4月17日 + * @version V1.0 + */ +@Component +@Aspect +public class RepeatSubmitAspect { + + //缓存数据存放 + private static final Cache caches = CacheBuilder.newBuilder() + .maximumSize(10000).expireAfterWrite(5, TimeUnit.SECONDS).build(); + + //切点 + @Pointcut("@annotation(com.gaotao.common.annotation.RepeatSubmit)") + public void pointCut() {} + + //处理业务逻辑 + @Around("pointCut()") + public Object submitAop(ProceedingJoinPoint pjp) throws Exception { + //获取request + ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); + HttpServletRequest request = attributes.getRequest(); + String url = request.getRequestURI(); + SysUserEntity currentUser = (SysUserEntity) SecurityUtils.getSubject().getPrincipal(); + //判断是否是否null + if(null == currentUser) { + HttpServletResponse response = attributes.getResponse(); + response.sendError(HttpServletResponse.SC_FORBIDDEN, "Session is expired!"); + return response; + } + String username = currentUser.getUsername(); + //根据用户id+url作为唯一识别的请求 + String key = username + "-" + url; + //空值校验 + if(!StringUtils.isEmpty(key)) { + //判断是否患有当前的key + if(caches.getIfPresent(key) == null) { + caches.put(key, key); + }else { + HttpServletResponse response = attributes.getResponse(); + response.sendError(500, "重复提交!"); + return response; + } + } + //通过检验继续操作 + try { + return pjp.proceed(); + } catch (Throwable e) { + throw new RuntimeException(e.getMessage()); + } + } +} \ No newline at end of file diff --git a/src/main/java/com/gaotao/modules/schedule/controller/ScheduleController.java b/src/main/java/com/gaotao/modules/schedule/controller/ScheduleController.java index 5995180..de9d820 100644 --- a/src/main/java/com/gaotao/modules/schedule/controller/ScheduleController.java +++ b/src/main/java/com/gaotao/modules/schedule/controller/ScheduleController.java @@ -1,6 +1,7 @@ package com.gaotao.modules.schedule.controller; import com.gaotao.common.utils.R; +import com.gaotao.common.annotation.RepeatSubmit; import com.gaotao.modules.schedule.data.*; import com.gaotao.modules.schedule.service.ScheduleService; import com.gaotao.modules.shopOrder.entity.OperatorData; @@ -514,6 +515,7 @@ public class ScheduleController { * @return com.gaotao.common.utils.R **/ @RequestMapping(value = "checkScheduleButton") + @RepeatSubmit public R checkScheduleButton(@RequestBody SearchScheduleData inData){ Map resultMap = scheduleService.checkScheduleButton(inData); return R.ok() @@ -530,6 +532,7 @@ public class ScheduleController { * @return com.gaotao.common.utils.R **/ @RequestMapping(value = "createNewRoll") + @RepeatSubmit public R createNewRoll(@RequestBody SearchScheduleData inData){ scheduleService.createNewRoll(inData); return R.ok() diff --git a/src/main/java/com/gaotao/modules/schedule/service/impl/ScheduleServiceImpl.java b/src/main/java/com/gaotao/modules/schedule/service/impl/ScheduleServiceImpl.java index 57e3993..3eea323 100644 --- a/src/main/java/com/gaotao/modules/schedule/service/impl/ScheduleServiceImpl.java +++ b/src/main/java/com/gaotao/modules/schedule/service/impl/ScheduleServiceImpl.java @@ -80,6 +80,17 @@ public class ScheduleServiceImpl implements ScheduleService { @Override public OperatorOutData getOperatorData(OperatorOutData inData) { + //查到需要做判断 + OperatorOutData operatorData = scheduleMapper.getOperatorData(inData); + //判断是否存在 + if(null == operatorData){ + throw new RRException("用户不存在!"); + } + //判断是否停用 + String status = operatorData.getStatus(); + if("N".equalsIgnoreCase(status)){ + throw new RRException("用户已停用!"); + } return scheduleMapper.getOperatorData(inData); } @@ -93,7 +104,8 @@ public class ScheduleServiceImpl implements ScheduleService { SfdcRollOpsData result = scheduleMapper.getCurrentRollOpsBySeqNo(inData); //判断是否查询到结果 if (null == result) { - throw new RRException("不存在上机卷!"); + result = new SfdcRollOpsData(); + result.setRollNo("暂无卷号"); } return result; }