Browse Source

Merge remote-tracking branch 'origin/prod-5.1.3' into prod-5.1.3

zhongwei
yang_shj 3 months ago
parent
commit
26f8a9361c
  1. 40
      hzims-biz-common/src/main/java/com/hnac/hzims/common/utils/FileUtil.java
  2. 5
      hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/dto/BigModelAnalysisResponseDTO.java
  3. 3
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/entity/ZhipuAnalysisInfoEntity.java
  4. 13
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/service/impl/ZhipuAnalysisServiceImpl.java
  5. 79
      hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/schedule/VideoTaskSchedule.java

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

@ -6,7 +6,6 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.io.*; import java.io.*;
import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.util.Base64; import java.util.Base64;
@ -17,7 +16,7 @@ import java.util.Base64;
*/ */
@Slf4j @Slf4j
public class FileUtil { public class FileUtil {
public static byte[] getFileBytes(String filePath) { public static byte[] getFileBytes(String filePath) throws IOException {
File file = new File(filePath); File file = new File(filePath);
FileInputStream fileInputStream = null; FileInputStream fileInputStream = null;
byte[] bytes = null; byte[] bytes = null;
@ -25,21 +24,15 @@ public class FileUtil {
fileInputStream = new FileInputStream(file); fileInputStream = new FileInputStream(file);
bytes = new byte[(int) file.length()]; bytes = new byte[(int) file.length()];
fileInputStream.read(bytes); fileInputStream.read(bytes);
return bytes;
} catch (Exception e) {
log.error("读取文件出错", e);
} finally { } finally {
if (null != fileInputStream) { if (null != fileInputStream) {
try {
fileInputStream.close(); fileInputStream.close();
} catch (IOException ignore) {
}
} }
} }
return bytes; return bytes;
} }
public static byte[] getUrlByte(URL url) { public static byte[] getUrlByte(URL url) throws IOException {
InputStream inputStream = null; InputStream inputStream = null;
ByteArrayOutputStream outputStream = null; ByteArrayOutputStream outputStream = null;
byte[] fileBytes = null; byte[] fileBytes = null;
@ -52,30 +45,19 @@ public class FileUtil {
outputStream.write(buffer, 0, bytesRead); outputStream.write(buffer, 0, bytesRead);
} }
fileBytes = outputStream.toByteArray(); fileBytes = outputStream.toByteArray();
} catch (Exception e) {
log.error("获取url文件失败", e);
} finally { } finally {
try {
if (null != inputStream) { if (null != inputStream) {
inputStream.close(); inputStream.close();
} }
if (null != outputStream) { if (null != outputStream) {
outputStream.close(); outputStream.close();
} }
} catch (Exception ignore) {
}
} }
return fileBytes; return fileBytes;
} }
public static byte[] getUrlByte(String urlString) { public static byte[] getUrlByte(String urlString) throws IOException {
try {
return getUrlByte(new URL(urlString)); return getUrlByte(new URL(urlString));
} catch (MalformedURLException e) {
log.error("获取url文件失败", e);
}
return null;
} }
public static String getContentTypeFromUrl(String url) { public static String getContentTypeFromUrl(String url) {
@ -113,17 +95,13 @@ public class FileUtil {
return result; return result;
} }
public static String getPureUrl(String url) { public static String getPureUrl(String url) throws UnsupportedEncodingException {
String result = removeUrlParam(url); String result = removeUrlParam(url);
try {
result = URLDecoder.decode(result, "utf-8"); result = URLDecoder.decode(result, "utf-8");
int index = result.lastIndexOf("http"); int index = result.lastIndexOf("http");
if (index > 0) { if (index > 0) {
result = result.substring(index); result = result.substring(index);
} }
} catch (UnsupportedEncodingException e) {
log.error("解码url失败");
}
return result; return result;
} }
@ -144,23 +122,19 @@ public class FileUtil {
return url; return url;
} }
public static MultipartFile getMultipartFileFromUrl(String urlStr) { public static MultipartFile 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) { public static MultipartFile getMultipartFileFromPureUrl(String pureUrlStr) throws IOException {
MultipartFile result = null; MultipartFile result = null;
try {
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();
String originalName = getOriginalFilename(name); String originalName = getOriginalFilename(name);
String contentType = getContentTypeFromUrl(originalName); String contentType = getContentTypeFromUrl(originalName);
result = new ByteArrayMultipartFile(name, originalName, contentType, bytes); result = new ByteArrayMultipartFile(name, originalName, contentType, bytes);
} catch (Exception e) {
log.error("获取url文件失败", e);
}
return result; return result;
} }
@ -168,7 +142,7 @@ public class FileUtil {
return Base64.getEncoder().encodeToString(bytes); return Base64.getEncoder().encodeToString(bytes);
} }
public static String getBase64(String filePath) { public static String getBase64(String filePath) throws IOException {
return getBase64(getFileBytes(filePath)); return getBase64(getFileBytes(filePath));
} }

5
hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/dto/BigModelAnalysisResponseDTO.java

@ -46,8 +46,11 @@ public class BigModelAnalysisResponseDTO implements Serializable {
@ApiModelProperty(value = "结果描述") @ApiModelProperty(value = "结果描述")
private String description; private String description;
@ApiModelProperty(value = "结果描述") @ApiModelProperty(value = "巡检识别子类型")
private String checkTypeSon; private String checkTypeSon;
@ApiModelProperty(value = "消息")
private String message;
} }
public Boolean getSuccess() { public Boolean getSuccess() {

3
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/entity/ZhipuAnalysisInfoEntity.java

@ -69,4 +69,7 @@ public class ZhipuAnalysisInfoEntity extends TenantEntity {
@TableField("RESULT_JUDGE_MODEL") @TableField("RESULT_JUDGE_MODEL")
private String resultJudgeModel; private String resultJudgeModel;
@ApiModelProperty(value = "消息")
@TableField("MESSAGE")
private String message;
} }

13
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/zhipuai/service/impl/ZhipuAnalysisServiceImpl.java

@ -25,6 +25,7 @@ import org.springblade.core.tool.utils.StringUtil;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import java.io.IOException;
import java.util.*; import java.util.*;
/** /**
@ -46,7 +47,7 @@ public class ZhipuAnalysisServiceImpl implements ZhipuAnalysisService {
private final String multiQuestionConstrains = "- 不要在输出中添加任何注释和思考过程和其他多余的内容,以JSON格式输出简单结果,{}结果只包含'是'或者'否'\n"; private final String multiQuestionConstrains = "- 不要在输出中添加任何注释和思考过程和其他多余的内容,以JSON格式输出简单结果,{}结果只包含'是'或者'否'\n";
private final String multiQuestionConstrainsList = "'问题{}'代表第{}个问题,"; private final String multiQuestionConstrainsList = "'{}'代表第{}个问题,";
@Override @Override
public ZhipuAnalysisFileResponse analysis(ZhipuAnalysisFileRequest request) { public ZhipuAnalysisFileResponse analysis(ZhipuAnalysisFileRequest request) {
@ -100,7 +101,11 @@ public class ZhipuAnalysisServiceImpl implements ZhipuAnalysisService {
return request.getUrl(); return request.getUrl();
} }
if (StringUtil.isNotBlank(request.getFilePath())) { if (StringUtil.isNotBlank(request.getFilePath())) {
try {
return FileUtil.getBase64(request.getFilePath()); return FileUtil.getBase64(request.getFilePath());
} catch (IOException e) {
throw new HzServiceException("获取文件内容失败");
}
} }
return null; return null;
} }
@ -164,7 +169,11 @@ public class ZhipuAnalysisServiceImpl implements ZhipuAnalysisService {
if (ObjectUtil.isEmpty(strategyType)) { if (ObjectUtil.isEmpty(strategyType)) {
continue; continue;
} }
result.setResult(strategyType.getStrategy().getResult(infoEntity, resultObj)); Object conclusionObj = strategyType.getStrategy().getResult(infoEntity, resultObj);
result.setResult(conclusionObj);
if (conclusionObj instanceof Boolean && !(Boolean) conclusionObj) {
result.setMessage(infoEntity.getMessage());
}
} }
response.setData(results); response.setData(results);
response.setCode(ResultCode.SUCCESS.getCode()); response.setCode(ResultCode.SUCCESS.getCode());

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

@ -11,6 +11,7 @@ import com.hnac.hzims.bigmodel.api.feign.IBigModelAnalysisClient;
import com.hnac.hzims.common.utils.FileUtil; 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;
@ -36,19 +37,25 @@ 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.utils.CollectionUtil; import org.springblade.core.tool.utils.CollectionUtil;
import org.springblade.core.tool.utils.DateUtil; import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.StringUtil; import org.springblade.core.tool.utils.StringUtil;
import org.springblade.message.MessageConstants;
import org.springblade.message.dto.BusinessMessageDTO;
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.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 org.springframework.web.multipart.MultipartFile;
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;
@ -78,6 +85,8 @@ public class VideoTaskSchedule {
private final IOssClient ossClient; private final IOssClient ossClient;
private final ContentService contentService; private final ContentService contentService;
private final IBigModelAnalysisClient bigModelClient; private final IBigModelAnalysisClient bigModelClient;
private final IMessageClient messageClient;
private final ISysClient sysClient;
/** /**
* 视频巡检任务执行 * 视频巡检任务执行
@ -180,7 +189,7 @@ public class VideoTaskSchedule {
String picUrl = hikApiService.manualCapture(camera.getPointCode()); String picUrl = hikApiService.manualCapture(camera.getPointCode());
record.setFileUrl(picUrl); record.setFileUrl(picUrl);
record.setCurrentValue(picUrl); record.setCurrentValue(picUrl);
pictureHandle(picUrl, content.getContentId(), record); pictureHandle(picUrl, content.getContentId(), record, task);
} }
} }
return record; return record;
@ -233,8 +242,15 @@ public class VideoTaskSchedule {
return null; return null;
} }
private void pictureHandle(String url, Long contentId, EventRecordEntity record) { private void pictureHandle(String url, Long contentId, EventRecordEntity record, TaskEntity task) {
MultipartFile multipartFile = FileUtil.getMultipartFileFromUrl(url);
MultipartFile multipartFile = null;
try {
multipartFile = FileUtil.getMultipartFileFromUrl(url);
} catch (IOException e) {
log.error("获取截图文件失败", e);
throw new HzServiceException("获取截图文件失败");
}
R<BladeFile> fileResponse = ossClient.putFile(multipartFile); R<BladeFile> fileResponse = ossClient.putFile(multipartFile);
if (fileResponse.isSuccess()) { if (fileResponse.isSuccess()) {
record.setFileUrl(Optional.ofNullable(fileResponse.getData().getLink()).orElse(record.getFileUrl())); record.setFileUrl(Optional.ofNullable(fileResponse.getData().getLink()).orElse(record.getFileUrl()));
@ -245,23 +261,64 @@ public class VideoTaskSchedule {
return; return;
} }
try {
String[] typeArray = content.getMultiCheckTypeSon().split(","); String[] typeArray = content.getMultiCheckTypeSon().split(",");
List<String> checkTypeSonList = Arrays.asList(typeArray); List<String> checkTypeSonList = Arrays.asList(typeArray);
String text = FileUtil.getBase64(multipartFile.getBytes()); 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(text);
BigModelAnalysisResponseDTO analysisResponse = bigModelClient.analysis(analysisRequest); BigModelAnalysisResponseDTO analysisResponse = bigModelClient.analysis(analysisRequest);
if (!analysisResponse.getSuccess() || CollectionUtil.isEmpty(analysisResponse.getData())) { if (!analysisResponse.getSuccess() || CollectionUtil.isEmpty(analysisResponse.getData())) {
return; throw new HzServiceException("大模型识别失败");
} }
List<BigModelAnalysisResponseDTO.BigModelAnalysisResult> results = analysisResponse.getData();
} catch (Exception e) { StringBuilder stringBuilder = new StringBuilder();
log.error("video task get big model analysis result fail", e); Boolean status = Boolean.TRUE;
for (BigModelAnalysisResponseDTO.BigModelAnalysisResult result : results) {
stringBuilder.append(result.getDescription()).append("\n");
Boolean isGood = (Boolean) result.getResult();
status = status && isGood;
if (!isGood) {
sendMessage(result.getMessage(), task, content);
} }
}
record.setCurrentStatus(status ? "1" : "0");
record.setCurrentValue(stringBuilder.toString());
} }
private void sendMessage(String messageText, TaskEntity task, ContentEntity content) {
BusinessMessageDTO messageDTO = new BusinessMessageDTO();
messageDTO.setBusinessClassify("inspect");
messageDTO.setBusinessKey(MessageConstants.BusinessClassifyEnum.INSPECT.getKey());
messageDTO.setSubject(MessageConstants.BusinessClassifyEnum.INSPECT.getDescription());
messageDTO.setTaskId(task.getId());
messageDTO.setTenantId(task.getTenantId());
messageDTO.setDeptId(task.getCreateDept());
messageDTO.setUserIds(String.valueOf(task.getUserId()));
messageDTO.setCreateUser(task.getCreateUser());
StringBuilder textBuilder = new StringBuilder();
textBuilder.append(task.getPlanName());
if (StringUtil.isNotBlank(task.getBatchNumber())) {
textBuilder.append(",").append(task.getBatchNumber());
}
if (StringUtil.isNotBlank(task.getRouteName())) {
textBuilder.append(",").append(task.getRouteName());
}
if (StringUtil.isNotBlank(content.getName())) {
textBuilder.append(",").append(content.getName());
}
textBuilder.append(",").append(messageText);
messageDTO.setContent(textBuilder.toString());
R booleanR = messageClient.sendAppAndWsMsgByUsers(messageDTO);
if (!booleanR.isSuccess()) {
throw new ServiceException("消息推送失败");
}
log.info("推送成功~");
}
} }

Loading…
Cancel
Save