|
@@ -37,12 +37,10 @@ import java.io.IOException;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.sql.ResultSet;
|
|
|
import java.sql.SQLException;
|
|
|
-import java.time.Duration;
|
|
|
-import java.time.LocalDate;
|
|
|
-import java.time.LocalDateTime;
|
|
|
-import java.time.ZoneId;
|
|
|
+import java.time.*;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Slf4j
|
|
@@ -152,7 +150,7 @@ public class WeatherInfoServiceImpl extends ServiceImpl<WeatherInfoMapper, Weath
|
|
|
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"));
|
|
|
+ stringRedisTemplate.opsForValue().set("blade-business::contractArea:yiKeYun:todayWeatherNums", weatherMap.get("nums"), getSecondsUntilMidnight(), TimeUnit.SECONDS);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -419,7 +417,7 @@ 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) {
|
|
|
+ if (nums != null && Integer.parseInt(nums) > 19000) {
|
|
|
log.info("获取历史天气失败:易客云获取历史天气的api次数已用完。");
|
|
|
return null;
|
|
|
}
|
|
@@ -445,7 +443,7 @@ public class WeatherInfoServiceImpl extends ServiceImpl<WeatherInfoMapper, Weath
|
|
|
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"));
|
|
|
+ stringRedisTemplate.opsForValue().set("blade-business::contractArea:yiKeYun:historyWeatherNums", map.get("nums"), getSecondsUntilMidnight(), TimeUnit.SECONDS);
|
|
|
}
|
|
|
}
|
|
|
return historyWeather;
|
|
@@ -493,4 +491,10 @@ public class WeatherInfoServiceImpl extends ServiceImpl<WeatherInfoMapper, Weath
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
+ public static long getSecondsUntilMidnight() {
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ LocalDateTime nextMidnight = now.with(LocalTime.MIDNIGHT).plusDays(1);
|
|
|
+ return TimeUnit.MILLISECONDS.toSeconds(nextMidnight.atZone(java.time.ZoneId.systemDefault()).toInstant().toEpochMilli()
|
|
|
+ - now.atZone(java.time.ZoneId.systemDefault()).toInstant().toEpochMilli());
|
|
|
+ }
|
|
|
}
|