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();
|
MemberRule memberRule = operateRule.getMemberRule();
|
||||||
if (memberRule != null) {
|
if (memberRule != null) {
|
||||||
List<String> groupList = result.getMatchGroupList();
|
|
||||||
List<SimulationMember> simulationMemberList = null;
|
List<SimulationMember> simulationMemberList = null;
|
||||||
if (memberRule.getIndex() == null) {
|
if (memberRule.getIndex() == null) {
|
||||||
simulationMemberList = memberRule.getParseRule().matchMember(simulation, null);
|
simulationMemberList = memberRule.getParseRule().matchMember(simulation, null);
|
||||||
} else if (memberRule.getIndex() < paramExtractResults.size()) {
|
} 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 {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -53,12 +53,11 @@ public class ReplyParseServiceImpl implements VoiceTransactionalService {
|
|||||||
// 匹配回复人员
|
// 匹配回复人员
|
||||||
MemberRule memberRule = replyRule.getMemberRule();
|
MemberRule memberRule = replyRule.getMemberRule();
|
||||||
if (memberRule != null) {
|
if (memberRule != null) {
|
||||||
List<String> groupList = result.getMatchGroupList();
|
|
||||||
List<SimulationMember> simulationMemberList = null;
|
List<SimulationMember> simulationMemberList = null;
|
||||||
if (memberRule.getIndex() == null) {
|
if (memberRule.getIndex() == null) {
|
||||||
simulationMemberList = memberRule.getParseRule().matchMember(simulation, null);
|
simulationMemberList = memberRule.getParseRule().matchMember(simulation, null);
|
||||||
} else if (memberRule.getIndex() < paramExtractResults.size()) {
|
} 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 {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package club.joylink.rtss.simulation.cbtc.discriminate;
|
package club.joylink.rtss.simulation.cbtc.discriminate;
|
||||||
|
|
||||||
import club.joylink.rtss.simulation.cbtc.Simulation;
|
import club.joylink.rtss.simulation.cbtc.Simulation;
|
||||||
|
import club.joylink.rtss.simulation.cbtc.data.map.MapElement;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -9,13 +10,35 @@ import lombok.Getter;
|
|||||||
@Getter
|
@Getter
|
||||||
public enum CommandParamParseRule {
|
public enum CommandParamParseRule {
|
||||||
|
|
||||||
STATION_NAME {
|
MAP_ELEMENT_CODE("获取地图元素Code") {
|
||||||
@Override
|
@Override
|
||||||
public Object extractParam(Simulation simulation, ParamExtractResult... extractResult) {
|
public Object extractParam(Simulation simulation, ParamExtractResult... extractResults) {
|
||||||
|
if (extractResults == null || extractResults.length ==0) {
|
||||||
return null;
|
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.PinYinUtil;
|
||||||
import club.joylink.rtss.util.StrUtils;
|
import club.joylink.rtss.util.StrUtils;
|
||||||
import com.google.common.collect.Maps;
|
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 lombok.Getter;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.commons.text.similarity.JaroWinklerSimilarity;
|
import org.apache.commons.text.similarity.JaroWinklerSimilarity;
|
||||||
@ -13,68 +16,95 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 参数的提取规则
|
* 参数的提取规则
|
||||||
*/
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
public enum ExtractRule {
|
public enum ExtractRule {
|
||||||
|
|
||||||
//车站名称
|
STATION_NAME_EXTRACT("根据车站名称匹配车站") {
|
||||||
STATION_NAME {
|
|
||||||
@Override
|
@Override
|
||||||
public Object matchParam(Simulation simulation, String... sourceStr) {
|
public Object matchParam(Simulation simulation, String... sourceStr) {
|
||||||
return ExtractRule.findDevice(simulation, MapElement.DeviceType.STATION, Station.class,sourceStr[0]);
|
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())))
|
||||||
SWITCH_NAME{
|
.findFirst();
|
||||||
@Override
|
if (stationOptional.isPresent()) {
|
||||||
public Object matchParam(Simulation simulation, String... sourceStr) {
|
return stationOptional.get();
|
||||||
return ExtractRule.findDevice(simulation, MapElement.DeviceType.SWITCH, Switch.class,sourceStr[0]);
|
}
|
||||||
|
throw new IllegalArgumentException("未找到【" + stationName + "】车站");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
//上下行
|
ROUTE_NAME_EXTRACT("根据进路名称匹配进路") {
|
||||||
UP_DOWN_WAY {
|
|
||||||
@Override
|
@Override
|
||||||
public Object matchParam(Simulation simulation, String... sourceStr) {
|
public Object matchParam(Simulation simulation, String... sourceStr) {
|
||||||
if(StringUtils.containsAnyIgnoreCase(sourceStr[0],"shangxing","shang")){
|
if (sourceStr == null || sourceStr.length == 0) {
|
||||||
return true;
|
throw new IllegalArgumentException("定位参数不缺失");
|
||||||
}else if(StringUtils.containsAnyIgnoreCase(sourceStr[0],"xiaxing","xia")){
|
}
|
||||||
|
// 这里可能对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 + "】进路");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
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 false;
|
||||||
}else{
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
return Objects.equals(startSignalName, route.getStart().getShowName())
|
||||||
|
|| Objects.equals(endSignalName, route.getDestination().getShowName());
|
||||||
|
}).findFirst();
|
||||||
|
if (routeOptional.isPresent()) {
|
||||||
|
return routeOptional.get();
|
||||||
}
|
}
|
||||||
},SIGNAL_NAME{
|
throw new IllegalArgumentException("未找到【" + startSignalName + "-" + endSignalName + "】进路");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
STAND_STATION_UP_DOWN_EXTRACT("根据车站、上下行匹配站台") {
|
||||||
@Override
|
@Override
|
||||||
public Object matchParam(Simulation simulation, String... sourceStr) {
|
public Object matchParam(Simulation simulation, String... sourceStr) {
|
||||||
return ExtractRule.findDevice(simulation, MapElement.DeviceType.SIGNAL, Signal.class,sourceStr[0]);
|
if (sourceStr == null || sourceStr.length < 2) {
|
||||||
|
throw new IllegalArgumentException("定位参数缺失");
|
||||||
}
|
}
|
||||||
},STAND_NAME{
|
String stationName = sourceStr[0], upDown = sourceStr[1];
|
||||||
@Override
|
Station station = (Station) STATION_NAME_EXTRACT.matchParam(simulation, stationName);
|
||||||
public Object matchParam(Simulation simulation, String... sourceStr) {
|
boolean right = "SHANG".equals(upDown);
|
||||||
return null;
|
return station.getStandOf(right);
|
||||||
}
|
}
|
||||||
};
|
},
|
||||||
|
;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 规则描述
|
||||||
|
*/
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
ExtractRule(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
public abstract Object matchParam(Simulation simulation, String... sourceStr);
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,23 +1,51 @@
|
|||||||
package club.joylink.rtss.simulation.cbtc.discriminate;
|
package club.joylink.rtss.simulation.cbtc.discriminate;
|
||||||
|
|
||||||
import club.joylink.rtss.simulation.cbtc.Simulation;
|
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 club.joylink.rtss.simulation.cbtc.member.SimulationMember;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 人员匹配规则
|
* 人员匹配规则
|
||||||
*/
|
*/
|
||||||
public enum MemberParseRule {
|
public enum MemberParseRule {
|
||||||
|
|
||||||
STATION_SUPERVISOR {
|
STATION_SUPERVISOR("获取指定车站值班员") {
|
||||||
@Override
|
@Override
|
||||||
public List<SimulationMember> matchMember(Simulation simulation, String sourceStr) {
|
public List<SimulationMember> matchMember(Simulation simulation, ParamExtractResult extractResult) {
|
||||||
return null;
|
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