package com.iailab.module.data.job.task;
|
|
import com.iailab.framework.tenant.core.context.TenantContextHolder;
|
import com.iailab.module.data.video.controller.admin.camera.vo.CameraPageReqVO;
|
import com.iailab.module.data.video.dahua.DHCapturePictureClient;
|
import com.iailab.module.data.video.dahua.DHClientFactory;
|
import com.iailab.module.data.video.dto.CameraDTO;
|
import com.iailab.module.data.video.enums.CaptureTypeEnum;
|
import com.iailab.module.data.video.service.CameraService;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
import org.springframework.stereotype.Component;
|
import org.springframework.util.CollectionUtils;
|
|
import javax.annotation.Resource;
|
import java.time.LocalDateTime;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.stream.Collectors;
|
|
/**
|
* 大华摄像头截图定时任务
|
*
|
* @author Houzhongjian
|
* @Description
|
* @createTime 2024年10月30日
|
*/
|
@Component("devCameraDahuaTask")
|
public class DevCameraDahuaTask implements ITask {
|
private Logger logger = LoggerFactory.getLogger(getClass());
|
|
@Resource
|
private CameraService cameraService;
|
|
@Resource
|
private DHClientFactory dhClientFactory;
|
|
@Override
|
public void run(String params) {
|
logger.info("devCameraDahuaTask定时任务正在执行,参数为:{}", params);
|
System.out.println(TenantContextHolder.getTenantId());
|
try {
|
CameraPageReqVO cameraPageReqVO = new CameraPageReqVO();
|
cameraPageReqVO.setType("2");
|
List<CameraDTO> list = cameraService.list(cameraPageReqVO);
|
if (CollectionUtils.isEmpty(list)) {
|
logger.info("Alarm List 为空");
|
return;
|
}
|
Map<String, List<CameraDTO>> alarmGroup = list.stream().collect(Collectors.groupingBy(CameraDTO::getNvrId));
|
for (Map.Entry<String, List<CameraDTO>> nvr : alarmGroup.entrySet()) {
|
DHCapturePictureClient client = dhClientFactory.getClient(nvr.getKey());
|
try {
|
if(!client.isLogin()) {
|
dhClientFactory.reLogin(client, nvr.getKey());
|
}
|
if(!client.isLogin()) {
|
continue;
|
}
|
List<CameraDTO> cameraList = nvr.getValue();
|
for (int i = 0; i < cameraList.size(); i++) {
|
CameraDTO camera = cameraList.get(i);
|
boolean captureResult = false;
|
if (CaptureTypeEnum.LOCAL.getCode().equals(camera.getCaptureType())) {
|
captureResult = client.localCapturePicture(camera.getChannel(), camera.getCode());
|
} else {
|
captureResult = client.remoteCapturePicture(camera.getChannel(), camera.getCode());
|
}
|
logger.info(camera.getCode() + ":captureResult = " + captureResult);
|
Thread.sleep(100);
|
}
|
} catch (Exception ex) {
|
logger.info("item:" + ex.getMessage());
|
}
|
}
|
logger.info("devCameraDahuaTask定时任务执行完成:" + LocalDateTime.now());
|
|
} catch (Exception ex) {
|
ex.printStackTrace();
|
logger.info("devCameraDahuaTask定时任务失败时间:" + LocalDateTime.now());
|
}
|
}
|
}
|