From 9a7ed13d553ed7493b14d94f5d366c2736ade388 Mon Sep 17 00:00:00 2001
From: lizijie <lzjiiie@163.com>
Date: Mon, 14 Mar 2022 16:25:06 +0800
Subject: [PATCH] 按条件查询环比信息接口
---
screen-api/src/main/java/com/moral/api/entity/CityWeather.java | 4
screen-api/src/main/java/com/moral/api/service/CityAqiService.java | 9 +
screen-job/src/main/java/com/moral/api/task/InformationTask.java | 2
screen-api/src/main/java/com/moral/api/controller/AqiController.java | 10 ++
screen-api/src/main/java/com/moral/api/service/impl/CityAqiServiceImpl.java | 231 +++++++++++++++++++++++++++++++++++++++++++--
5 files changed, 241 insertions(+), 15 deletions(-)
diff --git a/screen-api/src/main/java/com/moral/api/controller/AqiController.java b/screen-api/src/main/java/com/moral/api/controller/AqiController.java
index 087cc14..fdfeaca 100644
--- a/screen-api/src/main/java/com/moral/api/controller/AqiController.java
+++ b/screen-api/src/main/java/com/moral/api/controller/AqiController.java
@@ -305,4 +305,14 @@
return ResultMessage.ok(ComplianceDaysVO.convert(dtos));
}
+ @GetMapping("momDate")
+ public ResultMessage momDate(Integer regionCode, Integer size, Integer current, Integer orgId){
+ if(regionCode==null || size==null || current==null){
+ return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(),
+ ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
+ }
+ List<Map<String, Object>> resultList = cityAqiService.momData(regionCode, size, current, orgId);
+ return ResultMessage.ok(resultList);
+ }
+
}
diff --git a/screen-api/src/main/java/com/moral/api/entity/CityWeather.java b/screen-api/src/main/java/com/moral/api/entity/CityWeather.java
index 18eef33..553fca5 100644
--- a/screen-api/src/main/java/com/moral/api/entity/CityWeather.java
+++ b/screen-api/src/main/java/com/moral/api/entity/CityWeather.java
@@ -3,6 +3,8 @@
import com.baomidou.mybatisplus.extension.activerecord.Model;
import java.time.LocalDateTime;
import java.io.Serializable;
+import java.util.Date;
+
import lombok.Data;
import lombok.EqualsAndHashCode;
@@ -28,7 +30,7 @@
/**
* ������
*/
- private LocalDateTime time;
+ private Date time;
/**
* ������
diff --git a/screen-api/src/main/java/com/moral/api/service/CityAqiService.java b/screen-api/src/main/java/com/moral/api/service/CityAqiService.java
index 7006379..832ef00 100644
--- a/screen-api/src/main/java/com/moral/api/service/CityAqiService.java
+++ b/screen-api/src/main/java/com/moral/api/service/CityAqiService.java
@@ -63,4 +63,13 @@
* @Date: 2022/1/14
*/
List<AirQualityComparisonVO> queryAirQualityComparison(AirQualityComparisonForm form);
+
+ /**
+ *@Description: ������������������������
+ *@Param: [regionCode, size, current]
+ *@return: java.util.List<java.util.Map<java.lang.String,java.lang.Object>>
+ *@Author: lizijie
+ *@Date: 2022/3/10 15:49
+ **/
+ List<Map<String,Object>> momData(Integer regionCode, Integer size, Integer current, Integer orgId);
}
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..958c499 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,207 @@
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("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]
diff --git a/screen-job/src/main/java/com/moral/api/task/InformationTask.java b/screen-job/src/main/java/com/moral/api/task/InformationTask.java
index d4d931a..cab0ba1 100644
--- a/screen-job/src/main/java/com/moral/api/task/InformationTask.java
+++ b/screen-job/src/main/java/com/moral/api/task/InformationTask.java
@@ -159,7 +159,7 @@
TVOCListNow.add(Double.parseDouble(jsonObject.get("a99054").toString()));
}
List<HistoryHourly> historyHourliesBefore = new ArrayList<>();
- historyHourliesBefore = historyHourlyService.getValueByMacAndTime("p5dnd7a0392252", df1.parse(beforeTime), df1.parse(df.format(beforeCalendar.getTime()) + ":00:01"));
+ historyHourliesBefore = historyHourlyService.getValueByMacAndTime(mac, df1.parse(beforeTime), df1.parse(df.format(beforeCalendar.getTime()) + ":00:01"));
if (!ObjectUtils.isEmpty(historyHourliesBefore) && historyHourliesBefore.size()>0){
String value = historyHourliesBefore.get(0).getValue();
JSONObject jsonObject = JSONObject.parseObject(value);
--
Gitblit v1.8.0