From 4b659a6ece105f30debf0def9225b9a89c43bcd4 Mon Sep 17 00:00:00 2001
From: whyclxw <810412026@qq.com>
Date: 星期三, 05 二月 2025 10:39:08 +0800
Subject: [PATCH] 告警实时推送和告警历史查询

---
 src/main/java/com/whyc/util/SubTablePageInfoUtil.java |   84 ++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 81 insertions(+), 3 deletions(-)

diff --git a/src/main/java/com/whyc/util/SubTablePageInfoUtil.java b/src/main/java/com/whyc/util/SubTablePageInfoUtil.java
index 34b3093..1a9895d 100644
--- a/src/main/java/com/whyc/util/SubTablePageInfoUtil.java
+++ b/src/main/java/com/whyc/util/SubTablePageInfoUtil.java
@@ -3,6 +3,7 @@
 import com.github.pagehelper.PageInfo;
 import com.whyc.factory.ThreadPoolExecutorFactory;
 import com.whyc.mapper.CommonMapper;
+import com.whyc.pojo.db_lock_alarm.LockAlarmHis;
 import com.whyc.pojo.db_lock_his.LockHis;
 import com.whyc.service.SubTableService;
 import org.springframework.beans.BeanUtils;
@@ -27,9 +28,86 @@
     @Autowired
     private SubTableService service;
 
-    //鎸夊勾鏈堝垎琛�
+
+
     /**鎸夊勾浠借〃鍒嗛〉鏌ヨ*/
     public PageInfo<Object> getPageInfo(int pageNum,int pageSize,
+                                                      Date startTime,Date endTime,
+                                                      String dbName,String tablePrefix,
+                                                      Object pojo) throws ParseException {
+        Map<String, List<Date>> queryTimeForSubTables = DateUtil.getQueryTimeForSubTablesDesc2(startTime, endTime);
+        //鏌ヨ鍒嗚〃鏄惁瀛樺湪,瀛樺湪鍒欐煡璇㈢粨鏋�
+        Map<String,Integer> queryCountMap = new LinkedHashMap<>();
+        Set<String> tableYearKeySet = queryTimeForSubTables.keySet();
+        for (String tableYear : tableYearKeySet) {
+            List<Date> queryTime = queryTimeForSubTables.get(tableYear);
+
+            //鏁板��
+            String tableName = tablePrefix+"_"+tableYear;
+            String existTableName = commonMapper.existTable(dbName, tableName);
+            if(existTableName == null){
+                continue;
+            }
+            //====== 鏍规嵁涓嶅悓绫诲瀷绫诲瀷瀵硅薄瀵瑰簲璋冩暣 ======
+            if(pojo instanceof LockHis) {
+                LockAlarmHis his = new LockAlarmHis();
+                BeanUtils.copyProperties(pojo, his);
+                his.setStartTime(queryTime.get(0));
+                his.setEndTime(queryTime.get(1));
+                his.setRecordYear(tableName);
+                int currentCount = service.getLockAlmHisCount(his);
+                queryCountMap.put(tableYear, currentCount);
+            }
+        }
+
+        //鍒嗛〉淇℃伅
+        //纭鎬婚〉鏁�,鎬昏褰曟暟
+        PageInfo<Object> pageInfo = new PageInfo<>();
+
+        int total = 0;
+        Set<String> queryKeySet = queryCountMap.keySet();
+        for (String queryKey : queryKeySet) {
+            int size = queryCountMap.get(queryKey);
+            total+=size;
+        }
+        int pages = (int) Math.ceil(Float.parseFloat(String.valueOf(total))/pageSize);
+        pageInfo.setTotal(total);
+        pageInfo.setPages(pages);
+        pageInfo.setPageNum(pageNum);
+        pageInfo.setPageSize(pageSize);
+        //鏍规嵁褰撳墠椤垫墍闇�璁板綍,鏌ヨ褰撳墠椤佃褰�
+        int startNum = (pageNum-1)*pageSize+1;
+        int endNum = pageNum*pageSize;
+
+        //鏈�鍚庝竴涓畻娉�:涓婇潰涓嶅簲璇ュ厛鏌ヨ鎵�鏈夎褰�,搴旇鍙朿ount. 杩欏悗闈㈠畾浣嶅埌鍝釜琛ㄦ垨鍝嚑寮犺〃鍚�,閲囧彇limit鑾峰彇褰撳墠椤佃褰曟暟;
+        //鏍煎紡:{琛ㄥ悕,[limit 2,20]}
+        Map<String,List<Integer>> tableAndLimitMap = MathUtil.getQueryTableAndLimit(startNum,endNum,pageSize,queryCountMap);
+        Set<String> keySet = tableAndLimitMap.keySet();
+        List<Object> dataList = new LinkedList<>();
+        for (String key : keySet) {
+            List<Date> queryTime = queryTimeForSubTables.get(key);
+            //====== 鏍规嵁涓嶅悓绫诲瀷绫诲瀷瀵硅薄瀵瑰簲璋冩暣 ======
+            String recordYear = tablePrefix + "_" + key;
+            if(pojo instanceof LockHis) {
+                LockAlarmHis his = new LockAlarmHis();
+                BeanUtils.copyProperties(pojo, his);
+                his.setStartTime(queryTime.get(0));
+                his.setEndTime(queryTime.get(1));
+                his.setRecordYear(recordYear);
+                List<Integer> limitList = tableAndLimitMap.get(key);
+                his.setLimitStart(limitList.get(0));
+                his.setLimitEnd(limitList.get(1));
+                List<LockHis> list =  service.getLockAlmHisList(his);
+                dataList.addAll(list);
+            }
+
+        }
+        pageInfo.setList(dataList);
+        return pageInfo;
+    }
+
+    /**鎸夊勾浠借〃鍒嗛〉鏌ヨ*/
+    public PageInfo<Object> getPageInfoWithOutDefault(int pageNum,int pageSize,
                                         Date startTime,Date endTime,
                                         String dbName,String tablePrefix,
                                         Object pojo) throws ParseException {
@@ -95,7 +173,7 @@
                 List<Integer> limitList = tableAndLimitMap.get(key);
                 his.setLimitStart(limitList.get(0));
                 his.setLimitEnd(limitList.get(1));
-                List<LockHis> list =  service.getBattHisList(his);
+                List<LockHis> list =  service.getLockHisList(his);
                 dataList.addAll(list);
             }
 
@@ -201,7 +279,7 @@
                 List<Integer> limitList = tableAndLimitMap.get(key);
                 his.setLimitStart(limitList.get(0));
                 his.setLimitEnd(limitList.get(1));
-                List<LockHis> list =  service.getBattHisList(his);
+                List<LockHis> list =  service.getLockHisList(his);
                 dataList.addAll(list);
             }
         }

--
Gitblit v1.9.1