From 009c553b99fa6a6b7aeaa6a6115ab1c6a90669d2 Mon Sep 17 00:00:00 2001
From: lizijie <lzjiiie@163.com>
Date: Tue, 15 Mar 2022 14:52:37 +0800
Subject: [PATCH] 修改环比数据接口数据格式
---
screen-api/src/main/java/com/moral/api/service/impl/CityAqiServiceImpl.java | 568 +++++++++++++++++++++++++++++++++++++++++++++++++------
1 files changed, 499 insertions(+), 69 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 a6653e5..6676552 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
@@ -3,23 +3,18 @@
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.moral.api.config.properties.SpecialCitiesProperties;
-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.entity.*;
import com.moral.api.mapper.CityAqiMapper;
+import com.moral.api.mapper.DeviceMapper;
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.moral.api.pojo.dto.cityAQI.CityPollutionLevel;
+import com.moral.api.pojo.dto.cityAQI.ConcentrationAndPercent;
+import com.moral.api.pojo.form.aqi.AirQualityComparisonForm;
+import com.moral.api.pojo.vo.cityAQI.AirQualityComparisonVO;
+import com.moral.api.service.*;
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;
import com.moral.constant.RedisConstants;
import com.moral.pojo.AQI;
@@ -36,6 +31,7 @@
import org.springframework.util.ObjectUtils;
import java.text.DecimalFormat;
+import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.DoubleStream;
@@ -74,6 +70,18 @@
@Autowired
private SpecialCitiesProperties specialCitiesProperties;
+
+ @Autowired
+ private CityWeatherService cityWeatherService;
+
+ @Autowired
+ private OrganizationService organizationService;
+
+ @Autowired
+ private DeviceMapper deviceMapper;
+
+ @Autowired
+ private HistoryHourlyService historyHourlyService;
@Override
public List<Map<String, Object>> measuredCompareForecastOfO3(Map<String, Object> params) {
@@ -269,10 +277,10 @@
} else {
if ("province".equals(cityType)) {
//���������������������
- areaWrapper.select("area_code").eq("parent_code", curProvinceCode);
+ areaWrapper.select("area_code", "area_name").eq("parent_code", curProvinceCode);
} else {
//������������������������
- areaWrapper.select("area_code").eq("parent_code", curCityCode);
+ areaWrapper.select("area_code", "area_name").eq("parent_code", curCityCode);
}
sysAreas = sysAreaService.list(areaWrapper);
}
@@ -817,64 +825,11 @@
return result;
}
- /**
- * @Description: ������6������������
- * @Param: [cityAqiList]
- * @return: java.util.Map<java.lang.String, java.lang.Double>
- * ���������key���sensorCode,value������
- * @Author: ���������
- * @Date: 2021/11/2
- */
- private Map<String, Object> calculate6ParamAvg(List<CityAqi> cityAqiList) {
- Double co = calculateSensorAvg(cityAqiList, "CO");
- Double pm2_5 = calculateSensorAvg(cityAqiList, "PM2_5");
- Double pm10 = calculateSensorAvg(cityAqiList, "PM10");
- Double so2 = calculateSensorAvg(cityAqiList, "SO2");
- Double no2 = calculateSensorAvg(cityAqiList, "NO2");
- Double o3 = calculateSensorAvg(cityAqiList, "O3");
- Map<String, Object> result = new HashMap<>();
- result.put(Constants.SENSOR_CODE_CO, co);
- result.put(Constants.SENSOR_CODE_NO2, no2);
- result.put(Constants.SENSOR_CODE_SO2, so2);
- result.put(Constants.SENSOR_CODE_O3, o3);
- result.put(Constants.SENSOR_CODE_PM25, pm2_5);
- result.put(Constants.SENSOR_CODE_PM10, pm10);
- return result;
- }
-
- /**
- * @Description: ������������������������
- * @Param: [cityAqiList, sensor]
- * ���sensor���������������������������
- * @return: java.lang.Double
- * @Author: ���������
- * @Date: 2021/11/2
- */
- private Double calculateSensorAvg(List<CityAqi> cityAqiList, String sensor) {
- Double sum = 0d;
- int num = 0;
- for (CityAqi cityAqi : cityAqiList) {
- String value = cityAqi.getValue();
- if (value == null)
- continue;
- Map<String, Object> valueMap = JSON.parseObject(value, Map.class);
- Object sensorValueObject = valueMap.get(sensor);
- if (sensorValueObject == null)
- continue;
- Double sensorValue = Double.valueOf(sensorValueObject.toString());
- sum = MathUtils.add(sum, sensorValue);
- num++;
- }
- if (num == 0)
- return null;
- Double avg = MathUtils.division(sum, num, 2);
- return avg;
- }
/**
* @Description: ������������������������
* @Param: [regionCode]
- * @return: java.util.Map<java.lang.String, java.lang.Object>
+ * @return: java.util.Map<java.lang.String , java.lang.Object>
* @Author: ���������
* @Date: 2021/10/28
*/
@@ -1000,6 +955,396 @@
return result;
}
+ @Override
+ public List<AirQualityComparisonVO> queryAirQualityComparison(AirQualityComparisonForm form) {
+ //������
+ Integer regionCode = form.getRegionCode();
+ String regionType = form.getRegionType();
+ Date startDate = form.getStartDate();
+ Date endDate = form.getEndDate();
+ Date comparisonStartDate = form.getComparisonStartDate();
+ Date comparisonEndDate = form.getComparisonEndDate();
+ String dateType = form.getDateType();
+ //������������/������
+ List<SysArea> areas = getSysAreasByRegionType(regionType, regionCode);
+ if (ObjectUtils.isEmpty(areas))
+ return null;
+ List<AirQualityComparisonVO> vos = new ArrayList<>();
+ for (SysArea area : areas) {
+ //������������������������������������6������������������
+ Map<String, Object> data = getDataByTimeTypeAndRegionCode(dateType, startDate, endDate, area.getAreaCode());
+ Map<String, Object> comparisonData = getDataByTimeTypeAndRegionCode(dateType, comparisonStartDate, comparisonEndDate, area.getAreaCode());
+ if (ObjectUtils.isEmpty(data) || ObjectUtils.isEmpty(comparisonData))
+ continue;
+ //���������������������������������������
+ CityPollutionLevel days = cityAqiDailyService.calculateDaysByTimeAndSysArea(area, startDate, endDate);
+ CityPollutionLevel comparisonDays = cityAqiDailyService.calculateDaysByTimeAndSysArea(area, comparisonStartDate, comparisonEndDate);
+ int fineDays = days.getExcellentWeatherDays() + days.getGoodWeatherDays();
+ int serverDays = days.getSeriousWeatherDays() + days.getServerWeatherDays();
+ int comparisonFineDays = comparisonDays.getExcellentWeatherDays() + comparisonDays.getGoodWeatherDays();
+ int comparisonServerDays = comparisonDays.getSeriousWeatherDays() + comparisonDays.getServerWeatherDays();
+ //������6������������������
+ Map<String, ConcentrationAndPercent> sixParamAndComIndexResult = contrastSixParamAndComIndex(data, comparisonData);
+ //������������������������������������������
+ ConcentrationAndPercent fine = contrastDays(fineDays, comparisonFineDays);
+ ConcentrationAndPercent server = contrastDays(serverDays, comparisonServerDays);
+ //������������������
+ AirQualityComparisonVO vo = new AirQualityComparisonVO();
+ vo.setFineDays(fine);
+ vo.setServerDays(server);
+ vo.setCO(sixParamAndComIndexResult.get("CO"));
+ vo.setO3(sixParamAndComIndexResult.get("O3"));
+ vo.setPM25(sixParamAndComIndexResult.get("PM2_5"));
+ vo.setPM10(sixParamAndComIndexResult.get("PM10"));
+ vo.setSO2(sixParamAndComIndexResult.get("SO2"));
+ vo.setNO2(sixParamAndComIndexResult.get("NO2"));
+ vo.setCompositeIndex(sixParamAndComIndexResult.get("compositeIndex"));
+ vo.setCityName(area.getAreaName());
+ vos.add(vo);
+ }
+ return vos;
+ }
+
+ //������������
+ @Override
+ public Map<String, Object> momData(Integer regionCode, Integer size, Integer current, Integer orgId) {
+ Map<String,Object> result = new HashMap<>();
+ Page<CityAqi> page = new Page<>(current, size);
+ Page<CityAqi> pageNext = new Page<>(current+1, size);
+ QueryWrapper<CityAqi> cityAqiQueryWrapper = new QueryWrapper<>();
+ cityAqiQueryWrapper.eq("city_code",regionCode);
+ Integer count = cityAqiMapper.selectCount(cityAqiQueryWrapper);
+ if (count==0){
+ return result;
+ }
+ cityAqiQueryWrapper.orderByDesc("time");
+ Page<CityAqi> resultPage = cityAqiMapper.selectPage(page, cityAqiQueryWrapper);
+ List<CityAqi> cityAqiList = resultPage.getRecords();
+ Page<CityAqi> resultPageNext = cityAqiMapper.selectPage(pageNext, cityAqiQueryWrapper);
+ List<CityAqi> cityAqiListNext = resultPageNext.getRecords();
+ List<Map<String,Object>> resultList = new ArrayList<>();
+ if (cityAqiList.size()==0){
+ return result;
+ }
+ for (int i=0; i<cityAqiList.size(); i++) {
+ Map<String,Object> resultMap = new HashMap<>();
+ String hour = cityAqiList.get(i).getTime().toString().substring(11,13);
+ String previousHour = null;
+ Date previousTtime = null;
+ Double PM2_5 = null;
+ Double PM10 = null;
+ Double O3 = null;
+ Integer AQI = null;
+ String AQIIndex = null;
+ Double TVOC = null;
+ Double previousPM2_5 = null;
+ Double previousPM10 = null;
+ Double previousO3 = null;
+ String PM2_5_change = null;
+ String PM10_change = null;
+ String O3_change = null;
+ String value = cityAqiList.get(i).getValue();
+ if (!ObjectUtils.isEmpty(value)){
+ JSONObject jsonObject = JSONObject.parseObject(value);
+ if (!ObjectUtils.isEmpty(jsonObject.get("PM2_5"))){
+ PM2_5 = Double.parseDouble(jsonObject.get("PM2_5").toString());
+ }
+ if (!ObjectUtils.isEmpty(jsonObject.get("PM10"))){
+ PM10 = Double.parseDouble(jsonObject.get("PM10").toString());
+ }
+ if (!ObjectUtils.isEmpty(jsonObject.get("O3"))){
+ O3 = Double.parseDouble(jsonObject.get("O3").toString());
+ }
+ if (!ObjectUtils.isEmpty(jsonObject.get("AQI"))){
+ AQI = Integer.parseInt(jsonObject.get("AQI").toString());
+ AQIIndex = AQIUtils.classCodeOfPollutionByAqi(AQI);
+ }
+ }
+ if (i<cityAqiList.size()-1){
+ previousHour = cityAqiList.get(i+1).getTime().toString().substring(11,13);
+ previousTtime = cityAqiList.get(i+1).getTime();
+ String previousValue = cityAqiList.get(i+1).getValue();
+ if (!ObjectUtils.isEmpty(previousValue)){
+ JSONObject jsonObject = JSONObject.parseObject(previousValue);
+ if (!ObjectUtils.isEmpty(jsonObject.get("PM2_5"))){
+ previousPM2_5 = Double.parseDouble(jsonObject.get("PM2_5").toString());
+ }
+ if (!ObjectUtils.isEmpty(jsonObject.get("PM10"))){
+ previousPM10 = Double.parseDouble(jsonObject.get("PM10").toString());
+ }
+ if (!ObjectUtils.isEmpty(jsonObject.get("O3"))){
+ previousO3 = Double.parseDouble(jsonObject.get("O3").toString());
+ }
+ }
+ }else if (cityAqiListNext.size()>0){
+ previousHour = cityAqiListNext.get(0).getTime().toString().substring(11,13);
+ previousTtime = cityAqiListNext.get(0).getTime();
+ String previousValue = cityAqiListNext.get(0).getValue();
+ if (!ObjectUtils.isEmpty(previousValue)){
+ JSONObject jsonObject = JSONObject.parseObject(previousValue);
+ if (!ObjectUtils.isEmpty(jsonObject.get("PM2_5"))){
+ previousPM2_5 = Double.parseDouble(jsonObject.get("PM2_5").toString());
+ }
+ if (!ObjectUtils.isEmpty(jsonObject.get("PM10"))){
+ previousPM10 = Double.parseDouble(jsonObject.get("PM10").toString());
+ }
+ if (!ObjectUtils.isEmpty(jsonObject.get("O3"))){
+ previousO3 = Double.parseDouble(jsonObject.get("O3").toString());
+ }
+ }
+ }else {
+ continue;
+ }
+ if (!ObjectUtils.isEmpty(PM2_5) && !ObjectUtils.isEmpty(previousPM2_5)){
+ Double difference_PM2_5 = PM2_5-previousPM2_5;
+ if (difference_PM2_5==0){
+ PM2_5_change = "������";
+ }
+ if (difference_PM2_5>0){
+ PM2_5_change = "������"+difference_PM2_5;
+ }
+ if (difference_PM2_5<0){
+ PM2_5_change = "������"+Math.abs(difference_PM2_5);
+ }
+ }
+ if (!ObjectUtils.isEmpty(PM10) && !ObjectUtils.isEmpty(previousPM10)){
+ Double difference_PM10 = PM10-previousPM10;
+ if (difference_PM10==0){
+ PM10_change = "������";
+ }
+ if (difference_PM10>0){
+ PM10_change = "������"+difference_PM10;
+ }
+ if (difference_PM10<0){
+ PM10_change = "������"+Math.abs(difference_PM10);
+ }
+ }
+ if (!ObjectUtils.isEmpty(O3) && !ObjectUtils.isEmpty(previousO3)){
+ Double difference_O3 = O3-previousO3;
+ if (difference_O3==0){
+ O3_change = "������";
+ }
+ if (difference_O3>0){
+ O3_change = "������"+difference_O3;
+ }
+ if (difference_O3<0){
+ O3_change = "������"+Math.abs(difference_O3);
+ }
+ }
+ //���������������������������������id
+ List<Integer> allOrgId = new ArrayList<>();
+ allOrgId.add(orgId);
+ //������������
+ //���������������
+ List<Organization> allChildrenOrganization = organizationService.getChildrenOrganizationsById(orgId);
+ if (!ObjectUtils.isEmpty(allChildrenOrganization) || allChildrenOrganization.size() < 1){
+ for (Organization organization:allChildrenOrganization) {
+ allOrgId.add(organization.getId());
+ }
+ }
+ //������������
+ List<Integer> allOrgIdWithoutDuplicates = allOrgId.stream().distinct().collect(Collectors.toList());
+ //������������list���������������Mac
+ List<String> deviceMacList = new ArrayList<>();
+ for (Integer orgIdWithoutDuplicates:allOrgIdWithoutDuplicates) {
+ //������id������������������
+ QueryWrapper<Device> wrapper_device = new QueryWrapper<>();
+ wrapper_device.eq("is_delete",Constants.NOT_DELETE).eq("organization_id",orgIdWithoutDuplicates);
+ List<Device> devices = new ArrayList<>();
+ devices = deviceMapper.selectList(wrapper_device);
+ if (devices.size()>0){
+ for (Device device:devices) {
+ String deviceMac = device.getMac();
+ deviceMacList.add(deviceMac);
+ }
+ }else {
+ continue;
+ }
+ }
+ //������������
+ SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ String time = df.format(cityAqiList.get(i).getTime());
+ if (deviceMacList.size()>0){
+ List<HistoryHourly> valueByMacs = historyHourlyService.getValueByMacs(deviceMacList, time);
+ if (valueByMacs.size()>0){
+ for (HistoryHourly historyHourly:valueByMacs) {
+ String value_historyHourly = historyHourly.getValue();
+ if (!ObjectUtils.isEmpty(value_historyHourly)){
+ JSONObject jsonObject = JSONObject.parseObject(value_historyHourly);
+ if (!ObjectUtils.isEmpty(jsonObject.get("a99054"))){
+ TVOC = Double.parseDouble(jsonObject.get("a99054").toString());
+ }
+ }
+ }
+ }
+ }
+ resultMap.put("time",time.substring(0,13));
+ resultMap.put("title","���"+hour+"������������������");
+ String PM2_5_string = subZeroAndDot(PM2_5.toString());
+ String PM10_string = subZeroAndDot(PM10.toString());
+ String O3_string = subZeroAndDot(O3.toString());
+ String PM2_5_change_string = subZeroAndDot(PM2_5_change.toString());
+ String PM10_change_string = subZeroAndDot(PM10_change.toString());
+ String O3_change_string = subZeroAndDot(O3_change.toString());
+ resultMap.put("info",hour+"������������AQI���"+AQI+"������������"+AQIIndex+"������"+previousHour+"������������PM10���"+PM10_string+"������/������������"+PM10_change_string+"���PM2.5���"+PM2_5_string+"������/������������"+PM2_5_change_string+"���TVOC���������"+String.format("%.2f", TVOC)+"������/������������O3���"+O3_string+"������/������������"+O3_change_string+"���");
+ QueryWrapper<CityWeather> cityWeatherQueryWrapper = new QueryWrapper<>();
+ cityWeatherQueryWrapper.eq("city_code",regionCode);
+ cityWeatherQueryWrapper.eq("time",cityAqiList.get(i).getTime());
+ CityWeather cityWeather = cityWeatherService.getOne(cityWeatherQueryWrapper);
+ Integer temp = null;
+ Integer humidity = null;
+ String windDir = "";
+ Integer windScale = null;
+ if (!ObjectUtils.isEmpty(cityWeather)){
+ String cityWeatherValue = cityWeather.getValue();
+ if (!ObjectUtils.isEmpty(cityWeatherValue)){
+ JSONObject jsonObject = JSONObject.parseObject(cityWeatherValue);
+ if (!ObjectUtils.isEmpty(jsonObject.get("temp"))){
+ temp = Integer.parseInt(jsonObject.get("temp").toString());
+ }
+ if (!ObjectUtils.isEmpty(jsonObject.get("humidity"))){
+ humidity = Integer.parseInt(jsonObject.get("humidity").toString());
+ }
+ if (!ObjectUtils.isEmpty(jsonObject.get("windDir"))){
+ windDir = jsonObject.get("windDir").toString();
+ }
+ if (!ObjectUtils.isEmpty(jsonObject.get("windScale"))){
+ windScale = Integer.parseInt(jsonObject.get("windScale").toString());
+ }
+ }
+ }
+ String temp_string = "";
+ if (temp!=null){
+ temp_string = temp.toString();
+ }
+ String humidity_string = "";
+ if (humidity!=null){
+ humidity_string = humidity.toString();
+ }
+ String windScale_string = "";
+ if (windScale!=null){
+ windScale_string = windScale.toString();
+ }
+ resultMap.put("weatherCondition","���������������������������"+temp_string+"������������"+humidity_string+"%,"+windDir+windScale_string+"������");
+ resultMap.put("auther","���������������������������");
+ resultList.add(resultMap);
+ }
+ result.put("totel",count);
+ result.put("resultList",resultList);
+ result.put("current",current);
+ int totalPageNumber = count/size;
+ if(count%size != 0){
+ totalPageNumber += 1;
+ }
+ result.put("totalPageNumber",totalPageNumber);
+ return result;
+ }
+
+ /**
+ * @Description: ������6������������������������������������
+ * @Param: [data, comparisonData]
+ * @return: java.util.Map<java.lang.String , com.moral.api.pojo.dto.cityAQI.ConcentrationAndPercent>
+ * @Author: ���������
+ * @Date: 2022/1/17
+ */
+ private Map<String, ConcentrationAndPercent> contrastSixParamAndComIndex(Map<String, Object> data, Map<String, Object> comparisonData) {
+ Map<String, ConcentrationAndPercent> result = new HashMap<>();
+ result.put("CO", contrastParam(Double.parseDouble(data.get("CO").toString()), Double.parseDouble(comparisonData.get("CO").toString()), "CO"));
+ result.put("NO2", contrastParam(Double.parseDouble(data.get("NO2").toString()), Double.parseDouble(comparisonData.get("NO2").toString()), "NO2"));
+ result.put("SO2", contrastParam(Double.parseDouble(data.get("SO2").toString()), Double.parseDouble(comparisonData.get("SO2").toString()), "SO2"));
+ result.put("O3", contrastParam(Double.parseDouble(data.get("O3").toString()), Double.parseDouble(comparisonData.get("O3").toString()), "O3"));
+ result.put("PM2_5", contrastParam(Double.parseDouble(data.get("PM2_5").toString()), Double.parseDouble(comparisonData.get("PM2_5").toString()), "PM2_5"));
+ result.put("PM10", contrastParam(Double.parseDouble(data.get("PM10").toString()), Double.parseDouble(comparisonData.get("PM10").toString()), "PM10"));
+ result.put("compositeIndex", contrastParam(Double.parseDouble(data.get("compositeIndex").toString()), Double.parseDouble(comparisonData.get("compositeIndex").toString()), "compositeIndex"));
+ return result;
+ }
+
+ /**
+ * @Description: ������6������������������������/���������������������
+ * @Param: [data, comparisonData]
+ * @return: com.moral.api.pojo.dto.cityAQI.ConcentrationAndPercent
+ * @Author: ���������
+ * @Date: 2022/1/17
+ */
+ private ConcentrationAndPercent contrastParam(Double data, Double comparisonData, String sensor) {
+ double percentD = MathUtils.division(data - comparisonData, comparisonData, 4);
+ String percent = MathUtils.mul(percentD,100d) + "%";
+ ConcentrationAndPercent concentrationAndPercent = new ConcentrationAndPercent();
+ concentrationAndPercent.setPercent(percent);
+ if (sensor.equals("CO")) {//CO���������������������
+ Double CO = AmendUtils.sciCal(data, 1);
+ concentrationAndPercent.setConcentration(CO.toString());
+ }else if (sensor.equals("compositeIndex")){
+ concentrationAndPercent.setConcentration(data.toString());
+ }else{
+ Double sensorD = AmendUtils.sciCal(data, 0);
+ Integer sensorI = new Double(sensorD).intValue();
+ concentrationAndPercent.setConcentration(sensorI.toString());
+ }
+ return concentrationAndPercent;
+ }
+
+ /**
+ * @Description: ���������������������������������
+ * @Param: [days, comparisonDays]
+ * @return: com.moral.api.pojo.dto.cityAQI.ConcentrationAndPercent
+ * @Author: ���������
+ * @Date: 2022/1/17
+ */
+ private ConcentrationAndPercent contrastDays(Integer days, Integer comparisonDays) {
+ ConcentrationAndPercent concentrationAndPercent = new ConcentrationAndPercent();
+ concentrationAndPercent.setConcentration(days.toString());
+ Integer result = days - comparisonDays;
+ concentrationAndPercent.setPercent(result.toString() + "���");
+ return concentrationAndPercent;
+ }
+
+ /**
+ * @Description: ���������������������������������6������������������������������������������������������������������������
+ * @Param: [comparisonType, startDate, endDate, regionCode]
+ * @return: java.util.Map<java.lang.String , java.lang.Object>
+ * @Author: ���������
+ * @Date: 2022/1/17
+ */
+ private Map<String, Object> getDataByTimeTypeAndRegionCode(String TimeType, Date startDate, Date endDate, Integer regionCode) {
+ Map<String, Object> data;
+ if (Constants.MONTH.equals(TimeType) && (!DateUtils.isCurrentMonth(startDate) || !DateUtils.isCurrentYear(startDate))) {//��������������� ���������������
+ List<CityAqiMonthly> cityAqis = cityAqiMonthlyService.getCityAqiMonthByRegionCodeAndTime(regionCode, startDate, endDate);
+ if (ObjectUtils.isEmpty(cityAqis))
+ return null;
+ data = JSON.parseObject(cityAqis.get(0).getValue(), Map.class);
+ } else if (Constants.YEAR.equals(TimeType) && (!DateUtils.isCurrentYear(startDate))) {//��������������� ���������������
+ List<CityAqiYearly> cityAqis = cityAqiYearlyService.getCityAqiYearlyByRegionCodeAndTime(regionCode, startDate, endDate);
+ if (ObjectUtils.isEmpty(cityAqis))
+ return null;
+ data = JSON.parseObject(cityAqis.get(0).getValue(), Map.class);
+ } else {//���������������������
+ List<CityAqiDaily> cityAqis = cityAqiDailyService.getCityAqiDailyByRegionCodeAndTime(regionCode, startDate, endDate);
+ if (ObjectUtils.isEmpty(cityAqis))
+ return null;
+ List<CityAqi> newCityAqis = new ArrayList<>();
+ List<Map<String, Object>> dailyDataMaps = new ArrayList<>();
+ cityAqis.forEach((value) -> {
+ newCityAqis.add(new CityAqi(value));
+ dailyDataMaps.add(JSON.parseObject(value.getValue(), Map.class));
+ });
+ //������������
+ data = calculate6ParamAvg(newCityAqis);
+ //���������������
+ data.put("CO", Double.parseDouble(data.remove(Constants.SENSOR_CODE_CO).toString()));
+ data.put("NO2", Double.parseDouble(data.remove(Constants.SENSOR_CODE_NO2).toString()));
+ data.put("SO2", Double.parseDouble(data.remove(Constants.SENSOR_CODE_SO2).toString()));
+ data.put("O3", Double.parseDouble(data.remove(Constants.SENSOR_CODE_O3).toString()));
+ data.put("PM2_5", Double.parseDouble(data.remove(Constants.SENSOR_CODE_PM25).toString()));
+ data.put("PM10", Double.parseDouble(data.remove(Constants.SENSOR_CODE_PM10).toString()));
+ //������������������
+ Double compositeIndex = ComprehensiveIndexUtils.dailyData(data);
+ data.put("compositeIndex", compositeIndex);
+ }
+ return data;
+ }
+
+
//������������������
private void sortByField(List<Map<String, Object>> list, String sortField) {
list.sort((o1, o2) -> {
@@ -1030,4 +1375,89 @@
}
return result;
}
+
+ /**
+ * @Description: ���������������������������������������������������������
+ * @Param: [regionType, regionCode]
+ * @return: java.util.List<com.moral.api.entity.SysArea>
+ * @Author: ���������
+ * @Date: 2022/1/14
+ */
+ private List<SysArea> getSysAreasByRegionType(String regionType, Integer regionCode) {
+ List<SysArea> areas;
+ if (regionType.equals(Constants.TWENTY_EIGHT_CITIES)) {
+ SpecialCitiesProperties properties = new SpecialCitiesProperties();
+ areas = properties.getTwentyEightCities();
+ } else {
+ areas = sysAreaService.getChildren(regionCode);
+ }
+ return areas;
+ }
+
+ /**
+ * @Description: ������6������������
+ * @Param: [cityAqiList]
+ * @return: java.util.Map<java.lang.String , java.lang.Double>
+ * ���������key���sensorCode,value������
+ * @Author: ���������
+ * @Date: 2021/11/2
+ */
+ private Map<String, Object> calculate6ParamAvg(List<CityAqi> cityAqiList) {
+ Double co = calculateSensorAvg(cityAqiList, "CO");
+ Double pm2_5 = calculateSensorAvg(cityAqiList, "PM2_5");
+ Double pm10 = calculateSensorAvg(cityAqiList, "PM10");
+ Double so2 = calculateSensorAvg(cityAqiList, "SO2");
+ Double no2 = calculateSensorAvg(cityAqiList, "NO2");
+ Double o3 = calculateSensorAvg(cityAqiList, "O3");
+ Map<String, Object> result = new HashMap<>();
+ result.put(Constants.SENSOR_CODE_CO, co);
+ result.put(Constants.SENSOR_CODE_NO2, no2);
+ result.put(Constants.SENSOR_CODE_SO2, so2);
+ result.put(Constants.SENSOR_CODE_O3, o3);
+ result.put(Constants.SENSOR_CODE_PM25, pm2_5);
+ result.put(Constants.SENSOR_CODE_PM10, pm10);
+ return result;
+ }
+
+ /**
+ * @Description: ������������������������
+ * @Param: [cityAqiList, sensor]
+ * ���sensor���������������������������
+ * @return: java.lang.Double
+ * @Author: ���������
+ * @Date: 2021/11/2
+ */
+ private Double calculateSensorAvg(List<CityAqi> cityAqiList, String sensor) {
+ Double sum = 0d;
+ int num = 0;
+ for (CityAqi cityAqi : cityAqiList) {
+ String value = cityAqi.getValue();
+ if (value == null)
+ continue;
+ Map<String, Object> valueMap = JSON.parseObject(value, Map.class);
+ Object sensorValueObject = valueMap.get(sensor);
+ if (sensorValueObject == null)
+ continue;
+ Double sensorValue = Double.valueOf(sensorValueObject.toString());
+ sum = MathUtils.add(sum, sensorValue);
+ num++;
+ }
+ if (num == 0)
+ return null;
+ Double avg = MathUtils.division(sum, num, 2);
+ return avg;
+ }
+
+ /**
+ * ������java������������������������������.���0
+ * @param s
+ * @return
+ */
+ public static String subZeroAndDot(String s){
+ if(s.indexOf(".") > 0){
+ s = s.replaceAll("0+?$", "");//���������������0
+ s = s.replaceAll("[.]$", "");//������������������.���������
+ }
+ return s;
+ }
}
--
Gitblit v1.8.0