Browse Source

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

zhongwei
yang_shj 2 months ago
parent
commit
f1b3adda33
  1. 39
      hzims-biz-common/src/main/java/com/hnac/hzims/common/utils/FileUtil.java
  2. 2
      hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/fdp/constants/ScheduledConstant.java
  3. 2
      hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/database/service/WeaviateService.java
  4. 7
      hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/interactive/controller/FontEndInteractiveController.java
  5. 17
      hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/controller/DataInstructController.java
  6. 3
      hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/controller/DataRecordController.java
  7. 17
      hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/service/DataRecordService.java
  8. 1
      hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/service/KnowledgeFileInfoService.java
  9. 2
      hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/service/impl/AgentLogServiceImpl.java
  10. 11
      hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/service/impl/KnowledgeFileInfoServiceImpl.java
  11. 7
      hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/service/impl/VectorParamServiceImpl.java
  12. 2
      hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/zhipuai/handler/ZhipuAnalysisHandlerGlm4v.java
  13. 10
      hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/zhipuai/service/impl/ZhipuAnalysisServiceImpl.java
  14. 52
      hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/task/schedule/VideoTaskSchedule.java

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

@ -1,9 +1,19 @@
package com.hnac.hzims.common.utils; package com.hnac.hzims.common.utils;
import lombok.*; import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContextBuilder;
import org.apache.http.util.EntityUtils;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.net.ssl.SSLContext;
import java.io.*; import java.io.*;
import java.net.URL; import java.net.URL;
import java.net.URLDecoder; import java.net.URLDecoder;
@ -147,6 +157,10 @@ public class FileUtil {
return getBase64(getFileBytes(filePath)); return getBase64(getFileBytes(filePath));
} }
public static String getBase64(URL url) throws IOException {
return getBase64(getUrlByte(url));
}
@Data @Data
@AllArgsConstructor @AllArgsConstructor
public static class ByteArrayMultipartFile implements MultipartFile { public static class ByteArrayMultipartFile implements MultipartFile {
@ -187,4 +201,27 @@ public class FileUtil {
} }
} }
} }
public static byte[] getUrlByteByRequest(String urlString) {
try {
// 创建一个不验证主机名且接受任何证书的SSLContext
SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, (x509Certificates, s) -> true).build();
// 使用该SSLContext创建一个HttpClient,并禁用主机名验证
CloseableHttpClient httpClient = HttpClients.custom()
.setSSLContext(sslContext)
.setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE)
.build();
HttpGet request = new HttpGet(urlString);
CloseableHttpResponse response = httpClient.execute(request);
if (response.getStatusLine().getStatusCode() == 200) {
org.apache.http.HttpEntity entity = response.getEntity();
if (entity != null) {
return EntityUtils.toByteArray(entity);
}
}
} catch (Exception e) {
log.error("获取文件内容失败", e);
}
return null;
}
} }

2
hzims-service-api/equipment-api/src/main/java/com/hnac/hzims/fdp/constants/ScheduledConstant.java

@ -33,5 +33,5 @@ public interface ScheduledConstant {
String DEVICE_LEDGER_DATA_GENERATE = "deviceLedgerDataGenerate"; String DEVICE_LEDGER_DATA_GENERATE = "deviceLedgerDataGenerate";
/**设备台账数据存入向量数据库表名**/ /**设备台账数据存入向量数据库表名**/
String DEVICE_LEDGER_CLASS_NAME = "Hzn_lm_deviceLedger_data"; String DEVICE_LEDGER_CLASS_NAME = "Hzims_deviceLedger_data";
} }

2
hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/database/service/WeaviateService.java

@ -167,8 +167,8 @@ public class WeaviateService {
// 将entity转换为Map<String,String> // 将entity转换为Map<String,String>
JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(entity, SerializerFeature.WriteMapNullValue)); JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(entity, SerializerFeature.WriteMapNullValue));
Map<String,Object> map = new HashMap<>(); Map<String,Object> map = new HashMap<>();
data.add(this.getVectorData(map,attrsMap));
jsonObject.forEach((k,v) -> map.put(k,jsonObject.get(k))); jsonObject.forEach((k,v) -> map.put(k,jsonObject.get(k)));
data.add(this.getVectorData(map,attrsMap));
}); });
params.put("data",data); params.put("data",data);
String url = gglmUrl + invokeApi.getInsertVectors(); String url = gglmUrl + invokeApi.getInsertVectors();

7
hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/interactive/controller/FontEndInteractiveController.java

@ -89,8 +89,11 @@ public class FontEndInteractiveController {
@GetMapping("/getAnswerByChatId") @GetMapping("/getAnswerByChatId")
public R getAnswerByChatId(@RequestParam("chatId") @ApiParam("会话ID") String chatId){ public R getAnswerByChatId(@RequestParam("chatId") @ApiParam("会话ID") String chatId){
List<AnswerVO> answers = hznlmInvokeService.getAnswerBySessionIds(chatId); List<AnswerVO> answers = hznlmInvokeService.getAnswerBySessionIds(chatId);
if(Func.isNotEmpty(answers) && answers.size() == 1 && answers.get(0).getStatus().intValue() == 0) { if(Func.isNotEmpty(answers) && answers.size() == 1) {
return R.data(answers.get(0)); AnswerVO answerVO = answers.get(0);
if(answerVO.getStatus().intValue() == 0 || answerVO.getStatus().intValue() == -2) {
return R.data(answerVO);
}
} }
return R.success("操作成功!"); return R.success("操作成功!");
} }

17
hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/controller/DataInstructController.java

@ -1,5 +1,6 @@
package com.hnac.gglm.bigmodel.maintenance.controller; package com.hnac.gglm.bigmodel.maintenance.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.hnac.gglm.bigmodel.maintenance.dto.DeviceFuncDTO; import com.hnac.gglm.bigmodel.maintenance.dto.DeviceFuncDTO;
@ -11,6 +12,7 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springblade.core.mp.support.Condition; import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query; import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R; import org.springblade.core.tool.api.R;
@ -47,7 +49,20 @@ public class DataInstructController {
@ApiOperation("控制指令列表查询") @ApiOperation("控制指令列表查询")
@ApiOperationSupport(order = 3) @ApiOperationSupport(order = 3)
public R<IPage<DataInstructEntity>> listPage(Query query, DataInstructEntity req) { public R<IPage<DataInstructEntity>> listPage(Query query, DataInstructEntity req) {
return R.data(dataInstructService.page(Condition.getPage(query),Condition.getQueryWrapper(req).lambda())); QueryWrapper<DataInstructEntity> wrapper = new QueryWrapper<>();
if (StringUtils.isNotBlank(req.getItemId())) {
wrapper.lambda().eq(DataInstructEntity::getItemId, req.getItemId());
}
if (StringUtils.isNotBlank(req.getStationId())) {
wrapper.lambda().eq(DataInstructEntity::getStationId, req.getStationId());
}
if (StringUtils.isNotBlank(req.getDeviceId())) {
wrapper.lambda().eq(DataInstructEntity::getDeviceId, req.getDeviceId());
}
if (StringUtils.isNotBlank(req.getYkName())) {
wrapper.lambda().like(DataInstructEntity::getYkName, req.getYkName());
}
return R.data(dataInstructService.page(Condition.getPage(query), wrapper));
} }
@DeleteMapping("/removeByIds") @DeleteMapping("/removeByIds")

3
hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/controller/DataRecordController.java

@ -1,8 +1,10 @@
package com.hnac.gglm.bigmodel.maintenance.controller; package com.hnac.gglm.bigmodel.maintenance.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.hnac.gglm.bigmodel.maintenance.dto.DeviceAttrDTO; import com.hnac.gglm.bigmodel.maintenance.dto.DeviceAttrDTO;
import com.hnac.gglm.bigmodel.maintenance.entity.DataInstructEntity;
import com.hnac.gglm.bigmodel.maintenance.entity.DataRecordEntity; import com.hnac.gglm.bigmodel.maintenance.entity.DataRecordEntity;
import com.hnac.gglm.bigmodel.maintenance.service.DataRecordService; import com.hnac.gglm.bigmodel.maintenance.service.DataRecordService;
import com.hnac.gglm.bigmodel.maintenance.vo.DataRecordVO; import com.hnac.gglm.bigmodel.maintenance.vo.DataRecordVO;
@ -11,6 +13,7 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springblade.core.mp.support.Condition; import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query; import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R; import org.springblade.core.tool.api.R;

17
hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/service/DataRecordService.java

@ -1,6 +1,7 @@
package com.hnac.gglm.bigmodel.maintenance.service; package com.hnac.gglm.bigmodel.maintenance.service;
import com.baomidou.dynamic.datasource.annotation.DS; import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
@ -14,6 +15,7 @@ import com.hnac.gglm.bigmodel.maintenance.vo.DataRecordVO;
import com.hnac.hzinfo.sdk.v5.device.dto.DeviceAttrInfoDTO; import com.hnac.hzinfo.sdk.v5.device.dto.DeviceAttrInfoDTO;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springblade.core.mp.base.BaseServiceImpl; import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.mp.support.Condition; import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query; import org.springblade.core.mp.support.Query;
@ -46,7 +48,20 @@ public class DataRecordService extends BaseServiceImpl<DataRecordMapper, DataRec
} }
public IPage<DataRecordVO> page(Query query, DataRecordEntity req) { public IPage<DataRecordVO> page(Query query, DataRecordEntity req) {
IPage<DataRecordEntity> page = super.page(Condition.getPage(query), Condition.getQueryWrapper(req).lambda()); QueryWrapper<DataRecordEntity> wrapper = new QueryWrapper<>();
if (StringUtils.isNotBlank(req.getItemId())) {
wrapper.lambda().eq(DataRecordEntity::getItemId, req.getItemId());
}
if (StringUtils.isNotBlank(req.getStationId())) {
wrapper.lambda().eq(DataRecordEntity::getStationId, req.getStationId());
}
if (StringUtils.isNotBlank(req.getDeviceId())) {
wrapper.lambda().eq(DataRecordEntity::getDeviceId, req.getDeviceId());
}
if (StringUtils.isNotBlank(req.getRecordName())) {
wrapper.lambda().like(DataRecordEntity::getRecordName, req.getRecordName());
}
IPage<DataRecordEntity> page = super.page(Condition.getPage(query),wrapper);
if (page.getSize() == 0) { if (page.getSize() == 0) {
return new Page<>(); return new Page<>();
} }

1
hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/service/KnowledgeFileInfoService.java

@ -17,6 +17,7 @@ import java.util.List;
*/ */
public interface KnowledgeFileInfoService extends IService<KnowledgeFileInfo> { public interface KnowledgeFileInfoService extends IService<KnowledgeFileInfo> {
String SEGMENT_URL = "/kn/doc_segment"; String SEGMENT_URL = "/kn/doc_segment";
String VECTOR_DATABASE_NAME = "knowledge_data";
Boolean store(IdRequest req); Boolean store(IdRequest req);

2
hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/service/impl/AgentLogServiceImpl.java

@ -51,7 +51,7 @@ public class AgentLogServiceImpl extends ServiceImpl<AgentLogMapper, AgentLogEnt
.set(AgentLogEntity::getLabelStatus, 1) .set(AgentLogEntity::getLabelStatus, 1)
.set(AgentLogEntity::getLabelResult, labelResult) .set(AgentLogEntity::getLabelResult, labelResult)
.set(StringUtil.isNotBlank(req.getLabelContent()), AgentLogEntity::getLabelContent, req.getLabelContent()) .set(StringUtil.isNotBlank(req.getLabelContent()), AgentLogEntity::getLabelContent, req.getLabelContent())
.set(AgentLogEntity::getLabelOperator, AuthUtil.getUserName()) .set(AgentLogEntity::getLabelOperator, AuthUtil.getUserAccount())
.set(AgentLogEntity::getLabelTime, now) .set(AgentLogEntity::getLabelTime, now)
.set(AgentLogEntity::getUpdateTime, now) .set(AgentLogEntity::getUpdateTime, now)
.eq(AgentLogEntity::getId, req.getId())); .eq(AgentLogEntity::getId, req.getId()));

11
hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/service/impl/KnowledgeFileInfoServiceImpl.java

@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hnac.gglm.bigmodel.database.service.WeaviateService;
import com.hnac.gglm.bigmodel.maintenance.constants.StoreStatus; import com.hnac.gglm.bigmodel.maintenance.constants.StoreStatus;
import com.hnac.gglm.bigmodel.maintenance.entity.KnowledgeFileFragment; import com.hnac.gglm.bigmodel.maintenance.entity.KnowledgeFileFragment;
import com.hnac.gglm.bigmodel.maintenance.entity.KnowledgeFileInfo; import com.hnac.gglm.bigmodel.maintenance.entity.KnowledgeFileInfo;
@ -45,6 +46,7 @@ public class KnowledgeFileInfoServiceImpl extends ServiceImpl<KnowledgeFileInfoM
private final KnowledgeFileInfoMapper knowledgeFileInfoMapper; private final KnowledgeFileInfoMapper knowledgeFileInfoMapper;
private final KnowledgeFileFragmentService fileFragmentService; private final KnowledgeFileFragmentService fileFragmentService;
private final IOssClient ossClient; private final IOssClient ossClient;
private final WeaviateService weaviateService;
@Value("${gglm.url}") @Value("${gglm.url}")
private String interactionUrl; private String interactionUrl;
@ -119,7 +121,16 @@ public class KnowledgeFileInfoServiceImpl extends ServiceImpl<KnowledgeFileInfoM
public Boolean removeRecursive(List<Long> idsList) { public Boolean removeRecursive(List<Long> idsList) {
Boolean result = removeByIds(idsList); Boolean result = removeByIds(idsList);
if (result) { if (result) {
try {
fileFragmentService.remove(Wrappers.<KnowledgeFileFragment>lambdaQuery().in(KnowledgeFileFragment::getDocId, idsList)); fileFragmentService.remove(Wrappers.<KnowledgeFileFragment>lambdaQuery().in(KnowledgeFileFragment::getDocId, idsList));
for (Long id : idsList) {
Map<String, String> condition = new HashMap<>();
condition.put("doc_id", id.toString());
weaviateService.deleteCondition(VECTOR_DATABASE_NAME, condition);
}
} catch (Exception e) {
log.error("删除知识库文件文件出错", e);
}
} }
return result; return result;
} }

7
hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/maintenance/service/impl/VectorParamServiceImpl.java

@ -143,7 +143,9 @@ public class VectorParamServiceImpl extends ServiceImpl<VectorParamMapper, Vecto
} }
log.info("synchronization vector param id:{}", id); log.info("synchronization vector param id:{}", id);
VectorUrlResponse response = getUrlResponse(entity.getUrl(), bladeToken, hzinfoToken); VectorUrlResponse response = getUrlResponse(entity.getUrl(), bladeToken, hzinfoToken);
if (response != null) { if (response == null || response.getOriginalData() == null || response.getOriginalData().isEmpty()) {
return false;
}
ObjectMapper mapper = new ObjectMapper(); ObjectMapper mapper = new ObjectMapper();
JsonNode rootNode = null; JsonNode rootNode = null;
try { try {
@ -159,6 +161,7 @@ public class VectorParamServiceImpl extends ServiceImpl<VectorParamMapper, Vecto
} }
String tableName = entity.getTableName().replace(entity.getProjectPrefix() + "_", ""); String tableName = entity.getTableName().replace(entity.getProjectPrefix() + "_", "");
String syncResult = weaviateService.saveBatch(response.getOriginalData(), tableName, attrMap); String syncResult = weaviateService.saveBatch(response.getOriginalData(), tableName, attrMap);
log.info("synchronization vector param id:{}, result:{}", id, syncResult);
if (this.update(Wrappers.<VectorParamEntity>lambdaUpdate() if (this.update(Wrappers.<VectorParamEntity>lambdaUpdate()
.eq(VectorParamEntity::getId, id) .eq(VectorParamEntity::getId, id)
.set(VectorParamEntity::getSynchronizationRemark, syncResult) .set(VectorParamEntity::getSynchronizationRemark, syncResult)
@ -170,8 +173,6 @@ public class VectorParamServiceImpl extends ServiceImpl<VectorParamMapper, Vecto
return false; return false;
} }
} }
return true;
}
@Override @Override
public Boolean removeByIdsWithLog(List<Long> idList) { public Boolean removeByIdsWithLog(List<Long> idList) {

2
hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/zhipuai/handler/ZhipuAnalysisHandlerGlm4v.java

@ -37,7 +37,7 @@ public class ZhipuAnalysisHandlerGlm4v extends AbstractZhipuAnalysisHandler {
@Override @Override
public ModelApiResponse sendRequest(String text, String url) { public ModelApiResponse sendRequest(String text, String url) {
ChatCompletionRequest request = getRequest(text, url); ChatCompletionRequest request = getRequest(text, url);
log.info("send zhipu ai request :{}", Optional.ofNullable(request).map(JsonUtil::toJson).orElse("null")); log.info("send zhipu ai request ,text is {}", text);
return client.invokeModelApi(request); return client.invokeModelApi(request);
} }

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

@ -7,9 +7,9 @@ import com.hnac.gglm.bigmodel.zhipuai.constants.BaseEnum;
import com.hnac.gglm.bigmodel.zhipuai.constants.ErrorCode; import com.hnac.gglm.bigmodel.zhipuai.constants.ErrorCode;
import com.hnac.gglm.bigmodel.zhipuai.constants.ResultStrategyType; import com.hnac.gglm.bigmodel.zhipuai.constants.ResultStrategyType;
import com.hnac.gglm.bigmodel.zhipuai.entity.ZhipuAnalysisInfoEntity; import com.hnac.gglm.bigmodel.zhipuai.entity.ZhipuAnalysisInfoEntity;
import com.hnac.gglm.bigmodel.zhipuai.handler.result.ResultStrategy;
import com.hnac.gglm.bigmodel.zhipuai.handler.ZhipuAnalyser; import com.hnac.gglm.bigmodel.zhipuai.handler.ZhipuAnalyser;
import com.hnac.gglm.bigmodel.zhipuai.handler.ZhipuAnalysisFactory; import com.hnac.gglm.bigmodel.zhipuai.handler.ZhipuAnalysisFactory;
import com.hnac.gglm.bigmodel.zhipuai.handler.result.ResultStrategy;
import com.hnac.gglm.bigmodel.zhipuai.service.ZhipuAnalysisInfoService; import com.hnac.gglm.bigmodel.zhipuai.service.ZhipuAnalysisInfoService;
import com.hnac.gglm.bigmodel.zhipuai.service.ZhipuAnalysisService; import com.hnac.gglm.bigmodel.zhipuai.service.ZhipuAnalysisService;
import com.hnac.gglm.bigmodel.zhipuai.vo.ZhipuAnalysisFileRequest; import com.hnac.gglm.bigmodel.zhipuai.vo.ZhipuAnalysisFileRequest;
@ -99,7 +99,13 @@ public class ZhipuAnalysisServiceImpl implements ZhipuAnalysisService {
String getSendUrl(ZhipuAnalysisFileRequest request) { String getSendUrl(ZhipuAnalysisFileRequest request) {
if (StringUtil.isNotBlank(request.getUrl())) { if (StringUtil.isNotBlank(request.getUrl())) {
return request.getUrl(); String base64 = null;
try {
base64 = FileUtil.getBase64(FileUtil.getUrlByteByRequest(request.getUrl()));
} catch (Exception e) {
log.info("get base64 error", e);
}
return StringUtil.isBlank(base64) ? request.getUrl() : base64;
} }
Assert.isTrue(StringUtil.isNotBlank(request.getFilePath()), () -> { Assert.isTrue(StringUtil.isNotBlank(request.getFilePath()), () -> {
throw ErrorCode.GET_FILE_CONTENT_FAILURE.throwException(); throw ErrorCode.GET_FILE_CONTENT_FAILURE.throwException();

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