合并
This commit is contained in:
parent
c7e13aebe9
commit
c46b4fd97c
@ -11,6 +11,7 @@ import club.joylink.rtss.util.PinYinUtil;
|
||||
import lombok.Getter;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.text.similarity.JaroWinklerSimilarity;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -31,16 +32,18 @@ public enum ExtractRule {
|
||||
if (sourceStr == null || sourceStr.length == 0) {
|
||||
throw new IllegalArgumentException("定位参数不缺失");
|
||||
}
|
||||
|
||||
// 这里可能需要做对入参做一些处理
|
||||
String stationName = sourceStr[0];
|
||||
return findDevice(simulation, MapElement.DeviceType.STATION,Station.class,stationName);
|
||||
|
||||
Optional<Station> stationOptional = simulation.getRepository().getStationList().stream()
|
||||
/* Optional<Station> stationOptional = simulation.getRepository().getStationList().stream()
|
||||
.filter(station -> Objects.equals(stationName, PinYinUtil.toPinYin(station.getName())))
|
||||
.findFirst();
|
||||
if (stationOptional.isPresent()) {
|
||||
return stationOptional.get();
|
||||
}
|
||||
throw new IllegalArgumentException("未找到【" + stationName + "】车站");
|
||||
throw new IllegalArgumentException("未找到【" + stationName + "】车站");*/
|
||||
}
|
||||
},
|
||||
ROUTE_NAME_EXTRACT("根据进路名称匹配进路") {
|
||||
@ -51,14 +54,14 @@ public enum ExtractRule {
|
||||
}
|
||||
// 这里可能对X、S做处理
|
||||
String routeName = sourceStr[0];
|
||||
|
||||
Optional<Route> routeOptional = simulation.getRepository().getRouteList().stream()
|
||||
return findDevice(simulation, MapElement.DeviceType.ROUTE,Route.class,routeName);
|
||||
/* Optional<Route> routeOptional = simulation.getRepository().getRouteList().stream()
|
||||
.filter(route -> Objects.equals(route.getName(), routeName))
|
||||
.findFirst();
|
||||
if (routeOptional.isPresent()) {
|
||||
return routeOptional.get();
|
||||
}
|
||||
throw new IllegalArgumentException("未找到【" + routeName + "】进路");
|
||||
throw new IllegalArgumentException("未找到【" + routeName + "】进路");*/
|
||||
}
|
||||
},
|
||||
ROUTE_SIGNAL_EXTRACT("根据起始、终点信号机匹配进路") {
|
||||
@ -91,8 +94,24 @@ public enum ExtractRule {
|
||||
}
|
||||
String stationName = sourceStr[0], upDown = sourceStr[1];
|
||||
Station station = (Station) STATION_NAME_EXTRACT.matchParam(simulation, stationName);
|
||||
boolean right = "SHANG".equals(upDown);
|
||||
return station.getStandOf(right);
|
||||
Boolean right = (Boolean) UP_DOWN_WAY.matchParam(simulation,upDown);
|
||||
List<Stand> stands = station.getStandOf(right);
|
||||
if(CollectionUtils.isEmpty(stands)){
|
||||
throw new IllegalArgumentException(String.format("不能获取对应的站台 车站[%s-%s],上下行[%s-%s]",stationName,station.getCode(),upDown,right));
|
||||
}
|
||||
return station.getStandOf(right).get(0);
|
||||
|
||||
}
|
||||
},UP_DOWN_WAY("车辆上下行"){
|
||||
@Override
|
||||
public Object matchParam(Simulation simulation, String... sourceStr) {
|
||||
String way = sourceStr[0];
|
||||
if(StringUtils.containsAnyIgnoreCase(way,"shang")){
|
||||
return true;
|
||||
}else if(StringUtils.containsAnyIgnoreCase(way,"xia")){
|
||||
return false;
|
||||
}
|
||||
throw new IllegalArgumentException(String.format("不能解析上下行[%s]",way));
|
||||
}
|
||||
},
|
||||
;
|
||||
@ -107,4 +126,20 @@ public enum ExtractRule {
|
||||
}
|
||||
|
||||
public abstract Object matchParam(Simulation simulation, String... sourceStr);
|
||||
|
||||
private static MapNamedElement findDevice(Simulation simulation, MapElement.DeviceType dt, Class<? extends MapNamedElement> eleClass,String matchVal){
|
||||
List<? extends MapNamedElement> eleList = simulation.getRepository().getListByType(dt,eleClass);
|
||||
Map<Double,MapNamedElement> elementMap = Maps.newHashMap();
|
||||
for (MapNamedElement ele : eleList) {
|
||||
String namePinYin = PinYinUtil.toPinYin(ele.getName());
|
||||
double ratio = StrUtils.getJaroWinklerSimilarityRatio(namePinYin,matchVal);
|
||||
elementMap.put(ratio,ele);
|
||||
}
|
||||
Double d = elementMap.keySet().stream().mapToDouble(k->k).max().orElse(0D);
|
||||
MapNamedElement nameEle = elementMap.get(d);
|
||||
if(Objects.isNull(nameEle)){
|
||||
return null;
|
||||
}
|
||||
return nameEle;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user