diff --git a/hzims-service-api/inspect-api/src/main/java/com/hnac/hzinfo/inspect/ai/feign/IImageAnalysisClient.java b/hzims-service-api/inspect-api/src/main/java/com/hnac/hzinfo/inspect/ai/feign/IImageAnalysisClient.java new file mode 100644 index 0000000..8be314b --- /dev/null +++ b/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 analysisByStationId(@RequestBody Long stationId); +} diff --git a/hzims-service-api/inspect-api/src/main/java/com/hnac/hzinfo/inspect/ai/vo/ZhiPuImageAnalysisDTO.java b/hzims-service-api/inspect-api/src/main/java/com/hnac/hzinfo/inspect/ai/vo/ZhiPuImageAnalysisDTO.java new file mode 100644 index 0000000..d973f88 --- /dev/null +++ b/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; +} diff --git a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/ai/feign/ImageAnalysisClient.java b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/ai/feign/ImageAnalysisClient.java new file mode 100644 index 0000000..816853d --- /dev/null +++ b/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 analysisByStationId(Long stationId) { + return zhiPuBigModelService.analysisImgByStationId(stationId); + } +} diff --git a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/ai/service/IZhiPuBigModelService.java b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/ai/service/IZhiPuBigModelService.java new file mode 100644 index 0000000..14b0801 --- /dev/null +++ b/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 analysisImgByStationId(Long stationId); + + List getZhiPuAnalysisType(String[] originalCode); +} diff --git a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/ai/service/impl/ZhiPuBigModelServiceImpl.java b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/ai/service/impl/ZhiPuBigModelServiceImpl.java new file mode 100644 index 0000000..af93b3c --- /dev/null +++ b/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 analysisImgByStationId(Long stationId) { + List result = new ArrayList<>(); + List videoList = stationVideoTypeClient.listByStationId(stationId.toString()); + if (CollectionUtil.isEmpty(videoList)) { + return result; + } + List codeList = videoList.stream().map(StationVideoTypeEntity::getPointCode).collect(Collectors.toList()); + List cameraList = cameraInfoService.list(Wrappers.lambdaQuery().in(CameraInfoEntity::getPointCode, codeList)); + for (CameraInfoEntity cameraInfo : cameraList) { + String[] monitorItems = cameraInfo.getMonitorItems().split(CAMERA_TYPE_SPLIT); + List 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 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 getZhiPuAnalysisType(String[] originalCode) { + List result = new ArrayList<>(); + R> zhiPuResponse = dictClient.getList(ZHI_PU_TYPE_KEY); + if (!zhiPuResponse.isSuccess()) { + return result; + } + List zhiPuList = zhiPuResponse.getData(); + for (String code : originalCode) { + R 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; + } +}