dongyukun
2024-11-05 e8ad669f7c97d45cd23630dc101180a130d6c17e
提交 | 用户 | 时间
ce910c 1 package com.iailab.module.data.dev.task;
H 2
3 import com.iailab.module.data.dev.dto.AlarmCameraDTO;
4 import com.iailab.module.data.dev.enums.AlarmStatusEnum;
5 import com.iailab.module.data.dev.service.AlarmCameraService;
6 import org.slf4j.Logger;
7 import org.slf4j.LoggerFactory;
8 import org.springframework.beans.factory.annotation.Autowired;
9 import org.springframework.stereotype.Component;
10 import org.springframework.util.CollectionUtils;
11
12 import java.time.LocalDateTime;
13 import java.util.HashMap;
14 import java.util.List;
15 import java.util.Map;
16 import java.util.concurrent.ConcurrentHashMap;
17
18 /**
19  * @author PanZhibao
20  * @Description
21  * @createTime 2024年04月08日
22  */
23 @Component("cameraHeartTask")
24 public class CameraHeartTask implements ITask {
25
26     private Logger logger = LoggerFactory.getLogger(getClass());
27
28     public static Map<Integer, Long> cameraCapTime = new ConcurrentHashMap<>();
29
30     private long EXP_TIME = 1000 * 60 * 3;
31
32     @Autowired
33     private AlarmCameraService alarmCameraService;
34
35     @Override
36     public void run(String params){
37         logger.info("CameraHeartTask定时任务正在执行,参数为:{}", params);
38         try {
39             List<AlarmCameraDTO> alarmCameraList = alarmCameraService.list(new HashMap<>());
40             if (CollectionUtils.isEmpty(alarmCameraList)) {
41                 return;
42             }
43             alarmCameraList.forEach(item -> {
44                 if (!cameraCapTime.containsKey(item.getCameraCode())) {
45                     cameraCapTime.put(item.getCameraCode(), 0L);
46                 }
47             });
48             if (CollectionUtils.isEmpty(cameraCapTime)) {
49                 return;
50             }
51             cameraCapTime.forEach((k, v) -> {
52                 if ((v + EXP_TIME) < System.currentTimeMillis()) {
53                     logger.info("EXCEPTION CODE=" + k);
54                     alarmCameraService.updateStatus(k, AlarmStatusEnum.EXCEPTION);
55                 }
56             });
57
58             logger.info("CameraHeartTask定时任务执行完成:" + LocalDateTime.now());
59         } catch (Exception ex) {
60             ex.printStackTrace();
61             logger.info("CameraHeartTask定时任务失败时间:" + LocalDateTime.now());
62         }
63     }
64 }