Browse Source

日统计逻辑更改

丁治程 7 months ago
parent
commit
8c446f91ae

+ 7 - 0
jeecg-module-interlock/src/main/java/org/jeecg/modules/history/mapper/InterlockSummaryHistoryMapper.java

@@ -8,6 +8,7 @@ import org.jeecg.modules.history.entity.InterlockSummaryHistory;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import org.jeecg.modules.history.vo.InterlockHistoryDistinctZZXTVO;
 import org.jeecg.modules.interlockCountDay.entity.InterlockCountDay;
+import org.jeecg.modules.interlockSummaryDay.entity.InterlockSummaryDay;
 
 /**
  * @Description: 联锁总历史数据表
@@ -86,4 +87,10 @@ public interface InterlockSummaryHistoryMapper extends BaseMapper<InterlockSumma
     List<InterlockSummaryHistory> getSummaryHistoryList11(@Param("dto") InterlockHistoryQueryDTO dto);
 
 
+    List<InterlockCountDay> getLoopHealthLevelByTagTimeNew(@Param("currentday") String currentday);
+
+    List<InterlockCountDay> getInterlockStatusByTagTimeNew(@Param("currentDay") String currentDay);
+
+    List<InterlockSummaryDay> getCurrentDaySummaryInterlock();
+
 }

+ 57 - 0
jeecg-module-interlock/src/main/java/org/jeecg/modules/history/mapper/xml/InterlockSummaryHistoryMapper.xml

@@ -103,6 +103,32 @@
             h.interlock_system_id
     </select>
 
+
+    <select id="getLoopHealthLevelByTagTimeNew" resultType="org.jeecg.modules.interlockCountDay.entity.InterlockCountDay">
+        SELECT
+            h.interlock_system_id as interlock_system_id,
+            b.pid as device_id,
+            b.interlock_name as interlock_name,
+            h.loop_health_level as count_name,
+            COUNT( h.* ) AS count_num,
+            '0' as count_type,
+            #{currentday} as time
+        FROM
+            interlock_summary_day h
+            left join interlock_base b
+        on h.interlock_system_id = b.id
+        WHERE
+            h.tag_time LIKE TO_CHAR(#{currentday}::timestamp, 'YYYY-MM-DD') || '%'
+        GROUP BY
+            h.interlock_system_id,
+            b.pid,
+            b.interlock_name,
+            h.loop_health_level
+        ORDER BY
+            h.interlock_system_id
+    </select>
+
+
     <!-- 按日统计 投用状态(投用率) -->
     <select id="getInterlockStatusByTagTime" resultType="org.jeecg.modules.interlockCountDay.entity.InterlockCountDay">
         SELECT
@@ -128,6 +154,31 @@
             h.interlock_system_id
     </select>
 
+
+    <select id="getInterlockStatusByTagTimeNew" resultType="org.jeecg.modules.interlockCountDay.entity.InterlockCountDay">
+        SELECT
+            h.interlock_system_id as interlock_system_id,
+            b.pid as device_id,
+            b.interlock_name as interlock_name,
+            h.interlock_status as count_name,
+            COUNT( h.* ) AS count_num,
+            '1' as count_type,
+            #{currentDay} as time
+        FROM
+            "interlock_summary_day" h
+            left join interlock_base b
+        on h.interlock_system_id = b.id
+        WHERE
+            h.tag_time LIKE TO_CHAR(#{currentDay}::timestamp, 'YYYY-MM-DD') || '%'
+        GROUP BY
+            h.interlock_system_id,
+            b.pid,
+            b.interlock_name,
+            h.interlock_status
+        ORDER BY
+            h.interlock_system_id
+    </select>
+
     <!-- 按日统计 仪表状态(查询系统下的所有联锁) -->
     <select id="getYbStatusListByTagTime" resultType="org.jeecg.modules.interlockCountDay.entity.InterlockCountDay">
         SELECT
@@ -279,6 +330,12 @@
         </where>
     </select>
 
+    <select id="getCurrentDaySummaryInterlock" resultType="org.jeecg.modules.interlockSummaryDay.entity.InterlockSummaryDay">
+        select interlock_name,interlock_system_id,interlock_apparatus_id,interlock_status,loop_health_level,
+               ljgxinterlock_out_value,device_id,module_name,interlock_out_value_tag,create_by,create_time,
+               update_by,update_time,remark,sys_org_code,tag_time,interlock_status_ps,interlock_status_name
+        from interlock_summary
+    </select>
 
 
 </mapper>

+ 7 - 0
jeecg-module-interlock/src/main/java/org/jeecg/modules/history/service/IInterlockSummaryHistoryService.java

@@ -3,6 +3,7 @@ package org.jeecg.modules.history.service;
 import org.jeecg.modules.history.entity.InterlockSummaryHistory;
 import com.baomidou.mybatisplus.extension.service.IService;
 import org.jeecg.modules.interlockCountDay.entity.InterlockCountDay;
+import org.jeecg.modules.interlockSummaryDay.entity.InterlockSummaryDay;
 
 
 import java.util.List;
@@ -41,4 +42,10 @@ public interface IInterlockSummaryHistoryService extends IService<InterlockSumma
     */
     List<InterlockCountDay> getYbStatusListByTagTime(String yesterday);
 
+    List<InterlockCountDay> getLoopHealthLevelByTagTimeNew(String currentday);
+
+    List<InterlockCountDay> getInterlockStatusByTagTimeNew(String currentDay);
+
+    List<InterlockSummaryDay> getCurrentDaySummaryInterlock();
+
 }

+ 16 - 0
jeecg-module-interlock/src/main/java/org/jeecg/modules/history/service/impl/InterlockSummaryHistoryServiceImpl.java

@@ -4,6 +4,7 @@ import org.jeecg.modules.history.entity.InterlockSummaryHistory;
 import org.jeecg.modules.history.mapper.InterlockSummaryHistoryMapper;
 import org.jeecg.modules.history.service.IInterlockSummaryHistoryService;
 import org.jeecg.modules.interlockCountDay.entity.InterlockCountDay;
+import org.jeecg.modules.interlockSummaryDay.entity.InterlockSummaryDay;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -65,4 +66,19 @@ public class InterlockSummaryHistoryServiceImpl extends ServiceImpl<InterlockSum
     public List<InterlockCountDay> getYbStatusListByTagTime(String yesterday) {
         return mapper.getYbStatusListByTagTime(yesterday);
     }
+
+    @Override
+    public List<InterlockCountDay> getLoopHealthLevelByTagTimeNew(String currentday) {
+        return mapper.getLoopHealthLevelByTagTimeNew(currentday);
+    }
+
+    @Override
+    public List<InterlockCountDay> getInterlockStatusByTagTimeNew(String currentDay) {
+        return mapper.getInterlockStatusByTagTimeNew(currentDay);
+    }
+
+    @Override
+    public List<InterlockSummaryDay> getCurrentDaySummaryInterlock() {
+        return mapper.getCurrentDaySummaryInterlock();
+    }
 }

+ 20 - 9
jeecg-module-interlock/src/main/java/org/jeecg/modules/interlockjob/DayStatisticsJob.java

@@ -12,6 +12,8 @@ import org.jeecg.modules.history.service.IInterlockDetailHistoryService;
 import org.jeecg.modules.history.service.IInterlockSummaryHistoryService;
 import org.jeecg.modules.interlockCountDay.entity.InterlockCountDay;
 import org.jeecg.modules.interlockCountDay.service.IInterlockCountDayService;
+import org.jeecg.modules.interlockSummaryDay.entity.InterlockSummaryDay;
+import org.jeecg.modules.interlockSummaryDay.service.IInterlockSummaryDayService;
 import org.quartz.Job;
 import org.quartz.JobExecutionContext;
 import org.quartz.JobExecutionException;
@@ -59,21 +61,27 @@ public class DayStatisticsJob implements Job {
     @SuppressWarnings("all")
     private IInterlockBaseHyService baseHyService;
 
+    @Autowired
+    @SuppressWarnings("all")
+    private IInterlockSummaryDayService summaryDayService;
+
     @Override
     public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
         // 日统计的定时任务  统计 每个系统下的每个联锁 健康等级(A/B/C/D)、联锁状态,每个联锁条件的仪表状态 的个数
         DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
         String currentDay = DateUtils.getDate("yyyy-MM-dd HH:mm:ss");  // 当前日期
-        LocalDate yesterDate = LocalDate.now().minusDays(1);  // 当前 00:00:00 执行定时任务 减一天获取昨天的日期
-        String yesterday = yesterDate.atStartOfDay().format(formatter); // 昨天的日期
+        //LocalDate yesterDate = LocalDate.now().minusDays(1);  // 当前 00:00:00 执行定时任务 减一天获取昨天的日期
+        //String yesterday = currentDate.atStartOfDay().format(formatter); // 昨天的日期
         //String yesterday = "2024-06-28 00:00:00"; // 测试模拟的昨天日期
 
+        List<InterlockSummaryDay> currentDayList = summaryHistoryService.getCurrentDaySummaryInterlock();
+        summaryDayService.saveBatch(currentDayList);
+
         // 统计健康等级 count_type = 0
         /** 从历史数据中获取 */
         //List<InterlockCountDay> loopHealthLevelList = summaryHistoryService.getLoopHealthLevelByTagTime(yesterday);
 
-        /** 从每天第一次导出的日报表数据中获取 */
-        List<InterlockCountDay> loopHealthLevelList = summaryHistoryService.getLoopHealthLevelByTagTimeFromDay(yesterday);
+        List<InterlockCountDay> loopHealthLevelList = summaryHistoryService.getLoopHealthLevelByTagTimeNew(currentDay);
 
         HashMap<String, List<InterlockCountDay>> loopHealthLevelMap = new HashMap<>();
         for (InterlockCountDay item:loopHealthLevelList) {
@@ -110,7 +118,8 @@ public class DayStatisticsJob implements Job {
                     interlockCount.setCountName(d);
                     interlockCount.setCountNum("0");
                     interlockCount.setCountType("0");
-                    interlockCount.setTime(yesterday);
+                    //interlockCount.setTime(yesterday);
+                    interlockCount.setTime(currentDay);
                     sonList.add(interlockCount);
                 }
             }
@@ -121,7 +130,7 @@ public class DayStatisticsJob implements Job {
         //countService.saveBatch(loopHealthLevelResultList);
 
         // 统计联锁状态(投用/未投用)  count_type = 1
-        List<InterlockCountDay> interlockStatusList = summaryHistoryService.getInterlockStatusByTagTime(yesterday);
+        List<InterlockCountDay> interlockStatusList = summaryHistoryService.getInterlockStatusByTagTimeNew(currentDay);
 
         HashMap<String, List<InterlockCountDay>> interlockStatusMap = new HashMap<>();
         for (InterlockCountDay item:interlockStatusList) {
@@ -160,7 +169,8 @@ public class DayStatisticsJob implements Job {
                     interlockCount.setCountName(d);
                     interlockCount.setCountNum("0");
                     interlockCount.setCountType("1");
-                    interlockCount.setTime(yesterday);
+                    //interlockCount.setTime(yesterday);
+                    interlockCount.setTime(currentDay);
                     sonList.add(interlockCount);
                 }
             }
@@ -214,7 +224,8 @@ public class DayStatisticsJob implements Job {
             interlockCount.setCountName("投用率");
             interlockCount.setCountNum(String.valueOf(tyl));
             interlockCount.setCountType("2");
-            interlockCount.setTime(yesterday);
+            //interlockCount.setTime(yesterday);
+            interlockCount.setTime(currentDay);
             tylResultList.add(interlockCount);
         }
 
@@ -304,7 +315,7 @@ public class DayStatisticsJob implements Job {
                 .collect(Collectors.toList());
 
         QueryWrapper<InterlockCountDay> queryWapper = new QueryWrapper<>();
-        queryWapper.eq("time",yesterday);
+        queryWapper.eq("time",currentDay);
         boolean b = countService.remove(queryWapper);
         countService.saveBatch(list);
         log.info("日统计任务执行成功!");