Explorar o código

删除静态引入

欧阳劲驰 hai 2 semanas
pai
achega
92d5fd0da9

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

@@ -12,6 +12,7 @@ import com.shkpr.service.customgateway.core.domain.IntegrationKey;
 import com.shkpr.service.customgateway.core.properties.CallingProperties;
 import com.shkpr.service.customgateway.core.utils.CallingUtil;
 import com.shkpr.service.customgateway.core.utils.InfluxDbUtil;
+import com.shkpr.service.customgateway.zydma.constants.IotPlatformMetadata;
 import com.shkpr.service.customgateway.zydma.domain.IotPlatformData;
 import com.shkpr.service.customgateway.zydma.domain.IotPlatformResult;
 import org.apache.commons.collections4.CollectionUtils;
@@ -30,8 +31,6 @@ import java.time.temporal.ChronoUnit;
 import java.util.*;
 import java.util.stream.Collectors;
 
-import static com.shkpr.service.customgateway.zydma.constants.IotPlatformMetadata.*;
-
 /**
  * 数据采集器
  *
@@ -49,8 +48,6 @@ public class DataCollector {
     final
     CallingProperties callingProperties;
     final
-    CallingProperties.CallingEndpoint endpoint;
-    final
     DeviceRegistry deviceRegistry;
     final
     DeviceIdGenerator deviceIdGenerator;
@@ -64,7 +61,6 @@ public class DataCollector {
 
     public DataCollector(CallingProperties callingProperties, DeviceRegistry deviceRegistry, DeviceIdGenerator deviceIdGenerator, InfluxDbUtil influxDbUtil, CallingUtil callingUtil) {
         this.callingProperties = callingProperties;
-        this.endpoint = callingProperties.getEndpoints().get(NAME);
         this.deviceRegistry = deviceRegistry;
         this.deviceIdGenerator = deviceIdGenerator;
         this.influxDbUtil = influxDbUtil;
@@ -82,9 +78,12 @@ public class DataCollector {
                 , "开始采集流量数据,开始拉取数据");
         long begin = System.currentTimeMillis();
 
+        //平台对接点
+        CallingProperties.CallingEndpoint endpoint = callingProperties.getEndpoints().get(IotPlatformMetadata.NAME);
+
         //===================获取密钥===================
         try {
-            if (key == null) key = getKey(endpoint);
+            if (key == null) key = IotPlatformMetadata.getKey(endpoint);
         } catch (IOException e) {
             LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_WARN, BIZ_TYPE, CLASS_NAME,
                     String.format("加载设备序号数据失败,error:%s", e));
@@ -93,12 +92,12 @@ public class DataCollector {
         if (key == null) return;
 
         //请求地址
-        String url = endpoint.getUrl() + Uri.GET_DEVICE_HISTORY_DATA;
+        String url = endpoint.getUrl() + IotPlatformMetadata.Uri.GET_DEVICE_HISTORY_DATA;
         //请求头
         List<Header> headers = Arrays.asList(
                 new BasicHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE),
-                new BasicHeader(Headers.PANDA_TOKEN, key.getAccessKey()),
-                new BasicHeader(Headers.AUTHORIZATION, key.getSecretKey())
+                new BasicHeader(IotPlatformMetadata.Headers.PANDA_TOKEN, key.getAccessKey()),
+                new BasicHeader(IotPlatformMetadata.Headers.AUTHORIZATION, key.getSecretKey())
         );
 
         //查询时间
@@ -109,9 +108,9 @@ public class DataCollector {
         List<Point> results = new ArrayList<>();
 
         //===================按设备类型遍历===================
-        for (DeviceMapping deviceMapping : DeviceMapping.values()) {
+        for (IotPlatformMetadata.DeviceMapping deviceMapping : IotPlatformMetadata.DeviceMapping.values()) {
             //参数
-            Map<String, Object> params = getHistoryDataParams(deviceMapping, beginTime, endTime);
+            Map<String, Object> params = IotPlatformMetadata.getHistoryDataParams(deviceMapping, beginTime, endTime);
             //请求结果项
             List<IotPlatformData> items = callingUtil.request(url, HttpMethod.POST, params, headers,
                     new TypeReference<IotPlatformResult<List<IotPlatformData>>>() {
@@ -174,7 +173,7 @@ public class DataCollector {
      * @param deviceMapping 设备类型映射
      * @param snGroup       数据集合
      */
-    private void registryDevices(DeviceMapping deviceMapping, Map<String, List<IotPlatformData>> snGroup) {
+    private void registryDevices(IotPlatformMetadata.DeviceMapping deviceMapping, Map<String, List<IotPlatformData>> snGroup) {
         //需要添加的设备
         Set<String> addedDevices = deviceRegistry.findAddedDevices(snGroup.keySet());
         //处理需要添加的设备:生成设备,并注册
@@ -185,7 +184,7 @@ public class DataCollector {
                         StringUtils.isNoneBlank(snGroup.get(sn).get(0).getName()))
                 //生成设备
                 .map(sn -> deviceIdGenerator.generateDevice(
-                        Devices.AREA_CODE,
+                        IotPlatformMetadata.Devices.AREA_CODE,
                         deviceMapping.getKind(),
                         buildTag(deviceMapping, snGroup.get(sn)),
                         sn, snGroup.get(sn).get(0).getName()
@@ -200,7 +199,7 @@ public class DataCollector {
      * @param deviceMapping 设备类型映射
      * @param snGroup       数据集合
      */
-    private void updateDevices(DeviceMapping deviceMapping, Map<String, List<IotPlatformData>> snGroup) {
+    private void updateDevices(IotPlatformMetadata.DeviceMapping deviceMapping, Map<String, List<IotPlatformData>> snGroup) {
         //构建设备信息,k:远传id,v:标签集合
         Map<String, Set<String>> deviceInfo = snGroup.entrySet().stream().collect(Collectors.toMap(
                 Map.Entry::getKey, entry ->
@@ -236,7 +235,7 @@ public class DataCollector {
      * @param items         结果项
      * @return 采集标签集合
      */
-    private List<DeviceTag> buildTag(DeviceMapping deviceMapping, List<IotPlatformData> items) {
+    private List<DeviceTag> buildTag(IotPlatformMetadata.DeviceMapping deviceMapping, List<IotPlatformData> items) {
         //传感器名称
         Set<String> sensorNames = items.stream()
                 .map(IotPlatformData::getSensorName)