| | |
| | | package com.moral.api.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.moral.api.config.properties.SpecialCitiesProperties; |
| | | import com.moral.api.entity.CityAqiDaily; |
| | | import com.moral.api.entity.SysArea; |
| | | import com.moral.api.mapper.CityAqiDailyMapper; |
| | | import com.moral.api.pojo.dto.cityAQI.PieChartOfPollutionLevelDTO; |
| | | import com.moral.api.pojo.form.aqi.QueryPieChartOfPollutionLevelForm; |
| | | import com.moral.api.pojo.dto.cityAQI.CityPollutionLevel; |
| | | 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.PieChartOfPollutionLevelVO; |
| | | 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.ComprehensiveIndexUtils; |
| | | import com.moral.util.DateUtils; |
| | | import com.moral.util.MathUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.ObjectUtils; |
| | | |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | |
| | | /** |
| | |
| | | |
| | | @Autowired |
| | | CityAqiDailyMapper cityAqiDailyMapper; |
| | | @Autowired |
| | | SysAreaService sysAreaService; |
| | | @Autowired |
| | | SpecialCitiesProperties specialCitiesProperties; |
| | | |
| | | @Override |
| | | public PieChartOfPollutionLevelDTO queryPieChartOfPollutionLevels(QueryPieChartOfPollutionLevelForm form) { |
| | | 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) { |
| | | //取参 |
| | | Integer regionCode = form.getRegionCode(); |
| | | Date startDate = form.getStartDate(); |
| | | Date endDate = form.getEndDate(); |
| | | //查询数据 |
| | | QueryWrapper<CityAqiDaily> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("city_code",regionCode); |
| | | wrapper.between("time",startDate,endDate); |
| | | wrapper.eq("city_code", regionCode); |
| | | wrapper.between("time", startDate, endDate); |
| | | List<CityAqiDaily> cityAqiDailies = cityAqiDailyMapper.selectList(wrapper); |
| | | //取开始结束时间,拼装返回time |
| | | if(cityAqiDailies.size()==0) |
| | | if (cityAqiDailies.size() == 0) |
| | | return null; |
| | | String startTime = DateUtils.dateToDateString(cityAqiDailies.get(0).getTime(),"yyyy-MM-dd"); |
| | | String endTime = DateUtils.dateToDateString(cityAqiDailies.get(cityAqiDailies.size()-1).getTime(),"yyyy-MM-dd"); |
| | | String time = startTime+" 至 "+endTime; |
| | | String startTime = DateUtils.dateToDateString(cityAqiDailies.get(0).getTime(), "yyyy-MM-dd"); |
| | | String endTime = DateUtils.dateToDateString(cityAqiDailies.get(cityAqiDailies.size() - 1).getTime(), "yyyy-MM-dd"); |
| | | String time = startTime + " 至 " + endTime; |
| | | //如果数据的时间有重复则去重 |
| | | Map<String,CityAqiDaily> tmpMap = new HashMap<>(); |
| | | Map<String, CityAqiDaily> tmpMap = new HashMap<>(); |
| | | for (CityAqiDaily cityAqiDaily : cityAqiDailies) { |
| | | String tmpTime = DateUtils.dateToDateString(cityAqiDaily.getTime(),"yyyy-MM-dd"); |
| | | tmpMap.put(tmpTime,cityAqiDaily); |
| | | 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); |
| | | 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) |
| | | 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); |
| | | pollutionDaysMap.put(pollutionClass, days + 1); |
| | | } |
| | | //计算比例 |
| | | List<Map<String,Object>> valueMap = new ArrayList<>(); |
| | | List<Map<String, Object>> valueMap = new ArrayList<>(); |
| | | Set<Map.Entry<String, Integer>> entries = pollutionDaysMap.entrySet(); |
| | | Iterator<Map.Entry<String, Integer>> iterator = entries.iterator(); |
| | | Integer totalDays = 0; |
| | | while(iterator.hasNext()){ |
| | | while (iterator.hasNext()) { |
| | | Map.Entry<String, Integer> entry = iterator.next(); |
| | | Map<String,Object> pollutionMap = new HashMap<>(); |
| | | Map<String, Object> pollutionMap = new HashMap<>(); |
| | | String pollution = entry.getKey(); |
| | | Integer days = entry.getValue(); |
| | | Double proportionTmp = MathUtils.division(Double.valueOf(days),Double.valueOf(cityAqiDailies.size()),3); |
| | | Double proportionD = MathUtils.mul(proportionTmp,100); |
| | | String proportion = proportionD.toString()+"%"; |
| | | pollutionMap.put("proportion",proportion); |
| | | pollutionMap.put("pollution",pollution); |
| | | pollutionMap.put("days",days); |
| | | Double proportionTmp = MathUtils.division(Double.valueOf(days), Double.valueOf(cityAqiDailies.size()), 3); |
| | | Double proportionD = MathUtils.mul(proportionTmp, 100); |
| | | String proportion = proportionD.toString() + "%"; |
| | | pollutionMap.put("proportion", proportion); |
| | | pollutionMap.put("pollution", pollution); |
| | | pollutionMap.put("days", days); |
| | | valueMap.add(pollutionMap); |
| | | totalDays+=days; |
| | | totalDays += days; |
| | | } |
| | | //封装返回对象 |
| | | PieChartOfPollutionLevelDTO dto = new PieChartOfPollutionLevelDTO(); |
| | | dto.setTime(time); |
| | | dto.setValues(valueMap); |
| | | dto.setTotalDays(totalDays); |
| | | return dto; |
| | | PieChartOfPollutionLevelVO VO = new PieChartOfPollutionLevelVO(); |
| | | VO.setTime(time); |
| | | VO.setValues(valueMap); |
| | | VO.setTotalDays(totalDays); |
| | | return VO; |
| | | } |
| | | |
| | | @Override |
| | | public List<MonthlyPollutionLevel> queryBarChartOfPollutionLevels(ChartOfPollutionLevelForm form) { |
| | | //取参 |
| | | Integer regionCode = form.getRegionCode(); |
| | | Date startDate = form.getStartDate(); |
| | | Date endDate = form.getEndDate(); |
| | | //查询数据 |
| | | QueryWrapper<CityAqiDaily> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("city_code", regionCode); |
| | | 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, List<CityAqiDaily>> monthlyDataMap = new LinkedHashMap<>(); |
| | | cityAqiDailies.forEach(value -> { |
| | | String month = DateUtils.dateToDateString(value.getTime(), "yyyy-MM"); |
| | | List<CityAqiDaily> dataList = monthlyDataMap.get(month); |
| | | if (ObjectUtils.isEmpty(dataList)) |
| | | dataList = new ArrayList<>(); |
| | | dataList.add(value); |
| | | monthlyDataMap.put(month, dataList); |
| | | }); |
| | | //计算污染天数和比例 |
| | | List<MonthlyPollutionLevel> monthlyPollutionLevels = new ArrayList<>(); |
| | | Set<Map.Entry<String, List<CityAqiDaily>>> monthlyEntries = monthlyDataMap.entrySet(); |
| | | Iterator<Map.Entry<String, List<CityAqiDaily>>> monthlyIterator = monthlyEntries.iterator(); |
| | | while (monthlyIterator.hasNext()) { |
| | | Map.Entry<String, List<CityAqiDaily>> monthlyEntry = monthlyIterator.next(); |
| | | List<CityAqiDaily> monthlyValues = monthlyEntry.getValue(); |
| | | //用于统计各个污染等级的天数 |
| | | 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 : monthlyValues) { |
| | | 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); |
| | | } |
| | | |
| | | //计算比例 |
| | | List<PollutionDaysAndProportion> pollutionDaysAndProportions = new ArrayList<>(); |
| | | Set<Map.Entry<String, Integer>> entries = pollutionDaysMap.entrySet(); |
| | | Iterator<Map.Entry<String, Integer>> iterator = entries.iterator(); |
| | | while (iterator.hasNext()) { |
| | | Map.Entry<String, Integer> entry = iterator.next(); |
| | | String pollution = entry.getKey(); |
| | | Integer days = entry.getValue(); |
| | | Double proportionTmp = MathUtils.division(Double.valueOf(days), Double.valueOf(monthlyValues.size()), 3); |
| | | Double proportionD = MathUtils.mul(proportionTmp, 100); |
| | | String proportion = proportionD.toString() + "%"; |
| | | PollutionDaysAndProportion pollutionDaysAndProportion = new PollutionDaysAndProportion(); |
| | | pollutionDaysAndProportion.setDays(days); |
| | | pollutionDaysAndProportion.setPollutionLevel(pollution); |
| | | pollutionDaysAndProportion.setProportion(proportion); |
| | | pollutionDaysAndProportions.add(pollutionDaysAndProportion); |
| | | } |
| | | //封装返回对象 |
| | | MonthlyPollutionLevel monthlyPollutionLevel = new MonthlyPollutionLevel(); |
| | | monthlyPollutionLevel.setPollutionDaysAndProportions(pollutionDaysAndProportions); |
| | | monthlyPollutionLevel.setTime(monthlyEntry.getKey()); |
| | | monthlyPollutionLevels.add(monthlyPollutionLevel); |
| | | } |
| | | return monthlyPollutionLevels; |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Map<String, Object>> oneYearsData(Map map) { |
| | | int city_code = Integer.parseInt(map.get("cityCode").toString()); |
| | | String year = map.get("year").toString(); |
| | | String startTime = year + "-01-01 00:00:00"; |
| | | String endTime = year + "-12-31 23:59:59"; |
| | | QueryWrapper<CityAqiDaily> cityAqiDailyQueryWrapper = new QueryWrapper<>(); |
| | | cityAqiDailyQueryWrapper.eq("city_code", city_code); |
| | | cityAqiDailyQueryWrapper.between("time", startTime, endTime); |
| | | List<CityAqiDaily> cityAqiDailies = cityAqiDailyMapper.selectList(cityAqiDailyQueryWrapper); |
| | | Map<String, Map<String, Object>> resultMap = new HashMap<>(); |
| | | for (int i = 1; i < 13; i++) { |
| | | Map<String, Object> monthMap = new HashMap<>(); |
| | | String month = null; |
| | | if (i < 10) { |
| | | month = "0" + i; |
| | | } else { |
| | | month = String.valueOf(i); |
| | | } |
| | | String monthDate = year + "-" + month; |
| | | String monthFirstDay = year + "-" + month + "-01"; |
| | | int monthDay = DateUtils.getMonthDay(monthFirstDay); |
| | | for (int j = 1; j < monthDay + 1; j++) { |
| | | String day = null; |
| | | if (j < 10) { |
| | | day = "0" + j; |
| | | } else { |
| | | day = String.valueOf(j); |
| | | } |
| | | String dayDate = year + "-" + month + "-" + day; |
| | | monthMap.put(dayDate, null); |
| | | } |
| | | resultMap.put(monthDate, monthMap); |
| | | } |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | for (CityAqiDaily cityAqiDaily : cityAqiDailies) { |
| | | String time = sdf.format(cityAqiDaily.getTime()); |
| | | String monthDate = time.substring(0, 7); |
| | | String dayDate = time.substring(0, 10); |
| | | Double PM2_5 = null; |
| | | Double PM10 = null; |
| | | Double SO2 = null; |
| | | Double NO2 = null; |
| | | Double CO = null; |
| | | Double O3 = null; |
| | | String primaryPollutant = null; |
| | | String AQI = null; |
| | | String value = cityAqiDaily.getValue(); |
| | | JSONObject jsonObject = new 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("SO2"))) { |
| | | SO2 = (Double.parseDouble(jsonObject.get("SO2").toString())); |
| | | } |
| | | if (!ObjectUtils.isEmpty(jsonObject.get("NO2"))) { |
| | | NO2 = (Double.parseDouble(jsonObject.get("NO2").toString())); |
| | | } |
| | | if (!ObjectUtils.isEmpty(jsonObject.get("CO"))) { |
| | | CO = (Double.parseDouble(jsonObject.get("CO").toString())); |
| | | } |
| | | if (!ObjectUtils.isEmpty(jsonObject.get("O3"))) { |
| | | O3 = (Double.parseDouble(jsonObject.get("O3").toString())); |
| | | } |
| | | if (!ObjectUtils.isEmpty(jsonObject.get("primaryPollutant"))) { |
| | | primaryPollutant = jsonObject.get("primaryPollutant").toString(); |
| | | } |
| | | if (!ObjectUtils.isEmpty(jsonObject.get("AQI"))) { |
| | | AQI = jsonObject.get("AQI").toString(); |
| | | } |
| | | Map<String, Object> valueMap = new HashMap<>(); |
| | | valueMap.put("PM2_5", PM2_5); |
| | | valueMap.put("PM10", PM10); |
| | | valueMap.put("SO2", SO2); |
| | | valueMap.put("NO2", NO2); |
| | | valueMap.put("CO", CO); |
| | | valueMap.put("O3", O3); |
| | | valueMap.put("AQI", AQI); |
| | | valueMap.put("primaryPollutant", primaryPollutant); |
| | | Map<String, Object> monthMap = new HashMap<>(); |
| | | monthMap = resultMap.get(monthDate); |
| | | monthMap.put(dayDate, valueMap); |
| | | resultMap.put(monthDate, monthMap); |
| | | } |
| | | return resultMap; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public List<CityPollutionLevel> queryAreaPollutionLevel(AreaPollutionLevelForm form) { |
| | | //取参 |
| | | Integer regionCode = form.getRegionCode(); |
| | | Date startDate = form.getStartDate(); |
| | | Date endDate = form.getEndDate(); |
| | | //查询该市区下所有的县 |
| | | List<SysArea> allAreas = sysAreaService.getChildren(regionCode); |
| | | //创建返回数据对象 |
| | | List<CityPollutionLevel> datas = new ArrayList<>(); |
| | | //遍历每个县级市 查询数据 |
| | | for (SysArea area : allAreas) { |
| | | 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<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; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * @Description: 根据地区对象和开始结束时间计算污染天气 |
| | | * @Param: [area, startDate, endDate] |
| | | * @return: com.moral.api.pojo.dto.cityAQI.CityPollutionLevel |
| | | * @Author: 陈凯裕 |
| | | * @Date: 2021/12/31 |
| | | */ |
| | | @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); |
| | | //如果数据的时间有重复则去重 |
| | | 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; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | |