From 9655ea9ce8cdd671a766f87a0885b0fdff7b89c9 Mon Sep 17 00:00:00 2001
From: jinpengyong <jpy123456>
Date: Thu, 24 Aug 2023 17:12:28 +0800
Subject: [PATCH] Merge branch 'dev' of http://blit.7drlb.com:8888/r/moral into wb
---
screen-api/src/main/java/com/moral/api/service/impl/DeviceServiceImpl.java | 10 ++
screen-manage/src/main/java/com/moral/api/util/AdjustDataUtils.java | 68 +++++++++-------
screen-api/src/main/java/com/moral/api/config/Interceptor/WebAppConfiguration.java | 5 -
screen-manage/src/main/java/com/moral/api/service/impl/HistoryHourlyServiceImpl.java | 13 +-
screen-api/src/main/java/com/moral/api/config/Interceptor/CorsConfig.java | 51 ++++++++++++
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 ++++++++++++--
screen-manage/src/main/java/com/moral/api/kafka/consumer/DeviceConsumer.java | 16 +++
8 files changed, 173 insertions(+), 52 deletions(-)
diff --git a/screen-api/src/main/java/com/moral/api/config/Interceptor/CorsConfig.java b/screen-api/src/main/java/com/moral/api/config/Interceptor/CorsConfig.java
new file mode 100644
index 0000000..7db0bc2
--- /dev/null
+++ b/screen-api/src/main/java/com/moral/api/config/Interceptor/CorsConfig.java
@@ -0,0 +1,51 @@
+package com.moral.api.config.Interceptor;
+
+import org.springframework.boot.SpringBootConfiguration;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.cors.CorsConfiguration;
+import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
+import org.springframework.web.filter.CorsFilter;
+import org.springframework.web.servlet.config.annotation.CorsRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+/**
+ * @ClassName CorsConfig
+ * @Description TODO
+ * @Author @lizijie
+ * @Date 2023-08-23 13:27
+ * @Version 1.0
+ */
+@Configuration
+public class CorsConfig {
+
+ @Bean
+ public CorsFilter corsFilter() {
+
+ CorsConfiguration config = new CorsConfiguration();
+ //������������ip���������������������������������������������������������������
+ config.addAllowedOrigin("*");
+ //������������������Cookie������
+ config.setAllowCredentials(true);
+ //������������Http���������������������������
+ config.addAllowedMethod("*");
+ //������HTTP������������������������Header������
+ config.addAllowedHeader("*");
+ //������������������������������������������������������������������������������������
+// config.addExposedHeader("*");
+
+ config.addExposedHeader("Content-Type");
+ config.addExposedHeader( "X-Requested-With");
+ config.addExposedHeader("accept");
+ config.addExposedHeader("Origin");
+ config.addExposedHeader( "Access-Control-Request-Method");
+ config.addExposedHeader("Access-Control-Request-Headers");
+
+ //������������������������/**������������������������������������������������������������������
+ UrlBasedCorsConfigurationSource configSource = new UrlBasedCorsConfigurationSource();
+ configSource.registerCorsConfiguration("/**", config);
+
+ return new CorsFilter(configSource);
+ }
+
+}
diff --git a/screen-api/src/main/java/com/moral/api/config/Interceptor/WebAppConfiguration.java b/screen-api/src/main/java/com/moral/api/config/Interceptor/WebAppConfiguration.java
index f1cde10..ffb1dfa 100644
--- a/screen-api/src/main/java/com/moral/api/config/Interceptor/WebAppConfiguration.java
+++ b/screen-api/src/main/java/com/moral/api/config/Interceptor/WebAppConfiguration.java
@@ -4,10 +4,7 @@
import org.springframework.boot.system.ApplicationHome;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
-import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
-import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
-import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
-import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+import org.springframework.web.servlet.config.annotation.*;
import java.util.ArrayList;
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/DeviceServiceImpl.java b/screen-api/src/main/java/com/moral/api/service/impl/DeviceServiceImpl.java
index 005d4ca..9619dba 100644
--- a/screen-api/src/main/java/com/moral/api/service/impl/DeviceServiceImpl.java
+++ b/screen-api/src/main/java/com/moral/api/service/impl/DeviceServiceImpl.java
@@ -358,8 +358,14 @@
Map<String,Object> historyHourlyMap = new HashMap<>();
historyHourlyMap.put("mac",mac);
JSONObject value = JSONObject.parseObject(historyFiveMinutely.getValue());
- Double sensorValue = Double.parseDouble(value.get(sensorCode).toString());
- historyHourlyMap.put(sensorCode,sensorValue);
+ if (value.get(sensorCode)==null){
+ historyHourlyMap.put(sensorCode,0.0);
+ }else {
+ Double sensorValue = Double.parseDouble(value.get(sensorCode).toString());
+ historyHourlyMap.put(sensorCode,sensorValue);
+ }
+// Double sensorValue = Double.parseDouble(value.get(sensorCode).toString());
+// historyHourlyMap.put(sensorCode,sensorValue);
Date time = historyFiveMinutely.getTime();
String timeStr = DateUtils.dateToDateString(time, DateUtils.yyyy_MM_dd_HH_mm_ss_EN);
historyHourlyMap.put("time",timeStr);
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);
}
diff --git a/screen-manage/src/main/java/com/moral/api/kafka/consumer/DeviceConsumer.java b/screen-manage/src/main/java/com/moral/api/kafka/consumer/DeviceConsumer.java
index c21f1fb..30041ec 100644
--- a/screen-manage/src/main/java/com/moral/api/kafka/consumer/DeviceConsumer.java
+++ b/screen-manage/src/main/java/com/moral/api/kafka/consumer/DeviceConsumer.java
@@ -10,6 +10,9 @@
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;
+import java.text.DecimalFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
@@ -96,8 +99,19 @@
}
//������������
-// data.remove("time");
+ data.remove("time");
data.remove("entryTime");
+ SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ String format = dateFormat.format(new Date().getTime());
+ //������������
+ String substring = format.substring(0, 4);
+
+ String substring1 = time.toString().substring(0, 4);
+
+ String replace = time.toString().replace(substring1, substring);
+
+ data.put("DataTime",replace);
+
Iterator<Map.Entry<String, Object>> iterator = data.entrySet().iterator();
Map<String, Object> newMap = new HashMap<>();
Map.Entry<String, Object> next;
diff --git a/screen-manage/src/main/java/com/moral/api/service/impl/HistoryHourlyServiceImpl.java b/screen-manage/src/main/java/com/moral/api/service/impl/HistoryHourlyServiceImpl.java
index 71646df..5bc892c 100644
--- a/screen-manage/src/main/java/com/moral/api/service/impl/HistoryHourlyServiceImpl.java
+++ b/screen-manage/src/main/java/com/moral/api/service/impl/HistoryHourlyServiceImpl.java
@@ -51,14 +51,13 @@
Map<String, Object> versionInfo = (Map<String, Object>) deviceInfo.get("version");
Integer version = (Integer) versionInfo.get("id");
//���������������
- String time1 = data.get("time").toString();
- long l = Long.parseLong(time1);
- SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:00:00");
- String format1 = dateFormat.format(l);
- Date time = DateUtils.getDate(format1, DateUtils.yyyy_MM_dd_HH_mm_ss_EN);
+// String time1 = data.get("time").toString();
+// long l = Long.parseLong(time1);
+// SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:00:00");
+// String format1 = dateFormat.format(l);
+// Date time = DateUtils.getDate(format1, DateUtils.yyyy_MM_dd_HH_mm_ss_EN);
-
-// Date time = DateUtils.getDate((String) data.remove("DataTime"), DateUtils.yyyyMMddHHmmss_EN);
+ Date time = DateUtils.getDate((String) data.remove("DataTime"), DateUtils.yyyyMMddHHmmss_EN);
String yearAndMonth = DateUtils.dateToDateString(DateUtils.addHours(time, -1), DateUtils.yyyyMM_EN);
result.put("mac", mac);
diff --git a/screen-manage/src/main/java/com/moral/api/util/AdjustDataUtils.java b/screen-manage/src/main/java/com/moral/api/util/AdjustDataUtils.java
index eda029a..8d59d01 100644
--- a/screen-manage/src/main/java/com/moral/api/util/AdjustDataUtils.java
+++ b/screen-manage/src/main/java/com/moral/api/util/AdjustDataUtils.java
@@ -126,35 +126,45 @@
if (ObjectUtils.isEmpty(map)){
return deviceData;
}
- if (ObjectUtils.isEmpty(aqiMap.get("a21005"))){
- JSONObject jsonObject = JSONObject.parseObject(map.get("value").toString());
- String a21005 = jsonObject.get("a21005").toString();
- deviceData.put("a21005",Double.parseDouble(a21005));
- }
- if (ObjectUtils.isEmpty(aqiMap.get("a21026"))){
- JSONObject jsonObject = JSONObject.parseObject(map.get("value").toString());
- String a21026 = jsonObject.get("a21026").toString();
- deviceData.put("a21026",Double.parseDouble(a21026));
- }
- if (ObjectUtils.isEmpty(aqiMap.get("a21004"))){
- JSONObject jsonObject = JSONObject.parseObject(map.get("value").toString());
- String a21004 = jsonObject.get("a21004").toString();
- deviceData.put("a21004",Double.parseDouble(a21004));
- }
- if (ObjectUtils.isEmpty(aqiMap.get("a34002"))){
- JSONObject jsonObject = JSONObject.parseObject(map.get("value").toString());
- String a34002 = jsonObject.get("a34002").toString();
- deviceData.put("a34002",Double.parseDouble(a34002));
- }
- if (ObjectUtils.isEmpty(aqiMap.get("a34004"))){
- JSONObject jsonObject = JSONObject.parseObject(map.get("value").toString());
- String a34004 = jsonObject.get("a34004").toString();
- deviceData.put("a34004",Double.parseDouble(a34004));
- }
- if (ObjectUtils.isEmpty(aqiMap.get("a05024"))){
- JSONObject jsonObject = JSONObject.parseObject(map.get("value").toString());
- String a05024 = jsonObject.get("a05024").toString();
- deviceData.put("a05024",Double.parseDouble(a05024));
+ JSONObject jsonObject = JSONObject.parseObject(map.get("value").toString());
+ if (ObjectUtils.isEmpty(aqiMap)){
+ deviceData.put("a21005",Double.parseDouble(jsonObject.get("a21005").toString()));
+ deviceData.put("a21026",Double.parseDouble(jsonObject.get("a21026").toString()));
+ deviceData.put("a21004",Double.parseDouble(jsonObject.get("a21004").toString()));
+ deviceData.put("a34002",Double.parseDouble(jsonObject.get("a34002").toString()));
+ deviceData.put("a34004",Double.parseDouble(jsonObject.get("a34004").toString()));
+ deviceData.put("a05024",Double.parseDouble(jsonObject.get("a05024").toString()));
+ }else {
+ if (ObjectUtils.isEmpty(aqiMap.get("a21005"))){
+
+ String a21005 = jsonObject.get("a21005").toString();
+ deviceData.put("a21005",Double.parseDouble(a21005));
+ }
+ if (ObjectUtils.isEmpty(aqiMap.get("a21026"))){
+// JSONObject jsonObject = JSONObject.parseObject(map.get("value").toString());
+ String a21026 = jsonObject.get("a21026").toString();
+ deviceData.put("a21026",Double.parseDouble(a21026));
+ }
+ if (ObjectUtils.isEmpty(aqiMap.get("a21004"))){
+// JSONObject jsonObject = JSONObject.parseObject(map.get("value").toString());
+ String a21004 = jsonObject.get("a21004").toString();
+ deviceData.put("a21004",Double.parseDouble(a21004));
+ }
+ if (ObjectUtils.isEmpty(aqiMap.get("a34002"))){
+// JSONObject jsonObject = JSONObject.parseObject(map.get("value").toString());
+ String a34002 = jsonObject.get("a34002").toString();
+ deviceData.put("a34002",Double.parseDouble(a34002));
+ }
+ if (ObjectUtils.isEmpty(aqiMap.get("a34004"))){
+// JSONObject jsonObject = JSONObject.parseObject(map.get("value").toString());
+ String a34004 = jsonObject.get("a34004").toString();
+ deviceData.put("a34004",Double.parseDouble(a34004));
+ }
+ if (ObjectUtils.isEmpty(aqiMap.get("a05024"))){
+// JSONObject jsonObject = JSONObject.parseObject(map.get("value").toString());
+ String a05024 = jsonObject.get("a05024").toString();
+ deviceData.put("a05024",Double.parseDouble(a05024));
+ }
}
}
--
Gitblit v1.8.0