From 3cf84aa99a0bb5acddf63eeea9d5d84810105c1e Mon Sep 17 00:00:00 2001
From: lizijie <lzjiiie@163.com>
Date: Mon, 24 Jan 2022 10:12:19 +0800
Subject: [PATCH] 添加边界接口修改
---
screen-api/src/main/java/com/moral/api/service/impl/DataDisplayServiceImpl.java | 197 ++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 168 insertions(+), 29 deletions(-)
diff --git a/screen-api/src/main/java/com/moral/api/service/impl/DataDisplayServiceImpl.java b/screen-api/src/main/java/com/moral/api/service/impl/DataDisplayServiceImpl.java
index ac689eb..8172916 100644
--- a/screen-api/src/main/java/com/moral/api/service/impl/DataDisplayServiceImpl.java
+++ b/screen-api/src/main/java/com/moral/api/service/impl/DataDisplayServiceImpl.java
@@ -3,9 +3,12 @@
import com.alibaba.fastjson.JSON;
import com.moral.api.entity.*;
import com.moral.api.pojo.dto.dataDisplay.MonitorPointDataDisplayDTO;
+import com.moral.api.pojo.dto.dataDisplay.SensorComparisonDisplayDTO;
import com.moral.api.pojo.form.dataDisplay.MonitorPointDataDisplayForm;
+import com.moral.api.pojo.form.dataDisplay.SensorComparisonDisplayForm;
import com.moral.api.service.*;
import com.moral.constant.Constants;
+import com.moral.pojo.AQI;
import com.moral.util.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -65,7 +68,7 @@
dtos = calculateCustomData(macDataMap, deviceMap, startTime, endTime);
}
//���������������������������������������������������������
- else if (reportType.equals(Constants.HOURYLYREPORT)) {
+ else if (reportType.equals(Constants.HOURLY_REPORT)) {
Map<String, HistoryHourly> macDataMap = new HashMap<>();
//������������
macs.forEach(value -> {
@@ -74,24 +77,24 @@
macDataMap.put(value, datas.get(0));
});
if (macDataMap.size() != 0)
- dtos = calculateReportData(macDataMap, deviceMap, startTime);
+ dtos = calculateReportData(macDataMap, deviceMap, reportType, startTime);
}
//���������������������������������������������
- else if (reportType.equals(Constants.DAILYREPORT)) {
+ else if (reportType.equals(Constants.DAILY_REPORT)) {
//������������
Map<String, HistoryDaily> macDataMap = historyDailyService.getHistoryDailyByMacsAndDate(macs, startTime);
if (macDataMap.size() != 0)
- dtos = calculateReportData(macDataMap, deviceMap, startTime);
+ dtos = calculateReportData(macDataMap, deviceMap, reportType, startTime);
}
//���������������������������������������������
- else if (reportType.equals(Constants.WEEKLYREPORT)) {
+ else if (reportType.equals(Constants.WEEKLY_REPORT)) {
//������������
Map<String, HistoryWeekly> macDataMap = historyWeeklyService.getHistoryWeeklyByMacsAndDate(macs, startTime);
if (macDataMap.size() != 0)
- dtos = calculateReportData(macDataMap, deviceMap, startTime, endTime);
+ dtos = calculateReportData(macDataMap, deviceMap, reportType, startTime, endTime);
}
//������������������
- else if (reportType.equals(Constants.MONTHLYREPORT)) {
+ else if (reportType.equals(Constants.MONTHLY_REPORT)) {
//������������������������������������������������������������������������������������������������
Map<String, List<HistoryDaily>> macDataDailyMap = new HashMap<>();
Map<String, HistoryMonthly> macDataMonthlyMap = historyMonthlyService.getHistoryMonthlyByMacsAndDate(macs, startTime);
@@ -101,13 +104,149 @@
macDataDailyMap.put(mac, dailyDatas);
});
if (macDataMonthlyMap.size() != 0)
- dtos = calculateReportData(macDataMonthlyMap, deviceMap, startTime);
+ dtos = calculateReportData(macDataMonthlyMap, deviceMap, reportType, startTime);
//������������������
injectComprehensiveIndex(dtos, macDataDailyMap);
}
return dtos;
}
+ @Override
+ public List<SensorComparisonDisplayDTO> getSensorComparisonDisplayData(SensorComparisonDisplayForm form) {
+ //������
+ List<String> sensors = form.getSensors();
+ Date startDate = form.getStartDate();
+ Date endDate = form.getEndDate();
+ String mac = form.getMac();
+ String reportType = form.getReportType();
+ Map<String, String> timeValueMap = new LinkedHashMap<>();//key���time���value������������json
+ //������������������
+ if (reportType.equals(Constants.DAILY_REPORT)) {
+ List<HistoryHourly> hourlies = historyHourlyService.getValueByMacAndTime(mac, startDate, endDate);
+ for (HistoryHourly historyHourly : hourlies) {
+ Date time = historyHourly.getTime();
+ String dateStr = DateUtils.dateToDateString(time, "yyyy-MM-dd HH");
+ String value = historyHourly.getValue();
+ timeValueMap.put(dateStr, value);
+ }
+ //���������������������������������������24������������������
+ for (int i = 0; i < 24; i++) {
+ //������������
+ String time = DateUtils.dateToDateString(startDate, "yyyy-MM-dd");
+ if (i < 10)
+ time = time + " 0" + i;
+ else
+ time = time + " " + i;
+ if (timeValueMap.get(time) == null)
+ timeValueMap.put(time, null);
+ }
+ }
+ //������������������
+ else if (reportType.equals(Constants.MONTHLY_REPORT)) {
+ List<HistoryDaily> dailies = historyDailyService.getHistoryDailyByMacAndTimeSlot(mac, startDate, endDate);
+ for (HistoryDaily historyDaily : dailies) {
+ Date time = historyDaily.getTime();
+ String dateStr = DateUtils.dateToDateString(time, "yyyy-MM-dd");
+ String value = historyDaily.getValue();
+ timeValueMap.put(String.valueOf(dateStr), value);
+ }
+ //������������������������������������������������������
+ int days = DateUtils.getMonthDay(startDate);
+ for (int i = 1; i <= days; i++) {
+ //������������
+ String time = DateUtils.dateToDateString(startDate, "yyyy-MM");
+ if (i < 10)
+ time = time + "-0" + i;
+ else
+ time = time + "-" + i;
+ if (timeValueMap.get(time) == null)
+ timeValueMap.put(time, null);
+ }
+ } else
+ return null;
+ //������������
+ timeValueMap = sortMapByTime(timeValueMap, reportType);
+ //������������������
+ List<SensorComparisonDisplayDTO> dtos = new ArrayList<>();
+ for (String sensor : sensors) {
+ SensorComparisonDisplayDTO dto = new SensorComparisonDisplayDTO();
+ List<Map<String, Object>> dtoTimeValueList = new ArrayList<>();
+ dto.setSensorCode(sensor);
+ timeValueMap.forEach((time, valueJson) -> {
+ Map<String, Object> listMap = new HashMap<>();
+ //���������������������������������������������
+ if (valueJson == null) {
+ listMap.put("time", time);
+ listMap.put("value", "");
+ dtoTimeValueList.add(listMap);
+ return;
+ }
+ Map<String, Object> valueMap = JSON.parseObject(valueJson, Map.class);
+ Object sensorValueObject = valueMap.get(sensor);
+ //���������������������������������������������
+ if (sensorValueObject == null) {
+ listMap.put("time", time);
+ listMap.put("value", "");
+ dtoTimeValueList.add(listMap);
+ return;
+ }
+ //������������������������������������������
+ if (reportType.equals(Constants.DAILY_REPORT)) {
+ //���������������������N���������������
+ if (!Constants.NORMAL_FLAG.equals(valueMap.get(sensor + "-Flag"))) {
+ listMap.put("time", time);
+ listMap.put("value", "");
+ dtoTimeValueList.add(listMap);
+ return;
+ }
+ }
+ //������������
+ Double sensorValue = Double.parseDouble(sensorValueObject.toString());
+ //������������
+ listMap.put("time", time);
+ listMap.put("value", sensorValue);
+ dtoTimeValueList.add(listMap);
+ });
+ dto.setTimeValueList(dtoTimeValueList);
+ dtos.add(dto);
+ }
+ return dtos;
+ }
+
+ /**
+ * @Description: ������������������������
+ * @Param: [timeValueMap, reportType]
+ * @return: java.util.Map<java.lang.String , java.lang.String>
+ * @Author: ���������
+ * @Date: 2021/11/3
+ */
+ private Map<String, String> sortMapByTime(Map<String, String> timeValueMap, String reportType) {
+ List<Map.Entry<String, String>> entries = new ArrayList(timeValueMap.entrySet());
+ Collections.sort(entries, new Comparator<Map.Entry<String, String>>() {
+ @Override
+ public int compare(Map.Entry<String, String> o1, Map.Entry<String, String> o2) {
+ if (Constants.DAILY_REPORT.equals(reportType)) {
+ String atime = o1.getKey();
+ String btime = o2.getKey();
+ atime = atime.substring(11, 13);
+ btime = btime.substring(11, 13);
+ return Integer.parseInt(atime) - Integer.parseInt(btime);
+ } else if (Constants.MONTHLY_REPORT.equals(reportType)) {
+ String atime = o1.getKey();
+ String btime = o2.getKey();
+ atime = atime.substring(8, 10);
+ btime = btime.substring(8, 10);
+ return Integer.parseInt(atime) - Integer.parseInt(btime);
+ }
+ return 0;
+ }
+ });
+ Map<String, String> sortedMap = new LinkedHashMap<>();
+ for (Map.Entry<String, String> entry : entries) {
+ sortedMap.put(entry.getKey(), entry.getValue());
+ }
+ return sortedMap;
+ }
/**
* @Description: ������������������������������
@@ -128,7 +267,6 @@
String endTime = DateUtils.dateToDateString(endDate, "yyyy-MM-dd");
String time = startTime + " - " + endTime;
//������������������
- Double AQINum = 0d;
Double PM25Num = 0d;
Double PM10Num = 0d;
Double SO2Num = 0d;
@@ -136,8 +274,7 @@
Double CONum = 0d;
Double O3Num = 0d;
Double TVOCNum = 0d;
- //������AQI,PM2.5,PM10,SO2,NO2,CO,O3,TVOC���������
- Double AQISum = 0d;
+ //������PM2.5,PM10,SO2,NO2,CO,O3,TVOC���������
Double PM25Sum = 0d;
Double PM10Sum = 0d;
Double SO2Sum = 0d;
@@ -183,18 +320,6 @@
TVOCSum = MathUtils.add(TVOCSum, Double.valueOf(TVOC.toString()));
TVOCNum++;
}
- //���AQI
- int aqi = AQIUtils.hourlyAqi(valueMap);
- if (aqi != 0) {
- AQISum += Double.valueOf(aqi);
- AQINum++;
- }
- }
- //������aqi������
- if (AQINum != 0d) {
- Double AQID = AmendUtils.sciCal(AQISum / AQINum, 0);
- int AQIAvg = new Double(AQID).intValue();
- dto.setAQI(AQIAvg);
}
//������PM2.5������
if (PM25Num != 0d) {
@@ -236,6 +361,16 @@
Double TVOCAvg = AmendUtils.sciCal(TVOCSum / TVOCNum, 2);
dto.setA99054(TVOCAvg);
}
+ //������AQI
+ Map<String,Object> sixParamMap = new HashMap<>();
+ sixParamMap.put("a05024",dto.getA05024());
+ sixParamMap.put("a21004",dto.getA21004());
+ sixParamMap.put("a21005",dto.getA21005());
+ sixParamMap.put("a34002",dto.getA34002());
+ sixParamMap.put("a34004",dto.getA34004());
+ sixParamMap.put("a21026",dto.getA21026());
+ AQI aqi = AQIUtils.dailyAQI(sixParamMap);
+ dto.setAQI(aqi.getAQIValue());
dto.setDeviceName(deviceName);
dto.setTime(time);
dtos.add(dto);
@@ -251,7 +386,7 @@
* @Author: ���������
* @Date: 2021/9/28
*/
- private <T> List<MonitorPointDataDisplayDTO> calculateReportData(Map<String, T> macDataMap, Map<String, Device> deviceMap, Date... date) {
+ private <T> List<MonitorPointDataDisplayDTO> calculateReportData(Map<String, T> macDataMap, Map<String, Device> deviceMap, String reportType, Date... date) {
List<MonitorPointDataDisplayDTO> dtos = new ArrayList<>();
macDataMap.forEach((key, valueObject) -> {
MonitorPointDataDisplayDTO dto = new MonitorPointDataDisplayDTO();
@@ -279,7 +414,7 @@
startTime = DateUtils.dateToDateString(date[0], "yyyy-MM");
dto.setTime(startTime);
//������������
- injectDataToDto(valueMap, false, dto);
+ injectDataToDto(valueMap, false, dto, reportType);
dtos.add(dto);
});
return dtos;
@@ -293,7 +428,7 @@
* @Author: ���������
* @Date: 2021/9/28
*/
- private void injectDataToDto(Map<String, Object> valueMap, boolean flag, MonitorPointDataDisplayDTO dto) {
+ private void injectDataToDto(Map<String, Object> valueMap, boolean flag, MonitorPointDataDisplayDTO dto, String reportType) {
//������CO
String COFlag = (String) valueMap.get("a21005-Flag");
Object COObject = valueMap.get("a21005");
@@ -344,9 +479,13 @@
dto.setA05024(new Double(AmendUtils.sciCal(O3, 0)).intValue());
}
//������AQI
- int aqi = AQIUtils.hourlyAqi(valueMap);
- if (aqi != 0)
- dto.setAQI(aqi);
+ Integer aqi;
+ if (reportType.equals(Constants.HOURLY_REPORT)) {
+ aqi = AQIUtils.hourlyAQI(valueMap).getAQIValue();
+ } else {
+ aqi = AQIUtils.dailyAQI(valueMap).getAQIValue();
+ }
+ dto.setAQI(aqi);
}
--
Gitblit v1.8.0