提交RegionalWeatherData-定时同步代码

This commit is contained in:
yufengshuo 2026-03-18 10:41:32 +08:00
parent 186a3db27c
commit f8454295e9
6 changed files with 72 additions and 7 deletions

View File

@ -23,4 +23,6 @@ public interface NationalWeatherStationMapper extends BaseMapper<NationalWeather
@Param("startTime") String startTime,
@Param("endTime") String endTime
);
List<NationalWeatherStation> getSyncData(@Param("prevHourDate") String prevHourDate);
}

View File

@ -20,4 +20,6 @@ public interface RegionalWeatherStationMapper extends BaseMapper<RegionalWeather
@Param("startTime") String startTime,
@Param("endTime") String endTime
);
List<RegionalWeatherStation> getSyncData(@Param("prevHourDate") String prevHourDate);
}

View File

@ -1,6 +1,5 @@
package com.southern.power.grid.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.southern.power.grid.dao.NationalWeatherStationMapper;
import com.southern.power.grid.dao.RegionalWeatherDataMapper;
@ -40,11 +39,10 @@ public class RegionalWeatherDataServiceImpl extends ServiceImpl<RegionalWeatherD
try {
//获取当前时间前一个整点时间
String prevHourDate = LocalDateTime.now().minusHours(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:00:00"));
List<RegionalWeatherStation> regionalWeatherStations = regionalWeatherStationMapper.selectList(new LambdaQueryWrapper<RegionalWeatherStation>()
.eq(RegionalWeatherStation::getDataTime, prevHourDate));
List<NationalWeatherStation> nationalWeatherStations = nationalWeatherStationMapper.selectList(new LambdaQueryWrapper<NationalWeatherStation>()
.eq(NationalWeatherStation::getDataTime, prevHourDate));
List<RegionalWeatherStation> regionalWeatherStations = regionalWeatherStationMapper.getSyncData(prevHourDate);
List<NationalWeatherStation> nationalWeatherStations = nationalWeatherStationMapper.getSyncData(prevHourDate);
if (CollectionUtils.isEmpty(regionalWeatherStations) && CollectionUtils.isEmpty(nationalWeatherStations)) {
log.warn("【区域天气数据同步任务】没有查询到天气数据:{}", prevHourDate);
return;
}
loadWeatherAreaConfig();

View File

@ -2,6 +2,7 @@ package com.southern.power.grid.task;
import com.southern.power.grid.service.IRegionalWeatherDataService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
@ -17,12 +18,18 @@ public class WeatherDataScheduleTask {
// 防止并发执行
private final AtomicBoolean running = new AtomicBoolean(false);
/* @PostConstruct
public void init(){
log.info("【区域天气数据同步任务】项目启动触发");
execute();
}*/
/**
* 每小时第20分钟执行
*/
//@Scheduled(cron = "0 20 * * * ?")
@Scheduled(cron = "0 20 * * * ?")
public void schedule() {
log.info("【区域天气数据同步任务】定时触发");
log.info("【区域天气数据同步任务】定时触发--开始");
execute();
}
@ -37,6 +44,7 @@ public class WeatherDataScheduleTask {
try {
regionalWeatherDataService.scheduleSyncWeatherData();
log.info("【区域天气数据同步任务】定时触发--结束");
} catch (Exception e) {
log.error("【区域天气数据同步任务】执行异常", e);
} finally {

View File

@ -65,4 +65,32 @@
AND data_time &lt;= #{endTime}
ORDER BY data_time
</select>
<select id="getSyncData" resultType="com.southern.power.grid.entity.NationalWeatherStation">
select id,
data_time,
hourly_max_pressure,
hourly_min_pressure,
temperature,
hourly_max_temperature,
hourly_min_temperature,
dew_point_temperature,
relative_humidity,
water_vapor_pressure,
hourly_precipitation,
daily_precipitation,
max_wind_direction_hourly,
max_wind_speed_hourly,
instantaneous_wind_direction,
instantaneous_wind_speed,
extreme_wind_direction_hourly,
extreme_wind_speed_hourly,
extreme_wind_time_hourly,
min_visibility_hourly,
province,
city,
district
from national_weather_station
where data_time = #{prevHourDate}
</select>
</mapper>

View File

@ -65,4 +65,31 @@
AND data_time &lt;= #{endTime}
ORDER BY data_time
</select>
<select id="getSyncData" resultType="com.southern.power.grid.entity.RegionalWeatherStation">
select id,
data_time,
hourly_max_pressure,
hourly_min_pressure,
temperature,
hourly_max_temperature,
hourly_min_temperature,
dew_point_temperature,
relative_humidity,
hourly_precipitation,
daily_precipitation,
max_wind_direction_hourly,
max_wind_speed_hourly,
instantaneous_wind_direction,
instantaneous_wind_speed,
extreme_wind_direction_hourly,
extreme_wind_speed_hourly,
extreme_wind_time_hourly,
min_visibility_hourly,
province,
city,
district
from regional_weather_station
where data_time = #{prevHourDate}
</select>
</mapper>