From 06b49617f43d36220649e81a7e4ac912356fd1b4 Mon Sep 17 00:00:00 2001
From: cjl <276999030@qq.com>
Date: Wed, 23 Aug 2023 15:38:16 +0800
Subject: [PATCH] fix:监测站数据展示
---
screen-api/src/main/java/com/moral/api/dto/MonitoringStationDTO.java | 4 ++
screen-api/src/main/java/com/moral/api/service/impl/MonitorPointServiceImpl.java | 58 ++++++++++++++++++++++++----
2 files changed, 53 insertions(+), 9 deletions(-)
diff --git a/screen-api/src/main/java/com/moral/api/dto/MonitoringStationDTO.java b/screen-api/src/main/java/com/moral/api/dto/MonitoringStationDTO.java
index 54dc8be..2e50d5b 100644
--- a/screen-api/src/main/java/com/moral/api/dto/MonitoringStationDTO.java
+++ b/screen-api/src/main/java/com/moral/api/dto/MonitoringStationDTO.java
@@ -36,10 +36,14 @@
private int CompositeNum;
private BigDecimal SO2;
+ private int SO2Num;
private BigDecimal NO2;
+ private int NO2Num;
private BigDecimal PM10;
+ private int PM10Num;
private BigDecimal CO;
+ private int CONum;
}
diff --git a/screen-api/src/main/java/com/moral/api/service/impl/MonitorPointServiceImpl.java b/screen-api/src/main/java/com/moral/api/service/impl/MonitorPointServiceImpl.java
index 26353e6..b5e058d 100644
--- a/screen-api/src/main/java/com/moral/api/service/impl/MonitorPointServiceImpl.java
+++ b/screen-api/src/main/java/com/moral/api/service/impl/MonitorPointServiceImpl.java
@@ -525,7 +525,6 @@
return list;
}
Map<String,Map<String,ArrayList<Double>>> resultMap = new HashMap<>();
- int zz = 0;
for(HistoryDaily h : historyDailyByMacAndTimeSlot) {
JSONObject jsonObject = JSONObject.parseObject(h.getValue());
Map<String, Object> map = jsonObject.getInnerMap();
@@ -556,8 +555,6 @@
maps.put("NO2",numResult);
}
if(Objects.nonNull(map.get("a21005"))){
- System.out.println(">>>"+map.toString());
- System.out.println(">>>"+map.get("a21005").toString());
ArrayList<Double> numResult = Objects.nonNull(maps.get("CO"))?maps.get("CO"):new ArrayList<>();
numResult.add(Double.parseDouble(map.get("a21005").toString()));
maps.put("CO",numResult);
@@ -568,7 +565,6 @@
maps.put("TVOC",numResult);
}
resultMap.put(h.getMac(),maps);
- zz++;
}
for(Map.Entry entry : resultMap.entrySet()){
String mapKey = (String) entry.getKey();
@@ -583,21 +579,21 @@
}
if(mapValue.containsKey("PM10")){
Double ListAvg = mapValue.get("PM10").stream().collect(Collectors.averagingDouble(Double::doubleValue));
- double rsAvg = new BigDecimal(ListAvg).setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue();
+ double rsAvg = new BigDecimal(ListAvg).setScale(0, BigDecimal.ROUND_HALF_UP).doubleValue();
data.put("PM10",rsAvg);
}else {
data.put("PM10",0);
}
if(mapValue.containsKey("SO2")){
Double ListAvg = mapValue.get("SO2").stream().collect(Collectors.averagingDouble(Double::doubleValue));
- double rsAvg = new BigDecimal(ListAvg).setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue();
+ double rsAvg = new BigDecimal(ListAvg).setScale(0, BigDecimal.ROUND_HALF_UP).doubleValue();
data.put("SO2",rsAvg);
}else {
data.put("SO2",0);
}
if(mapValue.containsKey("NO2")){
Double ListAvg = mapValue.get("NO2").stream().collect(Collectors.averagingDouble(Double::doubleValue));
- double rsAvg = new BigDecimal(ListAvg).setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue();
+ double rsAvg = new BigDecimal(ListAvg).setScale(0, BigDecimal.ROUND_HALF_UP).doubleValue();
data.put("NO2",rsAvg);
}else {
data.put("NO2",0);
@@ -629,6 +625,10 @@
monitoringStationDTO.setO3(BigDecimal.valueOf(Double.parseDouble(data.get("O3").toString())));
monitoringStationDTO.setTovc(BigDecimal.valueOf(Double.parseDouble(data.get("TVOC").toString())));
monitoringStationDTO.setComposite(BigDecimal.valueOf(resultNum));
+ monitoringStationDTO.setSO2(BigDecimal.valueOf(Double.parseDouble(data.get("SO2").toString())));
+ monitoringStationDTO.setNO2(BigDecimal.valueOf(Double.parseDouble(data.get("NO2").toString())));
+ monitoringStationDTO.setPM10(BigDecimal.valueOf(Double.parseDouble(data.get("PM10").toString())));
+ monitoringStationDTO.setCO(BigDecimal.valueOf(Double.parseDouble(data.get("CO").toString())));
monitoringStationDTO.setMac(mapKey);
list.add(monitoringStationDTO);
}
@@ -636,12 +636,16 @@
List<MonitoringStationDTO> pM25List = fun3(list,2);
List<MonitoringStationDTO> o3List = fun3(list,3);
List<MonitoringStationDTO> tovcList = fun3(list,4);
+ List<MonitoringStationDTO> SO2List = fun3(list,5);
+ List<MonitoringStationDTO> NO2cList = fun3(list,6);
+ List<MonitoringStationDTO> PM10List = fun3(list,7);
+ List<MonitoringStationDTO> COList = fun3(list,8);
List<MonitoringStationDTO> resultList = new ArrayList<>();
LambdaQueryChainWrapper<Device> wrapper = deviceService.lambdaQuery();
wrapper.eq(Device::getIsDelete,0);
Map<String,String> deviceMap = new HashMap<>();
wrapper.list().forEach(it->deviceMap.put(it.getMac(),it.getName()));
- int num = 1;
+
for (MonitoringStationDTO m :compositeList ){
MonitoringStationDTO monit = new MonitoringStationDTO();
String mac = m.getMac();
@@ -658,7 +662,19 @@
monit.setPM25Num(pM25List.get(listPM25.indexOf(mac)).getPM25Num());
monit.setTovc(tovcList.get(listTovc.indexOf(mac)).getTovc());
monit.setTOVCNum(tovcList.get(listTovc.indexOf(mac)).getTOVCNum());
- //num++;
+ List<String> listSO2 = SO2List.stream().map(MonitoringStationDTO::getMac).collect(Collectors.toList());
+ monit.setSO2(SO2List.get(listSO2.indexOf(mac)).getSO2());
+ monit.setSO2Num(SO2List.get(listSO2.indexOf(mac)).getSO2Num());
+ List<String> listNO2 = NO2cList.stream().map(MonitoringStationDTO::getMac).collect(Collectors.toList());
+ monit.setNO2(NO2cList.get(listNO2.indexOf(mac)).getNO2());
+ monit.setNO2Num(NO2cList.get(listNO2.indexOf(mac)).getNO2Num());
+ List<String> listPM10 = PM10List.stream().map(MonitoringStationDTO::getMac).collect(Collectors.toList());
+ monit.setPM10(PM10List.get(listPM10.indexOf(mac)).getPM10());
+ monit.setPM10Num(PM10List.get(listPM10.indexOf(mac)).getPM10Num());
+ List<String> listCO = COList.stream().map(MonitoringStationDTO::getMac).collect(Collectors.toList());
+ monit.setCO(COList.get(listCO.indexOf(mac)).getCO());
+ monit.setCONum(COList.get(listCO.indexOf(mac)).getCONum());
+
resultList.add(monit);
}
return resultList;
@@ -680,6 +696,18 @@
}else if(type == 4){
compositeList = monList.stream().sorted(Comparator.comparing(MonitoringStationDTO::getTovc)).collect(Collectors.toList());
map1 = compositeList.stream().collect(Collectors.groupingBy(MonitoringStationDTO::getTovc,LinkedHashMap::new,Collectors.toList()));
+ }else if(type == 5){
+ compositeList = monList.stream().sorted(Comparator.comparing(MonitoringStationDTO::getSO2)).collect(Collectors.toList());
+ map1 = compositeList.stream().collect(Collectors.groupingBy(MonitoringStationDTO::getSO2,LinkedHashMap::new,Collectors.toList()));
+ }else if(type == 6){
+ compositeList = monList.stream().sorted(Comparator.comparing(MonitoringStationDTO::getNO2)).collect(Collectors.toList());
+ map1 = compositeList.stream().collect(Collectors.groupingBy(MonitoringStationDTO::getNO2,LinkedHashMap::new,Collectors.toList()));
+ }else if(type == 7){
+ compositeList = monList.stream().sorted(Comparator.comparing(MonitoringStationDTO::getPM10)).collect(Collectors.toList());
+ map1 = compositeList.stream().collect(Collectors.groupingBy(MonitoringStationDTO::getPM10,LinkedHashMap::new,Collectors.toList()));
+ }else if(type == 8){
+ compositeList = monList.stream().sorted(Comparator.comparing(MonitoringStationDTO::getCO)).collect(Collectors.toList());
+ map1 = compositeList.stream().collect(Collectors.groupingBy(MonitoringStationDTO::getCO,LinkedHashMap::new,Collectors.toList()));
}
int index = 1;
for (Map.Entry entry : map1.entrySet()) {
@@ -699,6 +727,18 @@
}else if(type == 4){
stationDTO.setTovc(m.getTovc());
stationDTO.setTOVCNum(index);
+ }else if(type == 5){
+ stationDTO.setSO2(m.getSO2());
+ stationDTO.setSO2Num(index);
+ }else if(type == 6){
+ stationDTO.setNO2(m.getNO2());
+ stationDTO.setNO2Num(index);
+ }else if(type == 7){
+ stationDTO.setPM10(m.getPM10());
+ stationDTO.setPM10Num(index);
+ }else if(type == 8){
+ stationDTO.setCO(m.getCO());
+ stationDTO.setCONum(index);
}
resultList.add(stationDTO);
}
--
Gitblit v1.8.0