diff --git a/src/main/java/club/joylink/rtss/vo/training2/rule/MemberRule.java b/src/main/java/club/joylink/rtss/vo/training2/rule/MemberRule.java new file mode 100644 index 000000000..678a3af8d --- /dev/null +++ b/src/main/java/club/joylink/rtss/vo/training2/rule/MemberRule.java @@ -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 memberList = simulation.getMemberListByType(type); + if (deviceCodeRule == null) { + return memberList.get(0); + } + /** + * 所属设备编码 + */ + String code = deviceCodeRule.resolve(simulation, mapElement); + List 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); + } +} diff --git a/src/main/java/club/joylink/rtss/vo/training2/rule/StepRule.java b/src/main/java/club/joylink/rtss/vo/training2/rule/StepRule.java index 9430d52db..6dbeac1ef 100644 --- a/src/main/java/club/joylink/rtss/vo/training2/rule/StepRule.java +++ b/src/main/java/club/joylink/rtss/vo/training2/rule/StepRule.java @@ -1,6 +1,9 @@ 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 club.joylink.rtss.vo.client.training2.ExpressionVO; import club.joylink.rtss.vo.client.training2.Operation2VO; import club.joylink.rtss.vo.client.training2.Step2VO; @@ -18,7 +21,7 @@ public class StepRule { private Integer id; - private String memberId; + private MemberRule memberRule; private String description; @@ -36,7 +39,12 @@ public class StepRule { public Step2VO convert2BO(Simulation simulation, Object mapElement) { 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) { // 描述 copyStep2.setDescription(PropertyValueRule.resolveContentFormat(description, simulation, mapElement)); }