From 73bb5617e6aeb4ee8f7dfd4ad54b61d477969d86 Mon Sep 17 00:00:00 2001 From: whycxzp <glperry@163.com> Date: 星期二, 10 六月 2025 20:22:06 +0800 Subject: [PATCH] 自动充放电自动化流程 --- src/main/java/com/whyc/util/SubTablePageInfoUtil.java | 242 ++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 223 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/whyc/util/SubTablePageInfoUtil.java b/src/main/java/com/whyc/util/SubTablePageInfoUtil.java index 9b5ba2b..48bb96e 100644 --- a/src/main/java/com/whyc/util/SubTablePageInfoUtil.java +++ b/src/main/java/com/whyc/util/SubTablePageInfoUtil.java @@ -1,10 +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.BattAlarmHis; +import com.whyc.pojo.db_alarm.BattAlarmHistory; +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; @@ -15,6 +26,7 @@ import java.util.concurrent.ThreadPoolExecutor; import java.util.regex.Pattern; import java.util.stream.Collectors; + /** * 鏁版嵁閲忔瀬澶х殑琛�,鎸夌収骞翠唤鍒嗚〃,鍒嗛〉鏌ヨ鏃惰幏鍙栨暟鎹� */ @@ -26,13 +38,147 @@ @Autowired private SubTableService service; - //鎸夊勾鏈堝垎琛� + @Autowired + private DevLithiumInfService devLithiumInfService; + + @Autowired + private UserInfService userInfService; + + /**鎸夊勾浠借〃鍒嗛〉鏌ヨ*/ + 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.getQueryTimeForSubTablesDescWithOutDefault(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; + boolean existTableName = commonMapper.existTable(dbName, tableName); + if(!existTableName){ + continue; + } + //====== 鏍规嵁涓嶅悓绫诲瀷绫诲瀷瀵硅薄瀵瑰簲璋冩暣 ====== + if(pojo instanceof BattAlarmHistory) { + BattAlarmHistory battAlarmHistory = new BattAlarmHistory(); + BeanUtils.copyProperties(pojo, battAlarmHistory); + battAlarmHistory.setAlmStartTime(queryTime.get(0)); + battAlarmHistory.setAlmEndTime(queryTime.get(1)); + battAlarmHistory.setRecordYear(tableName); + int currentCount = service.getBattHisCount(battAlarmHistory); + queryCountMap.put(tableYear, currentCount); + } + else if(pojo instanceof PowerAlarmHistory) { + PowerAlarmHistory powerAlarmHistory = new PowerAlarmHistory(); + BeanUtils.copyProperties(pojo, powerAlarmHistory); + powerAlarmHistory.setAlmStartTime(queryTime.get(0)); + 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); + } + + } + + //鍒嗛〉淇℃伅 + //纭鎬婚〉鏁�,鎬昏褰曟暟 + 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 BattAlarmHistory) { + BattAlarmHistory battAlarmHistory = new BattAlarmHistory(); + BeanUtils.copyProperties(pojo, battAlarmHistory); + battAlarmHistory.setAlmStartTime(queryTime.get(0)); + battAlarmHistory.setAlmEndTime(queryTime.get(1)); + battAlarmHistory.setRecordYear(recordYear); + List<Integer> limitList = tableAndLimitMap.get(key); + battAlarmHistory.setLimitStart(limitList.get(0)); + battAlarmHistory.setLimitEnd(limitList.get(1)); + List<BattAlarmHistory> list = service.getBattHisList(battAlarmHistory); + dataList.addAll(list); + } + else if(pojo instanceof PowerAlarmHistory) { + PowerAlarmHistory powerAlarmHistory = new PowerAlarmHistory(); + BeanUtils.copyProperties(pojo, powerAlarmHistory); + powerAlarmHistory.setAlmStartTime(queryTime.get(0)); + powerAlarmHistory.setAlmEndTime(queryTime.get(1)); + powerAlarmHistory.setRecordYear(recordYear); + List<Integer> limitList = tableAndLimitMap.get(key); + powerAlarmHistory.setLimitStart(limitList.get(0)); + powerAlarmHistory.setLimitEnd(limitList.get(1)); + 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; + } + /**鎸夋湀鍒嗚〃,鍒嗛〉鏌ヨ*/ public PageInfo<Object> getPageInfoByMonthTable(int pageNum, int pageSize, 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(); @@ -68,15 +214,40 @@ } pool.execute(()-> { //====== 鏍规嵁涓嶅悓绫诲瀷绫诲瀷瀵硅薄瀵瑰簲璋冩暣 ====== - if (pojo instanceof BattAlarmHis) { - BattAlarmHis battAlarmHis = new BattAlarmHis(); - BeanUtils.copyProperties(pojo,battAlarmHis); - battAlarmHis.setAlmStartTime(queryTime.get(0)); - battAlarmHis.setAlmEndTime(queryTime.get(1)); - battAlarmHis.setRecordYear(tableName); - int currentCount = service.getBattHisCount(battAlarmHis); + if (pojo instanceof BattAlarmHistory) { + BattAlarmHistory battAlarmHistory = new BattAlarmHistory(); + BeanUtils.copyProperties(pojo, battAlarmHistory); + battAlarmHistory.setAlmStartTime(queryTime.get(0)); + battAlarmHistory.setAlmEndTime(queryTime.get(1)); + battAlarmHistory.setRecordYear(tableName); + 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(); }); } @@ -115,16 +286,49 @@ List<Date> queryTime = queryTimeForSubTables.get(key); //====== 鏍规嵁涓嶅悓绫诲瀷绫诲瀷瀵硅薄瀵瑰簲璋冩暣 ====== String recordYear = key.equals("default") ? tablePrefix : tablePrefix + "_" + key; - if(pojo instanceof BattAlarmHis) { - BattAlarmHis battAlarmHis = new BattAlarmHis(); - BeanUtils.copyProperties(pojo,battAlarmHis); - battAlarmHis.setAlmStartTime(queryTime.get(0)); - battAlarmHis.setAlmEndTime(queryTime.get(1)); - battAlarmHis.setRecordYear(recordYear); + if(pojo instanceof BattAlarmHistory) { + BattAlarmHistory battAlarmHistory = new BattAlarmHistory(); + BeanUtils.copyProperties(pojo, battAlarmHistory); + battAlarmHistory.setAlmStartTime(queryTime.get(0)); + battAlarmHistory.setAlmEndTime(queryTime.get(1)); + battAlarmHistory.setRecordYear(recordYear); List<Integer> limitList = tableAndLimitMap.get(key); - battAlarmHis.setLimitStart(limitList.get(0)); - battAlarmHis.setLimitEnd(limitList.get(1)); - List<BattAlarmHis> list = service.getBattHisList(battAlarmHis); + battAlarmHistory.setLimitStart(limitList.get(0)); + battAlarmHistory.setLimitEnd(limitList.get(1)); + 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); } } -- Gitblit v1.9.1