Browse Source

/*修改一个预置位经过初筛算法和大模型算法调用之后,result_analysis只有一条大模型记录的bug,按照常理,应该有两条结果,一条是初筛结果,一条是大模型结果。*/

master
htjcAdmin 8 months ago
parent
commit
eda0e26bcb
2 changed files with 176 additions and 158 deletions
  1. +174
    -158
      inspect-main/inspect-main-task/src/main/java/com/inspect/analysis/service/impl/AnalysisServiceImpl.java
  2. +2
    -0
      inspect-main/inspect-main-task/src/main/resources/mapper/task/ResultAnalysisMapper.xml

+ 174
- 158
inspect-main/inspect-main-task/src/main/java/com/inspect/analysis/service/impl/AnalysisServiceImpl.java View File

@ -64,7 +64,7 @@ public class AnalysisServiceImpl implements IAnalysisService {
@Override
public void picAnalyseRetNotify(AnalyseResult analyseResult) {
log.info(Color.CYAN + "###### 分析算法模块返回的表计识别结果 start, isTest={} ######" + Color.END, analyseResult.isTest());
log.info(Color.CYAN + "###### 分析算法模块返回的表计识别结果 start, analyseResult:{} ######" + Color.END, analyseResult);
String requestId = analyseResult.getRequestId();
String keyId = AnalyseConstants.ANALYSE_REQUEST_ID.concat(requestId);
if (!redisService.hasKey(keyId)) {
@ -80,9 +80,11 @@ public class AnalysisServiceImpl implements IAnalysisService {
analyseResult.setTaskPatrolId(patrolTaskIdObj);
String keyFilterRequest = AnalyseConstants.ANALYSE_FILTER_REQUEST + requestId;
log.info("picAnalyseRetNotify keyFilterRequest={}", keyFilterRequest);
boolean flag = false;
AnalyseRequest analyseRequest = null;
if (redisService.hasKey(keyFilterRequest)) { // 初筛结果
analyseResult.setFilter("1"); // 设置初筛标志
AnalyseRequest analyseRequest = (AnalyseRequest) redisService.redisTemplate.opsForValue().getAndDelete(keyFilterRequest);
analyseRequest = (AnalyseRequest) redisService.redisTemplate.opsForValue().getAndDelete(keyFilterRequest);
AnalyseResPoint analyseResPoint = analyseResult.getResultList().get(0).getResults().get(0);
boolean bDefect = analyseResPoint.isDefect(); // code=2000代表初筛结果返回正常value=1代表有缺陷
log.info("picAnalyseRetNotify FILTER bDefect={}, algorithmType={}", bDefect, analyseResPoint.getType());
@ -101,8 +103,9 @@ public class AnalysisServiceImpl implements IAnalysisService {
* 如果无缺陷再去判断算法如果算法是meter就继续调用大模型*
*/
analyseResult.setResult("0");
log.info("picAnalyseRetNotify CALL BIG_MODEL REQUEST_ID={}", requestId);
ispAlgorithmRequestService.sendRequest(analyseRequest);
flag = true;
// log.info("picAnalyseRetNotify CALL BIG_MODEL REQUEST_ID={}", requestId);
// ispAlgorithmRequestService.sendRequest(analyseRequest);
} else {
//初筛结果无缺陷并且非表计算法不用调用大模型流程就此结束
log.info("picAnalyseRetNotify NO BIG_MODEL WOULD CALLED REQUEST_ID={}", requestId);
@ -110,6 +113,7 @@ public class AnalysisServiceImpl implements IAnalysisService {
} else {
// 大模型结果
log.info("picAnalyseRetNotify BIG_MODEL CALLBACK REQUEST_ID={}", requestId);
analyseResult.setFilter("0"); // 设置大模型标志为0
}
//qinyl
@ -118,9 +122,14 @@ public class AnalysisServiceImpl implements IAnalysisService {
doAlgorithmAnalysis(analyseResult);
//calculateProcess(analyseResult);
log.info(Color.CYAN + "###### 分析算法模块返回的表计识别结果 end ######" + Color.END);
if(flag) {
log.info("picAnalyseRetNotify CALL BIG_MODEL REQUEST_ID={}", requestId);
ispAlgorithmRequestService.sendRequest(analyseRequest);
}
}
public void doAlgorithmAnalysis(AnalyseResult analyseResult) {
public synchronized void doAlgorithmAnalysis(AnalyseResult analyseResult) {
log.info("doAlgorithmAnalysis analyseResult: {}", analyseResult);
int size = 0;
String taskId = "";
@ -149,185 +158,192 @@ public class AnalysisServiceImpl implements IAnalysisService {
Map<String, PatrolResult> resMap = selectObj2PatrolResultMap(analyseResult.getTaskPatrolId());
log.info(Color.GREEN + "doAlgorithmAnalysis meter algorithm resContentList: {}" + Color.END, resContentList);
log.info(Color.GREEN + "doAlgorithmAnalysis meter algorithm resMap: {}" + Color.END, JSONObject.toJSONString(resMap));
if (!resContentList.isEmpty()) {
List<WebsocketData> websocketDataArrayList = new ArrayList<>();
for (AnalyseResItem algorithmResult : resContentList) {
Long lineId = deviceIdLineIdMap.get(algorithmResult.getObjectId());
log.info("doAlgorithmAnalysis resultList lineId: {}, objectId: {}", lineId, algorithmResult.getObjectId());
ResultAnalysis resultAnalysis = new ResultAnalysis();
resultAnalysis.setBusinessId(String.valueOf(lineId));
resultAnalysis.setResultContent(new Gson().toJson(analyseResult));
resultAnalysis.setResultType("1");
resultAnalysis.setObjectId(algorithmResult.getObjectId());
List<AnalyseResPoint> resultsList = algorithmResult.getResults();
String value = "";
List<String> typeList = new ArrayList<>();
String description;
String objectId;
for (Iterator<AnalyseResPoint> iterator = resultsList.iterator(); iterator.hasNext(); resultAnalysis.setDescription(description)) {
AnalyseResPoint algorithmInnerResult = iterator.next();
value = algorithmInnerResult.getValue();
String code = algorithmInnerResult.getCode();
description = algorithmInnerResult.getDesc();
objectId = algorithmInnerResult.getType();
if (StringUtils.isNotEmpty(objectId)) {
typeList.add(objectId);
}
try {
if (!resContentList.isEmpty()) {
List<WebsocketData> websocketDataArrayList = new ArrayList<>();
for (AnalyseResItem algorithmResult : resContentList) {
Long lineId = deviceIdLineIdMap.get(algorithmResult.getObjectId());
log.info("doAlgorithmAnalysis resultList lineId: {}, objectId: {}", lineId, algorithmResult.getObjectId());
ResultAnalysis resultAnalysis = new ResultAnalysis();
resultAnalysis.setBusinessId(String.valueOf(lineId));
resultAnalysis.setResultContent(new Gson().toJson(analyseResult));
resultAnalysis.setResultType("1");
resultAnalysis.setObjectId(algorithmResult.getObjectId());
List<AnalyseResPoint> resultsList = algorithmResult.getResults();
String value = "";
List<String> typeList = new ArrayList<>();
String description;
String objectId;
for (Iterator<AnalyseResPoint> iterator = resultsList.iterator(); iterator.hasNext(); resultAnalysis.setDescription(description)) {
AnalyseResPoint algorithmInnerResult = iterator.next();
value = algorithmInnerResult.getValue();
String code = algorithmInnerResult.getCode();
description = algorithmInnerResult.getDesc();
objectId = algorithmInnerResult.getType();
if (StringUtils.isNotEmpty(objectId)) {
typeList.add(objectId);
}
log.info("doAlgorithmAnalysis RESULT CODE: {}, DESC: {}", code, description);
if ("meter normal".equals(description)) {
description = "识别完成";
}
log.info("doAlgorithmAnalysis RESULT CODE: {}, DESC: {}", code, description);
if ("meter normal".equals(description)) {
description = "识别完成";
}
resultAnalysis.setCreateTime(new Date());
switch (value) {
case "0":
resultAnalysis.setPointStatus("1");
resultAnalysis.setResultType("1");
resultAnalysis.setResStatus("1");
break;
case "1":
resultAnalysis.setPointStatus("0");
resultAnalysis.setResultType("0");
resultAnalysis.setResStatus("0");
break;
case "-1":
resultAnalysis.setPointStatus("0");
resultAnalysis.setResultType("2");
resultAnalysis.setResStatus("0");
break;
default:
resultAnalysis.setPointStatus("1");
resultAnalysis.setResultType("1");
resultAnalysis.setResStatus("1");
break;
}
resultAnalysis.setCreateTime(new Date());
switch (value) {
case "0":
resultAnalysis.setPointStatus("1");
resultAnalysis.setResultType("1");
resultAnalysis.setResStatus("1");
break;
case "1":
resultAnalysis.setPointStatus("0");
resultAnalysis.setResultType("0");
resultAnalysis.setResStatus("0");
break;
case "-1":
resultAnalysis.setPointStatus("0");
resultAnalysis.setResultType("2");
resultAnalysis.setResStatus("0");
break;
default:
resultAnalysis.setPointStatus("1");
resultAnalysis.setResultType("1");
resultAnalysis.setResStatus("1");
break;
}
if (!code.equals("2000")) {
resultAnalysis.setResultType("3");
description = "GET PICTURE FAIL";
}
if (!code.equals("2000")) {
resultAnalysis.setResultType("3");
description = "GET PICTURE FAIL";
}
resultAnalysis.setTaskPatrolId(analyseResult.getTaskPatrolId());
resultAnalysis.setRequestId(analyseResult.getRequestId());
resultAnalysis.setAlgType(algorithmInnerResult.getType());
resultAnalysis.setResValue(algorithmInnerResult.getValue());
resultAnalysis.setResCode(algorithmInnerResult.getCode());
resultAnalysis.setResConf(algorithmInnerResult.getConf());
resultAnalysis.setResDesc(algorithmInnerResult.getDesc());
resultAnalysis.setResult(analyseResult.getResult());
if (StringUtils.isEmpty(algorithmInnerResult.getResImageUrl())) {
PatrolResult patrolResult = resMap.get(algorithmResult.getObjectId());
log.info(Color.GREEN + "------------------------doAlgorithmAnalysis patrolResult: {}" + Color.END, JSONObject.toJSONString(patrolResult));
resultAnalysis.setResImgUrl(patrolResult.getFilePath());
} else {
resultAnalysis.setResImgUrl(algorithmInnerResult.getResImageUrl());
resultAnalysis.setTaskPatrolId(analyseResult.getTaskPatrolId());
resultAnalysis.setRequestId(analyseResult.getRequestId());
resultAnalysis.setAlgType(algorithmInnerResult.getType());
resultAnalysis.setResValue(algorithmInnerResult.getValue());
resultAnalysis.setResCode(algorithmInnerResult.getCode());
resultAnalysis.setResConf(algorithmInnerResult.getConf());
resultAnalysis.setResDesc(algorithmInnerResult.getDesc());
resultAnalysis.setResult(analyseResult.getResult());
if (StringUtils.isEmpty(algorithmInnerResult.getResImageUrl())) {
PatrolResult patrolResult = resMap.get(algorithmResult.getObjectId());
log.info(Color.GREEN + "------------------------doAlgorithmAnalysis patrolResult: {}" + Color.END, JSONObject.toJSONString(patrolResult));
resultAnalysis.setResImgUrl(patrolResult.getFilePath());
} else {
resultAnalysis.setResImgUrl(algorithmInnerResult.getResImageUrl());
}
resultAnalysis.setImageNormalUrlPath(algorithmInnerResult.getImageNormalUrlPath());
resultAnalysis.setResPos(algorithmInnerResult.getPos() == null ? StringUtils.EMPTY : JSONObject.toJSONString(algorithmInnerResult.getPos()));
resultAnalysis.setFilter(analyseResult.getFilter());
}
resultAnalysis.setImageNormalUrlPath(algorithmInnerResult.getImageNormalUrlPath());
resultAnalysis.setResPos(algorithmInnerResult.getPos() == null ? StringUtils.EMPTY : JSONObject.toJSONString(algorithmInnerResult.getPos()));
resultAnalysis.setFilter(analyseResult.getFilter());
}
log.info("doAlgorithmAnalysis BEFORE resultAnalysis: {}", resultAnalysis);
try {
setAllStatus(resultAnalysis);
} catch (Exception e) {
log.error("error", e);
}
log.info("doAlgorithmAnalysis BEFORE resultAnalysis: {}", resultAnalysis);
try {
setAllStatus(resultAnalysis);
} catch (Exception e) {
log.error("error", e);
}
log.info("doAlgorithmAnalysis AFTER resultAnalysis: {}", resultAnalysis);
if (StringUtils.isNotEmpty(resultAnalysis.getBusinessId())) {
ResultAnalysis analysis = new ResultAnalysis();
analysis.setBusinessId(resultAnalysis.getBusinessId());
List<ResultAnalysis> resultAnalyses = resultAnalysisService.selectResultAnalysisList(analysis);
if (resultAnalyses.isEmpty()) {
int analysisRes = resultAnalysisService.insertResultAnalysis(resultAnalysis);
log.info(Color.GREEN + "doAlgorithmAnalysis CRUD insert analysisRes: {}, lineId: {}" + Color.END, analysisRes, resultAnalysis.getLineId());
} else {
resultAnalysis.setLineId(resultAnalyses.get(0).getLineId());
int analysisRes = resultAnalysisService.updateResultAnalysis(resultAnalysis);
log.info(Color.GREEN + "doAlgorithmAnalysis CRUD update analysisRes: {}, lineId: {}" + Color.END, analysisRes, resultAnalysis.getLineId());
log.info("doAlgorithmAnalysis AFTER resultAnalysis: {}", resultAnalysis);
if (StringUtils.isNotEmpty(resultAnalysis.getBusinessId())) {
ResultAnalysis analysis = new ResultAnalysis();
analysis.setBusinessId(resultAnalysis.getBusinessId());
analysis.setFilter(resultAnalysis.getFilter());
analysis.setAlgType(resultAnalysis.getAlgType());
log.info("doAlgorithmAnalysis selectResultAnalysisList analysis: {}", analysis);
List<ResultAnalysis> resultAnalyses = resultAnalysisService.selectResultAnalysisList(analysis);
if (resultAnalyses.isEmpty()) {
int analysisRes = resultAnalysisService.insertResultAnalysis(resultAnalysis);
log.info(Color.GREEN + "doAlgorithmAnalysis CRUD insert analysisRes: {}, lineId: {}" + Color.END, analysisRes, resultAnalysis.getLineId());
} else {
resultAnalysis.setLineId(resultAnalyses.get(0).getLineId());
int analysisRes = resultAnalysisService.updateResultAnalysis(resultAnalysis);
log.info(Color.GREEN + "doAlgorithmAnalysis CRUD update analysisRes: {}, lineId: {}" + Color.END, analysisRes, resultAnalysis.getLineId());
}
}
}
PatrolResult patrolResult = patrolResultService.selectPatrolResultByLineId(lineId);
if (StringUtils.isNotEmpty(value) && patrolResult != null) {
patrolResult.setValue(value);
}
PatrolResult patrolResult = patrolResultService.selectPatrolResultByLineId(lineId);
if (StringUtils.isNotEmpty(value) && patrolResult != null) {
patrolResult.setValue(value);
}
String isAlgType = "";
if (!typeList.isEmpty()) {
List<String> typeListAgain = new ArrayList<>();
Iterator<String> iterator = typeList.iterator();
while (true) {
if (!iterator.hasNext()) {
if (!typeListAgain.isEmpty()) {
patrolResult.setRecognitionType(String.join(StringUtils.COMMA, typeListAgain));
String isAlgType = "";
if (!typeList.isEmpty()) {
List<String> typeListAgain = new ArrayList<>();
Iterator<String> iterator = typeList.iterator();
while (true) {
if (!iterator.hasNext()) {
if (!typeListAgain.isEmpty()) {
patrolResult.setRecognitionType(String.join(StringUtils.COMMA, typeListAgain));
}
break;
}
break;
}
objectId = iterator.next();
String[] types = objectId.split(StringUtils.COMMA);
for (String type : types) {
Map<String, String> algType = patrolResultService.selectAlgTypeByCode(type);
if (StringUtils.isEmpty(isAlgType) && algType != null && algType.get("alg_name") != null && algType.get("alg_name").equals("缺陷识别")) {
isAlgType = "1";
}
objectId = iterator.next();
String[] types = objectId.split(StringUtils.COMMA);
for (String type : types) {
Map<String, String> algType = patrolResultService.selectAlgTypeByCode(type);
if (StringUtils.isEmpty(isAlgType) && algType != null && algType.get("alg_name") != null && algType.get("alg_name").equals("缺陷识别")) {
isAlgType = "1";
}
System.out.println(type);
Map<String, String> algmap = patrolResultService.selectAlgTypeDataType(type);
if (algmap != null && StringUtils.isNotEmpty(algmap.get("remark"))) {
typeListAgain.add(algmap.get("remark"));
System.out.println(type);
Map<String, String> algmap = patrolResultService.selectAlgTypeDataType(type);
if (algmap != null && StringUtils.isNotEmpty(algmap.get("remark"))) {
typeListAgain.add(algmap.get("remark"));
}
}
}
}
}
if (StringUtils.isNotEmpty(isAlgType) && isAlgType.equals("1")) {
if (resultAnalysis.getResultType().equals("1")) {
patrolResult.setValueUnit("无缺陷");
} else {
patrolResult.setValueUnit("有缺陷");
if (StringUtils.isNotEmpty(isAlgType) && isAlgType.equals("1")) {
if (resultAnalysis.getResultType().equals("1")) {
patrolResult.setValueUnit("无缺陷");
} else {
patrolResult.setValueUnit("有缺陷");
}
}
}
Map<String, String> valueMap = patrolResultService.getPatrolResultValue(patrolResult);
if (null != valueMap && !valueMap.isEmpty()) {
if (valueMap.containsKey("value") && null != valueMap.get("value")) {
description = valueMap.get("value");
patrolResult.setValue(description);
}
Map<String, String> valueMap = patrolResultService.getPatrolResultValue(patrolResult);
if (null != valueMap && !valueMap.isEmpty()) {
if (valueMap.containsKey("value") && null != valueMap.get("value")) {
description = valueMap.get("value");
patrolResult.setValue(description);
}
if (valueMap.containsKey("value_unit") && null != valueMap.get("value_unit")) {
description = valueMap.get("value_unit");
patrolResult.setValueUnit(description);
if (valueMap.containsKey("value_unit") && null != valueMap.get("value_unit")) {
description = valueMap.get("value_unit");
patrolResult.setValueUnit(description);
}
}
}
patrolResultService.updatePatrolResult(patrolResult);
WebsocketData webData = new WebsocketData();
webData.setTime(DateUtils.format(DateUtils.yyyyMMddHHmmss2, new Date()));
objectId = algorithmResult.getObjectId();
webData.setDevId(objectId);
webData.setDesc(resultAnalysis.getDescription());
websocketDataArrayList.add(webData);
}
patrolResultService.updatePatrolResult(patrolResult);
WebsocketData webData = new WebsocketData();
webData.setTime(DateUtils.format(DateUtils.yyyyMMddHHmmss2, new Date()));
objectId = algorithmResult.getObjectId();
webData.setDevId(objectId);
webData.setDesc(resultAnalysis.getDescription());
websocketDataArrayList.add(webData);
}
PatrolTaskInfo patrolTaskInfo = new PatrolTaskInfo();
patrolTaskInfo.setTaskMajorId(taskId);
List<PatrolTaskInfo> arr = patrolTaskInfoService.selectPatrolTaskInfoList(patrolTaskInfo);
Set<String> point = new HashSet<>();
for (PatrolTaskInfo ass : arr) {
if (StringUtils.isNotEmpty(ass.getDeviceId())) {
point.add(ass.getDeviceId());
PatrolTaskInfo patrolTaskInfo = new PatrolTaskInfo();
patrolTaskInfo.setTaskMajorId(taskId);
List<PatrolTaskInfo> arr = patrolTaskInfoService.selectPatrolTaskInfoList(patrolTaskInfo);
Set<String> point = new HashSet<>();
for (PatrolTaskInfo ass : arr) {
if (StringUtils.isNotEmpty(ass.getDeviceId())) {
point.add(ass.getDeviceId());
}
}
}
if (point.size() == size) {
boolean bRes = redisService.deleteObject(requestId);
log.info("doAlgorithmAnalysis CLEAR requestId FROM REDIS: {}", bRes);
if (point.size() == size) {
boolean bRes = redisService.deleteObject(requestId);
log.info("doAlgorithmAnalysis CLEAR requestId FROM REDIS: {}", bRes);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}


+ 2
- 0
inspect-main/inspect-main-task/src/main/resources/mapper/task/ResultAnalysisMapper.xml View File

@ -107,6 +107,8 @@
('%',#{resultContent},'%')
</if>
<if test="resStatus != null and resStatus != ''">and res_status = #{resStatus}</if>
<if test="algType != null and algType != ''">and alg_type = #{algType}</if>
<if test="filter != null and filter != ''">and filter = #{filter}</if>
<if test="pointStatus != null and pointStatus != ''">and point_status = #{pointStatus}</if>
<if test="objectId != null and objectId != ''">and objectId = #{objectId}</if>
<if test="description != null and description != ''">and description = #{description}</if>


Loading…
Cancel
Save