【车站转换后,发送转换结果】

This commit is contained in:
weizhihong 2022-12-14 16:46:53 +08:00
parent 5d0a171092
commit 0d66226280
3 changed files with 35 additions and 6 deletions

View File

@ -14,6 +14,10 @@ import club.joylink.rtss.simulation.cbtc.data.vo.ControlTransferReplyVO;
import club.joylink.rtss.simulation.cbtc.exception.SimulationException;
import club.joylink.rtss.simulation.cbtc.exception.SimulationExceptionType;
import club.joylink.rtss.simulation.cbtc.member.SimulationMember;
import club.joylink.rtss.vo.client.SocketMessageVO;
import club.joylink.rtss.vo.client.WebSocketMessageType;
import club.joylink.rtss.vo.client.factory.SocketMessageFactory;
import club.joylink.rtss.websocket.StompMessageService;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@ -35,6 +39,9 @@ public class AtsStationService {
@Autowired
private AtsRouteService atsRouteService;
@Autowired
private StompMessageService stompMessageService;
public StationStatus info(Simulation simulation, String stationCode) {
Station station = getStation(simulation, stationCode);
return new StationStatus(station);
@ -178,14 +185,22 @@ public class AtsStationService {
if (CollectionUtils.isEmpty(replyVOList)) {
throw new SimulationException(SimulationExceptionType.Invalid_Operation, "回复结果列表不能为空");
}
Map<String,Object> resultMap = null;
SimulationMember applicant = null;
for (ControlTransferReplyVO reply : replyVOList) {
Station station = simulation.getRepository().getByCode(reply.getStationCode(), Station.class);
if (station.isControlTransferApplying()) {
if (reply.isAgree()) {
station.setControlMode(controlMode);
}
resultMap = new HashMap<>();
applicant = station.getApplicant();
resultMap.put("stationCode", station.getCode());
resultMap.put("applicantId", applicant.getId());
resultMap.put("apply2TheControlMode", station.getApply2TheControlMode());
resultMap.put("status", reply.isAgree());
station.cancelControlTransferApplication();
sendHandlerMessage(simulation, applicant, resultMap);
}
}
}
@ -548,4 +563,17 @@ public class AtsStationService {
new OperationMessage(fromMember.getId(), new HashSet<>(Collections.singleton(fromMember)),
operationType, null, true, Arrays.asList(stationCode)));
}
/**
* 发送车站转换结果
*
* @param simulation 仿真
* @param applicant 申请者
* @param data 转换结果
*/
private void sendHandlerMessage(Simulation simulation, SimulationMember applicant, Map<String, Object> data) {
SocketMessageVO<Map<String, Object>> messageVO =
SocketMessageFactory.build(WebSocketMessageType.Simulation_Control_Transfer_Result, simulation.getId(), data);
stompMessageService.sendToUser(Set.of(applicant.getUserId()), messageVO);
}
}

View File

@ -162,6 +162,10 @@ public enum WebSocketMessageType {
* 仿真-报警
*/
Simulation_Alarm,
/**
* 仿真-控制模式转换结果
*/
Simulation_Control_Transfer_Result,
//------------------ 仿真剧本 ------------------
/**

View File

@ -38,10 +38,7 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
public class SocketMessageFactory {
@ -105,6 +102,7 @@ public class SocketMessageFactory {
topicList.add(SimulationSubscribeTopic.Main.buildDestination(group));
break;
}
case Simulation_Control_Transfer_Result:
case Simulation_DeviceStatus: {
topicList.add(SimulationSubscribeTopic.DeviceStatus.buildDestination(group));
break;
@ -307,7 +305,6 @@ public class SocketMessageFactory {
return build(WebSocketMessageType.Be_Logged_Out, null, infoVO);
}
@Component
private static class SpringContextUtil implements ApplicationContextAware {