Browse Source

add:大模型分析,feign接口参数长度限制,改文件内容base64码为url

zhongwei
luyie 5 months ago
parent
commit
367e9544e2
  1. 16
      hzims-biz-common/src/main/java/com/hnac/hzims/common/utils/FileUtil.java
  2. 36
      hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/schedule/VideoTaskSchedule.java

16
hzims-biz-common/src/main/java/com/hnac/hzims/common/utils/FileUtil.java

@ -1,7 +1,6 @@
package com.hnac.hzims.common.utils; package com.hnac.hzims.common.utils;
import lombok.NonNull; import lombok.*;
import lombok.Value;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
@ -16,6 +15,8 @@ import java.util.Base64;
*/ */
@Slf4j @Slf4j
public class FileUtil { public class FileUtil {
public static final String IMG = "image/jpeg";
public static byte[] getFileBytes(String filePath) throws IOException { public static byte[] getFileBytes(String filePath) throws IOException {
File file = new File(filePath); File file = new File(filePath);
FileInputStream fileInputStream = null; FileInputStream fileInputStream = null;
@ -115,20 +116,20 @@ public class FileUtil {
} }
public static String removeUrlParam(String url) { public static String removeUrlParam(String url) {
int index = url.indexOf("&"); int index = url.indexOf("?");
if (index > 0) { if (index > 0) {
return url.substring(0, index); return url.substring(0, index);
} }
return url; return url;
} }
public static MultipartFile getMultipartFileFromUrl(String urlStr) throws IOException { public static ByteArrayMultipartFile getMultipartFileFromUrl(String urlStr) throws IOException {
String pureUrl = getPureUrl(urlStr); String pureUrl = getPureUrl(urlStr);
return getMultipartFileFromPureUrl(pureUrl); return getMultipartFileFromPureUrl(pureUrl);
} }
public static MultipartFile getMultipartFileFromPureUrl(String pureUrlStr) throws IOException { public static ByteArrayMultipartFile getMultipartFileFromPureUrl(String pureUrlStr) throws IOException {
MultipartFile result = null; ByteArrayMultipartFile result = null;
URL url = new URL(pureUrlStr); URL url = new URL(pureUrlStr);
byte[] bytes = getUrlByte(url); byte[] bytes = getUrlByte(url);
String name = url.getPath(); String name = url.getPath();
@ -146,7 +147,8 @@ public class FileUtil {
return getBase64(getFileBytes(filePath)); return getBase64(getFileBytes(filePath));
} }
@Value @Data
@AllArgsConstructor
public static class ByteArrayMultipartFile implements MultipartFile { public static class ByteArrayMultipartFile implements MultipartFile {
String name; String name;

36
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.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springblade.core.log.exception.ServiceException; 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.api.R;
import org.springblade.core.tool.utils.CollectionUtil; import org.springblade.core.tool.jackson.JsonUtil;
import org.springblade.core.tool.utils.DateUtil; import org.springblade.core.tool.utils.*;
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;
@ -53,7 +50,6 @@ 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.TransactionDefinition;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException; import java.io.IOException;
import java.time.LocalDateTime; import java.time.LocalDateTime;
@ -175,6 +171,7 @@ public class VideoTaskSchedule {
record.setUpdateUser(task.getUpdateUser()); record.setUpdateUser(task.getUpdateUser());
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.of(camera).map(JsonUtil::toJson).orElse("null"));
if (Func.isNotEmpty(camera)) { if (Func.isNotEmpty(camera)) {
// 获取计划时间段内视频的告警信息设置是否异常 // 获取计划时间段内视频的告警信息设置是否异常
if (Func.isNotEmpty(camera.getEmCode())) { if (Func.isNotEmpty(camera.getEmCode())) {
@ -244,17 +241,21 @@ 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) {
MultipartFile multipartFile = null; FileUtil.ByteArrayMultipartFile multipartFile = null;
try { try {
multipartFile = FileUtil.getMultipartFileFromUrl(url); multipartFile = FileUtil.getMultipartFileFromPureUrl(url);
if (ObjectUtil.isEmpty(multipartFile.getContentType())) {
multipartFile.setContentType(FileUtil.IMG);
}
} catch (IOException e) { } catch (IOException e) {
log.error("获取截图文件失败", e); log.error("获取截图文件失败", e);
throw new HzServiceException("获取截图文件失败"); throw new HzServiceException("获取截图文件失败");
} }
R<BladeFile> fileResponse = ossClient.putFile(multipartFile); // R<BladeFile> fileResponse = ossClient.putFile(multipartFile);
if (fileResponse.isSuccess()) { // log.info("【taskId:{}}】视频巡检任务执行,上传minio结果,{}", task.getId(), Optional.ofNullable(fileResponse).map(JsonUtil::toJson).orElse("null"));
record.setFileUrl(Optional.ofNullable(fileResponse.getData().getLink()).orElse(record.getFileUrl())); // if (fileResponse.isSuccess()) {
} // record.setFileUrl(Optional.ofNullable(fileResponse.getData().getLink()).orElse(record.getFileUrl()));
// }
ContentEntity content = contentService.getById(contentId); ContentEntity content = contentService.getById(contentId);
if (StringUtil.isBlank(content.getMultiCheckTypeSon())) { if (StringUtil.isBlank(content.getMultiCheckTypeSon())) {
@ -263,17 +264,12 @@ public class VideoTaskSchedule {
String[] typeArray = content.getMultiCheckTypeSon().split(","); String[] typeArray = content.getMultiCheckTypeSon().split(",");
List<String> checkTypeSonList = Arrays.asList(typeArray); List<String> 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(); BigModelAnalysisRequestDTO analysisRequest = new BigModelAnalysisRequestDTO();
analysisRequest.setCheckTypeSonList(checkTypeSonList); 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); 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())) { if (!analysisResponse.getSuccess() || CollectionUtil.isEmpty(analysisResponse.getData())) {
throw new HzServiceException("大模型识别失败"); throw new HzServiceException("大模型识别失败");
} }

Loading…
Cancel
Save