Browse Source

id转name

main
maochaoying 2 years ago
parent
commit
86ea505a61
  1. 10
      src/main/java/com/iflytop/nuclear/NuclearApplication.java
  2. 19
      src/main/java/com/iflytop/nuclear/service/impl/TaskServiceImpl.java
  3. 68
      src/main/java/com/iflytop/nuclear/websocket/WebSocketClient.java
  4. 3
      src/main/resources/application-dev.yml

10
src/main/java/com/iflytop/nuclear/NuclearApplication.java

@ -1,5 +1,6 @@
package com.iflytop.nuclear;
import com.iflytop.nuclear.websocket.WebSocketClient;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.Banner;
import org.springframework.boot.ResourceBanner;
@ -8,11 +9,18 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.core.io.ClassPathResource;
import javax.websocket.ContainerProvider;
import javax.websocket.DeploymentException;
import javax.websocket.Session;
import javax.websocket.WebSocketContainer;
import java.io.IOException;
import java.net.URI;
@SpringBootApplication
@MapperScan("com.iflytop.nuclear.mapper")
public class NuclearApplication {
public static void main(String[] args) {
public static void main(String[] args) throws DeploymentException, IOException {
SpringApplicationBuilder builder = new SpringApplicationBuilder(NuclearApplication.class);
builder.bannerMode(Banner.Mode.CONSOLE);
builder.banner(new ResourceBanner(new ClassPathResource("banner.txt")));

19
src/main/java/com/iflytop/nuclear/service/impl/TaskServiceImpl.java

@ -3,10 +3,10 @@ package com.iflytop.nuclear.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.iflytop.nuclear.mapper.TaskMapper;
import com.iflytop.nuclear.model.Account;
import com.iflytop.nuclear.model.NuclearCoreConfig;
import com.iflytop.nuclear.model.Task;
import com.iflytop.nuclear.model.*;
import com.iflytop.nuclear.service.NuclearCoreConfigService;
import com.iflytop.nuclear.service.NuclearCoreService;
import com.iflytop.nuclear.service.NuclearStationService;
import com.iflytop.nuclear.service.TaskService;
import com.iflytop.nuclear.vo.TaskVO;
import org.springframework.beans.factory.annotation.Autowired;
@ -24,6 +24,10 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements Ta
@Autowired
NuclearCoreConfigService nuclearCoreConfigService;
@Autowired
NuclearCoreService nuclearCoreService;
@Autowired
NuclearStationService nuclearStationService;
@Override
public List<TaskVO> getTaskInfoByUsername(String username, String user_role) {
@ -45,12 +49,17 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements Ta
if (nuclearCoreConfigList.size() > 0) {
canUpload = false;
}
Long nuclearStationId = task.getNuclearStationId();
Long nuclearCoreId = task.getNuclearCoreId();
NuclearCore nuclearCore = nuclearCoreService.getById(nuclearCoreId);
NuclearStation nuclearStation = nuclearStationService.getById(nuclearStationId);
TaskVO taskVO = TaskVO.builder()
.taskName(task.getTaskName())
.checkOrder(task.getCheckOrder())
.id(task.getId())
.nuclearCoreName("1")
.nuclearStationName("2")
.status(task.getStatus())
.nuclearCoreName(nuclearCore.getName())
.nuclearStationName(nuclearStation.getName())
.publishTime(task.getPublishTime())
.operatorName(task.getOperatorId())
.startTime(task.getStartTime())

68
src/main/java/com/iflytop/nuclear/websocket/WebSocketClient.java

@ -0,0 +1,68 @@
package com.iflytop.nuclear.websocket;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.iflytop.nuclear.handler.MessageHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import javax.websocket.*;
import java.io.IOException;
import java.net.URI;
/**
* @author cool
* @date 2023/7/4 19:12
*/
@ClientEndpoint
@Component
@Slf4j
public class WebSocketClient {
@Autowired
MessageHandler messageHandler;
private Session session;
@OnOpen
public void onOpen(Session session) {
this.session = session;
}
// WebSocketContainer container = ContainerProvider.getWebSocketContainer();
// String uri ="ws://127.0.0.1:8888/websocket/123";
// container.connectToServer(WebSocketClient.class, URI.create(uri));
@OnMessage
public void onMessage(String message) throws IOException {
if (!StringUtils.isEmpty(message)) {
try {
JSONObject jsonObject = JSON.parseObject(message);
String command = jsonObject.getString("command");
// 根据command类型分发给不同的handler和detection
if (!command.isEmpty()) {
messageHandler.dispatcher(command, jsonObject, this.session);
}
} catch (Exception e) {
JSONObject msg = new JSONObject();
msg.put("message", "传输数据必须为包含command字段的JSON格式");
this.session.getBasicRemote().sendText(msg.toString());
e.printStackTrace();
}
}
}
@OnError
public void onError(Throwable t) {
t.printStackTrace();
}
public void sendMessage(String message) throws IOException {
if(this.session != null) {
this.session.getBasicRemote().sendText(message);
}
}
}

3
src/main/resources/application-dev.yml

@ -4,4 +4,5 @@ spring:
url: jdbc:mysql://127.0.0.1:3306/nuclear?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
username: root
password: root
driverClassName: com.mysql.cj.jdbc.Driver
driverClassName: com.mysql.cj.jdbc.Driver
Loading…
Cancel
Save