diff --git a/pom.xml b/pom.xml index a17897433..f50e460e5 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ RuoYi-Vue-Plus后台管理系统 - 2.3.0 + 2.3.1 2.3.11.RELEASE UTF-8 UTF-8 diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml index 3838ff50e..3ea04c71e 100644 --- a/ruoyi-admin/src/main/resources/application.yml +++ b/ruoyi-admin/src/main/resources/application.yml @@ -8,8 +8,8 @@ ruoyi: copyrightYear: 2021 # 实例演示开关 demoEnabled: true - # 文件路径,使用jvm系统变量,兼容windows和linux; - profile: ${user.dir}/ruoyi/uploadPath + # 文件路径 + profile: ./ruoyi/uploadPath # 获取ip地址开关 addressEnabled: false diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/annotation/RedisLock.java b/ruoyi-common/src/main/java/com/ruoyi/common/annotation/RedisLock.java new file mode 100644 index 000000000..7b3c912f1 --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/annotation/RedisLock.java @@ -0,0 +1,27 @@ +package com.ruoyi.common.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * 分布式锁(注解模式,不推荐使用,最好用锁的工具类) + * + * @author shenxinquan + */ + +@Target({ElementType.METHOD}) +@Retention(RetentionPolicy.RUNTIME) +public @interface RedisLock { + + /** + * 锁过期时间 默认30秒 + */ + int expireTime() default 30; + + /** + * 锁key值 + */ + String key() default "redisLockKey"; +} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/PageUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/PageUtils.java index cf3f886d7..d5b72f77c 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/PageUtils.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/PageUtils.java @@ -43,9 +43,9 @@ public class PageUtils { public static final int DEFAULT_PAGE_NUM = 1; /** - * 每页显示记录数 默认值 + * 每页显示记录数 默认值 默认查全部 */ - public static final int DEFAULT_PAGE_SIZE = 10; + public static final int DEFAULT_PAGE_SIZE = Integer.MAX_VALUE; /** * 构建 plus 分页对象 diff --git a/ruoyi-demo/src/main/java/com/ruoyi/demo/controller/RedisLockController.java b/ruoyi-demo/src/main/java/com/ruoyi/demo/controller/RedisLockController.java new file mode 100644 index 000000000..7792784a1 --- /dev/null +++ b/ruoyi-demo/src/main/java/com/ruoyi/demo/controller/RedisLockController.java @@ -0,0 +1,35 @@ +package com.ruoyi.demo.controller; + +import com.ruoyi.common.annotation.RedisLock; +import com.ruoyi.common.core.domain.AjaxResult; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + + +/** + * 测试分布式锁的样例 + * + * @author shenxinquan + */ +@RestController +@RequestMapping("/demo/redisLock") +public class RedisLockController { + + /** + * #p0 标识取第一个参数为redis锁的key + */ + @GetMapping("/getLock") + @RedisLock(expireTime = 10, key = "#p0") + public AjaxResult getLock(String key, String value) { + try { + // 同时请求排队 +// Thread.sleep(5000); + // 锁超时测试 + Thread.sleep(11000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + return AjaxResult.success("操作成功",value); + } +} diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/RedisLockAspect.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/RedisLockAspect.java new file mode 100644 index 000000000..0ff695f8b --- /dev/null +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/RedisLockAspect.java @@ -0,0 +1,167 @@ +package com.ruoyi.framework.aspectj; + + +import com.ruoyi.common.annotation.RedisLock; +import lombok.extern.slf4j.Slf4j; +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.aspectj.lang.reflect.MethodSignature; +import org.redisson.api.RLock; +import org.redisson.api.RedissonClient; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.annotation.Order; +import org.springframework.stereotype.Component; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.TimeUnit; + +/** + * 分布式锁(注解实现版本) + * + * @author shenxinquan + */ + +@Slf4j +@Aspect +@Order(9) +@Component +public class RedisLockAspect { + + @Autowired + private RedissonClient redissonClient; + + private static final String LOCK_TITLE = "RedisLock_"; + + @Pointcut("@annotation(com.ruoyi.common.annotation.RedisLock)") + public void annotationPointcut() { + } + + @Around("annotationPointcut()") + public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable { + // 获得当前访问的class + Class className = joinPoint.getTarget().getClass(); + // 获得访问的方法名 + String methodName = joinPoint.getSignature().getName(); + // 得到方法的参数的类型 + Class[] argClass = ((MethodSignature) joinPoint.getSignature()).getParameterTypes(); + Object[] args = joinPoint.getArgs(); + String key = ""; + // 默认30秒过期时间 + int expireTime = 30; + + try { + // 得到访问的方法对象 + Method method = className.getMethod(methodName, argClass); + method.setAccessible(true); + // 判断是否存在@RedisLock注解 + if (method.isAnnotationPresent(RedisLock.class)) { + RedisLock annotation = method.getAnnotation(RedisLock.class); + key = getRedisKey(args, annotation.key()); + expireTime = getExpireTime(annotation); + } + } catch (Exception e) { + throw new RuntimeException("redis分布式锁注解参数异常", e); + } + + Object res; + try { + if (acquire(key, expireTime, TimeUnit.SECONDS)) { + try { + res = joinPoint.proceed(); + return res; + } catch (Exception e) { + throw new RuntimeException(e); + } finally { + release(key); + } + } else { + throw new RuntimeException("redis分布式锁注解参数异常"); + } + } catch (IllegalMonitorStateException e) { + log.error("lock timeout => key : " + key + " , ThreadName : " + Thread.currentThread().getName()); + throw new RuntimeException("lock timeout => key : " + key); + } catch (Exception e) { + throw new Exception("redis分布式未知异常", e); + } + } + + private int getExpireTime(RedisLock annotation) { + return annotation.expireTime(); + } + + private String getRedisKey(Object[] args, String primalKey) { + if (args.length == 0) { + return primalKey; + } + // 获取#p0...集合 + List keyList = getKeyParsList(primalKey); + for (String keyName : keyList) { + int keyIndex = Integer.parseInt(keyName.toLowerCase().replace("#p", "")); + Object parValue = args[keyIndex]; + primalKey = primalKey.replace(keyName, String.valueOf(parValue)); + } + return primalKey.replace("+", "").replace("'", ""); + } + + /** + * 获取key中#p0中的参数名称 + */ + private static List getKeyParsList(String key) { + List listPar = new ArrayList<>(); + if (key.contains("#")) { + int plusIndex = key.substring(key.indexOf("#")).indexOf("+"); + int indexNext = 0; + String parName; + int indexPre = key.indexOf("#"); + if (plusIndex > 0) { + indexNext = key.indexOf("#") + plusIndex; + parName = key.substring(indexPre, indexNext); + } else { + parName = key.substring(indexPre); + } + listPar.add(parName.trim()); + key = key.substring(indexNext + 1); + if (key.contains("#")) { + listPar.addAll(getKeyParsList(key)); + } + } + return listPar; + } + + /** + * 加锁(RLock)带超时时间的 + */ + private boolean acquire(String key, long expire, TimeUnit expireUnit) { + //声明key对象 + key = LOCK_TITLE + key; + try { + //获取锁对象 + RLock mylock = redissonClient.getLock(key); + //加锁,并且设置锁过期时间,防止死锁的产生 + mylock.tryLock(expire, expire, expireUnit); + } catch (InterruptedException e) { + return false; + } + log.info("lock => key : " + key + " , ThreadName : " + Thread.currentThread().getName()); + //加锁成功 + return true; + } + + /** + * 锁的释放 + */ + private void release(String lockName) { + //必须是和加锁时的同一个key + String key = LOCK_TITLE + lockName; + //获取所对象 + RLock mylock = redissonClient.getLock(key); + //释放锁(解锁) + mylock.unlock(); + log.info("unlock => key : " + key + " , ThreadName : " + Thread.currentThread().getName()); + } + +} diff --git a/ruoyi-generator/src/main/resources/vm/java/vo.java.vm b/ruoyi-generator/src/main/resources/vm/java/vo.java.vm index 87f72090f..4641d7808 100644 --- a/ruoyi-generator/src/main/resources/vm/java/vo.java.vm +++ b/ruoyi-generator/src/main/resources/vm/java/vo.java.vm @@ -29,7 +29,7 @@ public class ${ClassName}Vo { private ${pkColumn.javaType} ${pkColumn.javaField}; #foreach ($column in $columns) -#if($column.isList) +#if($column.isList && $column.isPk!=1) /** $column.columnComment */ #set($parentheseIndex=$column.columnComment.indexOf("(")) #if($parentheseIndex != -1) diff --git a/ruoyi-ui/package.json b/ruoyi-ui/package.json index 2fc1921b9..52551a4cc 100644 --- a/ruoyi-ui/package.json +++ b/ruoyi-ui/package.json @@ -1,6 +1,6 @@ { "name": "ruoyi-vue-plus", - "version": "2.3.0", + "version": "2.3.1", "description": "RuoYi-Vue-Plus后台管理系统", "author": "LionLi", "license": "MIT", diff --git a/ruoyi-ui/src/views/index.vue b/ruoyi-ui/src/views/index.vue index 29d4dbb5c..d904f3098 100644 --- a/ruoyi-ui/src/views/index.vue +++ b/ruoyi-ui/src/views/index.vue @@ -80,6 +80,18 @@ 更新日志 + +
    +
  1. add 增加 redisson 分布式锁 注解与demo案例
  2. +
  3. add 增加 Oracle 分支
  4. +
  5. update 优化 redis 空密码兼容性
  6. +
  7. update 优化前端代码生成按钮增加 loading
  8. +
  9. fix 修复 redisson 不能批量删除的bug
  10. +
  11. fix 修复表单构建选择下拉选择控制台报错问题
  12. +
  13. fix 修复 vo 代码生成 主键列表显示 重复生成bug
  14. +
  15. fix 修复上传路径 win 打包编译为 win 路径, linux 报错bug
  16. +
+
  1. add 升级 luttuce 为 redisson 性能更强 工具更全
  2. @@ -195,12 +207,14 @@