| | |
| | | import com.moral.api.service.CityAqiService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.moral.constant.RedisConstants; |
| | | import com.moral.util.AQIUtils; |
| | | import com.moral.util.DateUtils; |
| | | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | Map<String,Object> value = (Map<String, Object>) redisTemplate.opsForHash().get(RedisConstants.CITY_AQI,String.valueOf(regionCode)); |
| | | if(value==null) |
| | | value = queryCityAqiByRegionCodeFromDB(regionCode); |
| | | //根据AQI计算污染等级 |
| | | if(value==null||value.get("aqi")==null) |
| | | return null; |
| | | Integer aqi = Integer.parseInt(value.get("aqi").toString()); |
| | | String category = AQIUtils.classOfPollutionByAqi(aqi); |
| | | value.put("category",category); |
| | | return value; |
| | | } |
| | | |
| | |
| | | wrapper.orderByDesc("time"); |
| | | wrapper.last(true,"limit 1"); |
| | | CityAqi cityAqi = cityAqiMapper.selectOne(wrapper); |
| | | if(cityAqi==null) |
| | | return null; |
| | | String value = cityAqi.getValue(); |
| | | redisTemplate.opsForHash().put(RedisConstants.CITY_AQI,regionCode,value); |
| | | return JSON.parseObject(value,Map.class); |