46 lines
1.2 KiB
Java
46 lines
1.2 KiB
Java
package com.durant.aspect;
|
|
|
|
import com.durant.annotion.Independent;
|
|
import org.aspectj.lang.ProceedingJoinPoint;
|
|
import org.aspectj.lang.annotation.Around;
|
|
import org.aspectj.lang.annotation.Aspect;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
import java.util.Map;
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
/**
|
|
* @author 冯凯
|
|
* @version 1.0
|
|
* @description: TODO
|
|
* @date 2023/10/3 22:05
|
|
*/
|
|
@Aspect
|
|
@Component
|
|
public class IndependentAspect {
|
|
private Object result=null;
|
|
private Map<String,Object> resultMap=new ConcurrentHashMap<>();
|
|
|
|
@Around("@annotation(independent)")
|
|
public Object independent(ProceedingJoinPoint joinPoint, Independent independent) throws Throwable {
|
|
|
|
String id = generateId(joinPoint.getArgs());
|
|
if (resultMap.containsKey(id)){
|
|
System.out.println("不要重复提交请求");
|
|
return resultMap.get(id);
|
|
}
|
|
|
|
result= joinPoint.proceed();
|
|
resultMap.put(id,result);
|
|
return result;
|
|
}
|
|
|
|
private String generateId(Object[] args){
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
for (Object arg : args) {
|
|
stringBuilder.append(arg.hashCode());
|
|
}
|
|
return stringBuilder.toString();
|
|
}
|
|
}
|