zhanghaijun лет назад: 3
Родитель
Сommit
c4a3df0b30
24 измененных файлов с 1097 добавлено и 236 удалено
  1. 583 0
      docs/Api接口文档.docx
  2. BIN
      docs/代理结构图.vsdx
  3. BIN
      docs/资源模型数据库定义表20230809.xlsx
  4. 24 22
      src/main/java/com/cec/plugins/config/RedissonConfig.java
  5. 42 0
      src/main/java/com/cec/plugins/config/properties/RedisProperties.java
  6. 46 0
      src/main/java/com/cec/plugins/config/properties/RetryProperties.java
  7. 37 0
      src/main/java/com/cec/plugins/controller/DemoController.java
  8. 9 0
      src/main/java/com/cec/plugins/controller/EstimateController.java
  9. 11 2
      src/main/java/com/cec/plugins/controller/TaskController.java
  10. 84 90
      src/main/java/com/cec/plugins/utils/RedisUtils.java
  11. 22 0
      src/main/java/com/cec/plugins/domain/reported/RegistrationDto.java
  12. 38 0
      src/main/java/com/cec/plugins/domain/reported/ServiceDto.java
  13. 0 34
      src/main/java/com/cec/plugins/properties/RedisProperties.java
  14. 0 20
      src/main/java/com/cec/plugins/properties/RetryProperties.java
  15. 24 0
      src/main/java/com/cec/plugins/service/RedisEvaluate.java
  16. 24 0
      src/main/java/com/cec/plugins/service/RedisSource.java
  17. 19 0
      src/main/java/com/cec/plugins/service/ReportedService.java
  18. 19 0
      src/main/java/com/cec/plugins/service/TaskService.java
  19. 9 0
      src/main/java/com/cec/plugins/service/integration/ReportedPlatform.java
  20. 5 0
      src/main/java/com/cec/plugins/service/integration/ReportedQuery.java
  21. 23 5
      src/main/resources/application.yml
  22. 58 63
      src/test/java/com/cec/plugins/PluginsApplicationTests.java
  23. 4 0
      tools/README.md
  24. 16 0
      tools/read_excel.py

Разница между файлами не показана из-за своего большого размера
+ 583 - 0
docs/Api接口文档.docx


BIN
docs/代理结构图.vsdx


BIN
docs/资源模型数据库定义表20230809.xlsx


+ 24 - 22
src/main/java/com/cec/plugins/config/RedissonConfig.java

@@ -1,8 +1,8 @@
 package com.cec.plugins.config;
 
 import cn.hutool.core.util.StrUtil;
-import com.cec.plugins.properties.RedisProperties;
-import com.cec.plugins.properties.RetryProperties;
+import com.cec.plugins.config.properties.RedisProperties;
+import com.cec.plugins.config.properties.RetryProperties;
 import lombok.RequiredArgsConstructor;
 import org.redisson.Redisson;
 import org.redisson.api.RedissonClient;
@@ -26,7 +26,7 @@ import org.springframework.context.annotation.Primary;
 @EnableConfigurationProperties({RedisProperties.class, RetryProperties.class})
 public class RedissonConfig {
 
-    private final RedisProperties redisProperties;
+    private final RedisProperties property;
 
     /** 资源模型数据库 */
     @Primary
@@ -36,29 +36,31 @@ public class RedissonConfig {
         config.setTransportMode(TransportMode.NIO);
         config.setCodec(new JsonJacksonCodec());
         SingleServerConfig singleServerConfig = config.useSingleServer();
+        RedisProperties.RedisModel source = property.getSource();
         singleServerConfig
-                .setClientName(redisProperties.getClientName())
-                .setAddress(redisProperties.getUrl())
-                .setDatabase(redisProperties.getDatabase());
-        if (StrUtil.isNotBlank(redisProperties.getPassword())) {
-            singleServerConfig.setPassword(redisProperties.getPassword());
+            .setClientName(source.getClientName())
+            .setAddress(source.getUrl())
+            .setDatabase(source.getDatabase());
+        if (StrUtil.isNotBlank(source.getPassword())) {
+            singleServerConfig.setPassword(source.getPassword());
         }
         return Redisson.create(config);
     }
 
     /** 评估数据库 */
-    // @Bean(name = "redisEvaluate")
-    // public RedissonClient redissonEvaluateClient() {
-    //     Config config = new Config();
-    //     config.setTransportMode(TransportMode.NIO);
-    //     SingleServerConfig singleServerConfig = config.useSingleServer();
-    //     singleServerConfig
-    //             .setClientName(redisProperties.getClientName())
-    //             .setAddress(redisProperties.getUrl())
-    //             .setDatabase(redisProperties.getDatabase());
-    //     if (StrUtil.isNotBlank(redisProperties.getPassword())) {
-    //         singleServerConfig.setPassword(redisProperties.getPassword());
-    //     }
-    //     return Redisson.create(config);
-    // }
+    @Bean(name = "redisEvaluate")
+    public RedissonClient redissonEvaluateClient() {
+        Config config = new Config();
+        config.setTransportMode(TransportMode.NIO);
+        SingleServerConfig singleServerConfig = config.useSingleServer();
+        RedisProperties.RedisModel evaluate = property.getEvaluate();
+        singleServerConfig
+            .setClientName(evaluate.getClientName())
+            .setAddress(evaluate.getUrl())
+            .setDatabase(evaluate.getDatabase());
+        if (StrUtil.isNotBlank(evaluate.getPassword())) {
+            singleServerConfig.setPassword(evaluate.getPassword());
+        }
+        return Redisson.create(config);
+    }
 }

+ 42 - 0
src/main/java/com/cec/plugins/config/properties/RedisProperties.java

@@ -0,0 +1,42 @@
+package com.cec.plugins.config.properties;
+
+import lombok.Data;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+/**
+ * @author zhanghaijun
+ * @date 2023/8/11 17:38
+ * @description Redis配置参数
+ */
+@Data
+@ConfigurationProperties(prefix = "redisson")
+public class RedisProperties {
+
+    /** 资源模型数据库 */
+    private RedisModel source;
+    /** 评估数据库 */
+    private RedisModel evaluate;
+
+    @Data
+    public static class RedisModel {
+        /** 客户端名称 */
+        private String clientName;
+
+        /** 地址 */
+        private String host = "localhost";
+        /** 端口 */
+        private int port = 6379;
+        /** 认证密码 */
+        private String password;
+        /** 是否加密传输 */
+        private boolean ssl = false;
+        /** 库 */
+        private int database = 0;
+
+
+        public String getUrl() {
+            String protocol = isSsl() ? "rediss" : "redis";
+            return protocol + "://" + getHost() + ":" + getPort();
+        }
+    }
+}

+ 46 - 0
src/main/java/com/cec/plugins/config/properties/RetryProperties.java

@@ -0,0 +1,46 @@
+package com.cec.plugins.config.properties;
+
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+/**
+ * @author zhanghaijun
+ * @version 1.0
+ * @date 2023/8/15 18:41
+ * @description [一句话描述该类的功能]
+ */
+@Data
+@ConfigurationProperties(prefix = "project")
+public class RetryProperties {
+
+    private PlatformModel platform;
+    private PluginModel plugin;
+    private RetryModel simulation;
+
+    @Data
+    public static class RetryModel {
+        /** 最大重试此处 */
+        private int retries = 3;
+        /** 间隔时间(毫秒) */
+        private long delayMillis = 1000L;
+    }
+
+    @Data
+    public static class PlatformModel{
+        /** 平台的url */
+        private String url;
+        /** 最大重试此处 */
+        private int retries = 3;
+        /** 间隔时间(毫秒) */
+        private long delayMillis = 1000L;
+    }
+
+    @Data
+    public static class PluginModel {
+        /** 最大重试此处 */
+        private String ipAddress;
+        /** 间隔时间(毫秒) */
+        private Integer port;
+    }
+}

+ 37 - 0
src/main/java/com/cec/plugins/controller/DemoController.java

@@ -0,0 +1,37 @@
+package com.cec.plugins.controller;
+
+import com.cec.plugins.domain.ResultData;
+import com.cec.plugins.domain.reported.RegistrationDto;
+import com.cec.plugins.domain.reported.ServiceDto;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.validation.annotation.Validated;
+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;
+
+/**
+ * @author zhanghaijun
+ * @version 1.0
+ * @date 2023/8/15 23:07
+ * @description [一句话描述该类的功能]
+ */
+@Slf4j
+@RestController
+@RequestMapping("/api/v1")
+public class DemoController {
+
+    /** 模拟注册接口 */
+    @PostMapping("/serviceRegistration")
+    public ResultData registration(@RequestBody @Validated RegistrationDto dto) {
+        log.info("模拟注册接口,注册成功,注册参数:{}", dto);
+        return ResultData.success();
+    }
+
+    /** 模拟心跳接口 */
+    @PostMapping("/serviceState")
+    public ResultData serviceState(@RequestBody @Validated ServiceDto dto) {
+        log.info("模拟心跳接口,接受心跳成功,注册参数:{}", dto);
+        return ResultData.success();
+    }
+}

+ 9 - 0
src/main/java/com/cec/plugins/controller/EstimateController.java

@@ -0,0 +1,9 @@
+package com.cec.plugins.controller;
+
+/**
+ * @author zhanghaijun
+ * @date 2023/8/15 22:58
+ * @description 任务评估插件
+ */
+public class EstimateController {
+}

+ 11 - 2
src/main/java/com/cec/plugins/controller/TaskController.java

@@ -3,6 +3,8 @@ package com.cec.plugins.controller;
 import com.cec.plugins.domain.DtoDipatchmission;
 import com.cec.plugins.domain.DtoTaskStatus;
 import com.cec.plugins.domain.ResultData;
+import com.cec.plugins.service.TaskService;
+import lombok.RequiredArgsConstructor;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
@@ -20,12 +22,19 @@ import org.springframework.web.bind.annotation.RestController;
  */
 @RestController
 @RequestMapping("/config/api/v1")
+@RequiredArgsConstructor
 public class TaskController {
 
+    private final TaskService taskService;
+
     /** 任务状态下发接口 */
     @PostMapping("/taskStatus")
-    public ResultData taskStatus(@RequestBody @Validated DtoTaskStatus taskStatus) {
-        return ResultData.success();
+    public ResultData taskStatus(@RequestBody @Validated DtoTaskStatus dto) {
+        if (taskService.saveTaskStatus(dto)) {
+            return ResultData.success();
+        } else {
+            return ResultData.fail("下发任务状态失败");
+        }
     }
 
     /** 控制命令下发 */

+ 84 - 90
src/main/java/com/cec/plugins/utils/RedisUtils.java

@@ -1,5 +1,6 @@
-package com.cec.plugins.utils;
+package com.cec.plugins.core;
 
+import com.cec.plugins.utils.SpringUtils;
 import org.redisson.api.*;
 import org.redisson.config.Config;
 
@@ -15,12 +16,13 @@ import java.util.stream.Stream;
  * @date 2023/8/11 18:15
  * @description Redis工具类
  */
-public class RedisUtils {
+public abstract class RedisManage {
 
-    private static final RedissonClient CLIENT = SpringUtils.getBean(RedissonClient.class);
+    /** 获取客户端实例 */
+    public abstract RedissonClient getClient();
 
-    public static NameMapper getNameMapper() {
-        Config config = CLIENT.getConfig();
+    public NameMapper getNameMapper() {
+        Config config = getClient().getConfig();
         if (config.isClusterConfig()) {
             return config.useClusterServers().getNameMapper();
         }
@@ -36,8 +38,8 @@ public class RedisUtils {
      * @param rateInterval 速率间隔
      * @return -1 表示失败
      */
-    public static long rateLimiter(String key, RateType rateType, int rate, int rateInterval) {
-        RRateLimiter rateLimiter = CLIENT.getRateLimiter(key);
+    public long rateLimiter(String key, RateType rateType, int rate, int rateInterval) {
+        RRateLimiter rateLimiter = getClient().getRateLimiter(key);
         rateLimiter.trySetRate(rateType, rate, rateInterval, RateIntervalUnit.SECONDS);
         if (rateLimiter.tryAcquire()) {
             return rateLimiter.availablePermits();
@@ -46,13 +48,6 @@ public class RedisUtils {
         }
     }
 
-    /**
-     * 获取客户端实例
-     */
-    public static RedissonClient getClient() {
-        return CLIENT;
-    }
-
     /**
      * 发布通道消息
      *
@@ -60,14 +55,14 @@ public class RedisUtils {
      * @param msg        发送数据
      * @param consumer   自定义处理
      */
-    public static <T> void publish(String channelKey, T msg, Consumer<T> consumer) {
-        RTopic topic = CLIENT.getTopic(channelKey);
+    public <T> void publish(String channelKey, T msg, Consumer<T> consumer) {
+        RTopic topic = getClient().getTopic(channelKey);
         topic.publish(msg);
         consumer.accept(msg);
     }
 
-    public static <T> void publish(String channelKey, T msg) {
-        RTopic topic = CLIENT.getTopic(channelKey);
+    public <T> void publish(String channelKey, T msg) {
+        RTopic topic = getClient().getTopic(channelKey);
         topic.publish(msg);
     }
 
@@ -78,8 +73,8 @@ public class RedisUtils {
      * @param clazz      消息类型
      * @param consumer   自定义处理
      */
-    public static <T> void subscribe(String channelKey, Class<T> clazz, Consumer<T> consumer) {
-        RTopic topic = CLIENT.getTopic(channelKey);
+    public <T> void subscribe(String channelKey, Class<T> clazz, Consumer<T> consumer) {
+        RTopic topic = getClient().getTopic(channelKey);
         topic.addListener(clazz, (channel, msg) -> consumer.accept(msg));
     }
 
@@ -89,7 +84,7 @@ public class RedisUtils {
      * @param key   缓存的键值
      * @param value 缓存的值
      */
-    public static <T> void setCacheObject(final String key, final T value) {
+    public <T> void setCacheObject(final String key, final T value) {
         setCacheObject(key, value, false);
     }
 
@@ -101,8 +96,8 @@ public class RedisUtils {
      * @param isSaveTtl 是否保留TTL有效期(例如: set之前ttl剩余90 set之后还是为90)
      * @since Redis 6.X 以上使用 setAndKeepTTL 兼容 5.X 方案
      */
-    public static <T> void setCacheObject(final String key, final T value, final boolean isSaveTtl) {
-        RBucket<T> bucket = CLIENT.getBucket(key);
+    public <T> void setCacheObject(final String key, final T value, final boolean isSaveTtl) {
+        RBucket<T> bucket = getClient().getBucket(key);
         if (isSaveTtl) {
             try {
                 bucket.setAndKeepTTL(value);
@@ -122,8 +117,8 @@ public class RedisUtils {
      * @param value    缓存的值
      * @param duration 时间
      */
-    public static <T> void setCacheObject(final String key, final T value, final Duration duration) {
-        RBatch batch = CLIENT.createBatch();
+    public <T> void setCacheObject(final String key, final T value, final Duration duration) {
+        RBatch batch = getClient().createBatch();
         RBucketAsync<T> bucket = batch.getBucket(key);
         bucket.setAsync(value);
         bucket.expireAsync(duration);
@@ -138,8 +133,8 @@ public class RedisUtils {
      * @param key      缓存的键值
      * @param listener 监听器配置
      */
-    public static <T> void addObjectListener(final String key, final ObjectListener listener) {
-        RBucket<T> result = CLIENT.getBucket(key);
+    public <T> void addObjectListener(final String key, final ObjectListener listener) {
+        RBucket<T> result = getClient().getBucket(key);
         result.addListener(listener);
     }
 
@@ -150,7 +145,7 @@ public class RedisUtils {
      * @param timeout 超时时间
      * @return true=设置成功;false=设置失败
      */
-    public static boolean expire(final String key, final long timeout) {
+    public boolean expire(final String key, final long timeout) {
         return expire(key, Duration.ofSeconds(timeout));
     }
 
@@ -161,8 +156,8 @@ public class RedisUtils {
      * @param duration 超时时间
      * @return true=设置成功;false=设置失败
      */
-    public static boolean expire(final String key, final Duration duration) {
-        RBucket<Object> rBucket = CLIENT.getBucket(key);
+    public boolean expire(final String key, final Duration duration) {
+        RBucket<Object> rBucket = getClient().getBucket(key);
         return rBucket.expire(duration);
     }
 
@@ -172,8 +167,8 @@ public class RedisUtils {
      * @param key 缓存键值
      * @return 缓存键值对应的数据
      */
-    public static <T> T getCacheObject(final String key) {
-        RBucket<T> rBucket = CLIENT.getBucket(key);
+    public <T> T getCacheObject(final String key) {
+        RBucket<T> rBucket = getClient().getBucket(key);
         return rBucket.get();
     }
 
@@ -183,8 +178,8 @@ public class RedisUtils {
      * @param key 缓存键值
      * @return 剩余存活时间
      */
-    public static <T> long getTimeToLive(final String key) {
-        RBucket<T> rBucket = CLIENT.getBucket(key);
+    public <T> long getTimeToLive(final String key) {
+        RBucket<T> rBucket = getClient().getBucket(key);
         return rBucket.remainTimeToLive();
     }
 
@@ -193,8 +188,8 @@ public class RedisUtils {
      *
      * @param key 缓存的键值
      */
-    public static boolean deleteObject(final String key) {
-        return CLIENT.getBucket(key).delete();
+    public boolean deleteObject(final String key) {
+        return getClient().getBucket(key).delete();
     }
 
     /**
@@ -202,8 +197,8 @@ public class RedisUtils {
      *
      * @param collection 多个对象
      */
-    public static void deleteObject(final Collection collection) {
-        RBatch batch = CLIENT.createBatch();
+    public void deleteObject(final Collection collection) {
+        RBatch batch = getClient().createBatch();
         collection.forEach(t -> {
             batch.getBucket(t.toString()).deleteAsync();
         });
@@ -217,8 +212,8 @@ public class RedisUtils {
      * @param dataList 待缓存的List数据
      * @return 缓存的对象
      */
-    public static <T> boolean setCacheList(final String key, final List<T> dataList) {
-        RList<T> rList = CLIENT.getList(key);
+    public <T> boolean setCacheList(final String key, final List<T> dataList) {
+        RList<T> rList = getClient().getList(key);
         return rList.addAll(dataList);
     }
 
@@ -230,8 +225,8 @@ public class RedisUtils {
      * @param key      缓存的键值
      * @param listener 监听器配置
      */
-    public static <T> void addListListener(final String key, final ObjectListener listener) {
-        RList<T> rList = CLIENT.getList(key);
+    public <T> void addListListener(final String key, final ObjectListener listener) {
+        RList<T> rList = getClient().getList(key);
         rList.addListener(listener);
     }
 
@@ -241,8 +236,8 @@ public class RedisUtils {
      * @param key 缓存的键值
      * @return 缓存键值对应的数据
      */
-    public static <T> List<T> getCacheList(final String key) {
-        RList<T> rList = CLIENT.getList(key);
+    public <T> List<T> getCacheList(final String key) {
+        RList<T> rList = getClient().getList(key);
         return rList.readAll();
     }
 
@@ -253,8 +248,8 @@ public class RedisUtils {
      * @param dataSet 缓存的数据
      * @return 缓存数据的对象
      */
-    public static <T> boolean setCacheSet(final String key, final Set<T> dataSet) {
-        RSet<T> rSet = CLIENT.getSet(key);
+    public <T> boolean setCacheSet(final String key, final Set<T> dataSet) {
+        RSet<T> rSet = getClient().getSet(key);
         return rSet.addAll(dataSet);
     }
 
@@ -266,8 +261,8 @@ public class RedisUtils {
      * @param key      缓存的键值
      * @param listener 监听器配置
      */
-    public static <T> void addSetListener(final String key, final ObjectListener listener) {
-        RSet<T> rSet = CLIENT.getSet(key);
+    public <T> void addSetListener(final String key, final ObjectListener listener) {
+        RSet<T> rSet = getClient().getSet(key);
         rSet.addListener(listener);
     }
 
@@ -277,8 +272,8 @@ public class RedisUtils {
      * @param key 缓存的key
      * @return set对象
      */
-    public static <T> Set<T> getCacheSet(final String key) {
-        RSet<T> rSet = CLIENT.getSet(key);
+    public <T> Set<T> getCacheSet(final String key) {
+        RSet<T> rSet = getClient().getSet(key);
         return rSet.readAll();
     }
 
@@ -288,9 +283,9 @@ public class RedisUtils {
      * @param key     缓存的键值
      * @param dataMap 缓存的数据
      */
-    public static <T> void setCacheMap(final String key, final Map<String, T> dataMap) {
+    public <T> void setCacheMap(final String key, final Map<String, T> dataMap) {
         if (dataMap != null) {
-            RMap<String, T> rMap = CLIENT.getMap(key);
+            RMap<String, T> rMap = getClient().getMap(key);
             rMap.putAll(dataMap);
         }
     }
@@ -303,8 +298,8 @@ public class RedisUtils {
      * @param key      缓存的键值
      * @param listener 监听器配置
      */
-    public static <T> void addMapListener(final String key, final ObjectListener listener) {
-        RMap<String, T> rMap = CLIENT.getMap(key);
+    public <T> void addMapListener(final String key, final ObjectListener listener) {
+        RMap<String, T> rMap = getClient().getMap(key);
         rMap.addListener(listener);
     }
 
@@ -314,8 +309,8 @@ public class RedisUtils {
      * @param key 缓存的键值
      * @return map对象
      */
-    public static <T> Map<String, T> getCacheMap(final String key) {
-        RMap<String, T> rMap = CLIENT.getMap(key);
+    public <T> Map<String, T> getCacheMap(final String key) {
+        RMap<String, T> rMap = getClient().getMap(key);
         return rMap.getAll(rMap.keySet());
     }
 
@@ -325,8 +320,8 @@ public class RedisUtils {
      * @param key 缓存的键值
      * @return key列表
      */
-    public static <T> Set<String> getCacheMapKeySet(final String key) {
-        RMap<String, T> rMap = CLIENT.getMap(key);
+    public <T> Set<String> getCacheMapKeySet(final String key) {
+        RMap<String, T> rMap = getClient().getMap(key);
         return rMap.keySet();
     }
 
@@ -337,8 +332,8 @@ public class RedisUtils {
      * @param hKey  Hash键
      * @param value 值
      */
-    public static <T> void setCacheMapValue(final String key, final String hKey, final T value) {
-        RMap<String, T> rMap = CLIENT.getMap(key);
+    public <T> void setCacheMapValue(final String key, final String hKey, final T value) {
+        RMap<String, T> rMap = getClient().getMap(key);
         rMap.put(hKey, value);
     }
 
@@ -349,8 +344,8 @@ public class RedisUtils {
      * @param hKey Hash键
      * @return Hash中的对象
      */
-    public static <T> T getCacheMapValue(final String key, final String hKey) {
-        RMap<String, T> rMap = CLIENT.getMap(key);
+    public <T> T getCacheMapValue(final String key, final String hKey) {
+        RMap<String, T> rMap = getClient().getMap(key);
         return rMap.get(hKey);
     }
 
@@ -361,8 +356,8 @@ public class RedisUtils {
      * @param hKey Hash键
      * @return Hash中的对象
      */
-    public static <T> T delCacheMapValue(final String key, final String hKey) {
-        RMap<String, T> rMap = CLIENT.getMap(key);
+    public <T> T delCacheMapValue(final String key, final String hKey) {
+        RMap<String, T> rMap = getClient().getMap(key);
         return rMap.remove(hKey);
     }
 
@@ -373,8 +368,8 @@ public class RedisUtils {
      * @param hKeys Hash键集合
      * @return Hash对象集合
      */
-    public static <K, V> Map<K, V> getMultiCacheMapValue(final String key, final Set<K> hKeys) {
-        RMap<K, V> rMap = CLIENT.getMap(key);
+    public <K, V> Map<K, V> getMultiCacheMapValue(final String key, final Set<K> hKeys) {
+        RMap<K, V> rMap = getClient().getMap(key);
         return rMap.getAll(hKeys);
     }
 
@@ -384,8 +379,8 @@ public class RedisUtils {
      * @param key   Redis键
      * @param value 值
      */
-    public static void setAtomicValue(String key, long value) {
-        RAtomicLong atomic = CLIENT.getAtomicLong(key);
+    public void setAtomicValue(String key, long value) {
+        RAtomicLong atomic = getClient().getAtomicLong(key);
         atomic.set(value);
     }
 
@@ -395,8 +390,8 @@ public class RedisUtils {
      * @param key Redis键
      * @return 当前值
      */
-    public static long getAtomicValue(String key) {
-        RAtomicLong atomic = CLIENT.getAtomicLong(key);
+    public long getAtomicValue(String key) {
+        RAtomicLong atomic = getClient().getAtomicLong(key);
         return atomic.get();
     }
 
@@ -406,8 +401,8 @@ public class RedisUtils {
      * @param key Redis键
      * @return 当前值
      */
-    public static long incrAtomicValue(String key) {
-        RAtomicLong atomic = CLIENT.getAtomicLong(key);
+    public long incrAtomicValue(String key) {
+        RAtomicLong atomic = getClient().getAtomicLong(key);
         return atomic.incrementAndGet();
     }
 
@@ -417,8 +412,8 @@ public class RedisUtils {
      * @param key Redis键
      * @return 当前值
      */
-    public static long decrAtomicValue(String key) {
-        RAtomicLong atomic = CLIENT.getAtomicLong(key);
+    public long decrAtomicValue(String key) {
+        RAtomicLong atomic = getClient().getAtomicLong(key);
         return atomic.decrementAndGet();
     }
 
@@ -428,8 +423,8 @@ public class RedisUtils {
      * @param pattern 字符串前缀
      * @return 对象列表
      */
-    public static Collection<String> keys(final String pattern) {
-        Stream<String> stream = CLIENT.getKeys().getKeysStreamByPattern(getNameMapper().map(pattern));
+    public Collection<String> keys(final String pattern) {
+        Stream<String> stream = getClient().getKeys().getKeysStreamByPattern(getNameMapper().map(pattern));
         return stream.map(key -> getNameMapper().unmap(key)).collect(Collectors.toList());
     }
 
@@ -438,8 +433,8 @@ public class RedisUtils {
      *
      * @param pattern 字符串前缀
      */
-    public static void deleteKeys(final String pattern) {
-        CLIENT.getKeys().deleteByPattern(getNameMapper().map(pattern));
+    public void deleteKeys(final String pattern) {
+        getClient().getKeys().deleteByPattern(getNameMapper().map(pattern));
     }
 
     /**
@@ -447,8 +442,8 @@ public class RedisUtils {
      *
      * @param key 键
      */
-    public static Boolean hasKey(String key) {
-        RKeys rKeys = CLIENT.getKeys();
+    public Boolean hasKey(String key) {
+        RKeys rKeys = getClient().getKeys();
         return rKeys.countExists(getNameMapper().map(key)) > 0;
     }
 
@@ -459,8 +454,8 @@ public class RedisUtils {
      * @param value lock value
      * @return true 加锁成功, false 加锁失败
      */
-    public static boolean tryLock(String key, String value, long timeToLive, TimeUnit timeUnit) {
-        RBucket<Object> bucket = CLIENT.getBucket(key);
+    public boolean tryLock(String key, String value, long timeToLive, TimeUnit timeUnit) {
+        RBucket<Object> bucket = getClient().getBucket(key);
         return bucket.trySet(value, timeToLive, timeUnit);
     }
 
@@ -470,15 +465,14 @@ public class RedisUtils {
      * @param key   lock key
      * @param value lock value
      */
-    public static void unLock(String key, String value) {
-        CLIENT.getScript().eval(RScript.Mode.READ_WRITE, DEL_LOCK_SCRIPT, RScript.ReturnType.INTEGER, Collections.singletonList(key), value);
+    public void unLock(String key, String value) {
+        getClient().getScript().eval(RScript.Mode.READ_WRITE, DEL_LOCK_SCRIPT, RScript.ReturnType.INTEGER, Collections.singletonList(key), value);
     }
 
     // 解锁脚本
-    private static final String DEL_LOCK_SCRIPT =
-            "if redis.call(\"get\",KEYS[1]) == ARGV[1] then" +      // 如果 KEYS[1] 对应的 Value 值等于 ARGV[1]
-                    " return redis.call(\"del\",KEYS[1])" +         // 删除 KEYS[1]
-                    " else" +                                       // 否则
-                    " return 0" +                                   // 返回 0
-                    " end;";
+    private final String DEL_LOCK_SCRIPT = "if redis.call(\"get\",KEYS[1]) == ARGV[1] then" +      // 如果 KEYS[1] 对应的 Value 值等于 ARGV[1]
+        " return redis.call(\"del\",KEYS[1])" +         // 删除 KEYS[1]
+        " else" +                                       // 否则
+        " return 0" +                                   // 返回 0
+        " end;";
 }

+ 22 - 0
src/main/java/com/cec/plugins/domain/reported/RegistrationDto.java

@@ -0,0 +1,22 @@
+package com.cec.plugins.domain.reported;
+
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import javax.validation.constraints.NotBlank;
+
+/**
+ * @author zhanghaijun
+ * @version 1.0
+ * @date 2023/8/15 23:10
+ * @description [一句话描述该类的功能]
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+public class RegistrationDto extends ServiceDto {
+    /** 插件描述 */
+    private String desc = "典型轨道交通运行控制网代理插件";
+    /** 是否总代理 (0是) */
+    @NotBlank
+    private Integer isGeneral = 0;
+}

+ 38 - 0
src/main/java/com/cec/plugins/domain/reported/ServiceDto.java

@@ -0,0 +1,38 @@
+package com.cec.plugins.domain.reported;
+
+import lombok.Data;
+
+import javax.validation.constraints.NotBlank;
+
+/**
+ * @author zhanghaijun
+ * @version 1.0
+ * @date 2023/8/15 23:33
+ * @description [一句话描述该类的功能]
+ */
+@Data
+public class ServiceDto {
+
+    /** 插件名称 */
+    @NotBlank
+    private String serviceName = "RailwayAgent";
+    /** 插件的IP地址 */
+    @NotBlank
+    private String ipAddress;
+    /** 插件通信的端口号 */
+    @NotBlank
+    private String port;
+    /** 插件的唯一识别码 */
+    @NotBlank
+    private String type = "1";
+
+// 靶标名称:
+// 1、典型轨道交通运行控制网模拟系统
+// 2、智能交通控制网模拟系统
+// 3、典型物联网模拟系统
+// 4、典型城市公共事业控制网络模拟系统
+// 5、典型电力调度网模拟系统
+// 6、油气炼化控制网模拟系统
+// 7、油气管道传输控制网模拟系统
+// 8、典型金融业务控制网模拟系统
+}

+ 0 - 34
src/main/java/com/cec/plugins/properties/RedisProperties.java

@@ -1,34 +0,0 @@
-package com.cec.plugins.properties;
-
-import lombok.Data;
-import org.springframework.boot.context.properties.ConfigurationProperties;
-
-/**
- * @author zhanghaijun
- * @date 2023/8/11 17:38
- * @description Redis配置参数
- */
-@Data
-@ConfigurationProperties(prefix = "redisson")
-public class RedisProperties {
-
-    /** 客户端名称 */
-    private String clientName;
-
-    /** 地址 */
-    private String host = "localhost";
-    /** 端口 */
-    private int port = 6379;
-    /** 认证密码 */
-    private String password;
-    /** 是否加密传输 */
-    private boolean ssl = false;
-    /** 库 */
-    private int database = 0;
-
-
-    public String getUrl() {
-        String protocol = isSsl() ? "rediss" : "redis";
-        return protocol + "://" + getHost() + ":" + getPort();
-    }
-}

+ 0 - 20
src/main/java/com/cec/plugins/properties/RetryProperties.java

@@ -1,20 +0,0 @@
-package com.cec.plugins.properties;
-
-import lombok.Data;
-import org.springframework.boot.context.properties.ConfigurationProperties;
-
-/**
- * @author zhanghaijun
- * @version 1.0
- * @date 2023/8/15 18:41
- * @description [一句话描述该类的功能]
- */
-@Data
-@ConfigurationProperties(prefix = "retry")
-public class RetryProperties {
-
-    /** 最大重试此处 */
-    private final int retries;
-    /** 间隔时间(毫秒) */
-    private final long delayMillis;
-}

+ 24 - 0
src/main/java/com/cec/plugins/service/RedisEvaluate.java

@@ -0,0 +1,24 @@
+package com.cec.plugins.service;
+
+import com.cec.plugins.core.RedisManage;
+import com.cec.plugins.utils.SpringUtils;
+import org.redisson.api.RedissonClient;
+import org.springframework.stereotype.Service;
+
+import java.util.Optional;
+
+/**
+ * @author zhanghaijun
+ * @version 1.0
+ * @date 2023/8/16 00:06
+ * @description [一句话描述该类的功能]
+ */
+@Service
+public class RedisEvaluate extends RedisManage {
+
+    @Override
+    public RedissonClient getClient() {
+        RedissonClient bean = SpringUtils.getBean("redisEvaluate");
+        return Optional.ofNullable(bean).orElseThrow(() -> new RuntimeException("Source redis cannot connect..."));
+    }
+}

+ 24 - 0
src/main/java/com/cec/plugins/service/RedisSource.java

@@ -0,0 +1,24 @@
+package com.cec.plugins.service;
+
+import com.cec.plugins.core.RedisManage;
+import com.cec.plugins.utils.SpringUtils;
+import org.redisson.api.RedissonClient;
+import org.springframework.stereotype.Service;
+
+import java.util.Optional;
+
+/**
+ * @author zhanghaijun
+ * @version 1.0
+ * @date 2023/8/16 00:01
+ * @description [一句话描述该类的功能]
+ */
+@Service
+public class RedisSource extends RedisManage {
+
+    @Override
+    public RedissonClient getClient() {
+        RedissonClient bean = SpringUtils.getBean("redisResource");
+        return Optional.ofNullable(bean).orElseThrow(() -> new RuntimeException("Source redis cannot connect..."));
+    }
+}

+ 19 - 0
src/main/java/com/cec/plugins/service/ReportedService.java

@@ -0,0 +1,19 @@
+package com.cec.plugins.service;
+
+import com.cec.plugins.config.properties.RetryProperties;
+import lombok.RequiredArgsConstructor;
+import org.springframework.stereotype.Service;
+
+/**
+ * @author zhanghaijun
+ * @date 2023/8/15 23:03
+ * @description 上报业务处理
+ */
+@Service
+@RequiredArgsConstructor
+public class ReportedService {
+
+    private final RetryProperties properties;
+
+
+}

+ 19 - 0
src/main/java/com/cec/plugins/service/TaskService.java

@@ -1,5 +1,9 @@
 package com.cec.plugins.service;
 
+import com.cec.plugins.domain.DtoTaskStatus;
+import com.cec.plugins.enumerate.TaskEnum;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 
 /**
@@ -7,6 +11,21 @@ import org.springframework.stereotype.Service;
  * @date 2023/8/13 00:23
  * @description 任务相关的处理
  */
+@Slf4j
 @Service
+@RequiredArgsConstructor
 public class TaskService {
+
+    private final RedisSource redisSource;
+
+    public boolean saveTaskStatus(DtoTaskStatus dto) {
+        redisSource.setCacheObject(TaskEnum.TaskId.getKey(), dto.getTaskId());
+        redisSource.setCacheObject(TaskEnum.SubTaskId.getKey(), dto.getSubtaskId());
+        redisSource.setCacheObject(TaskEnum.XdSchemaId.getKey(), dto.getXdschemaId());
+
+        redisSource.setCacheObject(TaskEnum.TaskInstanceId.getKey(), dto.getInstanceId());
+        redisSource.setCacheObject(TaskEnum.TaskIdent.getKey(), dto.getIdent());
+        redisSource.setCacheObject(TaskEnum.TaskStatusOrder.getKey(), dto.getStatus());
+        return true;
+    }
 }

+ 9 - 0
src/main/java/com/cec/plugins/service/integration/ReportedPlatform.java

@@ -1,14 +1,23 @@
 package com.cec.plugins.service.integration;
 
+import com.cec.plugins.config.properties.RetryProperties;
+import com.cec.plugins.core.retry.RetryException;
 import com.cec.plugins.core.retry.RetryTemplate;
+import lombok.extern.slf4j.Slf4j;
 
 /**
  * @author zhanghaijun
  * @date 2023/8/15 18:37
  * @description 上报平台数据
  */
+@Slf4j
 public class ReportedPlatform extends RetryTemplate {
 
+
+    public ReportedPlatform(RetryProperties.RetryModel model) {
+        super(model.getRetries(), model.getDelayMillis(), RetryException.class);
+    }
+
     @Override
     protected Object handle() throws Exception {
         return null;

+ 5 - 0
src/main/java/com/cec/plugins/service/integration/ReportedQuery.java

@@ -1,5 +1,7 @@
 package com.cec.plugins.service.integration;
 
+import com.cec.plugins.config.properties.RetryProperties;
+import com.cec.plugins.core.retry.RetryException;
 import com.cec.plugins.core.retry.RetryTemplate;
 import lombok.extern.slf4j.Slf4j;
 
@@ -11,6 +13,9 @@ import lombok.extern.slf4j.Slf4j;
 @Slf4j
 public class ReportedQuery extends RetryTemplate {
 
+    public ReportedQuery(RetryProperties.RetryModel model) {
+        super(model.getRetries(), model.getDelayMillis(), RetryException.class);
+    }
 
     @Override
     protected Object handle() throws Exception {

+ 23 - 5
src/main/resources/application.yml

@@ -1,8 +1,7 @@
 spring:
   application:
     name: plugins
-  redis:
-    url:
+
 server:
   port: 8080
 
@@ -13,6 +12,25 @@ logging:
   config: classpath:logback.xml
 
 redisson:
-  client-name: ${spring.application.name}
-  host: 127.0.0.1
-  port: 6379
+  source:
+    client-name: ${spring.application.name}
+    host: 127.0.0.1
+    port: 6379
+    database: 0
+  evaluate:
+    client-name: ${spring.application.name}
+    host: 127.0.0.1
+    port: 6379
+    database: 0
+
+project:
+  platform:
+    url: http://127.0.0.1:${server.port}
+    retries: 3
+    delay-millis: 1000
+  plugin:
+    ip-address: 127.0.0.1
+    port: ${server.port}
+  simulation:
+    retries: 3
+    delay-millis: 1000

+ 58 - 63
src/test/java/com/cec/plugins/PluginsApplicationTests.java

@@ -1,34 +1,30 @@
 package com.cec.plugins;
 
-import com.cec.plugins.utils.RedisUtils;
-import com.cec.plugins.utils.RedisUtils2;
+import com.cec.plugins.service.RedisSource;
+import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.junit.jupiter.api.Test;
-import org.redisson.api.*;
+import org.redisson.api.RKeys;
 import org.springframework.boot.test.context.SpringBootTest;
 
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
 import java.util.Optional;
-import java.util.concurrent.ExecutionException;
 
 /**
  * {@see 'https://www.cnblogs.com/east7/p/16255305.html'}
  */
 @Slf4j
 @SpringBootTest
-// @RequiredArgsConstructor
+@RequiredArgsConstructor
 class PluginsApplicationTests {
 
-    private final RedisUtils2 redisUtils = null;
+    private final RedisSource RedisSource;
 
     @Test
     void contextLoads() {
-        RedisUtils.setCacheObject("111", "2222");
-        System.out.println(Optional.ofNullable(RedisUtils.getCacheObject("111")).orElse("--"));
+        RedisSource.setCacheObject("111", "2222");
+        System.out.println(Optional.ofNullable(RedisSource.getCacheObject("111")).orElse("--"));
 
-        RKeys keys = RedisUtils.getClient().getKeys();
+        RKeys keys = RedisSource.getClient().getKeys();
         // 获取所有key值
         Iterable<String> allKeys = keys.getKeys();
         // 模糊查询所有包含关键字key的值
@@ -43,55 +39,54 @@ class PluginsApplicationTests {
         long keysAmount = keys.count();
     }
 
-    private void strDemo() {
-        redisUtils.setStr("9999999999", "Hello, String.");
-        redisUtils.setStr("myBucket", "myBucketIsXxx");
-        RBuckets buckets = redisUtils.getBuckets();
-        Map<String, String> foundBuckets = buckets.get("myBucket*");
-        Map<String, Object> map = new HashMap<>();
-        map.put("myBucket1", "value1");
-        map.put("myBucket2", 30L);
-
-        // 同时保存全部通用对象桶。
-        buckets.set(map);
-        Map<String, String> loadedBuckets = buckets.get("myBucket1", "myBucket2", "myBucket3");
-        log.info("跨桶String 测试数据:{}", loadedBuckets);
-        map.put("myBucket3", 320L);
-    }
-
-    /**
-     * 批量操作
-     */
-    private void batchDemo() throws ExecutionException, InterruptedException {
-        Map<String, String> map = new HashMap<>();
-        map.put("abc", "testStr");
-        map.put("abcDemo", "redis");
-        redisUtils.setMassStrings(map);
-
-        log.info("String 测试数据:{}", redisUtils.getStr("abc") + " "
-                + redisUtils.getStr("abcDemo"));
-
-        RBatch batch = redisUtils.createBatch();
-        // 模拟购物车场景,真实场景中请替换店铺ID shopId 和商品ID commodityId
-        String field = "shopId:commodityId";
-        // 把即将执⾏的命令放进 RBatch
-        RMapAsync<Object, Object> testMap = batch.getMap("customerId:"+ 32L);
-        // 更新value,并返回上一次的值
-        String commodityNum = "mapValue" + String.valueOf((int)(Math.random()*9 + 100));
-        log.info("当前商品数量commodityNum是:{}", commodityNum);
-        testMap.putAsync(field, commodityNum);
-        testMap.putAsync("test2", "mapValue3");
-        testMap.putAsync("test2", "mapValue5");
-        testMap.putAsync("test:"+ String.valueOf((int)(Math.random()*900 + 100)), String.valueOf((int)(Math.random()*900 + 100)));
-
-        RAtomicLongAsync counter = batch.getAtomicLong("counter");
-
-        RFuture<Long> num = counter.incrementAndGetAsync();
-
-        // 执行RBatch中的全部命令,并返回执行结果
-        BatchResult<?> result = batch.execute();
-        List<?> list = result.getResponses();
-        log.info("Map Batch 执行结果:{}", list);
-        log.info("计数器当前值:{}", num.get());
-    }
+    // private RedisUtils2 redisUtils = null;
+    // private void strDemo() {
+    //     redisUtils.setStr("9999999999", "Hello, String.");
+    //     redisUtils.setStr("myBucket", "myBucketIsXxx");
+    //     RBuckets buckets = redisUtils.getBuckets();
+    //     Map<String, String> foundBuckets = buckets.get("myBucket*");
+    //     Map<String, Object> map = new HashMap<>();
+    //     map.put("myBucket1", "value1");
+    //     map.put("myBucket2", 30L);
+    //
+    //     // 同时保存全部通用对象桶。
+    //     buckets.set(map);
+    //     Map<String, String> loadedBuckets = buckets.get("myBucket1", "myBucket2", "myBucket3");
+    //     log.info("跨桶String 测试数据:{}", loadedBuckets);
+    //     map.put("myBucket3", 320L);
+    // }
+    //
+    // /** 批量操作 */
+    // private void batchDemo() throws ExecutionException, InterruptedException {
+    //     Map<String, String> map = new HashMap<>();
+    //     map.put("abc", "testStr");
+    //     map.put("abcDemo", "redis");
+    //     redisUtils.setMassStrings(map);
+    //
+    //     log.info("String 测试数据:{}", redisUtils.getStr("abc") + " "
+    //         + redisUtils.getStr("abcDemo"));
+    //
+    //     RBatch batch = redisUtils.createBatch();
+    //     // 模拟购物车场景,真实场景中请替换店铺ID shopId 和商品ID commodityId
+    //     String field = "shopId:commodityId";
+    //     // 把即将执⾏的命令放进 RBatch
+    //     RMapAsync<Object, Object> testMap = batch.getMap("customerId:" + 32L);
+    //     // 更新value,并返回上一次的值
+    //     String commodityNum = "mapValue" + String.valueOf((int) (Math.random() * 9 + 100));
+    //     log.info("当前商品数量commodityNum是:{}", commodityNum);
+    //     testMap.putAsync(field, commodityNum);
+    //     testMap.putAsync("test2", "mapValue3");
+    //     testMap.putAsync("test2", "mapValue5");
+    //     testMap.putAsync("test:" + String.valueOf((int) (Math.random() * 900 + 100)), String.valueOf((int) (Math.random() * 900 + 100)));
+    //
+    //     RAtomicLongAsync counter = batch.getAtomicLong("counter");
+    //
+    //     RFuture<Long> num = counter.incrementAndGetAsync();
+    //
+    //     // 执行RBatch中的全部命令,并返回执行结果
+    //     BatchResult<?> result = batch.execute();
+    //     List<?> list = result.getResponses();
+    //     log.info("Map Batch 执行结果:{}", list);
+    //     log.info("计数器当前值:{}", num.get());
+    // }
 }

+ 4 - 0
tools/README.md

@@ -0,0 +1,4 @@
+## 运行read_excel.py
+```shell
+
+```

+ 16 - 0
tools/read_excel.py

@@ -0,0 +1,16 @@
+import openpyxl
+
+# 打开工作簿
+workbook = openpyxl.load_workbook('../docs/资源模型数据库定义表20230809.xlsx')
+
+# 选择工作表
+sheet = workbook['Sheet1']  # 替换成你的工作表名称
+
+# 遍历行
+for row in sheet.iter_rows(min_row=2, values_only=True):  # 从第2行开始遍历,values_only=True表示只获取单元格的值
+    col1_value = row[0]  # 假设第一列是数据的第一个值
+    col2_value = row[1]  # 假设第二列是数据的第二个值
+    # 在这里你可以处理读取到的数据,比如打印或者保存到其他数据结构中
+
+# 关闭工作簿
+workbook.close()