From 5236663d1e40ca9ed0cbc0885cbc67a67c47943f Mon Sep 17 00:00:00 2001 From: kaiyu <404897439@qq.com> Date: Mon, 14 Mar 2022 16:27:23 +0800 Subject: [PATCH] screen-api 增加获取简报接口 --- screen-api/src/main/java/com/moral/api/service/impl/DataDisplayServiceImpl.java | 100 ++++++++++++++++++++++++++++++++++--------------- 1 files changed, 69 insertions(+), 31 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 c22f67e..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 @@ -8,6 +8,7 @@ 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; @@ -76,21 +77,21 @@ 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.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.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.MONTHLY_REPORT)) { @@ -103,7 +104,7 @@ macDataDailyMap.put(mac, dailyDatas); }); if (macDataMonthlyMap.size() != 0) - dtos = calculateReportData(macDataMonthlyMap, deviceMap, startTime); + dtos = calculateReportData(macDataMonthlyMap, deviceMap, reportType, startTime); //������������������ injectComprehensiveIndex(dtos, macDataDailyMap); } @@ -136,8 +137,8 @@ time = time + " 0" + i; else time = time + " " + i; - if(timeValueMap.get(time)==null) - timeValueMap.put(time,null); + if (timeValueMap.get(time) == null) + timeValueMap.put(time, null); } } //������������������ @@ -158,11 +159,13 @@ time = time + "-0" + i; else time = time + "-" + i; - if(timeValueMap.get(time)==null) - timeValueMap.put(time,null); + 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) { @@ -171,7 +174,7 @@ dto.setSensorCode(sensor); timeValueMap.forEach((time, valueJson) -> { Map<String, Object> listMap = new HashMap<>(); - //������������������������������ + //��������������������������������������������� if (valueJson == null) { listMap.put("time", time); listMap.put("value", ""); @@ -180,7 +183,7 @@ } Map<String, Object> valueMap = JSON.parseObject(valueJson, Map.class); Object sensorValueObject = valueMap.get(sensor); - //������������������������������������������null + //��������������������������������������������� if (sensorValueObject == null) { listMap.put("time", time); listMap.put("value", ""); @@ -189,6 +192,7 @@ } //������������������������������������������ if (reportType.equals(Constants.DAILY_REPORT)) { + //���������������������N��������������� if (!Constants.NORMAL_FLAG.equals(valueMap.get(sensor + "-Flag"))) { listMap.put("time", time); listMap.put("value", ""); @@ -209,6 +213,40 @@ 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: ������������������������������ @@ -229,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; @@ -237,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; @@ -284,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) { @@ -337,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); @@ -352,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(); @@ -380,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; @@ -394,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"); @@ -445,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