Explorar el Código

feat(系统配置、日志):

新增 自定义过期时间Cache
新增 系统信息管理
新增 Cache默认key为 default
18339543638 hace 2 años
padre
commit
8c7fbcb47f
Se han modificado 23 ficheros con 416 adiciones y 30 borrados
  1. 1 0
      tr-modules/pom.xml
  2. 24 0
      tr-modules/tr-module-export/pom.xml
  3. 5 0
      tr-modules/tr-module-system/pom.xml
  4. 50 0
      tr-modules/tr-module-system/src/main/java/cn/tr/module/sys/config/SysConfigController.java
  5. 34 0
      tr-modules/tr-module-system/src/main/java/cn/tr/module/sys/config/SysConfigManager.java
  6. 53 0
      tr-modules/tr-module-system/src/main/java/cn/tr/module/sys/config/SysConfigProperties.java
  7. 5 13
      tr-modules/tr-module-system/src/main/java/cn/tr/module/sys/log/controller/SysLogController.java
  8. 1 1
      tr-modules/tr-module-system/src/main/java/cn/tr/module/sys/oauth2/psw/operator/LoginOAuth2PswUserOperator.java
  9. 3 0
      tr-modules/tr-module-system/src/main/java/cn/tr/module/sys/sms/package-info.java
  10. 2 2
      tr-modules/tr-module-system/src/main/java/cn/tr/module/sys/user/service/ISysOrgService.java
  11. 51 0
      tr-modules/tr-module-system/src/main/resources/META-INF/spring-configuration-metadata.json
  12. 6 0
      tr-plugins/tr-spring-boot-starter-plugin-biz-tenant/pom.xml
  13. 3 3
      tr-plugins/tr-spring-boot-starter-plugin-biz-tenant/src/main/java/cn/tr/plugin/biz/tenant/TrTenantAutoConfiguration.java
  14. 3 4
      tr-plugins/tr-spring-boot-starter-plugin-biz-tenant/src/main/java/cn/tr/plugin/biz/tenant/config/aop/TenantCacheManagerAspect.java
  15. 7 0
      tr-plugins/tr-spring-boot-starter-plugin-cache/README.md
  16. 0 5
      tr-plugins/tr-spring-boot-starter-plugin-cache/pom.xml
  17. 54 0
      tr-plugins/tr-spring-boot-starter-plugin-cache/src/main/java/cn/tr/plugin/cache/CustomerRedisCacheManager.java
  18. 36 0
      tr-plugins/tr-spring-boot-starter-plugin-cache/src/main/java/cn/tr/plugin/cache/CustomizeKeyGenerator.java
  19. 71 0
      tr-plugins/tr-spring-boot-starter-plugin-cache/src/main/java/cn/tr/plugin/cache/CustomizeRedisCacheManagerAutoConfiguration.java
  20. 1 0
      tr-plugins/tr-spring-boot-starter-plugin-cache/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
  21. 1 1
      tr-plugins/tr-spring-boot-starter-plugin-operatelog/src/main/java/cn/tr/plugin/operatelog/config/OperateLogAspect.java
  22. 2 0
      tr-test/src/main/resources/application-sys.yml
  23. 3 1
      tr-test/src/main/resources/application.yml

+ 1 - 0
tr-modules/pom.xml

@@ -15,6 +15,7 @@
     <modules>
     <modules>
         <module>tr-module-system</module>
         <module>tr-module-system</module>
         <module>tr-module-gen</module>
         <module>tr-module-gen</module>
+        <module>tr-module-export</module>
     </modules>
     </modules>
 
 
 
 

+ 24 - 0
tr-modules/tr-module-export/pom.xml

@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>tr-modules</artifactId>
+        <groupId>cn.tr</groupId>
+        <version>${revision}</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>tr-module-export</artifactId>
+    <version>${revision}</version>
+
+    <description>文件导出中心</description>
+
+    <dependencies>
+
+        <dependency>
+            <groupId>cn.tr</groupId>
+            <artifactId>tr-spring-boot-starter-plugin-eventbus</artifactId>
+        </dependency>
+    </dependencies>
+</project>

+ 5 - 0
tr-modules/tr-module-system/pom.xml

@@ -67,5 +67,10 @@
             <groupId>cn.tr</groupId>
             <groupId>cn.tr</groupId>
             <artifactId>tr-module-system-api</artifactId>
             <artifactId>tr-module-system-api</artifactId>
         </dependency>
         </dependency>
+
+        <dependency>
+            <groupId>org.redisson</groupId>
+            <artifactId>redisson-spring-boot-starter</artifactId>
+        </dependency>
     </dependencies>
     </dependencies>
 </project>
 </project>

+ 50 - 0
tr-modules/tr-module-system/src/main/java/cn/tr/module/sys/config/SysConfigController.java

@@ -0,0 +1,50 @@
+package cn.tr.module.sys.config;
+
+import cn.dev33.satoken.annotation.SaCheckPermission;
+import cn.hutool.cache.CacheUtil;
+import cn.tr.core.pojo.CommonResult;
+import cn.tr.plugin.mybatis.base.BaseController;
+import cn.tr.plugin.operatelog.annotation.OperateLog;
+import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.AllArgsConstructor;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+/**
+ * 查看系统配置信息
+ *
+ * @author lf
+ * @date  2023/04/15 15:27
+ */
+@Api(tags = "系统配置")
+@RestController
+@RequestMapping("/sys/config")
+@AllArgsConstructor
+public class SysConfigController extends BaseController{
+    private final SysConfigManager configManager;
+    @ApiOperationSupport(author = "lf",order = 1)
+    @ApiOperation(value = "查看系统当前配置信息",notes = "权限: 无")
+    @GetMapping("/get/current")
+    public CommonResult<SysConfigProperties> getCurrent(){
+        return CommonResult.success(configManager.getCurrent());
+    }
+
+    @ApiOperationSupport(author = "lf",order = 2)
+    @ApiOperation(value="获取系统默认配置信息",notes = "权限:无")
+    @PostMapping("/get/default")
+    public CommonResult<SysConfigProperties> reset() {
+        return CommonResult.success(configManager.getDefault());
+    }
+
+    @ApiOperationSupport(author = "lf",order = 3)
+    @ApiOperation(value="修改系统配置信息",notes = "权限: sys:config:edit")
+    @PostMapping("/edit")
+    @SaCheckPermission("sys:config:edit")
+    public CommonResult<SysConfigProperties> add(@RequestBody@Validated SysConfigProperties source) {
+        return CommonResult.success(configManager.edit(source));
+    }
+
+
+}

+ 34 - 0
tr-modules/tr-module-system/src/main/java/cn/tr/module/sys/config/SysConfigManager.java

@@ -0,0 +1,34 @@
+package cn.tr.module.sys.config;
+
+import lombok.AllArgsConstructor;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.cache.annotation.CachePut;
+import org.springframework.cache.annotation.Cacheable;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * @ClassName : SysConfigManager
+ * @Description :
+ * @Author : LF
+ * @Date: 2023年04月19日
+ */
+@Configuration
+@EnableConfigurationProperties(SysConfigProperties.class)
+@AllArgsConstructor
+public class SysConfigManager {
+    private final SysConfigProperties configProperties;
+
+    @Cacheable(value = "global:sys:config#-1",key = "'default'")
+    public SysConfigProperties getCurrent(){
+        return configProperties;
+    }
+
+    public SysConfigProperties getDefault(){
+        return configProperties;
+    }
+
+    @CachePut(value = "global:sys:config#-1",key = "'default'")
+    public SysConfigProperties edit(SysConfigProperties source){
+        return source;
+    }
+}

+ 53 - 0
tr-modules/tr-module-system/src/main/java/cn/tr/module/sys/config/SysConfigProperties.java

@@ -0,0 +1,53 @@
+package cn.tr.module.sys.config;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+import javax.validation.constraints.NotNull;
+import java.io.Serializable;
+
+/**
+ * @ClassName : SysProperties
+ * @Description : 系统参数配置
+ * @Author : LF
+ * @Date: 2023年04月19日
+ */
+@Data
+@ConfigurationProperties(prefix = "sys.config")
+public class SysConfigProperties implements Serializable {
+    private static final long serialVersionUID = 298796558575282422L;
+    @ApiModelProperty(value = "系统LOGO",position = 1,required = true)
+    @NotNull(message = "系统LOGO不能为空")
+    private String logo;
+
+    @ApiModelProperty(value = "系统名称",position = 2,required = true)
+    @NotNull(message = "系统名称不能为空")
+    private String name;
+
+    @ApiModelProperty(value = "系统版本",position = 3,required = true)
+    @NotNull(message = "系统版本不能为空")
+    private String version;
+
+    @ApiModelProperty(value = "版权信息",position = 4,required = true)
+    @NotNull(message = "版权信息不能为空")
+    private String copyRight;
+
+    @ApiModelProperty(value = "版本链接",position = 5,required = true)
+    @NotNull(message = "版本链接不能为空")
+    private String copyRightUrl;
+
+    @ApiModelProperty(value = "登录验证码开关",position = 6)
+    private boolean captchaOpen;
+
+    @ApiModelProperty(value = "默认快捷方式",position = 7)
+    private String defaultWorkBenchData;
+
+    @ApiModelProperty(value = "默认密码",position = 8,required = true)
+    @NotNull(message = "默认密码不能为空")
+    private String defaultPsw;
+
+    @ApiModelProperty(value = "系统描述",position = 9)
+    private String defaultDescription;
+
+}

+ 5 - 13
tr-modules/tr-module-system/src/main/java/cn/tr/module/sys/log/controller/SysLogController.java

@@ -50,18 +50,10 @@ public class SysLogController extends BaseController{
     }
     }
 
 
     @ApiOperationSupport(author = "lf",order = 3)
     @ApiOperationSupport(author = "lf",order = 3)
-    @ApiOperation(value="添加系统日志",notes = "权限: sys:log:add")
-    @PostMapping("/add")
-    @SaCheckPermission("sys:log:add")
-    public CommonResult<Boolean> add(@RequestBody@Validated(Insert.class) SysLogDTO source) {
-        return CommonResult.success(sysLogService.insertSysLog(source));
-    }
-
-    @ApiOperationSupport(author = "lf",order = 4)
-    @ApiOperation(value="通过主键id编辑系统日志",notes = "权限: sys:log:edit")
-    @PostMapping("/edit")
-    @SaCheckPermission("sys:log:edit")
-    public CommonResult<Boolean> edit(@RequestBody@Validated(Update.class) SysLogDTO source) {
-        return CommonResult.success(sysLogService.updateSysLogById(source));
+    @ApiOperation(value="删除系统日志",notes = "权限: sys:log:remove")
+    @PostMapping("/removeByIds")
+    @SaCheckPermission("sys:log:remove")
+    public CommonResult<Integer> delete(@RequestBody Collection<String> ids) {
+        return CommonResult.success(sysLogService.removeSysLogByIds(ids));
     }
     }
 }
 }

+ 1 - 1
tr-modules/tr-module-system/src/main/java/cn/tr/module/sys/oauth2/psw/operator/LoginOAuth2PswUserOperator.java

@@ -103,7 +103,7 @@ public class LoginOAuth2PswUserOperator extends AbstractOAuth2PswUserOperator{
     }
     }
 
 
     @Override
     @Override
-    @Cacheable(value = "oauth2-psw-loginInfo")
+    @Cacheable(value = "oauth2-psw-loginInfo",key = "'default'")
     public Object getUserLoginInfo() {
     public Object getUserLoginInfo() {
         String loginId =String.valueOf( SaTokenUtils.getStpUtil().getLoginId());
         String loginId =String.valueOf( SaTokenUtils.getStpUtil().getLoginId());
         return OAuth2Mapper.INSTANCE.toPswLoginInfo(sysUserService.selectSysUserById(loginId));
         return OAuth2Mapper.INSTANCE.toPswLoginInfo(sysUserService.selectSysUserById(loginId));

+ 3 - 0
tr-modules/tr-module-system/src/main/java/cn/tr/module/sys/sms/package-info.java

@@ -0,0 +1,3 @@
+package cn.tr.module.sys.sms;
+
+//短信配置

+ 2 - 2
tr-modules/tr-module-system/src/main/java/cn/tr/module/sys/user/service/ISysOrgService.java

@@ -25,14 +25,14 @@ public interface ISysOrgService extends ITreeService {
      * 根据条件查询构造树结构
      * 根据条件查询构造树结构
      * @return
      * @return
      */
      */
-    @Cacheable(value = "sys:org")
+    @Cacheable(value = "sys:org",key = "'default'")
     default List<SysOrgTreeDTO> selectSysOrgTree(){
     default List<SysOrgTreeDTO> selectSysOrgTree(){
         SysOrgQueryDTO query = new SysOrgQueryDTO();
         SysOrgQueryDTO query = new SysOrgQueryDTO();
         query.setDisable(false);
         query.setDisable(false);
         return buildTree(SysOrgMapper.INSTANCE.toSysOrgTree(selectSysOrgList(query)));
         return buildTree(SysOrgMapper.INSTANCE.toSysOrgTree(selectSysOrgList(query)));
     };
     };
     
     
-    @CacheEvict(value = "sys:org")
+    @CacheEvict(value = "sys:org",key = "'default'")
     default void delSysOrgTreeCache(){
     default void delSysOrgTreeCache(){
         
         
     }
     }

+ 51 - 0
tr-modules/tr-module-system/src/main/resources/META-INF/spring-configuration-metadata.json

@@ -1,5 +1,10 @@
 {
 {
   "groups": [
   "groups": [
+    {
+      "name": "sys.config",
+      "type": "cn.tr.module.sys.config.SysConfigProperties",
+      "sourceType": "cn.tr.module.sys.config.SysConfigProperties"
+    },
     {
     {
       "name": "tr.oauth2.psw",
       "name": "tr.oauth2.psw",
       "type": "cn.tr.module.sys.oauth2.psw.properties.TrOAuth2PswClientProperties",
       "type": "cn.tr.module.sys.oauth2.psw.properties.TrOAuth2PswClientProperties",
@@ -7,6 +12,52 @@
     }
     }
   ],
   ],
   "properties": [
   "properties": [
+    {
+      "name": "sys.config.captcha-open",
+      "type": "java.lang.Boolean",
+      "sourceType": "cn.tr.module.sys.config.SysConfigProperties",
+      "defaultValue": false
+    },
+    {
+      "name": "sys.config.copy-right",
+      "type": "java.lang.String",
+      "sourceType": "cn.tr.module.sys.config.SysConfigProperties"
+    },
+    {
+      "name": "sys.config.copy-right-url",
+      "type": "java.lang.String",
+      "sourceType": "cn.tr.module.sys.config.SysConfigProperties"
+    },
+    {
+      "name": "sys.config.default-description",
+      "type": "java.lang.String",
+      "sourceType": "cn.tr.module.sys.config.SysConfigProperties"
+    },
+    {
+      "name": "sys.config.default-psw",
+      "type": "java.lang.String",
+      "sourceType": "cn.tr.module.sys.config.SysConfigProperties"
+    },
+    {
+      "name": "sys.config.default-work-bench-data",
+      "type": "java.lang.String",
+      "sourceType": "cn.tr.module.sys.config.SysConfigProperties"
+    },
+    {
+      "name": "sys.config.logo",
+      "type": "java.lang.String",
+      "sourceType": "cn.tr.module.sys.config.SysConfigProperties"
+    },
+    {
+      "name": "sys.config.name",
+      "type": "java.lang.String",
+      "sourceType": "cn.tr.module.sys.config.SysConfigProperties"
+    },
+    {
+      "name": "sys.config.version",
+      "type": "java.lang.String",
+      "sourceType": "cn.tr.module.sys.config.SysConfigProperties"
+    },
     {
     {
       "name": "tr.oauth2.psw.client-id",
       "name": "tr.oauth2.psw.client-id",
       "type": "java.lang.String",
       "type": "java.lang.String",

+ 6 - 0
tr-plugins/tr-spring-boot-starter-plugin-biz-tenant/pom.xml

@@ -53,6 +53,12 @@
             <artifactId>mybatis-plus-extension</artifactId>
             <artifactId>mybatis-plus-extension</artifactId>
             <scope>provided</scope>
             <scope>provided</scope>
         </dependency>
         </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-data-redis</artifactId>
+            <scope>provided</scope>
+        </dependency>
     </dependencies>
     </dependencies>
 
 
 </project>
 </project>

+ 3 - 3
tr-plugins/tr-spring-boot-starter-plugin-biz-tenant/src/main/java/cn/tr/plugin/biz/tenant/TrTenantAutoConfiguration.java

@@ -1,7 +1,7 @@
 package cn.tr.plugin.biz.tenant;
 package cn.tr.plugin.biz.tenant;
 
 
 import cn.tr.core.enums.WebFilterOrderEnum;
 import cn.tr.core.enums.WebFilterOrderEnum;
-import cn.tr.plugin.biz.tenant.config.aop.TenantCacheAspect;
+import cn.tr.plugin.biz.tenant.config.aop.TenantCacheManagerAspect;
 import cn.tr.plugin.biz.tenant.config.aop.TenantIgnoreAspect;
 import cn.tr.plugin.biz.tenant.config.aop.TenantIgnoreAspect;
 import cn.tr.plugin.biz.tenant.config.db.TenantCreateAndUpdateMetaObjectHandler;
 import cn.tr.plugin.biz.tenant.config.db.TenantCreateAndUpdateMetaObjectHandler;
 import cn.tr.plugin.biz.tenant.config.db.TenantDatabaseInterceptor;
 import cn.tr.plugin.biz.tenant.config.db.TenantDatabaseInterceptor;
@@ -86,7 +86,7 @@ public class TrTenantAutoConfiguration implements BeanPostProcessor {
 
 
     // ========== 缓存 ==========
     // ========== 缓存 ==========
     @Bean
     @Bean
-    public TenantCacheAspect tenantCacheAspect(){
-        return new TenantCacheAspect();
+    public TenantCacheManagerAspect tenantCacheManagerAspect(){
+        return new TenantCacheManagerAspect();
     }
     }
 }
 }

+ 3 - 4
tr-plugins/tr-spring-boot-starter-plugin-biz-tenant/src/main/java/cn/tr/plugin/biz/tenant/config/aop/TenantCacheAspect.java → tr-plugins/tr-spring-boot-starter-plugin-biz-tenant/src/main/java/cn/tr/plugin/biz/tenant/config/aop/TenantCacheManagerAspect.java

@@ -1,13 +1,11 @@
 package cn.tr.plugin.biz.tenant.config.aop;
 package cn.tr.plugin.biz.tenant.config.aop;
 
 
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.core.util.StrUtil;
-import cn.tr.core.annotation.TenantIgnore;
 import cn.tr.plugin.biz.tenant.context.TenantContextHolder;
 import cn.tr.plugin.biz.tenant.context.TenantContextHolder;
 import org.aspectj.lang.ProceedingJoinPoint;
 import org.aspectj.lang.ProceedingJoinPoint;
 import org.aspectj.lang.annotation.Around;
 import org.aspectj.lang.annotation.Around;
 import org.aspectj.lang.annotation.Aspect;
 import org.aspectj.lang.annotation.Aspect;
 import org.aspectj.lang.annotation.Pointcut;
 import org.aspectj.lang.annotation.Pointcut;
-import org.aspectj.lang.reflect.MethodSignature;
 
 
 import java.util.stream.Stream;
 import java.util.stream.Stream;
 
 
@@ -18,9 +16,10 @@ import java.util.stream.Stream;
  * @Date: 2023年04月06日
  * @Date: 2023年04月06日
  */
  */
 @Aspect
 @Aspect
-public class TenantCacheAspect {
+public class TenantCacheManagerAspect {
+
     @Around("getCachePointcut()")
     @Around("getCachePointcut()")
-    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
+    public Object aroundgetCache(ProceedingJoinPoint joinPoint) throws Throwable {
         Object name = joinPoint.getArgs()[0];
         Object name = joinPoint.getArgs()[0];
         if(!StrUtil.startWith(String.valueOf(name),"global",false)){
         if(!StrUtil.startWith(String.valueOf(name),"global",false)){
             String cacheName = TenantContextHolder.getTenantId() + StrUtil.COLON + name;
             String cacheName = TenantContextHolder.getTenantId() + StrUtil.COLON + name;

+ 7 - 0
tr-plugins/tr-spring-boot-starter-plugin-cache/README.md

@@ -0,0 +1,7 @@
+# 缓存插件
+
+使用{@Cacheable}注解时
+
+ @Cacheable(value = "global:sys:config#-1",key = "'default'")
+ 
+自定义过期时间: 分隔符为#,对value值进行划分,获取最后的数字即为自定义过期时间的值,单位/秒,若自定义过期时间不存在,则采取默认配置值为过期时间

+ 0 - 5
tr-plugins/tr-spring-boot-starter-plugin-cache/pom.xml

@@ -45,10 +45,5 @@
             <scope>provided</scope>
             <scope>provided</scope>
         </dependency>
         </dependency>
 
 
-        <dependency>
-            <groupId>org.redisson</groupId>
-            <artifactId>redisson-spring-boot-starter</artifactId>
-            <scope>provided</scope>
-        </dependency>
     </dependencies>
     </dependencies>
 </project>
 </project>

+ 54 - 0
tr-plugins/tr-spring-boot-starter-plugin-cache/src/main/java/cn/tr/plugin/cache/CustomerRedisCacheManager.java

@@ -0,0 +1,54 @@
+package cn.tr.plugin.cache;
+
+import cn.hutool.core.collection.CollectionUtil;
+import cn.hutool.core.util.StrUtil;
+import org.springframework.boot.autoconfigure.cache.CacheManagerCustomizer;
+import org.springframework.cache.CacheManager;
+import org.springframework.data.redis.cache.RedisCache;
+import org.springframework.data.redis.cache.RedisCacheConfiguration;
+import org.springframework.data.redis.cache.RedisCacheManager;
+import org.springframework.data.redis.cache.RedisCacheWriter;
+
+import java.time.Duration;
+import java.time.temporal.ChronoUnit;
+import java.util.*;
+
+/**
+ * @ClassName : CustomerRedisCacheManager
+ * @Description :
+ * @Author : LF
+ * @Date: 2023年04月19日
+ */
+
+public class CustomerRedisCacheManager extends RedisCacheManager {
+
+
+    public CustomerRedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration) {
+        super(cacheWriter, defaultCacheConfiguration);
+    }
+
+    //通过#进行分割,取最后一个为过期时间
+    @Override
+    protected RedisCache createRedisCache(String name, RedisCacheConfiguration cacheConfig) {
+        List<String> split = StrUtil.split(name, "#");
+        if(CollectionUtil.isEmpty(split)){
+            return super.createRedisCache(name, cacheConfig);
+        }
+        try {
+            //自定义过期时间
+            Integer customerTimeout = Integer.valueOf(CollectionUtil.getLast(split));
+            RedisCacheConfiguration customerCacheConfig = cacheConfig.entryTtl(Duration.of(customerTimeout, ChronoUnit.SECONDS));
+            return super.createRedisCache(name, customerCacheConfig);
+        }catch (Exception e){
+            return super.createRedisCache(name, cacheConfig);
+        }
+    }
+
+    public class  test implements CacheManagerCustomizer {
+
+        @Override
+        public void customize(CacheManager cacheManager) {
+
+        }
+    }
+}

+ 36 - 0
tr-plugins/tr-spring-boot-starter-plugin-cache/src/main/java/cn/tr/plugin/cache/CustomizeKeyGenerator.java

@@ -0,0 +1,36 @@
+package cn.tr.plugin.cache;
+
+import org.springframework.cache.interceptor.KeyGenerator;
+import org.springframework.cache.interceptor.SimpleKey;
+
+import java.lang.reflect.Method;
+
+/**
+ * @ClassName : CustomizeKeyGen
+ * @Description :
+ * @Author : LF
+ * @Date: 2023年04月20日
+ */
+
+public class CustomizeKeyGenerator implements KeyGenerator {
+    @Override
+    public Object generate(Object target, Method method, Object... params) {
+        return generateKey(params);
+    }
+
+    /**
+     * Generate a key based on the specified parameters.
+     */
+    public static Object generateKey(Object... params) {
+        if (params.length == 0) {
+            return SimpleKey.EMPTY;
+        }
+        if (params.length == 1) {
+            Object param = params[0];
+            if (param != null && !param.getClass().isArray()) {
+                return param;
+            }
+        }
+        return new SimpleKey(params);
+    }
+}

+ 71 - 0
tr-plugins/tr-spring-boot-starter-plugin-cache/src/main/java/cn/tr/plugin/cache/CustomizeRedisCacheManagerAutoConfiguration.java

@@ -0,0 +1,71 @@
+package cn.tr.plugin.cache;
+
+import org.springframework.beans.factory.ObjectProvider;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.cache.CacheProperties;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.cache.CacheManager;
+import org.springframework.cache.annotation.EnableCaching;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.io.ResourceLoader;
+import org.springframework.data.redis.cache.RedisCacheConfiguration;
+import org.springframework.data.redis.cache.RedisCacheWriter;
+import org.springframework.data.redis.connection.RedisConnectionFactory;
+import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer;
+import org.springframework.data.redis.serializer.RedisSerializationContext;
+
+/**
+ * @ClassName : CustomerRedisCacheManagerAutoConfiguration
+ * @Description :
+ * @Author : LF
+ * @Date: 2023年04月19日
+ */
+@Configuration
+@EnableConfigurationProperties(CacheProperties.class)
+@ConditionalOnProperty(prefix = "spring.cache",name = "type",havingValue = "redis")
+public class CustomizeRedisCacheManagerAutoConfiguration {
+    /**
+     * 配置cacheManage  使用 RedisTemplate 的配置信息
+     */
+    @Bean
+    public CacheManager customizeCacheManager( CacheProperties cacheProperties,
+                                              ObjectProvider<org.springframework.data.redis.cache.RedisCacheConfiguration> redisCacheConfiguration,
+                                              RedisConnectionFactory redisConnectionFactory,
+                                              ResourceLoader resourceLoader) {
+        RedisCacheConfiguration defaultCacheConfiguration = determineConfiguration(cacheProperties, redisCacheConfiguration, resourceLoader.getClassLoader());
+
+        return new CustomerRedisCacheManager(RedisCacheWriter.nonLockingRedisCacheWriter(redisConnectionFactory), defaultCacheConfiguration);
+    }
+
+    private org.springframework.data.redis.cache.RedisCacheConfiguration determineConfiguration(
+            CacheProperties cacheProperties,
+            ObjectProvider<RedisCacheConfiguration> redisCacheConfiguration,
+            ClassLoader classLoader) {
+        return redisCacheConfiguration.getIfAvailable(() -> createConfiguration(cacheProperties, classLoader));
+    }
+
+    private org.springframework.data.redis.cache.RedisCacheConfiguration createConfiguration(
+            CacheProperties cacheProperties, ClassLoader classLoader) {
+        CacheProperties.Redis redisProperties = cacheProperties.getRedis();
+        org.springframework.data.redis.cache.RedisCacheConfiguration config = org.springframework.data.redis.cache.RedisCacheConfiguration
+                .defaultCacheConfig();
+        config = config.serializeValuesWith(
+                RedisSerializationContext.SerializationPair.fromSerializer(new JdkSerializationRedisSerializer(classLoader)));
+        if (redisProperties.getTimeToLive() != null) {
+            config = config.entryTtl(redisProperties.getTimeToLive());
+        }
+        if (redisProperties.getKeyPrefix() != null) {
+            config = config.prefixCacheNameWith(redisProperties.getKeyPrefix());
+        }
+        if (!redisProperties.isCacheNullValues()) {
+            config = config.disableCachingNullValues();
+        }
+        if (!redisProperties.isUseKeyPrefix()) {
+            config = config.disableKeyPrefix();
+        }
+        return config;
+    }
+
+}

+ 1 - 0
tr-plugins/tr-spring-boot-starter-plugin-cache/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports

@@ -0,0 +1 @@
+cn.tr.plugin.cache.CustomizeRedisCacheManagerAutoConfiguration

+ 1 - 1
tr-plugins/tr-spring-boot-starter-plugin-operatelog/src/main/java/cn/tr/plugin/operatelog/config/OperateLogAspect.java

@@ -119,7 +119,7 @@ public class OperateLogAspect {
                                          Date startTime, Object result, Throwable exception) {
                                          Date startTime, Object result, Throwable exception) {
         MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
         MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
         operateLogObj.setJavaClass(methodSignature.getMethod().getDeclaringClass().getCanonicalName());
         operateLogObj.setJavaClass(methodSignature.getMethod().getDeclaringClass().getCanonicalName());
-        operateLogObj.setJavaMethod(methodSignature.toString());
+        operateLogObj.setJavaMethod(methodSignature.getMethod().getName());
         operateLogObj.setDuration((int) (DateUtil.between(startTime,DateUtil.date(),DateUnit.MS)));
         operateLogObj.setDuration((int) (DateUtil.between(startTime,DateUtil.date(),DateUnit.MS)));
         // 处理响应结果
         // 处理响应结果
         if (result != null) {
         if (result != null) {

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 2 - 0
tr-test/src/main/resources/application-sys.yml


+ 3 - 1
tr-test/src/main/resources/application.yml

@@ -47,10 +47,12 @@ spring:
 #      7天
 #      7天
       time-to-live: 604800000
       time-to-live: 604800000
   profiles:
   profiles:
-    include: doc
+    include: doc,sys
   jackson:
   jackson:
     date-format: yyyy-MM-dd HH:mm:ss
     date-format: yyyy-MM-dd HH:mm:ss
     time-zone: GMT-8
     time-zone: GMT-8
+  application:
+    name: tr
 
 
 
 
 tr:
 tr:

Algunos archivos no se mostraron porque demasiados archivos cambiaron en este cambio