12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- package com.sooka.sponest.dataexchange.scheduleTask;
- import cn.hutool.json.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import com.ruoyi.common.core.utils.DateUtils;
- import com.sooka.sponest.dataexchange.monitoringEquipment.inserctpests.service.PlantDiseasesAndInsectPestsService;
- import com.sooka.sponest.dataexchange.monitoringEquipment.sennor.service.SennorService;
- 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;
- // @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"));
- }
- }
- /**
- * 比较两个日期大小
- **/
- 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;
- }
- }
|