Browse Source

/*将红外算法增加到初筛和大模型文件中。*/

master
htjcAdmin 8 months ago
parent
commit
cbf2628aed
4 changed files with 280 additions and 63 deletions
  1. +88
    -63
      src/main/java/com/inspect/simulator/controller/AlgorithmController.java
  2. +4
    -0
      src/main/java/com/inspect/simulator/domain/algorithm/in/AnalyseRequest.java
  3. +13
    -0
      src/main/java/com/inspect/simulator/service/AlgorithmService.java
  4. +175
    -0
      src/main/java/com/inspect/simulator/service/impl/AlgorithmServiceImpl.java

+ 88
- 63
src/main/java/com/inspect/simulator/controller/AlgorithmController.java View File

@ -5,10 +5,13 @@ import com.inspect.simulator.domain.algorithm.in.AnalyseRequest;
import com.inspect.simulator.domain.algorithm.out.AnalyseResItem;
import com.inspect.simulator.domain.algorithm.out.AnalyseResPoint;
import com.inspect.simulator.domain.algorithm.out.AnalyseResult;
import com.inspect.simulator.service.AlgorithmService;
import com.inspect.simulator.service.remote.AnalysisRemoteService;
import com.inspect.simulator.utils.HttpClientUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@ -25,78 +28,100 @@ public class AlgorithmController {
private final Logger log = LoggerFactory.getLogger(this.getClass());
@Resource
private AnalysisRemoteService analysisRemoteService;
private AlgorithmService algorithmService;
@PostMapping("/simu/filter/picAnalyse")
public ResponseEntity<String> filterPicAnalyse(@RequestBody final String analyseRequestStr) {
log.info("[FILTER] filterPicAnalyse: analyseRequestStr={}", 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());
AnalyseResPoint analyseResPoint = new AnalyseResPoint();
analyseResPoint.setValue("0");
analyseResPoint.setConf("0.85");
analyseResPoint.setCode("2000");
analyseResPoint.setResImageUrl(analyseRequest.getObjectList().get(0).getImageUrlList()[0]);
List<AnalyseResPoint> analyseResPoints = new ArrayList<>();
analyseResPoints.add(analyseResPoint);
AnalyseResItem analyseResItem = new AnalyseResItem();
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));
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 ResponseEntity.ok().body("{\"code\":\"200\"}");
// log.info("[FILTER] filterPicAnalyse: analyseRequestStr={}", 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());
// AnalyseResPoint analyseResPoint = new AnalyseResPoint();
// analyseResPoint.setValue("0");
// analyseResPoint.setConf("0.85");
// analyseResPoint.setCode("2000");
// analyseResPoint.setResImageUrl(analyseRequest.getObjectList().get(0).getImageUrlList()[0]);
// List<AnalyseResPoint> analyseResPoints = new ArrayList<>();
// analyseResPoints.add(analyseResPoint);
// AnalyseResItem analyseResItem = new AnalyseResItem();
// 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));
// 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 ResponseEntity.ok().body("{\"code\":\"200\"}");
return ResponseEntity.ok().body(algorithmService.filterPicAnalyse(analyseRequestStr));
}
@PostMapping("/simu/bigModel/picAnalyse")
public ResponseEntity<String> bigModelPicAnalyse(@RequestBody final String analyseRequestStr) {
log.info("[FILTER] bigModelPicAnalyse: analyseRequestStr={}", 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());
AnalyseResPoint analyseResPoint = new AnalyseResPoint();
analyseResPoint.setValue("1");
analyseResPoint.setConf("0.95");
analyseResPoint.setCode("2000");
analyseResPoint.setResImageUrl(analyseRequest.getObjectList().get(0).getImageUrlList()[0]);
List<AnalyseResPoint> analyseResPoints = new ArrayList<>();
analyseResPoints.add(analyseResPoint);
AnalyseResItem analyseResItem = new AnalyseResItem();
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] bigModelPicAnalyse: analyseRequestStr={}", 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());
// AnalyseResPoint analyseResPoint = new AnalyseResPoint();
// analyseResPoint.setValue("1");
// analyseResPoint.setConf("0.95");
// analyseResPoint.setCode("2000");
// analyseResPoint.setResImageUrl(analyseRequest.getObjectList().get(0).getImageUrlList()[0]);
// List<AnalyseResPoint> analyseResPoints = new ArrayList<>();
// analyseResPoints.add(analyseResPoint);
// AnalyseResItem analyseResItem = new AnalyseResItem();
// analyseResItem.setObjectId(analyseRequest.getObjectList().get(0).getObjectId());
// analyseResItem.setAlgFactory("yd");
// analyseResItem.setResults(analyseResPoints);
// List<AnalyseResItem> analyseResItems = new ArrayList<>();
// analyseResItems.add(analyseResItem);
// analyseResult.setResultList(analyseResItems);
//
//
// if(infraredPath.equals("null")) {
// // 如果nacos中没有配置红外路径则将结果返回调用方
// try {
// log.info("[BIG MODEL] filterPicAnalyse: nacos file.infraredPath not config, feedback to caller, analyseResult={}", new Gson().toJson(analyseResult));
// 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();
// }
// } 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);
// } catch (Exception e) {
// log.info("[BIG MODEL] continue to call infrared EXCEPTION: {}", e.getMessage());
// }
// }
// return ResponseEntity
// .ok()
// .body("{\"code\":\"200\"}");
return ResponseEntity.ok().body(algorithmService.bigModelPicAnalyse(analyseRequestStr));
}
log.info("[FILTER] bigModelPicAnalyse: analyseResult={}", new Gson().toJson(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();
}
@PostMapping("/simu/infrared/picAnalyse")
public ResponseEntity<String> infraredPicAnalyse(@RequestBody final String analyseRequestStr) {
return ResponseEntity
.ok()
.body("{\"code\":\"200\"}");
.body(algorithmService.infraredPicAnalyse(analyseRequestStr));
}
}

+ 4
- 0
src/main/java/com/inspect/simulator/domain/algorithm/in/AnalyseRequest.java View File

@ -21,6 +21,10 @@ public class AnalyseRequest implements Serializable {
private String requestId;
private String algorithmPath;
private String taskPatrolId;
private String sftpHostIp;
private String sftpHostPort;
private String sftpUsername;
private String sftpPassword;
public AnalyseRequest clone() {
return JSONObject.parseObject(JSONObject.toJSONString(this), AnalyseRequest.class);


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

@ -0,0 +1,13 @@
package com.inspect.simulator.service;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
public interface AlgorithmService {
String filterPicAnalyse(final String analyseRequestStr);
String bigModelPicAnalyse(final String analyseRequestStr);
String infraredPicAnalyse(final String analyseRequestStr);
}

+ 175
- 0
src/main/java/com/inspect/simulator/service/impl/AlgorithmServiceImpl.java View File

@ -0,0 +1,175 @@
package com.inspect.simulator.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
import com.inspect.simulator.domain.algorithm.in.AnalyseReqItem;
import com.inspect.simulator.domain.algorithm.in.AnalyseRequest;
import com.inspect.simulator.domain.algorithm.out.AnalyseResItem;
import com.inspect.simulator.domain.algorithm.out.AnalyseResPoint;
import com.inspect.simulator.domain.algorithm.out.AnalyseResult;
import com.inspect.simulator.service.AlgorithmService;
import com.inspect.simulator.service.remote.AnalysisRemoteService;
import com.inspect.simulator.utils.HttpClientUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import retrofit2.Call;
import retrofit2.Response;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
@Service
public class AlgorithmServiceImpl implements AlgorithmService {
private final Logger log = LoggerFactory.getLogger(this.getClass());
@Value("${file.infraredPath:null}")
private String infraredPath;
@Resource
private AnalysisRemoteService analysisRemoteService;
@Override
public String filterPicAnalyse(String analyseRequestStr) {
log.info("[FILTER] filterPicAnalyse: analyseRequestStr={}", 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());
AnalyseResPoint analyseResPoint = new AnalyseResPoint();
analyseResPoint.setValue("0");
analyseResPoint.setConf("0.85");
analyseResPoint.setCode("2000");
analyseResPoint.setResImageUrl(analyseRequest.getObjectList().get(0).getImageUrlList()[0]);
List<AnalyseResPoint> analyseResPoints = new ArrayList<>();
analyseResPoints.add(analyseResPoint);
AnalyseResItem analyseResItem = new AnalyseResItem();
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));
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 "{\"code\":\"200\"}";
}
@Override
public String bigModelPicAnalyse(String analyseRequestStr) {
log.info("[FILTER] bigModelPicAnalyse: analyseRequestStr={}", 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());
AnalyseResPoint analyseResPoint = new AnalyseResPoint();
analyseResPoint.setValue("1");
analyseResPoint.setConf("0.95");
analyseResPoint.setCode("2000");
analyseResPoint.setResImageUrl(analyseRequest.getObjectList().get(0).getImageUrlList()[0]);
List<AnalyseResPoint> analyseResPoints = new ArrayList<>();
analyseResPoints.add(analyseResPoint);
AnalyseResItem analyseResItem = new AnalyseResItem();
analyseResItem.setObjectId(analyseRequest.getObjectList().get(0).getObjectId());
analyseResItem.setAlgFactory("yd");
analyseResItem.setResults(analyseResPoints);
List<AnalyseResItem> analyseResItems = new ArrayList<>();
analyseResItems.add(analyseResItem);
analyseResult.setResultList(analyseResItems);
if (infraredPath.equals("null")) {
// 如果nacos中没有配置红外路径则将结果返回调用方
try {
log.info("[BIG MODEL] filterPicAnalyse: nacos file.infraredPath not config, feedback to caller, analyseResult={}", new Gson().toJson(analyseResult));
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();
}
} 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);
} catch (Exception e) {
log.info("[BIG MODEL] continue to call infrared EXCEPTION: {}", e.getMessage());
}
}
return "{\"code\":\"200\"}";
}
@Override
public String infraredPicAnalyse(String analyseRequestStr) {
log.info("[INFRARED] irPicAnalyse: analyseRequestStr={}", analyseRequestStr);
AnalyseRequest analyseRequest;
try {
analyseRequest = new Gson().fromJson(analyseRequestStr, AnalyseRequest.class);
} catch (Exception e) {
log.error("[INFRARED] irPicAnalyse: analyseRequestJson parse exception: {}", e.getMessage());
return "{\"code\":\"201\"}";
}
log.info("[INFRARED] irPicAnalyse: analyseRequest={}", new Gson().toJson(analyseRequest));
List<AnalyseReqItem> analyseReqItemList = analyseRequest.getObjectList();
if(analyseReqItemList == null || analyseReqItemList.isEmpty()) {
log.error("[INFRARED] irPicAnalyse: analyseReqItemList empty!");
return "{\"code\":\"202\"}";
}
final AnalyseReqItem analyseReqItem = analyseReqItemList.get(0);
final String[] typeList = analyseReqItem.getTypeList();
String algType = "unKnownType";
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);
AnalyseResult analyseResult = new AnalyseResult();
analyseResult.setRequestId(analyseRequest.getRequestId());
AnalyseResPoint analyseResPoint = new AnalyseResPoint();
analyseResPoint.setValue("0");
analyseResPoint.setConf("0.85");
analyseResPoint.setCode("2000");
analyseResPoint.setResImageUrl(analyseRequest.getObjectList().get(0).getImageUrlList()[0]);
List<AnalyseResPoint> analyseResPoints = new ArrayList<>();
analyseResPoints.add(analyseResPoint);
AnalyseResItem analyseResItem = new AnalyseResItem();
analyseResItem.setObjectId(analyseRequest.getObjectList().get(0).getObjectId());
analyseResItem.setAlgFactory(algType);
analyseResItem.setResults(analyseResPoints);
List<AnalyseResItem> analyseResItems = new ArrayList<>();
analyseResItems.add(analyseResItem);
analyseResult.setResultList(analyseResItems);
try {
String analyseResultOutJson = JSONObject.toJSONString(analyseResult);
log.info("[INFRARED] irPicAnalyse: feedbackUrl={}, analyseResultOutJson={}", feedbackUrl, analyseResultOutJson);
String result = HttpClientUtils.sendPostAgain(feedbackUrl, analyseResultOutJson);
log.info("[INFRARED] irPicAnalyse: feedbackUrl={}, result: {}", feedbackUrl, result);
} catch (Exception e) {
log.info("[INFRARED] irPicAnalyse: feedbackUrl={}, EXCEPTION: {}", feedbackUrl, e.getMessage());
}
return "{\"code\":\"200\"}";
}
}

Loading…
Cancel
Save