|
@@ -21,6 +21,8 @@ import org.springframework.core.io.support.ResourcePatternResolver;
|
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
|
+import java.time.temporal.ChronoUnit;
|
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
@@ -64,8 +66,10 @@ public class DataMigrator {
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 迁移scada
|
|
* 迁移scada
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param previousHours 往前回溯小时数
|
|
|
*/
|
|
*/
|
|
|
- public void migrateScada() {
|
|
|
|
|
|
|
+ public void migrateScada(Integer previousHours) {
|
|
|
LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, BIZ_TYPE, CLASS_NAME
|
|
LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, BIZ_TYPE, CLASS_NAME
|
|
|
, "开始迁移Scada数据");
|
|
, "开始迁移Scada数据");
|
|
|
long begin = System.currentTimeMillis();
|
|
long begin = System.currentTimeMillis();
|
|
@@ -84,18 +88,26 @@ public class DataMigrator {
|
|
|
//传感器code
|
|
//传感器code
|
|
|
String code = sensorMap.getOrDefault(tag.getTag(), null);
|
|
String code = sensorMap.getOrDefault(tag.getTag(), null);
|
|
|
if (StringUtils.isBlank(code)) continue;
|
|
if (StringUtils.isBlank(code)) continue;
|
|
|
|
|
+
|
|
|
//数据时间
|
|
//数据时间
|
|
|
SensorCollectData timeRange = sensorCollectDataService.findTimeRange(migrateProperties.getSchema(), code);
|
|
SensorCollectData timeRange = sensorCollectDataService.findTimeRange(migrateProperties.getSchema(), code);
|
|
|
if (Objects.isNull(timeRange) || timeRange.getMinTime() == null || timeRange.getMaxTime() == null) {
|
|
if (Objects.isNull(timeRange) || timeRange.getMinTime() == null || timeRange.getMaxTime() == null) {
|
|
|
LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_ERROR, BIZ_TYPE, CLASS_NAME
|
|
LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_ERROR, BIZ_TYPE, CLASS_NAME
|
|
|
- , String.format("读取Scada数据空数据, tag:%s, code: %s", tag.getTag(), code)
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ , String.format("读取Scada数据空数据, tag:%s, code: %s", tag.getTag(), code));
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ LocalDateTime startTime = previousHours == null ? timeRange.getMinTime() : LocalDateTime.now().minusHours(previousHours).truncatedTo(ChronoUnit.HOURS);
|
|
|
|
|
+ LocalDateTime endTime = timeRange.getMaxTime();
|
|
|
|
|
+ if (startTime.isAfter(endTime)) {
|
|
|
|
|
+ LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, BIZ_TYPE, CLASS_NAME
|
|
|
|
|
+ , String.format("开始时间大于结束时间,跳过处理, tag:%s, code:%s, startTime:%s, endTime:%s",
|
|
|
|
|
+ tag.getTag(), code, startTime, endTime));
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//查询数据
|
|
//查询数据
|
|
|
List<SensorCollectData> dates = sensorCollectDataService.findAlign(migrateProperties.getSchema(),
|
|
List<SensorCollectData> dates = sensorCollectDataService.findAlign(migrateProperties.getSchema(),
|
|
|
- timeRange.getMinTime(), timeRange.getMaxTime(), migrateProperties.getInterval(),
|
|
|
|
|
|
|
+ startTime, endTime, migrateProperties.getInterval(),
|
|
|
migrateProperties.getIntervalUnit(), migrateProperties.getAlignUnit(), code);
|
|
migrateProperties.getIntervalUnit(), migrateProperties.getAlignUnit(), code);
|
|
|
|
|
|
|
|
//构建influxdb
|
|
//构建influxdb
|