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