| 
						
						
							
								
							
						
						
					 | 
					@ -20,6 +20,7 @@ import java.util.concurrent.TimeUnit; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					/** | 
					 | 
					 | 
					/** | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 * desc:利用用户token及请求url 防止用户重复提交,需要在没有唯一索引的保存或修改操作 方法入口上加上@NoRepeatSubMit注解 | 
					 | 
					 | 
					 * desc:利用用户token及请求url 防止用户重复提交,需要在没有唯一索引的保存或修改操作 方法入口上加上@NoRepeatSubMit注解 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					 * | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 * @author zhaoqifeng | 
					 | 
					 | 
					 * @author zhaoqifeng | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 * @dscription | 
					 | 
					 | 
					 * @dscription | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 * @date 2020/11/24 9:59 | 
					 | 
					 | 
					 * @date 2020/11/24 9:59 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					@ -34,7 +35,7 @@ public class NoRepeatSubmitAop { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    private DistributedLock distributedLock; | 
					 | 
					 | 
					    private DistributedLock distributedLock; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    @Around("@annotation(noRepeatSubmit)") | 
					 | 
					 | 
					    @Around("@annotation(noRepeatSubmit)") | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
						public Object around(ProceedingJoinPoint pjp,NoRepeatSubmit noRepeatSubmit) { | 
					 | 
					 | 
					    public Object around(ProceedingJoinPoint pjp, NoRepeatSubmit noRepeatSubmit) { | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        try { | 
					 | 
					 | 
					        try { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); | 
					 | 
					 | 
					            ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					@ -44,21 +45,23 @@ public class NoRepeatSubmitAop { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            String key = getKey(request.getRequestURI(), internalToken); | 
					 | 
					 | 
					            String key = getKey(request.getRequestURI(), internalToken); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            // 如果缓存中有这个url视为重复提交
 | 
					 | 
					 | 
					            // 如果缓存中有这个url视为重复提交
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            Object result = null; | 
					 | 
					 | 
					            Object result = null; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            RLock lock = null; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            try { | 
					 | 
					 | 
					            try { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                long leaseTime = noRepeatSubmit.leaseTime(); | 
					 | 
					 | 
					                long leaseTime = noRepeatSubmit.leaseTime(); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                //如果获取不到锁等待0秒直接返回 持锁时间为leaseTime
 | 
					 | 
					 | 
					                //如果获取不到锁等待0秒直接返回 持锁时间为leaseTime
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					                RLock lock = distributedLock.getLock(RedisKeys.getNoRepeatSubmitKey(key), leaseTime, NumConstant.ZERO_L, TimeUnit.MILLISECONDS); | 
					 | 
					 | 
					                lock = distributedLock.getLock(RedisKeys.getNoRepeatSubmitKey(key), leaseTime, NumConstant.ZERO_L, TimeUnit.MILLISECONDS); | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            } catch (Exception e) { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					                log.warn("noRepeatSubmit key:{},msg:{}", key, e.getMessage()); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					                //"未获取到锁,重复提交了
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					                throw new RenException(EpmetErrorCode.REPEAT_SUBMIT.getCode()); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            try { | 
					 | 
					 | 
					            try { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                //因为getLock如果获取失败抛异常 所以不做锁状态的判断
 | 
					 | 
					 | 
					                //因为getLock如果获取失败抛异常 所以不做锁状态的判断
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                result = pjp.proceed(); | 
					 | 
					 | 
					                result = pjp.proceed(); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            } finally { | 
					 | 
					 | 
					            } finally { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                distributedLock.unLock(lock); | 
					 | 
					 | 
					                distributedLock.unLock(lock); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            } | 
					 | 
					 | 
					            } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					            } catch (Exception e) { | 
					 | 
					 | 
					
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					 | 
					 | 
					               log.warn("noRepeatSubmit exception",e); | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                //"未获取到锁,重复提交了
 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                throw new RenException(EpmetErrorCode.REPEAT_SUBMIT.getCode()); | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            } | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            return result; | 
					 | 
					 | 
					            return result; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        } catch (RenException e) { | 
					 | 
					 | 
					        } catch (RenException e) { | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					@ -69,8 +72,8 @@ public class NoRepeatSubmitAop { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        } | 
					 | 
					 | 
					        } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    } | 
					 | 
					 | 
					    } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
						private String getKey(String keyExpress,String token) { | 
					 | 
					 | 
					    private String getKey(String keyExpress, String token) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
							return keyExpress+token; | 
					 | 
					 | 
					        return keyExpress + token; | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					    } | 
					 | 
					 | 
					    } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					} | 
					 | 
					 | 
					} | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
					 | 
					
  |