|
@@ -26,6 +26,8 @@ import org.springblade.manager.feign.ProjectClient;
|
|
|
import org.springblade.manager.feign.ProjectContractAreaClient;
|
|
|
import org.springblade.manager.vo.ContractInfoVO;
|
|
|
import org.springframework.dao.DataAccessException;
|
|
|
+import org.springframework.data.redis.core.RedisTemplate;
|
|
|
+import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.jdbc.core.ResultSetExtractor;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
@@ -54,6 +56,8 @@ public class WeatherInfoServiceImpl extends ServiceImpl<WeatherInfoMapper, Weath
|
|
|
|
|
|
private final JdbcTemplate jdbcTemplate;
|
|
|
|
|
|
+ private final StringRedisTemplate stringRedisTemplate;
|
|
|
+
|
|
|
/**
|
|
|
* 根据所选年份获取当年所有天气台账
|
|
|
*/
|
|
@@ -138,11 +142,19 @@ public class WeatherInfoServiceImpl extends ServiceImpl<WeatherInfoMapper, Weath
|
|
|
Map<String, String> weatherMap = cachedWeatherMap.get(area.getCity_code());
|
|
|
if (weatherMap == null) {
|
|
|
//获取天气信息(百度天气)
|
|
|
- weatherMap = YiKeYunApiUtils.getTodayWeatherByAdcode(area.getCity_code() + "000000");
|
|
|
+ String nums = stringRedisTemplate.opsForValue().get("blade-business::contractArea:yiKeYun:todayWeatherNums");
|
|
|
+ if (nums != null && Integer.parseInt(nums) <= 19000) {
|
|
|
+ weatherMap = YiKeYunApiUtils.getTodayWeatherByAdcode(area.getCity_code() + "000000");
|
|
|
+ }
|
|
|
if (weatherMap == null) {
|
|
|
weatherMap = BaiduApiUtil.getTodayWeather(area.getCity_code());
|
|
|
}
|
|
|
- cachedWeatherMap.put(area.getCity_code(), weatherMap);
|
|
|
+ if (weatherMap != null) {
|
|
|
+ cachedWeatherMap.put(area.getCity_code(), weatherMap);
|
|
|
+ if (weatherMap.get("nums") != null) {
|
|
|
+ stringRedisTemplate.opsForValue().set("blade-business::contractArea:yiKeYun:todayWeatherNums", weatherMap.get("nums"));
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
if (weatherMap != null) {
|
|
|
//计算平均气温
|
|
@@ -406,6 +418,11 @@ public class WeatherInfoServiceImpl extends ServiceImpl<WeatherInfoMapper, Weath
|
|
|
}
|
|
|
|
|
|
public Map<String, Map<String, String>> getHistoryWeather(ProjectContractArea area, String month) {
|
|
|
+ String nums = stringRedisTemplate.opsForValue().get("blade-business::contractArea:yiKeYun:historyWeatherNums");
|
|
|
+ if (nums == null || Integer.parseInt(nums) > 19000) {
|
|
|
+ log.info("获取历史天气失败:易客云获取历史天气的api次数已用完。");
|
|
|
+ return null;
|
|
|
+ }
|
|
|
String county = area.getCounty();
|
|
|
if (county.length() > 2) {
|
|
|
county = county.substring(0, county.length() - 1);
|
|
@@ -425,6 +442,12 @@ public class WeatherInfoServiceImpl extends ServiceImpl<WeatherInfoMapper, Weath
|
|
|
}
|
|
|
if (cityId != null) {
|
|
|
Map<String, Map<String, String>> historyWeather = YiKeYunApiUtils.getHistoryWeather(cityId, Integer.parseInt(month.substring(0, 4)), Integer.parseInt(month.substring(4, 6)));
|
|
|
+ if (historyWeather != null) {
|
|
|
+ Map<String, String> map = historyWeather.get("nums");
|
|
|
+ if (map != null && map.get("nums") != null) {
|
|
|
+ stringRedisTemplate.opsForValue().set("blade-business::contractArea:yiKeYun:historyWeatherNums", map.get("nums"));
|
|
|
+ }
|
|
|
+ }
|
|
|
return historyWeather;
|
|
|
} else {
|
|
|
log.info("获取历史天气失败:" + area.getCity()+"-"+area.getCounty());
|