Browse Source

横向路径流程

main
maochaoying 2 years ago
parent
commit
c88213a8f9
  1. 5
      pom.xml
  2. 24
      src/main/java/com/iflytop/nuclear/entity/DetectionMessage.java
  3. 19
      src/main/java/com/iflytop/nuclear/handler/MessageHandler.java
  4. 1
      src/main/java/com/iflytop/nuclear/service/CheckService.java
  5. 2
      src/main/java/com/iflytop/nuclear/service/NuclearCoreConfigService.java
  6. 21
      src/main/java/com/iflytop/nuclear/service/impl/CheckServiceImpl.java
  7. 13
      src/main/java/com/iflytop/nuclear/service/impl/NuclearCoreConfigServiceImpl.java

5
pom.xml

@ -36,6 +36,11 @@
<version>1.2.83</version>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.3.5</version>
</dependency>
<dependency>
<groupId>javax.websocket</groupId>
<artifactId>javax.websocket-api</artifactId>
<version>1.1</version>

24
src/main/java/com/iflytop/nuclear/entity/DetectionMessage.java

@ -0,0 +1,24 @@
package com.iflytop.nuclear.entity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* 检测消息体
* @author cool
* @date 2023/7/3 14:54
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class DetectionMessage {
private String messageId;
private int taskId;
private String coord;
}

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

@ -2,9 +2,11 @@ package com.iflytop.nuclear.handler;
import com.alibaba.fastjson.JSONObject;
import com.iflytop.nuclear.service.CheckService;
import com.iflytop.nuclear.service.NuclearCoreConfigService;
import com.iflytop.nuclear.service.impl.CheckServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import javax.websocket.Session;
@ -18,8 +20,11 @@ import java.io.IOException;
@Slf4j
public class MessageHandler {
@Lazy
@Autowired
CheckServiceImpl checkServiceImpl;
@Autowired
NuclearCoreConfigService nuclearCoreConfigService;
/**
* dispatcher分发器
@ -29,9 +34,17 @@ public class MessageHandler {
*/
public void dispatcher(String command, JSONObject data, Session session) throws IOException {
switch (command){
case "cmd1":
session.getBasicRemote().sendText("123");
checkServiceImpl.changeMessageReceived(true);
case "detection_completed":
// 需要把当前的检测结果进行保存
JSONObject result = data.getJSONObject("result");
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);
if (updateResult) {
checkServiceImpl.changeMessageReceived(true);
}
break;
default:
System.out.println("No match!");

1
src/main/java/com/iflytop/nuclear/service/CheckService.java

@ -10,7 +10,6 @@ import java.io.IOException;
* @author cool
* @date 2023/7/2 09:43
*/
@Transactional
public interface CheckService {
CheckInfo getCheckInfoByTaskId(int taskId);

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

@ -14,4 +14,6 @@ import java.util.List;
public interface NuclearCoreConfigService extends IService<NuclearCoreConfig> {
List<NuclearCoreConfig> getNuclearCoreConfigByTaskid(String taskId);
boolean updateDetectionResult(String imgUrl, String detectionResult, String coord, int taskId);
}

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

@ -1,8 +1,11 @@
package com.iflytop.nuclear.service.impl;
import cn.hutool.core.util.IdUtil;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.iflytop.nuclear.entity.CheckInfo;
import com.iflytop.nuclear.entity.CheckResult;
import com.iflytop.nuclear.entity.DetectionMessage;
import com.iflytop.nuclear.model.Task;
import com.iflytop.nuclear.service.CheckService;
import com.iflytop.nuclear.service.TaskService;
@ -22,8 +25,8 @@ public class CheckServiceImpl implements CheckService {
@Autowired
TaskService taskService;
// @Autowired
// WebSocketServer webSocketServer;
@Autowired
WebSocketServer webSocketServer;
private static boolean messageReceived = false;
@ -76,7 +79,12 @@ public class CheckServiceImpl implements CheckService {
this.updateCoordAndStatus(taskId, "1-6", 1);
String nextCoord = "1-6";
// 开始检测
// webSocketServer.sendMessage("开始检测 1-6");
DetectionMessage startMessage = DetectionMessage.builder()
.messageId(IdUtil.randomUUID())
.coord(nextCoord)
.taskId(taskId)
.build();
webSocketServer.sendMessage(startMessage.toString());
// 如果中间终止 则退出返回 与messagehandler 处理逻辑相同 外部控制while的终止
// 下一次进入后则进入其他流程
while (!"finish".equals(nextCoord)) {
@ -95,6 +103,13 @@ public class CheckServiceImpl implements CheckService {
// 检测完毕后获取下一个坐标
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);
}

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

@ -22,4 +22,17 @@ public class NuclearCoreConfigServiceImpl extends ServiceImpl<NuclearCoreConfigM
List<NuclearCoreConfig> list = this.list(nuclearCoreConfigQueryWrapper);
return list;
}
/**
* 保存检测结果
* @param imgUrl
* @param detectionResult
* @param coord
* @param taskId
* @return
*/
@Override
public boolean updateDetectionResult(String imgUrl, String detectionResult, String coord, int taskId) {
return true;
}
}
Loading…
Cancel
Save