linxk 1 день назад
Родитель
Сommit
c82147a211

+ 11 - 6
operating-service/src/main/java/com/txz/operating/configurer/StartLoadConfig.java

@@ -1,5 +1,6 @@
 package com.txz.operating.configurer;
 
+import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.ArrayUtil;
 import com.txz.operating.constants.RedisConstants;
 import com.txz.operating.dto.InterfacesDTO;
@@ -12,6 +13,8 @@ import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
+import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 
 /**
@@ -21,14 +24,16 @@ import java.util.List;
 @Slf4j
 public class StartLoadConfig implements CommandLineRunner {
 
-    @Resource
-    private RedisTemplate redisTemplate;
+//    @Resource
+//    private RedisTemplate redisTemplate;
+    private HashMap<String,InterfacesDTO> interfaces = new HashMap<>();
+
     @Resource
     private InterfacesService interfacesService;
 
     @Override
     public void run(String... strings) {
-        if (redisTemplate.opsForHash().size(RedisConstants.INTERFACES_MAP) > 0 && ArrayUtil.isEmpty(strings)) {
+        if (CollUtil.isNotEmpty(interfaces) && ArrayUtil.isEmpty(strings)) {
             // 有数据, 没参数, 不执行
             return;
         }
@@ -47,10 +52,10 @@ public class StartLoadConfig implements CommandLineRunner {
     }
 
     private void reloadInterfaces() {
-        redisTemplate.delete(RedisConstants.INTERFACES_MAP);
+        interfaces = CollUtil.newHashMap();
         List<Interfaces> all = interfacesService.findAll();
-        for (Interfaces interfaces : all) {
-            redisTemplate.opsForHash().put(RedisConstants.INTERFACES_MAP, interfaces.getServicePath(), InterfacesDTO.generator(interfaces));
+        for (Interfaces a : all) {
+            interfaces.put(a.getServicePath(), InterfacesDTO.generator(a));
         }
     }