武汉8号线列车位置显示功能
This commit is contained in:
parent
7065625895
commit
753c314292
@ -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.build.SimulationBuildParams;
|
||||||
import club.joylink.rtss.simulation.cbtc.data.map.Section;
|
import club.joylink.rtss.simulation.cbtc.data.map.Section;
|
||||||
import club.joylink.rtss.vo.ws.TrainPosition;
|
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 lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@ -14,10 +16,7 @@ import org.springframework.util.CollectionUtils;
|
|||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.Comparator;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -28,9 +27,9 @@ public class TrainPositionService {
|
|||||||
AtsTrainLoadService atsTrainLoadService;
|
AtsTrainLoadService atsTrainLoadService;
|
||||||
@Resource
|
@Resource
|
||||||
SimulationManager simulationManager;
|
SimulationManager simulationManager;
|
||||||
final Map<Section.SectionRoadType,List<Section>> map = new ConcurrentHashMap<>();
|
private final static Cache<Section.SectionRoadType,List<Section>> ROAD_TYPE_CACHE = CacheBuilder.newBuilder().build();
|
||||||
|
|
||||||
public void initTrainOrUpdate(String mapName,TrainPosition tp){
|
public void initTrainOrUpdate(String mapName,TrainPosition tp){
|
||||||
// this.simulationManager.getSimulationList().stream().filter(d->d.getb)
|
|
||||||
|
|
||||||
List<Simulation> simulationList = this.findSimulationList(mapName);
|
List<Simulation> simulationList = this.findSimulationList(mapName);
|
||||||
if(Objects.equals(true, CollectionUtils.isEmpty(simulationList))){
|
if(Objects.equals(true, CollectionUtils.isEmpty(simulationList))){
|
||||||
@ -38,21 +37,40 @@ public class TrainPositionService {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<Section> sectionList = findDirectionAllSection(simulationList.get(0),tp.getRoadType());
|
||||||
for (Simulation sim : simulationList) {
|
for (Simulation sim : simulationList) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void findSection(Simulation sim,TrainPosition tp,Section.SectionRoadType roadType){
|
private void findSecion(List<Section> sectionList,TrainPosition tp){
|
||||||
/* Section.SectionRoadType roadType = Section.SectionRoadType.LEFT;
|
int i = 0;
|
||||||
if(tp.getDirection() == 1){
|
Section findSection;
|
||||||
roadType = Section.SectionRoadType.RIGHT;
|
for (Section section : sectionList) {
|
||||||
}*/
|
if(tp.isRight()){
|
||||||
List<Section> list = sim.getRepository().getSectionList();
|
if(tp.getLocation() <= section.getKmMax()){
|
||||||
|
findSection = section;
|
||||||
list.stream().filter(d->d.getRoadType() == roadType).sorted((o1, o2) -> Integer.compare(1,2)).collect(Collectors.toList());
|
break;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static synchronized List<Section> findDirectionAllSection(Simulation sim,Section.SectionRoadType roadType){
|
||||||
|
List<Section> 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<Simulation> findSimulationList(String mapName){
|
private List<Simulation> findSimulationList(String mapName){
|
||||||
return this.simulationManager.getSimulationList().stream().filter(d->{
|
return this.simulationManager.getSimulationList().stream().filter(d->{
|
||||||
if(d instanceof Simulation){
|
if(d instanceof Simulation){
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package club.joylink.rtss.vo.ws;
|
package club.joylink.rtss.vo.ws;
|
||||||
|
|
||||||
|
import club.joylink.rtss.simulation.cbtc.data.map.Section;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
@ -7,6 +8,20 @@ import lombok.NoArgsConstructor;
|
|||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
public class TrainPosition {
|
public class TrainPosition {
|
||||||
private String trainTripNum;
|
private String trainTripNum;
|
||||||
|
/**
|
||||||
|
* 方向1=上行(向右),0=下行(向左)
|
||||||
|
*/
|
||||||
private int direction;
|
private int direction;
|
||||||
private float location;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user