Explorar el Código

定时任务优化

wangmiaomiao hace 11 meses
padre
commit
ae8635572c

+ 19 - 5
slibra-quartz/src/main/java/com/slibra/quartz/task/RyTask.java

@@ -56,10 +56,12 @@ public class RyTask
     @Autowired
     private TXinyiRobotMapper xinyiRobotMapper;
 //    public final static StopWatch watch = new StopWatch("task");
-    public static final String[] queryTags = {"信义污水厂JS_COD_Value","信义污水厂JS_PH_Value","信义污水厂JS_SS_Value","信义污水厂JS_ZL_Value","信义污水厂JS_ZA_Value","信义污水厂JS_AD_Value","信义污水厂JS_T_Value","信义污水厂进水泵房液位","信义污水厂出水瞬时流量","信义污水厂升级出水COD","信义污水厂升级出水PH","信义污水厂升级出水SS","信义污水厂升级出水TN","信义污水厂升级出水TP","信义污水厂升级出水氨氮","信义污水厂AIT202_Value","信义污水厂AIT203_Value","信义污水厂AIT207_Value","信义污水厂AIT206_Value","信义污水厂AIT209_Value","信义污水厂AIT210_Value","信义污水厂进水TDS","信义污水厂FT101_Value","信义污水厂SWCHHYHLB1_R_Value","信义污水厂SWCHHYHLB2_R_Value","信义污水厂SWCHHYHLB3_R_Value","信义污水厂SWCHHYHLB4_R_Value","信义污水厂SWCHHYHLB5_R_Value","信义污水厂SWCHHYHLB6_R_Value","信义污水厂SWCWNHLB1_R_Value","信义污水厂SWCWNHLB2_R_Value","信义污水厂SWCWNHLB3_R_Value","信义污水厂SWCWNHLB4_R_Value","信义污水厂SWCWNHLB5_R_Value","信义污水厂GFJ1_R_Value","信义污水厂GFJ2_R_Value","信义污水厂GFJ3_R_Value","信义污水厂GFJ4_R_Value","信义污水厂GFJ5_R_Value","信义污水厂GFJ6_R_Value","信义污水厂GFJ1_KQLL_Value","信义污水厂GFJ2_KQLL_Value","信义污水厂GFJ3_KQLL_Value","信义污水厂GFJ4_KQLL_Value","信义污水厂GFJ5_KQLL_Value","信义污水厂GFJ6_KQLL_Value"};
+    public static final String[] queryTags = {"信义污水厂JS_COD_Value","信义污水厂JS_PH_Value","信义污水厂JS_SS_Value","信义污水厂JS_ZL_Value","信义污水厂JS_ZA_Value","信义污水厂JS_AD_Value","信义污水厂JS_T_Value","信义污水厂进水泵房液位","信义污水厂出水瞬时流量","信义污水厂升级出水COD","信义污水厂升级出水PH","信义污水厂升级出水SS","信义污水厂升级出水TN","信义污水厂升级出水TP","信义污水厂升级出水氨氮","信义污水厂AIT202_Value","信义污水厂AIT203_Value","信义污水厂AIT207_Value","信义污水厂AIT206_Value","信义污水厂AIT209_Value","信义污水厂AIT210_Value","信义污水厂进水TDS","信义污水厂FT101_Value","信义污水厂SWCHHYHLB1_R_Value","信义污水厂SWCHHYHLB2_R_Value","信义污水厂SWCHHYHLB3_R_Value","信义污水厂SWCHHYHLB4_R_Value","信义污水厂SWCHHYHLB5_R_Value","信义污水厂SWCHHYHLB6_R_Value","信义污水厂SWCWNHLB1_R_Value","信义污水厂SWCWNHLB2_R_Value","信义污水厂SWCWNHLB3_R_Value","信义污水厂SWCWNHLB4_R_Value","信义污水厂SWCWNHLB5_R_Value","信义污水厂GFJ1_R_Value","信义污水厂GFJ2_R_Value","信义污水厂GFJ3_R_Value","信义污水厂GFJ4_R_Value","信义污水厂GFJ5_R_Value","信义污水厂GFJ6_R_Value","信义污水厂GFJ1_KQLL_Value","信义污水厂GFJ2_KQLL_Value","信义污水厂GFJ3_KQLL_Value","信义污水厂GFJ4_KQLL_Value","信义污水厂GFJ5_KQLL_Value","信义污水厂GFJ6_KQLL_Value","信义污水厂实际碳源加药量","信义污水厂除磷加药瞬时流量"};
 
     /**
      * 定时从工业库获取数据
+     *
+     * 2024年4月17日17:44:15 调整逻辑:考虑到因断电等情况导致服务断电,所以不再同步最近一小时,而是同步从上次成功的最后一条数据开始。
      */
     public void getIndustryData(){
         log.info("进入了定时同步工业库数据的任务");
@@ -70,8 +72,14 @@ public class RyTask
 
         // 给定时间段的起始时间和结束时间
         LocalDateTime endTime =  LocalDateTime.now();
-        LocalDateTime startTime = endTime.plusMinutes(-60);
-
+        //todo
+//        LocalDateTime startTime = endTime.plusMinutes(-60);
+        //获取上次最后一条同步的数据的日期到小时维度
+        String lastDateHour = this.xinyiIndustryMapper.getLastHour();
+        log.info("获取上次同步工业库的最后一条记录的时间是{}", lastDateHour);
+        lastDateHour = lastDateHour + ":00:00";
+        log.info("需要从{}开始同步工业库数据", lastDateHour);
+        LocalDateTime startTime = LocalDateTime.parse(lastDateHour.replaceAll("/", "-").replace(" ", "T"));
 
         /*LocalDateTime startTime = LocalDateTime.parse("2024-02-26T00:00:00");
         LocalDateTime endTime = LocalDateTime.parse("2024-02-27T00:00:00");*/
@@ -354,9 +362,15 @@ public class RyTask
         System.out.println("endTime = " + endTime);
         endTime = endTime.plusMinutes(60);
         System.out.println("endTime = " + endTime);*/
-        String str = "2024/04/15 09:55";
+        /*String str = "2024/04/15 09:55";
         System.out.println(str);
         System.out.println(str.substring(0,10));
-        System.out.println(str.substring(0,13));
+        System.out.println(str.substring(0,13));*/
+        String str = "2024/03/31 23";
+        str = str + ":00:00";
+        System.out.println(str);
+        LocalDateTime startTime = LocalDateTime.parse(str.replaceAll("/", "-").replace(" ", "T"));
+        System.out.println(startTime.plusHours(1L).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
+
     }
 }

+ 2 - 0
slibra-system/src/main/java/com/slibra/business/mapper/TXinyiIndustryMapper.java

@@ -67,4 +67,6 @@ public interface TXinyiIndustryMapper
 
     Integer updateTXinyiIndustryCLByBetweenTime(@Param("beginTime") String beginTime, @Param("endTime") String endTime, @Param("cljyssll") BigDecimal cljyssll);
     Integer updateTXinyiIndustrySJByBetweenTime(@Param("beginTime") String beginTime, @Param("endTime") String endTime, @Param("sjtyjly") BigDecimal sjtyjly);
+
+    String getLastHour();
 }

+ 4 - 0
slibra-system/src/main/resources/mapper/business/TXinyiIndustryMapper.xml

@@ -325,4 +325,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         update t_xinyi_industry set SJTYJLY = #{sjtyjly}
         where TEST_TIME between #{beginTime} and #{endTime}
     </update>
+
+    <select id="getLastHour" resultType="string">
+        SELECT TEST_HOUR FROM t_xinyi_industry  ORDER BY id DESC LIMIT 1
+    </select>
 </mapper>