增加订阅设备状态时发送所有设备状态逻辑
This commit is contained in:
parent
b4f7b305b6
commit
e379a0a95f
@ -127,37 +127,6 @@ public class ATSMessageCollectAndDispatcher {
|
|||||||
return totalList;
|
return totalList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void collectDeviceStatusAndSend(Simulation simulation, List<? extends MapElement> deviceList) {
|
|
||||||
if (!CollectionUtils.isEmpty(deviceList)) {
|
|
||||||
List<Object> filterList = new ArrayList<>();
|
|
||||||
SimulationDataRepository repository = simulation.getRepository();
|
|
||||||
deviceList.forEach(device -> {
|
|
||||||
DeviceStatus deviceStatus = repository.findStatusByCode(device.getCode());
|
|
||||||
if (Objects.isNull(deviceStatus)) {
|
|
||||||
deviceStatus = buildDeviceStatus(device);
|
|
||||||
if (Objects.nonNull(deviceStatus)) {
|
|
||||||
repository.addDeviceInfo(deviceStatus);
|
|
||||||
filterList.add(deviceStatus);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
DeviceStatusVO statusVO = buildDeviceStatusVO(device);
|
|
||||||
if (deviceStatus.compareAndChange(device, statusVO)) {
|
|
||||||
filterList.add(statusVO);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// 构建并发送设备状态消息
|
|
||||||
if (CollectionUtils.isEmpty(filterList)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
SocketMessageVO deviceStatusMessage =
|
|
||||||
SocketMessageFactory.build(WebSocketMessageType.Simulation_DeviceStatus,
|
|
||||||
simulation.getId(), filterList);
|
|
||||||
Set<String> sessions = simulation.getSimulationUserIds();
|
|
||||||
stompMessageService.sendToUser(sessions, deviceStatusMessage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private DeviceStatus buildDeviceStatus(MapElement device) {
|
private DeviceStatus buildDeviceStatus(MapElement device) {
|
||||||
DeviceStatus status = null;
|
DeviceStatus status = null;
|
||||||
switch (device.getDeviceType()) {
|
switch (device.getDeviceType()) {
|
||||||
|
@ -97,6 +97,10 @@ public class SimulationUserWsListener {
|
|||||||
handleSubscribeSimulationMain(simulation, simulationUser);
|
handleSubscribeSimulationMain(simulation, simulationUser);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case DeviceStatus: {
|
||||||
|
handleSubscribeSimulationDeviceStatus(simulation, userId);
|
||||||
|
break;
|
||||||
|
}
|
||||||
case SandBox: {
|
case SandBox: {
|
||||||
applicationContext.publishEvent(new SandboxUserConnectEvent(userId, subscribeTopic.getId(destination), this));
|
applicationContext.publishEvent(new SandboxUserConnectEvent(userId, subscribeTopic.getId(destination), this));
|
||||||
break;
|
break;
|
||||||
@ -114,6 +118,12 @@ public class SimulationUserWsListener {
|
|||||||
ctcLogicLoop.sendMessageWhenSubscribeCtc(simulation, userId);
|
ctcLogicLoop.sendMessageWhenSubscribeCtc(simulation, userId);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
// case Room:
|
||||||
|
// break;
|
||||||
|
// case Wgu3d:
|
||||||
|
// break;
|
||||||
|
// case YJDDZH_TRAIN_POSITION:
|
||||||
|
// break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,14 +133,6 @@ public class SimulationUserWsListener {
|
|||||||
private void handleSubscribeSimulationMain(club.joylink.rtss.simulation.cbtc.Simulation simulation, SimulationUser simulationUser) {
|
private void handleSubscribeSimulationMain(club.joylink.rtss.simulation.cbtc.Simulation simulation, SimulationUser simulationUser) {
|
||||||
String group = simulation.getId();
|
String group = simulation.getId();
|
||||||
String userId = simulationUser.getId();
|
String userId = simulationUser.getId();
|
||||||
// 将当前所有设备状态同步给用户
|
|
||||||
List<DeviceStatus> statusList = simulation.getRepository().getAllStatusList();
|
|
||||||
if (!CollectionUtils.isEmpty(statusList)) {
|
|
||||||
SocketMessageVO allStatusMessage =
|
|
||||||
SocketMessageFactory.build(WebSocketMessageType.Simulation_DeviceStatus,
|
|
||||||
group, statusList);
|
|
||||||
this.stompMessageService.sendToUser(userId, allStatusMessage);
|
|
||||||
}
|
|
||||||
// 将当前所有列车实际运行数据同步给用户
|
// 将当前所有列车实际运行数据同步给用户
|
||||||
List<RealRun> realRunRecordList = simulation.getRepository().getRealRunRecordList();
|
List<RealRun> realRunRecordList = simulation.getRepository().getRealRunRecordList();
|
||||||
if (!CollectionUtils.isEmpty(realRunRecordList)) {
|
if (!CollectionUtils.isEmpty(realRunRecordList)) {
|
||||||
@ -159,6 +161,17 @@ public class SimulationUserWsListener {
|
|||||||
this.stompMessageService.sendToUser(userId, message);
|
this.stompMessageService.sendToUser(userId, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void handleSubscribeSimulationDeviceStatus(club.joylink.rtss.simulation.cbtc.Simulation simulation, String userId) {
|
||||||
|
// 将当前所有设备状态同步给用户
|
||||||
|
List<DeviceStatus> statusList = simulation.getRepository().getAllStatusList();
|
||||||
|
if (!CollectionUtils.isEmpty(statusList)) {
|
||||||
|
SocketMessageVO allStatusMessage =
|
||||||
|
SocketMessageFactory.build(WebSocketMessageType.Simulation_DeviceStatus,
|
||||||
|
simulation.getId(), statusList);
|
||||||
|
this.stompMessageService.sendToUser(userId, allStatusMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Async("nsExecutor")
|
@Async("nsExecutor")
|
||||||
@EventListener
|
@EventListener
|
||||||
public void handle(SimulationUserUnsubscribeEvent event) {
|
public void handle(SimulationUserUnsubscribeEvent event) {
|
||||||
|
Loading…
Reference in New Issue
Block a user