Explorar el Código

修改中环数据迁移间隔

欧阳劲驰 hace 2 semanas
padre
commit
ec8084316d

+ 11 - 9
bespoke-gateway-zhscada/src/main/java/com/shkpr/service/bespokegateway/zhscada/components/DataMigrator.java

@@ -45,6 +45,11 @@ public class DataMigrator {
     private static final String CLASS_NAME = "DataCollector";
     private static final String BIZ_TYPE = LogFlagBusiType.ZHONG_HUAN_SACADA.toStrValue();
 
+    /**
+     * 多线程执行器
+     */
+    private static ExecutorService executor;
+
     final
     MigrateProperties migrateProperties;
     final
@@ -62,6 +67,11 @@ public class DataMigrator {
         this.deviceRegistry = deviceRegistry;
         this.sensorCollectDataService = sensorCollectDataService;
         this.influxDbUtil = influxDbUtil;
+
+        int size = Runtime.getRuntime().availableProcessors() * 8;
+        executor = Executors.newFixedThreadPool(size);
+        LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_ERROR, BIZ_TYPE, CLASS_NAME
+                , String.format("Scada迁移启动线程池, size:%d", size));
     }
 
     /**
@@ -76,8 +86,6 @@ public class DataMigrator {
 
         //加载传感器配置
         loadSensors();
-        //多线程执行器
-        ExecutorService executor = Executors.newFixedThreadPool(1);
 
         //设备
         List<Device> devices = deviceRegistry.findAll(ScadaPlatformMetadata.NAME);
@@ -96,14 +104,8 @@ public class DataMigrator {
                             , 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 startTime = previousHours == null ? timeRange.getMinTime() : timeRange.getMaxTime().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;
-                }
 
                 //查询数据
                 List<SensorCollectData> dates = sensorCollectDataService.findAlign(migrateProperties.getSchema(),

+ 2 - 2
bespoke-gateway-zhscada/src/main/java/com/shkpr/service/bespokegateway/zhscada/manager/DataMigrateManager.java

@@ -40,13 +40,13 @@ public class DataMigrateManager {
     public void init() {
         //迁移scada
         if (schedulingProperties.isTaskActive(ScadaPlatformMetadata.SchedulingKeys.MIGRATE_SCADA))
-            taskScheduler.execute(() -> dataMigrator.migrateScada(30 * 24));
+            taskScheduler.execute(() -> dataMigrator.migrateScada(7 * 24));
     }
 
     /**
      * 小时任务
      */
-    @Scheduled(cron = "0 * * * * ?")
+    @Scheduled(cron = "0 */15 * * * ?")
     public void hourTask() {
         //迁移scada
         if (schedulingProperties.isTaskActive(ScadaPlatformMetadata.SchedulingKeys.MIGRATE_SCADA))