| @ -1,37 +1,124 @@ | |||||
| package com.inspect.bigmodel.service.impl; | package com.inspect.bigmodel.service.impl; | ||||
| import com.alibaba.fastjson.JSONObject; | import com.alibaba.fastjson.JSONObject; | ||||
| import com.inspect.analysis.domain.AnalyseLog; | |||||
| import com.inspect.analysis.domain.ResultAnalysis; | |||||
| import com.inspect.analysis.service.IResultAnalysisService; | |||||
| import com.inspect.base.core.utils.HttpClientUtils; | import com.inspect.base.core.utils.HttpClientUtils; | ||||
| import com.inspect.base.core.utils.StringUtils; | |||||
| import com.inspect.base.redis.service.RedisService; | |||||
| import com.inspect.bigmodel.service.IBigModelResultService; | import com.inspect.bigmodel.service.IBigModelResultService; | ||||
| import com.inspect.partrolresult.domain.PatrolResult; | |||||
| import com.inspect.partrolresult.service.IPatrolResultService; | |||||
| import com.inspect.task.domain.PatrolData; | |||||
| import com.inspect.task.service.IPatrolTaskService; | import com.inspect.task.service.IPatrolTaskService; | ||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.data.redis.core.RedisTemplate; | |||||
| import org.springframework.stereotype.Service; | import org.springframework.stereotype.Service; | ||||
| import java.util.List; | |||||
| @Service | @Service | ||||
| public class BigModelResultServiceImpl implements IBigModelResultService { | public class BigModelResultServiceImpl implements IBigModelResultService { | ||||
| private final Logger log = LoggerFactory.getLogger(BigModelResultServiceImpl.class); | private final Logger log = LoggerFactory.getLogger(BigModelResultServiceImpl.class); | ||||
| @Autowired | @Autowired | ||||
| private IPatrolTaskService patrolTaskService; | private IPatrolTaskService patrolTaskService; | ||||
| @Autowired | |||||
| private IResultAnalysisService resultAnalysisService; | |||||
| @Autowired | |||||
| private IPatrolResultService patrolResultService; | |||||
| @Autowired | |||||
| private RedisService redisService; | |||||
| @Override | @Override | ||||
| public JSONObject getBigModelResult() { | public JSONObject getBigModelResult() { | ||||
| String analyseFilter = patrolTaskService.selectConfigByKey("ANALYSE_FILTER_URL"); | |||||
| log.info("-----调用大模型结果接口地址,url:{}", analyseFilter + "/bigModel/record/latest"); | |||||
| String resultStr = null; | |||||
| try { | |||||
| resultStr = HttpClientUtils.get(analyseFilter + "/bigModel/record/latest", ""); | |||||
| } catch (Exception e) { | |||||
| log.error("调用大模型结果接口,返回数据异常,exception:{}", e.getMessage()); | |||||
| // String analyseFilter = patrolTaskService.selectConfigByKey("ANALYSE_FILTER_URL"); | |||||
| // log.info("-----调用大模型结果接口地址,url:{}", analyseFilter + "/bigModel/record/latest"); | |||||
| // String resultStr = null; | |||||
| // try { | |||||
| // resultStr = HttpClientUtils.get(analyseFilter + "/bigModel/record/latest", ""); | |||||
| // } catch (Exception e) { | |||||
| // log.error("调用大模型结果接口,返回数据异常,exception:{}", e.getMessage()); | |||||
| // } | |||||
| // log.error("调用大模型结果接口,返回数据,resultStr:{}", resultStr); | |||||
| // JSONObject result = JSONObject.parseObject(resultStr); | |||||
| // if (result != null && "200".equals(result.getString("code"))) { | |||||
| // return result.getJSONObject("data"); | |||||
| // } else { | |||||
| // log.error("调用大模型结果接口,返回数据,resultStr:{}", resultStr); | |||||
| // return result; | |||||
| // } | |||||
| JSONObject jsonObject = new JSONObject(); | |||||
| // ResultAnalysis resultAnalysis = new ResultAnalysis(); | |||||
| // resultAnalysis.setFilter("0"); | |||||
| // ResultAnalysis bigModelResult = resultAnalysisService.getLatestResult(resultAnalysis); | |||||
| // if (bigModelResult == null) { | |||||
| // return jsonObject; | |||||
| // } | |||||
| // resultAnalysis.setFilter("1"); | |||||
| // resultAnalysis.setAlgType(bigModelResult.getAlgType()); | |||||
| // resultAnalysis.setObjectId(bigModelResult.getObjectId()); | |||||
| // resultAnalysis.setTaskPatrolId(bigModelResult.getTaskPatrolId()); | |||||
| // ResultAnalysis filterResult = resultAnalysisService.getLatestResult(resultAnalysis); | |||||
| // AnalyseLog analyseLog = new AnalyseLog("","1",bigModelResult.getTaskPatrolId(),"0","", bigModelResult.getObjectId(), ""); | |||||
| // AnalyseLog analyseLog = new AnalyseLog("","","","","", "", ""); | |||||
| // analyseLog = resultAnalysisService.getAnalyseLog(analyseLog); | |||||
| if (!redisService.hasKey("patrol_infer")) { | |||||
| return jsonObject; | |||||
| } | |||||
| Object patrol_infer = redisService.getCacheObject("patrol_infer"); | |||||
| JSONObject result = JSONObject.parseObject(patrol_infer.toString()); | |||||
| // 原图路径 | |||||
| String original_image_path = result.getString("original_image_path"); | |||||
| // 大模型分析图片路径 | |||||
| String model_image_url = result.getString("model_image_url"); | |||||
| if (StringUtils.isNotEmpty(original_image_path) && !original_image_path.startsWith("/")) { | |||||
| original_image_path = "/" + original_image_path; | |||||
| } | } | ||||
| log.error("调用大模型结果接口,返回数据,resultStr:{}", resultStr); | |||||
| JSONObject result = JSONObject.parseObject(resultStr); | |||||
| if (result != null && "200".equals(result.getString("code"))) { | |||||
| return result.getJSONObject("data"); | |||||
| } else { | |||||
| log.error("调用大模型结果接口,返回数据,resultStr:{}", resultStr); | |||||
| return result; | |||||
| if (StringUtils.isNotEmpty(model_image_url) && !model_image_url.startsWith("/")) { | |||||
| model_image_url = "/" + model_image_url; | |||||
| } | } | ||||
| // 重点区域分割图片路径 | |||||
| jsonObject.put("keyZonePicture", original_image_path); | |||||
| // 特征点对比图片路径 | |||||
| jsonObject.put("featureComparePictureA", original_image_path); | |||||
| // 特征点对比图片B路径 | |||||
| jsonObject.put("featureComparePictureB", original_image_path); | |||||
| // 多模态大模型图片路径 | |||||
| jsonObject.put("bigModelPicture", model_image_url); | |||||
| // 多模态大模型图片返回说明 | |||||
| jsonObject.put("bigModelDesc", result.getString("model_analysis")); | |||||
| // 多模态大模型图片问题 | |||||
| jsonObject.put("bigModelProblem", result.getString("prompt")); | |||||
| // 日志信息 | |||||
| jsonObject.put("logInfo", "日志:" + result.toJSONString()); | |||||
| String object_id = result.getString("object_id"); | |||||
| if (!redisService.hasKey("patrol_infer:" + object_id)) { | |||||
| return jsonObject; | |||||
| } | |||||
| Object filterCacheObject = redisService.getCacheObject("patrol_infer:" + object_id); | |||||
| JSONObject filterResultJson = JSONObject.parseObject(filterCacheObject.toString()); | |||||
| String roi_dots = filterResultJson.getString("roi_dots"); | |||||
| String roi_result = filterResultJson.getString("roi_result"); | |||||
| if (StringUtils.isNotEmpty(roi_dots) && !roi_dots.startsWith("/")) { | |||||
| roi_dots = "/" + roi_dots; | |||||
| } | |||||
| if (StringUtils.isNotEmpty(roi_result) && !roi_result.startsWith("/")) { | |||||
| roi_result = "/" + roi_result; | |||||
| } | |||||
| // 特征点对比图片路径 | |||||
| jsonObject.put("featureComparePictureA", roi_dots); | |||||
| // 特征点对比图片B路径 | |||||
| jsonObject.put("featureComparePictureB", roi_result); | |||||
| return jsonObject; | |||||
| } | } | ||||
| } | } | ||||