|
|
@@ -37,6 +37,8 @@ import java.text.DecimalFormat;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.time.LocalTime;
|
|
|
import java.util.*;
|
|
|
+import java.util.function.BiConsumer;
|
|
|
+import java.util.function.Consumer;
|
|
|
import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
|
import java.util.stream.Collectors;
|
|
|
@@ -91,7 +93,7 @@ public class MonitorNoticeServiceImpl extends ServiceImpl<MonitorNoticeMapper, M
|
|
|
public CountWithTime yesterday(String orgId) {
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
calendar.setTime(new Date());
|
|
|
- calendar.add(Calendar.DAY_OF_MONTH,-1);
|
|
|
+ calendar.add(Calendar.DAY_OF_MONTH, -1);
|
|
|
String day = dateFormat.format(calendar.getTime());
|
|
|
List<String> timePeriodList = new ArrayList<>();
|
|
|
List<Integer> countList = new ArrayList<>();
|
|
|
@@ -115,7 +117,7 @@ public class MonitorNoticeServiceImpl extends ServiceImpl<MonitorNoticeMapper, M
|
|
|
public CountWithTime dayBeforeYesterday(String orgId) {
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
calendar.setTime(new Date());
|
|
|
- calendar.add(Calendar.DAY_OF_MONTH,-2);
|
|
|
+ calendar.add(Calendar.DAY_OF_MONTH, -2);
|
|
|
String day = dateFormat.format(calendar.getTime());
|
|
|
List<String> timePeriodList = new ArrayList<>();
|
|
|
List<Integer> countList = new ArrayList<>();
|
|
|
@@ -173,57 +175,214 @@ public class MonitorNoticeServiceImpl extends ServiceImpl<MonitorNoticeMapper, M
|
|
|
appDeviceQueryParams.setSensorRoute(trendParam.getRoads());
|
|
|
appDeviceQueryParams.setAggregationWindow(trendParam.getAggregationWindow());
|
|
|
SensorEchartDataResult sensorEchartDataResult = appDeviceService.queryDataByDeviceIdAndRoads(appDeviceQueryParams);
|
|
|
- List<Float> tList = sensorEchartDataResult.getTemperature().getY();
|
|
|
- List<Float> hList = sensorEchartDataResult.getHumidity().getY();
|
|
|
- List<Float> cList = sensorEchartDataResult.getCo2().getY();
|
|
|
+ // 获取各传感器数据列表
|
|
|
+ List<Float> tList = sensorEchartDataResult.getTemperature().getY(); // 温度
|
|
|
+ List<Float> hList = sensorEchartDataResult.getHumidity().getY(); // 湿度
|
|
|
+ List<Float> cList = sensorEchartDataResult.getCo2().getY(); // 二氧化碳
|
|
|
+ List<Float> pm25List = sensorEchartDataResult.getPm25().getY(); // PM2.5
|
|
|
+ List<Float> pm10List = sensorEchartDataResult.getPm10().getY(); // PM10
|
|
|
+ List<Float> no2List = sensorEchartDataResult.getNo2().getY(); // 二氧化氮
|
|
|
+ List<Float> o3List = sensorEchartDataResult.getO3().getY(); // 臭氧
|
|
|
+ List<Float> o2List = sensorEchartDataResult.getO2().getY(); // 氧气
|
|
|
+ List<Float> so2List = sensorEchartDataResult.getSo2().getY(); // 二氧化硫
|
|
|
+ List<Float> vocList = sensorEchartDataResult.getTvoc().getY(); // 挥发性有机物
|
|
|
+ List<Float> coList = sensorEchartDataResult.getCo().getY(); // 一氧化碳
|
|
|
+ List<Float> h2List = sensorEchartDataResult.getH2().getY(); // 氢气
|
|
|
+ List<Float> ch2oList = sensorEchartDataResult.getCh2o().getY(); // 甲醛
|
|
|
+ List<Float> h2sList = sensorEchartDataResult.getH2s().getY(); // 硫化氢
|
|
|
+ List<Float> noiseList = sensorEchartDataResult.getDb().getY(); // 噪声
|
|
|
+ List<Float> pressureList = sensorEchartDataResult.getPressure().getY(); // 气压
|
|
|
+ List<Float> illuminanceList = sensorEchartDataResult.getIlluminance().getY(); // 光照
|
|
|
+ List<Float> ch4List = sensorEchartDataResult.getCh4().getY(); // 甲烷
|
|
|
+ List<Float> nh3List = sensorEchartDataResult.getNh3().getY(); // 氨
|
|
|
+ List<Float> odorList = sensorEchartDataResult.getOdor().getY(); // 异味
|
|
|
+ List<Float> tspList = sensorEchartDataResult.getTsp().getY(); // 细颗粒物
|
|
|
+ List<Float> smokeList = sensorEchartDataResult.getSmoke().getY(); // 烟雾
|
|
|
+ List<Float> n2List = sensorEchartDataResult.getN2().getY();
|
|
|
Trend trend = BeanUtil.copyProperties(oneByDeviceCodeAndSensorNo, Trend.class);
|
|
|
DecimalFormat df = new DecimalFormat("#.00");
|
|
|
+ // 处理温度数据
|
|
|
if (!tList.isEmpty()) {
|
|
|
- double tMax = tList.stream().mapToDouble(Number::floatValue).max().getAsDouble();
|
|
|
- double tMin = tList.stream().mapToDouble(Number::floatValue).min().getAsDouble();
|
|
|
- double tAvg = tList.stream().mapToDouble(Number::floatValue).average().getAsDouble();
|
|
|
- trend.setTMax((float) tMax);
|
|
|
- trend.setTMin((float) tMin);
|
|
|
- trend.setTAvg(Float.parseFloat(df.format(tAvg)));
|
|
|
- LinkedHashSet<String> x = sensorEchartDataResult.getTemperature().getX();
|
|
|
- LinkedHashSet<String> newX = new LinkedHashSet<>();
|
|
|
- x.forEach(xData -> {
|
|
|
- newX.add(formatTime(xData));
|
|
|
- });
|
|
|
- sensorEchartDataResult.setTemperature(new SensorEchartData(newX, tList));
|
|
|
+ processSensorData(tList, sensorEchartDataResult.getTemperature(),
|
|
|
+ trend::setTMax, trend::setTMin, trend::setTAvg,
|
|
|
+ (x, y) -> sensorEchartDataResult.setTemperature(new SensorEchartData(x, y)));
|
|
|
}
|
|
|
+
|
|
|
+ // 处理湿度数据
|
|
|
if (!hList.isEmpty()) {
|
|
|
- double hMax = hList.stream().mapToDouble(Number::floatValue).max().getAsDouble();
|
|
|
- double hMin = hList.stream().mapToDouble(Number::floatValue).min().getAsDouble();
|
|
|
- double hAvg = hList.stream().mapToDouble(Number::floatValue).average().getAsDouble();
|
|
|
- trend.setHMax((float) hMax);
|
|
|
- trend.setHMin((float) hMin);
|
|
|
- trend.setHAvg((float) hAvg);
|
|
|
- LinkedHashSet<String> x = sensorEchartDataResult.getHumidity().getX();
|
|
|
- LinkedHashSet<String> newX = new LinkedHashSet<>();
|
|
|
- x.forEach(xData -> {
|
|
|
- newX.add(formatTime(xData));
|
|
|
- });
|
|
|
- sensorEchartDataResult.setHumidity(new SensorEchartData(newX, hList));
|
|
|
+ processSensorData(hList, sensorEchartDataResult.getHumidity(),
|
|
|
+ trend::setHMax, trend::setHMin, trend::setHAvg,
|
|
|
+ (x, y) -> sensorEchartDataResult.setHumidity(new SensorEchartData(x, y)));
|
|
|
}
|
|
|
+
|
|
|
+ // 处理CO2数据
|
|
|
if (!cList.isEmpty()) {
|
|
|
- double cMax = cList.stream().mapToDouble(Number::floatValue).max().getAsDouble();
|
|
|
- double cMin = cList.stream().mapToDouble(Number::floatValue).min().getAsDouble();
|
|
|
- double cAvg = cList.stream().mapToDouble(Number::floatValue).average().getAsDouble();
|
|
|
- trend.setCMax((float) cMax);
|
|
|
- trend.setCMin((float) cMin);
|
|
|
- trend.setCAvg((float) cAvg);
|
|
|
- LinkedHashSet<String> x = sensorEchartDataResult.getCo2().getX();
|
|
|
- LinkedHashSet<String> newX = new LinkedHashSet<>();
|
|
|
- x.forEach(xData -> {
|
|
|
- newX.add(formatTime(xData));
|
|
|
- });
|
|
|
- sensorEchartDataResult.setCo2(new SensorEchartData(newX, cList));
|
|
|
+ processSensorData(cList, sensorEchartDataResult.getCo2(),
|
|
|
+ trend::setCMax, trend::setCMin, trend::setCAvg,
|
|
|
+ (x, y) -> sensorEchartDataResult.setCo2(new SensorEchartData(x, y)));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理PM2.5数据
|
|
|
+ if (!pm25List.isEmpty()) {
|
|
|
+ processSensorData(pm25List, sensorEchartDataResult.getPm25(),
|
|
|
+ trend::setPm25Max, trend::setPm25Min, trend::setPm25Avg,
|
|
|
+ (x, y) -> sensorEchartDataResult.setPm25(new SensorEchartData(x, y)));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理PM10数据
|
|
|
+ if (!pm10List.isEmpty()) {
|
|
|
+ processSensorData(pm10List, sensorEchartDataResult.getPm10(),
|
|
|
+ trend::setPm10Max, trend::setPm10Min, trend::setPm10Avg,
|
|
|
+ (x, y) -> sensorEchartDataResult.setPm10(new SensorEchartData(x, y)));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理NO2数据
|
|
|
+ if (!no2List.isEmpty()) {
|
|
|
+ processSensorData(no2List, sensorEchartDataResult.getNo2(),
|
|
|
+ trend::setNo2Max, trend::setNo2Min, trend::setNo2Avg,
|
|
|
+ (x, y) -> sensorEchartDataResult.setNo2(new SensorEchartData(x, y)));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理O3数据
|
|
|
+ if (!o3List.isEmpty()) {
|
|
|
+ processSensorData(o3List, sensorEchartDataResult.getO3(),
|
|
|
+ trend::setO3Max, trend::setO3Min, trend::setO3Avg,
|
|
|
+ (x, y) -> sensorEchartDataResult.setO3(new SensorEchartData(x, y)));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理O2数据
|
|
|
+ if (!o2List.isEmpty()) {
|
|
|
+ processSensorData(o2List, sensorEchartDataResult.getO2(),
|
|
|
+ trend::setO2Max, trend::setO2Min, trend::setO2Avg,
|
|
|
+ (x, y) -> sensorEchartDataResult.setO2(new SensorEchartData(x, y)));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理SO2数据
|
|
|
+ if (!so2List.isEmpty()) {
|
|
|
+ processSensorData(so2List, sensorEchartDataResult.getSo2(),
|
|
|
+ trend::setSo2Max, trend::setSo2Min, trend::setSo2Avg,
|
|
|
+ (x, y) -> sensorEchartDataResult.setSo2(new SensorEchartData(x, y)));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理VOC数据
|
|
|
+ if (!vocList.isEmpty()) {
|
|
|
+ processSensorData(vocList, sensorEchartDataResult.getTvoc(),
|
|
|
+ trend::setTvocMax, trend::setTvocMin, trend::setTvocAvg,
|
|
|
+ (x, y) -> sensorEchartDataResult.setTvoc(new SensorEchartData(x, y)));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理CO数据
|
|
|
+ if (!coList.isEmpty()) {
|
|
|
+ processSensorData(coList, sensorEchartDataResult.getCo(),
|
|
|
+ trend::setCoMax, trend::setCoMin, trend::setCoAvg,
|
|
|
+ (x, y) -> sensorEchartDataResult.setCo(new SensorEchartData(x, y)));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理H2数据
|
|
|
+ if (!h2List.isEmpty()) {
|
|
|
+ processSensorData(h2List, sensorEchartDataResult.getH2(),
|
|
|
+ trend::setH2Max, trend::setH2Min, trend::setH2Avg,
|
|
|
+ (x, y) -> sensorEchartDataResult.setH2(new SensorEchartData(x, y)));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理甲醛数据
|
|
|
+ if (!ch2oList.isEmpty()) {
|
|
|
+ processSensorData(ch2oList, sensorEchartDataResult.getCh2o(),
|
|
|
+ trend::setCh2oMax, trend::setCh2oMin, trend::setCh2oAvg,
|
|
|
+ (x, y) -> sensorEchartDataResult.setCh2o(new SensorEchartData(x, y)));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理H2S数据
|
|
|
+ if (!h2sList.isEmpty()) {
|
|
|
+ processSensorData(h2sList, sensorEchartDataResult.getH2s(),
|
|
|
+ trend::setH2sMax, trend::setH2sMin, trend::setH2sAvg,
|
|
|
+ (x, y) -> sensorEchartDataResult.setH2s(new SensorEchartData(x, y)));
|
|
|
}
|
|
|
+
|
|
|
+ // 处理噪声数据
|
|
|
+ if (!noiseList.isEmpty()) {
|
|
|
+ processSensorData(noiseList, sensorEchartDataResult.getDb(),
|
|
|
+ trend::setDbMax, trend::setDbMin, trend::setDbAvg,
|
|
|
+ (x, y) -> sensorEchartDataResult.setDb(new SensorEchartData(x, y)));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理气压数据
|
|
|
+ if (!pressureList.isEmpty()) {
|
|
|
+ processSensorData(pressureList, sensorEchartDataResult.getPressure(),
|
|
|
+ trend::setPressureMax, trend::setPressureMin, trend::setPressureAvg,
|
|
|
+ (x, y) -> sensorEchartDataResult.setPressure(new SensorEchartData(x, y)));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理光照数据
|
|
|
+ if (!illuminanceList.isEmpty()) {
|
|
|
+ processSensorData(illuminanceList, sensorEchartDataResult.getIlluminance(),
|
|
|
+ trend::setIlluminanceMax, trend::setIlluminanceMin, trend::setIlluminanceAvg,
|
|
|
+ (x, y) -> sensorEchartDataResult.setIlluminance(new SensorEchartData(x, y)));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理甲烷数据
|
|
|
+ if (!ch4List.isEmpty()) {
|
|
|
+ processSensorData(ch4List, sensorEchartDataResult.getCh4(),
|
|
|
+ trend::setCh4Max, trend::setCh4Min, trend::setCh4Avg,
|
|
|
+ (x, y) -> sensorEchartDataResult.setCh4(new SensorEchartData(x, y)));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理氨数据
|
|
|
+ if (!nh3List.isEmpty()) {
|
|
|
+ processSensorData(nh3List, sensorEchartDataResult.getNh3(),
|
|
|
+ trend::setNh3Max, trend::setNh3Min, trend::setNh3Avg,
|
|
|
+ (x, y) -> sensorEchartDataResult.setNh3(new SensorEchartData(x, y)));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理异味数据
|
|
|
+ if (!odorList.isEmpty()) {
|
|
|
+ processSensorData(odorList, sensorEchartDataResult.getOdor(),
|
|
|
+ trend::setOdorMax, trend::setOdorMin, trend::setOdorAvg,
|
|
|
+ (x, y) -> sensorEchartDataResult.setOdor(new SensorEchartData(x, y)));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理TSP数据
|
|
|
+ if (!tspList.isEmpty()) {
|
|
|
+ processSensorData(tspList, sensorEchartDataResult.getTsp(),
|
|
|
+ trend::setTspMax, trend::setTspMin, trend::setTspAvg,
|
|
|
+ (x, y) -> sensorEchartDataResult.setTsp(new SensorEchartData(x, y)));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理烟雾数据
|
|
|
+ if (!smokeList.isEmpty()) {
|
|
|
+ processSensorData(smokeList, sensorEchartDataResult.getSmoke(),
|
|
|
+ trend::setSmokeMax, trend::setSmokeMin, trend::setSmokeAvg,
|
|
|
+ (x, y) -> sensorEchartDataResult.setSmoke(new SensorEchartData(x, y)));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!n2List.isEmpty()) {
|
|
|
+ processSensorData(n2List, sensorEchartDataResult.getN2(),
|
|
|
+ trend::setN2Max, trend::setN2Min, trend::setN2Avg,
|
|
|
+ (x, y) -> sensorEchartDataResult.setN2(new SensorEchartData(x, y)));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
trend.setSensorEchartDataResult(sensorEchartDataResult);
|
|
|
return trend;
|
|
|
}
|
|
|
|
|
|
+ // 通用处理方法
|
|
|
+ private void processSensorData(List<Float> dataList, SensorEchartData sensorData,
|
|
|
+ Consumer<Float> setMax, Consumer<Float> setMin, Consumer<Float> setAvg,
|
|
|
+ BiConsumer<LinkedHashSet<String>, List<Float>> setResult) {
|
|
|
+ double max = dataList.stream().mapToDouble(Number::floatValue).max().getAsDouble();
|
|
|
+ double min = dataList.stream().mapToDouble(Number::floatValue).min().getAsDouble();
|
|
|
+ double avg = dataList.stream().mapToDouble(Number::floatValue).average().getAsDouble();
|
|
|
+
|
|
|
+ setMax.accept((float) max);
|
|
|
+ setMin.accept((float) min);
|
|
|
+ setAvg.accept((float) avg);
|
|
|
+
|
|
|
+ LinkedHashSet<String> newX = new LinkedHashSet<>();
|
|
|
+ sensorData.getX().forEach(xData -> newX.add(formatTime(xData)));
|
|
|
+ setResult.accept(newX, dataList);
|
|
|
+ }
|
|
|
+
|
|
|
private String formatTime(String time) {
|
|
|
String[] split = time.split(" ");
|
|
|
String regex = "[\u4e00-\u9fa5]";
|