Pārlūkot izejas kodu

使用系统时间关闭相应的timer

zhoupeng 2 gadi atpakaļ
vecāks
revīzija
59b8d09fcd

+ 9 - 1
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/task/OpcDaChangeTask.java

@@ -45,6 +45,8 @@ public class OpcDaChangeTask extends TimerTask {
 
     private final String timeFormat;
 
+    private final Long endTime;
+
     private Boolean eventFlage = false;
 
     public OpcDaChangeTask(RedisUtil redisUtil,
@@ -57,7 +59,9 @@ public class OpcDaChangeTask extends TimerTask {
                            ItemGroup itemGroup,
                            DataSource dataSource,
                            Map<String, DataModel> map,
-                           List<com.example.opc_common.entity.Item> itemList, String timeFormat) {
+                           List<com.example.opc_common.entity.Item> itemList,
+                           String timeFormat,
+                           Long endTime) {
         this.redisUtil = redisUtil;
         this.opcAsyncTask = opcAsyncTask;
         this.cronId = cronId;
@@ -70,6 +74,7 @@ public class OpcDaChangeTask extends TimerTask {
         this.map = map;
         this.itemList = itemList;
         this.timeFormat = timeFormat;
+        this.endTime = endTime;
     }
 
     @Override
@@ -223,6 +228,9 @@ public class OpcDaChangeTask extends TimerTask {
                 if (Blank.isEmpty(flage)) {
                     flage = false;
                 }
+                if (System.currentTimeMillis() >= endTime) {
+                    flage = false;
+                }
                 if (!flage) {
                     //执行组装数据库的数据,以及生成驱动报表
                     String sqlCurrentYmdh = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id));

+ 9 - 1
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/task/OpcDaExceedTask.java

@@ -43,6 +43,8 @@ public class OpcDaExceedTask extends TimerTask {
 
     private final String timeFormat;
 
+    private final Long endTime;
+
     private Boolean eventFlage = false;
 
     public OpcDaExceedTask(RedisUtil redisUtil,
@@ -55,7 +57,9 @@ public class OpcDaExceedTask extends TimerTask {
                            ItemGroup itemGroup,
                            DataSource dataSource,
                            Map<String, DataModel> map,
-                           List<com.example.opc_common.entity.Item> itemList, String timeFormat) {
+                           List<com.example.opc_common.entity.Item> itemList,
+                           String timeFormat,
+                           Long endTime) {
         this.redisUtil = redisUtil;
         this.opcAsyncTask = opcAsyncTask;
         this.cronId = cronId;
@@ -68,6 +72,7 @@ public class OpcDaExceedTask extends TimerTask {
         this.map = map;
         this.itemList = itemList;
         this.timeFormat = timeFormat;
+        this.endTime = endTime;
     }
 
     @Override
@@ -187,6 +192,9 @@ public class OpcDaExceedTask extends TimerTask {
                 if (Blank.isEmpty(flage)) {
                     flage = false;
                 }
+                if (System.currentTimeMillis() >= endTime) {
+                    flage = false;
+                }
                 if (!flage) {
                     //执行组装数据库的数据,以及生成驱动报表
                     String sqlCurrentYmdh = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id));

+ 9 - 1
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/task/OpcDaFrequencyTask.java

@@ -43,6 +43,8 @@ public class OpcDaFrequencyTask extends TimerTask {
 
     private final String timeFormat;
 
+    private final Long endTime;
+
     private Boolean eventFlage = false;
 
     public OpcDaFrequencyTask(RedisUtil redisUtil,
@@ -55,7 +57,9 @@ public class OpcDaFrequencyTask extends TimerTask {
                               ItemGroup itemGroup,
                               DataSource dataSource,
                               Map<String, DataModel> map,
-                              List<com.example.opc_common.entity.Item> itemList, String timeFormat) {
+                              List<com.example.opc_common.entity.Item> itemList,
+                              String timeFormat,
+                              Long endTime) {
         this.redisUtil = redisUtil;
         this.opcAsyncTask = opcAsyncTask;
         this.cronId = cronId;
@@ -68,6 +72,7 @@ public class OpcDaFrequencyTask extends TimerTask {
         this.map = map;
         this.itemList = itemList;
         this.timeFormat = timeFormat;
+        this.endTime = endTime;
     }
 
     @Override
@@ -218,6 +223,9 @@ public class OpcDaFrequencyTask extends TimerTask {
                 if (Blank.isEmpty(flage)) {
                     flage = false;
                 }
+                if (System.currentTimeMillis() >= endTime) {
+                    flage = false;
+                }
                 if (!flage) {
                     //执行组装数据库的数据,以及生成驱动报表
                     String sqlCurrentYmdh = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id));

+ 9 - 1
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/task/OpcDaLowseTask.java

@@ -43,6 +43,8 @@ public class OpcDaLowseTask extends TimerTask {
 
     private final String timeFormat;
 
+    private final Long endTime;
+
     private Boolean eventFlage = false;
 
     public OpcDaLowseTask(RedisUtil redisUtil,
@@ -55,7 +57,9 @@ public class OpcDaLowseTask extends TimerTask {
                           ItemGroup itemGroup,
                           DataSource dataSource,
                           Map<String, DataModel> map,
-                          List<com.example.opc_common.entity.Item> itemList, String timeFormat) {
+                          List<com.example.opc_common.entity.Item> itemList,
+                          String timeFormat,
+                          Long endTime) {
         this.redisUtil = redisUtil;
         this.opcAsyncTask = opcAsyncTask;
         this.cronId = cronId;
@@ -68,6 +72,7 @@ public class OpcDaLowseTask extends TimerTask {
         this.map = map;
         this.itemList = itemList;
         this.timeFormat = timeFormat;
+        this.endTime = endTime;
     }
 
     @Override
@@ -187,6 +192,9 @@ public class OpcDaLowseTask extends TimerTask {
                 if (Blank.isEmpty(flage)) {
                     flage = false;
                 }
+                if (System.currentTimeMillis() >= endTime) {
+                    flage = false;
+                }
                 if (!flage) {
                     //执行组装数据库的数据,以及生成驱动报表
                     String sqlCurrentYmdh = String.valueOf(redisUtil.get(ConstantStr.VALUE_BELONG_TIME + id));

+ 12 - 12
chaunyi_opc/opc_da/src/main/java/com/example/opc_da/task/OpcDaTask.java

@@ -95,9 +95,9 @@ public class OpcDaTask {
                             dataSource,
                             map,
                             allItemList,
-                            timeFormat),
-                    startDate,
-                    endDate.getTime() - startDate.getTime());
+                            timeFormat,
+                            endDate.getTime()),
+                    startDate);
         } else if (readMode == ConstantStr.ON_CHANGE) {
             timer.schedule(new OpcDaChangeTask(redisUtil,
                             opcAsyncTask,
@@ -110,9 +110,9 @@ public class OpcDaTask {
                             dataSource,
                             map,
                             allItemList,
-                            timeFormat),
-                    startDate,
-                    endDate.getTime() - startDate.getTime());
+                            timeFormat,
+                            endDate.getTime()),
+                    startDate);
         } else if (readMode == ConstantStr.EXCEED_SET_VALUE) {
             timer.schedule(new OpcDaExceedTask(redisUtil,
                             opcAsyncTask,
@@ -125,9 +125,9 @@ public class OpcDaTask {
                             dataSource,
                             map,
                             allItemList,
-                            timeFormat),
-                    startDate,
-                    endDate.getTime() - startDate.getTime());
+                            timeFormat,
+                            endDate.getTime()),
+                    startDate);
         } else if (readMode == ConstantStr.LOWER_SET_VALUE) {
             timer.schedule(new OpcDaLowseTask(redisUtil,
                             opcAsyncTask,
@@ -140,9 +140,9 @@ public class OpcDaTask {
                             dataSource,
                             map,
                             allItemList,
-                            timeFormat),
-                    startDate,
-                    endDate.getTime() - startDate.getTime());
+                            timeFormat,
+                            endDate.getTime()),
+                    startDate);
         } else if (readMode == ConstantStr.SPECIFY_TIME) {
             timer.schedule(new OpcDaSpecifyTask(redisUtil,
                             opcAsyncTask,