From 6fd5031abb19075bd31cb90971734e511c1d0623 Mon Sep 17 00:00:00 2001 From: wr <1754607820@qq.com> Date: Fri, 5 May 2023 16:17:46 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=AF=E5=8C=BA=E5=9B=BE=E7=AE=97=E6=B3=95?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=8C=E6=9C=88=20=E5=AD=A3=20=E5=B9=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mysql/Impl/line/PollutionServiceImpl.java | 204 +++++++++++++----- 1 file changed, 145 insertions(+), 59 deletions(-) diff --git a/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/harmonic/service/mysql/Impl/line/PollutionServiceImpl.java b/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/harmonic/service/mysql/Impl/line/PollutionServiceImpl.java index 4a11a849b..19103af71 100644 --- a/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/harmonic/service/mysql/Impl/line/PollutionServiceImpl.java +++ b/pqs-prepare/prepare-boot/src/main/java/com/njcn/prepare/harmonic/service/mysql/Impl/line/PollutionServiceImpl.java @@ -18,8 +18,7 @@ import com.njcn.device.pq.api.DeptLineFeignClient; import com.njcn.device.pq.api.LineFeignClient; import com.njcn.device.pq.pojo.po.Overlimit; import com.njcn.harmonic.pojo.dto.PublicDTO; -import com.njcn.harmonic.pojo.po.RMpPollutionDPO; -import com.njcn.harmonic.pojo.po.RStatDataVD; +import com.njcn.harmonic.pojo.po.*; import com.njcn.harmonic.pojo.po.day.*; import com.njcn.influxdb.utils.InfluxDbUtils; import com.njcn.prepare.harmonic.mapper.mysql.line.*; @@ -166,17 +165,21 @@ public class PollutionServiceImpl implements PollutionService { } log.info("污区数据统计间隔"+local+"----->"+localEnd); - lambdaQuery.ge(RMpPollutionDPO::getDataDate, local).le(RMpPollutionDPO::getDataDate,localEnd); - List pollutionDayList = rMpPollutionDMapper.selectList(lambdaQuery); + List pollutionDayList =new ArrayList<>(); + if(Integer.valueOf(BizParamConstant.STAT_BIZ_DAY).equals(lineParam.getType())){ + lambdaQuery.ge(RMpPollutionDPO::getDataDate, local).le(RMpPollutionDPO::getDataDate,localEnd); + pollutionDayList = rMpPollutionDMapper.selectList(lambdaQuery); + } + //MySql入表变电站、单位 - insertPolluctionMySql(pollutionDayList, dictData, local, lineParam.getType()); + insertPolluctionMySql(pollutionDayList, dictData, local, localEnd, lineParam.getType()); LogUtil.njcnDebug(log, "监测点污染指标数据完成耗时:{}", timer.intervalRestart()); } /** * MySql入表 */ - private void insertPolluctionMySql(List pollutionDayList, List dictData, LocalDateTime local, Integer type){ + private void insertPolluctionMySql(List pollutionDayList, List dictData, LocalDateTime local, LocalDateTime localEnd,Integer type){ HttpResult>> substationOut = lineFeignClient.getLineBySubstationRelation(1); //HttpResult>> unitOut = deptLineFeignClient.getLineByDeptRelation(1); @@ -188,8 +191,8 @@ public class PollutionServiceImpl implements PollutionService { Map> substationMap = substationOut.getData(); - insertSubstation(dictData,substationMap,pollutionDayList,local,type); - insertUnit(dictData,deptGetChildrenDTOList,pollutionDayList,local,type); + insertSubstation(dictData,substationMap,pollutionDayList,local,localEnd,type); + insertUnit(dictData,deptGetChildrenDTOList,pollutionDayList,local,localEnd,type); } /*MySql入表 r_mp_pollution_d*/ @@ -206,69 +209,152 @@ public class PollutionServiceImpl implements PollutionService { } /*MySql入表 r_stat_pollution_substation*/ - private void insertSubstation(List dictDataList,Map> substationMap,List pollutionDayList,LocalDateTime local, Integer type){ - for (String key : substationMap.keySet()){ - List processList = new ArrayList<>(); - List substationList = substationMap.get(key); - for(String lineid : substationList){ - for (RMpPollutionDPO pollution : pollutionDayList){ - if (lineid.equals(pollution.getLineId())){ - processList.add(pollution); + private void insertSubstation(List dictDataList,Map> substationMap,List pollutionDayList,LocalDateTime local,LocalDateTime localEnd, Integer type){ + if(Integer.valueOf(BizParamConstant.STAT_BIZ_DAY).equals(type)){ + for (String key : substationMap.keySet()){ + List processList = new ArrayList<>(); + List substationList = substationMap.get(key); + for(String lineid : substationList){ + for (RMpPollutionDPO pollution : pollutionDayList){ + if (lineid.equals(pollution.getLineId())){ + processList.add(pollution); + } + } + } + Map inMap = new HashMap<>(); + inMap.put("substationId",key); + inMap.put("dataDate",local); + for (DictData dictData : dictDataList){ + processData(dictData, processList, inMap); + if (!inMap.containsKey("pollutionType")){ + continue; + } + if (Integer.valueOf(BizParamConstant.STAT_BIZ_DAY).equals(type)){ + rStatPollutionSubstationDMapper.insertPollution(inMap); + } } } - } - Map inMap = new HashMap<>(); - inMap.put("substationId",key); - inMap.put("dataDate",local); - for (DictData dictData : dictDataList){ - processData(dictData, processList, inMap); - if (!inMap.containsKey("pollutionType")){ - continue; - } - if (Integer.valueOf(BizParamConstant.STAT_BIZ_DAY).equals(type)){ - rStatPollutionSubstationDMapper.insertPollution(inMap); - }else if (Integer.valueOf(BizParamConstant.STAT_BIZ_MONTH).equals(type)){ - rStatPollutionSubstationMMapper.insertPollution(inMap); - }else if (Integer.valueOf(BizParamConstant.STAT_BIZ_QUARTER).equals(type)){ - rStatPollutionSubstationQMapper.insertPollution(inMap); - }else if (Integer.valueOf(BizParamConstant.STAT_BIZ_YEAR).equals(type)){ - rStatPollutionSubstationYMapper.insertPollution(inMap); - } - } + }else if (Integer.valueOf(BizParamConstant.STAT_BIZ_MONTH).equals(type)){ + List substationD = rStatPollutionSubstationDMapper.selectList(new LambdaQueryWrapper() + .ge(RStatPollutionSubstationDPO::getDataDate, local) + .le(RStatPollutionSubstationDPO::getDataDate, localEnd) + ); + Map> substationDMap = substationD.stream().collect(Collectors.groupingBy(temp -> temp.getSubstationId() +"_"+ temp.getPollutionType())); + substationDMap.forEach((key,value)->{ + String[] split = key.split("_"); + Map inMap = new HashMap<>(); + inMap.put("substationId",split[0]); + inMap.put("dataDate",local); + inMap.put("pollutionType",split[1]); + inMap.put("value",value.stream().max(Comparator.comparing(RStatPollutionSubstationDPO::getValue)).get().getValue()); + rStatPollutionSubstationMMapper.insertPollution(inMap); + + }); + }else if (Integer.valueOf(BizParamConstant.STAT_BIZ_QUARTER).equals(type)){ + List substationM = rStatPollutionSubstationMMapper.selectList(new LambdaQueryWrapper() + .ge(RStatPollutionSubstationM::getDataDate, local) + .le(RStatPollutionSubstationM::getDataDate, localEnd) + ); + Map> substationDMap = substationM.stream().collect(Collectors.groupingBy(temp -> temp.getSubstationId() +"_"+ temp.getPollutionType())); + substationDMap.forEach((key,value)->{ + String[] split = key.split("_"); + Map inMap = new HashMap<>(); + inMap.put("substationId",split[0]); + inMap.put("dataDate",local); + inMap.put("pollutionType",split[1]); + inMap.put("value",value.stream().max(Comparator.comparing(RStatPollutionSubstationM::getValue)).get().getValue()); + rStatPollutionSubstationQMapper.insertPollution(inMap); + + }); + }else if (Integer.valueOf(BizParamConstant.STAT_BIZ_YEAR).equals(type)){ + List substationM = rStatPollutionSubstationQMapper.selectList(new LambdaQueryWrapper() + .ge(RStatPollutionSubstationQPO::getDataDate, local) + .le(RStatPollutionSubstationQPO::getDataDate, localEnd) + ); + Map> substationDMap = substationM.stream().collect(Collectors.groupingBy(temp -> temp.getSubstationId() +"_"+ temp.getPollutionType())); + substationDMap.forEach((key,value)->{ + String[] split = key.split("_"); + Map inMap = new HashMap<>(); + inMap.put("substationId",split[0]); + inMap.put("dataDate",local); + inMap.put("pollutionType",split[1]); + inMap.put("value",value.stream().max(Comparator.comparing(RStatPollutionSubstationQPO::getValue)).get().getValue()); + rStatPollutionSubstationYMapper.insertPollution(inMap); + }); } } /*MySql入表 r_stat_pollution_org*/ - private void insertUnit(List dictDataList,List deptGetChildrenDTOList,List pollutionDayList,LocalDateTime local, Integer type){ - for (DeptGetChildrenDTO deptGetChildrenDTO : deptGetChildrenDTOList){ - List processList = new ArrayList<>(); - - for(String lineid : deptGetChildrenDTO.getLineIds()){ - for (RMpPollutionDPO pollution : pollutionDayList){ - if (lineid.equals(pollution.getLineId())){ - processList.add(pollution); + private void insertUnit(List dictDataList,List deptGetChildrenDTOList,List pollutionDayList,LocalDateTime local, LocalDateTime localEnd, Integer type){ + if (Integer.valueOf(BizParamConstant.STAT_BIZ_DAY).equals(type)){ + for (DeptGetChildrenDTO deptGetChildrenDTO : deptGetChildrenDTOList){ + List processList = new ArrayList<>(); + for(String lineid : deptGetChildrenDTO.getLineIds()){ + for (RMpPollutionDPO pollution : pollutionDayList){ + if (lineid.equals(pollution.getLineId())){ + processList.add(pollution); + } } } - } - Map inMap = new HashMap<>(); - inMap.put("orgId",deptGetChildrenDTO.getDeptId()); - inMap.put("dataDate",local); - for (DictData dictData : dictDataList){ - processData(dictData, processList, inMap); - if (!inMap.containsKey("pollutionType")){ - continue; - } - if (Integer.valueOf(BizParamConstant.STAT_BIZ_DAY).equals(type)){ + Map inMap = new HashMap<>(); + inMap.put("orgId",deptGetChildrenDTO.getDeptId()); + inMap.put("dataDate",local); + for (DictData dictData : dictDataList){ + processData(dictData, processList, inMap); + if (!inMap.containsKey("pollutionType")){ + continue; + } rStatPollutionOrgDMapper.insertPollution(inMap); - }else if (Integer.valueOf(BizParamConstant.STAT_BIZ_MONTH).equals(type)){ - rStatPollutionOrgMMapper.insertPollution(inMap); - }else if (Integer.valueOf(BizParamConstant.STAT_BIZ_QUARTER).equals(type)){ - rStatPollutionOrgQMapper.insertPollution(inMap); - }else if (Integer.valueOf(BizParamConstant.STAT_BIZ_YEAR).equals(type)){ - rStatPollutionOrgYMapper.insertPollution(inMap); } } + + }else if (Integer.valueOf(BizParamConstant.STAT_BIZ_MONTH).equals(type)){ + List substationD = rStatPollutionOrgDMapper.selectList(new LambdaQueryWrapper() + .ge(RStatPollutionOrgDPO::getDataDate, local) + .le(RStatPollutionOrgDPO::getDataDate, localEnd) + ); + Map> substationDMap = substationD.stream().collect(Collectors.groupingBy(temp -> temp.getOrgId() +"_"+ temp.getPollutionType())); + substationDMap.forEach((key,value)->{ + String[] split = key.split("_"); + Map inMap = new HashMap<>(); + inMap.put("orgId",split[0]); + inMap.put("dataDate",local); + inMap.put("pollutionType",split[1]); + inMap.put("value",value.stream().max(Comparator.comparing(RStatPollutionOrgDPO::getValue)).get().getValue()); + rStatPollutionOrgMMapper.insertPollution(inMap); + }); + }else if (Integer.valueOf(BizParamConstant.STAT_BIZ_QUARTER).equals(type)){ + List substationD = rStatPollutionOrgMMapper.selectList(new LambdaQueryWrapper() + .ge(RStatPollutionOrgMPO::getDataDate, local) + .le(RStatPollutionOrgMPO::getDataDate, localEnd) + ); + Map> substationDMap = substationD.stream().collect(Collectors.groupingBy(temp -> temp.getOrgId() +"_"+ temp.getPollutionType())); + substationDMap.forEach((key,value)->{ + String[] split = key.split("_"); + Map inMap = new HashMap<>(); + inMap.put("orgId",split[0]); + inMap.put("dataDate",local); + inMap.put("pollutionType",split[1]); + inMap.put("value",value.stream().max(Comparator.comparing(RStatPollutionOrgMPO::getValue)).get().getValue()); + rStatPollutionOrgQMapper.insertPollution(inMap); + }); + }else if (Integer.valueOf(BizParamConstant.STAT_BIZ_YEAR).equals(type)){ + List substationD = rStatPollutionOrgQMapper.selectList(new LambdaQueryWrapper() + .ge(RStatPollutionOrgQPO::getDataDate, local) + .le(RStatPollutionOrgQPO::getDataDate, localEnd) + ); + Map> substationDMap = substationD.stream().collect(Collectors.groupingBy(temp -> temp.getOrgId() +"_"+ temp.getPollutionType())); + substationDMap.forEach((key,value)->{ + String[] split = key.split("_"); + Map inMap = new HashMap<>(); + inMap.put("orgId",split[0]); + inMap.put("dataDate",local); + inMap.put("pollutionType",split[1]); + inMap.put("value",value.stream().max(Comparator.comparing(RStatPollutionOrgQPO::getValue)).get().getValue()); + rStatPollutionOrgYMapper.insertPollution(inMap); + }); } + } private void processDataLineId(DictData dictData, PollutionDTO pollution, Map map){