|
@@ -120,7 +120,7 @@ public class WeatherInfoServiceImpl extends ServiceImpl<WeatherInfoMapper, Weath
|
|
/**
|
|
/**
|
|
* 获取当前系统所有项目下所有合同段的当天天气
|
|
* 获取当前系统所有项目下所有合同段的当天天气
|
|
*/
|
|
*/
|
|
- @Scheduled(cron = "0 18 10 * * ?")
|
|
|
|
|
|
+ @Scheduled(cron = "0 10 0,6,12,18,23 * * ?")
|
|
public void syncWeatherInfo() {
|
|
public void syncWeatherInfo() {
|
|
if (!SystemUtils.isLinux()) {
|
|
if (!SystemUtils.isLinux()) {
|
|
return;
|
|
return;
|
|
@@ -128,12 +128,13 @@ public class WeatherInfoServiceImpl extends ServiceImpl<WeatherInfoMapper, Weath
|
|
//获取所有合同段的定位信息
|
|
//获取所有合同段的定位信息
|
|
List<ProjectContractArea> areaList = this.projectContractAreaClient.queryAllContractArea();
|
|
List<ProjectContractArea> areaList = this.projectContractAreaClient.queryAllContractArea();
|
|
Map<String, Map<String, String>> cachedWeatherMap = new HashMap<>();
|
|
Map<String, Map<String, String>> cachedWeatherMap = new HashMap<>();
|
|
|
|
+ String date = DateUtil.format(new Date(), "yyyy-MM-dd");
|
|
for (ProjectContractArea area : areaList) {
|
|
for (ProjectContractArea area : areaList) {
|
|
try {
|
|
try {
|
|
//校验当前区域是否已经获取当天日期(手动补填或自动获取)
|
|
//校验当前区域是否已经获取当天日期(手动补填或自动获取)
|
|
Map<String, Object> queryMap = new HashMap<>();
|
|
Map<String, Object> queryMap = new HashMap<>();
|
|
queryMap.put("contractAreaId", area.getId());
|
|
queryMap.put("contractAreaId", area.getId());
|
|
- queryMap.put("recordTime", DateUtil.format(new Date(), "yyyy-MM-dd"));
|
|
|
|
|
|
+ queryMap.put("recordTime", date);
|
|
//查询
|
|
//查询
|
|
long count = this.count(Condition.getQueryWrapper(queryMap, WeatherInfo.class));
|
|
long count = this.count(Condition.getQueryWrapper(queryMap, WeatherInfo.class));
|
|
if (count > 0) {
|
|
if (count > 0) {
|
|
@@ -146,30 +147,30 @@ public class WeatherInfoServiceImpl extends ServiceImpl<WeatherInfoMapper, Weath
|
|
String nums = stringRedisTemplate.opsForValue().get("blade-business::contractArea:yiKeYun:todayWeatherNums");
|
|
String nums = stringRedisTemplate.opsForValue().get("blade-business::contractArea:yiKeYun:todayWeatherNums");
|
|
if (nums == null || Integer.parseInt(nums) <= 19000) {
|
|
if (nums == null || Integer.parseInt(nums) <= 19000) {
|
|
// 重试三次
|
|
// 重试三次
|
|
- weatherMap = YiKeYunApiUtils.getTodayWeatherByAdcodeTry(area.getCity_code() + "000000");
|
|
|
|
- if (weatherMap != null) {
|
|
|
|
|
|
+// weatherMap = YiKeYunApiUtils.getTodayWeatherByAdcodeTry(area.getCity_code() + "000000");
|
|
|
|
+ Map<String, Map<String, String>> map = getHistoryWeather(area, date, date);
|
|
|
|
+ if (map != null && !map.isEmpty()) {
|
|
|
|
+ weatherMap = map.values().stream().findFirst().orElse( null);
|
|
|
|
+ }
|
|
|
|
+ if (weatherMap != null && !weatherMap.isEmpty()) {
|
|
cachedWeatherMap.put(area.getCity_code(), weatherMap);
|
|
cachedWeatherMap.put(area.getCity_code(), weatherMap);
|
|
if (weatherMap.get("nums") != null) {
|
|
if (weatherMap.get("nums") != null) {
|
|
stringRedisTemplate.opsForValue().set("blade-business::contractArea:yiKeYun:todayWeatherNums", weatherMap.get("nums"), getSecondsUntilMidnight(), TimeUnit.SECONDS);
|
|
stringRedisTemplate.opsForValue().set("blade-business::contractArea:yiKeYun:todayWeatherNums", weatherMap.get("nums"), getSecondsUntilMidnight(), TimeUnit.SECONDS);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- //获取天气信息(百度天气)
|
|
|
|
-// if (weatherMap == null) {
|
|
|
|
-// weatherMap = BaiduApiUtil.getTodayWeather(area.getCity_code());
|
|
|
|
-// }
|
|
|
|
}
|
|
}
|
|
- if (weatherMap != null) {
|
|
|
|
|
|
+ if (weatherMap != null && !weatherMap.isEmpty()) {
|
|
//计算平均气温
|
|
//计算平均气温
|
|
BigDecimal aver = (new BigDecimal(weatherMap.get("high")).add(new BigDecimal(weatherMap.get("low")))).divide(new BigDecimal("2"), 1, BigDecimal.ROUND_HALF_UP);
|
|
BigDecimal aver = (new BigDecimal(weatherMap.get("high")).add(new BigDecimal(weatherMap.get("low")))).divide(new BigDecimal("2"), 1, BigDecimal.ROUND_HALF_UP);
|
|
WeatherInfo newWeather = new WeatherInfo(String.valueOf(area.getId()), weatherMap.get("weather"), aver.toString(), weatherMap.get("high"), weatherMap.get("low"), weatherMap.get("windLevel"));
|
|
WeatherInfo newWeather = new WeatherInfo(String.valueOf(area.getId()), weatherMap.get("weather"), aver.toString(), weatherMap.get("high"), weatherMap.get("low"), weatherMap.get("windLevel"));
|
|
this.save(newWeather);
|
|
this.save(newWeather);
|
|
log.info("今日的天气已经同步完成!contractAreaId:" + area.getId() + ",syncTime:" + DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
|
|
log.info("今日的天气已经同步完成!contractAreaId:" + area.getId() + ",syncTime:" + DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
|
|
} else {
|
|
} else {
|
|
- log.info("获取今日的天气失败!contractAreaId:" + area.getId() + ",syncTime:" + DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
|
|
|
|
|
|
+ log.warn("获取今日的天气失败!contractAreaId:" + area.getId() + ",syncTime:" + DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- e.printStackTrace();
|
|
|
|
|
|
+ log.error("获取今日的天气失败!contractAreaId:" + area.getId() + ",syncTime:" + DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"), e);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
System.out.println("同步当天天气完成");
|
|
System.out.println("同步当天天气完成");
|
|
@@ -264,7 +265,7 @@ public class WeatherInfoServiceImpl extends ServiceImpl<WeatherInfoMapper, Weath
|
|
//判断集合中是否存在当前天气,如果不存在则获取
|
|
//判断集合中是否存在当前天气,如果不存在则获取
|
|
if (weatherMap == null || weatherMap.get(plainTime.format(DateTimeFormatter.ofPattern("yyyy年MM月dd日"))) == null) {
|
|
if (weatherMap == null || weatherMap.get(plainTime.format(DateTimeFormatter.ofPattern("yyyy年MM月dd日"))) == null) {
|
|
String month = plainTime.format(DateTimeFormatter.ofPattern("yyyyMM"));
|
|
String month = plainTime.format(DateTimeFormatter.ofPattern("yyyyMM"));
|
|
- weatherMap = this.getHistoryWeather(projectContractArea, month);
|
|
|
|
|
|
+ weatherMap = this.getHistoryWeather(projectContractArea, month, null);
|
|
if (weatherMap == null) {
|
|
if (weatherMap == null) {
|
|
weatherMap = this.getWeather(county.toString(), month);
|
|
weatherMap = this.getWeather(county.toString(), month);
|
|
if (weatherMap == null || weatherMap.get(plainTime.format(DateTimeFormatter.ofPattern("yyyy年MM月dd日"))) == null) {
|
|
if (weatherMap == null || weatherMap.get(plainTime.format(DateTimeFormatter.ofPattern("yyyy年MM月dd日"))) == null) {
|
|
@@ -361,7 +362,7 @@ public class WeatherInfoServiceImpl extends ServiceImpl<WeatherInfoMapper, Weath
|
|
Map<String, List<LocalDate>> map = missDate.stream().collect(Collectors.groupingBy(l -> l.format(DateTimeFormatter.ofPattern("yyyyMM"))));
|
|
Map<String, List<LocalDate>> map = missDate.stream().collect(Collectors.groupingBy(l -> l.format(DateTimeFormatter.ofPattern("yyyyMM"))));
|
|
for (String s : map.keySet()) {
|
|
for (String s : map.keySet()) {
|
|
//获取整月天气
|
|
//获取整月天气
|
|
- weatherMap = this.getHistoryWeather(area, s);
|
|
|
|
|
|
+ weatherMap = this.getHistoryWeather(area, s, null);
|
|
if (weatherMap == null) {
|
|
if (weatherMap == null) {
|
|
weatherMap = this.getWeather(county.toString(), s);
|
|
weatherMap = this.getWeather(county.toString(), s);
|
|
if (weatherMap == null || weatherMap.size() == 0) {
|
|
if (weatherMap == null || weatherMap.size() == 0) {
|
|
@@ -426,7 +427,7 @@ public class WeatherInfoServiceImpl extends ServiceImpl<WeatherInfoMapper, Weath
|
|
System.out.println("9999");
|
|
System.out.println("9999");
|
|
}
|
|
}
|
|
|
|
|
|
- public Map<String, Map<String, String>> getHistoryWeather(ProjectContractArea area, String month) {
|
|
|
|
|
|
+ public Map<String, Map<String, String>> getHistoryWeather(ProjectContractArea area, String month, String date) {
|
|
String nums = stringRedisTemplate.opsForValue().get("blade-business::contractArea:yiKeYun:historyWeatherNums");
|
|
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次数已用完。");
|
|
log.info("获取历史天气失败:易客云获取历史天气的api次数已用完。");
|
|
@@ -455,7 +456,7 @@ public class WeatherInfoServiceImpl extends ServiceImpl<WeatherInfoMapper, Weath
|
|
cityId = jdbcTemplate.queryForObject("select id from m_yikeyun_weather_city where cityZh like '" + county + "%'", String.class);
|
|
cityId = jdbcTemplate.queryForObject("select id from m_yikeyun_weather_city where cityZh like '" + county + "%'", String.class);
|
|
}
|
|
}
|
|
if (cityId != null) {
|
|
if (cityId != null) {
|
|
- Map<String, Map<String, String>> historyWeather = YiKeYunApiUtils.getHistoryWeather(cityId, Integer.parseInt(month.substring(0, 4)), Integer.parseInt(month.substring(4, 6)));
|
|
|
|
|
|
+ Map<String, Map<String, String>> historyWeather = YiKeYunApiUtils.getHistoryWeather(cityId, Integer.parseInt(month.substring(0, 4)), Integer.parseInt(month.substring(4, 6)), date);
|
|
if (historyWeather != null) {
|
|
if (historyWeather != null) {
|
|
Map<String, String> map = historyWeather.get("nums");
|
|
Map<String, String> map = historyWeather.get("nums");
|
|
if (map != null && map.get("nums") != null) {
|
|
if (map != null && map.get("nums") != null) {
|