package com.gyee.impala.schdule; import com.gyee.impala.common.util.DateUtil; import com.gyee.impala.model.decision.WfNwpData; import com.gyee.impala.model.master.Weatherforecast; import com.gyee.impala.service.decision.WfNwpDataService; import com.gyee.impala.service.master.WeatherforecastService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * 来自功率预测的天气数据同步至kudu样本库 */ @Component public class TaskWeather { @Autowired private WfNwpDataService nwpDataService; @Autowired private WeatherforecastService forecastService; private static Map MAP_STATION = new HashMap<>(); static { MAP_STATION.put(1, "NSS_FDC"); MAP_STATION.put(2, "QS_FDC"); MAP_STATION.put(3, "SBQ_FDC"); MAP_STATION.put(4, "XS_FDC"); MAP_STATION.put(5, "MHS_FDC"); } @Scheduled(cron = "0 0 1 * * ?") public void weatherForecastTask(){ MAP_STATION.forEach((k, v) -> { Weatherforecast forecast = forecastService.getOneMaxTimeByStation(v); if (forecast == null) return; String time = forecast.getTime(); List ls = nwpDataService.getListByStationAndTime(k, DateUtil.parseStrtoDate(time, DateUtil.YYYY_MM_DD_HH_MM_SS), null); List list = new ArrayList<>(); ls.stream().forEach(obj -> { Weatherforecast wf = (Weatherforecast) new Weatherforecast().toData(obj); wf.toData(obj); wf.setStationen(v); list.add(wf); }); forecastService.insertBatch(list); }); } }