From cdec9062c85f52d43e8d74e82cbcf9f8606ebb01 Mon Sep 17 00:00:00 2001 From: jinpengyong <jpy123456> Date: Tue, 30 Jan 2024 16:39:59 +0800 Subject: [PATCH] chore:设备在线率接口提交 --- screen-api/src/main/java/com/moral/api/service/impl/CityAqiDailyServiceImpl.java | 564 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 519 insertions(+), 45 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 44e67e4..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 @@ -3,26 +3,33 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.moral.api.config.properties.BulletinProperties; +import com.moral.api.config.properties.SpecialCitiesProperties; import com.moral.api.entity.CityAqiDaily; +import com.moral.api.entity.CityAqiMonthly; +import com.moral.api.entity.CityAqiYearly; import com.moral.api.entity.SysArea; 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.AreaPollutionLevelForm; +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.pojo.form.aqi.ChartOfPollutionLevelForm; import com.moral.api.service.CityAqiDailyService; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.moral.api.service.CityAqiMonthlyService; +import com.moral.api.service.CityAqiYearlyService; import com.moral.api.service.SysAreaService; import com.moral.constant.Constants; -import com.moral.util.AQIUtils; -import com.moral.util.DateUtils; -import com.moral.util.MathUtils; +import com.moral.util.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.ObjectUtils; +import java.text.DecimalFormat; import java.text.SimpleDateFormat; import java.util.*; @@ -41,6 +48,22 @@ CityAqiDailyMapper cityAqiDailyMapper; @Autowired SysAreaService sysAreaService; + @Autowired + SpecialCitiesProperties specialCitiesProperties; + @Autowired + BulletinProperties bulletinProperties; + @Autowired + CityAqiMonthlyService cityAqiMonthlyService; + @Autowired + CityAqiYearlyService cityAqiYearlyService; + + @Override + public List<CityAqiDaily> getCityAqiDailyByRegionCodeAndTime(Integer regionCode, Date startDate, Date endDate) { + QueryWrapper<CityAqiDaily> queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("city_code", regionCode); + queryWrapper.between("time", startDate, endDate); + return cityAqiDailyMapper.selectList(queryWrapper); + } @Override public PieChartOfPollutionLevelVO queryPieChartOfPollutionLevels(ChartOfPollutionLevelForm form) { @@ -283,6 +306,7 @@ return resultMap; } + @Override public List<CityPollutionLevel> queryAreaPollutionLevel(AreaPollutionLevelForm form) { //������ @@ -295,49 +319,499 @@ List<CityPollutionLevel> datas = new ArrayList<>(); //��������������������� ������������ for (SysArea area : allAreas) { - //������������ - QueryWrapper<CityAqiDaily> wrapper = new QueryWrapper<>(); - wrapper.eq("city_code", area.getAreaCode()); - wrapper.between("time", startDate, endDate); - wrapper.orderByAsc("time"); - List<CityAqiDaily> cityAqiDailies = cityAqiDailyMapper.selectList(wrapper); - //��������������������������������������� - Map<String, CityAqiDaily> tmpMap = new LinkedHashMap<>(); - for (CityAqiDaily cityAqiDaily : cityAqiDailies) { - String tmpTime = DateUtils.dateToDateString(cityAqiDaily.getTime(), "yyyy-MM-dd"); - tmpMap.put(tmpTime, cityAqiDaily); - } - cityAqiDailies = new ArrayList<CityAqiDaily>(tmpMap.values()); - //��������������������������������������� - Map<String, Integer> pollutionDaysMap = new LinkedHashMap<>(); - pollutionDaysMap.put(Constants.EXCELLENT_WEATHER_CODE, 0); - pollutionDaysMap.put(Constants.GOOD_WEATHER_CODE, 0); - pollutionDaysMap.put(Constants.MILD_WEATHER_CODE, 0); - pollutionDaysMap.put(Constants.MIDDLE_WEATHER_CODE, 0); - pollutionDaysMap.put(Constants.SERIOUS_WEATHER_CODE, 0); - pollutionDaysMap.put(Constants.SERVER_WEATHER_CODE, 0); - for (CityAqiDaily cityAqiDaily : cityAqiDailies) { - Map<String, Object> valueMap = JSON.parseObject(cityAqiDaily.getValue(), Map.class); - if (valueMap.get("AQI") == null) - continue; - Integer aqi = Integer.valueOf(valueMap.get("AQI").toString()); - //������AQI������������ - String pollutionClass = AQIUtils.classCodeOfPollutionByAqi(aqi); - Integer days = pollutionDaysMap.get(pollutionClass); - pollutionDaysMap.put(pollutionClass, days + 1); - } - //������������ - CityPollutionLevel cityPollutionLevel = new CityPollutionLevel(); - cityPollutionLevel.setRegionName(area.getAreaName()); - cityPollutionLevel.setExcellentWeatherDays(pollutionDaysMap.get(Constants.EXCELLENT_WEATHER_CODE)); - cityPollutionLevel.setGoodWeatherDays(pollutionDaysMap.get(Constants.GOOD_WEATHER_CODE)); - cityPollutionLevel.setMildWeatherDays(pollutionDaysMap.get(Constants.MILD_WEATHER_CODE)); - cityPollutionLevel.setMiddleWeatherDays(pollutionDaysMap.get(Constants.MIDDLE_WEATHER_CODE)); - cityPollutionLevel.setSeriousWeatherDays(pollutionDaysMap.get(Constants.SERIOUS_WEATHER_CODE)); - cityPollutionLevel.setServerWeatherDays(pollutionDaysMap.get(Constants.SERVER_WEATHER_CODE)); + CityPollutionLevel cityPollutionLevel = calculateDaysByTimeAndSysArea(area, startDate, endDate); datas.add(cityPollutionLevel); } return datas; } + @Override + public List<CityPollutionLevel> querySpecialCitiesPollutionLevel(SpecialCitiesPollutionLevelForm form) { + //������ + Date startDate = form.getStartDate(); + Date endDate = form.getEndDate(); + List<SysArea> areas = specialCitiesProperties.getTwentyEightCities(); + //������������������������ + List<CityPollutionLevel> datas = new ArrayList<>(); + //��������������������� ������������ + for (SysArea area : areas) { + CityPollutionLevel cityPollutionLevel = calculateDaysByTimeAndSysArea(area, startDate, endDate); + datas.add(cityPollutionLevel); + } + return datas; + } + + @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(); + Date endDate = form.getEndDate(); + Integer regionCode = form.getRegionCode(); + //������������������������ + List<SysArea> allCities = sysAreaService.getChildren(regionCode); + //������������������������ + List<CityPollutionLevel> datas = new ArrayList<>(); + //��������������������� ������������ + for (SysArea city : allCities) { + CityPollutionLevel cityPollutionLevel = calculateDaysByTimeAndSysArea(city, startDate, endDate); + datas.add(cityPollutionLevel); + } + return datas; + } + + @Override + public CityPollutionLevel calculateDaysByTimeAndSysArea(SysArea area, Date startDate, Date endDate) { + //������������ + QueryWrapper<CityAqiDaily> wrapper = new QueryWrapper<>(); + wrapper.eq("city_code", area.getAreaCode()); + wrapper.between("time", startDate, endDate); + wrapper.orderByAsc("time"); + List<CityAqiDaily> cityAqiDailies = cityAqiDailyMapper.selectList(wrapper); + if (ObjectUtils.isEmpty(cityAqiDailies)) + return null; + //��������������������������������������� + Map<String, CityAqiDaily> tmpMap = new LinkedHashMap<>(); + for (CityAqiDaily cityAqiDaily : cityAqiDailies) { + String tmpTime = DateUtils.dateToDateString(cityAqiDaily.getTime(), "yyyy-MM-dd"); + tmpMap.put(tmpTime, cityAqiDaily); + } + cityAqiDailies = new ArrayList<CityAqiDaily>(tmpMap.values()); + //��������������������������������������� + Map<String, Integer> pollutionDaysMap = new LinkedHashMap<>(); + pollutionDaysMap.put(Constants.EXCELLENT_WEATHER_CODE, 0); + pollutionDaysMap.put(Constants.GOOD_WEATHER_CODE, 0); + pollutionDaysMap.put(Constants.MILD_WEATHER_CODE, 0); + pollutionDaysMap.put(Constants.MIDDLE_WEATHER_CODE, 0); + pollutionDaysMap.put(Constants.SERIOUS_WEATHER_CODE, 0); + pollutionDaysMap.put(Constants.SERVER_WEATHER_CODE, 0); + for (CityAqiDaily cityAqiDaily : cityAqiDailies) { + Map<String, Object> valueMap = JSON.parseObject(cityAqiDaily.getValue(), Map.class); + if (valueMap.get("AQI") == null) + continue; + Integer aqi = Integer.valueOf(valueMap.get("AQI").toString()); + //������AQI������������ + String pollutionClass = AQIUtils.classCodeOfPollutionByAqi(aqi); + Integer days = pollutionDaysMap.get(pollutionClass); + pollutionDaysMap.put(pollutionClass, days + 1); + } + //������������ + CityPollutionLevel cityPollutionLevel = new CityPollutionLevel(); + cityPollutionLevel.setRegionName(area.getAreaName()); + cityPollutionLevel.setExcellentWeatherDays(pollutionDaysMap.get(Constants.EXCELLENT_WEATHER_CODE)); + cityPollutionLevel.setGoodWeatherDays(pollutionDaysMap.get(Constants.GOOD_WEATHER_CODE)); + cityPollutionLevel.setMildWeatherDays(pollutionDaysMap.get(Constants.MILD_WEATHER_CODE)); + cityPollutionLevel.setMiddleWeatherDays(pollutionDaysMap.get(Constants.MIDDLE_WEATHER_CODE)); + cityPollutionLevel.setSeriousWeatherDays(pollutionDaysMap.get(Constants.SERIOUS_WEATHER_CODE)); + cityPollutionLevel.setServerWeatherDays(pollutionDaysMap.get(Constants.SERVER_WEATHER_CODE)); + return cityPollutionLevel; + } + + @Override + public List<String> airQualityBulletin(String regionCode, Date time) { + List<String> result = new ArrayList<>(); + //��������������� + QueryWrapper<CityAqiDaily> dailyWrapper = new QueryWrapper<>(); + dailyWrapper.eq("city_code", regionCode); + dailyWrapper.eq("time", time); + CityAqiDaily cityAqiDaily = cityAqiDailyMapper.selectOne(dailyWrapper); + if (cityAqiDaily == null) + return null; + Map<String, Object> dailyDataMap = JSON.parseObject(cityAqiDaily.getValue(), Map.class); + //��������������� + int year = DateUtils.getYear(time); + int month = DateUtils.getMonth(time); + int day = DateUtils.getDay(time); + //������������title + String title = getBulletinTitle(month + "", day + ""); + if (title == null) + return null; + //��������������������������� + String paragraphOne = getParagraphOne(month + "", day + "", dailyDataMap); + if (paragraphOne == null) + return null; + //��������������������� + List<String> paragraphTwoAndFour = getParagraphTwoAndFour(year + "", month + "", day + "", regionCode, time); + if (paragraphTwoAndFour == null) + return null; + String paragraphTwo = paragraphTwoAndFour.get(0); + //��������������������������� + String paragraphThree = getParagraphThree(month + "", day + "", regionCode, time); + if (paragraphThree == null) + return null; + //��������������������� + String paragraphFour = paragraphTwoAndFour.get(1); + result.add(title); + result.add(paragraphOne); + result.add(paragraphTwo); + result.add(paragraphThree); + result.add(paragraphFour); + return result; + } + + //������������title������ + private String getBulletinTitle(String month, String day) { + String title = bulletinProperties.getTitle(); + title = title.replace("{month}", month); + title = title.replace("{day}", day); + return title; + } + + //��������������������������� + private String getParagraphOne(String month, String day, Map<String, Object> dailyData) { + //������������������ + String pollutionLevelDescribe = AQIUtils.classOfPollutionByAqi(Integer.parseInt(dailyData.get("AQI").toString())); + String pollutionLevel = AQIUtils.classCodeOfPollutionByAqi(Integer.parseInt(dailyData.get("AQI").toString())); + //��������������������������� + int standardCount = AQIUtils.standardCount(dailyData); + String paragraphOne = bulletinProperties.getParagraphOne(); + paragraphOne = paragraphOne.replace("{month}", month); + paragraphOne = paragraphOne.replace("{day}", day); + paragraphOne = paragraphOne.replace("{pollutionLevel}", pollutionLevel); + paragraphOne = paragraphOne.replace("{pollutionLevelDescribe}", pollutionLevelDescribe); + paragraphOne = paragraphOne.replace("{standardCount}", standardCount + ""); + paragraphOne = paragraphOne.replace("{PM2.5}", dailyData.get("PM2_5").toString()); + paragraphOne = paragraphOne.replace("{SO2}", dailyData.get("SO2").toString()); + paragraphOne = paragraphOne.replace("{NO2}", dailyData.get("NO2").toString()); + paragraphOne = paragraphOne.replace("{CO}", dailyData.get("CO").toString()); + paragraphOne = paragraphOne.replace("{O3}", dailyData.get("O3").toString()); + paragraphOne = paragraphOne.replace("{PM10}", dailyData.get("PM10").toString()); + return paragraphOne; + } + + //��������������������������������������� + private List<String> getParagraphTwoAndFour(String year, String month, String day, String regionCode, Date time) { + List<String> result = new ArrayList<>(); + String paragraphTwo = bulletinProperties.getParagraphTwo(); + String paragraphFour = bulletinProperties.getParagraphFour(); + Date startTime = DateUtils.getFirstDayOfYear(time); + Date endTime = time; + Date compareStartTime = DateUtils.addMonths(startTime, -12); + Date compareEndTime = DateUtils.addMonths(endTime, -12); + SysArea area = new SysArea(); + area.setAreaCode(Integer.parseInt(regionCode)); + //������������������������ + CityPollutionLevel days = calculateDaysByTimeAndSysArea(area, startTime, endTime); + //������������������������������ + CityPollutionLevel compareDays = calculateDaysByTimeAndSysArea(area, compareStartTime, compareEndTime); + if (days == null || compareDays == null) + return null; + //������������������ + List<CityAqiYearly> yearDataList = cityAqiYearlyService.getCityAqiYearlyByRegionCodeAndTime(Integer.parseInt(regionCode), startTime, endTime); + List<CityAqiYearly> compareYearDataList = cityAqiYearlyService.getCityAqiYearlyByRegionCodeAndTime(Integer.parseInt(regionCode), compareStartTime, compareEndTime); + if (ObjectUtils.isEmpty(yearDataList) || ObjectUtils.isEmpty(compareYearDataList)) + return null; + CityAqiYearly yearData = yearDataList.get(0); + CityAqiYearly compareYearData = compareYearDataList.get(0); + Map<String, Object> dataMap = JSON.parseObject(yearData.getValue(), Map.class); + Map<String, Object> compareDataMap = JSON.parseObject(compareYearData.getValue(), Map.class); + //��������������������� + String yearPM_5 = dataMap.get("PM2_5").toString(); + String fineDays = days.getExcellentWeatherDays() + days.getGoodWeatherDays() + ""; + int allDays = DateUtils.getDays(startTime, endTime) + 1; + paragraphTwo = paragraphTwo.replace("{year}", year); + paragraphTwo = paragraphTwo.replace("{yearPM2.5}", yearPM_5); + paragraphTwo = paragraphTwo.replace("{fineDays}", fineDays); + paragraphTwo = paragraphTwo.replace("{days}", allDays + ""); + result.add(paragraphTwo); + + //��������������������� + //������������������������ + Double compositeIndex = Double.valueOf(dataMap.get("compositeIndex").toString()); + Double compareCompositeIndex = Double.valueOf(compareDataMap.get("compositeIndex").toString()); + //������������������������������������ + String yoyYearCompositeIndexUpDown = getUpOrDown(compositeIndex, compareCompositeIndex); + //������������������������������������������ + String yoyYearCompositeIndex = calculateComparePerPositive(compositeIndex, compareCompositeIndex).toString(); + + //������������PM2.5 + Double PM2_5 = Double.valueOf(dataMap.get("PM2_5").toString()); + Double comparePM2_5 = Double.valueOf(compareDataMap.get("PM2_5").toString()); + //������PM2.5������������������ + String yoyYearPM2_5UpDown = getUpOrDown(PM2_5, comparePM2_5); + //������PM2.5������������������������ + String yoyYearPM2_5 = calculateComparePerPositive(PM2_5, comparePM2_5).toString(); + + //������������������������ + int yearFineDays = days.getExcellentWeatherDays() + days.getGoodWeatherDays(); + //������������������������������ + int compareYearFineDays = compareDays.getExcellentWeatherDays() + days.getGoodWeatherDays(); + //������������������������ + int yoyYearFineDaysInt = yearFineDays - compareYearFineDays; + String yoyYearFineDays = yoyYearFineDaysInt > 0 ? yoyYearFineDaysInt + "" : yoyYearFineDaysInt * (-1) + ""; + //��������������������������������� + String yoyYearFineDaysUpDown = getIncreaseOrDecrease(yearFineDays, compareYearFineDays); + //������������������������ + int yearPollutionDays = days.getMildWeatherDays() + days.getMiddleWeatherDays() + days.getSeriousWeatherDays() + days.getServerWeatherDays(); + //������������������������������ + String yearFineDaysPer = String.valueOf(MathUtils.division(yearFineDays * 100, allDays, 2)); + + //������168������������������������������������������������������ + List<Integer> oneSixEightRanges = rangeByCities(compositeIndex, + calculateCompare(compositeIndex, compareCompositeIndex), + startTime, endTime, compareStartTime, compareEndTime, + specialCitiesProperties.getOneSixEightCities()); + + //������28������������������������������������������������������ + List<Integer> twentyEightRanges = rangeByCities(compositeIndex, + calculateCompare(compositeIndex, compareCompositeIndex), + startTime, endTime, compareStartTime, compareEndTime, + specialCitiesProperties.getTwentyEightCities()); + + String compositeIndex28range = twentyEightRanges.get(0).toString(); + String compositeIndexPer28range = twentyEightRanges.get(1).toString(); + 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); + result.add(paragraphFour); + return result; + } + + //������������������������������������������������������ + private List<Integer> rangeByCities( + 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) { + //������������ + 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)) + 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); + //������������������ + compositeIndexList.add(Double.valueOf(dataMap.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)); + } + + //��������������������������� + private String getParagraphThree(String month, String day, String regionCode, Date time) { + String paragraphThree = bulletinProperties.getParagraphThree(); + //������������������������ + CityAqiMonthly monthlyData = cityAqiMonthlyService.getCityAqiMonthByRegionCodeAndTime(Integer.parseInt(regionCode), time); + //������������������������ + Date compareTime = DateUtils.addMonths(time, -12); + CityAqiMonthly compareMonthlyData = cityAqiMonthlyService.getCityAqiMonthByRegionCodeAndTime(Integer.parseInt(regionCode), compareTime); + if (monthlyData == null || compareMonthlyData == null) + return null; + Map<String, Object> monthlyDataMap = JSON.parseObject(monthlyData.getValue(), Map.class); + Map<String, Object> compareMonthlyDataMap = JSON.parseObject(compareMonthlyData.getValue(), Map.class); + //������������������ + Date endTime = time; + Date startTime = DateUtils.getFirstDayOfMonth(time); + Date compareStartTime = DateUtils.addMonths(startTime, -12); + Date compareEndTime = DateUtils.addMonths(endTime, -12); + SysArea area = new SysArea(); + area.setAreaCode(Integer.parseInt(regionCode)); + CityPollutionLevel days = calculateDaysByTimeAndSysArea(area, startTime, endTime); + CityPollutionLevel compareDays = calculateDaysByTimeAndSysArea(area, compareStartTime, compareEndTime); + if (days == null || compareDays == null) + return null; + //������������������������ + Double compositeIndex = Double.valueOf(monthlyDataMap.get("compositeIndex").toString()); + Double compareCompositeIndex = Double.valueOf(compareMonthlyDataMap.get("compositeIndex").toString()); + //������������������������������������ + String yoyMonthCompositeIndexUpDown = getUpOrDown(compositeIndex, compareCompositeIndex); + //������������������������������������������ + String yoyMonthCompositeIndex = calculateComparePerPositive(compositeIndex, compareCompositeIndex).toString(); + + //������������PM2.5 + Double PM2_5 = Double.valueOf(monthlyDataMap.get("PM2_5").toString()); + Double comparePM2_5 = Double.valueOf(compareMonthlyDataMap.get("PM2_5").toString()); + //������PM2.5������������������ + String yoyMonthPM2_5UpDown = getUpOrDown(PM2_5, comparePM2_5); + //������PM2.5������������������������ + String yoyMonthPM2_5 = calculateComparePerPositive(PM2_5, comparePM2_5).toString(); + + //������������������������ + int monthFineDays = days.getExcellentWeatherDays() + days.getGoodWeatherDays(); + //������������������������������ + int compareMonthFineDays = compareDays.getExcellentWeatherDays() + days.getGoodWeatherDays(); + //������������������������ + int yoyMonthFineDaysInt = monthFineDays - compareMonthFineDays; + String yoyMonthFineDays = yoyMonthFineDaysInt > 0 ? yoyMonthFineDaysInt + "" : yoyMonthFineDaysInt * (-1) + ""; + //��������������������������������� + String yoyMonthFineDaysUpDown = getIncreaseOrDecrease(monthFineDays, compareMonthFineDays); + + paragraphThree = paragraphThree.replace("{month}", month); + paragraphThree = paragraphThree.replace("{day}", day); + paragraphThree = paragraphThree.replace("{monthCompositeIndex}", compositeIndex.toString()); + paragraphThree = paragraphThree.replace("{yoyMonthCompositeIndex}", yoyMonthCompositeIndex); + paragraphThree = paragraphThree.replace("{yoyMonthCompositeIndexUpDown}", yoyMonthCompositeIndexUpDown); + paragraphThree = paragraphThree.replace("{monthPM2.5}", PM2_5.toString()); + paragraphThree = paragraphThree.replace("{yoyMonthPM2.5UpDown}", yoyMonthPM2_5UpDown); + paragraphThree = paragraphThree.replace("{yoyMonthPM2.5}", yoyMonthPM2_5); + paragraphThree = paragraphThree.replace("{monthFineDays}", monthFineDays + ""); + paragraphThree = paragraphThree.replace("{yoyMonthFineDaysUpDown}", yoyMonthFineDaysUpDown); + paragraphThree = paragraphThree.replace("{yoyMonthFineDays}", yoyMonthFineDays); + return paragraphThree; + } + + //������currentData���compareData���������������"������","������".currentData>compareData��������������� + private String getUpOrDown(Double currentData, Double compareData) { + if (MathUtils.sub(currentData, compareData) > 0) + return "������"; + return "������"; + } + + //������������������������������������������������������������"������","������".currentData>compareData��������������� + private String getIncreaseOrDecrease(int currentDays, int compareDays) { + if (currentDays - compareDays > 0) + return "������"; + return "������"; + } + + + //������������������/������������ ���������������������-���������������/������������ ��������������� + private Double calculateComparePerPositive(Double currentData, Double compareData) { + double tmp1 = MathUtils.sub(currentData, compareData); + 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); + } + + + //��������������������������������������� ������������ ������������ + 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