diff --git a/hzims-biz-common/src/main/java/com/hnac/hzims/common/utils/FileUtil.java b/hzims-biz-common/src/main/java/com/hnac/hzims/common/utils/FileUtil.java index 180eb0e..7b38cfc 100644 --- a/hzims-biz-common/src/main/java/com/hnac/hzims/common/utils/FileUtil.java +++ b/hzims-biz-common/src/main/java/com/hnac/hzims/common/utils/FileUtil.java @@ -1,7 +1,6 @@ package com.hnac.hzims.common.utils; -import lombok.NonNull; -import lombok.Value; +import lombok.*; import lombok.extern.slf4j.Slf4j; import org.springframework.web.multipart.MultipartFile; @@ -16,6 +15,8 @@ import java.util.Base64; */ @Slf4j public class FileUtil { + public static final String IMG = "image/jpeg"; + public static byte[] getFileBytes(String filePath) throws IOException { File file = new File(filePath); FileInputStream fileInputStream = null; @@ -115,20 +116,20 @@ public class FileUtil { } public static String removeUrlParam(String url) { - int index = url.indexOf("&"); + int index = url.indexOf("?"); if (index > 0) { return url.substring(0, index); } return url; } - public static MultipartFile getMultipartFileFromUrl(String urlStr) throws IOException { + public static ByteArrayMultipartFile getMultipartFileFromUrl(String urlStr) throws IOException { String pureUrl = getPureUrl(urlStr); return getMultipartFileFromPureUrl(pureUrl); } - public static MultipartFile getMultipartFileFromPureUrl(String pureUrlStr) throws IOException { - MultipartFile result = null; + public static ByteArrayMultipartFile getMultipartFileFromPureUrl(String pureUrlStr) throws IOException { + ByteArrayMultipartFile result = null; URL url = new URL(pureUrlStr); byte[] bytes = getUrlByte(url); String name = url.getPath(); @@ -146,7 +147,8 @@ public class FileUtil { return getBase64(getFileBytes(filePath)); } - @Value + @Data + @AllArgsConstructor public static class ByteArrayMultipartFile implements MultipartFile { String name; diff --git a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/schedule/VideoTaskSchedule.java b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/schedule/VideoTaskSchedule.java index ddf145e..5acefaf 100644 --- a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/schedule/VideoTaskSchedule.java +++ b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/schedule/VideoTaskSchedule.java @@ -38,12 +38,9 @@ import com.xxl.job.core.log.XxlJobLogger; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springblade.core.log.exception.ServiceException; -import org.springblade.core.oss.model.BladeFile; import org.springblade.core.tool.api.R; -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.core.tool.jackson.JsonUtil; +import org.springblade.core.tool.utils.*; import org.springblade.message.MessageConstants; import org.springblade.message.dto.BusinessMessageDTO; import org.springblade.message.fegin.IMessageClient; @@ -53,7 +50,6 @@ import org.springframework.jdbc.datasource.DataSourceTransactionManager; import org.springframework.stereotype.Component; import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.annotation.Transactional; -import org.springframework.web.multipart.MultipartFile; import java.io.IOException; import java.time.LocalDateTime; @@ -175,6 +171,7 @@ public class VideoTaskSchedule { record.setUpdateUser(task.getUpdateUser()); record.setCurrentStatus("1"); CameraInfoEntity camera = this.getCameraByProIdAndConId(project.getProjectId(), content.getContentId()); + log.info("【taskId:" + task.getId() + "】视频巡检任务执行,获取视频巡检结果,camera:" + Optional.of(camera).map(JsonUtil::toJson).orElse("null")); if (Func.isNotEmpty(camera)) { // 获取计划时间段内视频的告警信息设置是否异常 if (Func.isNotEmpty(camera.getEmCode())) { @@ -244,17 +241,21 @@ public class VideoTaskSchedule { private void pictureHandle(String url, Long contentId, EventRecordEntity record, TaskEntity task) { - MultipartFile multipartFile = null; + FileUtil.ByteArrayMultipartFile multipartFile = null; try { - multipartFile = FileUtil.getMultipartFileFromUrl(url); + multipartFile = FileUtil.getMultipartFileFromPureUrl(url); + if (ObjectUtil.isEmpty(multipartFile.getContentType())) { + multipartFile.setContentType(FileUtil.IMG); + } } catch (IOException e) { log.error("获取截图文件失败", e); throw new HzServiceException("获取截图文件失败"); } - R fileResponse = ossClient.putFile(multipartFile); - if (fileResponse.isSuccess()) { - record.setFileUrl(Optional.ofNullable(fileResponse.getData().getLink()).orElse(record.getFileUrl())); - } +// R fileResponse = ossClient.putFile(multipartFile); +// 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())); +// } ContentEntity content = contentService.getById(contentId); if (StringUtil.isBlank(content.getMultiCheckTypeSon())) { @@ -263,17 +264,12 @@ public class VideoTaskSchedule { String[] typeArray = content.getMultiCheckTypeSon().split(","); List checkTypeSonList = Arrays.asList(typeArray); - String text = null; - try { - text = FileUtil.getBase64(multipartFile.getBytes()); - } catch (IOException e) { - log.error("转换截图文件内容失败", e); - throw new HzServiceException("转换截图文件内容失败"); - } BigModelAnalysisRequestDTO analysisRequest = new BigModelAnalysisRequestDTO(); analysisRequest.setCheckTypeSonList(checkTypeSonList); - analysisRequest.setUrl(text); + analysisRequest.setUrl(url); + log.info("【taskId:{}}】视频巡检任务执行,大模型分析请求,{}", task.getId(), Optional.ofNullable(analysisRequest).map(JsonUtil::toJson).orElse("null")); BigModelAnalysisResponseDTO analysisResponse = bigModelClient.analysis(analysisRequest); + log.info("【taskId:{}}】视频巡检任务执行,大模型分析结果,{}", task.getId(), Optional.ofNullable(analysisResponse).map(JsonUtil::toJson).orElse("null")); if (!analysisResponse.getSuccess() || CollectionUtil.isEmpty(analysisResponse.getData())) { throw new HzServiceException("大模型识别失败"); }