gaodm 5 лет назад
Родитель
Сommit
429890da1d
23 измененных файлов с 192 добавлено и 70 удалено
  1. 0 6
      common-biz-client/pom.xml
  2. 0 19
      common-biz-client/src/main/java/com/diagbot/config/JetcacheConfigurer.java
  3. 5 5
      common-biz-client/src/main/java/com/diagbot/facade/PermissionFacade.java
  4. 0 8
      config-server/src/main/resources/shared/application-dev.yml
  5. 0 8
      config-server/src/main/resources/shared/application-local.yml
  6. 0 8
      config-server/src/main/resources/shared/application-pre.yml
  7. 0 8
      config-server/src/main/resources/shared/application-pro.yml
  8. 0 8
      config-server/src/main/resources/shared/application-test.yml
  9. 5 0
      config-server/src/main/resources/shared/data-service-dev.yml
  10. 6 0
      config-server/src/main/resources/shared/data-service-local.yml
  11. 5 0
      config-server/src/main/resources/shared/data-service-pre.yml
  12. 5 0
      config-server/src/main/resources/shared/data-service-pro.yml
  13. 5 0
      config-server/src/main/resources/shared/data-service-test.yml
  14. 6 0
      config-server/src/main/resources/shared/ltapi-service-dev.yml
  15. 6 0
      config-server/src/main/resources/shared/ltapi-service-local.yml
  16. 6 0
      config-server/src/main/resources/shared/ltapi-service-pre.yml
  17. 6 0
      config-server/src/main/resources/shared/ltapi-service-pro.yml
  18. 6 0
      config-server/src/main/resources/shared/ltapi-service-test.yml
  19. 9 0
      data-service/pom.xml
  20. 34 0
      data-service/src/main/java/com/diagbot/config/CacheConfigurer.java
  21. 9 0
      ltapi-service/pom.xml
  22. 34 0
      ltapi-service/src/main/java/com/diagbot/config/CacheConfigurer.java
  23. 45 0
      ltapi-service/src/main/java/com/diagbot/web/PermissionCacheController.java

+ 0 - 6
common-biz-client/pom.xml

@@ -51,12 +51,6 @@
             <scope>provided</scope>
         </dependency>
 
-        <dependency>
-            <groupId>com.alicp.jetcache</groupId>
-            <artifactId>jetcache-starter-redis</artifactId>
-            <version>2.5.16</version>
-        </dependency>
-
         <dependency>
             <groupId>com.diagbot</groupId>
             <artifactId>common</artifactId>

+ 0 - 19
common-biz-client/src/main/java/com/diagbot/config/JetcacheConfigurer.java

@@ -1,19 +0,0 @@
-package com.diagbot.config;
-
-
-import com.alicp.jetcache.anno.config.EnableCreateCacheAnnotation;
-import com.alicp.jetcache.anno.config.EnableMethodCache;
-import org.springframework.context.annotation.Configuration;
-
-
-/**
- * @Description: Swagger配置类
- * @author: gaodm
- * @time: 2018/8/2 14:21
- */
-@Configuration
-@EnableMethodCache(basePackages = "com.diagbot.facade")
-@EnableCreateCacheAnnotation
-public class JetcacheConfigurer {
-
-}

+ 5 - 5
common-biz-client/src/main/java/com/diagbot/facade/PermissionFacade.java

@@ -1,11 +1,10 @@
 package com.diagbot.facade;
 
-import com.alicp.jetcache.anno.CacheInvalidate;
-import com.alicp.jetcache.anno.CacheType;
-import com.alicp.jetcache.anno.Cached;
 import com.diagbot.dto.PermissionDTO;
 import com.diagbot.vo.PermissionVO;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.cache.annotation.CacheEvict;
+import org.springframework.cache.annotation.Cacheable;
 import org.springframework.stereotype.Component;
 
 /**
@@ -16,8 +15,9 @@ import org.springframework.stereotype.Component;
 @Component
 @Slf4j
 public class PermissionFacade {
+    private static final String PERMISSIONCACHE = "permissionCache";
 
-    @Cached(name = "permissionCache", cacheType = CacheType.LOCAL, key = "'_hc_' + #permissionVO.hospitalCode + '_st_' + #permissionVO.sysType")
+    @Cacheable(value = PERMISSIONCACHE, key = "'_hc_' + #permissionVO.hospitalCode + '_st_' + #permissionVO.sysType")
     public PermissionDTO getPermission(PermissionVO permissionVO) {
         log.info("获取了缓存");
         PermissionDTO permissionDTO = new PermissionDTO();
@@ -25,7 +25,7 @@ public class PermissionFacade {
         return permissionDTO;
     }
 
-    @CacheInvalidate(name = "permissionCache")
+    @CacheEvict(cacheNames = PERMISSIONCACHE, allEntries = true)
     public Boolean delPermission() {
         log.info("清理了缓存");
         return true;

+ 0 - 8
config-server/src/main/resources/shared/application-dev.yml

@@ -83,14 +83,6 @@ crypt:
 permission:
   enable: true
 
-jetcache:
-  statIntervalMinutes: 15
-  areaInCacheName: false
-  local:
-    default:
-      type: linkedhashmap
-      keyConvertor: fastjson
-
 mrqc:
   server:
     address: http://192.168.2.234:8090

+ 0 - 8
config-server/src/main/resources/shared/application-local.yml

@@ -83,14 +83,6 @@ crypt:
 permission:
   enable: true
 
-jetcache:
-  statIntervalMinutes: 15
-  areaInCacheName: false
-  local:
-    default:
-      type: linkedhashmap
-      keyConvertor: fastjson
-
 mrqc:
   server:
     address: http://192.168.2.234:8090

+ 0 - 8
config-server/src/main/resources/shared/application-pre.yml

@@ -83,14 +83,6 @@ crypt:
 permission:
   enable: true
 
-jetcache:
-  statIntervalMinutes: 15
-  areaInCacheName: false
-  local:
-    default:
-      type: linkedhashmap
-      keyConvertor: fastjson
-
 mrqc:
   server:
     address: http://192.168.2.186:8090

+ 0 - 8
config-server/src/main/resources/shared/application-pro.yml

@@ -83,14 +83,6 @@ crypt:
 permission:
   enable: true
 
-jetcache:
-  statIntervalMinutes: 15
-  areaInCacheName: false
-  local:
-    default:
-      type: linkedhashmap
-      keyConvertor: fastjson
-
 mrqc:
   server:
     address: http://192.168.2.123:8090

+ 0 - 8
config-server/src/main/resources/shared/application-test.yml

@@ -83,14 +83,6 @@ crypt:
 permission:
   enable: true
 
-jetcache:
-  statIntervalMinutes: 15
-  areaInCacheName: false
-  local:
-    default:
-      type: linkedhashmap
-      keyConvertor: fastjson
-
 mrqc:
   server:
     address: http://192.168.2.241:8090

+ 5 - 0
config-server/src/main/resources/shared/data-service-dev.yml

@@ -21,3 +21,8 @@ spring:
     publisher-confirms: true
     virtual-host: /
 
+  # 配置缓存,初始缓存容量,最大容量,过期时间(这里配置写入后过期时间10小时)
+  cache:
+    type: caffeine
+    caffeine:
+      spec: initialCapacity=10,maximumSize=200,refreshAfterWrite=36000s

+ 6 - 0
config-server/src/main/resources/shared/data-service-local.yml

@@ -20,3 +20,9 @@ spring:
     password: guest
     publisher-confirms: true
     virtual-host: /
+
+  # 配置缓存,初始缓存容量,最大容量,过期时间(这里配置写入后过期时间10小时)
+  cache:
+    type: caffeine
+    caffeine:
+      spec: initialCapacity=10,maximumSize=200,refreshAfterWrite=36000s

+ 5 - 0
config-server/src/main/resources/shared/data-service-pre.yml

@@ -21,3 +21,8 @@ spring:
     publisher-confirms: true
     virtual-host: /
 
+  # 配置缓存,初始缓存容量,最大容量,过期时间(这里配置写入后过期时间10小时)
+  cache:
+    type: caffeine
+    caffeine:
+      spec: initialCapacity=10,maximumSize=200,refreshAfterWrite=36000s

+ 5 - 0
config-server/src/main/resources/shared/data-service-pro.yml

@@ -21,3 +21,8 @@ spring:
     publisher-confirms: true
     virtual-host: /
 
+  # 配置缓存,初始缓存容量,最大容量,过期时间(这里配置写入后过期时间10小时)
+  cache:
+    type: caffeine
+    caffeine:
+      spec: initialCapacity=10,maximumSize=200,refreshAfterWrite=36000s

+ 5 - 0
config-server/src/main/resources/shared/data-service-test.yml

@@ -20,3 +20,8 @@ spring:
     publisher-confirms: true
     virtual-host: /
 
+  # 配置缓存,初始缓存容量,最大容量,过期时间(这里配置写入后过期时间10小时)
+  cache:
+    type: caffeine
+    caffeine:
+      spec: initialCapacity=10,maximumSize=200,refreshAfterWrite=36000s

+ 6 - 0
config-server/src/main/resources/shared/ltapi-service-dev.yml

@@ -20,3 +20,9 @@ spring:
     password: lantone
     publisher-confirms: true
     virtual-host: /
+
+  # 配置缓存,初始缓存容量,最大容量,过期时间(这里配置写入后过期时间10小时)
+  cache:
+    type: caffeine
+    caffeine:
+      spec: initialCapacity=10,maximumSize=200,refreshAfterWrite=36000s

+ 6 - 0
config-server/src/main/resources/shared/ltapi-service-local.yml

@@ -20,3 +20,9 @@ spring:
     password: guest
     publisher-confirms: true
     virtual-host: /
+
+  # 配置缓存,初始缓存容量,最大容量,过期时间(这里配置写入后过期时间10小时)
+  cache:
+    type: caffeine
+    caffeine:
+      spec: initialCapacity=10,maximumSize=200,refreshAfterWrite=36000s

+ 6 - 0
config-server/src/main/resources/shared/ltapi-service-pre.yml

@@ -20,3 +20,9 @@ spring:
     password: lantone
     publisher-confirms: true
     virtual-host: /
+
+  # 配置缓存,初始缓存容量,最大容量,过期时间(这里配置写入后过期时间10小时)
+  cache:
+    type: caffeine
+    caffeine:
+      spec: initialCapacity=10,maximumSize=200,refreshAfterWrite=36000s

+ 6 - 0
config-server/src/main/resources/shared/ltapi-service-pro.yml

@@ -20,3 +20,9 @@ spring:
     password: lantone
     publisher-confirms: true
     virtual-host: /
+
+  # 配置缓存,初始缓存容量,最大容量,过期时间(这里配置写入后过期时间10小时)
+  cache:
+    type: caffeine
+    caffeine:
+      spec: initialCapacity=10,maximumSize=200,refreshAfterWrite=36000s

+ 6 - 0
config-server/src/main/resources/shared/ltapi-service-test.yml

@@ -20,3 +20,9 @@ spring:
     password: lantone
     publisher-confirms: true
     virtual-host: /
+
+  # 配置缓存,初始缓存容量,最大容量,过期时间(这里配置写入后过期时间10小时)
+  cache:
+    type: caffeine
+    caffeine:
+      spec: initialCapacity=10,maximumSize=200,refreshAfterWrite=36000s

+ 9 - 0
data-service/pom.xml

@@ -129,6 +129,15 @@
             <artifactId>spring-cloud-starter-stream-rabbit</artifactId>
         </dependency>
 
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-cache</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.github.ben-manes.caffeine</groupId>
+            <artifactId>caffeine</artifactId>
+        </dependency>
+
     </dependencies>
 
     <build>

+ 34 - 0
data-service/src/main/java/com/diagbot/config/CacheConfigurer.java

@@ -0,0 +1,34 @@
+package com.diagbot.config;
+
+import com.github.benmanes.caffeine.cache.CacheLoader;
+import org.springframework.cache.annotation.EnableCaching;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+@EnableCaching
+public class CacheConfigurer {
+    /**
+     * 必须要指定这个Bean,refreshAfterWrite=xs这个配置属性才生效
+     *
+     * @return
+     */
+    @Bean
+    public CacheLoader<Object, Object> cacheLoader() {
+        CacheLoader<Object, Object> cacheLoader = new CacheLoader<Object, Object>() {
+
+            @Override
+            public Object load(Object key) throws Exception {
+                return null;
+            }
+
+            // 重写这个方法将oldValue值返回回去,进而刷新缓存
+            @Override
+            public Object reload(Object key, Object oldValue) throws Exception {
+                return oldValue;
+            }
+        };
+
+        return cacheLoader;
+    }
+}

+ 9 - 0
ltapi-service/pom.xml

@@ -129,6 +129,15 @@
             <artifactId>spring-cloud-starter-stream-rabbit</artifactId>
         </dependency>
 
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-cache</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.github.ben-manes.caffeine</groupId>
+            <artifactId>caffeine</artifactId>
+        </dependency>
+
     </dependencies>
 
     <build>

+ 34 - 0
ltapi-service/src/main/java/com/diagbot/config/CacheConfigurer.java

@@ -0,0 +1,34 @@
+package com.diagbot.config;
+
+import com.github.benmanes.caffeine.cache.CacheLoader;
+import org.springframework.cache.annotation.EnableCaching;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+@EnableCaching
+public class CacheConfigurer {
+    /**
+     * 必须要指定这个Bean,refreshAfterWrite=xs这个配置属性才生效
+     *
+     * @return
+     */
+    @Bean
+    public CacheLoader<Object, Object> cacheLoader() {
+        CacheLoader<Object, Object> cacheLoader = new CacheLoader<Object, Object>() {
+
+            @Override
+            public Object load(Object key) throws Exception {
+                return null;
+            }
+
+            // 重写这个方法将oldValue值返回回去,进而刷新缓存
+            @Override
+            public Object reload(Object key, Object oldValue) throws Exception {
+                return oldValue;
+            }
+        };
+
+        return cacheLoader;
+    }
+}

+ 45 - 0
ltapi-service/src/main/java/com/diagbot/web/PermissionCacheController.java

@@ -0,0 +1,45 @@
+package com.diagbot.web;
+
+import com.diagbot.annotation.SysLogger;
+import com.diagbot.dto.PermissionDTO;
+import com.diagbot.dto.RespDTO;
+import com.diagbot.facade.PermissionFacade;
+import com.diagbot.vo.PermissionVO;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @Description:
+ * @author: gaodm
+ * @time: 2020/2/17 20:26
+ */
+@RestController
+@RequestMapping("/permissionCache")
+@Api(value = "权限缓存相关API", tags = { "权限缓存相关API" })
+@SuppressWarnings("unchecked")
+public class PermissionCacheController {
+
+    @Autowired
+    private PermissionFacade permissionFacade;
+
+    @ApiOperation(value = "清空权限缓存[by:gaodm]",
+            notes = "")
+    @PostMapping("/delPermission")
+    @SysLogger("delPermission")
+    public RespDTO<Boolean> delPermission() {
+        return RespDTO.onSuc(permissionFacade.delPermission());
+    }
+
+    @ApiOperation(value = "获取权限缓存[by:gaodm]",
+            notes = "")
+    @PostMapping("/getPermission")
+    @SysLogger("getPermission")
+    public RespDTO<PermissionDTO> getPermission(@RequestBody PermissionVO permissionVO) {
+        return RespDTO.onSuc(permissionFacade.getPermission(permissionVO));
+    }
+}