From 0c68ddbef7aa46a1e62cca537acf12d2b8178f31 Mon Sep 17 00:00:00 2001
From: lxw <810412026@qq.com>
Date: 星期五, 08 九月 2023 13:34:08 +0800
Subject: [PATCH] Merge branch 'master' of http://118.89.139.230:10101/r/fg_v2.0

---
 src/main/java/com/whyc/util/SubTablePageInfoUtils.java |  142 +++++++++++++++++++++++++++++------------------
 1 files changed, 88 insertions(+), 54 deletions(-)

diff --git a/src/main/java/com/whyc/util/SubTablePageInfoUtils.java b/src/main/java/com/whyc/util/SubTablePageInfoUtils.java
index 247b1f5..a3a844d 100644
--- a/src/main/java/com/whyc/util/SubTablePageInfoUtils.java
+++ b/src/main/java/com/whyc/util/SubTablePageInfoUtils.java
@@ -1,18 +1,21 @@
 package com.whyc.util;
 
 import com.github.pagehelper.PageInfo;
-import com.whyc.constant.Com;
 import com.whyc.dto.InterfaceParam;
 import com.whyc.dto.paramter.AlarmPar;
 import com.whyc.dto.paramter.DevAlarmPar;
 import com.whyc.dto.result.AlarmRes;
+import com.whyc.factory.ThreadPoolExecutorFactory;
 import com.whyc.mapper.*;
 import com.whyc.pojo.*;
+import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
 import java.text.ParseException;
 import java.util.*;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ThreadPoolExecutor;
 import java.util.regex.Pattern;
 import java.util.stream.Collectors;
 
@@ -241,16 +244,16 @@
     public PageInfo<Object> getPageInfoByMonthTable(int pageNum,int pageSize,
                                         Date startTime,Date endTime,
                                         String dbName,String tablePrefix,
-                                        Object pojo) throws ParseException {
+                                        Object pojo) throws ParseException, InterruptedException {
         Map<String, List<Date>> queryTimeForSubTables = DateUtil.getQueryTimeForSubTablesByMonthDesc(startTime, endTime);
         //鏌ヨ鍒嗚〃鏄惁瀛樺湪,瀛樺湪鍒欐煡璇㈢粨鏋�
         Map<String,Integer> queryCountMap = new LinkedHashMap<>();
         Set<String> tableYearKeySet = queryTimeForSubTables.keySet();
         //浼樺寲1-鏌ヨ鎵�鏈夌殑绗﹀悎鏈堜唤瑙勫垯鐨勮〃鍜屼富琛�
         List<String> tableNameListDB = getTableList(dbName, tablePrefix, tablePrefix + "(_[0-9]{4}_[0-9]{2})?");
-
+        List<String> tableYearListInDB = new LinkedList<>(); //鏌ヨ鏃堕棿娈靛唴鐨勫勾鏈堝垎琛ㄩ泦鍚堜笖鍦ㄦ暟鎹簱涓瓨鍦�
+        //杩囨护鎺夋椂闂存鍐呮暟鎹簱涓笉瀛樺湪鐨勫勾鏈堝垎琛�
         for (String tableYear : tableYearKeySet) {
-            List<Date> queryTime = queryTimeForSubTables.get(tableYear);
 
             String tableName;
             if(!tableYear.equals("default")){
@@ -260,70 +263,101 @@
                 if(!tableNameListDB.contains(tableName)){ //浼樺寲1-鏁版嵁搴撲腑涓嶅瓨鍦�,鍘婚櫎澶氭鏌ヨ〃,涓�娆℃煡鍑�
                     continue;
                 }
+            }
+            tableYearListInDB.add(tableYear);
+        }
+        //鏌ヨ骞存湀鍒嗚〃鐨勮褰曟暟
+        //浼樺寲2:澶氱嚎绋嬭鍙�
+        ThreadPoolExecutor pool = ThreadPoolExecutorFactory.getPoolExecutor();
+        CountDownLatch latch = new CountDownLatch(tableYearListInDB.size());
+        for (String tableYear : tableYearListInDB) {
+            List<Date> queryTime = queryTimeForSubTables.get(tableYear);
+
+            String tableName;
+            if(!tableYear.equals("default")){
+                //鏁板��
+                tableName = tablePrefix+"_"+tableYear;
             }else{
                 tableName = tablePrefix;
             }
-            //====== 鏍规嵁涓嶅悓绫诲瀷绫诲瀷瀵硅薄瀵瑰簲璋冩暣 ======
-            if(pojo instanceof UserLog) {
-                UserLog userLog = (UserLog) pojo;
-                userLog.setOperationTime(queryTime.get(0));
-                userLog.setOperationTime2(queryTime.get(1));
-                userLog.setRecordYear(tableName);
-                int currentCount = userLogMapper.getCount(userLog);
-                queryCountMap.put(tableYear,currentCount);
-            }
-            else if(pojo instanceof AlarmPar){ //鐢垫睜鍛婅鍘嗗彶
-                AlarmPar param = (AlarmPar) pojo;
-                param.setAlmStartTime(queryTime.get(0));
-                param.setAlmStartTime1(queryTime.get(1));
-                param.setRecordYear(tableName);
-                int currentCount = battAlarmDataHistoryMapper.getCount(param);
-                queryCountMap.put(tableYear,currentCount);
-            }
-            else if (pojo instanceof DevAlarmPar) {
-                DevAlarmPar param = (DevAlarmPar) pojo;
-                param.setAlmStartTime(queryTime.get(0));
-                param.setAlmStartTime1(queryTime.get(1));
-                param.setRecordYear(tableName);
-                int currentCount = devAlarmDataHistoryMapper.getCount(param);
-                queryCountMap.put(tableYear,currentCount);
+            pool.execute(()-> {
 
-            }
-            else if (pojo instanceof PwrdevAlarmHistory) {
-                PwrdevAlarmHistory param = (PwrdevAlarmHistory) pojo;
-                if(param.getRecordId() == 1) {
+                //====== 鏍规嵁涓嶅悓绫诲瀷绫诲瀷瀵硅薄瀵瑰簲璋冩暣 ======
+                if (pojo instanceof UserLog) {
+                    //UserLog userLog = (UserLog) pojo;
+                    UserLog userLog = new UserLog();
+                    BeanUtils.copyProperties(pojo,userLog);
+                    userLog.setOperationTime(queryTime.get(0));
+                    userLog.setOperationTime2(queryTime.get(1));
+                    userLog.setRecordYear(tableName);
+                    int currentCount = userLogMapper.getCount(userLog);
+                    queryCountMap.put(tableYear, currentCount);
+                } else if (pojo instanceof AlarmPar) { //鐢垫睜鍛婅鍘嗗彶
+                    //AlarmPar param = (AlarmPar) pojo;
+                    AlarmPar param = new AlarmPar();
+                    BeanUtils.copyProperties(pojo,param);
                     param.setAlmStartTime(queryTime.get(0));
                     param.setAlmStartTime1(queryTime.get(1));
                     param.setRecordYear(tableName);
-                    int currentCount = powerAlarmHistoryMapper.getCount(param);
+                    int currentCount = battAlarmDataHistoryMapper.getCount(param);
                     queryCountMap.put(tableYear, currentCount);
-                }else{
+                } else if (pojo instanceof DevAlarmPar) {
+                    //DevAlarmPar param = (DevAlarmPar) pojo;
+                    DevAlarmPar param = new DevAlarmPar();
+                    BeanUtils.copyProperties(pojo,param);
                     param.setAlmStartTime(queryTime.get(0));
                     param.setAlmStartTime1(queryTime.get(1));
                     param.setRecordYear(tableName);
-                    int currentCount = powerAlarmHistoryMapper.getCountForTX(param);
+                    int currentCount = devAlarmDataHistoryMapper.getCount(param);
                     queryCountMap.put(tableYear, currentCount);
-                }
 
-            }
-            else if (pojo instanceof InterfaceParam){
-                InterfaceParam param = (InterfaceParam) pojo;
-                if(tablePrefix.equals("tb_battalarm_data_history")){
-                    param.setStartTime(queryTime.get(0));
-                    param.setEndTime(queryTime.get(1));
-                    param.setRecordYear(tableName);
-                    int currentCount = battAlarmDataHistoryMapper.getCountForInterface(param);
-                    queryCountMap.put(tableYear,currentCount);
-                }else if(tablePrefix.equals("tb_devalarm_data_history")){
-                    param.setStartTime(queryTime.get(0));
-                    param.setEndTime(queryTime.get(1));
-                    param.setRecordYear(tableName);
-                    int currentCount = devAlarmDataHistoryMapper.getCountForInterface(param);
-                    queryCountMap.put(tableYear,currentCount);
+                } else if (pojo instanceof PwrdevAlarmHistory) {
+                    //PwrdevAlarmHistory param = (PwrdevAlarmHistory) pojo;
+                    PwrdevAlarmHistory param = new PwrdevAlarmHistory();
+                    BeanUtils.copyProperties(pojo,param);
+                    if (param.getRecordId() == 1) {
+                        param.setAlmStartTime(queryTime.get(0));
+                        param.setAlmStartTime1(queryTime.get(1));
+                        param.setRecordYear(tableName);
+                        int currentCount = powerAlarmHistoryMapper.getCount(param);
+                        queryCountMap.put(tableYear, currentCount);
+                    } else {
+                        param.setAlmStartTime(queryTime.get(0));
+                        param.setAlmStartTime1(queryTime.get(1));
+                        param.setRecordYear(tableName);
+                        int currentCount = powerAlarmHistoryMapper.getCountForTX(param);
+                        queryCountMap.put(tableYear, currentCount);
+                    }
+
+                } else if (pojo instanceof InterfaceParam) {
+                    //InterfaceParam param = (InterfaceParam) pojo;
+                    InterfaceParam param = new InterfaceParam();
+                    BeanUtils.copyProperties(pojo,param);
+                    if (tablePrefix.equals("tb_battalarm_data_history")) {
+                        param.setStartTime(queryTime.get(0));
+                        param.setEndTime(queryTime.get(1));
+                        param.setRecordYear(tableName);
+                        int currentCount = battAlarmDataHistoryMapper.getCountForInterface(param);
+                        queryCountMap.put(tableYear, currentCount);
+                    } else if (tablePrefix.equals("tb_devalarm_data_history")) {
+                        param.setStartTime(queryTime.get(0));
+                        param.setEndTime(queryTime.get(1));
+                        param.setRecordYear(tableName);
+                        int currentCount = devAlarmDataHistoryMapper.getCountForInterface(param);
+                        queryCountMap.put(tableYear, currentCount);
+                    }
                 }
-            }
+                latch.countDown();
+            });
         }
-
+        latch.await();
+        //鍥犱负澶氱嚎绋嬪悗鏃犲簭,闇�瑕侀噸鎺掑簭
+        List<String> keySetDesc = queryCountMap.keySet().stream().sorted(Comparator.reverseOrder()).collect(Collectors.toList());
+        Map<String,Integer> queryCountMapDesc = new LinkedHashMap<>();
+        for (String key : keySetDesc) {
+            Integer count = queryCountMap.get(key);
+            queryCountMapDesc.put(key,count);
+        }
         //鍒嗛〉淇℃伅
         //纭鎬婚〉鏁�,鎬昏褰曟暟
         PageInfo<Object> pageInfo = new PageInfo<>();
@@ -345,7 +379,7 @@
 
         //鏈�鍚庝竴涓畻娉�:涓婇潰涓嶅簲璇ュ厛鏌ヨ鎵�鏈夎褰�,搴旇鍙朿ount. 杩欏悗闈㈠畾浣嶅埌鍝釜琛ㄦ垨鍝嚑寮犺〃鍚�,閲囧彇limit鑾峰彇褰撳墠椤佃褰曟暟;
         //鏍煎紡:{琛ㄥ悕,[limit 2,20]}
-        Map<String,List<Integer>> tableAndLimitMap = MathUtil.getQueryTableAndLimit(startNum,endNum,pageSize,queryCountMap);
+        Map<String,List<Integer>> tableAndLimitMap = MathUtil.getQueryTableAndLimit(startNum,endNum,pageSize,queryCountMapDesc);
         Set<String> keySet = tableAndLimitMap.keySet();
         List<Object> dataList = new LinkedList<>();
         for (String key : keySet) {

--
Gitblit v1.9.1