@ -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 ) ;