Browse Source

fix:视频巡检日志添加记录状态

zhongwei
luyie 2 months ago
parent
commit
eccff0a08c
  1. 52
      hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/schedule/VideoTaskSchedule.java

52
hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/schedule/VideoTaskSchedule.java

@ -8,10 +8,8 @@ import com.google.common.collect.Lists;
import com.hnac.gglm.bigmodel.api.dto.BigModelAnalysisRequestDTO; import com.hnac.gglm.bigmodel.api.dto.BigModelAnalysisRequestDTO;
import com.hnac.gglm.bigmodel.api.dto.BigModelAnalysisResponseDTO; import com.hnac.gglm.bigmodel.api.dto.BigModelAnalysisResponseDTO;
import com.hnac.gglm.bigmodel.api.feign.IBigModelAnalysisClient; import com.hnac.gglm.bigmodel.api.feign.IBigModelAnalysisClient;
import com.hnac.hzims.common.utils.FileUtil;
import com.hnac.hzinfo.datasearch.soe.ISoeClient; import com.hnac.hzinfo.datasearch.soe.ISoeClient;
import com.hnac.hzinfo.datasearch.soe.vo.DeviceSoeVO; import com.hnac.hzinfo.datasearch.soe.vo.DeviceSoeVO;
import com.hnac.hzinfo.exception.HzServiceException;
import com.hnac.hzinfo.inspect.ai.entity.CameraInfoEntity; import com.hnac.hzinfo.inspect.ai.entity.CameraInfoEntity;
import com.hnac.hzinfo.inspect.ai.entity.RobotTaskEntity; import com.hnac.hzinfo.inspect.ai.entity.RobotTaskEntity;
import com.hnac.hzinfo.inspect.ai.service.ICameraInfoService; import com.hnac.hzinfo.inspect.ai.service.ICameraInfoService;
@ -34,26 +32,25 @@ import com.hnac.hzinfo.inspect.task.service.impl.FileUploaderService;
import com.hnac.hzinfo.sdk.core.response.HzPage; import com.hnac.hzinfo.sdk.core.response.HzPage;
import com.hnac.hzinfo.sdk.core.response.Result; import com.hnac.hzinfo.sdk.core.response.Result;
import com.xxl.job.core.biz.model.ReturnT; import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob; import com.xxl.job.core.handler.annotation.XxlJob;
import com.xxl.job.core.log.XxlJobLogger; import com.xxl.job.core.log.XxlJobLogger;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.oss.model.BladeFile; import org.springblade.core.oss.model.BladeFile;
import org.springblade.core.tool.api.R; import org.springblade.core.tool.api.R;
import org.springblade.core.tool.jackson.JsonUtil; import org.springblade.core.tool.jackson.JsonUtil;
import org.springblade.core.tool.utils.*; import org.springblade.core.tool.utils.CollectionUtil;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.message.MessageConstants; import org.springblade.message.MessageConstants;
import org.springblade.message.dto.BusinessMessageDTO; import org.springblade.message.dto.BusinessMessageDTO;
import org.springblade.message.fegin.IMessageClient; import org.springblade.message.fegin.IMessageClient;
import org.springblade.resource.feign.IOssClient; import org.springblade.resource.feign.IOssClient;
import org.springblade.system.feign.ISysClient;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.io.IOException;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -174,13 +171,13 @@ public class VideoTaskSchedule {
record.setCurrentStatus("1"); record.setCurrentStatus("1");
CameraInfoEntity camera = this.getCameraByProIdAndConId(project.getProjectId(), content.getContentId()); CameraInfoEntity camera = this.getCameraByProIdAndConId(project.getProjectId(), content.getContentId());
log.info("【taskId:" + task.getId() + "】视频巡检任务执行,获取视频巡检结果,camera:" + Optional.ofNullable(camera).map(JsonUtil::toJson).orElse("null")); log.info("【taskId:" + task.getId() + "】视频巡检任务执行,获取视频巡检结果,camera:" + Optional.ofNullable(camera).map(JsonUtil::toJson).orElse("null"));
XxlJobHelper.log("【taskId:" + task.getId() + "】视频巡检任务执行,获取视频巡检结果,camera:" + Optional.ofNullable(camera).map(JsonUtil::toJson).orElse("null"));
if (Func.isNotEmpty(camera)) { if (Func.isNotEmpty(camera)) {
// 获取计划时间段内视频的告警信息设置是否异常 // 获取计划时间段内视频的告警信息设置是否异常
if (Func.isNotEmpty(camera.getEmCode())) { if (Func.isNotEmpty(camera.getEmCode())) {
Result<HzPage<DeviceSoeVO>> deviceSoeR = soeClient.getDeviceCodeByTaosSoe(DateUtil.formatDateTime(task.getPlanStartTime()), DateUtil.formatDateTime(task.getPlanEndTime()), camera.getEmCode(), 0, String.valueOf(-1)); Result<HzPage<DeviceSoeVO>> deviceSoeR = soeClient.getDeviceCodeByTaosSoe(DateUtil.formatDateTime(task.getPlanStartTime()), DateUtil.formatDateTime(task.getPlanEndTime()), camera.getEmCode(), 0, String.valueOf(-1));
if (deviceSoeR.isSuccess() && CollectionUtil.isNotEmpty(deviceSoeR.getData().getRecords())) { if (deviceSoeR.isSuccess() && CollectionUtil.isNotEmpty(deviceSoeR.getData().getRecords())) {
record.setCurrentStatus("0"); record.setCurrentStatus("0");
} }
} }
String picUrl = null; String picUrl = null;
@ -189,7 +186,7 @@ public class VideoTaskSchedule {
try { try {
picUrl = hikApiService.manualCapture(camera.getPointCode()); picUrl = hikApiService.manualCapture(camera.getPointCode());
} catch (Exception e) { } catch (Exception e) {
log.error("get picture url fail", e); XxlJobHelper.log("【taskId:" + task.getId() + "】 获取图片地址失败 {}", e.getMessage());
} }
} }
if (Func.isNotEmpty(picUrl)) { if (Func.isNotEmpty(picUrl)) {
@ -197,6 +194,7 @@ public class VideoTaskSchedule {
record.setCurrentValue(picUrl); record.setCurrentValue(picUrl);
pictureHandle(picUrl, content.getContentId(), record, task); pictureHandle(picUrl, content.getContentId(), record, task);
} else { } else {
record.setCurrentStatus(TaskContants.CurrentStatusEnum.abnormal.getType());
record.setCurrentValue("获取视频地址失败"); record.setCurrentValue("获取视频地址失败");
} }
} }
@ -251,35 +249,20 @@ public class VideoTaskSchedule {
} }
private void pictureHandle(String url, Long contentId, EventRecordEntity record, TaskEntity task) { private void pictureHandle(String url, Long contentId, EventRecordEntity record, TaskEntity task) {
XxlJobHelper.log("【taskId:{}}】视频巡检任务执行,上传minio url={}", task.getId(), url);
// FileUtil.ByteArrayMultipartFile multipartFile = null;
// try {
// multipartFile = FileUtil.getMultipartFileFromPureUrl(url);
// if (ObjectUtil.isEmpty(multipartFile.getContentType())) {
// multipartFile.setContentType(FileUtil.IMG);
// }
// } catch (IOException e) {
// log.error("获取截图文件失败", e);
// record.setCurrentValue("获取截图文件失败");
// return;
// }
// R<BladeFile> fileResponse = ossClient.putFileByNameAndTenantId("file", multipartFile, task.getTenantId());
// log.info("【taskId:{}}】视频巡检任务执行,上传minio结果,{}", task.getId(), Optional.ofNullable(fileResponse).map(JsonUtil::toJson).orElse("null"));
// if (fileResponse.isSuccess()) {
// record.setFileUrl(Optional.ofNullable(fileResponse.getData().getLink()).orElse(record.getFileUrl()));
// }
try { try {
BladeFile bladeFile = fileUploaderService.upload(url, UUID.randomUUID().toString() + ".jpg"); BladeFile bladeFile = fileUploaderService.upload(url, UUID.randomUUID().toString() + ".jpg");
record.setFileUrl(Optional.ofNullable(bladeFile.getLink()).orElse(record.getFileUrl())); record.setFileUrl(Optional.ofNullable(bladeFile.getLink()).orElse(record.getFileUrl()));
} catch (Exception e) { } catch (Exception e) {
log.error("获取截图文件失败", e); XxlJobHelper.log("【taskId:{}}】视频巡检任务执行,上传minio失败", task.getId());
record.setCurrentValue("获取截图文件失败"); record.setCurrentStatus(TaskContants.CurrentStatusEnum.abnormal.getType());
record.setCurrentValue("截图文件上传失败");
return; return;
} }
ContentEntity content = contentService.getById(contentId); ContentEntity content = contentService.getById(contentId);
if (StringUtil.isBlank(content.getMultiCheckTypeSon())) { if (StringUtil.isBlank(content.getMultiCheckTypeSon())) {
record.setCurrentStatus(TaskContants.CurrentStatusEnum.abnormal.getType());
record.setCurrentValue("没有找到巡检内容"); record.setCurrentValue("没有找到巡检内容");
return; return;
} }
@ -289,12 +272,19 @@ public class VideoTaskSchedule {
BigModelAnalysisRequestDTO analysisRequest = new BigModelAnalysisRequestDTO(); BigModelAnalysisRequestDTO analysisRequest = new BigModelAnalysisRequestDTO();
analysisRequest.setCheckTypeSonList(checkTypeSonList); analysisRequest.setCheckTypeSonList(checkTypeSonList);
analysisRequest.setUrl(url); analysisRequest.setUrl(url);
log.info("【taskId:{}}】视频巡检任务执行,大模型分析请求,{}", task.getId(), Optional.ofNullable(analysisRequest).map(JsonUtil::toJson).orElse("null")); log.info("【taskId:{}}】视频巡检任务执行,大模型分析请求,{}", task.getId(), Optional.ofNullable(analysisRequest).map(JsonUtil::toJson).orElse("null"));
XxlJobHelper.log("【taskId:{}}】视频巡检任务执行,大模型分析请求,{}", task.getId(), Optional.ofNullable(analysisRequest).map(JsonUtil::toJson).orElse("null"));
BigModelAnalysisResponseDTO analysisResponse = bigModelClient.analysis(analysisRequest); BigModelAnalysisResponseDTO analysisResponse = bigModelClient.analysis(analysisRequest);
log.info("【taskId:{}}】视频巡检任务执行,大模型分析结果,{}", task.getId(), Optional.ofNullable(analysisResponse).map(JsonUtil::toJson).orElse("null")); log.info("【taskId:{}}】视频巡检任务执行,大模型分析结果,{}", task.getId(), Optional.ofNullable(analysisResponse).map(JsonUtil::toJson).orElse("null"));
XxlJobHelper.log("【taskId:{}}】视频巡检任务执行,大模型分析结果,{}", task.getId(), Optional.ofNullable(analysisResponse).map(JsonUtil::toJson).orElse("null"));
if (!analysisResponse.getSuccess() || CollectionUtil.isEmpty(analysisResponse.getData())) { if (!analysisResponse.getSuccess() || CollectionUtil.isEmpty(analysisResponse.getData())) {
record.setCurrentStatus(TaskContants.CurrentStatusEnum.abnormal.getType());
record.setCurrentValue("大模型分析失败"); record.setCurrentValue("大模型分析失败");
log.error("【taskId:{}}】,返回消息 : {}", task.getId(), Optional.ofNullable(analysisResponse).map(JsonUtil::toJson).orElse("null")); log.error("【taskId:{}}】,返回消息 : {}", task.getId(), Optional.ofNullable(analysisResponse).map(JsonUtil::toJson).orElse("null"));
XxlJobHelper.log("【taskId:{}}】,返回消息 : {}", task.getId(), Optional.ofNullable(analysisResponse).map(JsonUtil::toJson).orElse("null"));
return; return;
} }
List<BigModelAnalysisResponseDTO.BigModelAnalysisResult> results = analysisResponse.getData(); List<BigModelAnalysisResponseDTO.BigModelAnalysisResult> results = analysisResponse.getData();
@ -308,7 +298,7 @@ public class VideoTaskSchedule {
sendMessage(result.getMessage(), task, content); sendMessage(result.getMessage(), task, content);
} }
} }
record.setCurrentStatus(status ? "1" : "0"); record.setCurrentStatus(status ? TaskContants.CurrentStatusEnum.normal.getType() : TaskContants.CurrentStatusEnum.abnormal.getType());
record.setCurrentValue(stringBuilder.toString()); record.setCurrentValue(stringBuilder.toString());
} }

Loading…
Cancel
Save