dongyukun
2024-11-05 e8ad669f7c97d45cd23630dc101180a130d6c17e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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<Integer, Long> 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<AlarmCameraDTO> 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());
        }
    }
}