StaticScheduleTask.java 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. package com.sooka.sponest.middleground.scheduleTask;
  2. import cn.hutool.json.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.ruoyi.common.core.utils.DateUtils;
  5. import com.sooka.sponest.middleground.controller.MonitorController;
  6. import com.sooka.sponest.middleground.monitoringEquipment.inserctpests.service.PlantDiseasesAndInsectPestsService;
  7. import com.sooka.sponest.middleground.monitoringEquipment.sennor.service.SennorService;
  8. import com.sooka.sponest.middleground.remoteapi.service.center.dahuaLog.RemoteDahuaLogService;
  9. import com.sooka.sponest.middleground.remoteapi.service.center.iot.RemoteIotService;
  10. import com.sooka.sponest.middleground.remoteapi.service.center.lineCharts.RemoteLineChartsService;
  11. import com.sooka.sponest.middleground.remoteapi.service.center.pollingPositionMsg.RemotePollingPositionMsgService;
  12. import org.apache.commons.lang3.time.FastDateFormat;
  13. import org.slf4j.Logger;
  14. import org.slf4j.LoggerFactory;
  15. import org.springframework.beans.factory.annotation.Value;
  16. import org.springframework.context.annotation.Configuration;
  17. import org.springframework.scheduling.annotation.EnableScheduling;
  18. import org.springframework.scheduling.annotation.Scheduled;
  19. import javax.annotation.Resource;
  20. import java.text.ParseException;
  21. import java.util.Calendar;
  22. /**
  23. * @author limeng
  24. * @date 2023年11月30日 8:50
  25. */
  26. @Configuration
  27. @EnableScheduling
  28. public class StaticScheduleTask {
  29. protected static final Logger logger = LoggerFactory.getLogger(StaticScheduleTask.class);
  30. private static FastDateFormat simpleDateFormat = FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss");
  31. @Resource
  32. private SennorService sennorService;
  33. @Resource
  34. private PlantDiseasesAndInsectPestsService plantDiseasesAndInsectPestsService;
  35. /**
  36. * 精讯物联网设备类型
  37. **/
  38. @Value("${monitoringEquipment.sennor.sennorDeviceTypes:}")
  39. public String sennorDeviceTypes;
  40. /**
  41. * 精讯物联网病虫害设备类型
  42. **/
  43. @Value("${monitoringEquipment.insect.sennorInsectDeviceType:}")
  44. public String sennorInsectDeviceType;
  45. ;
  46. @Resource
  47. public MonitorController monitorController;
  48. @Resource
  49. public RemoteDahuaLogService remoteDahuaLogService;
  50. @Resource
  51. public RemoteIotService remoteIotService;
  52. @Resource
  53. public RemoteLineChartsService remoteLineCharService;
  54. @Resource
  55. public RemotePollingPositionMsgService remotePollingPositionMsgService;
  56. // @Scheduled(cron = "0 0 0/2 * * ?")//添加定时任务 每2小时执行
  57. //// @Scheduled(cron = "0 */5 * * * ?")//添加定时任务 每1分钟执行
  58. // private void configureTasks() {
  59. // logger.info("执行物联网数据采集定时任务=>{}", DateUtils.dateTimeNow());
  60. // JSONArray jsonArray = sennorService.getDevideCodeMapByTypes(sennorDeviceTypes);
  61. // for (Object object : jsonArray) {
  62. // JSONObject jsonObject = JSONObject.parseObject(object.toString());
  63. // sennorService.getDeviceInfo(jsonObject.getString("device_code"));
  64. // }
  65. // }
  66. //
  67. //
  68. // @Scheduled(cron = "0 0 0/2 * * ?")//添加定时任务 每2小时执行
  69. //// @Scheduled(cron = "0 */5 * * * ?")//添加定时任务 每1分钟执行
  70. // private void configureTask() {
  71. // logger.info("执行虫情数据采集定时任务=>{}", DateUtils.dateTimeNow());
  72. // JSONArray jsonArray = sennorService.getDevideCodeMapByTypes(sennorInsectDeviceType);
  73. // for (Object object : jsonArray) {
  74. // JSONObject jsonObject = JSONObject.parseObject(object.toString());
  75. // plantDiseasesAndInsectPestsService.plantDiseasesAndInsectPestsMessageReceiver(jsonObject.getString("device_code"));
  76. // }
  77. // }
  78. @Scheduled(cron = "0 0/30 1 * * ?")//添加定时任务 每天1点半执行
  79. private void configureBlackTasks() {
  80. logger.info("执行凌晨1点半对接大华云台日志定时任务=>{}", DateUtils.dateTimeNow());
  81. remoteDahuaLogService.configureBlackTasks();
  82. }
  83. @Scheduled(cron = "0 0 0/1 * * ?")//添加定时任务 每1小时执行
  84. private void configureWhiteTasks() {
  85. logger.info("执行每1小时对接大华云台日志定时任务=>{}", DateUtils.dateTimeNow());
  86. remoteDahuaLogService.configureWhiteTasks();
  87. }
  88. // @Scheduled(cron = "0 0/10 * * * ?")//添加定时任务 每天10分钟执行
  89. // private void configureGpsTank() throws Exception {
  90. // logger.info("执行每天10分钟一次对接北斗卫星定位设备车辆轨迹和行程定时任务=>{}", DateUtils.dateTimeNow());
  91. // monitorController.configureGpsTank();
  92. // }
  93. @Scheduled(cron = "0 0/2 * * * ?")//添加定时任务 每2分钟执行一次
  94. private void getLongPollingPositionMsg() {
  95. logger.info("对接大华根据组织获取执法记录仪、单兵设备在线状态定时任务定时任务=>{}", DateUtils.dateTimeNow());
  96. remotePollingPositionMsgService.getLongPollingPositionMsg();
  97. }
  98. // @Scheduled(cron = "0 0 0/1 * * ?")//添加定时任务 每1小时执行一次
  99. // private void updateDeviceStatusQuartz() {
  100. // logger.info("IOT传感器设备定时任务=>{}", DateUtils.dateTimeNow());
  101. // remoteIotService.updateDeviceStatusQuartz();
  102. // }
  103. @Scheduled(cron = "0 0 0/2 * * ?")//添加定时任务 每两小时执行一次
  104. private void selectDayLineChartCountTask() {
  105. logger.info("监控中心首页-离线设备日折线图缓存定时任务=>{}", DateUtils.dateTimeNow());
  106. remoteLineCharService.selectDayLineChartCountTask();
  107. }
  108. @Scheduled(cron = "0 0 0/2 * * ?")//添加定时任务 每两小时执行一次
  109. private void selectMonthlyLineChartCountTask() {
  110. logger.info("监控中心首页-离线设备月折线图缓存存定时任务=>{}", DateUtils.dateTimeNow());
  111. remoteLineCharService.selectMonthlyLineChartCountTask();
  112. }
  113. @Scheduled(cron = "0 0 0/2 * * ?")//添加定时任务 每两小时执行一次
  114. private void quarterlineChartTask() {
  115. logger.info("监控中心首页-离线设备季度折线图缓存定时任务=>{}", DateUtils.dateTimeNow());
  116. remoteLineCharService.quarterlineChartTask();
  117. }
  118. @Scheduled(cron = "0 0 0/2 * * ?")//添加定时任务 每两小时执行一次
  119. private void yearlineChartTask() {
  120. logger.info("监控中心首页-离线设备年折线图缓存定时任务=>{}", DateUtils.dateTimeNow());
  121. remoteLineCharService.yearlineChartTask();
  122. }
  123. /**
  124. * 比较两个日期大小
  125. **/
  126. private boolean daysBefore(String time) {
  127. boolean result = false;
  128. try {
  129. Calendar calendar = getCalendar(time);
  130. Calendar now = Calendar.getInstance();
  131. result = calendar.before(now);
  132. } catch (ParseException e) {
  133. logger.error(e.getMessage());
  134. }
  135. return result;
  136. }
  137. /**
  138. * 将String时间转换为Calendar
  139. **/
  140. private static Calendar getCalendar(String time) throws ParseException {
  141. Calendar calendar = Calendar.getInstance();
  142. calendar.setTime(simpleDateFormat.parse(time));
  143. return calendar;
  144. }
  145. }