diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/dcmd/DisCmdTestController.java b/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/dcmd/DisCmdTestController.java index 73fe2ffab..c3b2d1f03 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/dcmd/DisCmdTestController.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/dcmd/DisCmdTestController.java @@ -3,10 +3,7 @@ package club.joylink.rtss.simulation.cbtc.CTC.rail.dcmd; import club.joylink.rtss.simulation.cbtc.CTC.rail.dcmd.data.DisCmd; import club.joylink.rtss.simulation.cbtc.CTC.rail.dcmd.data.DisCmdCompany; -import club.joylink.rtss.simulation.cbtc.CTC.rail.dcmd.vo.DisCmdCreateRspVo; -import club.joylink.rtss.simulation.cbtc.CTC.rail.dcmd.vo.DisCmdFindAllForHolderRspVo; -import club.joylink.rtss.simulation.cbtc.CTC.rail.dcmd.vo.DisCmdForwardPrepareRspVo; -import club.joylink.rtss.simulation.cbtc.CTC.rail.dcmd.vo.DisCmdReceiptRspVo; +import club.joylink.rtss.simulation.cbtc.CTC.rail.dcmd.vo.*; import lombok.Data; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -57,7 +54,13 @@ public class DisCmdTestController { public DisCmd pushForSend(){ return null; } - + /** + * 后台向前端推送的同步消息 + */ + @PostMapping("/1-5471-194-903/operate/CTC_SEND_DIS_COMMAND/sync") + public DisCmdSyncMsgVo pushSync(){ + return null; + } /** * 处理前端发送来的签收指令 */ diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/dcmd/service/DisCmdCrudService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/dcmd/service/DisCmdCrudService.java index 1624dfea6..3432e0c70 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/dcmd/service/DisCmdCrudService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/dcmd/service/DisCmdCrudService.java @@ -6,6 +6,7 @@ import club.joylink.rtss.simulation.cbtc.CTC.rail.dcmd.data.DisCmdCompany; import club.joylink.rtss.simulation.cbtc.CTC.rail.dcmd.data.DisCmdCompanyState; import club.joylink.rtss.simulation.cbtc.CTC.rail.dcmd.data.DisCmdDb; import club.joylink.rtss.simulation.cbtc.CTC.rail.dcmd.vo.DisCmdCreateRspVo; +import club.joylink.rtss.simulation.cbtc.CTC.rail.dcmd.vo.DisCmdSyncMsgVo; import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.member.SimulationMember; import org.springframework.beans.factory.annotation.Autowired; @@ -17,6 +18,8 @@ import java.util.List; public class DisCmdCrudService { @Autowired private DisCmdCommonService commonService; + @Autowired + private DisCmdSendService disCmdSendService; /** * 新建调度命令,生成调度命令唯一id和调度命令号 @@ -109,9 +112,6 @@ public class DisCmdCrudService { } BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertTrue(allRc,String.format("仿真(%s),调度命令id(%s)增补的单位必须为受令单位", simulation.getId(), cmdId)); rcs.forEach(rc->{ - DisCmdCompanyState rcState = new DisCmdCompanyState(); - rcState.setCpId(rc.getId()); - db.getUnSafeCmdStateMap().put(rcState.getCpId(), rcState); cmd.getRcvCompanies().add(rc); }); }finally { @@ -134,19 +134,17 @@ public class DisCmdCrudService { db.removeCmdAndAboutAll(old.getCmdId()); } db.getUnSafeCmdMap().put(cmd.getCmdId(), cmd); - //为单位生成状态 + //为发令单位生成状态 DisCmdCompanyState send = new DisCmdCompanyState(); send.setCpId(cmd.getSendCompany().getId()); send.setState(DisCmdCompanyState.Status.Cache); send.setTime(commonService.getNow(simulation)); send.setOperatorId(curMember.getId()); db.getUnSafeCmdStateMap().put(send.getCpId(), send); - // - cmd.getRcvCompanies().forEach(rc -> { - DisCmdCompanyState rcs = new DisCmdCompanyState(); - rcs.setCpId(rc.getId()); - db.getUnSafeCmdStateMap().put(rcs.getCpId(), rcs); - }); + //同步状态到前端 + List toList = new ArrayList<>(); + toList.add(cmd.getSendCompany()); + disCmdSendService.sendDisCmdSyncMessage(simulation, DisCmdSyncMsgVo.create(send),toList); } finally { db.unlock(); } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/dcmd/service/DisCmdSendService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/dcmd/service/DisCmdSendService.java index ba6a2fae9..8e1b8b4b0 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/dcmd/service/DisCmdSendService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/dcmd/service/DisCmdSendService.java @@ -2,8 +2,10 @@ package club.joylink.rtss.simulation.cbtc.CTC.rail.dcmd.service; import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.simulation.cbtc.CTC.rail.dcmd.data.*; +import club.joylink.rtss.simulation.cbtc.CTC.rail.dcmd.vo.DisCmdSyncMsgVo; import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.data.map.DisStation; +import club.joylink.rtss.simulation.cbtc.data.map.MapElement; import club.joylink.rtss.simulation.cbtc.data.map.Station; import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain; import club.joylink.rtss.simulation.cbtc.member.SimulationMember; @@ -65,10 +67,19 @@ public class DisCmdSendService { // DisCmd cmd = db.findUnSafeCmd(cmdId); BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertTrue(null != cmd, String.format("仿真(%s),调度命令id(%s)不存在", simulation.getId(), cmdId)); - // + //为受令单位生成状态 + cmd.getRcvCompanies().forEach(rc -> { + if (!db.getUnSafeCmdStateMap().containsKey(rc.getId())) { + DisCmdCompanyState rcs = new DisCmdCompanyState(); + rcs.setCpId(rc.getId()); + db.getUnSafeCmdStateMap().put(rcs.getCpId(), rcs); + } + }); + //向受令单位发送调度命令 cmd.getRcvCompanies().forEach(rc -> { this.doSend(simulation, db, cmd, rc, sender); }); + //推送消息到前端 this.pushDisCmdToClient(simulation, db, cmd); } finally { db.unlock(); @@ -145,20 +156,30 @@ public class DisCmdSendService { DisCmd sendMsg = cmd.createSendMsg(to.getId()); // SocketMessageVO nt = SocketMessageFactory.buildDisCmdAddNotify(simulation.getId(), sendMsg); - // + this.pushMessage(simulation,nt,to); + } + + /** + * 向终端同步调度命令相关信息 + */ + public void sendDisCmdSyncMessage(Simulation simulation, DisCmdSyncMsgVo msg, List toList) { + SocketMessageVO nt = SocketMessageFactory.buildDisCmdSyncMessage(simulation.getId(), msg); + for(DisCmdCompany to:toList){ + this.pushMessage(simulation,nt,to); + } + } + private void pushMessage(Simulation simulation, SocketMessageVO nt, DisCmdCompany to) { if (DisCmdCompany.Type.Station.equals(to.getCpType())) {//向车站的相关成员发送通知 Station station = simulation.getRepository().getByCode(to.getCode(), Station.class); if (null != station) { - Set receiverUserIds = simulation.getSimulationMembersByDevice(station).stream().map(club.joylink.rtss.simulation.SimulationMember::getUserId) - .collect(Collectors.toSet()); + Set receiverUserIds = simulation.getSimulationMembersByDevice(station).stream().map(club.joylink.rtss.simulation.SimulationMember::getUserId).collect(Collectors.toSet()); stompMessageService.sendToUser(receiverUserIds, nt); } } else if (DisCmdCompany.Type.Dispatcher.equals(to.getCpType())) {//向调度台的调度推送通知 List disStationList = simulation.getRepository().getDisStationList(); disStationList.forEach(disStation -> { if (disStation.getCode().equals(to.getCode())) { - Set receiverUserIds = simulation.getSimulationMembersByDevice(disStation).stream().map(club.joylink.rtss.simulation.SimulationMember::getUserId) - .collect(Collectors.toSet()); + Set receiverUserIds = simulation.getSimulationMembersByDevice(disStation).stream().map(club.joylink.rtss.simulation.SimulationMember::getUserId).collect(Collectors.toSet()); stompMessageService.sendToUser(receiverUserIds, nt); } }); @@ -175,8 +196,7 @@ public class DisCmdSendService { if (null != trains && !trains.isEmpty()) { VirtualRealityTrain train = trains.get(0); //查找该次列车的司机,向司机推送通知 - Set receiverUserIds = simulation.getSimulationMembersByDevice(train).stream().map(club.joylink.rtss.simulation.SimulationMember::getUserId) - .collect(Collectors.toSet()); + Set receiverUserIds = simulation.getSimulationMembersByDevice(train).stream().map(club.joylink.rtss.simulation.SimulationMember::getUserId).collect(Collectors.toSet()); stompMessageService.sendToUser(receiverUserIds, nt); } } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/dcmd/service/DisCmdSimpleService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/dcmd/service/DisCmdSimpleService.java index f741d73b5..05f4ea70d 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/dcmd/service/DisCmdSimpleService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/dcmd/service/DisCmdSimpleService.java @@ -2,11 +2,15 @@ package club.joylink.rtss.simulation.cbtc.CTC.rail.dcmd.service; import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.simulation.cbtc.CTC.rail.dcmd.data.*; +import club.joylink.rtss.simulation.cbtc.CTC.rail.dcmd.vo.DisCmdSyncMsgVo; import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.member.SimulationMember; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.ArrayList; +import java.util.List; + /** * 一般简单操作业务 */ @@ -14,7 +18,8 @@ import org.springframework.stereotype.Service; public class DisCmdSimpleService { @Autowired private DisCmdCommonService commonService; - + @Autowired + private DisCmdSendService disCmdSendService; /** * 前端阅读调度命令 * @@ -36,6 +41,11 @@ public class DisCmdSimpleService { // 记录回执 DisCmdCompany rc = db.findCmdCompany(cmdId, rcId); db.addCmdReceipt(DisCmdReceipt.Status.Received, cmd, rc, reader); + // 向发令单位同步状态 + List toList = new ArrayList<>(); + toList.add(cmd.getSendCompany()); + toList.add(rc); + disCmdSendService.sendDisCmdSyncMessage(simulation,DisCmdSyncMsgVo.create(rcState),toList); } finally { db.unlock(); } @@ -63,6 +73,11 @@ public class DisCmdSimpleService { // 记录回执 DisCmdCompany rc = db.findCmdCompany(cmdId, rcId); db.addCmdReceipt(proxySign ? DisCmdReceipt.Status.ProxySigned : DisCmdReceipt.Status.Signed, cmd, rc, signer); + // 向发令单位同步状态 + List toList = new ArrayList<>(); + toList.add(cmd.getSendCompany()); + toList.add(rc); + disCmdSendService.sendDisCmdSyncMessage(simulation,DisCmdSyncMsgVo.create(rcState),toList); // this.checkAndUpdateSendCompany(simulation, cmdId); } finally { @@ -91,6 +106,11 @@ public class DisCmdSimpleService { // 记录回执 DisCmdCompany rc = db.findCmdCompany(cmdId, rcId); db.addCmdReceipt(DisCmdReceipt.Status.Rejected, cmd, rc, reject); + // 向发令单位同步状态 + List toList = new ArrayList<>(); + toList.add(cmd.getSendCompany()); + toList.add(rc); + disCmdSendService.sendDisCmdSyncMessage(simulation,DisCmdSyncMsgVo.create(rcState),toList); // this.checkAndUpdateSendCompany(simulation, cmdId); } finally { @@ -117,17 +137,26 @@ public class DisCmdSimpleService { } } // + boolean needSync = false; if (allSigned) { sendState.setState(DisCmdCompanyState.Status.Signed); sendState.setTime(commonService.getNow(simulation)); + needSync = true; // 记录回执 DisCmdCompany rc = db.findCmdCompany(cmdId, sendState.getCpId()); db.addCmdReceipt(DisCmdReceipt.Status.AllSigned, cmd, rc, null); } else { if (DisCmdCompanyState.Status.Signed.equals(sendState.getState())) { sendState.setState(DisCmdCompanyState.Status.Sent); + needSync = true; } } + //同步状态到发令方 + if(needSync){ + List toList = new ArrayList<>(); + toList.add(cmd.getSendCompany()); + disCmdSendService.sendDisCmdSyncMessage(simulation,DisCmdSyncMsgVo.create(sendState),toList); + } } finally { db.unlock(); } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/dcmd/vo/DisCmdSyncMsgVo.java b/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/dcmd/vo/DisCmdSyncMsgVo.java new file mode 100644 index 000000000..09202848f --- /dev/null +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/dcmd/vo/DisCmdSyncMsgVo.java @@ -0,0 +1,31 @@ +package club.joylink.rtss.simulation.cbtc.CTC.rail.dcmd.vo; + +import club.joylink.rtss.simulation.cbtc.CTC.rail.dcmd.data.DisCmdCompanyState; +import lombok.Data; + +import java.util.HashMap; +import java.util.Map; + +/** + * 后端向前端同步的消息 + */ +@Data +public class DisCmdSyncMsgVo { + /** + * 发令或受令单位状态 + */ + private Map cpStateMap = new HashMap<>(); + + /** + * 添加受令单位状态 + */ + public void addDisCmdCompanyState(DisCmdCompanyState state){ + cpStateMap.put(state.getCpId(),state); + } + + public static DisCmdSyncMsgVo create(DisCmdCompanyState msg){ + DisCmdSyncMsgVo sync = new DisCmdSyncMsgVo(); + sync.addDisCmdCompanyState(msg); + return sync; + } +} diff --git a/src/main/java/club/joylink/rtss/vo/client/WebSocketMessageType.java b/src/main/java/club/joylink/rtss/vo/client/WebSocketMessageType.java index 79d0ce532..63ac6ec1d 100644 --- a/src/main/java/club/joylink/rtss/vo/client/WebSocketMessageType.java +++ b/src/main/java/club/joylink/rtss/vo/client/WebSocketMessageType.java @@ -348,9 +348,9 @@ public enum WebSocketMessageType { */ SIMULATION_RAIL_CTC_DIS_COMMAND_ADD, /** - * 调度命令v2,通知前端受令单位未在60秒内签收 + * 调度命令v2,将调度服务器端数据变化同步到前端 */ - SIMULATION_RAIL_CTC_DIS_COMMAND_TIMEOUT60_SIGN, + SIMULATION_RAIL_CTC_DIS_COMMAND_SYNC, /** * 大铁路票 */ diff --git a/src/main/java/club/joylink/rtss/vo/client/factory/SocketMessageFactory.java b/src/main/java/club/joylink/rtss/vo/client/factory/SocketMessageFactory.java index 7ac06b1a6..4f3a08abe 100644 --- a/src/main/java/club/joylink/rtss/vo/client/factory/SocketMessageFactory.java +++ b/src/main/java/club/joylink/rtss/vo/client/factory/SocketMessageFactory.java @@ -7,6 +7,7 @@ import club.joylink.rtss.simulation.cbtc.CTC.data.vo.BusyBoardVO; import club.joylink.rtss.simulation.cbtc.CTC.data.vo.CtcStationRunPlanLogVO; import club.joylink.rtss.simulation.cbtc.CTC.data.vo.RailDispatchCommandVO; import club.joylink.rtss.simulation.cbtc.CTC.rail.dcmd.data.DisCmd; +import club.joylink.rtss.simulation.cbtc.CTC.rail.dcmd.vo.DisCmdSyncMsgVo; import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.communication.vo.TrainPosition; import club.joylink.rtss.simulation.cbtc.conversation.Conversation; @@ -102,7 +103,7 @@ public class SocketMessageFactory { case SIMULATION_CTC_RUN_PLAN_CONFIRM_SEND: case SIMULATION_RAIL_CTC_DISPATCH_COMMAND: case SIMULATION_RAIL_CTC_DIS_COMMAND_ADD: - case SIMULATION_RAIL_CTC_DIS_COMMAND_TIMEOUT60_SIGN: + case SIMULATION_RAIL_CTC_DIS_COMMAND_SYNC: case Simulation_RailCtcStatus: { topicList.add(SimulationSubscribeTopic.Ctc.buildDestination(group)); break; @@ -434,7 +435,12 @@ public class SocketMessageFactory { public static SocketMessageVO buildDisCmdAddNotify(String sId, DisCmd body) { return build(WebSocketMessageType.SIMULATION_RAIL_CTC_DIS_COMMAND_ADD, sId, body); } - + /** + * CTC调度命令消息2,将调度服务器端数据变化同步到前端 + */ + public static SocketMessageVObuildDisCmdSyncMessage(String sId, DisCmdSyncMsgVo syncMsg){ + return build(WebSocketMessageType.SIMULATION_RAIL_CTC_DIS_COMMAND_SYNC, sId, syncMsg); + } /** * CTC路票消息 */