mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-09-20 18:15:56 +08:00
feat: 修订实现中的坏味道
Signed-off-by: 李小平 <8922024+li-xiaoping-2021@user.noreply.gitee.com>
This commit is contained in:
parent
653bf84929
commit
da878f64d1
@ -4,6 +4,7 @@ import cn.dev33.satoken.SaManager;
|
|||||||
import cn.hutool.core.util.ArrayUtil;
|
import cn.hutool.core.util.ArrayUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.crypto.SecureUtil;
|
import cn.hutool.crypto.SecureUtil;
|
||||||
|
import java.util.Objects;
|
||||||
import org.dromara.common.core.constant.GlobalConstants;
|
import org.dromara.common.core.constant.GlobalConstants;
|
||||||
import org.dromara.common.core.domain.R;
|
import org.dromara.common.core.domain.R;
|
||||||
import org.dromara.common.core.exception.ServiceException;
|
import org.dromara.common.core.exception.ServiceException;
|
||||||
@ -39,21 +40,25 @@ public class RepeatSubmitAspect {
|
|||||||
private static final ThreadLocal<String> KEY_CACHE = new ThreadLocal<>();
|
private static final ThreadLocal<String> KEY_CACHE = new ThreadLocal<>();
|
||||||
|
|
||||||
@Before("@annotation(repeatSubmit)")
|
@Before("@annotation(repeatSubmit)")
|
||||||
public void doBefore(JoinPoint point, RepeatSubmit repeatSubmit) throws Throwable {
|
public void doBefore(JoinPoint point, RepeatSubmit repeatSubmit) {
|
||||||
// 如果注解不为0 则使用注解数值
|
// 如果注解不为0 则使用注解数值
|
||||||
long interval = repeatSubmit.timeUnit().toMillis(repeatSubmit.interval());
|
long interval = repeatSubmit.timeUnit().toMillis(repeatSubmit.interval());
|
||||||
|
|
||||||
if (interval < 1000) {
|
if (interval < 1000) {
|
||||||
throw new ServiceException("重复提交间隔时间不能小于'1'秒");
|
throw new ServiceException("重复提交间隔时间不能小于'1'秒。");
|
||||||
}
|
}
|
||||||
HttpServletRequest request = ServletUtils.getRequest();
|
|
||||||
String nowParams = argsArrayToString(point.getArgs());
|
String nowParams = argsArrayToString(point.getArgs());
|
||||||
|
|
||||||
// 请求地址(作为存放cache的key值)
|
// 请求地址(作为存放cache的key值)
|
||||||
String url = request.getRequestURI();
|
String url = "";
|
||||||
|
String submitKey = "";
|
||||||
|
HttpServletRequest request = ServletUtils.getRequest();
|
||||||
|
if (Objects.nonNull(request)) {
|
||||||
|
url = request.getRequestURI();
|
||||||
// 唯一值(没有消息头则使用请求地址)
|
// 唯一值(没有消息头则使用请求地址)
|
||||||
String submitKey = StringUtils.trimToEmpty(request.getHeader(SaManager.getConfig().getTokenName()));
|
submitKey = StringUtils.trimToEmpty(request.getHeader(SaManager.getConfig().getTokenName()));
|
||||||
|
}
|
||||||
|
|
||||||
submitKey = SecureUtil.md5(submitKey + ":" + nowParams);
|
submitKey = SecureUtil.md5(submitKey + ":" + nowParams);
|
||||||
// 唯一标识(指定key + url + 消息头)
|
// 唯一标识(指定key + url + 消息头)
|
||||||
@ -75,6 +80,7 @@ public class RepeatSubmitAspect {
|
|||||||
* @param joinPoint 切点
|
* @param joinPoint 切点
|
||||||
*/
|
*/
|
||||||
@AfterReturning(pointcut = "@annotation(repeatSubmit)", returning = "jsonResult")
|
@AfterReturning(pointcut = "@annotation(repeatSubmit)", returning = "jsonResult")
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public void doAfterReturning(JoinPoint joinPoint, RepeatSubmit repeatSubmit, Object jsonResult) {
|
public void doAfterReturning(JoinPoint joinPoint, RepeatSubmit repeatSubmit, Object jsonResult) {
|
||||||
if (jsonResult instanceof R<?> r) {
|
if (jsonResult instanceof R<?> r) {
|
||||||
try {
|
try {
|
||||||
@ -96,6 +102,7 @@ public class RepeatSubmitAspect {
|
|||||||
* @param e 异常
|
* @param e 异常
|
||||||
*/
|
*/
|
||||||
@AfterThrowing(value = "@annotation(repeatSubmit)", throwing = "e")
|
@AfterThrowing(value = "@annotation(repeatSubmit)", throwing = "e")
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public void doAfterThrowing(JoinPoint joinPoint, RepeatSubmit repeatSubmit, Exception e) {
|
public void doAfterThrowing(JoinPoint joinPoint, RepeatSubmit repeatSubmit, Exception e) {
|
||||||
RedisUtils.deleteObject(KEY_CACHE.get());
|
RedisUtils.deleteObject(KEY_CACHE.get());
|
||||||
KEY_CACHE.remove();
|
KEY_CACHE.remove();
|
||||||
@ -117,27 +124,17 @@ public class RepeatSubmitAspect {
|
|||||||
return params.toString();
|
return params.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 判断是否需要过滤的对象。
|
|
||||||
*
|
|
||||||
* @param o 对象信息。
|
|
||||||
* @return 如果是需要过滤的对象,则返回true;否则返回false。
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("rawtypes")
|
|
||||||
public boolean isFilterObject(final Object o) {
|
public boolean isFilterObject(final Object o) {
|
||||||
Class<?> clazz = o.getClass();
|
Class<?> clazz = o.getClass();
|
||||||
if (clazz.isArray()) {
|
if (clazz.isArray()) {
|
||||||
return clazz.getComponentType().isAssignableFrom(MultipartFile.class);
|
return clazz.getComponentType().isAssignableFrom(MultipartFile.class);
|
||||||
} else if (Collection.class.isAssignableFrom(clazz)) {
|
} else if (Collection.class.isAssignableFrom(clazz)) {
|
||||||
Collection collection = (Collection) o;
|
Collection<?> collection = (Collection<?>) o;
|
||||||
for (Object value : collection) {
|
return collection.stream().anyMatch(MultipartFile.class::isInstance);
|
||||||
return value instanceof MultipartFile;
|
|
||||||
}
|
|
||||||
} else if (Map.class.isAssignableFrom(clazz)) {
|
} else if (Map.class.isAssignableFrom(clazz)) {
|
||||||
Map map = (Map) o;
|
Map<?, ?> map = (Map<?, ?>) o;
|
||||||
for (Object value : map.values()) {
|
return map.values().stream().anyMatch(MultipartFile.class::isInstance);
|
||||||
return value instanceof MultipartFile;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return o instanceof MultipartFile || o instanceof HttpServletRequest || o instanceof HttpServletResponse
|
return o instanceof MultipartFile || o instanceof HttpServletRequest || o instanceof HttpServletResponse
|
||||||
|| o instanceof BindingResult;
|
|| o instanceof BindingResult;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user