Browse Source

add:按station id进行视频截图并进行分析,返回结果

zhongwei
luyie 3 months ago
parent
commit
616d2d368b
  1. 22
      hzims-service-api/inspect-api/src/main/java/com/hnac/hzinfo/inspect/ai/feign/IImageAnalysisClient.java
  2. 15
      hzims-service-api/inspect-api/src/main/java/com/hnac/hzinfo/inspect/ai/vo/ZhiPuImageAnalysisDTO.java
  3. 27
      hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/ai/feign/ImageAnalysisClient.java
  4. 15
      hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/ai/service/IZhiPuBigModelService.java
  5. 107
      hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/ai/service/impl/ZhiPuBigModelServiceImpl.java

22
hzims-service-api/inspect-api/src/main/java/com/hnac/hzinfo/inspect/ai/feign/IImageAnalysisClient.java

@ -0,0 +1,22 @@
package com.hnac.hzinfo.inspect.ai.feign;
import com.hnac.hzinfo.inspect.Constants;
import com.hnac.hzinfo.inspect.ai.vo.ZhiPuImageAnalysisDTO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import java.util.List;
/**
* @Author: ypj
* @Date: 2024/8/29 20:13
*/
@FeignClient(value = Constants.APP_NAME)
public interface IImageAnalysisClient {
String API_PREFIX = "/feign/ai";
String ANALYSIS_BY_STATION_ID = "/analysisByStationId";
@PostMapping(API_PREFIX + ANALYSIS_BY_STATION_ID)
List<ZhiPuImageAnalysisDTO> analysisByStationId(@RequestBody Long stationId);
}

15
hzims-service-api/inspect-api/src/main/java/com/hnac/hzinfo/inspect/ai/vo/ZhiPuImageAnalysisDTO.java

@ -0,0 +1,15 @@
package com.hnac.hzinfo.inspect.ai.vo;
import lombok.Data;
/**
* @Author: ypj
* @Date: 2024/8/29 16:10
*/
@Data
public class ZhiPuImageAnalysisDTO {
private String url;
private String conclusion;
}

27
hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/ai/feign/ImageAnalysisClient.java

@ -0,0 +1,27 @@
package com.hnac.hzinfo.inspect.ai.feign;
import com.hnac.hzinfo.inspect.ai.service.IZhiPuBigModelService;
import com.hnac.hzinfo.inspect.ai.vo.ZhiPuImageAnalysisDTO;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* @Author: ypj
* @Date: 2024/8/29 20:20
*/
@RestController
@AllArgsConstructor
@RequestMapping("/feign/ai")
public class ImageAnalysisClient implements IImageAnalysisClient {
private final IZhiPuBigModelService zhiPuBigModelService;
@Override
@PostMapping(ANALYSIS_BY_STATION_ID)
public List<ZhiPuImageAnalysisDTO> analysisByStationId(Long stationId) {
return zhiPuBigModelService.analysisImgByStationId(stationId);
}
}

15
hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/ai/service/IZhiPuBigModelService.java

@ -0,0 +1,15 @@
package com.hnac.hzinfo.inspect.ai.service;
import com.hnac.hzinfo.inspect.ai.vo.ZhiPuImageAnalysisDTO;
import java.util.List;
/**
* @Author: ypj
* @Date: 2024/8/29 13:58
*/
public interface IZhiPuBigModelService {
List<ZhiPuImageAnalysisDTO> analysisImgByStationId(Long stationId);
List<String> getZhiPuAnalysisType(String[] originalCode);
}

107
hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/ai/service/impl/ZhiPuBigModelServiceImpl.java

@ -0,0 +1,107 @@
package com.hnac.hzinfo.inspect.ai.service.impl;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hnac.hzims.bigmodel.api.dto.BigModelAnalysisRequestDTO;
import com.hnac.hzims.bigmodel.api.dto.BigModelAnalysisResponseDTO;
import com.hnac.hzims.bigmodel.api.feign.IBigModelAnalysisClient;
import com.hnac.hzims.operational.station.entity.StationVideoTypeEntity;
import com.hnac.hzims.operational.station.feign.IStationVideoTypeClient;
import com.hnac.hzinfo.inspect.ai.entity.CameraInfoEntity;
import com.hnac.hzinfo.inspect.ai.service.ICameraInfoService;
import com.hnac.hzinfo.inspect.ai.service.IZhiPuBigModelService;
import com.hnac.hzinfo.inspect.ai.vo.ZhiPuImageAnalysisDTO;
import com.hnac.hzinfo.inspect.utils.HiKUtil;
import lombok.AllArgsConstructor;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.CollectionUtil;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.system.entity.Dict;
import org.springblade.system.feign.IDictClient;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* @Author: ypj
* @Date: 2024/8/29 15:26
*/
@Service
@AllArgsConstructor
public class ZhiPuBigModelServiceImpl implements IZhiPuBigModelService {
private final IStationVideoTypeClient stationVideoTypeClient;
private final ICameraInfoService cameraInfoService;
private final IDictClient dictClient;
private final IBigModelAnalysisClient bigModelClient;
private static final String ZHI_PU_TYPE_KEY = "big_model_analysis";
private static final String CAMERA_TYPE_KEY = "minitor_item";
private static final String CAMERA_TYPE_SPLIT = "\\^";
@Override
public List<ZhiPuImageAnalysisDTO> analysisImgByStationId(Long stationId) {
List<ZhiPuImageAnalysisDTO> result = new ArrayList<>();
List<StationVideoTypeEntity> videoList = stationVideoTypeClient.listByStationId(stationId.toString());
if (CollectionUtil.isEmpty(videoList)) {
return result;
}
List<String> codeList = videoList.stream().map(StationVideoTypeEntity::getPointCode).collect(Collectors.toList());
List<CameraInfoEntity> cameraList = cameraInfoService.list(Wrappers.<CameraInfoEntity>lambdaQuery().in(CameraInfoEntity::getPointCode, codeList));
for (CameraInfoEntity cameraInfo : cameraList) {
String[] monitorItems = cameraInfo.getMonitorItems().split(CAMERA_TYPE_SPLIT);
List<String> analysisTypeList = getZhiPuAnalysisType(monitorItems);
if (CollectionUtil.isEmpty(analysisTypeList)) {
continue;
}
String url = HiKUtil.manualCapture(cameraInfo.getPointCode());
if (StringUtil.isBlank(url)) {
continue;
}
BigModelAnalysisRequestDTO zhiPuRequest = new BigModelAnalysisRequestDTO();
zhiPuRequest.setUrl(url);
zhiPuRequest.setCheckTypeSonList(analysisTypeList);
BigModelAnalysisResponseDTO zhiPuResponse = bigModelClient.analysis(zhiPuRequest);
if (zhiPuResponse.getSuccess()) {
ZhiPuImageAnalysisDTO dto = new ZhiPuImageAnalysisDTO();
List<BigModelAnalysisResponseDTO.BigModelAnalysisResult> data = zhiPuResponse.getData();
if (CollectionUtil.isEmpty(data)) {
continue;
}
dto.setUrl(url);
StringBuilder builder = new StringBuilder();
for (BigModelAnalysisResponseDTO.BigModelAnalysisResult item : data) {
builder.append(item.getDescription()).append("\n");
}
dto.setConclusion(builder.toString());
result.add(dto);
}
}
return result;
}
@Override
public List<String> getZhiPuAnalysisType(String[] originalCode) {
List<String> result = new ArrayList<>();
R<List<Dict>> zhiPuResponse = dictClient.getList(ZHI_PU_TYPE_KEY);
if (!zhiPuResponse.isSuccess()) {
return result;
}
List<Dict> zhiPuList = zhiPuResponse.getData();
for (String code : originalCode) {
R<String> valueResponse = dictClient.getValue(CAMERA_TYPE_KEY, code);
if (!valueResponse.isSuccess()|| StringUtil.isBlank(valueResponse.getData())) {
continue;
}
String value = valueResponse.getData();
for (Dict dict : zhiPuList) {
if (value.indexOf(dict.getDictValue()) >= 0 || dict.getDictValue().indexOf(value) >= 0) {
result.add(dict.getDictKey());
}
}
}
return result;
}
}
Loading…
Cancel
Save