From b79a18c26e4fb88e5e37e4a02b15686f95048d2a Mon Sep 17 00:00:00 2001 From: maochaoying <925670706@qq.com> Date: Tue, 4 Jul 2023 11:10:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=AD=E6=96=AD=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iflytop/nuclear/handler/MessageHandler.java | 5 +- .../nuclear/service/NuclearCoreConfigService.java | 2 +- .../nuclear/service/impl/CheckServiceImpl.java | 59 +++++++++++++++++++--- .../service/impl/NuclearCoreConfigServiceImpl.java | 14 ++--- 4 files changed, 65 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/iflytop/nuclear/handler/MessageHandler.java b/src/main/java/com/iflytop/nuclear/handler/MessageHandler.java index e5feb93..679077e 100644 --- a/src/main/java/com/iflytop/nuclear/handler/MessageHandler.java +++ b/src/main/java/com/iflytop/nuclear/handler/MessageHandler.java @@ -40,8 +40,9 @@ public class MessageHandler { String imgUrl = result.getString("imgUrl"); String coord = result.getString("coord"); int taskId = Integer.parseInt(result.getString("taskId")); - String detectionResult = result.getString("detection_result"); - boolean updateResult = nuclearCoreConfigService.updateDetectionResult(imgUrl, detectionResult, coord, taskId); + String detectionResultTop = result.getString("detection_result_top"); + String detectionResultBottom = result.getString("detection_result_bottom"); + boolean updateResult = nuclearCoreConfigService.updateDetectionResult(imgUrl, detectionResultTop, coord, taskId, detectionResultBottom); if (updateResult) { checkServiceImpl.changeMessageReceived(true); }else { diff --git a/src/main/java/com/iflytop/nuclear/service/NuclearCoreConfigService.java b/src/main/java/com/iflytop/nuclear/service/NuclearCoreConfigService.java index 6444eee..d0c9837 100644 --- a/src/main/java/com/iflytop/nuclear/service/NuclearCoreConfigService.java +++ b/src/main/java/com/iflytop/nuclear/service/NuclearCoreConfigService.java @@ -15,7 +15,7 @@ public interface NuclearCoreConfigService extends IService { List getNuclearCoreConfigByTaskid(String taskId); - boolean updateDetectionResult(String imgUrl, String detectionResult, String coord, int taskId); + boolean updateDetectionResult(String imgUrl, String detectionResult, String coord, int taskId, String detectionResultBottom); NuclearCoreConfig getDetailById(String taskId, String serialNumber); } diff --git a/src/main/java/com/iflytop/nuclear/service/impl/CheckServiceImpl.java b/src/main/java/com/iflytop/nuclear/service/impl/CheckServiceImpl.java index b7a3121..14d514b 100644 --- a/src/main/java/com/iflytop/nuclear/service/impl/CheckServiceImpl.java +++ b/src/main/java/com/iflytop/nuclear/service/impl/CheckServiceImpl.java @@ -72,6 +72,7 @@ public class CheckServiceImpl implements CheckService { @Override public CheckResult autoCheck(int order, String startIndex, int taskId) throws IOException { + this.changeBreakOff(false); currentTaskId = taskId; if (order == 0) { if (startIndex == null || "".equals(startIndex)) { @@ -89,17 +90,66 @@ public class CheckServiceImpl implements CheckService { // 下一次进入后则进入其他流程 while (!"finish".equals(nextCoord)) { // 需要一个中断的接口, 中途暂停本次流程 - if (this.breakOff) { - this.updateCoordAndStatus(taskId, nextCoord, 2); + // 用messagehandler处理检测完毕的消息 从而启动以下流程 + boolean breakFirst = false; + while (true) { + if (this.breakOff) { + breakFirst = true; + this.updateCoordAndStatus(taskId, nextCoord, 2); + break; + } + if (this.isMessageReceived()) { + messageReceived = false; + break; // 跳出循环 + } + } + if (breakFirst) { break; } + // 检测完毕后获取下一个坐标 + nextCoord = this.getNextCoord(nextCoord, 0); + this.updateCoordAndStatus(taskId, nextCoord, 1); + DetectionMessage detectionMessage = DetectionMessage.builder() + .messageId(IdUtil.randomUUID()) + .coord(nextCoord) + .taskId(taskId) + .build(); + JSONObject from = JSONObject.from(detectionMessage); + webSocketServer.sendMessage(from.toString()); + if ("finish".equals(nextCoord)) { + this.updateCoordAndStatus(taskId, nextCoord, 3); + } + } + }else { + // 被中断过,需要从中断的currentCoord坐标继续 + // 首先需要读取数据库,获得当前taskId的信息 + Task task = taskService.getById(taskId); + String nextCoord = task.getCurrentCoord(); + DetectionMessage startMessage = DetectionMessage.builder() + .messageId(IdUtil.randomUUID()) + .coord(nextCoord) + .taskId(taskId) + .build(); + webSocketServer.sendMessage(startMessage.toString()); + // 得到的currentCoord已经检测过,直接进入下一流程 + while (!"finish".equals(nextCoord)) { + // 需要一个中断的接口, 中途暂停本次流程 // 用messagehandler处理检测完毕的消息 从而启动以下流程 + boolean breakFirst = false; while (true) { + if (this.breakOff) { + breakFirst = true; + this.updateCoordAndStatus(taskId, nextCoord, 2); + break; + } if (this.isMessageReceived()) { messageReceived = false; break; // 跳出循环 } } + if (breakFirst){ + break; + } // 检测完毕后获取下一个坐标 nextCoord = this.getNextCoord(nextCoord, 0); this.updateCoordAndStatus(taskId, nextCoord, 1); @@ -113,13 +163,10 @@ public class CheckServiceImpl implements CheckService { if ("finish".equals(nextCoord)) { this.updateCoordAndStatus(taskId, nextCoord, 3); } - System.out.println(nextCoord); } - }else { - } }else if (order == 1) { - if (startIndex == null) { + if (startIndex == null || "".equals(startIndex)) { // 指定初始化index为6-1 this.updateCoordAndStatus(taskId, "6-1", 1); }else { diff --git a/src/main/java/com/iflytop/nuclear/service/impl/NuclearCoreConfigServiceImpl.java b/src/main/java/com/iflytop/nuclear/service/impl/NuclearCoreConfigServiceImpl.java index aff00c1..8e2e07e 100644 --- a/src/main/java/com/iflytop/nuclear/service/impl/NuclearCoreConfigServiceImpl.java +++ b/src/main/java/com/iflytop/nuclear/service/impl/NuclearCoreConfigServiceImpl.java @@ -28,27 +28,29 @@ public class NuclearCoreConfigServiceImpl extends ServiceImpl nuclearCoreConfigUpdateWrapper = new UpdateWrapper<>(); nuclearCoreConfigUpdateWrapper.eq("task_id",taskId).eq("serial_number", coord); NuclearCoreConfig nuclearCoreConfig = new NuclearCoreConfig(); nuclearCoreConfig.setResultImg(imgUrl); nuclearCoreConfig.setTaskId(taskId); - nuclearCoreConfig.setResultSerial(detectionResult); + nuclearCoreConfig.setResultSerial(detectionResultTop + "-" + detectionResultBottom); QueryWrapper nuclearCoreConfigQueryWrapper = new QueryWrapper<>(); nuclearCoreConfigQueryWrapper.eq("task_id",taskId).eq("serial_number", coord); NuclearCoreConfig one = this.getOne(nuclearCoreConfigQueryWrapper); String firstSign = one.getFirstSign(); - if (!"".equals(firstSign)){ + String secondSign = one.getSecondSign(); + if (!"".equals(firstSign) && !"".equals(secondSign)){ // 取后四位 - String lastFourStr = firstSign.substring(firstSign.length() - 4); - if (lastFourStr.equals(detectionResult)){ + // String firstLastFourStr = firstSign.substring(firstSign.length() - 4); + // String secondLastFourStr = secondSign.substring(firstSign.length() - 4); + if (firstSign.equals(detectionResultTop) && secondSign.equals(detectionResultBottom)){ // 对比源数据和检测数据 得出结果并保存 // 1 为正确 nuclearCoreConfig.setResult(1);