From bb9d407a8e01823ad5927c4ac2d611d21b037b2c Mon Sep 17 00:00:00 2001 From: weizhihong Date: Fri, 28 Oct 2022 11:16:19 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E5=A2=9E=E5=8A=A0=E5=AE=9E=E8=AE=AD?= =?UTF-8?q?=E8=A7=92=E8=89=B2=E8=8E=B7=E5=8F=96=E8=A7=84=E5=88=99=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rtss/vo/training2/rule/MemberRule.java | 43 +++++++++++++++++++ .../rtss/vo/training2/rule/StepRule.java | 12 +++++- 2 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 src/main/java/club/joylink/rtss/vo/training2/rule/MemberRule.java 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)); }