package com.iailab.module.data.dev.task; import com.iailab.module.data.dev.dto.AlarmCameraDTO; import com.iailab.module.data.dev.enums.AlarmStatusEnum; import com.iailab.module.data.dev.service.AlarmCameraService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.util.CollectionUtils; import java.time.LocalDateTime; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; /** * @author PanZhibao * @Description * @createTime 2024年04月08日 */ @Component("cameraHeartTask") public class CameraHeartTask implements ITask { private Logger logger = LoggerFactory.getLogger(getClass()); public static Map cameraCapTime = new ConcurrentHashMap<>(); private long EXP_TIME = 1000 * 60 * 3; @Autowired private AlarmCameraService alarmCameraService; @Override public void run(String params){ logger.info("CameraHeartTask定时任务正在执行,参数为:{}", params); try { List alarmCameraList = alarmCameraService.list(new HashMap<>()); if (CollectionUtils.isEmpty(alarmCameraList)) { return; } alarmCameraList.forEach(item -> { if (!cameraCapTime.containsKey(item.getCameraCode())) { cameraCapTime.put(item.getCameraCode(), 0L); } }); if (CollectionUtils.isEmpty(cameraCapTime)) { return; } cameraCapTime.forEach((k, v) -> { if ((v + EXP_TIME) < System.currentTimeMillis()) { logger.info("EXCEPTION CODE=" + k); alarmCameraService.updateStatus(k, AlarmStatusEnum.EXCEPTION); } }); logger.info("CameraHeartTask定时任务执行完成:" + LocalDateTime.now()); } catch (Exception ex) { ex.printStackTrace(); logger.info("CameraHeartTask定时任务失败时间:" + LocalDateTime.now()); } } }