public List<List<String>> getAllSubwayStations() {
// 创建一个用于存储站点的 Map
Map<Integer, List<String>> subwayStationsMap = new HashMap<>();
// 查询数据库中所有的站点,并按照站点 ID 从小到大排序
List<Station> allStations = stationService.list();
Collections.sort(allStations, Comparator.comparing(Station::getStationID));
// 遍历所有的站点,按照地铁线路号将站点添加到相应的列表中
for (Station station : allStations) {
Integer lineNumber = station.getLineNumber();
String stationName = station.getStationName();
List<String> stationList = subwayStationsMap.getOrDefault(lineNumber, new ArrayList<>());
stationList.add(stationName);
subwayStationsMap.put(lineNumber, stationList);
}
// 将所有线路的站点列表放入一个 List<List<String>> 中,并按照地铁线路号进行排序
List<List<String>> allSubwayStations = new ArrayList<>();
for (Map.Entry<Integer, List<String>> entry : subwayStationsMap.entrySet()) {
allSubwayStations.add(entry.getValue());
}
return allSubwayStations;
}
@PostMapping("getstation")标签:站点,String,地铁,List,查询,allSubwayStations,station,new From: https://www.cnblogs.com/hbro/p/18142013
public Result getStation(@RequestBody QueryParam query){
HashMap param = query.getParam();
String startStation = (String) param.get("startStation");
String endStation = (String) param.get("endStation");
System.out.println(startStation);
System.out.println(endStation);
List<List<String>> allSubwayStations = getAllSubwayStations();
Subway subway = new Subway();
List<String> stationsBetween = subway.getStationsBetween(startStation,endStation, allSubwayStations);
List<Station> stations = new ArrayList<>();
for(String s : stationsBetween){
LambdaQueryWrapper<Station> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(Station::getStationName,s);
List<Station> station = stationService.list(lambdaQueryWrapper);
stations.add(station.get(0));
}
System.out.println("Stations between A and G: " + stationsBetween);
return Result.suc(stations);
}