72 lines
2.7 KiB
Java
72 lines
2.7 KiB
Java
package com.zhgd.xmgl.task;
|
|
|
|
import com.zhgd.xmgl.modules.bigdevice.entity.Lifter;
|
|
import com.zhgd.xmgl.modules.bigdevice.entity.Tower;
|
|
import com.zhgd.xmgl.modules.bigdevice.service.ILifterService;
|
|
import com.zhgd.xmgl.modules.bigdevice.service.ITowerService;
|
|
import lombok.extern.log4j.Log4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import net.javacrumbs.shedlock.core.SchedulerLock;
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
import java.util.List;
|
|
|
|
/**
|
|
* @Author zzp
|
|
* @Date 2022/7/4
|
|
* Do: 离线警告任务,目前需要警告的设备类型:
|
|
* 升降机
|
|
* 塔吊
|
|
*/
|
|
@Slf4j
|
|
@Component
|
|
public class OfflineAlarmTask {
|
|
|
|
@Autowired
|
|
private ILifterService lifterService;
|
|
@Autowired
|
|
private ITowerService towerService;
|
|
|
|
/**
|
|
* 升降机、塔吊离线警告通知
|
|
* 应需求超过5分钟没有收到实时数据发送手机“设备离线通知警告”
|
|
* 每2分钟执行一次
|
|
*/
|
|
@Scheduled(cron = "0 0 */2 * * ?")
|
|
@SchedulerLock(name = "OfflineAlarmTask", lockAtMostFor = 1000*60*5, lockAtLeastFor = 1000*100)
|
|
public void OfflineAlarmTask() {
|
|
log.info("升降机、塔吊离线警告通知任务开始");
|
|
long start = System.currentTimeMillis();
|
|
try {
|
|
// 应需要超过5分钟无实时数据的则算作离线 对离线设备进行报警发送手机消息
|
|
// 查询离线升降机
|
|
List<Lifter> offlineLifterList = lifterService.queryOfflineLifter();
|
|
// 查询离线塔吊
|
|
List<Tower> offlineTowerList = towerService.queryOfflineTower();
|
|
if (CollectionUtils.isNotEmpty(offlineLifterList)){
|
|
log.info("有"+offlineLifterList+"台升降机超5分钟离线");
|
|
for (Lifter offlineLifter : offlineLifterList) {
|
|
// 发送升降机离线警告
|
|
lifterService. offlineAlarm(offlineLifter);
|
|
}
|
|
}
|
|
if (CollectionUtils.isNotEmpty(offlineTowerList)){
|
|
log.info("有"+offlineLifterList+"台塔吊超5分钟离线");
|
|
for (Tower offlineTower : offlineTowerList) {
|
|
|
|
// 发送塔吊离线警告
|
|
towerService. offlineAlarm(offlineTower);
|
|
}
|
|
}
|
|
}catch (Exception e){
|
|
log.error("升降机、塔吊离线警告通知任务异常"+e);
|
|
}finally {
|
|
log.info("升降机、塔吊离线警告通知任务结束,耗时"+(System.currentTimeMillis()-start)+"ms");
|
|
}
|
|
|
|
}
|
|
}
|