Browse Source

/*灵州站红外适配*/

master
htjcAdmin 5 months ago
parent
commit
acef807e6b
4 changed files with 133 additions and 132 deletions
  1. +0
    -46
      src/main/java/com/inspect/simulator/controller/AlgorithmController.java
  2. +55
    -56
      src/main/java/com/inspect/simulator/controller/IvsServerController.java
  3. +35
    -30
      src/main/java/com/inspect/simulator/service/impl/AlgorithmServiceImpl.java
  4. +43
    -0
      src/main/java/com/inspect/simulator/utils/MiscUtils.java

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

@ -69,52 +69,6 @@ public class AlgorithmController {
@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);
//
//
// 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));
}


+ 55
- 56
src/main/java/com/inspect/simulator/controller/IvsServerController.java View File

@ -2,6 +2,8 @@ package com.inspect.simulator.controller;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
import com.inspect.simulator.constant.AlgConstants;
import com.inspect.simulator.domain.analysis.vi.AnalysisObject;
import com.inspect.simulator.domain.analysis.vi.AnalysisRequest;
import com.inspect.simulator.domain.analysis.vo.AnalysisResult;
import com.inspect.simulator.domain.analysis.vo.AnalysisResultEntity;
@ -9,8 +11,10 @@ import com.inspect.simulator.domain.analysis.vo.AnalysisResultList;
import com.inspect.simulator.domain.ivs.*;
import com.inspect.simulator.service.remote.AnalysisRemoteService;
import com.inspect.simulator.utils.MiscUtils;
import com.inspect.simulator.view.IvsPlatformSnapshotView;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
@ -32,9 +36,9 @@ import java.nio.file.Files;
import java.util.*;
import java.util.List;
@Slf4j
@RestController
public class IvsServerController {
private final Logger log = LoggerFactory.getLogger(this.getClass());
private final String TASK_CODE = "1234567890";
private final String PIC_URL = "https://image.baidu.com/search/detail?ct=503316480&z=0&ipn=d&word=songbird&step_word=&hs=0&pn=15&spn=0&di=7360350738658099201&pi=0&rn=1&tn=baiduimagedetail&is=0%2C0&istype=2&ie=utf-8&oe=utf-8&in=&cl=2&lm=&st=-1&cs=1060316073%2C1951231255&os=2156611125%2C946097664&simid=60689125%2C716595069&adpicid=0&lpn=0&ln=1080&fr=&fmq=1718353459191_R&fm=result&ic=0&s=undefined&hd=&latest=&copyright=&se=&sme=&tab=0&width=&height=&face=undefined&ist=&jit=&cg=&bdtype=0&oriquery=&objurl=https%3A%2F%2Fup.sc.enterdesk.com%2Fedpic%2Ff4%2F4a%2Fee%2Ff44aeeb12debd4e56faf34d72890d76d.jpg&fromurl=ippr_z2C%24qAzdH3FAzdH3F4_z%26e3Bfv_z%26e3Bjgpj61jfh_z%26e3Bv54AzdH3F_jgAzdH3Ff7vwtAzdH3Fnbn8lb_z%26e3Bip4s&gsm=1e&rpstart=0&rpnum=0&islist=&querylist=&nojc=undefined&lid=6977254189663851692";
@ -276,67 +280,62 @@ public class IvsServerController {
}
}
@PostMapping({"/picAnalyse"})
public ResponseEntity<String> picAnalyse(@RequestBody AnalysisRequest analysisRequest) {
log.info("[GAB] analysisRequest!!!!!!: {}", analysisRequest.toString());
// OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder();
// Interceptor interceptor = chain -> {
// Request request = chain.request().newBuilder().addHeader("Authorization", "token 012345678").build();
// return chain.proceed(request);
// };
//
// clientBuilder.interceptors().add(interceptor);
// Retrofit retrofit = new Retrofit.Builder()
// .baseUrl(analysisRequest.getRequestHostIp() + ":" + analysisRequest.getRequestHostPort())
// .client(clientBuilder.build())
// .addConverterFactory(JacksonConverterFactory.create())
// .build();
AnalysisResult analysisResult = AnalysisResult.builder()
.code("2000")
.resImageUrl(analysisRequest.getObjectList().get(0).getImageUrlList().get(0))
.pos(Arrays.asList(""))
.conf(0.99)
.value("30")
.type("meter")
.desc("blablabla")
.build();
List<AnalysisResult> results = new ArrayList<>();
results.add(analysisResult);
AnalysisResultList analysisResultList = AnalysisResultList.builder()
.algFactory("yd")
.objectId(analysisRequest.getObjectList().get(0).getObjectId())
.results(results)
.build();
List<AnalysisResultList> resultList = new ArrayList<>();
resultList.add(analysisResultList);
AnalysisResultEntity analysisResultEntity = AnalysisResultEntity.builder()
.requestId(analysisRequest.getRequestId())
.resultList(resultList)
.build();
final String analysisResultJson = new Gson().toJson(analysisResultEntity);
System.out.println("res entity: \n" + analysisResultJson);
try {
JSONObject parseObject = JSONObject.parseObject(analysisResultJson);
System.out.println("parseObject: \n" + parseObject);
} catch (Exception e) {
e.printStackTrace();
log.info("PIC_ANALYZE PARAMS: {}", analysisRequest.toString());
if(analysisRequest.getObjectList() == null || analysisRequest.getObjectList().isEmpty()) {
return ResponseEntity.ok().body("Invalid Parameter: " + analysisRequest);
}
AnalysisObject analysisObject = analysisRequest.getObjectList().get(0);
List<String> typeList = analysisObject.getTypeList();
if(MiscUtils.checkInfraredType(typeList)) {
log.info("INFRARED_PROC, CALL IR PIC_ANALYZE");
} else {
log.info("SIMULATOR_PROC, RETURN TEST DATA");
AnalysisResult analysisResult = AnalysisResult.builder()
.code("2000")
.resImageUrl(analysisRequest.getObjectList().get(0).getImageUrlList().get(0))
.pos(Arrays.asList(""))
.conf(0.99)
.value("30")
.type("meter")
.desc("blablabla")
.build();
List<AnalysisResult> results = new ArrayList<>();
results.add(analysisResult);
AnalysisResultList analysisResultList = AnalysisResultList.builder()
.algFactory("atia")
.objectId(analysisRequest.getObjectList().get(0).getObjectId())
.results(results)
.build();
List<AnalysisResultList> resultList = new ArrayList<>();
resultList.add(analysisResultList);
AnalysisResultEntity analysisResultEntity = AnalysisResultEntity.builder()
.requestId(analysisRequest.getRequestId())
.resultList(resultList)
.build();
try {
Call<Object> call = analysisRemoteService.analysisResultNotify(analysisResultEntity);
Response<Object> response = call.execute();
Object result = response.body();
System.out.println("result: " + result);
} catch (Exception e) {
e.printStackTrace();
final String analysisResultJson = new Gson().toJson(analysisResultEntity);
System.out.println("res entity: \n" + analysisResultJson);
try {
JSONObject parseObject = JSONObject.parseObject(analysisResultJson);
System.out.println("parseObject: \n" + parseObject);
} catch (Exception e) {
e.printStackTrace();
}
try {
Call<Object> call = analysisRemoteService.analysisResultNotify(analysisResultEntity);
Response<Object> response = call.execute();
Object result = response.body();
System.out.println("result: " + result);
} catch (Exception e) {
e.printStackTrace();
}
}
return ResponseEntity.ok().body("This is the test result!");
}
}

+ 35
- 30
src/main/java/com/inspect/simulator/service/impl/AlgorithmServiceImpl.java View File

@ -1,6 +1,7 @@
package com.inspect.simulator.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.nacos.common.utils.StringUtils;
import com.google.gson.Gson;
import com.inspect.simulator.constant.Color;
import com.inspect.simulator.domain.Infrared.Coordinate;
@ -11,6 +12,7 @@ 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.domain.analysis.vi.AnalysisObject;
import com.inspect.simulator.domain.basedata.BasedataEqpBookChannel;
import com.inspect.simulator.domain.result.BasedataPatrolPoint;
import com.inspect.simulator.domain.result.PatrolPresetPos;
@ -19,6 +21,7 @@ import com.inspect.simulator.mapper.PatrolPresetPosMapper;
import com.inspect.simulator.service.AlgorithmService;
import com.inspect.simulator.service.remote.AnalysisRemoteService;
import com.inspect.simulator.utils.HttpClientUtils;
import com.inspect.simulator.utils.MiscUtils;
import com.inspect.simulator.utils.redis.RedisService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -97,11 +100,15 @@ public class AlgorithmServiceImpl implements AlgorithmService {
@Override
public String bigModelPicAnalyse(String analyseRequestStr) {
log.info(Color.MAGENTA + "[BIG MODEL] bigModelPicAnalyse: analyseRequestStr={}" + Color.END, analyseRequestStr);
log.info(Color.MAGENTA + "BIG_MODEL_ANALYZE bigModelPicAnalyse: infraredPath: {}, analyseRequestStr={}" + Color.END, infraredPath, analyseRequestStr);
AnalyseRequest analyseRequest = new Gson().fromJson(analyseRequestStr, AnalyseRequest.class);
if (analyseRequest.getObjectList() == null || analyseRequest.getObjectList().isEmpty()) {
return "Invalid Parameter: " + analyseRequestStr;
}
String[] typeList = analyseRequest.getObjectList().get(0).getTypeList();
String typeListStr = String.join(",", typeList);
AnalyseReqItem analyseReqItem = analyseRequest.getObjectList().get(0);
String[] typeList = analyseReqItem.getTypeList();
String typeListStr = String.join(StringUtils.COMMA, typeList);
AnalyseResult analyseResult = new AnalyseResult();
analyseResult.setRequestId(analyseRequest.getRequestId());
AnalyseResPoint analyseResPoint = new AnalyseResPoint();
@ -114,62 +121,60 @@ public class AlgorithmServiceImpl implements AlgorithmService {
analyseResPoints.add(analyseResPoint);
AnalyseResItem analyseResItem = new AnalyseResItem();
analyseResItem.setObjectId(analyseRequest.getObjectList().get(0).getObjectId());
analyseResItem.setAlgFactory("yd");
analyseResItem.setAlgFactory("atia");
analyseResItem.setResults(analyseResPoints);
List<AnalyseResItem> analyseResItems = new ArrayList<>();
analyseResItems.add(analyseResItem);
analyseResult.setResultList(analyseResItems);
if (infraredPath.equals("null")) {
// 如果nacos中没有配置红外路径则将结果返回调用方
try {
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();
System.out.println("result: " + result);
} catch (Exception e) {
e.printStackTrace();
}
} else {
// 如果nacos中配置了红外路径则继续调用红外模块
if (MiscUtils.checkInfraredType(typeList) && !"null".equals(infraredPath)) {
try {
log.info(Color.MAGENTA + "[BIG MODEL] filterPicAnalyse: continue to call infrared, infraredPath: {}, analyseRequestStr={}" + Color.END, infraredPath, analyseRequestStr);
log.info(Color.MAGENTA + "BIG_MODEL_INFRARED 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 infraredResult = HttpClientUtils.sendPostAgain(infraredPath, analyseRequestStrNew);
log.info(Color.MAGENTA + "[BIG MODEL] FROM infrared RESULT: {}" + Color.END, infraredResult);
log.info(Color.MAGENTA + "BIG_MODEL_INFRARED RESULT: {}" + Color.END, infraredResult);
// 返回给智巡服务器
AnalyseResult analyseResultFromInfrared = new Gson().fromJson(infraredResult, AnalyseResult.class);
Call<Object> call = analysisRemoteService.picAnalyseRetNotify(analyseResultFromInfrared);
Response<Object> response = call.execute();
Object objectFromPatrolMain = response.body();
log.info(Color.MAGENTA + "[BIG MODEL] FROM PATROL-MAIN: {}", objectFromPatrolMain);
log.info(Color.MAGENTA + "[BIG MODEL] FROM PATROL-MAIN: {}", objectFromPatrolMain);
} catch (Exception e) {
log.error("[BIG MODEL] continue to call infrared EXCEPTION: {}", e.getMessage());
log.error("BIG_MODEL_INFRARED continue to call infrared EXCEPTION: {}", e.getMessage());
}
} else {
try {
log.info(Color.MAGENTA + "BIG_MODEL_COMMON 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();
System.out.println("result: " + result);
} catch (Exception e) {
log.error("BIG_MODEL_COMMON EXCEPTION: {}", e.getMessage());
}
}
return "{\"code\":\"200\"}";
}
@Override
public String infraredPicAnalyse(String analyseRequestStr) {
log.info(Color.MAGENTA + "[INFRARED] irPicAnalyse: analyseRequestStr={}" + Color.END, analyseRequestStr);
log.info(Color.MAGENTA + "INFRARED_PIC_ANALYZE irPicAnalyse: analyseRequestStr={}" + Color.END, analyseRequestStr);
AnalyseRequest analyseRequest;
try {
analyseRequest = new Gson().fromJson(analyseRequestStr, AnalyseRequest.class);
} catch (Exception e) {
log.error(Color.MAGENTA + "[INFRARED] irPicAnalyse: analyseRequestJson parse exception: {}" + Color.END, e.getMessage());
log.error(Color.MAGENTA + "INFRARED_PIC_ANALYZE irPicAnalyse: analyseRequestJson parse exception: {}" + Color.END, e.getMessage());
return "{\"code\":\"201\"}";
}
log.info(Color.MAGENTA + "[INFRARED] irPicAnalyse: analyseRequest={}" + Color.END, new Gson().toJson(analyseRequest));
log.info(Color.MAGENTA + "INFRARED_PIC_ANALYZE irPicAnalyse: analyseRequest={}" + Color.END, new Gson().toJson(analyseRequest));
List<AnalyseReqItem> analyseReqItemList = analyseRequest.getObjectList();
if (analyseReqItemList == null || analyseReqItemList.isEmpty()) {
log.error("[INFRARED] irPicAnalyse: analyseReqItemList empty!");
log.error("INFRARED_PIC_ANALYZE irPicAnalyse: analyseReqItemList empty!");
return "{\"code\":\"202\"}";
}
@ -196,19 +201,19 @@ public class AlgorithmServiceImpl implements AlgorithmService {
basedataPatrolPoint.setPatrolPointCode(patrolPointId);
List<BasedataPatrolPoint> basedataPatrolPoints = basedataPatrolPointMapper.selectBasedataPatrolPointListLikePointCode(basedataPatrolPoint);
if (basedataPatrolPoints == null || basedataPatrolPoints.isEmpty()) {
log.error("[INFRARED] irPicAnalyse: basedataPatrolPoints empty!");
log.error("INFRARED_PIC_ANALYZE irPicAnalyse: basedataPatrolPoints empty!");
return "{\"code\":\"203\"}";
}
BasedataPatrolPoint basedataPatrolPoint2 = basedataPatrolPoints.get(0);
final String infraFrameContent = basedataPatrolPoint2.getMeterType();
log.info(Color.MAGENTA + "[INFRARED] irPicAnalyse: basedataPatrolPoint2: {}, infraFrameContent={}" + Color.END, basedataPatrolPoint2, infraFrameContent);
log.info(Color.MAGENTA + "INFRARED_PIC_ANALYZE irPicAnalyse: basedataPatrolPoint2: {}, infraFrameContent={}" + Color.END, basedataPatrolPoint2, infraFrameContent);
String[] imageUrlList = analyseReqItem.getImageUrlList();
String[] typeListImg = analyseReqItem.getTypeList();
// 调用红外算法
InfraPictureInfo infraPictureInfo = new InfraPictureInfo();
infraPictureInfo.setImgType(typeListImg[0]);
infraPictureInfo.setFilePath(imageUrlList[0]);
InfraredInfo infraredInfo = hikVisionService.calculatePicture(infraPictureInfo,infraFrameContent);
InfraredInfo infraredInfo = hikVisionService.calculatePicture(infraPictureInfo, infraFrameContent);
final String feedBackHostIp = analyseRequest.getRequestHostIp();
final String feedBackPort = analyseRequest.getRequestHostPort();
@ -243,7 +248,7 @@ public class AlgorithmServiceImpl implements AlgorithmService {
analyseResItems.add(analyseResItem);
analyseResult.setResultList(analyseResItems);
log.info(Color.GREEN+"返回值打印: 最高温度值"+analyseResPoint.getValue()+",返回图片路径:"+analyseResPoint.getResImageUrl());
log.info(Color.GREEN + "返回值打印: 最高温度值" + analyseResPoint.getValue() + ",返回图片路径:" + analyseResPoint.getResImageUrl());
// try {
//// String analyseResultOutJson = JSONObject.toJSONString(analyseResult);
// String analyseResultOutJson = new Gson().toJson(analyseResult);


+ 43
- 0
src/main/java/com/inspect/simulator/utils/MiscUtils.java View File

@ -0,0 +1,43 @@
package com.inspect.simulator.utils;
import com.inspect.simulator.constant.AlgConstants;
import lombok.extern.slf4j.Slf4j;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@Slf4j
public class MiscUtils {
private static final Set<String> INFRARED_TYPES = new HashSet<>(Arrays.asList(
AlgConstants.INFRA_1800,
AlgConstants.INFRA_YU3,
AlgConstants.INFRA_CAMERA,
AlgConstants.INFRA_CAMERA_REVERSE
));
public static boolean checkInfraredType(List<String> typeList) {
if (typeList == null) {
return false;
}
for (String type : typeList) {
if (INFRARED_TYPES.contains(type)) {
return true;
}
}
return false;
}
public static boolean checkInfraredType(String[] typeList) {
if (typeList == null) {
return false;
}
for (String type : typeList) {
if (INFRARED_TYPES.contains(type)) {
return true;
}
}
return false;
}
}

Loading…
Cancel
Save