123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- package com.sooka.sponest.middleground.scheduleTask;
- import cn.hutool.json.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.ruoyi.common.core.utils.DateUtils;
- import com.sooka.sponest.middleground.controller.MonitorController;
- import com.sooka.sponest.middleground.monitoringEquipment.inserctpests.service.PlantDiseasesAndInsectPestsService;
- import com.sooka.sponest.middleground.monitoringEquipment.sennor.service.SennorService;
- import com.sooka.sponest.middleground.remoteapi.service.center.dahuaLog.RemoteDahuaLogService;
- import com.sooka.sponest.middleground.remoteapi.service.center.iot.RemoteIotService;
- import com.sooka.sponest.middleground.remoteapi.service.center.lineCharts.RemoteLineChartsService;
- import com.sooka.sponest.middleground.remoteapi.service.center.pollingPositionMsg.RemotePollingPositionMsgService;
- import org.apache.commons.lang3.time.FastDateFormat;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.context.annotation.Configuration;
- import org.springframework.scheduling.annotation.EnableScheduling;
- import org.springframework.scheduling.annotation.Scheduled;
- import javax.annotation.Resource;
- import java.text.ParseException;
- import java.util.Calendar;
- /**
- * @author limeng
- * @date 2023年11月30日 8:50
- */
- @Configuration
- @EnableScheduling
- public class StaticScheduleTask {
- protected static final Logger logger = LoggerFactory.getLogger(StaticScheduleTask.class);
- private static FastDateFormat simpleDateFormat = FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss");
- @Resource
- private SennorService sennorService;
- @Resource
- private PlantDiseasesAndInsectPestsService plantDiseasesAndInsectPestsService;
- /**
- * 精讯物联网设备类型
- **/
- @Value("${monitoringEquipment.sennor.sennorDeviceTypes:}")
- public String sennorDeviceTypes;
- /**
- * 精讯物联网病虫害设备类型
- **/
- @Value("${monitoringEquipment.insect.sennorInsectDeviceType:}")
- public String sennorInsectDeviceType;
- ;
- @Resource
- public MonitorController monitorController;
- @Resource
- public RemoteDahuaLogService remoteDahuaLogService;
- @Resource
- public RemoteIotService remoteIotService;
- @Resource
- public RemoteLineChartsService remoteLineCharService;
- @Resource
- public RemotePollingPositionMsgService remotePollingPositionMsgService;
- // @Scheduled(cron = "0 0 0/2 * * ?")//添加定时任务 每2小时执行
- //// @Scheduled(cron = "0 */5 * * * ?")//添加定时任务 每1分钟执行
- // private void configureTasks() {
- // logger.info("执行物联网数据采集定时任务=>{}", DateUtils.dateTimeNow());
- // JSONArray jsonArray = sennorService.getDevideCodeMapByTypes(sennorDeviceTypes);
- // for (Object object : jsonArray) {
- // JSONObject jsonObject = JSONObject.parseObject(object.toString());
- // sennorService.getDeviceInfo(jsonObject.getString("device_code"));
- // }
- // }
- //
- //
- // @Scheduled(cron = "0 0 0/2 * * ?")//添加定时任务 每2小时执行
- //// @Scheduled(cron = "0 */5 * * * ?")//添加定时任务 每1分钟执行
- // private void configureTask() {
- // logger.info("执行虫情数据采集定时任务=>{}", DateUtils.dateTimeNow());
- // JSONArray jsonArray = sennorService.getDevideCodeMapByTypes(sennorInsectDeviceType);
- // for (Object object : jsonArray) {
- // JSONObject jsonObject = JSONObject.parseObject(object.toString());
- // plantDiseasesAndInsectPestsService.plantDiseasesAndInsectPestsMessageReceiver(jsonObject.getString("device_code"));
- // }
- // }
- @Scheduled(cron = "0 0/30 1 * * ?")//添加定时任务 每天1点半执行
- private void configureBlackTasks() {
- logger.info("执行凌晨1点半对接大华云台日志定时任务=>{}", DateUtils.dateTimeNow());
- remoteDahuaLogService.configureBlackTasks();
- }
- @Scheduled(cron = "0 0 0/1 * * ?")//添加定时任务 每1小时执行
- private void configureWhiteTasks() {
- logger.info("执行每1小时对接大华云台日志定时任务=>{}", DateUtils.dateTimeNow());
- remoteDahuaLogService.configureWhiteTasks();
- }
- // @Scheduled(cron = "0 0/10 * * * ?")//添加定时任务 每天10分钟执行
- // private void configureGpsTank() throws Exception {
- // logger.info("执行每天10分钟一次对接北斗卫星定位设备车辆轨迹和行程定时任务=>{}", DateUtils.dateTimeNow());
- // monitorController.configureGpsTank();
- // }
- @Scheduled(cron = "0 0/2 * * * ?")//添加定时任务 每2分钟执行一次
- private void getLongPollingPositionMsg() {
- logger.info("对接大华根据组织获取执法记录仪、单兵设备在线状态定时任务定时任务=>{}", DateUtils.dateTimeNow());
- remotePollingPositionMsgService.getLongPollingPositionMsg();
- }
- // @Scheduled(cron = "0 0 0/1 * * ?")//添加定时任务 每1小时执行一次
- // private void updateDeviceStatusQuartz() {
- // logger.info("IOT传感器设备定时任务=>{}", DateUtils.dateTimeNow());
- // remoteIotService.updateDeviceStatusQuartz();
- // }
- @Scheduled(cron = "0 0 0/2 * * ?")//添加定时任务 每两小时执行一次
- private void selectDayLineChartCountTask() {
- logger.info("监控中心首页-离线设备日折线图缓存定时任务=>{}", DateUtils.dateTimeNow());
- remoteLineCharService.selectDayLineChartCountTask();
- }
- @Scheduled(cron = "0 0 0/2 * * ?")//添加定时任务 每两小时执行一次
- private void selectMonthlyLineChartCountTask() {
- logger.info("监控中心首页-离线设备月折线图缓存存定时任务=>{}", DateUtils.dateTimeNow());
- remoteLineCharService.selectMonthlyLineChartCountTask();
- }
- @Scheduled(cron = "0 0 0/2 * * ?")//添加定时任务 每两小时执行一次
- private void quarterlineChartTask() {
- logger.info("监控中心首页-离线设备季度折线图缓存定时任务=>{}", DateUtils.dateTimeNow());
- remoteLineCharService.quarterlineChartTask();
- }
- @Scheduled(cron = "0 0 0/2 * * ?")//添加定时任务 每两小时执行一次
- private void yearlineChartTask() {
- logger.info("监控中心首页-离线设备年折线图缓存定时任务=>{}", DateUtils.dateTimeNow());
- remoteLineCharService.yearlineChartTask();
- }
- /**
- * 比较两个日期大小
- **/
- private boolean daysBefore(String time) {
- boolean result = false;
- try {
- Calendar calendar = getCalendar(time);
- Calendar now = Calendar.getInstance();
- result = calendar.before(now);
- } catch (ParseException e) {
- logger.error(e.getMessage());
- }
- return result;
- }
- /**
- * 将String时间转换为Calendar
- **/
- private static Calendar getCalendar(String time) throws ParseException {
- Calendar calendar = Calendar.getInstance();
- calendar.setTime(simpleDateFormat.parse(time));
- return calendar;
- }
- }
|