Przeglądaj źródła

删除内部类

欧阳劲驰 1 miesiąc temu
rodzic
commit
86a212a784

+ 25 - 0
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/domain/CallingEndpoint.java

@@ -0,0 +1,25 @@
+package com.shkpr.service.customgateway.core.domain;
+
+import lombok.Data;
+
+/**
+ * 对接信息
+ *
+ * @author 欧阳劲驰
+ * @since 1.0.0
+ */
+@Data
+public class CallingEndpoint {
+    /**
+     * 地址
+     */
+    private String url;
+    /**
+     * 账号
+     */
+    private String accessKey;
+    /**
+     * 密码
+     */
+    private String secretKey;
+}

+ 11 - 0
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/properties/CallingProperties.java

@@ -1,5 +1,6 @@
 package com.shkpr.service.customgateway.core.properties;
 
+import com.shkpr.service.customgateway.core.utils.BeanUtil;
 import lombok.Data;
 import lombok.Getter;
 import lombok.Setter;
@@ -32,6 +33,16 @@ public class CallingProperties {
     private Map<String, CallingEndpoint> endpoints;
 
     /**
+     * 获取对接点
+     *
+     * @param name 平台名称
+     * @return 对接信息
+     */
+    public com.shkpr.service.customgateway.core.domain.CallingEndpoint getEndpoint(String name) {
+        return BeanUtil.copy(endpoints.getOrDefault(name, null), com.shkpr.service.customgateway.core.domain.CallingEndpoint.class);
+    }
+
+    /**
      * 对接点
      */
     @Data

+ 35 - 0
custom-gateway-core/src/main/java/com/shkpr/service/customgateway/core/utils/BeanUtil.java

@@ -0,0 +1,35 @@
+package com.shkpr.service.customgateway.core.utils;
+
+import org.apache.commons.lang3.ObjectUtils;
+import org.springframework.beans.BeanUtils;
+
+/**
+ * bean工具类
+ *
+ * @author 欧阳劲驰
+ * @since 1.0.0
+ */
+public class BeanUtil {
+
+    /**
+     * 拷贝
+     *
+     * @param source     被拷贝对象
+     * @param targetType 类型
+     * @param <T>        类型
+     * @return 新对象
+     */
+    public static <T> T copy(Object source, Class<T> targetType) {
+        try {
+            if (!ObjectUtils.allNotNull(source, targetType)) {
+                return null;
+            }
+            //拷贝资源
+            T t = targetType.getDeclaredConstructor().newInstance();
+            BeanUtils.copyProperties(source, t);
+            return t;
+        } catch (ReflectiveOperationException e) {
+            return null;
+        }
+    }
+}

+ 2 - 1
custom-gateway-zhscada/src/main/java/com/shkpr/service/customgateway/zhscada/components/DataCollector.java

@@ -5,6 +5,7 @@ import com.global.base.log.LogLevelFlag;
 import com.global.base.log.LogPrintMgr;
 import com.shkpr.service.customgateway.core.components.DeviceRegistry;
 import com.shkpr.service.customgateway.core.constants.LogFlagBusiType;
+import com.shkpr.service.customgateway.core.domain.CallingEndpoint;
 import com.shkpr.service.customgateway.core.domain.Device;
 import com.shkpr.service.customgateway.core.domain.DeviceTag;
 import com.shkpr.service.customgateway.core.exception.SelfException;
@@ -60,7 +61,7 @@ public class DataCollector {
         long begin = System.currentTimeMillis();
 
         //平台对接点
-        CallingProperties.CallingEndpoint endpoint = callingProperties.getEndpoints().get(ScadaPlatformMetadata.NAME);
+        CallingEndpoint endpoint = callingProperties.getEndpoint(ScadaPlatformMetadata.NAME);
         //请求地址
         String url = endpoint.getUrl() + ScadaPlatformMetadata.Uri.REAL_TIME_DATA;
 

+ 2 - 1
custom-gateway-zhscada/src/main/java/com/shkpr/service/customgateway/zhscada/components/InfoSynchronizer.java

@@ -5,6 +5,7 @@ import com.fasterxml.jackson.core.type.TypeReference;
 import com.global.base.log.LogLevelFlag;
 import com.global.base.log.LogPrintMgr;
 import com.shkpr.service.customgateway.core.constants.LogFlagBusiType;
+import com.shkpr.service.customgateway.core.domain.CallingEndpoint;
 import com.shkpr.service.customgateway.core.domain.po.DeviceTags;
 import com.shkpr.service.customgateway.core.exception.SelfException;
 import com.shkpr.service.customgateway.core.properties.CallingProperties;
@@ -59,7 +60,7 @@ public class InfoSynchronizer {
         long begin = System.currentTimeMillis();
 
         //对接点
-        CallingProperties.CallingEndpoint endpoint = callingProperties.getEndpoints().get(ScadaPlatformMetadata.NAME);
+        CallingEndpoint endpoint = callingProperties.getEndpoint(ScadaPlatformMetadata.NAME);
         //请求地址
         String url = endpoint.getUrl() + ScadaPlatformMetadata.Uri.VARIABLES;
 

+ 2 - 1
custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/components/DataCollector.java

@@ -6,6 +6,7 @@ import com.global.base.log.LogPrintMgr;
 import com.shkpr.service.customgateway.core.components.DeviceIdGenerator;
 import com.shkpr.service.customgateway.core.components.DeviceRegistry;
 import com.shkpr.service.customgateway.core.constants.LogFlagBusiType;
+import com.shkpr.service.customgateway.core.domain.CallingEndpoint;
 import com.shkpr.service.customgateway.core.domain.Device;
 import com.shkpr.service.customgateway.core.domain.DeviceTag;
 import com.shkpr.service.customgateway.core.domain.IntegrationKey;
@@ -80,7 +81,7 @@ public class DataCollector {
         long begin = System.currentTimeMillis();
 
         //平台对接点
-        CallingProperties.CallingEndpoint endpoint = callingProperties.getEndpoints().get(IotPlatformMetadata.NAME);
+        CallingEndpoint endpoint = callingProperties.getEndpoint(IotPlatformMetadata.NAME);
 
         //===================获取密钥===================
         try {

+ 6 - 5
custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/components/InfoSynchronizer.java

@@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.type.TypeReference;
 import com.global.base.log.LogLevelFlag;
 import com.global.base.log.LogPrintMgr;
 import com.shkpr.service.customgateway.core.constants.LogFlagBusiType;
+import com.shkpr.service.customgateway.core.domain.CallingEndpoint;
 import com.shkpr.service.customgateway.core.domain.IntegrationKey;
 import com.shkpr.service.customgateway.core.domain.po.FunctionInfo;
 import com.shkpr.service.customgateway.core.domain.po.PersonnelInfo;
@@ -68,7 +69,7 @@ public class InfoSynchronizer {
         long begin = System.currentTimeMillis();
 
         //对接点
-        CallingProperties.CallingEndpoint endpoint = callingProperties.getEndpoints().get(MiddlePlatformMetadata.NAME);
+        CallingEndpoint endpoint = callingProperties.getEndpoint(MiddlePlatformMetadata.NAME);
 
         //获取用户
         List<MiddlePlatformUser> users = getUsers(endpoint);
@@ -119,7 +120,7 @@ public class InfoSynchronizer {
         long begin = System.currentTimeMillis();
 
         //对接点
-        CallingProperties.CallingEndpoint endpoint = callingProperties.getEndpoints().get(MiddlePlatformMetadata.NAME);
+        CallingEndpoint endpoint = callingProperties.getEndpoint(MiddlePlatformMetadata.NAME);
 
         //获取角色
         List<MiddlePlatformRole> roles = getRoles(endpoint);
@@ -146,7 +147,7 @@ public class InfoSynchronizer {
      * @param endpoint 对接点
      * @return 用户列表
      */
-    private List<MiddlePlatformUser> getUsers(CallingProperties.CallingEndpoint endpoint) {
+    private List<MiddlePlatformUser> getUsers(CallingEndpoint endpoint) {
         //请求地址
         String url = endpoint.getUrl() + MiddlePlatformMetadata.Uri.GET_USERS;
         //请求获取用户
@@ -180,7 +181,7 @@ public class InfoSynchronizer {
      * @param endpoint 对接点
      * @return 角色列表
      */
-    private List<MiddlePlatformRole> getRoles(CallingProperties.CallingEndpoint endpoint) {
+    private List<MiddlePlatformRole> getRoles(CallingEndpoint endpoint) {
         //结果
         List<MiddlePlatformRole> result = new ArrayList<>();
         //请求地址
@@ -237,7 +238,7 @@ public class InfoSynchronizer {
      * @param endpoint 对接点
      * @return 角色列表
      */
-    private List<MiddlePlatformUserRole> getUserRoles(CallingProperties.CallingEndpoint endpoint) {
+    private List<MiddlePlatformUserRole> getUserRoles(CallingEndpoint endpoint) {
         //请求地址
         String url = endpoint.getUrl() + MiddlePlatformMetadata.Uri.GET_USER_ROLES;
         //参数

+ 2 - 2
custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/constants/IotPlatformMetadata.java

@@ -3,8 +3,8 @@ package com.shkpr.service.customgateway.zydma.constants;
 import com.fasterxml.jackson.annotation.JsonAlias;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.shkpr.service.customgateway.core.constants.*;
+import com.shkpr.service.customgateway.core.domain.CallingEndpoint;
 import com.shkpr.service.customgateway.core.domain.IntegrationKey;
-import com.shkpr.service.customgateway.core.properties.CallingProperties;
 import lombok.AllArgsConstructor;
 import lombok.Data;
 import lombok.Getter;
@@ -40,7 +40,7 @@ public abstract class IotPlatformMetadata {
     /**
      * 获取密钥
      */
-    public static IntegrationKey getKey(CallingProperties.CallingEndpoint endpoint) throws IOException {
+    public static IntegrationKey getKey(CallingEndpoint endpoint) throws IOException {
         //请求token
         Response response = Request.Post(endpoint.getUrl() + Uri.GENERATE_TOKEN)
                 .addHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)

+ 2 - 1
custom-gateway-zydma/src/main/java/com/shkpr/service/customgateway/zydma/controller/UserController.java

@@ -6,6 +6,7 @@ import com.global.base.log.LogPrintMgr;
 import com.shkpr.service.customgateway.core.constants.Api;
 import com.shkpr.service.customgateway.core.constants.LogFlagBusiType;
 import com.shkpr.service.customgateway.core.constants.ResponseCode;
+import com.shkpr.service.customgateway.core.domain.CallingEndpoint;
 import com.shkpr.service.customgateway.core.domain.IntegrationKey;
 import com.shkpr.service.customgateway.core.domain.ResultResponse;
 import com.shkpr.service.customgateway.core.domain.TmpTokenData;
@@ -109,7 +110,7 @@ public class UserController {
 
         //===========================请求用户信息===========================
         //接入点
-        CallingProperties.CallingEndpoint endpoint = callingProperties.getEndpoints().get(MiddlePlatformMetadata.NAME);
+        CallingEndpoint endpoint = callingProperties.getEndpoint(MiddlePlatformMetadata.NAME);
         //地址
         String url = endpoint.getUrl() + MiddlePlatformMetadata.Uri.GET_USER_BY_TICKET;
         //参数