From fd5888558d5ac4d45b8cffc2092f65f410f864c2 Mon Sep 17 00:00:00 2001 From: maochaoying <925670706@qq.com> Date: Mon, 3 Jul 2023 10:07:39 +0800 Subject: [PATCH] while finish --- .../nuclear/controller/CheckController.java | 4 +++- .../com/iflytop/nuclear/service/CheckService.java | 4 +++- .../nuclear/service/impl/CheckServiceImpl.java | 27 ++++++++++++++++------ 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/iflytop/nuclear/controller/CheckController.java b/src/main/java/com/iflytop/nuclear/controller/CheckController.java index 1d596dc..ad22bd7 100644 --- a/src/main/java/com/iflytop/nuclear/controller/CheckController.java +++ b/src/main/java/com/iflytop/nuclear/controller/CheckController.java @@ -8,6 +8,8 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import java.io.IOException; + /** * @author cool * @date 2023/7/2 09:41 @@ -22,7 +24,7 @@ public class CheckController { CheckService checkService; @GetMapping("/auto/{id}") - public ResponseData checkAuto(@PathVariable(name = "id") int taskId) { + public ResponseData checkAuto(@PathVariable(name = "id") int taskId) throws IOException { CheckInfo checkInfo = checkService.getCheckInfoByTaskId(taskId); int order = checkInfo.getOrder(); String startIndex = checkInfo.getCurrentCoord(); diff --git a/src/main/java/com/iflytop/nuclear/service/CheckService.java b/src/main/java/com/iflytop/nuclear/service/CheckService.java index 642901b..fd86c72 100644 --- a/src/main/java/com/iflytop/nuclear/service/CheckService.java +++ b/src/main/java/com/iflytop/nuclear/service/CheckService.java @@ -4,6 +4,8 @@ import com.iflytop.nuclear.entity.CheckInfo; import com.iflytop.nuclear.entity.CheckResult; import org.springframework.transaction.annotation.Transactional; +import java.io.IOException; + /** * @author cool * @date 2023/7/2 09:43 @@ -13,5 +15,5 @@ public interface CheckService { CheckInfo getCheckInfoByTaskId(int taskId); - CheckResult autoCheck(int order, String startIndex, int taskId); + CheckResult autoCheck(int order, String startIndex, int taskId) throws IOException; } 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 5b2359c..12cf9a6 100644 --- a/src/main/java/com/iflytop/nuclear/service/impl/CheckServiceImpl.java +++ b/src/main/java/com/iflytop/nuclear/service/impl/CheckServiceImpl.java @@ -8,9 +8,13 @@ import com.iflytop.nuclear.model.Account; import com.iflytop.nuclear.model.Task; import com.iflytop.nuclear.service.CheckService; import com.iflytop.nuclear.service.TaskService; +import com.iflytop.nuclear.websocket.WebSocketServer; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.io.IOException; +import java.util.Date; + /** * @author cool * @date 2023/7/2 09:44 @@ -20,6 +24,8 @@ public class CheckServiceImpl implements CheckService { @Autowired TaskService taskService; + @Autowired + WebSocketServer webSocketServer; @Override public CheckInfo getCheckInfoByTaskId(int taskId) { @@ -38,23 +44,30 @@ public class CheckServiceImpl implements CheckService { Task task = new Task(); task.setCurrentCoord(currentCoord); task.setStatus(status); + task.setStartTime(new Date()); boolean update = taskService.update(task, taskUpdateWrapper); return update; } @Override - public CheckResult autoCheck(int order, String startIndex, int taskId) { + public CheckResult autoCheck(int order, String startIndex, int taskId) throws IOException { if (order == 0) { - if (startIndex == null) { + if (startIndex == null || "".equals(startIndex)) { // 指定初始化index为1-6 this.updateCoordAndStatus(taskId, "1-6", 1); // 开始检测 - // 检测完毕后获取下一个坐标 + webSocketServer.sendMessage("开始检测 1-6"); + String nextCoord = "1-6"; + // 检测完毕后获取下一个坐标 用messagehandler处理检测完毕的消息 从而启动以下流程 + // TODO // 检测下一个坐标 while - // 如果中间终止 则退出返回 + // 如果中间终止 则退出返回 与messagehandler 处理逻辑相同 外部控制while的终止 // 下一次进入后则进入其他流程 - String nextCoord = this.getNextCoord("1-6", 0); - System.out.println(nextCoord); + while (!"finish".equals(nextCoord)) { + nextCoord = this.getNextCoord(nextCoord, 0); + this.updateCoordAndStatus(taskId, nextCoord, 1); + System.out.println(nextCoord); + } // !!! 记录规则路径上的路过但是不检测的坐标 进行排除即可 }else { @@ -171,7 +184,7 @@ public class CheckServiceImpl implements CheckService { if (minorLine < 8){ return mainLine + "-" + (minorLine + 1); }else { - return null; + return "finish"; } } }