|
|
@@ -0,0 +1,93 @@
|
|
|
+package com.shkpr.service.customgateway.zhscada.components;
|
|
|
+
|
|
|
+
|
|
|
+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.po.DeviceTags;
|
|
|
+import com.shkpr.service.customgateway.core.properties.CallingProperties;
|
|
|
+import com.shkpr.service.customgateway.core.service.DeviceTagsService;
|
|
|
+import com.shkpr.service.customgateway.core.utils.CallingUtil;
|
|
|
+import com.shkpr.service.customgateway.zhscada.constants.ScadaPlatformMetadata;
|
|
|
+import com.shkpr.service.customgateway.zhscada.domain.ScadaPlatformVariables;
|
|
|
+import com.shkpr.service.customgateway.zhscada.domain.ScadaPlatformVariablesResult;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.http.HttpMethod;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 信息同步器
|
|
|
+ *
|
|
|
+ * @author 欧阳劲驰
|
|
|
+ * @since 1.0.0
|
|
|
+ */
|
|
|
+@Component
|
|
|
+@Slf4j
|
|
|
+public class InfoSynchronizer {
|
|
|
+ /**
|
|
|
+ * log
|
|
|
+ */
|
|
|
+ private static final String BIZ_TYPE = "InfoSynchronizer";
|
|
|
+ private static final String CLASS_NAME = LogFlagBusiType.BUSI_ALL.toStrValue();
|
|
|
+
|
|
|
+ final
|
|
|
+ CallingProperties callingProperties;
|
|
|
+ final
|
|
|
+ DeviceTagsService deviceTagsService;
|
|
|
+ final
|
|
|
+ CallingUtil callingUtil;
|
|
|
+
|
|
|
+ public InfoSynchronizer(CallingProperties callingProperties, DeviceTagsService deviceTagsService, CallingUtil callingUtil) {
|
|
|
+ this.callingProperties = callingProperties;
|
|
|
+ this.deviceTagsService = deviceTagsService;
|
|
|
+ this.callingUtil = callingUtil;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 同步标签
|
|
|
+ */
|
|
|
+ public void syncDeviceTags() {
|
|
|
+ LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, BIZ_TYPE, CLASS_NAME
|
|
|
+ , "开始同步采集标签,开始拉取数据");
|
|
|
+ long begin = System.currentTimeMillis();
|
|
|
+
|
|
|
+ //对接点
|
|
|
+ CallingProperties.CallingEndpoint endpoint = callingProperties.getEndpoints().get(ScadaPlatformMetadata.NAME);
|
|
|
+ //请求地址
|
|
|
+ String url = endpoint.getUrl() + ScadaPlatformMetadata.Uri.VARIABLES;
|
|
|
+
|
|
|
+ //参数
|
|
|
+ Map<String, Object> params = Collections.singletonMap(ScadaPlatformMetadata.Params.PROJECT_NAME,
|
|
|
+ ScadaPlatformMetadata.DefaultValues.PROJECT_NAME);
|
|
|
+ //请求结果项
|
|
|
+ List<ScadaPlatformVariables> items = callingUtil.request(url, HttpMethod.GET, params, Collections.emptyList(),
|
|
|
+ new TypeReference<ScadaPlatformVariablesResult<List<ScadaPlatformVariables>>>() {
|
|
|
+ });
|
|
|
+ LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, BIZ_TYPE, CLASS_NAME
|
|
|
+ , String.format("拉取标签成功,数据量:%d", items.size()));
|
|
|
+
|
|
|
+
|
|
|
+ //转换采集标签对象
|
|
|
+ List<DeviceTags> dates = items.stream()
|
|
|
+ .map(var -> var.toDeviceTags(ScadaPlatformMetadata.NAME))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ //更新采集标签
|
|
|
+ Boolean upserted = deviceTagsService.syncDeviceTags(ScadaPlatformMetadata.NAME, dates);
|
|
|
+
|
|
|
+ long end = System.currentTimeMillis();
|
|
|
+ LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, BIZ_TYPE, CLASS_NAME
|
|
|
+ , String.format(
|
|
|
+ "结束执行同步采集标签,同步状态:%s,用时(毫秒):%d"
|
|
|
+ , upserted
|
|
|
+ , (end - begin)
|
|
|
+ )
|
|
|
+ );
|
|
|
+ }
|
|
|
+}
|