| | |
| | | |
| | | 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.mapper.*; |
| | | import com.whyc.pojo.DevalarmDataHistory; |
| | | import com.whyc.pojo.PwrdevAlarmHistory; |
| | | import com.whyc.pojo.UserLog; |
| | | import com.whyc.pojo.*; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.text.ParseException; |
| | | import java.util.*; |
| | | import java.util.regex.Pattern; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 数据量极大的表,按照年份分表,分页查询时获取数据 |
| | |
| | | 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); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | dataList.addAll(list); |
| | | } |
| | | } |
| | | else if (pojo instanceof InterfaceParam){ |
| | | InterfaceParam data = (InterfaceParam) pojo; |
| | | if(tablePrefix.equals("tb_battalarm_data_history")){ |
| | | data.setStartTime(queryTime.get(0)); |
| | | data.setEndTime(queryTime.get(1)); |
| | | |
| | | List<Integer> limitList = tableAndLimitMap.get(key); |
| | | data.setLimitStart(limitList.get(0)); |
| | | data.setLimitEnd(limitList.get(1)); |
| | | data.setRecordYear(recordYear); |
| | | List<AlarmRes> list = battAlarmDataHistoryMapper.getListForInterface(data); |
| | | dataList.addAll(list); |
| | | }else if(tablePrefix.equals("tb_devalarm_data_history")){ |
| | | data.setStartTime(queryTime.get(0)); |
| | | data.setEndTime(queryTime.get(1)); |
| | | |
| | | List<Integer> limitList = tableAndLimitMap.get(key); |
| | | data.setLimitStart(limitList.get(0)); |
| | | data.setLimitEnd(limitList.get(1)); |
| | | data.setRecordYear(recordYear); |
| | | List<AlarmRes> list = devAlarmDataHistoryMapper.getListForInterface(data); |
| | | dataList.addAll(list); |
| | | } |
| | | } |
| | | } |
| | | pageInfo.setList(dataList); |
| | | return pageInfo; |
| | | } |
| | | |
| | | /**查询是否包含特定规则的表,存在,则返回表名*/ |
| | | public List<String> getTableList(String dbName,String tableLike,String regex){ |
| | | List<String> resultTableList = new LinkedList<>(); |
| | | List<String> tableList = commonMapper.getTableListLike(dbName,tableLike); |
| | | for (String tableName : tableList) { |
| | | boolean matches = Pattern.matches(regex, tableName); |
| | | if(matches){ |
| | | resultTableList.add(tableName); |
| | | } |
| | | } |
| | | return resultTableList; |
| | | } |
| | | |
| | | /**所有记录分为四级查询个数*/ |
| | | public List<Integer> getLevelList(int uId,String dbName,String tableLike,String regex,List<Integer> almTypes ){ |
| | | List<Integer> result = new LinkedList<>(); |
| | | List<String> tableList = getTableList(dbName, tableLike, regex); |
| | | List<Integer> levelList = new LinkedList(); |
| | | for (String tableName : tableList) { |
| | | List<BattalarmDataHistory> levelInfoSubList; |
| | | List<Integer> levelSubList; |
| | | if(tableLike.equals("tb_battalarm_data_history")) { |
| | | levelInfoSubList = battAlarmDataHistoryMapper.getLevelSubList(uId, tableName); |
| | | } |
| | | else if(tableLike.equals("tb_devalarm_data_history")){ |
| | | levelInfoSubList = devAlarmDataHistoryMapper.getLevelSubList(uId, tableName); |
| | | } |
| | | else{ |
| | | levelInfoSubList = powerAlarmHistoryMapper.getLevelSubList(uId, tableName,almTypes); |
| | | } |
| | | levelSubList = levelInfoSubList.stream().map(BattalarmDataHistory::getAlmLevel).collect(Collectors.toList()); |
| | | levelList.addAll(levelSubList); |
| | | } |
| | | //分为四级查询个数 |
| | | Map<Integer, List<Integer>> levelMap = levelList.stream().collect(Collectors.groupingBy(Integer::intValue)); |
| | | Set<Integer> levelSet = levelMap.keySet(); |
| | | List<Integer> listOfLevelSet = new LinkedList(); |
| | | //补齐1,2,3,4四级 |
| | | listOfLevelSet.add(1); |
| | | listOfLevelSet.add(2); |
| | | listOfLevelSet.add(3); |
| | | listOfLevelSet.add(4); |
| | | if(!levelSet.contains(1)){ |
| | | levelMap.put(1,new LinkedList<>()); |
| | | } |
| | | if(!levelSet.contains(2)){ |
| | | levelMap.put(2,new LinkedList<>()); |
| | | } |
| | | if(!levelSet.contains(3)){ |
| | | levelMap.put(3,new LinkedList<>()); |
| | | } |
| | | if(!levelSet.contains(4)){ |
| | | levelMap.put(4,new LinkedList<>()); |
| | | } |
| | | //待测试 |
| | | for (Integer level : listOfLevelSet) { |
| | | result.add(levelMap.get(level).size()); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | String regex = "tb_battalarm_data_history_?[0-9]*"; |
| | | String table = "tb_battalarm_data_history"; |
| | | System.out.println(Pattern.matches(regex,table)); |
| | | } |
| | | } |