From 239927b057f65a040594f7a4cb08c8881b303797 Mon Sep 17 00:00:00 2001
From: cjl <276999030@qq.com>
Date: Fri, 18 Aug 2023 14:52:16 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/cjl-230812' into cjl-230812
---
screen-api/src/main/java/com/moral/api/service/impl/CityAqiDailyServiceImpl.java | 182 ++++++++++++++++++++++++++++++++++++---------
1 files changed, 145 insertions(+), 37 deletions(-)
diff --git a/screen-api/src/main/java/com/moral/api/service/impl/CityAqiDailyServiceImpl.java b/screen-api/src/main/java/com/moral/api/service/impl/CityAqiDailyServiceImpl.java
index 698e474..e17da0d 100644
--- a/screen-api/src/main/java/com/moral/api/service/impl/CityAqiDailyServiceImpl.java
+++ b/screen-api/src/main/java/com/moral/api/service/impl/CityAqiDailyServiceImpl.java
@@ -12,9 +12,11 @@
import com.moral.api.mapper.CityAqiDailyMapper;
import com.moral.api.mapper.CityAqiMonthlyMapper;
import com.moral.api.pojo.dto.cityAQI.CityPollutionLevel;
+import com.moral.api.pojo.dto.cityAQI.ConcentrationAndPercent;
import com.moral.api.pojo.dto.cityAQI.MonthlyPollutionLevel;
import com.moral.api.pojo.dto.cityAQI.PollutionDaysAndProportion;
import com.moral.api.pojo.form.aqi.*;
+import com.moral.api.pojo.vo.cityAQI.CityAreaRangeVO;
import com.moral.api.pojo.vo.cityAQI.PieChartOfPollutionLevelVO;
import com.moral.api.service.CityAqiDailyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -340,6 +342,91 @@
}
@Override
+ public List<CityAreaRangeVO> cityAreaRange(Integer regionCode, Date time) {
+ //���������������������������������������������������null
+ if (DateUtils.getYesterdayDate().getTime() < time.getTime())
+ return null;
+ //������������������������������������
+ List<SysArea> allAreas = sysAreaService.getChildren(regionCode);
+ //������������������
+ Date compareTime = DateUtils.addMonths(time, -12);
+ //���������������������������������������������
+ Date startDate = DateUtils.getFirstDayOfMonth(time);
+ Date endDate = DateUtils.getLastDayOfMonth(time);
+ //���������������������������������������������
+ Date compareStartDate = DateUtils.getFirstDayOfMonth(compareTime);
+ Date compareEndDate = DateUtils.getLastDayOfMonth(compareTime);
+ //���������������
+ List<CityAreaRangeVO> vos = new ArrayList<>();
+ for (SysArea area : allAreas) {
+ CityAreaRangeVO vo = new CityAreaRangeVO();
+ Map<String, Object> data = new HashMap<>();
+ Map<String, Object> compareData = new HashMap<>();
+ //���������������������������
+ QueryWrapper<CityAqiDaily> wrapper = new QueryWrapper<>();
+ wrapper.eq("time", time);
+ wrapper.eq("city_code", area.getAreaCode());
+ List<CityAqiDaily> datas = cityAqiDailyMapper.selectList(wrapper);
+ if (!ObjectUtils.isEmpty(datas))
+ data = JSON.parseObject(datas.get(0).getValue(), Map.class);
+ //���������������������������
+ QueryWrapper<CityAqiDaily> compareWrapper = new QueryWrapper<>();
+ compareWrapper.eq("time", compareTime);
+ compareWrapper.eq("city_code", area.getAreaCode());
+ List<CityAqiDaily> compareDatas = cityAqiDailyMapper.selectList(compareWrapper);
+ if (!ObjectUtils.isEmpty(compareDatas))
+ compareData = JSON.parseObject(compareDatas.get(0).getValue(), Map.class);
+ if (ObjectUtils.isEmpty(compareDatas) && ObjectUtils.isEmpty(datas)) {
+ vos.add(vo);
+ continue;
+ }
+ //������6������������������������������������
+ ConcentrationAndPercent PM25 = getConcentrationAndPercent(data.get("PM2_5"), compareData.get("PM2_5"));
+ ConcentrationAndPercent PM10 = getConcentrationAndPercent(data.get("PM10"), compareData.get("PM10"));
+ ConcentrationAndPercent SO2 = getConcentrationAndPercent(data.get("SO2"), compareData.get("SO2"));
+ ConcentrationAndPercent NO2 = getConcentrationAndPercent(data.get("NO2"), compareData.get("NO2"));
+ ConcentrationAndPercent CO = getConcentrationAndPercent(data.get("CO"), compareData.get("CO"));
+ ConcentrationAndPercent O3 = getConcentrationAndPercent(data.get("O3"), compareData.get("O3"));
+ ConcentrationAndPercent compositeIndex = getConcentrationAndPercent(data.get("compositeIndex"), compareData.get("compositeIndex"));
+ //���������������������������������������
+ CityPollutionLevel days = calculateDaysByTimeAndSysArea(area, startDate, endDate);
+ CityPollutionLevel compareDays = calculateDaysByTimeAndSysArea(area, compareStartDate, compareEndDate);
+ Integer fineDays = null;
+ Integer pollutionDays = null;
+ Integer compareFineDays = null;
+ Integer comparePollutionDays = null;
+ if (days != null) {
+ fineDays = days.getExcellentWeatherDays() + days.getGoodWeatherDays();
+ pollutionDays = days.getMildWeatherDays() + days.getServerWeatherDays() + days.getSeriousWeatherDays() + days.getMiddleWeatherDays();
+ }
+ if (compareDays != null) {
+ compareFineDays = compareDays.getExcellentWeatherDays() + compareDays.getGoodWeatherDays();
+ comparePollutionDays = compareDays.getMildWeatherDays() + compareDays.getServerWeatherDays() + compareDays.getSeriousWeatherDays() + compareDays.getMiddleWeatherDays();
+ }
+ ConcentrationAndPercent fineDaysData = getFineDaysConcentrationAndPercent(fineDays, compareFineDays);
+ ConcentrationAndPercent pollutionDaysData = getFineDaysConcentrationAndPercent(pollutionDays, comparePollutionDays);
+ //������������
+ vo.setCityName(area.getAreaName());
+ vo.setCompositeIndex(compositeIndex);
+ vo.setPM10(PM10);
+ vo.setPM25(PM25);
+ vo.setNO2(NO2);
+ vo.setSO2(SO2);
+ vo.setO3(O3);
+ vo.setCO(CO);
+ vo.setFineDays(fineDaysData);
+ vo.setServerDays(pollutionDaysData);
+ vos.add(vo);
+ }
+ //���������������������
+ vos.sort(Comparator.comparing(value -> Double.valueOf(value.getCompositeIndex().getConcentration())));
+ for(int i =1;i<vos.size()+1;i++){
+ vos.get(i-1).setRange(i);
+ }
+ return vos;
+ }
+
+ @Override
public List<CityPollutionLevel> queryProvinceCitiesPollutionLevel(ProvinceCitiesPollutionLevelForm form) {
//������
Date startDate = form.getStartDate();
@@ -429,15 +516,15 @@
return null;
//���������������������
List<String> paragraphTwoAndFour = getParagraphTwoAndFour(year + "", month + "", day + "", regionCode, time);
- if(paragraphTwoAndFour==null)
+ if (paragraphTwoAndFour == null)
return null;
- String paragraphTwo = paragraphTwoAndFour.get(0);
+ String paragraphTwo = paragraphTwoAndFour.get(0);
//���������������������������
String paragraphThree = getParagraphThree(month + "", day + "", regionCode, time);
if (paragraphThree == null)
return null;
//���������������������
- String paragraphFour = paragraphTwoAndFour.get(1);
+ String paragraphFour = paragraphTwoAndFour.get(1);
result.add(title);
result.add(paragraphOne);
result.add(paragraphTwo);
@@ -491,7 +578,7 @@
CityPollutionLevel days = calculateDaysByTimeAndSysArea(area, startTime, endTime);
//������������������������������
CityPollutionLevel compareDays = calculateDaysByTimeAndSysArea(area, compareStartTime, compareEndTime);
- if(days==null||compareDays==null)
+ if (days == null || compareDays == null)
return null;
//������������������
List<CityAqiYearly> yearDataList = cityAqiYearlyService.getCityAqiYearlyByRegionCodeAndTime(Integer.parseInt(regionCode), startTime, endTime);
@@ -505,7 +592,7 @@
//���������������������
String yearPM_5 = dataMap.get("PM2_5").toString();
String fineDays = days.getExcellentWeatherDays() + days.getGoodWeatherDays() + "";
- int allDays = DateUtils.getDays(startTime, endTime)+1;
+ int allDays = DateUtils.getDays(startTime, endTime) + 1;
paragraphTwo = paragraphTwo.replace("{year}", year);
paragraphTwo = paragraphTwo.replace("{yearPM2.5}", yearPM_5);
paragraphTwo = paragraphTwo.replace("{fineDays}", fineDays);
@@ -541,7 +628,7 @@
//������������������������
int yearPollutionDays = days.getMildWeatherDays() + days.getMiddleWeatherDays() + days.getSeriousWeatherDays() + days.getServerWeatherDays();
//������������������������������
- String yearFineDaysPer = String.valueOf(MathUtils.division(yearFineDays*100 ,allDays,2));
+ String yearFineDaysPer = String.valueOf(MathUtils.division(yearFineDays * 100, allDays, 2));
//������168������������������������������������������������������
List<Integer> oneSixEightRanges = rangeByCities(compositeIndex,
@@ -560,35 +647,35 @@
String compositeIndex168range = oneSixEightRanges.get(0).toString();
String compositeIndexPer168range = oneSixEightRanges.get(1).toString();
//������������������
- paragraphFour = paragraphFour.replace("{month}",month);
- paragraphFour = paragraphFour.replace("{day}",day);
- paragraphFour = paragraphFour.replace("{yearCompositeIndex}",compositeIndex+"");
- paragraphFour = paragraphFour.replace("{yoyYearCompositeIndex}",yoyYearCompositeIndex);
- paragraphFour = paragraphFour.replace("{yoyYearCompositeIndexUpDown}",yoyYearCompositeIndexUpDown);
- paragraphFour = paragraphFour.replace("{yearPM2.5}",PM2_5+"");
- paragraphFour = paragraphFour.replace("{yoyYearPM2.5UpDown}",yoyYearPM2_5UpDown);
- paragraphFour = paragraphFour.replace("{yoyYearPM2.5}",yoyYearPM2_5);
- paragraphFour = paragraphFour.replace("{yearFineDays}",yearFineDays+"");
- paragraphFour = paragraphFour.replace("{yearFineDaysPer}",yearFineDaysPer);
- paragraphFour = paragraphFour.replace("{yearPollutionDays}",yearPollutionDays+"");
- paragraphFour = paragraphFour.replace("{yoyYearFineDaysUpDown}",yoyYearFineDaysUpDown);
- paragraphFour = paragraphFour.replace("{yoyYearFineDays}",yoyYearFineDays);
- paragraphFour = paragraphFour.replace("{compositeIndex28range}",compositeIndex28range);
- paragraphFour = paragraphFour.replace("{compositeIndexPer28range}",compositeIndexPer28range);
- paragraphFour = paragraphFour.replace("{compositeIndex168range}",compositeIndex168range);
- paragraphFour = paragraphFour.replace("{compositeIndexPer168range}",compositeIndexPer168range);
+ paragraphFour = paragraphFour.replace("{month}", month);
+ paragraphFour = paragraphFour.replace("{day}", day);
+ paragraphFour = paragraphFour.replace("{yearCompositeIndex}", compositeIndex + "");
+ paragraphFour = paragraphFour.replace("{yoyYearCompositeIndex}", yoyYearCompositeIndex);
+ paragraphFour = paragraphFour.replace("{yoyYearCompositeIndexUpDown}", yoyYearCompositeIndexUpDown);
+ paragraphFour = paragraphFour.replace("{yearPM2.5}", PM2_5 + "");
+ paragraphFour = paragraphFour.replace("{yoyYearPM2.5UpDown}", yoyYearPM2_5UpDown);
+ paragraphFour = paragraphFour.replace("{yoyYearPM2.5}", yoyYearPM2_5);
+ paragraphFour = paragraphFour.replace("{yearFineDays}", yearFineDays + "");
+ paragraphFour = paragraphFour.replace("{yearFineDaysPer}", yearFineDaysPer);
+ paragraphFour = paragraphFour.replace("{yearPollutionDays}", yearPollutionDays + "");
+ paragraphFour = paragraphFour.replace("{yoyYearFineDaysUpDown}", yoyYearFineDaysUpDown);
+ paragraphFour = paragraphFour.replace("{yoyYearFineDays}", yoyYearFineDays);
+ paragraphFour = paragraphFour.replace("{compositeIndex28range}", compositeIndex28range);
+ paragraphFour = paragraphFour.replace("{compositeIndexPer28range}", compositeIndexPer28range);
+ paragraphFour = paragraphFour.replace("{compositeIndex168range}", compositeIndex168range);
+ paragraphFour = paragraphFour.replace("{compositeIndexPer168range}", compositeIndexPer168range);
result.add(paragraphFour);
return result;
}
//������������������������������������������������������
private List<Integer> rangeByCities(
- Double compositeIndex,
- Double compositeIndexPer,
- Date startTime,
- Date endTime,
- Date compareStartTime,
- Date compareEndTime, List<SysArea> areas){
+ Double compositeIndex,
+ Double compositeIndexPer,
+ Date startTime,
+ Date endTime,
+ Date compareStartTime,
+ Date compareEndTime, List<SysArea> areas) {
List<Double> compositeIndexList = new ArrayList<>();
List<Double> compositePerList = new ArrayList<>();
for (SysArea sysArea : areas) {
@@ -596,21 +683,21 @@
List<CityAqiYearly> data = cityAqiYearlyService.getCityAqiYearlyByRegionCodeAndTime(sysArea.getAreaCode(), startTime, endTime);
//������������������
List<CityAqiYearly> compareData = cityAqiYearlyService.getCityAqiYearlyByRegionCodeAndTime(sysArea.getAreaCode(), compareStartTime, compareEndTime);
- if(ObjectUtils.isEmpty(data)||ObjectUtils.isEmpty(compareData))
+ if (ObjectUtils.isEmpty(data) || ObjectUtils.isEmpty(compareData))
continue;
- Map<String,Object> dataMap = JSON.parseObject(data.get(0).getValue(),Map.class);
- Map<String,Object> compareDataMap = JSON.parseObject(compareData.get(0).getValue(),Map.class);
+ Map<String, Object> dataMap = JSON.parseObject(data.get(0).getValue(), Map.class);
+ Map<String, Object> compareDataMap = JSON.parseObject(compareData.get(0).getValue(), Map.class);
//������������������
compositeIndexList.add(Double.valueOf(dataMap.get("compositeIndex").toString()));
//���������������������������
- Double per = calculateCompare(Double.valueOf(dataMap.get("compositeIndex").toString()),Double.valueOf(compareDataMap.get("compositeIndex").toString()));
+ Double per = calculateCompare(Double.valueOf(dataMap.get("compositeIndex").toString()), Double.valueOf(compareDataMap.get("compositeIndex").toString()));
compositePerList.add(per);
}
Collections.sort(compositeIndexList);
Collections.sort(compositePerList);
Integer compositeIndexRange = compositeIndexList.indexOf(compositeIndex);
Integer compositePerRange = compositePerList.indexOf(compositeIndexPer);
- return Arrays.asList((compositeIndexRange+1),(compositePerRange+1));
+ return Arrays.asList((compositeIndexRange + 1), (compositePerRange + 1));
}
//���������������������������
@@ -694,14 +781,35 @@
//������������������/������������ ���������������������-���������������/������������ ���������������
private Double calculateComparePerPositive(Double currentData, Double compareData) {
double tmp1 = MathUtils.sub(currentData, compareData);
- double result = MathUtils.mul(MathUtils.division(tmp1, compareData, 4),100d);
+ double result = MathUtils.mul(MathUtils.division(tmp1, compareData, 4), 100d);
return result > 0 ? result : MathUtils.mul(result, -1d);
}
- //������������������/������������ ���������������������-���������������/������������ ���������������
+ //������������������/������������ ���������������������-���������������/������������
private Double calculateCompare(Double currentData, Double compareData) {
double tmp1 = MathUtils.sub(currentData, compareData);
- return MathUtils.mul(MathUtils.division(tmp1, compareData, 4),100d);
+ return MathUtils.mul(MathUtils.division(tmp1, compareData, 4), 100d);
+ }
+
+
+ //��������������������������������������� ������������ ������������
+ private ConcentrationAndPercent getConcentrationAndPercent(Object data, Object compareData) {
+ ConcentrationAndPercent cap = new ConcentrationAndPercent();
+ cap.setConcentration(data != null ? data.toString() : "-");
+ cap.setCompareConcentration(compareData != null ? compareData.toString() : "-");
+ if (data != null && compareData != null)
+ cap.setPercent(calculateCompare(Double.valueOf(data.toString()), Double.valueOf(compareData.toString())) + "%");
+ else
+ cap.setPercent("-");
+ return cap;
+ }
+
+ //������������������������������������������������
+ private ConcentrationAndPercent getFineDaysConcentrationAndPercent(Integer days, Integer compareDays) {
+ ConcentrationAndPercent cap = new ConcentrationAndPercent();
+ cap.setConcentration(days != null ? days + "���" : "-");
+ cap.setPercent(compareDays != null ? (days - compareDays) + "���" : "-");
+ return cap;
}
--
Gitblit v1.8.0