整理统一发送websocket接口,并将模拟想定推演时间和剩余时间相关数据的发送
This commit is contained in:
parent
3629f00104
commit
1946f33be3
|
|
@ -5,13 +5,15 @@
|
||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="050b8051-b1ec-42aa-bac3-c1c189a4697d" name="更改" comment="修改线程继承自定义线程相关类错误问题">
|
<list default="true" id="050b8051-b1ec-42aa-bac3-c1c189a4697d" name="更改" comment="修改线程继承自定义线程相关类错误问题">
|
||||||
<change afterPath="$PROJECT_DIR$/src/main/java/com/simulationservice/config/CorsFilter.java" afterDir="false" />
|
|
||||||
<change afterPath="$PROJECT_DIR$/src/main/java/com/simulationservice/util/redisUtil.java" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/main/java/com/simulationservice/controller/InferenceController.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/simulationservice/controller/InferenceController.java" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/pom.xml" beforeDir="false" afterPath="$PROJECT_DIR$/pom.xml" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/main/java/com/simulationservice/service/InferenceTaskService.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/simulationservice/service/InferenceTaskService.java" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/main/java/com/simulationservice/service/DemandThread.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/simulationservice/service/DemandThread.java" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/main/java/com/simulationservice/service/TaskAssignThread.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/simulationservice/service/TaskAssignThread.java" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/main/java/com/simulationservice/service/TaskThread.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/simulationservice/service/TaskThread.java" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/main/java/com/simulationservice/service/TimeSyncThread.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/simulationservice/service/TimeSyncThread.java" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/main/java/com/simulationservice/service/TimeSyncThread.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/simulationservice/service/TimeSyncThread.java" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/main/java/com/simulationservice/service/WasterThread.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/simulationservice/service/WasterThread.java" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/main/java/com/simulationservice/service/WebSocketServer.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/simulationservice/service/WebSocketServer.java" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/main/java/com/simulationservice/service/WebSocketServer.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/simulationservice/service/WebSocketServer.java" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/main/java/com/simulationservice/util/CustomThread.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/com/simulationservice/util/CustomThread.java" afterDir="false" />
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
|
|
@ -128,7 +130,7 @@
|
||||||
<workItem from="1757664586037" duration="3070000" />
|
<workItem from="1757664586037" duration="3070000" />
|
||||||
<workItem from="1757820561153" duration="249000" />
|
<workItem from="1757820561153" duration="249000" />
|
||||||
<workItem from="1757829080725" duration="24604000" />
|
<workItem from="1757829080725" duration="24604000" />
|
||||||
<workItem from="1757922989495" duration="18673000" />
|
<workItem from="1757922989495" duration="29564000" />
|
||||||
</task>
|
</task>
|
||||||
<task id="LOCAL-00001" summary="修改配置文件和去掉打包时test模块">
|
<task id="LOCAL-00001" summary="修改配置文件和去掉打包时test模块">
|
||||||
<option name="closed" value="true" />
|
<option name="closed" value="true" />
|
||||||
|
|
|
||||||
6
pom.xml
6
pom.xml
|
|
@ -35,6 +35,12 @@
|
||||||
<artifactId>spring-boot-starter-websocket</artifactId>
|
<artifactId>spring-boot-starter-websocket</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.hutool</groupId>
|
||||||
|
<artifactId>hutool-all</artifactId>
|
||||||
|
<version>5.8.26</version> <!-- 可以去 [Maven中央仓库](https://search.maven.org/search?q=hutool-all) 查最新版本 -->
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-validation</artifactId>
|
<artifactId>spring-boot-starter-validation</artifactId>
|
||||||
|
|
|
||||||
|
|
@ -13,11 +13,7 @@ public class DemandThread extends CustomThread {
|
||||||
if (max < 0) max = 1000;
|
if (max < 0) max = 1000;
|
||||||
max--;
|
max--;
|
||||||
String info = String.valueOf(max) + " " + getRoomId();
|
String info = String.valueOf(max) + " " + getRoomId();
|
||||||
try {
|
//SendWebSocketMsg();
|
||||||
WebSocketServer.sendInfo(info, "1111");
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,11 +14,7 @@ public class TaskAssignThread extends CustomThread {
|
||||||
if (max < 0) max = 1000;
|
if (max < 0) max = 1000;
|
||||||
max--;
|
max--;
|
||||||
String info = String.valueOf(max) + " " + getRoomId();
|
String info = String.valueOf(max) + " " + getRoomId();
|
||||||
try {
|
//SendWebSocketMsg();
|
||||||
WebSocketServer.sendInfo(info, "3333");
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,11 +13,6 @@ public class TaskThread extends CustomThread {
|
||||||
if (max < 0) max = 1000;
|
if (max < 0) max = 1000;
|
||||||
max--;
|
max--;
|
||||||
String info = String.valueOf(max) + " " + getRoomId();
|
String info = String.valueOf(max) + " " + getRoomId();
|
||||||
try {
|
SendWebSocketMsg(info, "111");
|
||||||
WebSocketServer.sendInfo(info, "2222");
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@ import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
import cn.hutool.extra.spring.SpringUtil;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.simulationservice.util.CustomThread;
|
import com.simulationservice.util.CustomThread;
|
||||||
import com.simulationservice.util.RedisUtil;
|
import com.simulationservice.util.RedisUtil;
|
||||||
|
|
||||||
|
|
@ -105,10 +107,18 @@ public class TimeSyncThread extends CustomThread {
|
||||||
|
|
||||||
// 推演的时间键值:roomId-runTime
|
// 推演的时间键值:roomId-runTime
|
||||||
String key = getRoomId() + "-runTime";
|
String key = getRoomId() + "-runTime";
|
||||||
//_redis.set(key, strTime);
|
SpringUtil.getBean(RedisUtil.class).set(key, strTime);
|
||||||
// 房间剩余时间键值:roomId-resvTime
|
// 房间剩余时间键值:roomId-resvTime
|
||||||
key = getRoomId() + "-resvTime";
|
key = getRoomId() + "-resvTime";
|
||||||
//_redis.set(key, _resvTime);
|
SpringUtil.getBean(RedisUtil.class).set(key, _resvTime);
|
||||||
|
|
||||||
|
//推送时间到客户端
|
||||||
|
JSONObject jsonObject = new JSONObject();
|
||||||
|
jsonObject.putIfAbsent("roomId", getRoomId());
|
||||||
|
jsonObject.putIfAbsent("runTime", strTime);
|
||||||
|
jsonObject.putIfAbsent("resvTime", _resvTime);
|
||||||
|
String jsonString = jsonObject.toJSONString();
|
||||||
|
SendWebSocketMsg(jsonString, "1111");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBeginTime(String beginTime) {
|
public void setBeginTime(String beginTime) {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
package com.simulationservice.service;
|
package com.simulationservice.service;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.*;
|
import java.lang.*;
|
||||||
|
|
||||||
import com.simulationservice.util.CustomThread;
|
import com.simulationservice.util.CustomThread;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 作战分队物资消耗线程,用于各个作战单元的资源消耗
|
* 作战分队物资消耗线程,用于各个作战单元的资源消耗
|
||||||
*/
|
*/
|
||||||
|
|
@ -13,11 +15,7 @@ public class WasterThread extends CustomThread {
|
||||||
if (max < 0) max = 1000;
|
if (max < 0) max = 1000;
|
||||||
max--;
|
max--;
|
||||||
String info = String.valueOf(max) + " " + getRoomId();
|
String info = String.valueOf(max) + " " + getRoomId();
|
||||||
try {
|
//SendWebSocketMsg();
|
||||||
WebSocketServer.sendInfo(info, "1111");
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -126,14 +126,18 @@ public class WebSocketServer {
|
||||||
/**
|
/**
|
||||||
* 发送自定义消息
|
* 发送自定义消息
|
||||||
*/
|
*/
|
||||||
public static void sendInfo(String message, @PathParam("userId") String userId) throws IOException {
|
public static <Gson> void sendInfo(String message, @PathParam("userId") String userId) throws IOException {
|
||||||
|
|
||||||
if (!StringUtils.isNotBlank(userId) || !webSocketMap.containsKey(userId)) {
|
if (!StringUtils.isNotBlank(userId) || !webSocketMap.containsKey(userId)) {
|
||||||
//log.error("用户" + userId + ",不在线!");
|
//log.error("用户" + userId + ",不在线!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
log.info("发送消息到:" + userId + ",报文:" + message);
|
//log.info("发送消息到:" + userId + ",报文:" + message);
|
||||||
webSocketMap.get(userId).sendMessage(message);
|
JSONObject jsonObject = new JSONObject();
|
||||||
|
jsonObject.putIfAbsent("name", userId);
|
||||||
|
jsonObject.putIfAbsent("data", message);
|
||||||
|
String jsonString = jsonObject.toJSONString();
|
||||||
|
webSocketMap.get(userId).sendMessage(jsonString);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static synchronized int getOnlineCount() {
|
public static synchronized int getOnlineCount() {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,7 @@
|
||||||
package com.simulationservice.util;
|
package com.simulationservice.util;
|
||||||
|
import com.simulationservice.service.WebSocketServer;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.lang.*;
|
import java.lang.*;
|
||||||
/**
|
/**
|
||||||
* 需求消耗线程,用于各个作战单元的需求消耗
|
* 需求消耗线程,用于各个作战单元的需求消耗
|
||||||
|
|
@ -11,6 +14,7 @@ public abstract class CustomThread extends Thread {
|
||||||
private String roomId = ""; //房间号
|
private String roomId = ""; //房间号
|
||||||
public int max = 1000;
|
public int max = 1000;
|
||||||
public int time = 1000; //快进和快退时间,单位毫秒
|
public int time = 1000; //快进和快退时间,单位毫秒
|
||||||
|
private RedisUtil _redis;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
@ -66,4 +70,12 @@ public abstract class CustomThread extends Thread {
|
||||||
public void setTime(int time) {
|
public void setTime(int time) {
|
||||||
this.time = time;
|
this.time = time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SendWebSocketMsg(String msg, String userId) {
|
||||||
|
try {
|
||||||
|
WebSocketServer.sendInfo(msg, userId);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user