【增加实训角色获取规则】

This commit is contained in:
weizhihong 2022-10-28 11:16:19 +08:00
parent 6561c722c0
commit bb9d407a8e
2 changed files with 53 additions and 2 deletions

View File

@ -0,0 +1,43 @@
package club.joylink.rtss.vo.training2.rule;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.exception.SimulationException;
import club.joylink.rtss.simulation.cbtc.exception.SimulationExceptionType;
import club.joylink.rtss.simulation.cbtc.member.SimulationMember;
import org.springframework.util.CollectionUtils;
import java.util.List;
import java.util.stream.Collectors;
/**
* 筛选人员规则
*/
public class MemberRule {
/**
* 人员类型
*/
private SimulationMember.Type type;
/**
* 所属设备编码规则
*/
private PropertyValueRule deviceCodeRule;
public SimulationMember convert2BO(Simulation simulation, Object mapElement) {
List<SimulationMember> memberList = simulation.getMemberListByType(type);
if (deviceCodeRule == null) {
return memberList.get(0);
}
/**
* 所属设备编码
*/
String code = deviceCodeRule.resolve(simulation, mapElement);
List<SimulationMember> resultMemberList = memberList.stream().filter(member -> member.getDevice() != null
&& member.getDevice().getCode().equals(code)).collect(Collectors.toList());
if (CollectionUtils.isEmpty(resultMemberList)) {
throw new SimulationException(SimulationExceptionType.Illegal_Argument, String.format("未找到角色为[%s]的成员", type));
}
return resultMemberList.get(0);
}
}

View File

@ -1,6 +1,9 @@
package club.joylink.rtss.vo.training2.rule; package club.joylink.rtss.vo.training2.rule;
import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.exception.SimulationException;
import club.joylink.rtss.simulation.cbtc.exception.SimulationExceptionType;
import club.joylink.rtss.simulation.cbtc.member.SimulationMember;
import club.joylink.rtss.vo.client.training2.ExpressionVO; import club.joylink.rtss.vo.client.training2.ExpressionVO;
import club.joylink.rtss.vo.client.training2.Operation2VO; import club.joylink.rtss.vo.client.training2.Operation2VO;
import club.joylink.rtss.vo.client.training2.Step2VO; import club.joylink.rtss.vo.client.training2.Step2VO;
@ -18,7 +21,7 @@ public class StepRule {
private Integer id; private Integer id;
private String memberId; private MemberRule memberRule;
private String description; private String description;
@ -36,7 +39,12 @@ public class StepRule {
public Step2VO convert2BO(Simulation simulation, Object mapElement) { public Step2VO convert2BO(Simulation simulation, Object mapElement) {
Step2VO copyStep2 = new Step2VO(); Step2VO copyStep2 = new Step2VO();
copyStep2.setMemberId(memberId); if (memberRule != null) {
SimulationMember member = memberRule.convert2BO(simulation, mapElement);
copyStep2.setMemberId(member.getId());
} else {
throw new SimulationException(SimulationExceptionType.Illegal_Argument, String.format("未找到角色的成员"));
}
if (description != null) { // 描述 if (description != null) { // 描述
copyStep2.setDescription(PropertyValueRule.resolveContentFormat(description, simulation, mapElement)); copyStep2.setDescription(PropertyValueRule.resolveContentFormat(description, simulation, mapElement));
} }