whycxzp
2025-04-10 f26dc28abc0f5efc0ab0143d3554474ebbc6c169
src/main/java/com/whyc/util/SubTablePageInfoUtil.java
@@ -1,12 +1,21 @@
package com.whyc.util;
import com.github.pagehelper.PageInfo;
import com.whyc.constant.DevAlmEnum;
import com.whyc.dto.DevA200AlarmDto;
import com.whyc.factory.ThreadPoolExecutorFactory;
import com.whyc.mapper.CommonMapper;
import com.whyc.pojo.db_alarm.BattAlarmHistory;
import com.whyc.pojo.db_power_alarm.PowerAlarm;
import com.whyc.pojo.db_alarm.DevLithiumAlarmDataYear;
import com.whyc.pojo.db_lithium_ram_db.DevLithiumInf;
import com.whyc.pojo.db_power_alarm.PowerAlarmHistory;
import com.whyc.pojo.db_power_history.BattRealTimeDataHistory;
import com.whyc.pojo.db_power_history.BattStationTempHistory;
import com.whyc.pojo.db_power_history.PowerRealTimeDataHistory;
import com.whyc.pojo.db_user.UserInf;
import com.whyc.service.DevLithiumInfService;
import com.whyc.service.SubTableService;
import com.whyc.service.UserInfService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -17,6 +26,7 @@
import java.util.concurrent.ThreadPoolExecutor;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
/**
 * 数据量极大的表,按照年份分表,分页查询时获取数据
 */
@@ -28,7 +38,12 @@
    @Autowired
    private SubTableService service;
    //按年月分表
    @Autowired
    private DevLithiumInfService devLithiumInfService;
    @Autowired
    private UserInfService userInfService;
    /**按年份表分页查询*/
    public PageInfo<Object> getPageInfo(int pageNum,int pageSize,
                                        Date startTime,Date endTime,
@@ -43,8 +58,8 @@
            //数值
            String tableName = tablePrefix+"_"+tableYear;
            String existTableName = commonMapper.existTable(dbName, tableName);
            if(existTableName == null){
            boolean existTableName = commonMapper.existTable(dbName, tableName);
            if(!existTableName){
                continue;
            }
            //====== 根据不同类型类型对象对应调整 ======
@@ -64,6 +79,14 @@
                powerAlarmHistory.setAlmEndTime(queryTime.get(1));
                powerAlarmHistory.setRecordYear(tableName);
                int currentCount = service.getPowerHisCount(powerAlarmHistory);
                queryCountMap.put(tableYear, currentCount);
            }
            else if (pojo instanceof DevA200AlarmDto) {
                DevA200AlarmDto dto = (DevA200AlarmDto) pojo;
                dto.setStartTime(queryTime.get(0));
                dto.setEndTime(queryTime.get(1));
                dto.setTableName(tableName);
                int currentCount = service.getCountForDevAlm(dto);
                queryCountMap.put(tableYear, currentCount);
            }
@@ -121,6 +144,30 @@
                List<PowerAlarmHistory> list =  service.getPowerHisList(powerAlarmHistory);
                dataList.addAll(list);
            }
            else if (pojo instanceof DevA200AlarmDto) {
                if(!key.equals("default")){
                    DevA200AlarmDto dto = (DevA200AlarmDto) pojo;
                    dto.setStartTime(queryTime.get(0));
                    dto.setEndTime(queryTime.get(1));
                    List<Integer> limitList = tableAndLimitMap.get(key);
                    dto.setLimitStart(limitList.get(0));
                    dto.setLimitEnd(limitList.get(1));
                    dto.setTableName(recordYear);
                    List<DevLithiumAlarmDataYear> list =  service.getListDevAlm(dto);
                    for (DevLithiumAlarmDataYear year:list) {
                        int devId=year.getDevId();
                        int uid=year.getConfirmedUid();
                        DevLithiumInf dinf=devLithiumInfService.getDinfByDevId(devId);
                        UserInf uinf= userInfService.getUinfByUId(uid);
                        int almId=year.getAlmId();
                        String almName= DevAlmEnum.getValue(almId);
                        year.setAlmName(almName!=null?almName:"");
                        year.setDevInf(dinf);
                        year.setConfirmedUname(uinf!=null?uinf.getUname():"");
                    }
                    dataList.addAll(list);
                }
            }
        }
        pageInfo.setList(dataList);
        return pageInfo;
@@ -131,7 +178,7 @@
                                                    Date startTime, Date endTime,
                                                    String dbName, String tablePrefix,
                                                    Object pojo) throws ParseException, InterruptedException {
        Map<String, List<Date>> queryTimeForSubTables = DateUtil.getQueryTimeForSubTablesByMonthDesc(startTime, endTime);
        Map<String, List<Date>> queryTimeForSubTables = DateUtil.getQueryTimeForSubTablesByMonthDesc2(startTime, endTime);
        //查询分表是否存在,存在则查询结果
        Map<String,Integer> queryCountMap = new LinkedHashMap<>();
        Set<String> tableYearKeySet = queryTimeForSubTables.keySet();
@@ -176,6 +223,31 @@
                    int currentCount = service.getBattHisCount(battAlarmHistory);
                    queryCountMap.put(tableYear, currentCount);
                 }
                else if (pojo instanceof BattStationTempHistory) {
                    BattStationTempHistory tempHistory = new BattStationTempHistory();
                    tempHistory.setStartTime(queryTime.get(0));
                    tempHistory.setEndTime(queryTime.get(1));
                    tempHistory.setRecordYearMonth(tableName);
                    int currentCount = service.getBattStationTempHisCount(tempHistory);
                    queryCountMap.put(tableYear, currentCount);
                }
                else if (pojo instanceof BattRealTimeDataHistory) {
                    BattRealTimeDataHistory tempHistory = new BattRealTimeDataHistory();
                    tempHistory.setStartTime(queryTime.get(0));
                    tempHistory.setEndTime(queryTime.get(1));
                    tempHistory.setRecordYearMonth(tableName);
                    int currentCount = service.getBattRealTimeDataHisCount(tempHistory);
                    queryCountMap.put(tableYear, currentCount);
                }
                else if (pojo instanceof PowerRealTimeDataHistory) {
                    PowerRealTimeDataHistory tempHistory = new PowerRealTimeDataHistory();
                    tempHistory.setStartTime(queryTime.get(0));
                    tempHistory.setEndTime(queryTime.get(1));
                    tempHistory.setRecordYearMonth(tableName);
                    int currentCount = service.getPowerRealTimeDataHisCount(tempHistory);
                    queryCountMap.put(tableYear, currentCount);
                }
                latch.countDown();
            });
        }
@@ -226,6 +298,39 @@
                List<BattAlarmHistory> list =  service.getBattHisList(battAlarmHistory);
                dataList.addAll(list);
            }
            else if (pojo instanceof BattStationTempHistory){
                BattStationTempHistory tempHistory = new BattStationTempHistory();
                tempHistory.setStartTime(queryTime.get(0));
                tempHistory.setEndTime(queryTime.get(1));
                tempHistory.setRecordYearMonth(recordYear);
                List<Integer> limitList = tableAndLimitMap.get(key);
                tempHistory.setLimitStart(limitList.get(0));
                tempHistory.setLimitEnd(limitList.get(1));
                List<BattStationTempHistory> list =  service.getBattStationTempHisList(tempHistory);
                dataList.addAll(list);
            }
            else if (pojo instanceof BattRealTimeDataHistory){
                BattRealTimeDataHistory tempHistory = new BattRealTimeDataHistory();
                tempHistory.setStartTime(queryTime.get(0));
                tempHistory.setEndTime(queryTime.get(1));
                tempHistory.setRecordYearMonth(recordYear);
                List<Integer> limitList = tableAndLimitMap.get(key);
                tempHistory.setLimitStart(limitList.get(0));
                tempHistory.setLimitEnd(limitList.get(1));
                List<BattRealTimeDataHistory> list =  service.getBattRealTimeDataHisList(tempHistory);
                dataList.addAll(list);
            }
            else if (pojo instanceof PowerRealTimeDataHistory){
                PowerRealTimeDataHistory tempHistory = new PowerRealTimeDataHistory();
                tempHistory.setStartTime(queryTime.get(0));
                tempHistory.setEndTime(queryTime.get(1));
                tempHistory.setRecordYearMonth(recordYear);
                List<Integer> limitList = tableAndLimitMap.get(key);
                tempHistory.setLimitStart(limitList.get(0));
                tempHistory.setLimitEnd(limitList.get(1));
                List<PowerRealTimeDataHistory> list =  service.getPowerRealTimeDataHisList(tempHistory);
                dataList.addAll(list);
            }
        }
        pageInfo.setList(dataList);
        return pageInfo;