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