Merge remote-tracking branch 'origin/test-training2' into test-training2
# Conflicts: # src/main/java/club/joylink/rtss/simulation/cbtc/discriminate/ExtractRule.java
This commit is contained in:
commit
c7e13aebe9
@ -66,12 +66,11 @@ public class OperateParseServiceImpl implements VoiceTransactionalService {
|
||||
// 成员解析
|
||||
MemberRule memberRule = operateRule.getMemberRule();
|
||||
if (memberRule != null) {
|
||||
List<String> groupList = result.getMatchGroupList();
|
||||
List<SimulationMember> simulationMemberList = null;
|
||||
if (memberRule.getIndex() == null) {
|
||||
simulationMemberList = memberRule.getParseRule().matchMember(simulation, null);
|
||||
} else if (memberRule.getIndex() < paramExtractResults.size()) {
|
||||
simulationMemberList = memberRule.getParseRule().matchMember(simulation, groupList.get(memberRule.getIndex()));
|
||||
simulationMemberList = memberRule.getParseRule().matchMember(simulation, paramExtractResults.get(memberRule.getIndex()));
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
@ -53,12 +53,11 @@ public class ReplyParseServiceImpl implements VoiceTransactionalService {
|
||||
// 匹配回复人员
|
||||
MemberRule memberRule = replyRule.getMemberRule();
|
||||
if (memberRule != null) {
|
||||
List<String> groupList = result.getMatchGroupList();
|
||||
List<SimulationMember> simulationMemberList = null;
|
||||
if (memberRule.getIndex() == null) {
|
||||
simulationMemberList = memberRule.getParseRule().matchMember(simulation, null);
|
||||
} else if (memberRule.getIndex() < paramExtractResults.size()) {
|
||||
simulationMemberList = memberRule.getParseRule().matchMember(simulation, groupList.get(memberRule.getIndex()));
|
||||
simulationMemberList = memberRule.getParseRule().matchMember(simulation, paramExtractResults.get(memberRule.getIndex()));
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package club.joylink.rtss.simulation.cbtc.discriminate;
|
||||
|
||||
import club.joylink.rtss.simulation.cbtc.Simulation;
|
||||
import club.joylink.rtss.simulation.cbtc.data.map.MapElement;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
@ -9,13 +10,35 @@ import lombok.Getter;
|
||||
@Getter
|
||||
public enum CommandParamParseRule {
|
||||
|
||||
STATION_NAME {
|
||||
MAP_ELEMENT_CODE("获取地图元素Code") {
|
||||
@Override
|
||||
public Object extractParam(Simulation simulation, ParamExtractResult... extractResult) {
|
||||
|
||||
return null;
|
||||
public Object extractParam(Simulation simulation, ParamExtractResult... extractResults) {
|
||||
if (extractResults == null || extractResults.length ==0) {
|
||||
throw new IllegalArgumentException("执行方法参数为空");
|
||||
}
|
||||
ParamExtractResult paramResult = extractResults[0];
|
||||
if (paramResult.getValue() instanceof MapElement) {
|
||||
return ((MapElement) paramResult.getValue()).getCode();
|
||||
}
|
||||
throw new IllegalArgumentException("参数类型【MAP_ELEMENT_CODE】不匹配");
|
||||
}
|
||||
};
|
||||
},
|
||||
PARAM_VALUE("获取参数值") { // 像限速、上下行等已经处理后的参数可直接使用
|
||||
@Override
|
||||
public Object extractParam(Simulation simulation, ParamExtractResult... extractResults) {
|
||||
if (extractResults == null || extractResults.length ==0) {
|
||||
throw new IllegalArgumentException("执行方法参数为空");
|
||||
}
|
||||
return extractResults[0].getValue();
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
public abstract Object extractParam(Simulation simulation, ParamExtractResult... extractResult);
|
||||
private String description;
|
||||
|
||||
CommandParamParseRule(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public abstract Object extractParam(Simulation simulation, ParamExtractResult... extractResults);
|
||||
}
|
@ -5,6 +5,9 @@ import club.joylink.rtss.simulation.cbtc.data.map.*;
|
||||
import club.joylink.rtss.util.PinYinUtil;
|
||||
import club.joylink.rtss.util.StrUtils;
|
||||
import com.google.common.collect.Maps;
|
||||
import club.joylink.rtss.simulation.cbtc.data.map.Route;
|
||||
import club.joylink.rtss.simulation.cbtc.data.map.Station;
|
||||
import club.joylink.rtss.util.PinYinUtil;
|
||||
import lombok.Getter;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.text.similarity.JaroWinklerSimilarity;
|
||||
@ -13,68 +16,95 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* 参数的提取规则
|
||||
*/
|
||||
@Getter
|
||||
public enum ExtractRule {
|
||||
|
||||
//车站名称
|
||||
STATION_NAME {
|
||||
STATION_NAME_EXTRACT("根据车站名称匹配车站") {
|
||||
@Override
|
||||
public Object matchParam(Simulation simulation, String... sourceStr) {
|
||||
return ExtractRule.findDevice(simulation, MapElement.DeviceType.STATION, Station.class,sourceStr[0]);
|
||||
}
|
||||
|
||||
},
|
||||
// 道岔名称
|
||||
SWITCH_NAME{
|
||||
@Override
|
||||
public Object matchParam(Simulation simulation, String... sourceStr) {
|
||||
return ExtractRule.findDevice(simulation, MapElement.DeviceType.SWITCH, Switch.class,sourceStr[0]);
|
||||
}
|
||||
},
|
||||
//上下行
|
||||
UP_DOWN_WAY {
|
||||
@Override
|
||||
public Object matchParam(Simulation simulation, String... sourceStr) {
|
||||
if(StringUtils.containsAnyIgnoreCase(sourceStr[0],"shangxing","shang")){
|
||||
return true;
|
||||
}else if(StringUtils.containsAnyIgnoreCase(sourceStr[0],"xiaxing","xia")){
|
||||
return false;
|
||||
}else{
|
||||
return null;
|
||||
if (sourceStr == null || sourceStr.length == 0) {
|
||||
throw new IllegalArgumentException("定位参数不缺失");
|
||||
}
|
||||
// 这里可能需要做对入参做一些处理
|
||||
String stationName = sourceStr[0];
|
||||
|
||||
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 + "】车站");
|
||||
}
|
||||
},SIGNAL_NAME{
|
||||
},
|
||||
ROUTE_NAME_EXTRACT("根据进路名称匹配进路") {
|
||||
@Override
|
||||
public Object matchParam(Simulation simulation, String... sourceStr) {
|
||||
return ExtractRule.findDevice(simulation, MapElement.DeviceType.SIGNAL, Signal.class,sourceStr[0]);
|
||||
if (sourceStr == null || sourceStr.length == 0) {
|
||||
throw new IllegalArgumentException("定位参数不缺失");
|
||||
}
|
||||
// 这里可能对X、S做处理
|
||||
String routeName = sourceStr[0];
|
||||
|
||||
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 + "】进路");
|
||||
}
|
||||
},STAND_NAME{
|
||||
},
|
||||
ROUTE_SIGNAL_EXTRACT("根据起始、终点信号机匹配进路") {
|
||||
@Override
|
||||
public Object matchParam(Simulation simulation, String... sourceStr) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
if (sourceStr == null || sourceStr.length < 2) {
|
||||
throw new IllegalArgumentException("定位参数缺失");
|
||||
}
|
||||
String startSignalName = sourceStr[0], endSignalName = sourceStr[1];
|
||||
|
||||
|
||||
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);
|
||||
Optional<Route> routeOptional = simulation.getRepository().getRouteList().stream()
|
||||
.filter(route -> {
|
||||
if (route.getStart() == null || route.getDestination() == null) {
|
||||
return false;
|
||||
}
|
||||
return Objects.equals(startSignalName, route.getStart().getShowName())
|
||||
|| Objects.equals(endSignalName, route.getDestination().getShowName());
|
||||
}).findFirst();
|
||||
if (routeOptional.isPresent()) {
|
||||
return routeOptional.get();
|
||||
}
|
||||
throw new IllegalArgumentException("未找到【" + startSignalName + "-" + endSignalName + "】进路");
|
||||
}
|
||||
Double d = elementMap.keySet().stream().mapToDouble(k->k).max().orElse(0D);
|
||||
MapNamedElement nameEle = elementMap.get(d);
|
||||
if(Objects.isNull(nameEle)){
|
||||
return null;
|
||||
},
|
||||
STAND_STATION_UP_DOWN_EXTRACT("根据车站、上下行匹配站台") {
|
||||
@Override
|
||||
public Object matchParam(Simulation simulation, String... sourceStr) {
|
||||
if (sourceStr == null || sourceStr.length < 2) {
|
||||
throw new IllegalArgumentException("定位参数缺失");
|
||||
}
|
||||
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);
|
||||
}
|
||||
return nameEle;
|
||||
},
|
||||
;
|
||||
|
||||
/**
|
||||
* 规则描述
|
||||
*/
|
||||
private String description;
|
||||
|
||||
ExtractRule(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public abstract Object matchParam(Simulation simulation, String... sourceStr);
|
||||
}
|
||||
|
@ -1,23 +1,51 @@
|
||||
package club.joylink.rtss.simulation.cbtc.discriminate;
|
||||
|
||||
import club.joylink.rtss.simulation.cbtc.Simulation;
|
||||
import club.joylink.rtss.simulation.cbtc.data.map.MapElement;
|
||||
import club.joylink.rtss.simulation.cbtc.data.map.Station;
|
||||
import club.joylink.rtss.simulation.cbtc.member.SimulationMember;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 人员匹配规则
|
||||
*/
|
||||
public enum MemberParseRule {
|
||||
|
||||
STATION_SUPERVISOR {
|
||||
STATION_SUPERVISOR("获取指定车站值班员") {
|
||||
@Override
|
||||
public List<SimulationMember> matchMember(Simulation simulation, String sourceStr) {
|
||||
return null;
|
||||
public List<SimulationMember> matchMember(Simulation simulation, ParamExtractResult extractResult) {
|
||||
if (extractResult != null && (extractResult.getValue() instanceof Station)) {
|
||||
throw new IllegalArgumentException("人员匹配入参为空");
|
||||
}
|
||||
SimulationMember member =
|
||||
simulation.getSimulationMember((MapElement) extractResult.getValue(), SimulationMember.Type.STATION_SUPERVISOR);
|
||||
return Arrays.asList(member);
|
||||
}
|
||||
},
|
||||
ALL_STATION_SUPERVISOR("全体车站值班员") {
|
||||
@Override
|
||||
public List<SimulationMember> matchMember(Simulation simulation, ParamExtractResult extractResult) {
|
||||
List<SimulationMember> simulationMemberList = simulation.getSimulationMembers().stream()
|
||||
.filter(simulationMember -> Objects.equals(SimulationMember.Type.STATION_SUPERVISOR, simulationMember.getType()))
|
||||
.collect(Collectors.toList());
|
||||
return simulationMemberList;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 规则描述
|
||||
*/
|
||||
private String description;
|
||||
|
||||
public abstract List<SimulationMember> matchMember(Simulation simulation, String sourceStr);
|
||||
MemberParseRule(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public abstract List<SimulationMember> matchMember(Simulation simulation, ParamExtractResult extractResult);
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user