|
|
@ -1,7 +1,6 @@ |
|
|
|
package com.iflytop.nuclear.service.impl; |
|
|
|
|
|
|
|
import cn.hutool.core.util.IdUtil; |
|
|
|
import com.alibaba.fastjson2.JSONObject; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
|
|
|
import com.iflytop.nuclear.entity.CheckInfo; |
|
|
@ -10,6 +9,7 @@ import com.iflytop.nuclear.entity.DetectionMessage; |
|
|
|
import com.iflytop.nuclear.model.Task; |
|
|
|
import com.iflytop.nuclear.service.CheckService; |
|
|
|
import com.iflytop.nuclear.service.TaskService; |
|
|
|
import com.iflytop.nuclear.websocket.SocketClient; |
|
|
|
import com.iflytop.nuclear.websocket.WebSocketServer; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
@ -28,13 +28,13 @@ public class CheckServiceImpl implements CheckService { |
|
|
|
TaskService taskService; |
|
|
|
@Autowired |
|
|
|
WebSocketServer webSocketServer; |
|
|
|
@Autowired |
|
|
|
SocketClient socketClient; |
|
|
|
|
|
|
|
private static boolean messageReceived = false; |
|
|
|
|
|
|
|
private static boolean breakOff = false; |
|
|
|
|
|
|
|
private static int currentTaskId = 0; |
|
|
|
|
|
|
|
// !!! 记录规则路径上的路过但是不检测的坐标 进行排除即可 |
|
|
|
|
|
|
|
public void changeMessageReceived(boolean flag) { |
|
|
@ -56,7 +56,7 @@ public class CheckServiceImpl implements CheckService { |
|
|
|
return checkInfo; |
|
|
|
} |
|
|
|
|
|
|
|
public boolean updateCoordAndStatus(int taskId, String currentCoord, int status, boolean updateStartTime, boolean updateEndTime) throws IOException { |
|
|
|
public boolean updateCoordAndStatus(int taskId, String currentCoord, int status, boolean updateStartTime, boolean updateEndTime, Integer order) throws IOException { |
|
|
|
UpdateWrapper<Task> taskUpdateWrapper = new UpdateWrapper<>(); |
|
|
|
taskUpdateWrapper.eq("id",taskId); |
|
|
|
Task task = new Task(); |
|
|
@ -73,6 +73,9 @@ public class CheckServiceImpl implements CheckService { |
|
|
|
task.setEndTime(new Date()); |
|
|
|
} |
|
|
|
task.setStatus(status); |
|
|
|
if (order != null){ |
|
|
|
task.setCheckOrder(order); |
|
|
|
} |
|
|
|
boolean update = taskService.update(task, taskUpdateWrapper); |
|
|
|
this.sendMessageToPage(); |
|
|
|
return update; |
|
|
@ -83,12 +86,12 @@ public class CheckServiceImpl implements CheckService { |
|
|
|
} |
|
|
|
|
|
|
|
public void sendMessageToDevice(String nextCoord, int taskId) throws IOException { |
|
|
|
// DetectionMessage startMessage = DetectionMessage.builder() |
|
|
|
// .messageId(IdUtil.randomUUID()) |
|
|
|
// .coord(nextCoord) |
|
|
|
// .taskId(taskId) |
|
|
|
// .build(); |
|
|
|
// webSocketServer.sendMessage(startMessage.toString()); |
|
|
|
DetectionMessage startMessage = DetectionMessage.builder() |
|
|
|
.messageId(IdUtil.randomUUID()) |
|
|
|
.coord(nextCoord) |
|
|
|
.taskId(taskId) |
|
|
|
.build(); |
|
|
|
socketClient.sendMessage(startMessage.toString()); |
|
|
|
} |
|
|
|
|
|
|
|
public void sendMessageToPage() throws IOException { |
|
|
@ -98,7 +101,7 @@ public class CheckServiceImpl implements CheckService { |
|
|
|
public String initCheck(String initNextCoord,int order, int taskId) throws IOException { |
|
|
|
// 指定初始化index为1-6 |
|
|
|
String nextCoord = initNextCoord; |
|
|
|
this.updateCoordAndStatus(taskId, nextCoord, 1, true, false); |
|
|
|
this.updateCoordAndStatus(taskId, nextCoord, 1, true, false, order); |
|
|
|
// 开始检测 |
|
|
|
this.sendMessageToDevice(nextCoord, taskId); |
|
|
|
// 如果中间终止 则退出返回 与messagehandler 处理逻辑相同 外部控制while的终止 |
|
|
@ -110,7 +113,7 @@ public class CheckServiceImpl implements CheckService { |
|
|
|
while (true) { |
|
|
|
if (this.breakOff) { |
|
|
|
breakFirst = true; |
|
|
|
this.updateCoordAndStatus(taskId, nextCoord, 2, false, false); |
|
|
|
this.updateCoordAndStatus(taskId, nextCoord, 2, false, false, order); |
|
|
|
break; |
|
|
|
} |
|
|
|
if (this.isMessageReceived()) { |
|
|
@ -123,10 +126,10 @@ public class CheckServiceImpl implements CheckService { |
|
|
|
} |
|
|
|
// 检测完毕后获取下一个坐标 |
|
|
|
nextCoord = this.getNextCoord(nextCoord, order); |
|
|
|
this.updateCoordAndStatus(taskId, nextCoord, 1, false, false); |
|
|
|
this.updateCoordAndStatus(taskId, nextCoord, 1, false, false, order); |
|
|
|
this.sendMessageToDevice(nextCoord, taskId); |
|
|
|
if ("finish".equals(nextCoord)) { |
|
|
|
this.updateCoordAndStatus(taskId, nextCoord, 3, false, true); |
|
|
|
this.updateCoordAndStatus(taskId, nextCoord, 3, false, true, order); |
|
|
|
} |
|
|
|
} |
|
|
|
return nextCoord; |
|
|
@ -146,7 +149,7 @@ public class CheckServiceImpl implements CheckService { |
|
|
|
while (true) { |
|
|
|
if (this.breakOff) { |
|
|
|
breakFirst = true; |
|
|
|
this.updateCoordAndStatus(taskId, nextCoord, 2, false, false); |
|
|
|
this.updateCoordAndStatus(taskId, nextCoord, 2, false, false, order); |
|
|
|
break; |
|
|
|
} |
|
|
|
if (this.isMessageReceived()) { |
|
|
@ -159,10 +162,10 @@ public class CheckServiceImpl implements CheckService { |
|
|
|
} |
|
|
|
// 检测完毕后获取下一个坐标 |
|
|
|
nextCoord = this.getNextCoord(nextCoord, order); |
|
|
|
this.updateCoordAndStatus(taskId, nextCoord, 1, false, false); |
|
|
|
this.updateCoordAndStatus(taskId, nextCoord, 1, false, false, order); |
|
|
|
this.sendMessageToDevice(nextCoord, taskId); |
|
|
|
if ("finish".equals(nextCoord)) { |
|
|
|
this.updateCoordAndStatus(taskId, nextCoord, 3, false, true); |
|
|
|
this.updateCoordAndStatus(taskId, nextCoord, 3, false, true, order); |
|
|
|
} |
|
|
|
} |
|
|
|
return nextCoord; |
|
|
@ -180,8 +183,7 @@ public class CheckServiceImpl implements CheckService { |
|
|
|
return checkResult; |
|
|
|
} |
|
|
|
this.changeBreakOff(false); |
|
|
|
this.updateCoordAndStatus(taskId, null, 1, false, false); |
|
|
|
currentTaskId = taskId; |
|
|
|
this.updateCoordAndStatus(taskId, null, 1, false, false, order); |
|
|
|
String nextCoord = ""; |
|
|
|
if (order == 0) { |
|
|
|
if (startIndex == null || "".equals(startIndex)) { |
|
|
@ -202,11 +204,10 @@ public class CheckServiceImpl implements CheckService { |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void breakOffByTaskId(int taskId) { |
|
|
|
if (taskId == currentTaskId) { |
|
|
|
public void breakOffByTaskId(int taskId) throws IOException { |
|
|
|
this.updateCoordAndStatus(taskId, null, 2,false, false, null); |
|
|
|
this.changeBreakOff(true); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 传入当前检查的坐标点 |
|
|
|