| | |
| | | |
| | | //环比数据 |
| | | @Override |
| | | public List<Map<String, Object>> momData(Integer regionCode, Integer size, Integer current, Integer orgId) { |
| | | public Map<String, Object> momData(Integer regionCode, Integer size, Integer current, Integer orgId) { |
| | | Map<String,Object> result = new HashMap<>(); |
| | | 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); |
| | | Integer count = cityAqiMapper.selectCount(cityAqiQueryWrapper); |
| | | if (count==0){ |
| | | return result; |
| | | } |
| | | cityAqiQueryWrapper.orderByDesc("time"); |
| | | Page<CityAqi> resultPage = cityAqiMapper.selectPage(page, cityAqiQueryWrapper); |
| | | List<CityAqi> cityAqiList = resultPage.getRecords(); |
| | |
| | | List<CityAqi> cityAqiListNext = resultPageNext.getRecords(); |
| | | List<Map<String,Object>> resultList = new ArrayList<>(); |
| | | if (cityAqiList.size()==0){ |
| | | return resultList; |
| | | return result; |
| | | } |
| | | for (int i=0; i<cityAqiList.size(); i++) { |
| | | Map<String,Object> resultMap = new HashMap<>(); |
| | |
| | | } |
| | | 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+"。"); |
| | | String PM2_5_string = subZeroAndDot(PM2_5.toString()); |
| | | String PM10_string = subZeroAndDot(PM10.toString()); |
| | | String O3_string = subZeroAndDot(O3.toString()); |
| | | String PM2_5_change_string = subZeroAndDot(PM2_5_change.toString()); |
| | | String PM10_change_string = subZeroAndDot(PM10_change.toString()); |
| | | String O3_change_string = subZeroAndDot(O3_change.toString()); |
| | | resultMap.put("info",hour+"时,我市AQI:"+AQI+",等级:"+AQIIndex+"。与"+previousHour+"时相比,PM10:"+PM10_string+"微克/立方米,"+PM10_change_string+";PM2.5:"+PM2_5_string+"微克/立方米,"+PM2_5_change_string+";TVOC总量:"+String.format("%.2f", TVOC)+"毫克/立方米;O3:"+O3_string+"微克/立方米,"+O3_change_string+"。"); |
| | | 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 temp = null; |
| | | Integer humidity = null; |
| | | String windDir = ""; |
| | | Integer windScale = null; |
| | | if (!ObjectUtils.isEmpty(cityWeather)){ |
| | | 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()); |
| | | temp = Integer.parseInt(jsonObject.get("temp").toString()); |
| | | } |
| | | if (!ObjectUtils.isEmpty(jsonObject.get("humidity"))){ |
| | | humidity = Double.parseDouble(jsonObject.get("humidity").toString()); |
| | | humidity = Integer.parseInt(jsonObject.get("humidity").toString()); |
| | | } |
| | | if (!ObjectUtils.isEmpty(jsonObject.get("windDir"))){ |
| | | windDir = jsonObject.get("windDir").toString(); |
| | |
| | | windScale = Integer.parseInt(jsonObject.get("windScale").toString()); |
| | | } |
| | | } |
| | | resultMap.put("weatherCondition","当前天气状况:温度"+temp+"℃,湿度"+humidity+"%,"+windDir+windScale+"级。"); |
| | | } |
| | | String temp_string = ""; |
| | | if (temp!=null){ |
| | | temp_string = temp.toString(); |
| | | } |
| | | String humidity_string = ""; |
| | | if (humidity!=null){ |
| | | humidity_string = humidity.toString(); |
| | | } |
| | | String windScale_string = ""; |
| | | if (windScale!=null){ |
| | | windScale_string = windScale.toString(); |
| | | } |
| | | resultMap.put("weatherCondition","当前天气状况:温度"+temp_string+"℃,湿度"+humidity_string+"%,"+windDir+windScale_string+"级。"); |
| | | resultMap.put("auther","(七星瓢虫专家组)"); |
| | | resultList.add(resultMap); |
| | | } |
| | | return resultList; |
| | | result.put("totel",count); |
| | | result.put("resultList",resultList); |
| | | result.put("current",current); |
| | | int totalPageNumber = count/size; |
| | | if(count%size != 0){ |
| | | totalPageNumber += 1; |
| | | } |
| | | result.put("totalPageNumber",totalPageNumber); |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | |
| | | Double avg = MathUtils.division(sum, num, 2); |
| | | return avg; |
| | | } |
| | | |
| | | /** |
| | | * 使用java正则表达式去掉多余的.与0 |
| | | * @param s |
| | | * @return |
| | | */ |
| | | public static String subZeroAndDot(String s){ |
| | | if(s.indexOf(".") > 0){ |
| | | s = s.replaceAll("0+?$", "");//去掉多余的0 |
| | | s = s.replaceAll("[.]$", "");//如最后一位是.则去掉 |
| | | } |
| | | return s; |
| | | } |
| | | } |