Browse Source

中断接口

main
maochaoying 2 years ago
parent
commit
b79a18c26e
  1. 5
      src/main/java/com/iflytop/nuclear/handler/MessageHandler.java
  2. 2
      src/main/java/com/iflytop/nuclear/service/NuclearCoreConfigService.java
  3. 59
      src/main/java/com/iflytop/nuclear/service/impl/CheckServiceImpl.java
  4. 14
      src/main/java/com/iflytop/nuclear/service/impl/NuclearCoreConfigServiceImpl.java

5
src/main/java/com/iflytop/nuclear/handler/MessageHandler.java

@ -40,8 +40,9 @@ public class MessageHandler {
String imgUrl = result.getString("imgUrl"); String imgUrl = result.getString("imgUrl");
String coord = result.getString("coord"); String coord = result.getString("coord");
int taskId = Integer.parseInt(result.getString("taskId")); 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) { if (updateResult) {
checkServiceImpl.changeMessageReceived(true); checkServiceImpl.changeMessageReceived(true);
}else { }else {

2
src/main/java/com/iflytop/nuclear/service/NuclearCoreConfigService.java

@ -15,7 +15,7 @@ public interface NuclearCoreConfigService extends IService<NuclearCoreConfig> {
List<NuclearCoreConfig> getNuclearCoreConfigByTaskid(String taskId); List<NuclearCoreConfig> 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); NuclearCoreConfig getDetailById(String taskId, String serialNumber);
} }

59
src/main/java/com/iflytop/nuclear/service/impl/CheckServiceImpl.java

@ -72,6 +72,7 @@ public class CheckServiceImpl implements CheckService {
@Override @Override
public CheckResult autoCheck(int order, String startIndex, int taskId) throws IOException { public CheckResult autoCheck(int order, String startIndex, int taskId) throws IOException {
this.changeBreakOff(false);
currentTaskId = taskId; currentTaskId = taskId;
if (order == 0) { if (order == 0) {
if (startIndex == null || "".equals(startIndex)) { if (startIndex == null || "".equals(startIndex)) {
@ -89,17 +90,66 @@ public class CheckServiceImpl implements CheckService {
// 下一次进入后则进入其他流程 // 下一次进入后则进入其他流程
while (!"finish".equals(nextCoord)) { 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; 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处理检测完毕的消息 从而启动以下流程 // 用messagehandler处理检测完毕的消息 从而启动以下流程
boolean breakFirst = false;
while (true) { while (true) {
if (this.breakOff) {
breakFirst = true;
this.updateCoordAndStatus(taskId, nextCoord, 2);
break;
}
if (this.isMessageReceived()) { if (this.isMessageReceived()) {
messageReceived = false; messageReceived = false;
break; // 跳出循环 break; // 跳出循环
} }
} }
if (breakFirst){
break;
}
// 检测完毕后获取下一个坐标 // 检测完毕后获取下一个坐标
nextCoord = this.getNextCoord(nextCoord, 0); nextCoord = this.getNextCoord(nextCoord, 0);
this.updateCoordAndStatus(taskId, nextCoord, 1); this.updateCoordAndStatus(taskId, nextCoord, 1);
@ -113,13 +163,10 @@ public class CheckServiceImpl implements CheckService {
if ("finish".equals(nextCoord)) { if ("finish".equals(nextCoord)) {
this.updateCoordAndStatus(taskId, nextCoord, 3); this.updateCoordAndStatus(taskId, nextCoord, 3);
} }
System.out.println(nextCoord);
} }
}else {
} }
}else if (order == 1) { }else if (order == 1) {
if (startIndex == null) {
if (startIndex == null || "".equals(startIndex)) {
// 指定初始化index为6-1 // 指定初始化index为6-1
this.updateCoordAndStatus(taskId, "6-1", 1); this.updateCoordAndStatus(taskId, "6-1", 1);
}else { }else {

14
src/main/java/com/iflytop/nuclear/service/impl/NuclearCoreConfigServiceImpl.java

@ -28,27 +28,29 @@ public class NuclearCoreConfigServiceImpl extends ServiceImpl<NuclearCoreConfigM
/** /**
* 保存检测结果 * 保存检测结果
* @param imgUrl * @param imgUrl
* @param detectionResult
* @param detectionResultTop
* @param coord * @param coord
* @param taskId * @param taskId
* @return * @return
*/ */
@Override @Override
public boolean updateDetectionResult(String imgUrl, String detectionResult, String coord, int taskId) {
public boolean updateDetectionResult(String imgUrl, String detectionResultTop, String coord, int taskId, String detectionResultBottom) {
UpdateWrapper<NuclearCoreConfig> nuclearCoreConfigUpdateWrapper = new UpdateWrapper<>(); UpdateWrapper<NuclearCoreConfig> nuclearCoreConfigUpdateWrapper = new UpdateWrapper<>();
nuclearCoreConfigUpdateWrapper.eq("task_id",taskId).eq("serial_number", coord); nuclearCoreConfigUpdateWrapper.eq("task_id",taskId).eq("serial_number", coord);
NuclearCoreConfig nuclearCoreConfig = new NuclearCoreConfig(); NuclearCoreConfig nuclearCoreConfig = new NuclearCoreConfig();
nuclearCoreConfig.setResultImg(imgUrl); nuclearCoreConfig.setResultImg(imgUrl);
nuclearCoreConfig.setTaskId(taskId); nuclearCoreConfig.setTaskId(taskId);
nuclearCoreConfig.setResultSerial(detectionResult);
nuclearCoreConfig.setResultSerial(detectionResultTop + "-" + detectionResultBottom);
QueryWrapper<NuclearCoreConfig> nuclearCoreConfigQueryWrapper = new QueryWrapper<>(); QueryWrapper<NuclearCoreConfig> nuclearCoreConfigQueryWrapper = new QueryWrapper<>();
nuclearCoreConfigQueryWrapper.eq("task_id",taskId).eq("serial_number", coord); nuclearCoreConfigQueryWrapper.eq("task_id",taskId).eq("serial_number", coord);
NuclearCoreConfig one = this.getOne(nuclearCoreConfigQueryWrapper); NuclearCoreConfig one = this.getOne(nuclearCoreConfigQueryWrapper);
String firstSign = one.getFirstSign(); 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 为正确 // 1 为正确
nuclearCoreConfig.setResult(1); nuclearCoreConfig.setResult(1);

Loading…
Cancel
Save