TaskWeather.java 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package com.gyee.impala.schdule;
  2. import com.gyee.impala.common.util.DateUtil;
  3. import com.gyee.impala.model.decision.WfNwpData;
  4. import com.gyee.impala.model.master.Weatherforecast;
  5. import com.gyee.impala.service.decision.WfNwpDataService;
  6. import com.gyee.impala.service.master.WeatherforecastService;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.scheduling.annotation.Scheduled;
  9. import org.springframework.stereotype.Component;
  10. import java.util.ArrayList;
  11. import java.util.HashMap;
  12. import java.util.List;
  13. import java.util.Map;
  14. /**
  15. * 来自功率预测的天气数据同步至kudu样本库
  16. */
  17. @Component
  18. public class TaskWeather {
  19. @Autowired
  20. private WfNwpDataService nwpDataService;
  21. @Autowired
  22. private WeatherforecastService forecastService;
  23. private static Map<Integer, String> MAP_STATION = new HashMap<>();
  24. static {
  25. MAP_STATION.put(1, "NSS_FDC");
  26. MAP_STATION.put(2, "QS_FDC");
  27. MAP_STATION.put(3, "SBQ_FDC");
  28. MAP_STATION.put(4, "XS_FDC");
  29. MAP_STATION.put(5, "MHS_FDC");
  30. }
  31. @Scheduled(cron = "0 0 1 * * ?")
  32. public void weatherForecastTask(){
  33. MAP_STATION.forEach((k, v) -> {
  34. Weatherforecast forecast = forecastService.getOneMaxTimeByStation(v);
  35. if (forecast == null)
  36. return;
  37. String time = forecast.getTime();
  38. List<WfNwpData> ls = nwpDataService.getListByStationAndTime(k, DateUtil.parseStrtoDate(time, DateUtil.YYYY_MM_DD_HH_MM_SS), null);
  39. List<Weatherforecast> list = new ArrayList<>();
  40. ls.stream().forEach(obj -> {
  41. Weatherforecast wf = (Weatherforecast) new Weatherforecast().toData(obj);
  42. wf.toData(obj);
  43. wf.setStationen(v);
  44. list.add(wf);
  45. });
  46. forecastService.insertBatch(list);
  47. });
  48. }
  49. }