SaticScheduleTask.java 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. package cn.gyee.tamplate.task;
  2. import cn.gyee.tamplate.service.analysis.AnalysisNewService;
  3. import cn.gyee.tamplate.service.analysis.AnalysisService;
  4. import cn.gyee.tamplate.service.benchmark.BenchmarkService;
  5. import cn.gyee.tamplate.service.operation.OperationService;
  6. import cn.gyee.tamplate.util.DateUtils;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.context.annotation.Configuration;
  9. import org.springframework.scheduling.annotation.EnableScheduling;
  10. import org.springframework.scheduling.annotation.Scheduled;
  11. import javax.annotation.Resource;
  12. import java.text.ParseException;
  13. import java.time.LocalDateTime;
  14. /**
  15. * @ClassName : SaticScheduleTask
  16. * @Author : xieshengjie
  17. * @Date: 2021/1/21 19:43
  18. * @Description : 调度
  19. */
  20. @Configuration //1.主要用于标记配置类,兼备Component的效果。
  21. @EnableScheduling // 2.开启定时任务
  22. public class SaticScheduleTask {
  23. @Autowired
  24. private OperationService operationService;
  25. @Autowired
  26. private BenchmarkService benchmarkService;
  27. @Resource
  28. private AnalysisService analysisService;
  29. @Resource
  30. private AnalysisNewService analysisNewService;
  31. // //3.添加定时任务
  32. // /**
  33. // * 控制指令调度
  34. // */
  35. // @Scheduled(cron = "0 0 1 * * ?")
  36. // //或直接指定时间间隔,例如:5秒
  37. // //@Scheduled(fixedRate=5000)
  38. // private void configureTasks1() {
  39. // try {
  40. // operationService.opeMapTask();
  41. // } catch (ParseException e) {
  42. // e.printStackTrace();
  43. // }
  44. // }
  45. //
  46. // /**
  47. // * 值际五损调度
  48. // */
  49. // @Scheduled(cron = "0 0 2 * * ?")
  50. // //或直接指定时间间隔,例如:5秒
  51. // //@Scheduled(fixedRate=5000)
  52. // private void configureTasks2() {
  53. // try {
  54. // benchmarkService.createBeanchmarkList();
  55. // } catch (Exception e) {
  56. // e.printStackTrace();
  57. // }
  58. // }
  59. /**
  60. * 风电统计分析
  61. */
  62. @Scheduled(cron = "0 25 0 * * ?")
  63. //或直接指定时间间隔,例如:5秒
  64. //@Scheduled(fixedRate=5000)
  65. private void analysisTasks() {
  66. String yesterday = DateUtils.getYesterdayStr("yyyy-MM-dd");
  67. try {
  68. //保存主表
  69. analysisNewService.savaAnalysismain(yesterday, yesterday);
  70. //风电表底
  71. analysisNewService.saveAnalysisTableBottom(yesterday, yesterday);
  72. //风电工程
  73. analysisNewService.saveWindProject(yesterday, yesterday);
  74. //风电场站
  75. analysisNewService.saveWindStation(yesterday, yesterday);
  76. //公司
  77. analysisNewService.saveCompany(yesterday, yesterday);
  78. } catch (Exception e) {
  79. e.printStackTrace();
  80. }
  81. }
  82. /**
  83. * 光伏统计分析
  84. */
  85. @Scheduled(cron = "0 5 18 * * ?")
  86. //或直接指定时间间隔,例如:5秒
  87. //@Scheduled(fixedRate=5000)
  88. private void analysisGfTasks() {
  89. // String yesterday = DateUtils.getYesterdayStr("yyyy-MM-dd");
  90. String yesterday = DateUtils.toDate1(DateUtils.today());
  91. try {
  92. //主表
  93. analysisNewService.savaAnalysismain(yesterday, yesterday);
  94. //光伏主表
  95. analysisNewService.savaAnalysisGfmain(yesterday, yesterday);
  96. //下午6点的表底存储
  97. analysisNewService.saveAnalysisTableBottom1(yesterday, yesterday);
  98. //光伏表底存储
  99. analysisNewService.saveAnalysisGfTableBottom(yesterday, yesterday);
  100. //光伏项目
  101. analysisNewService.savePvProject(yesterday, yesterday);
  102. //光伏场站
  103. analysisNewService.savePvStation(yesterday, yesterday);
  104. } catch (Exception e) {
  105. e.printStackTrace();
  106. }
  107. }
  108. }