From 21ce462f92abbaff092ce6adf49a3ee555bd0121 Mon Sep 17 00:00:00 2001
From: jinpengyong <jpy123456>
Date: Tue, 22 Mar 2022 13:08:50 +0800
Subject: [PATCH] city_aqi_monthly月数据增加6参和综指同比计算
---
screen-job/src/main/java/com/moral/api/service/impl/CityAqiMonthlyServiceImpl.java | 48 +++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 47 insertions(+), 1 deletions(-)
diff --git a/screen-job/src/main/java/com/moral/api/service/impl/CityAqiMonthlyServiceImpl.java b/screen-job/src/main/java/com/moral/api/service/impl/CityAqiMonthlyServiceImpl.java
index 1745e77..be90d19 100644
--- a/screen-job/src/main/java/com/moral/api/service/impl/CityAqiMonthlyServiceImpl.java
+++ b/screen-job/src/main/java/com/moral/api/service/impl/CityAqiMonthlyServiceImpl.java
@@ -96,6 +96,17 @@
Map<Integer, List<CityAqiMonthly>> lastMonthData = lastCityAqiMonthly.stream()
.collect(Collectors.groupingBy(CityAqiMonthly::getCityCode));
+
+ //������������������������
+ Date thisMonthOfLastYear = DateUtils.addYears(start, -1);
+ queryWrapper.clear();
+ queryWrapper.select("city_code", "value")
+ .eq("time", DateUtils.dateToDateString(thisMonthOfLastYear));
+ List<CityAqiMonthly> thisMonthOfLastYearList = cityAqiMonthlyMapper.selectList(queryWrapper);
+ Map<Integer, List<CityAqiMonthly>> thisMonthOfLastYearData = thisMonthOfLastYearList.stream()
+ .collect(Collectors.groupingBy(CityAqiMonthly::getCityCode));
+
+
List<CityAqiMonthly> cityAqiMonthlyList = new ArrayList<>();
Date finalStart = start;
@@ -145,7 +156,7 @@
Double compositeIndex = ComprehensiveIndexUtils.dailyData(jsonMap);
jsonMap.put("compositeIndex", compositeIndex);
- //���������������������������
+ //���������������������������(������������������)
List<CityAqiMonthly> cityAqiMonthlies = lastMonthData.get(Integer.parseInt(cityCode));
if (!ObjectUtils.isEmpty(cityAqiMonthlies)) {
CityAqiMonthly monthly = cityAqiMonthlies.get(0);
@@ -155,9 +166,44 @@
String format = decimalFormat.format((compositeIndex - lastCompositeIndex) / lastCompositeIndex);
jsonMap.put("monthContrast", format);
}
+
+ //���������������������������������������������
+ List<CityAqiMonthly> thisMonthOfLastYears = thisMonthOfLastYearData.get(Integer.parseInt(cityCode));
+
+ //���������������������
+ Map<String, Object> yearOnYearValue = yearOnYearOfSensor(thisMonthOfLastYears, jsonMap);
+ if (yearOnYearValue != null) {
+ jsonMap.putAll(yearOnYearValue);
+ }
+
cityAqiMonthly.setValue(JSONObject.toJSONString(jsonMap));
cityAqiMonthlyList.add(cityAqiMonthly);
});
cityAqiMonthlyMapper.insertCityAqiMonthly(cityAqiMonthlyList);
}
+
+ /**
+ * @param thisMonthOfLastYearData ������������������
+ * @param currentData ������������������
+ */
+ private Map<String, Object> yearOnYearOfSensor(List<CityAqiMonthly> thisMonthOfLastYearData, Map<String, Object> currentData) {
+ Map<String, Object> result = null;
+ //���������������������������
+ List<String> sensors = Arrays.asList("PM2_5", "PM10", "SO2", "NO2", "CO", "O3", "compositeIndex");
+ if (!ObjectUtils.isEmpty(thisMonthOfLastYearData)) {
+ result = new HashMap<>();
+ CityAqiMonthly monthly = thisMonthOfLastYearData.get(0);
+ Map<String, Object> map = JSONObject.parseObject(monthly.getValue(), Map.class);
+ for (String sensor : sensors) {
+ //������������������������
+ double thisMonthOfLeastYearValue = Double.parseDouble(map.get(sensor).toString());
+ //������������������
+ double currentValue = Double.parseDouble(currentData.get(sensor).toString());
+ DecimalFormat decimalFormat = new DecimalFormat("0.00%");
+ String format = decimalFormat.format((currentValue - thisMonthOfLeastYearValue) / thisMonthOfLeastYearValue);
+ result.put(sensor + "_yearOnYear", format);
+ }
+ }
+ return result;
+ }
}
--
Gitblit v1.8.0