From 645f627a559585048032d1972f903f9b33918c26 Mon Sep 17 00:00:00 2001
From: jinpengyong <jpy123456>
Date: Mon, 08 Nov 2021 15:12:00 +0800
Subject: [PATCH] 空气质量排名详情接口
---
screen-api/src/main/java/com/moral/api/service/impl/CityAqiServiceImpl.java | 532 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 530 insertions(+), 2 deletions(-)
diff --git a/screen-api/src/main/java/com/moral/api/service/impl/CityAqiServiceImpl.java b/screen-api/src/main/java/com/moral/api/service/impl/CityAqiServiceImpl.java
index 357a1df..ac464a6 100644
--- a/screen-api/src/main/java/com/moral/api/service/impl/CityAqiServiceImpl.java
+++ b/screen-api/src/main/java/com/moral/api/service/impl/CityAqiServiceImpl.java
@@ -5,14 +5,18 @@
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.moral.api.entity.CityAqi;
import com.moral.api.entity.CityAqiDaily;
+import com.moral.api.entity.CityAqiMonthly;
+import com.moral.api.entity.CityAqiYearly;
import com.moral.api.entity.Forecast;
import com.moral.api.entity.Organization;
import com.moral.api.entity.SysArea;
import com.moral.api.mapper.CityAqiMapper;
import com.moral.api.mapper.ForecastMapper;
import com.moral.api.service.CityAqiDailyService;
+import com.moral.api.service.CityAqiMonthlyService;
import com.moral.api.service.CityAqiService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.moral.api.service.CityAqiYearlyService;
import com.moral.api.service.OrganizationService;
import com.moral.api.service.SysAreaService;
import com.moral.constant.Constants;
@@ -20,6 +24,7 @@
import com.moral.pojo.AQI;
import com.moral.util.AQIUtils;
import com.moral.util.AmendUtils;
+import com.moral.util.ComprehensiveIndexUtils;
import com.moral.util.DateUtils;
import com.moral.util.MathUtils;
@@ -29,7 +34,9 @@
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
+import java.text.DecimalFormat;
import java.util.*;
+import java.util.stream.Collectors;
import java.util.stream.DoubleStream;
/**
@@ -60,6 +67,12 @@
@Autowired
private CityAqiDailyService cityAqiDailyService;
+
+ @Autowired
+ private CityAqiMonthlyService cityAqiMonthlyService;
+
+ @Autowired
+ private CityAqiYearlyService cityAqiYearlyService;
@Override
public List<Map<String, Object>> measuredCompareForecastOfO3(Map<String, Object> params) {
@@ -198,12 +211,526 @@
//������������aqi������������������
Map<String, Object> result = new HashMap<>();
AQI aqi = AQIUtils.hourlyAQI(sixParamAvg);
- result.put("aqi",aqi.getAQIValue());
- result.put("pollutant",aqi.getPrimaryPollutantNames());
+ result.put("aqi", aqi.getAQIValue());
+ result.put("pollutant", aqi.getPrimaryPollutantNames());
//���������������������
CityAqi lastCityAqi = cityAqis.get(cityAqis.size() - 1);
String time = DateUtils.dateToDateString(lastCityAqi.getTime(), "HH:mm");
result.put("time", time);
+ return result;
+ }
+
+ @Override
+ public List<Map<String, Object>> rankingDetails(Map<String, Object> params) {
+ List<Map<String, Object>> result = new ArrayList<>();
+ int orgId = Integer.parseInt(params.get("organizationId").toString());
+ String type = params.get("type").toString();
+ String time = null;
+ if (!ObjectUtils.isEmpty(params.get("time"))) {
+ time = params.get("time").toString();
+ }
+ String start = null;
+ String end = null;
+ if (!ObjectUtils.isEmpty(params.get("start")) || !ObjectUtils.isEmpty(params.get("end"))) {
+ start = params.get("start").toString();
+ end = params.get("end").toString();
+ }
+ String cityType = params.get("cityType").toString();
+
+ //���������,���code
+ Organization organization = organizationService.getById(orgId);
+ Integer curProvinceCode = organization.getProvinceCode();
+ Integer curCityCode = organization.getCityCode();
+
+ QueryWrapper<SysArea> areaWrapper = new QueryWrapper<>();
+ if ("province".equals(cityType)) {
+ //���������������������
+ areaWrapper.select("area_code").eq("parent_code", curProvinceCode);
+ } else {
+ //������������������������
+ areaWrapper.select("area_code").eq("parent_code", curCityCode);
+ }
+ List<Object> regionCodes = sysAreaService.listObjs(areaWrapper);
+
+ switch (type) {
+ case "today":
+ result = accumulatedTodayRank(regionCodes);
+ break;
+ case "hour":
+ time = new StringBuilder(time).replace(10, 11, " ").toString() + ":00:00";
+ result = hourRank(regionCodes, time);
+ break;
+ case "day":
+ time = time + " 00:00:00";
+ result = dayRank(regionCodes, time);
+ break;
+ case "month":
+ time = time + "-01 00:00:00";
+ result = monthRank(regionCodes, time);
+ break;
+ case "year":
+ time = time + "-01-01 00:00:00";
+ result = yearRank(regionCodes, time);
+ break;
+ case "custom":
+ start = start + " 00:00:00";
+ end = end + " :00:00";
+ result = customRank(regionCodes, start, end);
+ break;
+ default:
+ break;
+ }
+ return result;
+ }
+
+ /**
+ * @param regionCodes ���������������������������������������
+ * @return ���������������������������
+ */
+ private List<Map<String, Object>> accumulatedTodayRank(List<Object> regionCodes) {
+ List<Map<String, Object>> result = new ArrayList<>();
+ List<String> sensors = Arrays.asList("PM2_5", "PM10", "SO2", "NO2", "CO", "O3");
+ Date now = new Date();
+ String today = DateUtils.dateToDateString(now, DateUtils.yyyy_MM_dd_EN);
+ QueryWrapper<CityAqi> wrapper = new QueryWrapper<>();
+ wrapper.select("city_code", "value")
+ .ge("time", today)
+ .in("city_code", regionCodes);
+ List<Map<String, Object>> cumulativeData = cityAqiMapper.selectMaps(wrapper);
+ //���city_code������
+ Map<String, List<Map<String, Object>>> data = cumulativeData.parallelStream().collect(Collectors.groupingBy(o -> o.get("city_code").toString()));
+ data.forEach((cityCode, value) -> {
+ List<Double> doubles = new ArrayList<>();
+ for (Map<String, Object> objectMap : value) {
+ Object o = JSONObject.parseObject((String) objectMap.get("value"), Map.class).get("O3_8H");
+ if (!ObjectUtils.isEmpty(o)) {
+ double v = Double.parseDouble(o.toString());
+ doubles.add(v);
+ }
+ }
+
+ Map<String, Object> dataMap = new HashMap<>();
+ sensors.forEach(sensor -> {
+ OptionalDouble optionalDouble = value.parallelStream().flatMapToDouble(v -> {
+ Map<String, Object> sensorValue = JSONObject.parseObject((String) v.get("value"), Map.class);
+ Object o = sensorValue.get(sensor);
+ if (ObjectUtils.isEmpty(o)) {
+ return null;
+ }
+ double aDouble = Double.parseDouble(o.toString());
+ return DoubleStream.of(aDouble);
+ }).average();
+
+ if (optionalDouble.isPresent()) {
+ //���������������������
+ double sciCal = AmendUtils.sciCal(optionalDouble.getAsDouble(), 0);
+ if ("CO".equals(sensor)) {
+ sciCal = AmendUtils.sciCal(optionalDouble.getAsDouble(), 1);
+ }
+ dataMap.put(sensor, sciCal);
+ }
+ });
+
+ //������������O3_8H������,������������O3������8H���������
+ if (!ObjectUtils.isEmpty(doubles)) {
+ dataMap.put("O3_8H", Collections.max(doubles));
+ }
+
+ //������������aqi,���������������������
+ Map<String, Object> sixParamMap = new HashMap<>();
+ sixParamMap.put(Constants.SENSOR_CODE_PM25, dataMap.get("PM2_5"));
+ sixParamMap.put(Constants.SENSOR_CODE_PM10, dataMap.get("PM10"));
+ sixParamMap.put(Constants.SENSOR_CODE_SO2, dataMap.get("SO2"));
+ sixParamMap.put(Constants.SENSOR_CODE_NO2, dataMap.get("NO2"));
+ sixParamMap.put(Constants.SENSOR_CODE_CO, dataMap.get("CO"));
+ sixParamMap.put(Constants.SENSOR_CODE_O3, dataMap.get("O3"));
+ AQI aqi = AQIUtils.dailyAQI(sixParamMap);
+ dataMap.put("AQI", aqi.getAQIValue());
+ dataMap.put("primaryPollutant", aqi.getPrimaryPollutantNames());
+
+ //������������������������������,O3������������O3_8H������
+ Map<String, Object> compositeIndexMap = new HashMap<>(dataMap);
+ compositeIndexMap.put("O3", compositeIndexMap.get("O3_8H"));
+ Double compositeIndex = ComprehensiveIndexUtils.dailyData(compositeIndexMap);
+ dataMap.put("compositeIndex", compositeIndex);
+
+ //���������
+ QueryWrapper<SysArea> queryWrapper = new QueryWrapper<>();
+ queryWrapper.select("area_name").eq("area_code", cityCode);
+ String areaName = sysAreaService.getOne(queryWrapper).getAreaName();
+ dataMap.put("cityName", areaName);
+
+ result.add(dataMap);
+ });
+ return result;
+ }
+
+ /**
+ * @param regionCodes ���������������������������������
+ * @param time ��������������������������� 2021-11-04 13:00:00
+ * @return ���������������������
+ */
+ private List<Map<String, Object>> hourRank(List<Object> regionCodes, String time) {
+ List<Map<String, Object>> result = new ArrayList<>();
+ QueryWrapper<CityAqi> wrapper = new QueryWrapper<>();
+ wrapper.select("value")
+ .eq("time", time)
+ .in("city_code", regionCodes);
+ List<Map<String, Object>> hourData = cityAqiMapper.selectMaps(wrapper);
+ for (Map<String, Object> hourDatum : hourData) {
+ Map<String, Object> value = JSONObject.parseObject((String) hourDatum.get("value"), Map.class);
+ value.remove("pubtime");
+ value.remove("rank");
+ result.add(value);
+ }
+ return result;
+ }
+
+ /**
+ * @param regionCodes ���������������������������������
+ * @param time ��������������������������� 2021-11-04 00:00:00
+ * @return ������������������
+ */
+ private List<Map<String, Object>> dayRank(List<Object> regionCodes, String time) {
+ List<Map<String, Object>> result = new ArrayList<>();
+ QueryWrapper<CityAqiDaily> wrapper = new QueryWrapper<>();
+ wrapper.select("city_code", "value")
+ .eq("time", time)
+ .in("city_code", regionCodes);
+ List<Map<String, Object>> dayData = cityAqiDailyService.listMaps(wrapper);
+ for (Map<String, Object> dayDatum : dayData) {
+ Map<String, Object> value = JSONObject.parseObject((String) dayDatum.get("value"), Map.class);
+ //���������
+ QueryWrapper<SysArea> queryWrapper = new QueryWrapper<>();
+ queryWrapper.select("area_name")
+ .eq("area_code", dayDatum.get("city_code"));
+ String areaName = sysAreaService.getOne(queryWrapper).getAreaName();
+ value.put("cityName", areaName);
+ result.add(value);
+ }
+ return result;
+ }
+
+ /**
+ * @param regionCodes ���������������������������������
+ * @param time ��������������������������� 2021-11-01 00:00:00 ������1���
+ * @return ������������������
+ */
+ private List<Map<String, Object>> monthRank(List<Object> regionCodes, String time) {
+ //���������������������������
+ List<String> sensors = Arrays.asList("PM2_5", "PM10", "SO2", "NO2");
+ List<Map<String, Object>> result = new ArrayList<>();
+ //���������������,������������������������������city_aqi_monthly������
+ if (!time.substring(0, 7).equals(DateUtils.dateToDateString(new Date(), DateUtils.yyyy_MM_EN))) {
+ QueryWrapper<CityAqiMonthly> cityAqiMonthlyQueryWrapper = new QueryWrapper<>();
+ for (Object regionCode : regionCodes) {
+ cityAqiMonthlyQueryWrapper.clear();
+ cityAqiMonthlyQueryWrapper.select("value")
+ .eq("city_code", regionCode)
+ .eq("time", time);
+ CityAqiMonthly cityAqiMonthly = cityAqiMonthlyService.getOne(cityAqiMonthlyQueryWrapper);
+ if (cityAqiMonthly == null) {
+ continue;
+ }
+ String value = cityAqiMonthly.getValue();
+ Map<String, Object> resultMap = JSONObject.parseObject(value, Map.class);
+ //���������
+ QueryWrapper<SysArea> sysAreaQueryWrapper = new QueryWrapper<>();
+ sysAreaQueryWrapper.select("area_name")
+ .eq("area_code", regionCode);
+ String areaName = sysAreaService.getOne(sysAreaQueryWrapper).getAreaName();
+ resultMap.put("cityName", areaName);
+ result.add(resultMap);
+ }
+ return result;
+ }
+
+ QueryWrapper<CityAqiDaily> cityAqiDailyQueryWrapper = new QueryWrapper<>();
+ cityAqiDailyQueryWrapper.select("city_code", "value")
+ .ge("time", time)
+ .in("city_code", regionCodes);
+ List<Map<String, Object>> thisMonthData = cityAqiDailyService.listMaps(cityAqiDailyQueryWrapper);
+ //���city_code������
+ Map<String, List<Map<String, Object>>> thisMonthMap = thisMonthData.parallelStream().collect(Collectors.groupingBy(o -> o.get("city_code").toString()));
+ thisMonthMap.forEach((cityCode, value) -> {
+ Map<String, Object> resultMap = new HashMap<>();
+
+ Map<String, Object> params = new HashMap<>();
+ List<Map<String, Object>> temp = new ArrayList<>();
+ for (Map<String, Object> map : value) {
+ Map<String, Object> sensorsValue = JSONObject.parseObject(map.get("value").toString(), Map.class);
+ Map<String, Object> tempMap = new HashMap<>();
+ tempMap.put(Constants.SENSOR_CODE_CO, sensorsValue.get("CO"));
+ tempMap.put(Constants.SENSOR_CODE_O3, sensorsValue.get("O3"));
+ Map<String, Object> hashMap = new HashMap<>();
+ hashMap.put("value", JSONObject.toJSONString(tempMap));
+ temp.add(hashMap);
+ }
+ params.put("data", temp);
+ //1. CO 95������������������������
+ Map<String, Object> coAvgOfWeekOrMonth = AmendUtils.getCOAvgOfWeekOrMonth(params);
+ if (!ObjectUtils.isEmpty(coAvgOfWeekOrMonth)) {
+ resultMap.put("CO", coAvgOfWeekOrMonth.get(Constants.SENSOR_CODE_CO));
+ }
+
+ //2. O3 90������������������������
+ Map<String, Object> o3AvgOfWeekOrMonth = AmendUtils.getO3AvgOfWeekOrMonth(params);
+ if (!ObjectUtils.isEmpty(o3AvgOfWeekOrMonth)) {
+ resultMap.put("O3", o3AvgOfWeekOrMonth.get(Constants.SENSOR_CODE_O3));
+ }
+
+ sensors.forEach(sensor -> {
+ OptionalDouble optionalDouble = value.parallelStream().flatMapToDouble(v -> {
+ Map<String, Object> sensorValue = JSONObject.parseObject((String) v.get("value"), Map.class);
+ Object o = sensorValue.get(sensor);
+ if (ObjectUtils.isEmpty(o)) {
+ return null;
+ }
+ double aDouble = Double.parseDouble(o.toString());
+ return DoubleStream.of(aDouble);
+ }).average();
+
+ if (optionalDouble.isPresent()) {
+ //���������������������
+ double sciCal = AmendUtils.sciCal(optionalDouble.getAsDouble(), 0);
+ resultMap.put(sensor, sciCal);
+ }
+ });
+
+ //������������������
+ Double compositeIndex = ComprehensiveIndexUtils.dailyData(resultMap);
+ resultMap.put("compositeIndex", compositeIndex);
+
+ //������O3���O3_8H������
+ resultMap.put("O3_8H", resultMap.remove("O3"));
+
+ //���������������������������
+ Date lastMonth = DateUtils.addMonths(DateUtils.getDate(time), -1);
+ QueryWrapper<CityAqiMonthly> queryWrapper = new QueryWrapper<>();
+ queryWrapper.select("value")
+ .eq("city_code", cityCode)
+ .eq("time", DateUtils.dateToDateString(lastMonth));
+ //������������������
+ CityAqiMonthly lastCityAqiMonthly = cityAqiMonthlyService.getOne(queryWrapper);
+ String monthContrast = "";
+ if (lastCityAqiMonthly != null) {
+ Map<String, Object> map = JSONObject.parseObject(lastCityAqiMonthly.getValue(), Map.class);
+ double lastCompositeIndex = Double.parseDouble(map.get("compositeIndex").toString());
+ DecimalFormat decimalFormat = new DecimalFormat("0.00%");
+ monthContrast = decimalFormat.format((compositeIndex - lastCompositeIndex) / lastCompositeIndex);
+ }
+ resultMap.put("monthContrast", monthContrast);
+
+ //���������
+ QueryWrapper<SysArea> sysAreaQueryWrapper = new QueryWrapper<>();
+ sysAreaQueryWrapper.select("area_name")
+ .eq("area_code", cityCode);
+ String areaName = sysAreaService.getOne(sysAreaQueryWrapper).getAreaName();
+ resultMap.put("cityName", areaName);
+
+ result.add(resultMap);
+ });
+ return result;
+ }
+
+ /**
+ * @param regionCodes ���������������������������������
+ * @param time ��������������������������� 2021-11-01 00:00:00 ������1���1���
+ * @return ������������������
+ */
+ private List<Map<String, Object>> yearRank(List<Object> regionCodes, String time) {
+ //���������������������������
+ List<String> sensors = Arrays.asList("PM2_5", "PM10", "SO2", "NO2");
+ List<Map<String, Object>> result = new ArrayList<>();
+ //���������������,������������������������������city_aqi_monthly������
+ if (!time.substring(0, 4).equals(DateUtils.dateToDateString(new Date(), DateUtils.yyyy))) {
+ QueryWrapper<CityAqiYearly> cityAqiYearlyQueryWrapper = new QueryWrapper<>();
+ for (Object regionCode : regionCodes) {
+ cityAqiYearlyQueryWrapper.clear();
+ cityAqiYearlyQueryWrapper.select("value")
+ .eq("city_code", regionCode)
+ .eq("time", time);
+ CityAqiYearly cityAqiYearly = cityAqiYearlyService.getOne(cityAqiYearlyQueryWrapper);
+ if (cityAqiYearly == null) {
+ continue;
+ }
+ String value = cityAqiYearly.getValue();
+ Map<String, Object> resultMap = JSONObject.parseObject(value, Map.class);
+ //���������
+ QueryWrapper<SysArea> sysAreaQueryWrapper = new QueryWrapper<>();
+ sysAreaQueryWrapper.select("area_name")
+ .eq("area_code", regionCode);
+ String areaName = sysAreaService.getOne(sysAreaQueryWrapper).getAreaName();
+ resultMap.put("cityName", areaName);
+ result.add(resultMap);
+ }
+ return result;
+ }
+
+ QueryWrapper<CityAqiDaily> cityAqiDailyQueryWrapper = new QueryWrapper<>();
+ cityAqiDailyQueryWrapper.select("city_code", "value")
+ .ge("time", time)
+ .in("city_code", regionCodes);
+ List<Map<String, Object>> thisMonthData = cityAqiDailyService.listMaps(cityAqiDailyQueryWrapper);
+ //���city_code������
+ Map<String, List<Map<String, Object>>> thisYearMap = thisMonthData.parallelStream().collect(Collectors.groupingBy(o -> o.get("city_code").toString()));
+ thisYearMap.forEach((cityCode, value) -> {
+ Map<String, Object> resultMap = new HashMap<>();
+
+ Map<String, Object> params = new HashMap<>();
+ List<Map<String, Object>> temp = new ArrayList<>();
+ for (Map<String, Object> map : value) {
+ Map<String, Object> sensorsValue = JSONObject.parseObject(map.get("value").toString(), Map.class);
+ Map<String, Object> tempMap = new HashMap<>();
+ tempMap.put(Constants.SENSOR_CODE_CO, sensorsValue.get("CO"));
+ tempMap.put(Constants.SENSOR_CODE_O3, sensorsValue.get("O3"));
+ Map<String, Object> hashMap = new HashMap<>();
+ hashMap.put("value", JSONObject.toJSONString(tempMap));
+ temp.add(hashMap);
+ }
+ params.put("data", temp);
+ //1. CO 95������������������������
+ Map<String, Object> coAvgOfWeekOrMonth = AmendUtils.getCOAvgOfWeekOrMonth(params);
+ if (!ObjectUtils.isEmpty(coAvgOfWeekOrMonth)) {
+ resultMap.put("CO", coAvgOfWeekOrMonth.get(Constants.SENSOR_CODE_CO));
+ }
+
+ //2. O3 90������������������������
+ Map<String, Object> o3AvgOfWeekOrMonth = AmendUtils.getO3AvgOfWeekOrMonth(params);
+ if (!ObjectUtils.isEmpty(o3AvgOfWeekOrMonth)) {
+ resultMap.put("O3", o3AvgOfWeekOrMonth.get(Constants.SENSOR_CODE_O3));
+ }
+
+ sensors.forEach(sensor -> {
+ OptionalDouble optionalDouble = value.parallelStream().flatMapToDouble(v -> {
+ Map<String, Object> sensorValue = JSONObject.parseObject((String) v.get("value"), Map.class);
+ Object o = sensorValue.get(sensor);
+ if (ObjectUtils.isEmpty(o)) {
+ return null;
+ }
+ double aDouble = Double.parseDouble(o.toString());
+ return DoubleStream.of(aDouble);
+ }).average();
+
+ if (optionalDouble.isPresent()) {
+ //���������������������
+ double sciCal = AmendUtils.sciCal(optionalDouble.getAsDouble(), 0);
+ resultMap.put(sensor, sciCal);
+ }
+ });
+
+ //������������������
+ Double compositeIndex = ComprehensiveIndexUtils.dailyData(resultMap);
+ resultMap.put("compositeIndex", compositeIndex);
+
+ //������O3���O3_8H������
+ resultMap.put("O3_8H", resultMap.remove("O3"));
+
+ //���������������������������
+ String lastYear = DateUtils.getDateAddYear(time.substring(0, 4), -1);
+ QueryWrapper<CityAqiYearly> queryWrapper = new QueryWrapper<>();
+ queryWrapper.select("value")
+ .eq("city_code", cityCode)
+ .eq("time", lastYear);
+ //������������������
+ CityAqiYearly lastCityAqiYearly = cityAqiYearlyService.getOne(queryWrapper);
+ String yearContrast = "";
+ if (lastCityAqiYearly != null) {
+ Map<String, Object> map = JSONObject.parseObject(lastCityAqiYearly.getValue(), Map.class);
+ double lastCompositeIndex = Double.parseDouble(map.get("compositeIndex").toString());
+ DecimalFormat decimalFormat = new DecimalFormat("0.00%");
+ yearContrast = decimalFormat.format((compositeIndex - lastCompositeIndex) / lastCompositeIndex);
+ }
+ resultMap.put("yearContrast", yearContrast);
+ //���������
+ QueryWrapper<SysArea> sysAreaQueryWrapper = new QueryWrapper<>();
+ sysAreaQueryWrapper.select("area_name").eq("area_code", cityCode);
+ String areaName = sysAreaService.getOne(sysAreaQueryWrapper).getAreaName();
+ resultMap.put("cityName", areaName);
+
+ result.add(resultMap);
+ });
+ return result;
+ }
+
+ /**
+ * @param regionCodes ���������������������������������
+ * @param start ���������������������������������,���������������2021-11-03 00:00:00
+ * @param end ���������������������������������,���������������2021-11-25 00:00:00
+ * @return ������������������������
+ */
+ private List<Map<String, Object>> customRank(List<Object> regionCodes, String start, String end) {
+ //���������������������������
+ List<String> sensors = Arrays.asList("PM2_5", "PM10", "SO2", "NO2");
+ List<Map<String, Object>> result = new ArrayList<>();
+ QueryWrapper<CityAqiDaily> cityAqiDailyQueryWrapper = new QueryWrapper<>();
+ cityAqiDailyQueryWrapper.select("city_code", "value")
+ .ge("time", start)
+ .le("time", end)
+ .in("city_code", regionCodes);
+ List<Map<String, Object>> thisMonthData = cityAqiDailyService.listMaps(cityAqiDailyQueryWrapper);
+ //���city_code������
+ Map<String, List<Map<String, Object>>> customMap = thisMonthData.parallelStream().collect(Collectors.groupingBy(o -> o.get("city_code").toString()));
+ customMap.forEach((cityCode, value) -> {
+ Map<String, Object> resultMap = new HashMap<>();
+
+ Map<String, Object> params = new HashMap<>();
+ List<Map<String, Object>> temp = new ArrayList<>();
+ for (Map<String, Object> map : value) {
+ Map<String, Object> sensorsValue = JSONObject.parseObject(map.get("value").toString(), Map.class);
+ Map<String, Object> tempMap = new HashMap<>();
+ tempMap.put(Constants.SENSOR_CODE_CO, sensorsValue.get("CO"));
+ tempMap.put(Constants.SENSOR_CODE_O3, sensorsValue.get("O3"));
+ Map<String, Object> hashMap = new HashMap<>();
+ hashMap.put("value", JSONObject.toJSONString(tempMap));
+ temp.add(hashMap);
+ }
+ params.put("data", temp);
+ //1. CO 95������������������������
+ Map<String, Object> coAvgOfWeekOrMonth = AmendUtils.getCOAvgOfWeekOrMonth(params);
+ if (!ObjectUtils.isEmpty(coAvgOfWeekOrMonth)) {
+ resultMap.put("CO", coAvgOfWeekOrMonth.get(Constants.SENSOR_CODE_CO));
+ }
+
+ //2. O3 90������������������������
+ Map<String, Object> o3AvgOfWeekOrMonth = AmendUtils.getO3AvgOfWeekOrMonth(params);
+ if (!ObjectUtils.isEmpty(o3AvgOfWeekOrMonth)) {
+ resultMap.put("O3", o3AvgOfWeekOrMonth.get(Constants.SENSOR_CODE_O3));
+ }
+
+ sensors.forEach(sensor -> {
+ OptionalDouble optionalDouble = value.parallelStream().flatMapToDouble(v -> {
+ Map<String, Object> sensorValue = JSONObject.parseObject((String) v.get("value"), Map.class);
+ Object o = sensorValue.get(sensor);
+ if (ObjectUtils.isEmpty(o)) {
+ return null;
+ }
+ double aDouble = Double.parseDouble(o.toString());
+ return DoubleStream.of(aDouble);
+ }).average();
+
+ if (optionalDouble.isPresent()) {
+ //���������������������
+ double sciCal = AmendUtils.sciCal(optionalDouble.getAsDouble(), 0);
+ resultMap.put(sensor, sciCal);
+ }
+ });
+
+ //���������������������
+ Double compositeIndex = ComprehensiveIndexUtils.dailyData(resultMap);
+ resultMap.put("compositeIndex", compositeIndex);
+
+ //������O3���O3_8H������
+ resultMap.put("O3_8H", resultMap.remove("O3"));
+
+ //���������
+ QueryWrapper<SysArea> sysAreaQueryWrapper = new QueryWrapper<>();
+ sysAreaQueryWrapper.select("area_name").eq("area_code", cityCode);
+ String areaName = sysAreaService.getOne(sysAreaQueryWrapper).getAreaName();
+ resultMap.put("cityName", areaName);
+
+ result.add(resultMap);
+ });
return result;
}
@@ -423,4 +950,5 @@
return result;
}
+
}
--
Gitblit v1.8.0