diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/TrainPositionService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/TrainPositionService.java index f0d900c13..ef2cdafe4 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/TrainPositionService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/TrainPositionService.java @@ -7,6 +7,8 @@ import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.build.SimulationBuildParams; import club.joylink.rtss.simulation.cbtc.data.map.Section; import club.joylink.rtss.vo.ws.TrainPosition; +import com.google.common.cache.Cache; +import com.google.common.cache.CacheBuilder; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; import org.springframework.stereotype.Service; @@ -14,10 +16,7 @@ import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; import javax.annotation.Resource; -import java.util.Comparator; -import java.util.List; -import java.util.Map; -import java.util.Objects; +import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; @@ -28,9 +27,9 @@ public class TrainPositionService { AtsTrainLoadService atsTrainLoadService; @Resource SimulationManager simulationManager; - final Map> map = new ConcurrentHashMap<>(); + private final static Cache> ROAD_TYPE_CACHE = CacheBuilder.newBuilder().build(); + public void initTrainOrUpdate(String mapName,TrainPosition tp){ -// this.simulationManager.getSimulationList().stream().filter(d->d.getb) List simulationList = this.findSimulationList(mapName); if(Objects.equals(true, CollectionUtils.isEmpty(simulationList))){ @@ -38,21 +37,40 @@ public class TrainPositionService { return; } + List
sectionList = findDirectionAllSection(simulationList.get(0),tp.getRoadType()); for (Simulation sim : simulationList) { } } - private void findSection(Simulation sim,TrainPosition tp,Section.SectionRoadType roadType){ - /* Section.SectionRoadType roadType = Section.SectionRoadType.LEFT; - if(tp.getDirection() == 1){ - roadType = Section.SectionRoadType.RIGHT; - }*/ - List
list = sim.getRepository().getSectionList(); - - list.stream().filter(d->d.getRoadType() == roadType).sorted((o1, o2) -> Integer.compare(1,2)).collect(Collectors.toList()); + private void findSecion(List
sectionList,TrainPosition tp){ + int i = 0; + Section findSection; + for (Section section : sectionList) { + if(tp.isRight()){ + if(tp.getLocation() <= section.getKmMax()){ + findSection = section; + break; + } + }else{ + } + i++; + } } + + + private static synchronized List
findDirectionAllSection(Simulation sim,Section.SectionRoadType roadType){ + List
list = ROAD_TYPE_CACHE.getIfPresent(roadType); + if(Objects.equals(true,CollectionUtils.isEmpty(list))){ + list = sim.getRepository().getSectionList(); + list = list.stream().filter(d->d.getRoadType() == roadType) + .sorted(Comparator.comparing(Section::getKmMin)/*.reversed()*/).collect(Collectors.toList()); + ROAD_TYPE_CACHE.put(roadType,list); + } + return list; + } + private List findSimulationList(String mapName){ return this.simulationManager.getSimulationList().stream().filter(d->{ if(d instanceof Simulation){ diff --git a/src/main/java/club/joylink/rtss/vo/ws/TrainPosition.java b/src/main/java/club/joylink/rtss/vo/ws/TrainPosition.java index 32d053f17..a9d5e8c5a 100644 --- a/src/main/java/club/joylink/rtss/vo/ws/TrainPosition.java +++ b/src/main/java/club/joylink/rtss/vo/ws/TrainPosition.java @@ -1,5 +1,6 @@ package club.joylink.rtss.vo.ws; +import club.joylink.rtss.simulation.cbtc.data.map.Section; import lombok.Data; import lombok.NoArgsConstructor; @@ -7,6 +8,20 @@ import lombok.NoArgsConstructor; @NoArgsConstructor public class TrainPosition { private String trainTripNum; + /** + * 方向1=上行(向右),0=下行(向左) + */ private int direction; private float location; + + public Section.SectionRoadType getRoadType(){ + Section.SectionRoadType type = Section.SectionRoadType.LEFT; + if(this.direction == 1){ + return Section.SectionRoadType.RIGHT; + } + return type; + } + public boolean isRight(){ + return this.direction == 1; + } }