潘志宝
2024-11-02 c96e44ceedf98afe9541b49172a3d80d983442a0
提交 | 用户 | 时间
1432cd 1 package com.iailab.module.data.job.task;
H 2
3 import com.iailab.module.data.dev.controller.admin.camera.vo.DevCameraPageReqVO;
4 import com.iailab.module.data.dev.dahua.DHCapturePictureClient;
5 import com.iailab.module.data.dev.dahua.DHClientFactory;
6 import com.iailab.module.data.dev.dto.DevCameraDTO;
7 import com.iailab.module.data.dev.enums.CaptureTypeEnum;
8 import com.iailab.module.data.dev.service.DevCameraService;
9 import org.slf4j.Logger;
10 import org.slf4j.LoggerFactory;
11 import org.springframework.stereotype.Component;
12 import org.springframework.util.CollectionUtils;
13
14 import javax.annotation.Resource;
15 import java.time.LocalDateTime;
16 import java.util.List;
17 import java.util.Map;
18 import java.util.stream.Collectors;
19
20 /**
21  * 大华摄像头截图定时任务
22  *
23  * @author Houzhongjian
24  * @Description
25  * @createTime 2024年10月30日
26  */
27 @Component("devCameraDahuaTask")
28 public class DevCameraDahuaTask implements ITask {
29     private Logger logger = LoggerFactory.getLogger(getClass());
30
31     @Resource
32     private DevCameraService devCameraService;
33
34     @Resource
35     private DHClientFactory dhClientFactory;
36
37     @Override
38     public void run(String params) {
39         logger.info("devCameraDahuaTask定时任务正在执行,参数为:{}", params);
40         try {
41             DevCameraPageReqVO cameraPageReqVO = new DevCameraPageReqVO();
42             List<DevCameraDTO> list = devCameraService.list(cameraPageReqVO);
43             if (CollectionUtils.isEmpty(list)) {
44                 logger.info("Alarm List 为空");
45                 return;
46             }
47             Map<String, List<DevCameraDTO>> alarmGroup = list.stream().collect(Collectors.groupingBy(DevCameraDTO::getNvrId));
48             for  (Map.Entry<String, List<DevCameraDTO>> nvr : alarmGroup.entrySet()) {
49                 DHCapturePictureClient client = dhClientFactory.getClient(nvr.getKey());
50                 try {
51                     if(!client.isLogin()) {
52                         dhClientFactory.reLogin(client, nvr.getKey());
53                     }
54                     if(!client.isLogin()) {
55                         continue;
56                     }
57                     List<DevCameraDTO> cameraList = nvr.getValue();
58                     for (int i = 0; i < cameraList.size(); i++) {
59                         DevCameraDTO camera = cameraList.get(i);
60                         boolean captureResult = false;
61                         if (CaptureTypeEnum.LOCAL.getCode().equals(camera.getCaptureType())) {
62                             captureResult = client.localCapturePicture(camera.getChannel(), camera.getCode());
63                         } else {
64                             captureResult = client.remoteCapturePicture(camera.getChannel(), camera.getCode());
65                         }
66                         logger.info(camera.getCode() + ":captureResult = " + captureResult);
67                         Thread.sleep(100);
68                     }
69                 } catch (Exception ex) {
70                     logger.info("item:" + ex.getMessage());
71                 }
72             }
73             logger.info("devCameraDahuaTask定时任务执行完成:" + LocalDateTime.now());
c96e44 74
1432cd 75         } catch (Exception ex) {
H 76             ex.printStackTrace();
77             logger.info("devCameraDahuaTask定时任务失败时间:" + LocalDateTime.now());
78         }
79     }
80 }