| | |
| | | package org.jeecg.modules.quartz.job; |
| | | |
| | | import org.jeecg.common.util.DateUtils; |
| | | import org.jeecg.modules.iot.entity.MqttParameter; |
| | | import org.jeecg.modules.iot.entity.ServerDeploy; |
| | | import org.jeecg.modules.iot.mqtt.config.MqttCustomerClient; |
| | | import org.jeecg.modules.iot.service.IServerDeployService; |
| | | import org.quartz.Job; |
| | | import org.quartz.JobExecutionContext; |
| | | import org.quartz.JobExecutionException; |
| | | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 示例不带参定时任务 |
| | | * |
| | | * 心跳发送定时任务 |
| | | * |
| | | * @Author Scott |
| | | */ |
| | | @Slf4j |
| | | public class SampleJob implements Job { |
| | | |
| | | @Autowired |
| | | private IServerDeployService serverDeployService; |
| | | @Autowired |
| | | private MqttCustomerClient mqttCustomerClient; |
| | | |
| | | @Override |
| | | public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException { |
| | | log.info(" Job Execution key:"+jobExecutionContext.getJobDetail().getKey()); |
| | | log.info(String.format(" Jeecg-Boot 普通定时任务 SampleJob ! 时间:" + DateUtils.getTimestamp())); |
| | | List<ServerDeploy> serverDeploys = serverDeployService.list(); |
| | | if (serverDeploys != null) { |
| | | serverDeploys.forEach(sd -> { |
| | | if (sd.getGuardState().equals(1)) { |
| | | // 发送心跳信号 |
| | | MqttParameter mqttParameter = new MqttParameter(); |
| | | mqttParameter.setId(sd.getServerCode()); |
| | | mqttParameter.setType("palpitate"); |
| | | mqttParameter.setParameter1("0"); |
| | | mqttCustomerClient.pushlish(2, false, sd.getServerCode(), mqttParameter); |
| | | // 发送采集状态 |
| | | MqttParameter parameter = new MqttParameter(); |
| | | parameter.setId(sd.getServerCode()); |
| | | parameter.setType("collect"); |
| | | parameter.setParameter1("0"); |
| | | mqttCustomerClient.pushlish(2, false, sd.getServerCode(), parameter); |
| | | log.info("心跳♥采集状态发送成功! 服务器编号:" + sd.getServerCode() + " 时间:" + DateUtils.getTimestamp()); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | // 查询虚设备下参数存在oporation的虚设备列表 |
| | | List<ServerDeploy> serverDeploy = serverDeployService.list(); |
| | | // 查询是否存在设备状态 |
| | | |
| | | } |
| | | } |