【实现简单的提取规则(未对入参做校准处理)】

This commit is contained in:
weizhihong 2023-04-10 13:42:57 +08:00
parent d3bb96d95e
commit 1748f7c42d
5 changed files with 145 additions and 18 deletions

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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);
}

View File

@ -1,22 +1,100 @@
package club.joylink.rtss.simulation.cbtc.discriminate;
import club.joylink.rtss.simulation.cbtc.Simulation;
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 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 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 + "】车站");
}
},
ROUTE_NAME_EXTRACT("根据进路名称匹配进路") {
@Override
public Object matchParam(Simulation simulation, String... sourceStr) {
if (sourceStr == null || sourceStr.length == 0) {
throw new IllegalArgumentException("定位参数不缺失");
}
// 这里可能对XS做处理
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 + "】进路");
}
},
ROUTE_SIGNAL_EXTRACT("根据起始、终点信号机匹配进路") {
@Override
public Object matchParam(Simulation simulation, String... sourceStr) {
if (sourceStr == null || sourceStr.length < 2) {
throw new IllegalArgumentException("定位参数缺失");
}
String startSignalName = sourceStr[0], endSignalName = sourceStr[1];
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 + "】进路");
}
},
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);
}
},
;
/**
* 规则描述
*/
private String description;
ExtractRule(String description) {
this.description = description;
}
public abstract Object matchParam(Simulation simulation, String... sourceStr);
}

View File

@ -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);
}