|
|
@@ -21,7 +21,6 @@ import org.springframework.core.io.support.ResourcePatternResolver;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
-import java.time.LocalDateTime;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
@@ -78,14 +77,19 @@ public class DataMigrator {
|
|
|
//传感器code
|
|
|
String code = sensorMap.getOrDefault(tag.getTag(), null);
|
|
|
if (StringUtils.isBlank(code)) continue;
|
|
|
- //起止时间
|
|
|
- SensorCollectData timeRange = sensorCollectDataService.findTimeRange(migrateProperties.getSchema(),code);
|
|
|
- LocalDateTime minTime = timeRange.getMinTime();
|
|
|
- LocalDateTime maxTime = timeRange.getMaxTime();
|
|
|
+ //数据时间
|
|
|
+ SensorCollectData timeRange = sensorCollectDataService.findTimeRange(migrateProperties.getSchema(), code);
|
|
|
+ if (Objects.isNull(timeRange) || timeRange.getMinTime() == null || timeRange.getMaxTime() == null) {
|
|
|
+ LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_ERROR, BIZ_TYPE, CLASS_NAME
|
|
|
+ , String.format("读取Scada数据空数据, tag:%s, code: %s", tag.getTag(), code)
|
|
|
+ );
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
//查询数据
|
|
|
List<SensorCollectData> dates = sensorCollectDataService.findAlign(migrateProperties.getSchema(),
|
|
|
- minTime, maxTime, migrateProperties.getInterval(), migrateProperties.getIntervalUnit(),
|
|
|
- migrateProperties.getAlignUnit(), code);
|
|
|
+ timeRange.getMinTime(), timeRange.getMaxTime(), migrateProperties.getInterval(),
|
|
|
+ migrateProperties.getIntervalUnit(), migrateProperties.getAlignUnit(), code);
|
|
|
|
|
|
//构建influxdb
|
|
|
List<Point> points = dates.parallelStream().map(d -> d.toPoint(devices, sensorMap))
|
|
|
@@ -113,8 +117,12 @@ public class DataMigrator {
|
|
|
Resource resources = resourceResolver.getResources(migrateProperties.getSensorMapPath())[0];
|
|
|
//解析map
|
|
|
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
|
|
|
- sensorMap = mapper.readValue(resources.getFile(), mapper.getTypeFactory()
|
|
|
+ Map<String, String> readValues = mapper.readValue(resources.getFile(), mapper.getTypeFactory()
|
|
|
.constructMapType(HashMap.class, String.class, String.class));
|
|
|
+ //过滤空value
|
|
|
+ sensorMap = readValues.entrySet().stream()
|
|
|
+ .filter(entry -> StringUtils.isNotBlank(entry.getValue()))
|
|
|
+ .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
|
|
} catch (IOException e) {
|
|
|
LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_ERROR, BIZ_TYPE, CLASS_NAME
|
|
|
, String.format("传感器映射配置文件读取失败 error:%s", e)
|