mirror of
				https://github.com/dromara/RuoYi-Vue-Plus.git
				synced 2025-11-04 08:13:44 +08:00 
			
		
		
		
	fix 修复重复提交不生效问题 由于概念不同 使用 RedisUtils 重构
This commit is contained in:
		@@ -33,7 +33,7 @@
 | 
			
		||||
| Redis客户端 | Redisson | [Redisson文档](https://github.com/redisson/redisson/wiki/%E7%9B%AE%E5%BD%95) | 支持单机、集群配置 |
 | 
			
		||||
| 分布式限流 | Redisson | [Redisson文档](https://github.com/redisson/redisson/wiki/%E7%9B%AE%E5%BD%95) | 全局、请求IP、集群ID 多种限流 |
 | 
			
		||||
| 分布式锁 | Lock4j | [Lock4j官网](https://gitee.com/baomidou/lock4j) | 注解锁、工具锁 多种多样 |
 | 
			
		||||
| 分布式幂等 | Lock4j | [Lock4j文档](https://gitee.com/baomidou/lock4j) | 基于分布式锁实现 |
 | 
			
		||||
| 分布式幂等 | Redisson | [Lock4j文档](https://gitee.com/baomidou/lock4j) | 拦截重复提交 |
 | 
			
		||||
| 分布式日志 | TLog | [TLog文档](https://yomahub.com/tlog/docs) | 支持跟踪链路日志记录、性能分析、链路排查 |
 | 
			
		||||
| 分布式任务调度 | Xxl-Job | [Xxl-Job官网](https://www.xuxueli.com/xxl-job/) | 高性能 高可靠 易扩展 |
 | 
			
		||||
| 文件存储 | Minio | [Minio文档](https://docs.min.io/) | 本地存储 |
 | 
			
		||||
 
 | 
			
		||||
@@ -9,7 +9,6 @@ import io.swagger.annotations.Api;
 | 
			
		||||
import io.swagger.annotations.ApiOperation;
 | 
			
		||||
import lombok.extern.slf4j.Slf4j;
 | 
			
		||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
			
		||||
import org.springframework.cache.annotation.Cacheable;
 | 
			
		||||
import org.springframework.web.bind.annotation.GetMapping;
 | 
			
		||||
import org.springframework.web.bind.annotation.RequestMapping;
 | 
			
		||||
import org.springframework.web.bind.annotation.RestController;
 | 
			
		||||
@@ -74,13 +73,4 @@ public class RedisLockController {
 | 
			
		||||
        return AjaxResult.success("操作成功", value);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 测试spring-cache注解
 | 
			
		||||
     */
 | 
			
		||||
    @ApiOperation("测试spring-cache注解")
 | 
			
		||||
    @Cacheable(value = "test", key = "#key")
 | 
			
		||||
    @GetMapping("/testCache")
 | 
			
		||||
    public AjaxResult<String> testCache(String key) {
 | 
			
		||||
        return AjaxResult.success("操作成功", key);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,13 +1,12 @@
 | 
			
		||||
package com.ruoyi.framework.aspectj;
 | 
			
		||||
 | 
			
		||||
import cn.hutool.crypto.SecureUtil;
 | 
			
		||||
import com.baomidou.lock.LockInfo;
 | 
			
		||||
import com.baomidou.lock.LockTemplate;
 | 
			
		||||
import com.ruoyi.common.annotation.RepeatSubmit;
 | 
			
		||||
import com.ruoyi.common.constant.Constants;
 | 
			
		||||
import com.ruoyi.common.exception.ServiceException;
 | 
			
		||||
import com.ruoyi.common.properties.TokenProperties;
 | 
			
		||||
import com.ruoyi.common.utils.JsonUtils;
 | 
			
		||||
import com.ruoyi.common.utils.RedisUtils;
 | 
			
		||||
import com.ruoyi.common.utils.ServletUtils;
 | 
			
		||||
import com.ruoyi.common.utils.StringUtils;
 | 
			
		||||
import com.ruoyi.framework.config.properties.RepeatSubmitProperties;
 | 
			
		||||
@@ -25,6 +24,7 @@ import javax.servlet.http.HttpServletRequest;
 | 
			
		||||
import javax.servlet.http.HttpServletResponse;
 | 
			
		||||
import java.util.Collection;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
import java.util.concurrent.TimeUnit;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * 防止重复提交
 | 
			
		||||
@@ -39,7 +39,6 @@ public class RepeatSubmitAspect {
 | 
			
		||||
 | 
			
		||||
    private final TokenProperties tokenProperties;
 | 
			
		||||
    private final RepeatSubmitProperties repeatSubmitProperties;
 | 
			
		||||
    private final LockTemplate lockTemplate;
 | 
			
		||||
 | 
			
		||||
    @Before("@annotation(repeatSubmit)")
 | 
			
		||||
    public void doBefore(JoinPoint point, RepeatSubmit repeatSubmit) throws Throwable {
 | 
			
		||||
@@ -65,8 +64,10 @@ public class RepeatSubmitAspect {
 | 
			
		||||
        submitKey = SecureUtil.md5(submitKey + ":" + nowParams);
 | 
			
		||||
        // 唯一标识(指定key + 消息头)
 | 
			
		||||
        String cacheRepeatKey = Constants.REPEAT_SUBMIT_KEY + submitKey;
 | 
			
		||||
        LockInfo lock = lockTemplate.lock(cacheRepeatKey, interval, interval / 2);
 | 
			
		||||
        if (lock == null) {
 | 
			
		||||
        String key = RedisUtils.getCacheObject(cacheRepeatKey);
 | 
			
		||||
        if (key == null) {
 | 
			
		||||
            RedisUtils.setCacheObject(cacheRepeatKey, "", interval, TimeUnit.MILLISECONDS);
 | 
			
		||||
        } else {
 | 
			
		||||
            throw new ServiceException(repeatSubmit.message());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user