Browse Source

/*红外流程贯通过程中bug修改。*/

master
htjcAdmin 8 months ago
parent
commit
e5fb75aec0
3 changed files with 60 additions and 21 deletions
  1. +8
    -0
      src/main/java/com/inspect/simulator/controller/AlgorithmController.java
  2. +2
    -0
      src/main/java/com/inspect/simulator/service/AlgorithmService.java
  3. +50
    -21
      src/main/java/com/inspect/simulator/service/impl/AlgorithmServiceImpl.java

+ 8
- 0
src/main/java/com/inspect/simulator/controller/AlgorithmController.java View File

@ -124,4 +124,12 @@ public class AlgorithmController {
.ok()
.body(algorithmService.infraredPicAnalyse(analyseRequestStr));
}
@PostMapping("/simu/bigModel/picAnalyseRetNotify")
public ResponseEntity<String> bigModelPicAnalyseRetNotify(@RequestBody String picAnalyseResult) {
return ResponseEntity
.ok()
.body(algorithmService.bigModelPicAnalyseRetNotify(picAnalyseResult));
}
}

+ 2
- 0
src/main/java/com/inspect/simulator/service/AlgorithmService.java View File

@ -10,4 +10,6 @@ public interface AlgorithmService {
String bigModelPicAnalyse(final String analyseRequestStr);
String infraredPicAnalyse(final String analyseRequestStr);
String bigModelPicAnalyseRetNotify(final String picAnalyseResult);
}

+ 50
- 21
src/main/java/com/inspect/simulator/service/impl/AlgorithmServiceImpl.java View File

@ -2,6 +2,7 @@ package com.inspect.simulator.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
import com.inspect.simulator.constant.Color;
import com.inspect.simulator.domain.algorithm.in.AnalyseReqItem;
import com.inspect.simulator.domain.algorithm.in.AnalyseRequest;
import com.inspect.simulator.domain.algorithm.out.AnalyseResItem;
@ -34,9 +35,8 @@ public class AlgorithmServiceImpl implements AlgorithmService {
@Override
public String filterPicAnalyse(String analyseRequestStr) {
log.info("[FILTER] filterPicAnalyse: analyseRequestStr={}", analyseRequestStr);
log.info(Color.MAGENTA + "[FILTER] filterPicAnalyse: analyseRequestStr={}" + Color.END, analyseRequestStr);
AnalyseRequest analyseRequest = new Gson().fromJson(analyseRequestStr, AnalyseRequest.class);
log.info("[FILTER] filterPicAnalyse: analyseRequest={}", new Gson().toJson(analyseRequest));
AnalyseResult analyseResult = new AnalyseResult();
analyseResult.setRequestId(analyseRequest.getRequestId());
@ -44,6 +44,7 @@ public class AlgorithmServiceImpl implements AlgorithmService {
analyseResPoint.setValue("0");
analyseResPoint.setConf("0.85");
analyseResPoint.setCode("2000");
analyseResPoint.setType("meter");
analyseResPoint.setResImageUrl(analyseRequest.getObjectList().get(0).getImageUrlList()[0]);
List<AnalyseResPoint> analyseResPoints = new ArrayList<>();
analyseResPoints.add(analyseResPoint);
@ -51,11 +52,12 @@ public class AlgorithmServiceImpl implements AlgorithmService {
analyseResItem.setObjectId(analyseRequest.getObjectList().get(0).getObjectId());
analyseResItem.setAlgFactory("yd");
analyseResItem.setResults(analyseResPoints);
List<AnalyseResItem> analyseResItems = new ArrayList<>();
analyseResItems.add(analyseResItem);
analyseResult.setResultList(analyseResItems);
log.info("[FILTER] filterPicAnalyse: analyseResult={}", new Gson().toJson(analyseResult));
log.info(Color.MAGENTA + "[FILTER] filterPicAnalyse: analyseResult={}" + Color.END, new Gson().toJson(analyseResult));
try {
Call<Object> call = analysisRemoteService.picAnalyseRetNotify(analyseResult);
Response<Object> response = call.execute();
@ -69,9 +71,8 @@ public class AlgorithmServiceImpl implements AlgorithmService {
@Override
public String bigModelPicAnalyse(String analyseRequestStr) {
log.info("[FILTER] bigModelPicAnalyse: analyseRequestStr={}", analyseRequestStr);
log.info(Color.MAGENTA + "[BIG MODEL] bigModelPicAnalyse: analyseRequestStr={}" + Color.END, analyseRequestStr);
AnalyseRequest analyseRequest = new Gson().fromJson(analyseRequestStr, AnalyseRequest.class);
log.info("[FILTER] bigModelPicAnalyse: analyseRequest={}", new Gson().toJson(analyseRequest));
AnalyseResult analyseResult = new AnalyseResult();
analyseResult.setRequestId(analyseRequest.getRequestId());
@ -93,7 +94,7 @@ public class AlgorithmServiceImpl implements AlgorithmService {
if (infraredPath.equals("null")) {
// 如果nacos中没有配置红外路径则将结果返回调用方
try {
log.info("[BIG MODEL] filterPicAnalyse: nacos file.infraredPath not config, feedback to caller, analyseResult={}", new Gson().toJson(analyseResult));
log.info(Color.MAGENTA + "[BIG MODEL] filterPicAnalyse: nacos file.infraredPath not config, feedback to caller, analyseResult={}" + Color.END, new Gson().toJson(analyseResult));
Call<Object> call = analysisRemoteService.picAnalyseRetNotify(analyseResult);
Response<Object> response = call.execute();
Object result = response.body();
@ -104,31 +105,57 @@ public class AlgorithmServiceImpl implements AlgorithmService {
} else {
// 如果nacos中配置了红外路径则继续调用红外模块
try {
log.info("[BIG MODEL] filterPicAnalyse: continue to call infrared, infraredPath: {}, analyseRequestStr={}", infraredPath, analyseRequestStr);
String result = HttpClientUtils.sendPostAgain(infraredPath, analyseRequestStr);
log.info("[BIG MODEL] continue to call infrared RESULT: {}", result);
log.info(Color.MAGENTA + "[BIG MODEL] filterPicAnalyse: continue to call infrared, infraredPath: {}, analyseRequestStr={}" + Color.END, infraredPath, analyseRequestStr);
// 将请求红外的发起方地址改为大模型的地址
analyseRequest.setRequestHostIp("199.199.199.210");
analyseRequest.setRequestHostPort("18530");
final String analyseRequestStrNew = new Gson().toJson(analyseRequest);
String result = HttpClientUtils.sendPostAgain(infraredPath, analyseRequestStrNew);
log.info(Color.MAGENTA + "[BIG MODEL] FROM infrared RESULT: {}" + Color.END, result);
// 返回给智巡服务器
// AnalyseResult analyseResultFromInfrared = new Gson().fromJson(analyseRequestStr, AnalyseResult.class);
// Call<Object> call = analysisRemoteService.picAnalyseRetNotify(analyseResultFromInfrared);
// Response<Object> response = call.execute();
// Object result2 = response.body();
// System.out.println("result2: " + result2);
// log.info(Color.MAGENTA + "[BIG MODEL] result2: {}" + Color.END, result2);
} catch (Exception e) {
log.info("[BIG MODEL] continue to call infrared EXCEPTION: {}", e.getMessage());
log.error("[BIG MODEL] continue to call infrared EXCEPTION: {}", e.getMessage());
}
}
return "{\"code\":\"200\"}";
}
@Override
public String bigModelPicAnalyseRetNotify(final String picAnalyseResult) {
AnalyseResult analyseResult = new Gson().fromJson(picAnalyseResult, AnalyseResult.class);
log.info(Color.MAGENTA + "[BIG MODEL] bigModelPicAnalyseRetNotify: picAnalyseResultStr={}, picAnalyseResult: {}" + Color.END, picAnalyseResult, analyseResult);
try {
Call<Object> call = analysisRemoteService.picAnalyseRetNotify(analyseResult);
Response<Object> response = call.execute();
Object result = response.body();
System.out.println("result: " + result);
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
@Override
public String infraredPicAnalyse(String analyseRequestStr) {
log.info("[INFRARED] irPicAnalyse: analyseRequestStr={}", analyseRequestStr);
log.info(Color.MAGENTA + "[INFRARED] irPicAnalyse: analyseRequestStr={}" + Color.END, analyseRequestStr);
AnalyseRequest analyseRequest;
try {
analyseRequest = new Gson().fromJson(analyseRequestStr, AnalyseRequest.class);
} catch (Exception e) {
log.error("[INFRARED] irPicAnalyse: analyseRequestJson parse exception: {}", e.getMessage());
log.error(Color.MAGENTA + "[INFRARED] irPicAnalyse: analyseRequestJson parse exception: {}" + Color.END, e.getMessage());
return "{\"code\":\"201\"}";
}
log.info("[INFRARED] irPicAnalyse: analyseRequest={}", new Gson().toJson(analyseRequest));
log.info(Color.MAGENTA + "[INFRARED] irPicAnalyse: analyseRequest={}" + Color.END, new Gson().toJson(analyseRequest));
List<AnalyseReqItem> analyseReqItemList = analyseRequest.getObjectList();
if(analyseReqItemList == null || analyseReqItemList.isEmpty()) {
if (analyseReqItemList == null || analyseReqItemList.isEmpty()) {
log.error("[INFRARED] irPicAnalyse: analyseReqItemList empty!");
return "{\"code\":\"202\"}";
}
@ -136,13 +163,13 @@ public class AlgorithmServiceImpl implements AlgorithmService {
final AnalyseReqItem analyseReqItem = analyseReqItemList.get(0);
final String[] typeList = analyseReqItem.getTypeList();
String algType = "unKnownType";
if(typeList != null && typeList.length != 0) {
if (typeList != null && typeList.length != 0) {
algType = typeList[0];
}
final String feedBackHostIp = analyseRequest.getRequestHostIp();
final String feedBackPort = analyseRequest.getRequestHostPort();
final String feedbackUrl = feedBackHostIp + feedBackPort + "/picAnalyseRetNotify";
log.info("[INFRARED] irPicAnalyse: feedbackUrl={}", feedbackUrl);
final String feedbackUrl = "http://" + feedBackHostIp + ":" + feedBackPort + "/simu/bigModel/picAnalyseRetNotify";
log.info(Color.MAGENTA + "[INFRARED] irPicAnalyse: feedbackUrl={}" + Color.END, feedbackUrl);
AnalyseResult analyseResult = new AnalyseResult();
analyseResult.setRequestId(analyseRequest.getRequestId());
@ -162,14 +189,16 @@ public class AlgorithmServiceImpl implements AlgorithmService {
analyseResult.setResultList(analyseResItems);
try {
String analyseResultOutJson = JSONObject.toJSONString(analyseResult);
log.info("[INFRARED] irPicAnalyse: feedbackUrl={}, analyseResultOutJson={}", feedbackUrl, analyseResultOutJson);
//String analyseResultOutJson = JSONObject.toJSONString(analyseResult);
String analyseResultOutJson = new Gson().toJson(analyseResult);
log.info(Color.MAGENTA + "[INFRARED] irPicAnalyse: feedbackUrl={}, analyseResultOutJson={}" + Color.END, feedbackUrl, analyseResultOutJson);
String result = HttpClientUtils.sendPostAgain(feedbackUrl, analyseResultOutJson);
log.info("[INFRARED] irPicAnalyse: feedbackUrl={}, result: {}", feedbackUrl, result);
log.info(Color.MAGENTA + "[INFRARED] irPicAnalyse: feedbackUrl={}, result: {}" + Color.END, feedbackUrl, result);
} catch (Exception e) {
log.info("[INFRARED] irPicAnalyse: feedbackUrl={}, EXCEPTION: {}", feedbackUrl, e.getMessage());
log.error("[INFRARED] irPicAnalyse: feedbackUrl={}, EXCEPTION: {}", feedbackUrl, e.getMessage());
}
return "{\"code\":\"200\"}";
}
}

Loading…
Cancel
Save