From cc7d57a511bc171dfa4a3f7ab6660eb5e14523bf Mon Sep 17 00:00:00 2001 From: weizhihong Date: Wed, 7 Sep 2022 10:28:19 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E3=80=90=E6=8C=87=E6=A0=87=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=E5=AF=B9=E5=BA=94=EF=BC=8C=E5=88=9B=E5=BB=BA=E6=8C=87?= =?UTF-8?q?=E6=A0=87=E6=93=8D=E4=BD=9C=E7=B1=BB=EF=BC=8C=E6=8C=87=E6=A0=87?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E7=B1=BB=E5=9E=8B=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../services/training2/Training2Service.java | 7 ++++--- .../index/IndexAlgorithmService.java | 4 ++-- .../index/impl/IndexAlgorithmTestService.java | 2 +- .../simulation/cbtc/training2/Training2.java | 12 +++--------- .../cbtc/training2/index/Index.java | 19 +++++++++---------- 5 files changed, 19 insertions(+), 25 deletions(-) diff --git a/src/main/java/club/joylink/rtss/services/training2/Training2Service.java b/src/main/java/club/joylink/rtss/services/training2/Training2Service.java index 41fadd74a..45e810344 100644 --- a/src/main/java/club/joylink/rtss/services/training2/Training2Service.java +++ b/src/main/java/club/joylink/rtss/services/training2/Training2Service.java @@ -367,7 +367,9 @@ public class Training2Service { if (!CollectionUtils.isEmpty(training2.getIndexList())) { training2.getIndexList().stream() .filter(index -> !index.getType().isContinuity() - && Objects.equals(simOperation2.getOperationType(), index.getType().getOperationType())) + && !CollectionUtils.isEmpty(index.getType().getOperationType()) + && index.getType().getOperationType().contains(simOperation2.getOperationType()) + ) .forEach(index -> training2.getIndexAlgorithmMap().get(index.getId()).calculation(simulation, null)); } } @@ -682,8 +684,7 @@ public class Training2Service { .forEach(index -> { String jobName = String.format(INDEX_JOB_NAME, index.getId()); if (!simulation.getJobMap().containsKey(jobName)) { - simulation.addJobIfAbsent(jobName, - () -> training2.getIndexAlgorithmMap().get(index.getId()).calculation(simulation, null), RATE); //移除指标执行任务 + simulation.addJobIfAbsent(jobName, () -> training2.getIndexAlgorithmMap().get(index.getId()).calculation(simulation, null), RATE); //移除指标执行任务 } }); } diff --git a/src/main/java/club/joylink/rtss/services/training2/index/IndexAlgorithmService.java b/src/main/java/club/joylink/rtss/services/training2/index/IndexAlgorithmService.java index a8378b8db..b140494ab 100644 --- a/src/main/java/club/joylink/rtss/services/training2/index/IndexAlgorithmService.java +++ b/src/main/java/club/joylink/rtss/services/training2/index/IndexAlgorithmService.java @@ -10,7 +10,7 @@ import java.util.Map; /** * 指标计算统计接口 */ -public abstract class IndexAlgorithmService { +public abstract class IndexAlgorithmService { /** * 统计的指标结果 */ @@ -24,7 +24,7 @@ public abstract class IndexAlgorithmService { /** * 结束时统计 */ - public abstract T statistics(); + public abstract R statistics(); /** * 清理统计数据 diff --git a/src/main/java/club/joylink/rtss/services/training2/index/impl/IndexAlgorithmTestService.java b/src/main/java/club/joylink/rtss/services/training2/index/impl/IndexAlgorithmTestService.java index 58a8c0167..d7f1046a6 100644 --- a/src/main/java/club/joylink/rtss/services/training2/index/impl/IndexAlgorithmTestService.java +++ b/src/main/java/club/joylink/rtss/services/training2/index/impl/IndexAlgorithmTestService.java @@ -9,7 +9,7 @@ import java.util.Map; /** * 持续性测试指标 */ -public class IndexAlgorithmTestService extends IndexAlgorithmService { +public class IndexAlgorithmTestService extends IndexAlgorithmService { @Override public void calculation(Simulation simulation, Map params) { diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/training2/Training2.java b/src/main/java/club/joylink/rtss/simulation/cbtc/training2/Training2.java index 2c8c5c035..15ec72f04 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/training2/Training2.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/training2/Training2.java @@ -14,6 +14,7 @@ import club.joylink.rtss.vo.client.training2.ScoringRuleVO; import club.joylink.rtss.vo.client.training2.Step2VO; import lombok.Getter; import lombok.Setter; +import org.springframework.beans.BeanUtils; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; @@ -137,15 +138,8 @@ public class Training2 { this.indexList = (Arrays.asList(index1, index2)); if (!CollectionUtils.isEmpty(this.indexList)) { this.indexAlgorithmMap = new HashMap<>(this.indexList.size()); - this.indexList.stream().forEach(index -> { - try { - IndexAlgorithmService service = - (IndexAlgorithmService) index.getType().getAlgorithmService().getDeclaredConstructor().newInstance(); - this.indexAlgorithmMap.put(index.getId(), service); - } catch (Exception e) { - - } - }); + this.indexList.forEach(index -> this.indexAlgorithmMap.put(index.getId(), + BeanUtils.instantiateClass(index.getType().getAlgorithmService(), IndexAlgorithmService.class))); } else { this.indexAlgorithmMap = new HashMap<>(); } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/training2/index/Index.java b/src/main/java/club/joylink/rtss/simulation/cbtc/training2/index/Index.java index 7424d0e04..716c5764f 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/training2/index/Index.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/training2/index/Index.java @@ -5,6 +5,9 @@ import club.joylink.rtss.simulation.cbtc.ATS.operation.Operation; import lombok.Getter; import lombok.Setter; +import java.util.Arrays; +import java.util.List; + @Getter @Setter public class Index { @@ -30,28 +33,24 @@ public class Index { /** * 触发式测试指标 */ - TRIGGERED_TEST_INDEX(1, IndexAlgorithmTestService.class, Operation.Type.Signal_Set_Route), + TRIGGERED_TEST_INDEX(false, IndexAlgorithmTestService.class, Arrays.asList(Operation.Type.Signal_Set_Route)), /** * 连续式测试指标 */ - CONTINUITY_TEST_INDEX(0, IndexAlgorithmTestService.class, null), + CONTINUITY_TEST_INDEX(true, IndexAlgorithmTestService.class, null), ; - private int rate; // 频率 0:连续性计算、1:触发性计算 + private boolean continuity; // 频率 ture:连续性计算、false:触发性计算 private Class algorithmService; // 指标计算统计service类名 - private Operation.Type operationType; // 触发式指标事件类型 + private List operationType; // 触发式指标事件类型 - Type(int rate, Class algorithmService, Operation.Type operationType) { - this.rate = rate; + Type(boolean continuity, Class algorithmService, List operationType) { + this.continuity = continuity; this.algorithmService = algorithmService; this.operationType = operationType; } - - public boolean isContinuity() { - return this.rate == 0; - } } } From 9b8080d5f3d5b0433b1fb50dc7808e8300ef3fe2 Mon Sep 17 00:00:00 2001 From: weizhihong Date: Wed, 7 Sep 2022 10:41:06 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E3=80=90=E5=AE=9E=E8=AE=AD=E6=8C=87?= =?UTF-8?q?=E6=A0=87=E8=AE=A1=E7=AE=97=E5=8A=A0=E5=85=A5=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../club/joylink/rtss/services/training2/Training2Service.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/club/joylink/rtss/services/training2/Training2Service.java b/src/main/java/club/joylink/rtss/services/training2/Training2Service.java index 45e810344..541980d31 100644 --- a/src/main/java/club/joylink/rtss/services/training2/Training2Service.java +++ b/src/main/java/club/joylink/rtss/services/training2/Training2Service.java @@ -370,7 +370,7 @@ public class Training2Service { && !CollectionUtils.isEmpty(index.getType().getOperationType()) && index.getType().getOperationType().contains(simOperation2.getOperationType()) ) - .forEach(index -> training2.getIndexAlgorithmMap().get(index.getId()).calculation(simulation, null)); + .forEach(index -> training2.getIndexAlgorithmMap().get(index.getId()).calculation(simulation, simOperation2.getParams())); } } } From 101956f8d6bfe6574cce38117a6712e34ef4ee83 Mon Sep 17 00:00:00 2001 From: weizhihong Date: Wed, 7 Sep 2022 10:48:28 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E6=8C=87?= =?UTF-8?q?=E6=A0=87=E5=B1=9E=E6=80=A7=E7=B1=BB=E5=9E=8B=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rtss/simulation/cbtc/training2/index/Index.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/training2/index/Index.java b/src/main/java/club/joylink/rtss/simulation/cbtc/training2/index/Index.java index 716c5764f..da87b9418 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/training2/index/Index.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/training2/index/Index.java @@ -41,13 +41,13 @@ public class Index { CONTINUITY_TEST_INDEX(true, IndexAlgorithmTestService.class, null), ; - private boolean continuity; // 频率 ture:连续性计算、false:触发性计算 + private final boolean continuity; // 频率 ture:连续性计算、false:触发性计算 - private Class algorithmService; // 指标计算统计service类名 + private final Class algorithmService; // 指标计算统计service类名 - private List operationType; // 触发式指标事件类型 + private final List operationType; // 触发式指标事件类型 - Type(boolean continuity, Class algorithmService, List operationType) { + Type(boolean continuity, Class algorithmService, List operationType) { this.continuity = continuity; this.algorithmService = algorithmService; this.operationType = operationType; From f9eb48625f44876b5f53490feb661e828250baec Mon Sep 17 00:00:00 2001 From: xzb <223@qq.com> Date: Wed, 7 Sep 2022 14:01:06 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E8=B0=83=E5=BA=A6=E5=91=BD=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../simulation/cbtc/CTC/rail/cmd/DisCmd.java | 5 +- .../cbtc/CTC/rail/cmd/DisCmdRcvCompany.java | 10 +- .../cbtc/CTC/rail/cmd/DisCmdSendCompany.java | 6 +- .../cbtc/CTC/rail/cmd/DisCmdService.java | 48 ++++++-- .../rail/cmd/convertor/DisCmdConvertor.java | 111 ++++++++++++++++-- .../CTC/rail/cmd/vo/DisCmdRcvCompanyVo.java | 83 ++++++++++++- .../cbtc/CTC/rail/cmd/vo/DisCmdRspVo.java | 101 ++++++++++++++++ .../CTC/rail/cmd/vo/DisCmdSendCompanyVo.java | 38 +++++- .../cbtc/CTC/rail/cmd/vo/DisCmdSrcVo.java | 70 +++++++++++ .../cbtc/CTC/rail/cmd/vo/DisCmdVo.java | 25 ---- .../cmd/vo/FindAllDisCmdForHolderRspVo.java | 2 +- .../client/factory/SocketMessageFactory.java | 6 +- 12 files changed, 448 insertions(+), 57 deletions(-) create mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/cmd/vo/DisCmdRspVo.java create mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/cmd/vo/DisCmdSrcVo.java delete mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/cmd/vo/DisCmdVo.java diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/cmd/DisCmd.java b/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/cmd/DisCmd.java index 966341257..2262679de 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/cmd/DisCmd.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/cmd/DisCmd.java @@ -64,7 +64,7 @@ public class DisCmd { /** * 调度命令类型 */ - private Type type; + private Type type = Type.Undefined; /** * 调度命令正文 */ @@ -84,10 +84,11 @@ public class DisCmd { * 调度命令类型 */ public enum Type { + Undefined, /** * 正常调度命令 */ - NORMAL, + Normal, ; } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/cmd/DisCmdRcvCompany.java b/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/cmd/DisCmdRcvCompany.java index f4e288568..03e6cb40c 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/cmd/DisCmdRcvCompany.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/cmd/DisCmdRcvCompany.java @@ -62,7 +62,7 @@ public class DisCmdRcvCompany { /** * 最终受令端对于调度命令的状态 */ - private Status state; + private Status state = Status.Undefined; /** * 最终受令端对于调度命令的接收时间 */ @@ -73,12 +73,13 @@ public class DisCmdRcvCompany { private LocalDateTime signTime; /** * 最终受令端对于调度命令的实际签收人 + * @see SimulationMember#getUserId() */ - private SimulationMember signByReal; + private String signByReal; /** * 无线调度命令的中转站对调度命令的状态 */ - private TransStatus transStatus; + private TransStatus transStatus = TransStatus.Undefined; /** * 无线调度命令的中转站对调度命令的接收时间 */ @@ -111,6 +112,7 @@ public class DisCmdRcvCompany { * 发令单位类型 */ public enum Type { + Undefined, Dispatcher,//调度台 Station,//车站 Train,//无线 @@ -122,6 +124,7 @@ public class DisCmdRcvCompany { * 受令单位对于调度命令的状态 */ public enum Status { + Undefined, Received,//接收 Signed,//签收 ; @@ -131,6 +134,7 @@ public class DisCmdRcvCompany { * 无线调度命令时中转站对于调度命令的状态 */ public enum TransStatus { + Undefined, Received,//接收 Sent,//发送 ; diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/cmd/DisCmdSendCompany.java b/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/cmd/DisCmdSendCompany.java index daf06769c..41d8dc3ba 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/cmd/DisCmdSendCompany.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/cmd/DisCmdSendCompany.java @@ -12,7 +12,7 @@ public class DisCmdSendCompany { /** * 发令单位类型 */ - private Type type; + private Type type = Type.Undefined; /** * 发令单位名称 */ @@ -29,7 +29,7 @@ public class DisCmdSendCompany { /** * 调度命令对应发令单的状态 */ - private Status state; + private Status state = Status.Undefined; /** * 发令时间 */ @@ -48,6 +48,7 @@ public class DisCmdSendCompany { * 发令单位类型 */ public enum Type { + Undefined, Dispatcher,//调度台 Station,//车站 ; @@ -57,6 +58,7 @@ public class DisCmdSendCompany { * 发令单位对调度命令的状态 */ public enum Status { + Undefined, Cache,//缓存 Send,//发送 Signed,//签收完成(所有受令者签收完成) diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/cmd/DisCmdService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/cmd/DisCmdService.java index dd0406288..b5d1974fb 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/cmd/DisCmdService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/cmd/DisCmdService.java @@ -4,10 +4,12 @@ import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.simulation.cbtc.CTC.data.CtcRepository; import club.joylink.rtss.simulation.cbtc.CTC.rail.cmd.convertor.DisCmdConvertor; import club.joylink.rtss.simulation.cbtc.CTC.rail.cmd.vo.DisCmdHolderEnum; -import club.joylink.rtss.simulation.cbtc.CTC.rail.cmd.vo.DisCmdVo; +import club.joylink.rtss.simulation.cbtc.CTC.rail.cmd.vo.DisCmdRspVo; +import club.joylink.rtss.simulation.cbtc.CTC.rail.cmd.vo.DisCmdSrcVo; import club.joylink.rtss.simulation.cbtc.CTC.rail.cmd.vo.FindAllDisCmdForHolderRspVo; import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.data.map.Station; +import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain; import club.joylink.rtss.simulation.cbtc.member.SimulationMember; import club.joylink.rtss.vo.client.SocketMessageVO; import club.joylink.rtss.vo.client.factory.SocketMessageFactory; @@ -37,9 +39,14 @@ public class DisCmdService { /** * 保存调度命令,保存到发送方缓存箱(保存到仓库) */ - public void save(Simulation simulation,DisCmd disCmd){ - // + public void save(Simulation simulation, DisCmdSrcVo disCmdVo){ + DisCmd disCmd = DisCmdConvertor.convert(disCmdVo); CtcRepository ctcRepository = simulation.getCtcRepository(); + //为受令记录生成id + disCmd.getRcvCompanies().forEach(rc->{ + rc.setId(String.valueOf(ctcRepository.getDisCmdRcvCompanyIdGenerator().getAndIncrement())); + }); + // ctcRepository.getDisCmdMap().put(disCmd.getCode(),disCmd); // disCmd.getSendCompany().setState(DisCmdSendCompany.Status.Cache); @@ -157,7 +164,7 @@ public class DisCmdService { // rc.setState(DisCmdRcvCompany.Status.Signed); rc.setSignTime(this.getNow(simulation)); - rc.setSignByReal(signer); + rc.setSignByReal(signer.getUserId()); } /** * 监控调度命令 @@ -181,8 +188,6 @@ public class DisCmdService { } } //todo: 根据监控向前端推送其他通知 - - }); } @@ -260,7 +265,7 @@ public class DisCmdService { } // if(hasCmd){ - DisCmdVo cmdVo = DisCmdConvertor.convert(cmd); + DisCmdRspVo cmdVo = DisCmdConvertor.convert(cmd); rsp.getCmdMap().put(cmdVo.getCode(),cmdVo); } @@ -274,11 +279,12 @@ public class DisCmdService { * 注意如果向列控服务器推送通知,则系统自动处理通知签收 */ private void sendNotifyToRcvCompany(Simulation simulation,DisCmdRcvCompany rc){ - DisCmdVo disCmdVo = DisCmdConvertor.convert(this.find(simulation,rc.getDisCmdCode())); + DisCmdRspVo disCmdVo = DisCmdConvertor.convert(this.find(simulation,rc.getDisCmdCode())); + disCmdVo.setRcId(rc.getId()); // - WebSocketMessage messageBody - = new WebSocketMessage<>(DisCmdVo.WsMsgType.ADD, disCmdVo); - SocketMessageVO> message + WebSocketMessage messageBody + = new WebSocketMessage<>(DisCmdRspVo.WsMsgType.ADD, disCmdVo); + SocketMessageVO> message = SocketMessageFactory.buildDispatchCommandMessage2(simulation.getId(), messageBody); // if(DisCmdRcvCompany.Type.Station.equals(rc.getType())){//向车站的相关成员发送通知 @@ -288,6 +294,25 @@ public class DisCmdService { .collect(Collectors.toSet()); stompMessageService.sendToUser(receiverUserIds,message); } + }else if(DisCmdRcvCompany.Type.Dispatcher.equals(rc.getType())){ + //todo: 调度台暂时没有 + log.warn("==>>调度台不存在,不能推送通知!"); + }else if(DisCmdRcvCompany.Type.Tsr.equals(rc.getType())){ + //todo: 列控服务器暂时没有 + log.warn("==>>列控服务器不存在,不能推送通知!"); + }else if(DisCmdRcvCompany.Type.Train.equals(rc.getType())){ + //车次号 + String trainNum = rc.getTrainNum(); + //机车号 + String trainCode = rc.getTrainCode(); + List trains = simulation.getRepository().getOnlineTrainList().stream().filter(tr->{return tr.getTripNumber().equals(trainNum);}).collect(Collectors.toList()); + if(null!=trains&&!trains.isEmpty()){ + VirtualRealityTrain train = trains.get(0); + //查找该次列车的司机,向司机推送通知 + Set receiverUserIds = simulation.getSimulationMembersByDevice(train).stream().map(club.joylink.rtss.simulation.SimulationMember::getUserId) + .collect(Collectors.toSet()); + stompMessageService.sendToUser(receiverUserIds,message); + } } } /** @@ -299,6 +324,7 @@ public class DisCmdService { */ private boolean checkTrainInStation(Simulation simulation,String trainNum,String trainCode,String stationCode){ //todo + return true; } /** diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/cmd/convertor/DisCmdConvertor.java b/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/cmd/convertor/DisCmdConvertor.java index c429d72f6..2cc5fbd28 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/cmd/convertor/DisCmdConvertor.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/cmd/convertor/DisCmdConvertor.java @@ -5,20 +5,115 @@ import club.joylink.rtss.simulation.cbtc.CTC.rail.cmd.DisCmdRcvCompany; import club.joylink.rtss.simulation.cbtc.CTC.rail.cmd.DisCmdSendCompany; import club.joylink.rtss.simulation.cbtc.CTC.rail.cmd.vo.DisCmdRcvCompanyVo; import club.joylink.rtss.simulation.cbtc.CTC.rail.cmd.vo.DisCmdSendCompanyVo; -import club.joylink.rtss.simulation.cbtc.CTC.rail.cmd.vo.DisCmdVo; +import club.joylink.rtss.simulation.cbtc.CTC.rail.cmd.vo.DisCmdRspVo; +import club.joylink.rtss.simulation.cbtc.CTC.rail.cmd.vo.DisCmdSrcVo; +import java.util.stream.Collectors; public class DisCmdConvertor { - public static DisCmdVo convert(DisCmd from){ - - return null; + public static DisCmdRspVo convert(DisCmd from){ + DisCmdRspVo to = new DisCmdRspVo(); + to.setAuthState(from.getAuthState()); + to.setCode(from.getCode()); + to.setAuthTime(from.getAuthTime()); + to.setContent(from.getContent()); + to.setChiefOnDuty(from.getChiefOnDuty()); + to.setChiefOnDutyAuth(from.getChiefOnDutyAuth()); + to.setDesigner(from.getDesigner()); + to.setSender(from.getSender()); + to.setDailyPlanNum(from.getDailyPlanNum()); + to.setFinishedTime(from.getFinishedTime()); + to.setReviewer(from.getReviewer()); + to.setSendTime(from.getSendTime()); + to.setTitle(from.getTitle()); + to.setTransitId(from.getTransitId()); + to.setType(from.getType().name()); + to.setSendCompany(DisCmdConvertor.convert(from.getSendCompany())); + return to; } public static DisCmdSendCompanyVo convert(DisCmdSendCompany from){ - - return null; + DisCmdSendCompanyVo to = new DisCmdSendCompanyVo(); + to.setDisCmdCode(from.getDisCmdCode()); + to.setCode(from.getCode()); + to.setName(from.getName()); + to.setSendTime(from.getSendTime()); + to.setType(from.getType().name()); + to.setState(from.getState().name()); + to.setSignedTime(from.getSignedTime()); + return to; + } + public static DisCmdSendCompany convert(DisCmdSendCompanyVo from){ + DisCmdSendCompany to = new DisCmdSendCompany(); + to.setDisCmdCode(from.getDisCmdCode()); + to.setCode(from.getCode()); + to.setName(from.getName()); + to.setSendTime(from.getSendTime()); + to.setType(DisCmdSendCompany.Type.valueOf(from.getType())); + to.setState(DisCmdSendCompany.Status.valueOf(from.getState())); + to.setSignedTime(from.getSignedTime()); + return to; } public static DisCmdRcvCompanyVo convert(DisCmdRcvCompany from){ - - return null; + DisCmdRcvCompanyVo to = new DisCmdRcvCompanyVo(); + to.setDisCmdCode(from.getDisCmdCode()); + to.setDisCode(from.getDisCode()); + to.setId(from.getId()); + to.setName(from.getName()); + to.setState(from.getState().name()); + to.setSignByReal(from.getSignByReal()); + to.setReceiveTime(from.getReceiveTime()); + to.setSignTime(from.getSignTime()); + to.setStationCode(from.getStationCode()); + to.setTrainCode(from.getTrainCode()); + to.setTrainViaGsmR(from.getTrainViaGsmR()); + to.setTrainNum(from.getTrainNum()); + to.setTransReceiveTime(from.getTransReceiveTime()); + to.setTransStationCode(from.getTransStationCode()); + to.setTsrCode(from.getTsrCode()); + to.setTransSendTime(from.getTransSendTime()); + to.setType(from.getType().name()); + to.setTransStatus(from.getTransStatus().name()); + return to; + } + public static DisCmdRcvCompany convert(DisCmdRcvCompanyVo from){ + DisCmdRcvCompany to = new DisCmdRcvCompany(); + to.setDisCmdCode(from.getDisCmdCode()); + to.setDisCode(from.getDisCode()); + to.setId(from.getId()); + to.setName(from.getName()); + to.setState(DisCmdRcvCompany.Status.valueOf(from.getState())); + to.setSignByReal(from.getSignByReal()); + to.setReceiveTime(from.getReceiveTime()); + to.setSignTime(from.getSignTime()); + to.setStationCode(from.getStationCode()); + to.setTrainCode(from.getTrainCode()); + to.setTrainViaGsmR(from.getTrainViaGsmR()); + to.setTrainNum(from.getTrainNum()); + to.setTransReceiveTime(from.getTransReceiveTime()); + to.setTransStationCode(from.getTransStationCode()); + to.setTsrCode(from.getTsrCode()); + to.setTransSendTime(from.getTransSendTime()); + to.setType(DisCmdRcvCompany.Type.valueOf(from.getType())); + to.setTransStatus(DisCmdRcvCompany.TransStatus.valueOf(from.getTransStatus())); + return to; + } + public static DisCmd convert(DisCmdSrcVo from){ + DisCmd to = new DisCmd(); + to.setAuthState(from.getAuthState()); + to.setCode(from.getCode()); + to.setContent(from.getContent()); + to.setChiefOnDuty(from.getChiefOnDuty()); + to.setChiefOnDutyAuth(from.getChiefOnDutyAuth()); + to.setDesigner(from.getDesigner()); + to.setSender(from.getSender()); + to.setDailyPlanNum(from.getDailyPlanNum()); + to.setReviewer(from.getReviewer()); + to.setTitle(from.getTitle()); + to.setTransitId(from.getTransitId()); + to.setType(DisCmd.Type.valueOf(from.getType())); + // + to.setSendCompany(DisCmdConvertor.convert(from.getSendCompany())); + to.setRcvCompanies(from.getRcvCompanies().stream().map(rcVo->{return DisCmdConvertor.convert(rcVo);}).collect(Collectors.toList())); + return to; } } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/cmd/vo/DisCmdRcvCompanyVo.java b/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/cmd/vo/DisCmdRcvCompanyVo.java index a30566749..ef37fd026 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/cmd/vo/DisCmdRcvCompanyVo.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/cmd/vo/DisCmdRcvCompanyVo.java @@ -1,14 +1,95 @@ package club.joylink.rtss.simulation.cbtc.CTC.rail.cmd.vo; +import club.joylink.rtss.simulation.cbtc.CTC.rail.cmd.DisCmdRcvCompany; +import club.joylink.rtss.simulation.cbtc.member.SimulationMember; import lombok.Data; +import java.time.LocalDateTime; /** * 受令单位 */ @Data public class DisCmdRcvCompanyVo { + /** * 调度命令号(唯一) */ - private String disCmdCode; + private String disCmdCode; + /** + * 唯一id,受令单位记录id + */ + private String id; + /** + * 受令单位类型 + * @see DisCmdRcvCompany.Type + */ + private String type = "Undefined"; + /** + * 受令单位名称 + */ + private String name; + //////////////////受令者///////////////////// + /** + * 车站受令者code + */ + private String stationCode; + /** + * 调度台受令者code + */ + private String disCode; + /** + * 列控服务器受令者code + */ + private String tsrCode; + //////////////////受令者train//////////////////////// + /** + * 无线调度命令,true-通过手机移动网络直接发送,false-通过车站专有网络发送 + */ + private Boolean trainViaGsmR = true; + /** + * 中转车站code + *

+ * 当trainViaGsmR=false时,不为空。 + */ + private String transStationCode; + /** + * 车次号 + */ + private String trainNum; + /** + * 机车号(train code) + */ + private String trainCode; + /////////////////////运行时数据////////////////// + /** + * 最终受令端对于调度命令的状态 + * @see DisCmdRcvCompany.Status + */ + private String state = "Undefined"; + /** + * 最终受令端对于调度命令的接收时间 + */ + private LocalDateTime receiveTime; + /** + * 最终受令端对于调度命令的签收时间 + */ + private LocalDateTime signTime; + /** + * 最终受令端对于调度命令的实际签收人id + * @see SimulationMember#getUserId() + */ + private String signByReal; + /** + * 无线调度命令的中转站对调度命令的状态 + * @see DisCmdRcvCompany.TransStatus + */ + private String transStatus = "Undefined"; + /** + * 无线调度命令的中转站对调度命令的接收时间 + */ + private LocalDateTime transReceiveTime; + /** + * 无线调度命令的中转站对调度命令的发送时间 + */ + private LocalDateTime transSendTime; } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/cmd/vo/DisCmdRspVo.java b/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/cmd/vo/DisCmdRspVo.java new file mode 100644 index 000000000..3be449395 --- /dev/null +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/cmd/vo/DisCmdRspVo.java @@ -0,0 +1,101 @@ +package club.joylink.rtss.simulation.cbtc.CTC.rail.cmd.vo; + +import club.joylink.rtss.simulation.cbtc.CTC.rail.cmd.DisCmd; +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; +import java.time.LocalDateTime; + +/** + * 响应给客户端调度命令记录 + */ +@Data +public class DisCmdRspVo { + /** + * 标题 + */ + private String title; + /** + * 调度命令号(唯一) + */ + private String code; + /** + * 中转识别号 + */ + private String transitId; + /** + * 发令时间 + */ + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime sendTime; + /** + * 发令人 + */ + private String sender; + /** + * 授权时间 + */ + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime authTime; + /** + * 值班主任(仿真成员) + */ + private String chiefOnDuty; + /** + * 需值班主任授权 + */ + private Boolean chiefOnDutyAuth = false; + /** + * 授权状态 + */ + private String authState; + /** + * 定稿时间 + */ + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime finishedTime; + /** + * 审核人(仿真成员) + */ + private String reviewer; + /** + * 日计划号 + */ + private String dailyPlanNum; + /** + * 拟令人(起草者、设计者) + */ + private String designer; + /** + * 调度命令类型 + * @see DisCmd.Type + */ + private String type = "Undefined"; + /** + * 调度命令正文 + */ + private String content; + /////////////////////////////////////// + /** + * 发令单位 + */ + private DisCmdSendCompanyVo sendCompany; + /////////////////////////////////////// + /** + * 受令单位记录唯一id,仅在向前端推送通知时有效 + */ + private String rcId; + //////////////////////////////////////// + /** + * webSocket消息类型 + */ + public enum WsMsgType { + ALL, + ADD, + UPDATE, + DELETE, + } +} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/cmd/vo/DisCmdSendCompanyVo.java b/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/cmd/vo/DisCmdSendCompanyVo.java index 86e06d72c..82c21d958 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/cmd/vo/DisCmdSendCompanyVo.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/cmd/vo/DisCmdSendCompanyVo.java @@ -1,14 +1,50 @@ package club.joylink.rtss.simulation.cbtc.CTC.rail.cmd.vo; +import club.joylink.rtss.simulation.cbtc.CTC.rail.cmd.DisCmdSendCompany; +import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; +import java.time.LocalDateTime; /** * 发令单位 */ @Data public class DisCmdSendCompanyVo { + + /** + * 发令单位类型 + * @see DisCmdSendCompany.Type + */ + private String type = "Undefined"; + /** + * 发令单位名称 + */ + private String name; + /** + * 发令单位code + */ + private String code; /** * 调度命令号(唯一) */ - private String disCmdCode; + private String disCmdCode; + //////////////////运行时数据//////////////// + /** + * 调度命令对应发令单的状态 + * @see DisCmdSendCompany.Status + */ + private String state = "Undefined"; + /** + * 发令时间 + */ + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime sendTime; + /** + * 签收完成时间 + */ + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime signedTime; } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/cmd/vo/DisCmdSrcVo.java b/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/cmd/vo/DisCmdSrcVo.java new file mode 100644 index 000000000..16473df24 --- /dev/null +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/cmd/vo/DisCmdSrcVo.java @@ -0,0 +1,70 @@ +package club.joylink.rtss.simulation.cbtc.CTC.rail.cmd.vo; + +import club.joylink.rtss.simulation.cbtc.CTC.rail.cmd.DisCmd; +import lombok.Data; +import java.util.List; + +/** + * 创建调度命令的源客户端(调度台或车站)发送来的调度命令原始信息 + */ +@Data +public class DisCmdSrcVo { + /** + * 标题 + */ + private String title; + /** + * 调度命令号(唯一) + */ + private String code; + /** + * 中转识别号 + */ + private String transitId; + /** + * 发令人 + */ + private String sender; + /** + * 值班主任(仿真成员) + */ + private String chiefOnDuty; + /** + * 需值班主任授权 + */ + private Boolean chiefOnDutyAuth = false; + /** + * 授权状态 + */ + private String authState; + /** + * 审核人(仿真成员) + */ + private String reviewer; + /** + * 日计划号 + */ + private String dailyPlanNum; + /** + * 拟令人(起草者、设计者) + */ + private String designer; + /** + * 调度命令类型 + * @see DisCmd.Type + */ + private String type = "Undefined"; + /** + * 调度命令正文 + */ + private String content; + /////////////////////////////////////// + /** + * 发令单位 + */ + private DisCmdSendCompanyVo sendCompany; + /** + * 受令单位列表 + */ + private List rcvCompanies; +} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/cmd/vo/DisCmdVo.java b/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/cmd/vo/DisCmdVo.java deleted file mode 100644 index 4a9b19457..000000000 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/cmd/vo/DisCmdVo.java +++ /dev/null @@ -1,25 +0,0 @@ -package club.joylink.rtss.simulation.cbtc.CTC.rail.cmd.vo; - -import lombok.Data; - -@Data -public class DisCmdVo { - /** - * 标题 - */ - private String title; - /** - * 调度命令号(唯一) - */ - private String code; - /////////////////////////////////////// - /** - * webSocket消息类型 - */ - public enum WsMsgType { - ALL, - ADD, - UPDATE, - DELETE, - } -} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/cmd/vo/FindAllDisCmdForHolderRspVo.java b/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/cmd/vo/FindAllDisCmdForHolderRspVo.java index 07c62dd5e..ad53aaa98 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/cmd/vo/FindAllDisCmdForHolderRspVo.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/CTC/rail/cmd/vo/FindAllDisCmdForHolderRspVo.java @@ -28,7 +28,7 @@ public class FindAllDisCmdForHolderRspVo { /** * 调度命令列表 */ - private Map cmdMap = new HashMap<>(); + private Map cmdMap = new HashMap<>(); /** * 调度命令发令单位 */ diff --git a/src/main/java/club/joylink/rtss/vo/client/factory/SocketMessageFactory.java b/src/main/java/club/joylink/rtss/vo/client/factory/SocketMessageFactory.java index b710ff5d7..3fa0afb4e 100644 --- a/src/main/java/club/joylink/rtss/vo/client/factory/SocketMessageFactory.java +++ b/src/main/java/club/joylink/rtss/vo/client/factory/SocketMessageFactory.java @@ -6,7 +6,7 @@ import club.joylink.rtss.simulation.cbtc.CTC.data.Ticket; import club.joylink.rtss.simulation.cbtc.CTC.data.vo.BusyBoardVO; import club.joylink.rtss.simulation.cbtc.CTC.data.vo.CtcStationRunPlanLogVO; import club.joylink.rtss.simulation.cbtc.CTC.data.vo.RailDispatchCommandVO; -import club.joylink.rtss.simulation.cbtc.CTC.rail.cmd.vo.DisCmdVo; +import club.joylink.rtss.simulation.cbtc.CTC.rail.cmd.vo.DisCmdRspVo; import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.communication.vo.TrainPosition; import club.joylink.rtss.simulation.cbtc.conversation.Conversation; @@ -440,8 +440,8 @@ public class SocketMessageFactory { /** * CTC调度命令消息2 */ - public static SocketMessageVO> buildDispatchCommandMessage2 - (String simulationId, WebSocketMessage message) { + public static SocketMessageVO> buildDispatchCommandMessage2 + (String simulationId, WebSocketMessage message) { return build(WebSocketMessageType.SIMULATION_RAIL_CTC_DISPATCH_COMMAND, simulationId, message); } From 1308e569c19cf08bc1b9099d855b182d26d7cec6 Mon Sep 17 00:00:00 2001 From: weizhihong Date: Wed, 7 Sep 2022 14:10:10 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E3=80=90=E6=8C=87=E6=A0=87=E8=AE=A1?= =?UTF-8?q?=E7=AE=97=E9=80=BB=E8=BE=91=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../services/training2/Training2Service.java | 57 ++++++++++--------- .../index/IndexAlgorithmService.java | 33 +++++------ .../index/impl/IndexAlgorithmTestService.java | 14 ++--- .../index/impl/IndexTriggeredTestService.java | 25 ++++++++ .../simulation/cbtc/training2/Training2.java | 26 +++------ .../cbtc/training2/index/Index.java | 57 ++++++------------- 6 files changed, 99 insertions(+), 113 deletions(-) create mode 100644 src/main/java/club/joylink/rtss/services/training2/index/impl/IndexTriggeredTestService.java diff --git a/src/main/java/club/joylink/rtss/services/training2/Training2Service.java b/src/main/java/club/joylink/rtss/services/training2/Training2Service.java index 541980d31..71b3b768a 100644 --- a/src/main/java/club/joylink/rtss/services/training2/Training2Service.java +++ b/src/main/java/club/joylink/rtss/services/training2/Training2Service.java @@ -4,6 +4,7 @@ import club.joylink.rtss.dao.DraftTraining2DAO; import club.joylink.rtss.dao.PublishedTraining2DAO; import club.joylink.rtss.entity.training2.DraftTraining2WithBLOBs; import club.joylink.rtss.entity.training2.PublishedTraining2WithBLOBs; +import club.joylink.rtss.services.training2.index.IndexAlgorithmService; import club.joylink.rtss.simulation.cbtc.ATS.operation.AtsOperationDispatcher; import club.joylink.rtss.simulation.cbtc.GroupSimulationCache; import club.joylink.rtss.simulation.cbtc.GroupSimulationService; @@ -19,6 +20,7 @@ import club.joylink.rtss.simulation.cbtc.script.ScriptBO; import club.joylink.rtss.simulation.cbtc.training2.Operation2; import club.joylink.rtss.simulation.cbtc.training2.Step2; import club.joylink.rtss.simulation.cbtc.training2.Training2; +import club.joylink.rtss.simulation.cbtc.training2.index.Index; import club.joylink.rtss.util.JsonUtils; import club.joylink.rtss.vo.AccountVO; import club.joylink.rtss.vo.LoginUserInfoVO; @@ -46,7 +48,7 @@ import java.util.function.Consumer; public class Training2Service { public static final String EXECUTE_JOB_NAME = "Training2"; public static final String SCORING_JOB_NAME = "Training2Scoring"; - public static final String INDEX_JOB_NAME = "Training2Index_%d"; + public static final String INDEX_JOB_NAME = "Training2Index"; public static final int RATE = 1000; @Autowired @@ -79,12 +81,12 @@ public class Training2Service { /** * 完成步骤接口信号量 */ - private Semaphore completeStepSemaphore = new Semaphore(1); + private final Semaphore completeStepSemaphore = new Semaphore(1); /** * 完成操作接口信号量 */ - private Semaphore completeOperationSemaphore = new Semaphore(1); + private final Semaphore completeOperationSemaphore = new Semaphore(1); /** * 实训运行 @@ -92,6 +94,8 @@ public class Training2Service { public void run(Simulation simulation) { Training2 training2 = simulation.getTraining2(); if (training2 == null || !training2.isStarted() || training2.isFinish()) { + // 结束并移除运行任务 + removeTrainingJob(simulation); return; } // 获取运行步骤 @@ -194,7 +198,6 @@ public class Training2Service { throw new SimulationException(SimulationExceptionType.Invalid_Operation, "实训数据不存在"); } if (training2.isNeedReloadScenes()) { - simulationLifeCycleService.pause(simulation); // 重置仿真状态 groupSimulationService.planOver(group); if (!StringUtils.isEmpty(training2.getBgSceneJson())) { @@ -223,7 +226,7 @@ public class Training2Service { // 创建者退出,则清理实训 if (simulation.getCreator().getId().equals(user.getId())) { training2.finish(); - removeTrainingJob(simulation, training2); + removeTrainingJob(simulation); } scoreMap = training2.mark(); } else { @@ -250,7 +253,7 @@ public class Training2Service { if (step == null) { throw new SimulationException(SimulationExceptionType.Invalid_Operation, "不存在步骤"); } - if (Objects.equals(user.getId(), step.getSimulationMember().getId())) { + if (!Objects.equals(String.valueOf(user.getId()), step.getSimulationMember().getUserId())) { throw new SimulationException(SimulationExceptionType.Invalid_Operation, "无权限操作"); } try { @@ -300,7 +303,7 @@ public class Training2Service { if (step == null) { throw new SimulationException(SimulationExceptionType.Invalid_Operation, "不存在步骤"); } - if (Objects.equals(user.getId(), step.getSimulationMember().getId())) { + if (!Objects.equals(String.valueOf(user.getId()), step.getSimulationMember().getUserId())) { throw new SimulationException(SimulationExceptionType.Invalid_Operation, "无权限操作"); } Operation2 operation = step.getOperations().stream().filter(o -> Objects.equals(o.getId(), id)) @@ -364,13 +367,15 @@ public class Training2Service { } // 操作完成后,如果是测验模式则仿真启动 pauseOrStartSimulation(simulation, false); + // 检查是否要计算指标 if (!CollectionUtils.isEmpty(training2.getIndexList())) { training2.getIndexList().stream() - .filter(index -> !index.getType().isContinuity() - && !CollectionUtils.isEmpty(index.getType().getOperationType()) - && index.getType().getOperationType().contains(simOperation2.getOperationType()) + .filter(index -> !index.isContinuity() && !CollectionUtils.isEmpty(index.getOperationType()) + && index.getOperationType().contains(simOperation2.getOperationType()) + && training2.getIndexAlgorithmMap().containsKey(index.name()) ) - .forEach(index -> training2.getIndexAlgorithmMap().get(index.getId()).calculation(simulation, simOperation2.getParams())); + .forEach(index -> training2.getIndexAlgorithmMap().get(index.name()) + .calculation(simulation, simOperation2.getParams())); } } } @@ -653,7 +658,7 @@ public class Training2Service { /** * 移除实训任务 */ - private void removeTrainingJob(Simulation simulation, Training2 training2) { + private void removeTrainingJob(Simulation simulation) { if (simulation.getJobMap().containsKey(SCORING_JOB_NAME)) { simulation.removeJob(SCORING_JOB_NAME); //移除打分监视任务 } @@ -661,14 +666,8 @@ public class Training2Service { simulation.removeJob(EXECUTE_JOB_NAME); //移除实训执行任务 } // 去除指标计算任务 - if (training2 != null && !CollectionUtils.isEmpty(training2.getIndexList())) { - training2.getIndexList().stream().filter(index -> index.getType().isContinuity()) - .forEach(index -> { - String jobName = String.format(INDEX_JOB_NAME, index.getId()); - if (simulation.getJobMap().containsKey(jobName)) { - simulation.removeJob(jobName); //移除指标执行任务 - } - }); + if (simulation.getJobMap().containsKey(INDEX_JOB_NAME)) { + simulation.removeJob(INDEX_JOB_NAME); } } @@ -676,17 +675,19 @@ public class Training2Service { * 增加实训任务 */ private void addTrainingJob(Simulation simulation, Training2 training2) { - removeTrainingJob(simulation, training2); + // 移除后再添加 + removeTrainingJob(simulation); simulation.addJobIfAbsent(EXECUTE_JOB_NAME, () -> this.run(simulation), RATE); // 增加指标计算任务 if (training2 != null && !CollectionUtils.isEmpty(training2.getIndexList())) { - training2.getIndexList().stream().filter(index -> index.getType().isContinuity()) - .forEach(index -> { - String jobName = String.format(INDEX_JOB_NAME, index.getId()); - if (!simulation.getJobMap().containsKey(jobName)) { - simulation.addJobIfAbsent(jobName, () -> training2.getIndexAlgorithmMap().get(index.getId()).calculation(simulation, null), RATE); //移除指标执行任务 - } - }); + Map trainIndexServiceMap = training2.getIndexAlgorithmMap(); + simulation.addJobIfAbsent(INDEX_JOB_NAME, () -> + training2.getIndexList().stream().filter(Index::isContinuity).forEach(index -> { + if (trainIndexServiceMap.containsKey(index.name())) { + trainIndexServiceMap.get(index.name()).calculation(simulation); + } + }) + , RATE); } } diff --git a/src/main/java/club/joylink/rtss/services/training2/index/IndexAlgorithmService.java b/src/main/java/club/joylink/rtss/services/training2/index/IndexAlgorithmService.java index b140494ab..c58960110 100644 --- a/src/main/java/club/joylink/rtss/services/training2/index/IndexAlgorithmService.java +++ b/src/main/java/club/joylink/rtss/services/training2/index/IndexAlgorithmService.java @@ -1,37 +1,30 @@ package club.joylink.rtss.services.training2.index; import club.joylink.rtss.simulation.cbtc.Simulation; -import org.springframework.util.CollectionUtils; -import java.util.ArrayList; -import java.util.List; import java.util.Map; /** * 指标计算统计接口 */ -public abstract class IndexAlgorithmService { - /** - * 统计的指标结果 - */ - private List indexValList = new ArrayList<>(); +public interface IndexAlgorithmService { /** - * 运行时计算 + * 没参数计算 */ - public abstract void calculation(Simulation simulation, Map params); + default void calculation(Simulation simulation) { + + } + + /** + * 操作触发时,带有参数性 + */ + default void calculation(Simulation simulation, Map params) { + + } /** * 结束时统计 */ - public abstract R statistics(); - - /** - * 清理统计数据 - */ - public void reset() { - if (!CollectionUtils.isEmpty(indexValList)) { - this.indexValList.clear(); - } - } + R statistics(); } diff --git a/src/main/java/club/joylink/rtss/services/training2/index/impl/IndexAlgorithmTestService.java b/src/main/java/club/joylink/rtss/services/training2/index/impl/IndexAlgorithmTestService.java index d7f1046a6..4f0d99af2 100644 --- a/src/main/java/club/joylink/rtss/services/training2/index/impl/IndexAlgorithmTestService.java +++ b/src/main/java/club/joylink/rtss/services/training2/index/impl/IndexAlgorithmTestService.java @@ -3,22 +3,22 @@ package club.joylink.rtss.services.training2.index.impl; import club.joylink.rtss.services.training2.index.IndexAlgorithmService; import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.training2.index.IndexTestValue; - -import java.util.Map; +import lombok.extern.slf4j.Slf4j; /** - * 持续性测试指标 + * 指标计算统计实现 */ -public class IndexAlgorithmTestService extends IndexAlgorithmService { +@Slf4j +public class IndexAlgorithmTestService implements IndexAlgorithmService { @Override - public void calculation(Simulation simulation, Map params) { - System.out.println(this.hashCode() + " 计算"); + public void calculation(Simulation simulation) { + log.info(this.getClass().getSimpleName() + "[" + this.hashCode() + "]任务持续 计算"); } @Override public IndexTestValue statistics() { - System.out.println(this.hashCode() + "统计"); + log.info(this.getClass().getSimpleName() + "[" + this.hashCode() + "] 统计"); return null; } } diff --git a/src/main/java/club/joylink/rtss/services/training2/index/impl/IndexTriggeredTestService.java b/src/main/java/club/joylink/rtss/services/training2/index/impl/IndexTriggeredTestService.java new file mode 100644 index 000000000..608e8f235 --- /dev/null +++ b/src/main/java/club/joylink/rtss/services/training2/index/impl/IndexTriggeredTestService.java @@ -0,0 +1,25 @@ +package club.joylink.rtss.services.training2.index.impl; + +import club.joylink.rtss.services.training2.index.IndexAlgorithmService; +import club.joylink.rtss.simulation.cbtc.Simulation; +import club.joylink.rtss.simulation.cbtc.training2.index.IndexTestValue; +import lombok.extern.slf4j.Slf4j; + +import java.util.Map; + +/** + * 指标计算统计实现 + */ +@Slf4j +public class IndexTriggeredTestService implements IndexAlgorithmService { + @Override + public void calculation(Simulation simulation, Map params) { + log.info(this.getClass().getSimpleName() + "[" + this.hashCode() + "]操作触发 计算"); + } + + @Override + public IndexTestValue statistics() { + log.info(this.getClass().getSimpleName() + "[" + this.hashCode() + "] 统计"); + return null; + } +} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/training2/Training2.java b/src/main/java/club/joylink/rtss/simulation/cbtc/training2/Training2.java index 15ec72f04..12b6363a0 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/training2/Training2.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/training2/Training2.java @@ -96,7 +96,7 @@ public class Training2 { /** * 指标处理逻辑 */ - private Map indexAlgorithmMap; + private Map indexAlgorithmMap; public Training2(DraftTraining2WithBLOBs draftTraining2, Simulation simulation) { this.id = draftTraining2.getId(); @@ -127,22 +127,6 @@ public class Training2 { ExpressionVO evo = JsonUtils.read(draftTraining2.getFailureConditionJson(), ExpressionVO.class); this.failureCondition = evo.convert2BO(simulation.getRepository()); } - Index index1 = new Index(); - index1.setId(1); - index1.setName("指标1"); - index1.setType(Index.Type.TRIGGERED_TEST_INDEX); - Index index2 = new Index(); - index2.setId(2); - index2.setName("指标2"); - index2.setType(Index.Type.CONTINUITY_TEST_INDEX); - this.indexList = (Arrays.asList(index1, index2)); - if (!CollectionUtils.isEmpty(this.indexList)) { - this.indexAlgorithmMap = new HashMap<>(this.indexList.size()); - this.indexList.forEach(index -> this.indexAlgorithmMap.put(index.getId(), - BeanUtils.instantiateClass(index.getType().getAlgorithmService(), IndexAlgorithmService.class))); - } else { - this.indexAlgorithmMap = new HashMap<>(); - } } public void start(ScriptBO.Mode mode) { @@ -231,8 +215,12 @@ public class Training2 { this.steps.forEach(Step2::reset); } // 重置时清空 - if (!CollectionUtils.isEmpty(this.indexAlgorithmMap)) { - this.indexAlgorithmMap.forEach((k, v) -> v.reset()); + if (!CollectionUtils.isEmpty(this.indexList)) { + this.indexAlgorithmMap = new HashMap<>(this.indexList.size()); + this.indexList.forEach(index -> this.indexAlgorithmMap.put(index.name(), + BeanUtils.instantiateClass(index.getAlgorithmService(), IndexAlgorithmService.class))); + } else { + this.indexAlgorithmMap = new HashMap<>(); } } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/training2/index/Index.java b/src/main/java/club/joylink/rtss/simulation/cbtc/training2/index/Index.java index da87b9418..d7ba17de9 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/training2/index/Index.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/training2/index/Index.java @@ -1,56 +1,35 @@ package club.joylink.rtss.simulation.cbtc.training2.index; import club.joylink.rtss.services.training2.index.impl.IndexAlgorithmTestService; +import club.joylink.rtss.services.training2.index.impl.IndexTriggeredTestService; import club.joylink.rtss.simulation.cbtc.ATS.operation.Operation; import lombok.Getter; -import lombok.Setter; import java.util.Arrays; import java.util.List; @Getter -@Setter -public class Index { - private int id; +public enum Index { + TRIGGERED_TEST_INDEX("触发式测试指标", "", false, + IndexTriggeredTestService.class, Arrays.asList(Operation.Type.Signal_Set_Route)), - /** - * 指标名称 - */ - private String name; + CONTINUITY_TEST_INDEX("连续式测试指标", "", true, + IndexAlgorithmTestService.class, null), + ; - /** - * 指标描述 - */ - private String description; + private final String name; // 指标名称 + private final String description; // 指标说明 + private final boolean continuity; // 频率 ture:连续性计算、false:触发性计算 - /** - * 指标类型 - */ - private Type type; + private final Class algorithmService; // 指标计算统计service类名 - @Getter - public enum Type { - /** - * 触发式测试指标 - */ - TRIGGERED_TEST_INDEX(false, IndexAlgorithmTestService.class, Arrays.asList(Operation.Type.Signal_Set_Route)), + private final List operationType; // 触发式指标事件类型 - /** - * 连续式测试指标 - */ - CONTINUITY_TEST_INDEX(true, IndexAlgorithmTestService.class, null), - ; - - private final boolean continuity; // 频率 ture:连续性计算、false:触发性计算 - - private final Class algorithmService; // 指标计算统计service类名 - - private final List operationType; // 触发式指标事件类型 - - Type(boolean continuity, Class algorithmService, List operationType) { - this.continuity = continuity; - this.algorithmService = algorithmService; - this.operationType = operationType; - } + Index(String name, String description, boolean continuity, Class algorithmService, List operationType) { + this.name = name; + this.description = description; + this.continuity = continuity; + this.algorithmService = algorithmService; + this.operationType = operationType; } } From faeef7a0ea4b217fd6a335396fcdaf1b52832828 Mon Sep 17 00:00:00 2001 From: weizhihong Date: Wed, 7 Sep 2022 15:04:17 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E3=80=90=E5=AE=9E=E8=AE=AD=E9=87=8D?= =?UTF-8?q?=E6=96=B0=E5=BC=80=E5=A7=8B=E6=97=B6=E7=8A=B6=E6=80=81=E6=9C=AA?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E9=97=AE=E9=A2=98=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rtss/services/training2/Training2Service.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main/java/club/joylink/rtss/services/training2/Training2Service.java b/src/main/java/club/joylink/rtss/services/training2/Training2Service.java index 71b3b768a..9acdbff40 100644 --- a/src/main/java/club/joylink/rtss/services/training2/Training2Service.java +++ b/src/main/java/club/joylink/rtss/services/training2/Training2Service.java @@ -5,6 +5,7 @@ import club.joylink.rtss.dao.PublishedTraining2DAO; import club.joylink.rtss.entity.training2.DraftTraining2WithBLOBs; import club.joylink.rtss.entity.training2.PublishedTraining2WithBLOBs; import club.joylink.rtss.services.training2.index.IndexAlgorithmService; +import club.joylink.rtss.simulation.cbtc.ATS.ATSMessageCollectAndDispatcher; import club.joylink.rtss.simulation.cbtc.ATS.operation.AtsOperationDispatcher; import club.joylink.rtss.simulation.cbtc.GroupSimulationCache; import club.joylink.rtss.simulation.cbtc.GroupSimulationService; @@ -78,6 +79,9 @@ public class Training2Service { @Autowired private ApplicationContext applicationContext; + @Autowired + private ATSMessageCollectAndDispatcher atsMessageCollectAndDispatcher; + /** * 完成步骤接口信号量 */ @@ -197,17 +201,16 @@ public class Training2Service { if (training2 == null) { throw new SimulationException(SimulationExceptionType.Invalid_Operation, "实训数据不存在"); } - if (training2.isNeedReloadScenes()) { + if (training2.isNeedReloadScenes() && !StringUtils.isEmpty(training2.getBgSceneJson())) { + groupSimulationService.loadScenes(simulation.getId(), training2.getBgSceneJson()); + } else { // 重置仿真状态 - groupSimulationService.planOver(group); - if (!StringUtils.isEmpty(training2.getBgSceneJson())) { - groupSimulationService.loadScenes(simulation.getId(), training2.getBgSceneJson()); - } + simulationLifeCycleService.reset(simulation); + atsMessageCollectAndDispatcher.collectAllAndSend(simulation); } // 增加实训任务 training2.start(mode); addTrainingJob(simulation, training2); - simulationLifeCycleService.resume(simulation); } /**