From 8dce9a3ac3d04150a8656219b32f0bdda445ab2c Mon Sep 17 00:00:00 2001
From: lizijie <lzjiiie@163.com>
Date: Mon, 14 Mar 2022 17:13:43 +0800
Subject: [PATCH] 环比数据接口修改
---
screen-api/src/main/java/com/moral/api/service/impl/CityAqiServiceImpl.java | 232 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 219 insertions(+), 13 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 be28219..a701188 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,27 +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.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.CityAqiDailyService;
-import com.moral.api.service.CityAqiMonthlyService;
-import com.moral.api.service.CityAqiService;
+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;
@@ -40,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;
@@ -78,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) {
@@ -1001,6 +1005,208 @@
return vos;
}
+ //������������
+ @Override
+ public List<Map<String, Object>> momData(Integer regionCode, Integer size, Integer current, Integer orgId) {
+ 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);
+ 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 resultList;
+ }
+ 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+"������������������");
+ resultMap.put("info",hour+"������������AQI���"+AQI+"������������"+AQIIndex+"������"+previousHour+"������������PM10���"+PM10+"������/������������"+PM10_change+"���PM2_5���"+PM2_5+"������/������������"+PM2_5_change+"���TVOC���������"+TVOC+"������/������������O3���"+O3+"������/������������"+O3_change+"���");
+ QueryWrapper<CityWeather> cityWeatherQueryWrapper = new QueryWrapper<>();
+ cityWeatherQueryWrapper.eq("city_code",regionCode);
+ cityWeatherQueryWrapper.eq("time",cityAqiList.get(i).getTime());
+ CityWeather cityWeather = cityWeatherService.getOne(cityWeatherQueryWrapper);
+ Double temp = null;
+ Double humidity = null;
+ String windDir = null;
+ Integer windScale = null;
+ String cityWeatherValue = cityWeather.getValue();
+ if (!ObjectUtils.isEmpty(cityWeatherValue)){
+ JSONObject jsonObject = JSONObject.parseObject(cityWeatherValue);
+ if (!ObjectUtils.isEmpty(jsonObject.get("temp"))){
+ temp = Double.parseDouble(jsonObject.get("temp").toString());
+ }
+ if (!ObjectUtils.isEmpty(jsonObject.get("humidity"))){
+ humidity = Double.parseDouble(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());
+ }
+ }
+ resultMap.put("weatherCondition","���������������������������"+temp+"������������"+humidity+"%,"+windDir+windScale+"������");
+ resultMap.put("auther","���������������������������");
+ resultList.add(resultMap);
+ }
+ return resultList;
+ }
+
/**
* @Description: ������6������������������������������������
* @Param: [data, comparisonData]
--
Gitblit v1.8.0