rt仿真调整

This commit is contained in:
walker-sheng 2021-05-13 15:14:18 +08:00
parent f189b728fd
commit 190f510ba3
9 changed files with 95 additions and 70 deletions

View File

@ -1,22 +1,18 @@
package club.joylink.rtss.simulation.rt.ATS; package club.joylink.rtss.simulation.rt.ATS;
import club.joylink.rtss.simulation.SimulationUser;
import club.joylink.rtss.simulation.rt.ATS.bo.AtsRepository; import club.joylink.rtss.simulation.rt.ATS.bo.AtsRepository;
import club.joylink.rtss.simulation.rt.ATS.bo.AtsRepositoryBuilder; import club.joylink.rtss.simulation.rt.ATS.bo.AtsRepositoryBuilder;
import club.joylink.rtss.simulation.rt.RtSimulation; import club.joylink.rtss.simulation.rt.RtSimulation;
import club.joylink.rtss.simulation.rt.RtSimulationSubscribeTopic;
import club.joylink.rtss.simulation.rt.RtSimulationUser;
import club.joylink.rtss.vo.client.map.MapVO; import club.joylink.rtss.vo.client.map.MapVO;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.List;
/** /**
* ATS逻辑 * ATS逻辑
*/ */
@Component @Component
public class AtsLogicService { public class AtsLogicService {
public static final int Main_Logic_Rate = 1000;
public void init(RtSimulation rtSimulation, MapVO mapVO) { public void init(RtSimulation rtSimulation, MapVO mapVO) {
AtsRepository atsRepository = AtsRepositoryBuilder.buildFrom(mapVO); AtsRepository atsRepository = AtsRepositoryBuilder.buildFrom(mapVO);
rtSimulation.addRepository(atsRepository); rtSimulation.addRepository(atsRepository);
@ -25,28 +21,4 @@ public class AtsLogicService {
rtSimulation.addMessagePublisher(atsMessagePublisher); rtSimulation.addMessagePublisher(atsMessagePublisher);
} }
// public void addJobs(RtSimulation rtSimulation) {
// for (RtSimulationSubscribeTopic topic : RtSimulationSubscribeTopic.values()) {
// rtSimulation.addFixedRateJob("MESSAGE-" + topic.name(), () -> sendMessages(rtSimulation, topic), topic.getRate());
// }
// }
public void sendMessages(RtSimulation rtSimulation, RtSimulationSubscribeTopic topic) {
AtsRepository repository = rtSimulation.getRepository(AtsRepository.NAME, AtsRepository.class);
List<List<Object>> messages = repository.removeReady2SendMessages();
if (!CollectionUtils.isEmpty(messages)) {
List<RtSimulationUser> simulationUsers = rtSimulation.getSimulationUsers();
String dest = topic.buildDestination(rtSimulation.getId());
for (SimulationUser simulationUser : simulationUsers) {
if (simulationUser.isSubscribe(dest)) {
rtSimulation.pushMessageToUser(simulationUser.getId(), dest, messages);
}
}
}
}
public List<List<Object>> getAllMessages(RtSimulation rtSimulation) {
AtsRepository repository = rtSimulation.getRepository(AtsRepository.NAME, AtsRepository.class);
return repository.getAllMessages();
}
} }

View File

@ -0,0 +1,32 @@
package club.joylink.rtss.simulation.rt.ATS;
import club.joylink.rtss.simulation.rt.ATS.bo.AtsRepository;
import club.joylink.rtss.simulation.rt.ATS.bo.AtsTrain;
import org.springframework.stereotype.Component;
@Component
public class AtsTrainRouteService {
public void triggerRouteForTrain(AtsRepository atsRepository, AtsTrain atsTrain) {
if (atsTrain.isPlanTrain()) { // 计划车
this.triggerForPlanTrain(atsRepository, atsTrain);
} else if (atsTrain.isHeadTrain()) { // 头码车
this.triggerForHeadTrain(atsRepository, atsTrain);
}
}
private void triggerForPlanTrain(AtsRepository atsRepository, AtsTrain atsTrain) {
this.simpleTrigger(atsRepository, atsTrain);
}
private void simpleTrigger(AtsRepository atsRepository, AtsTrain atsTrain) {
if (atsTrain.getNextSectionId() == null) {
return;
}
}
private void triggerForHeadTrain(AtsRepository atsRepository, AtsTrain atsTrain) {
this.simpleTrigger(atsRepository, atsTrain);
}
}

View File

@ -3,11 +3,12 @@ package club.joylink.rtss.simulation.rt.ATS.bo;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.simulation.SimulationRepository; import club.joylink.rtss.simulation.SimulationRepository;
import club.joylink.rtss.simulation.cbtc.data.map.Station; import club.joylink.rtss.simulation.cbtc.data.map.Station;
import club.joylink.rtss.simulation.rt.ATS.bo.plan.AtsRunPlan;
import club.joylink.rtss.simulation.rt.ATS.bo.plan.AtsStationPlan;
import club.joylink.rtss.simulation.rt.ATS.bo.plan.AtsTripPlan;
import lombok.Getter; import lombok.Getter;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
@Getter @Getter
@ -15,10 +16,6 @@ public class AtsRepository extends SimulationRepository {
public static final String NAME = "ATS"; public static final String NAME = "ATS";
AtsRunPlan runPlan; AtsRunPlan runPlan;
// TODO: 2021/4/22 如果设备id有重复那不同类的设备的消息需要分开存
Map<String, List<Object>> messageMap = new HashMap<>();
Map<String, List<Object>> ready2SendMessageMap = new HashMap<>();
Map<String, AtsRoute> routeMap = new HashMap<>(); Map<String, AtsRoute> routeMap = new HashMap<>();
Map<String, AtsRunPlan> runPlanMap = new HashMap<>(); Map<String, AtsRunPlan> runPlanMap = new HashMap<>();
@ -69,22 +66,7 @@ public class AtsRepository extends SimulationRepository {
return atsRoute; return atsRoute;
} }
public void ready2Send(String id, int i, Object value) { public AtsTripPlan getTripPlanBy(String sn, String tn) {
List<Object> message = messageMap.get(id); return this.runPlan.getTripPlanBy(sn, tn);
if (message != null) {
message.set(i, value);
ready2SendMessageMap.putIfAbsent(id, message);
}
}
public List<List<Object>> removeReady2SendMessages() {
ArrayList<List<Object>> messages = new ArrayList<>(this.ready2SendMessageMap.values());
ready2SendMessageMap.clear();
return messages;
}
public List<List<Object>> getAllMessages() {
return new ArrayList<>(this.messageMap.values());
} }
} }

View File

@ -18,15 +18,14 @@ public class AtsRepositoryBuilder {
buildRoutes(logicDataNew.getRouteList(), atsRepository.routeMap); buildRoutes(logicDataNew.getRouteList(), atsRepository.routeMap);
buildSections(graphDataNew.getSectionList(), atsRepository.sectionMap); buildSections(graphDataNew.getSectionList(), atsRepository.sectionMap);
buildSignals(graphDataNew.getSignalList(), atsRepository.signalMap); buildSignals(graphDataNew.getSignalList(), atsRepository.signalMap);
buildSwitches(graphDataNew.getSwitchList(), atsRepository.switchMap, atsRepository.messageMap); buildSwitches(graphDataNew.getSwitchList(), atsRepository.switchMap);
return atsRepository; return atsRepository;
} }
private static void buildSwitches(List<MapSwitchVO> switchList, Map<String, AtsSwitch> switchMap, Map<String, List<Object>> messageMap) { private static void buildSwitches(List<MapSwitchVO> switchList, Map<String, AtsSwitch> switchMap) {
for (MapSwitchVO switchVO : switchList) { for (MapSwitchVO switchVO : switchList) {
AtsSwitch atsSwitch = new AtsSwitch(switchVO.getCode(), switchVO.getName()); AtsSwitch atsSwitch = new AtsSwitch(switchVO.getCode(), switchVO.getName());
switchMap.put(atsSwitch.getId(), atsSwitch); switchMap.put(atsSwitch.getId(), atsSwitch);
messageMap.put(atsSwitch.getId(), atsSwitch.buildMessage());
} }
} }

View File

@ -1,9 +1,35 @@
package club.joylink.rtss.simulation.rt.ATS.bo; package club.joylink.rtss.simulation.rt.ATS.bo;
import lombok.Getter;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
/**
* ATS监控列车
*/
@Getter
public class AtsTrain extends AtsDevice { public class AtsTrain extends AtsDevice {
int type; // 列车类型
public static final int TYPE_P = 1; // 计划车
public static final int TYPE_H = 2; // 头码车
public static final int TYPE_M = 3; // 人工车
int direction;
public static final int DIRECTION_N = 0; // 未知
public static final int DIRECTION_R = 1; //
public static final int DIRECTION_L = -1; //
String sectionId; // 轨道区段计轴区段或道岔区段
int offset; // 轨道区段偏移
String logicSectionId; // 逻辑区段逻辑区段或道岔计轴区段或岔心
String sn;// 服务号/表号
String tn;// 车次号/圈数
String dn;// 目的地号
String destSectionId; // 目的地区段id
String nextSectionId; // 下一目标区段id
List<String> routeList;//ats为此列车办理的进路
public AtsTrain(String id, String name) { public AtsTrain(String id, String name) {
super(id, name); super(id, name);
} }
@ -12,4 +38,12 @@ public class AtsTrain extends AtsDevice {
public List<Object> buildMessage() { public List<Object> buildMessage() {
return Arrays.asList(this.id); return Arrays.asList(this.id);
} }
public boolean isPlanTrain() {
return TYPE_P == this.type;
}
public boolean isHeadTrain() {
return TYPE_H == this.type;
}
} }

View File

@ -1,4 +1,4 @@
package club.joylink.rtss.simulation.rt.ATS.bo; package club.joylink.rtss.simulation.rt.ATS.bo.plan;
import lombok.Getter; import lombok.Getter;
@ -6,8 +6,8 @@ import java.time.LocalTime;
@Getter @Getter
public class AtsStationPlan { public class AtsStationPlan {
AtsStation station; String stationId;
AtsSection section; String sectionId;
LocalTime arriveTime;// 到站时间 LocalTime arriveTime;// 到站时间
LocalTime leaveTime;// 出发时间 LocalTime leaveTime;// 出发时间
int parkTime;// 停靠时长 int parkTime;// 停靠时长

View File

@ -1,6 +1,7 @@
package club.joylink.rtss.simulation.rt.ATS.bo; package club.joylink.rtss.simulation.rt.ATS.bo.plan;
import lombok.Getter; import lombok.Getter;
import org.springframework.util.StringUtils;
import java.time.LocalTime; import java.time.LocalTime;
import java.util.List; import java.util.List;
@ -13,12 +14,16 @@ public class AtsTripPlan {
boolean in;// 回库 boolean in;// 回库
boolean out;// 出库 boolean out;// 出库
boolean spare;// 备用 boolean spare;// 备用
AtsStation startStation; String startStationId;
AtsSection startSection; String startSectionId;
LocalTime startTime; LocalTime startTime;
AtsStation endStation; String endStationId;
AtsSection endSection; String endSectionId;
LocalTime endTime; LocalTime endTime;
List<AtsStationPlan> stationPlanList; List<AtsStationPlan> stationPlanList;
boolean depart; // 是否已经发车 boolean depart; // 是否已经发车
public static String buildSTNumber(String sn, String tn) {
return String.format("%s%s", StringUtils.hasText(sn)?sn:"", StringUtils.hasText(tn)?tn:"");
}
} }

View File

@ -16,7 +16,6 @@ import club.joylink.rtss.vo.client.map.MapVO;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Objects; import java.util.Objects;
@Component @Component
@ -58,8 +57,10 @@ public class RtSimulationService {
} }
private void initCreatorPlayMember(RtSimulation rtSimulation) { private void initCreatorPlayMember(RtSimulation rtSimulation) {
List<RtSimulationMember> memberList = rtSimulation.querySimulationMembersOfRole(RtSimulationMember.Role.LOWS); // RtSimulationMember simulationMember = rtSimulation.querySimulationMemberById("2");
this.simulationManager.memberPlayedByUser(rtSimulation.getId(), memberList.get(0).getId(), rtSimulation.getCreator().getId()); // List<RtSimulationMember> memberList = rtSimulation.querySimulationMembersOfRole(RtSimulationMember.Role.LOWS);
// 大铁暂时默认新绛站值班员
this.simulationManager.memberPlayedByUser(rtSimulation.getId(), "2", rtSimulation.getCreator().getId());
} }
private void initSimulationMember(RtSimulation rtSimulation) { private void initSimulationMember(RtSimulation rtSimulation) {

View File

@ -1,9 +1,9 @@
package club.joylink.rtss.simulation.rt; package club.joylink.rtss.simulation.rt;
import club.joylink.rtss.simulation.rt.ATS.bo.AtsRepository; import club.joylink.rtss.simulation.rt.ATS.bo.AtsRepository;
import club.joylink.rtss.simulation.rt.ATS.bo.AtsRunPlan; import club.joylink.rtss.simulation.rt.ATS.bo.plan.AtsRunPlan;
import club.joylink.rtss.simulation.rt.ATS.bo.AtsStationPlan; import club.joylink.rtss.simulation.rt.ATS.bo.plan.AtsStationPlan;
import club.joylink.rtss.simulation.rt.ATS.bo.AtsTripPlan; import club.joylink.rtss.simulation.rt.ATS.bo.plan.AtsTripPlan;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.time.LocalDateTime; import java.time.LocalDateTime;