调度命令

This commit is contained in:
xzb 2022-09-30 13:15:02 +08:00
parent 080c29da23
commit ee3e67046f
7 changed files with 115 additions and 28 deletions

View File

@ -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.DisCmd;
import club.joylink.rtss.simulation.cbtc.CTC.rail.dcmd.data.DisCmdCompany; 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.*;
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 lombok.Data; import lombok.Data;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
@ -57,7 +54,13 @@ public class DisCmdTestController {
public DisCmd pushForSend(){ public DisCmd pushForSend(){
return null; return null;
} }
/**
* 后台向前端推送的同步消息
*/
@PostMapping("/1-5471-194-903/operate/CTC_SEND_DIS_COMMAND/sync")
public DisCmdSyncMsgVo pushSync(){
return null;
}
/** /**
* 处理前端发送来的签收指令 * 处理前端发送来的签收指令
*/ */

View File

@ -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.DisCmdCompanyState;
import club.joylink.rtss.simulation.cbtc.CTC.rail.dcmd.data.DisCmdDb; 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.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.Simulation;
import club.joylink.rtss.simulation.cbtc.member.SimulationMember; import club.joylink.rtss.simulation.cbtc.member.SimulationMember;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -17,6 +18,8 @@ import java.util.List;
public class DisCmdCrudService { public class DisCmdCrudService {
@Autowired @Autowired
private DisCmdCommonService commonService; private DisCmdCommonService commonService;
@Autowired
private DisCmdSendService disCmdSendService;
/** /**
* 新建调度命令生成调度命令唯一id和调度命令号 * 新建调度命令生成调度命令唯一id和调度命令号
@ -109,9 +112,6 @@ public class DisCmdCrudService {
} }
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertTrue(allRc,String.format("仿真(%s),调度命令id(%s)增补的单位必须为受令单位", simulation.getId(), cmdId)); BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertTrue(allRc,String.format("仿真(%s),调度命令id(%s)增补的单位必须为受令单位", simulation.getId(), cmdId));
rcs.forEach(rc->{ rcs.forEach(rc->{
DisCmdCompanyState rcState = new DisCmdCompanyState();
rcState.setCpId(rc.getId());
db.getUnSafeCmdStateMap().put(rcState.getCpId(), rcState);
cmd.getRcvCompanies().add(rc); cmd.getRcvCompanies().add(rc);
}); });
}finally { }finally {
@ -134,19 +134,17 @@ public class DisCmdCrudService {
db.removeCmdAndAboutAll(old.getCmdId()); db.removeCmdAndAboutAll(old.getCmdId());
} }
db.getUnSafeCmdMap().put(cmd.getCmdId(), cmd); db.getUnSafeCmdMap().put(cmd.getCmdId(), cmd);
//单位生成状态 //发令单位生成状态
DisCmdCompanyState send = new DisCmdCompanyState(); DisCmdCompanyState send = new DisCmdCompanyState();
send.setCpId(cmd.getSendCompany().getId()); send.setCpId(cmd.getSendCompany().getId());
send.setState(DisCmdCompanyState.Status.Cache); send.setState(DisCmdCompanyState.Status.Cache);
send.setTime(commonService.getNow(simulation)); send.setTime(commonService.getNow(simulation));
send.setOperatorId(curMember.getId()); send.setOperatorId(curMember.getId());
db.getUnSafeCmdStateMap().put(send.getCpId(), send); db.getUnSafeCmdStateMap().put(send.getCpId(), send);
// //同步状态到前端
cmd.getRcvCompanies().forEach(rc -> { List<DisCmdCompany> toList = new ArrayList<>();
DisCmdCompanyState rcs = new DisCmdCompanyState(); toList.add(cmd.getSendCompany());
rcs.setCpId(rc.getId()); disCmdSendService.sendDisCmdSyncMessage(simulation, DisCmdSyncMsgVo.create(send),toList);
db.getUnSafeCmdStateMap().put(rcs.getCpId(), rcs);
});
} finally { } finally {
db.unlock(); db.unlock();
} }

View File

@ -2,8 +2,10 @@ package club.joylink.rtss.simulation.cbtc.CTC.rail.dcmd.service;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum; 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.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.Simulation;
import club.joylink.rtss.simulation.cbtc.data.map.DisStation; 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.map.Station;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain; import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain;
import club.joylink.rtss.simulation.cbtc.member.SimulationMember; import club.joylink.rtss.simulation.cbtc.member.SimulationMember;
@ -65,10 +67,19 @@ public class DisCmdSendService {
// //
DisCmd cmd = db.findUnSafeCmd(cmdId); DisCmd cmd = db.findUnSafeCmd(cmdId);
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertTrue(null != cmd, String.format("仿真(%s),调度命令id(%s)不存在", simulation.getId(), 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 -> { cmd.getRcvCompanies().forEach(rc -> {
this.doSend(simulation, db, cmd, rc, sender); this.doSend(simulation, db, cmd, rc, sender);
}); });
//推送消息到前端
this.pushDisCmdToClient(simulation, db, cmd); this.pushDisCmdToClient(simulation, db, cmd);
} finally { } finally {
db.unlock(); db.unlock();
@ -145,20 +156,30 @@ public class DisCmdSendService {
DisCmd sendMsg = cmd.createSendMsg(to.getId()); DisCmd sendMsg = cmd.createSendMsg(to.getId());
// //
SocketMessageVO<DisCmd> nt = SocketMessageFactory.buildDisCmdAddNotify(simulation.getId(), sendMsg); SocketMessageVO<DisCmd> nt = SocketMessageFactory.buildDisCmdAddNotify(simulation.getId(), sendMsg);
// this.pushMessage(simulation,nt,to);
}
/**
* 向终端同步调度命令相关信息
*/
public void sendDisCmdSyncMessage(Simulation simulation, DisCmdSyncMsgVo msg, List<DisCmdCompany> toList) {
SocketMessageVO<DisCmdSyncMsgVo> 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())) {//向车站的相关成员发送通知 if (DisCmdCompany.Type.Station.equals(to.getCpType())) {//向车站的相关成员发送通知
Station station = simulation.getRepository().getByCode(to.getCode(), Station.class); Station station = simulation.getRepository().getByCode(to.getCode(), Station.class);
if (null != station) { if (null != station) {
Set<String> receiverUserIds = simulation.getSimulationMembersByDevice(station).stream().map(club.joylink.rtss.simulation.SimulationMember::getUserId) Set<String> receiverUserIds = simulation.getSimulationMembersByDevice(station).stream().map(club.joylink.rtss.simulation.SimulationMember::getUserId).collect(Collectors.toSet());
.collect(Collectors.toSet());
stompMessageService.sendToUser(receiverUserIds, nt); stompMessageService.sendToUser(receiverUserIds, nt);
} }
} else if (DisCmdCompany.Type.Dispatcher.equals(to.getCpType())) {//向调度台的调度推送通知 } else if (DisCmdCompany.Type.Dispatcher.equals(to.getCpType())) {//向调度台的调度推送通知
List<DisStation> disStationList = simulation.getRepository().getDisStationList(); List<DisStation> disStationList = simulation.getRepository().getDisStationList();
disStationList.forEach(disStation -> { disStationList.forEach(disStation -> {
if (disStation.getCode().equals(to.getCode())) { if (disStation.getCode().equals(to.getCode())) {
Set<String> receiverUserIds = simulation.getSimulationMembersByDevice(disStation).stream().map(club.joylink.rtss.simulation.SimulationMember::getUserId) Set<String> receiverUserIds = simulation.getSimulationMembersByDevice(disStation).stream().map(club.joylink.rtss.simulation.SimulationMember::getUserId).collect(Collectors.toSet());
.collect(Collectors.toSet());
stompMessageService.sendToUser(receiverUserIds, nt); stompMessageService.sendToUser(receiverUserIds, nt);
} }
}); });
@ -175,8 +196,7 @@ public class DisCmdSendService {
if (null != trains && !trains.isEmpty()) { if (null != trains && !trains.isEmpty()) {
VirtualRealityTrain train = trains.get(0); VirtualRealityTrain train = trains.get(0);
//查找该次列车的司机向司机推送通知 //查找该次列车的司机向司机推送通知
Set<String> receiverUserIds = simulation.getSimulationMembersByDevice(train).stream().map(club.joylink.rtss.simulation.SimulationMember::getUserId) Set<String> receiverUserIds = simulation.getSimulationMembersByDevice(train).stream().map(club.joylink.rtss.simulation.SimulationMember::getUserId).collect(Collectors.toSet());
.collect(Collectors.toSet());
stompMessageService.sendToUser(receiverUserIds, nt); stompMessageService.sendToUser(receiverUserIds, nt);
} }
} }

View File

@ -2,11 +2,15 @@ package club.joylink.rtss.simulation.cbtc.CTC.rail.dcmd.service;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum; 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.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.Simulation;
import club.joylink.rtss.simulation.cbtc.member.SimulationMember; import club.joylink.rtss.simulation.cbtc.member.SimulationMember;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; 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 { public class DisCmdSimpleService {
@Autowired @Autowired
private DisCmdCommonService commonService; private DisCmdCommonService commonService;
@Autowired
private DisCmdSendService disCmdSendService;
/** /**
* 前端阅读调度命令 * 前端阅读调度命令
* *
@ -36,6 +41,11 @@ public class DisCmdSimpleService {
// 记录回执 // 记录回执
DisCmdCompany rc = db.findCmdCompany(cmdId, rcId); DisCmdCompany rc = db.findCmdCompany(cmdId, rcId);
db.addCmdReceipt(DisCmdReceipt.Status.Received, cmd, rc, reader); db.addCmdReceipt(DisCmdReceipt.Status.Received, cmd, rc, reader);
// 向发令单位同步状态
List<DisCmdCompany> toList = new ArrayList<>();
toList.add(cmd.getSendCompany());
toList.add(rc);
disCmdSendService.sendDisCmdSyncMessage(simulation,DisCmdSyncMsgVo.create(rcState),toList);
} finally { } finally {
db.unlock(); db.unlock();
} }
@ -63,6 +73,11 @@ public class DisCmdSimpleService {
// 记录回执 // 记录回执
DisCmdCompany rc = db.findCmdCompany(cmdId, rcId); DisCmdCompany rc = db.findCmdCompany(cmdId, rcId);
db.addCmdReceipt(proxySign ? DisCmdReceipt.Status.ProxySigned : DisCmdReceipt.Status.Signed, cmd, rc, signer); db.addCmdReceipt(proxySign ? DisCmdReceipt.Status.ProxySigned : DisCmdReceipt.Status.Signed, cmd, rc, signer);
// 向发令单位同步状态
List<DisCmdCompany> toList = new ArrayList<>();
toList.add(cmd.getSendCompany());
toList.add(rc);
disCmdSendService.sendDisCmdSyncMessage(simulation,DisCmdSyncMsgVo.create(rcState),toList);
// //
this.checkAndUpdateSendCompany(simulation, cmdId); this.checkAndUpdateSendCompany(simulation, cmdId);
} finally { } finally {
@ -91,6 +106,11 @@ public class DisCmdSimpleService {
// 记录回执 // 记录回执
DisCmdCompany rc = db.findCmdCompany(cmdId, rcId); DisCmdCompany rc = db.findCmdCompany(cmdId, rcId);
db.addCmdReceipt(DisCmdReceipt.Status.Rejected, cmd, rc, reject); db.addCmdReceipt(DisCmdReceipt.Status.Rejected, cmd, rc, reject);
// 向发令单位同步状态
List<DisCmdCompany> toList = new ArrayList<>();
toList.add(cmd.getSendCompany());
toList.add(rc);
disCmdSendService.sendDisCmdSyncMessage(simulation,DisCmdSyncMsgVo.create(rcState),toList);
// //
this.checkAndUpdateSendCompany(simulation, cmdId); this.checkAndUpdateSendCompany(simulation, cmdId);
} finally { } finally {
@ -117,17 +137,26 @@ public class DisCmdSimpleService {
} }
} }
// //
boolean needSync = false;
if (allSigned) { if (allSigned) {
sendState.setState(DisCmdCompanyState.Status.Signed); sendState.setState(DisCmdCompanyState.Status.Signed);
sendState.setTime(commonService.getNow(simulation)); sendState.setTime(commonService.getNow(simulation));
needSync = true;
// 记录回执 // 记录回执
DisCmdCompany rc = db.findCmdCompany(cmdId, sendState.getCpId()); DisCmdCompany rc = db.findCmdCompany(cmdId, sendState.getCpId());
db.addCmdReceipt(DisCmdReceipt.Status.AllSigned, cmd, rc, null); db.addCmdReceipt(DisCmdReceipt.Status.AllSigned, cmd, rc, null);
} else { } else {
if (DisCmdCompanyState.Status.Signed.equals(sendState.getState())) { if (DisCmdCompanyState.Status.Signed.equals(sendState.getState())) {
sendState.setState(DisCmdCompanyState.Status.Sent); sendState.setState(DisCmdCompanyState.Status.Sent);
needSync = true;
} }
} }
//同步状态到发令方
if(needSync){
List<DisCmdCompany> toList = new ArrayList<>();
toList.add(cmd.getSendCompany());
disCmdSendService.sendDisCmdSyncMessage(simulation,DisCmdSyncMsgVo.create(sendState),toList);
}
} finally { } finally {
db.unlock(); db.unlock();
} }

View File

@ -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<String, DisCmdCompanyState> 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;
}
}

View File

@ -348,9 +348,9 @@ public enum WebSocketMessageType {
*/ */
SIMULATION_RAIL_CTC_DIS_COMMAND_ADD, SIMULATION_RAIL_CTC_DIS_COMMAND_ADD,
/** /**
* 调度命令v2,通知前端受令单位未在60秒内签收 * 调度命令v2,将调度服务器端数据变化同步到前端
*/ */
SIMULATION_RAIL_CTC_DIS_COMMAND_TIMEOUT60_SIGN, SIMULATION_RAIL_CTC_DIS_COMMAND_SYNC,
/** /**
* 大铁路票 * 大铁路票
*/ */

View File

@ -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.CtcStationRunPlanLogVO;
import club.joylink.rtss.simulation.cbtc.CTC.data.vo.RailDispatchCommandVO; 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.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.Simulation;
import club.joylink.rtss.simulation.cbtc.communication.vo.TrainPosition; import club.joylink.rtss.simulation.cbtc.communication.vo.TrainPosition;
import club.joylink.rtss.simulation.cbtc.conversation.Conversation; import club.joylink.rtss.simulation.cbtc.conversation.Conversation;
@ -102,7 +103,7 @@ public class SocketMessageFactory {
case SIMULATION_CTC_RUN_PLAN_CONFIRM_SEND: case SIMULATION_CTC_RUN_PLAN_CONFIRM_SEND:
case SIMULATION_RAIL_CTC_DISPATCH_COMMAND: case SIMULATION_RAIL_CTC_DISPATCH_COMMAND:
case SIMULATION_RAIL_CTC_DIS_COMMAND_ADD: 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: { case Simulation_RailCtcStatus: {
topicList.add(SimulationSubscribeTopic.Ctc.buildDestination(group)); topicList.add(SimulationSubscribeTopic.Ctc.buildDestination(group));
break; break;
@ -434,7 +435,12 @@ public class SocketMessageFactory {
public static SocketMessageVO<DisCmd> buildDisCmdAddNotify(String sId, DisCmd body) { public static SocketMessageVO<DisCmd> buildDisCmdAddNotify(String sId, DisCmd body) {
return build(WebSocketMessageType.SIMULATION_RAIL_CTC_DIS_COMMAND_ADD, sId, body); return build(WebSocketMessageType.SIMULATION_RAIL_CTC_DIS_COMMAND_ADD, sId, body);
} }
/**
* CTC调度命令消息2,将调度服务器端数据变化同步到前端
*/
public static SocketMessageVO<DisCmdSyncMsgVo>buildDisCmdSyncMessage(String sId, DisCmdSyncMsgVo syncMsg){
return build(WebSocketMessageType.SIMULATION_RAIL_CTC_DIS_COMMAND_SYNC, sId, syncMsg);
}
/** /**
* CTC路票消息 * CTC路票消息
*/ */