diff --git a/src/main/java/club/joylink/rtss/controller/racetr/RaceApplicationController.java b/src/main/java/club/joylink/rtss/controller/racetr/RaceApplicationController.java new file mode 100644 index 000000000..52927a2a3 --- /dev/null +++ b/src/main/java/club/joylink/rtss/controller/racetr/RaceApplicationController.java @@ -0,0 +1,66 @@ +package club.joylink.rtss.controller.racetr; + +import org.springframework.web.bind.annotation.*; + +/** + * 赛题训练接口 + */ +@RestController +@RequestMapping("/api/race") +public class RaceApplicationController { + /** + * 开始训练 + * + * @param paperId 赛题ID + * @return 训练的信息 + */ + @PostMapping("/{paperId}") + public Object start(@PathVariable long paperId) { + //暂时就用用户id作为竞赛上下文的id,也就是说一个用户同时只能开一个竞赛 + return null; + } + + /** + * 加载场景 + * + * @param simulationId 场景依托的仿真 + * @param sceneId 场景的ID + */ + @PutMapping("/{simulationId}/{sceneId}/load") + public void loadScene(@PathVariable String simulationId, @PathVariable String sceneId) { + + } + + /** + * 完成任务 + * + * @param taskId 任务ID + * @param record 任务记录(需要前端进行判定的操作的记录) + */ + @PutMapping("/{taskId}/finish") + public void finishTask(@PathVariable long taskId, @RequestBody Object record) { + + } + + /** + * 完成训练 + * + * @return 评分结果 + */ + public Object finish() { + return null; + } + + /** + * 获取用户正在进行的竞赛信息 + *

+ * 目前想到的使用场景就是页面刷新后 + * + * @return 竞赛信息 + */ + @GetMapping("") + public Object getRaceInfo() { + return null; + } + +} diff --git a/src/main/java/club/joylink/rtss/controller/simulation/SimulationV1Controller.java b/src/main/java/club/joylink/rtss/controller/simulation/SimulationV1Controller.java index b46376e2f..9b379d8b0 100644 --- a/src/main/java/club/joylink/rtss/controller/simulation/SimulationV1Controller.java +++ b/src/main/java/club/joylink/rtss/controller/simulation/SimulationV1Controller.java @@ -18,6 +18,7 @@ import club.joylink.rtss.simulation.cbtc.data.vo.SimulationVO; import club.joylink.rtss.simulation.cbtc.member.MemberManager; import club.joylink.rtss.simulation.cbtc.member.SimulationMember; import club.joylink.rtss.simulation.cbtc.script.ScriptBO; +import club.joylink.rtss.simulation.cbtc.vo.SimulationWorkParamVO; import club.joylink.rtss.simulation.vo.SimulationInfoVO; import club.joylink.rtss.vo.AccountVO; import club.joylink.rtss.vo.LoginUserInfoVO; @@ -31,37 +32,22 @@ import club.joylink.rtss.vo.client.operation.DriveParamVO; import club.joylink.rtss.vo.client.psl.PslStatus; import club.joylink.rtss.vo.client.runplan.PlanTripNumberVO; import club.joylink.rtss.vo.client.runplan.RunPlanEChartsDataVO; -import club.joylink.rtss.vo.client.simulationv1.RunAsPlanParam; -import club.joylink.rtss.vo.client.simulationv1.SimulationInfoQueryVO; -import club.joylink.rtss.vo.client.simulationv1.SimulationLogPagedQueryVO; -import club.joylink.rtss.vo.client.simulationv1.SimulationMemberVO; -import club.joylink.rtss.vo.client.simulationv1.SimulationUserVO; +import club.joylink.rtss.vo.client.simulationv1.*; import club.joylink.rtss.vo.map.MapVO; import club.joylink.rtss.vo.map.graph.MapStationNewVO; -import java.time.LocalDateTime; -import java.time.LocalTime; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Set; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotNull; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.format.annotation.DateTimeFormat; import org.springframework.util.StringUtils; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestAttribute; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.util.*; +import java.util.stream.Collectors; +import java.util.stream.Stream; /** * 新仿真接口 @@ -70,319 +56,319 @@ import org.springframework.web.bind.annotation.RestController; @RequestMapping("/simulation") public class SimulationV1Controller { - @Autowired - private GroupSimulationService groupSimulationService; + @Autowired + private GroupSimulationService groupSimulationService; - @Autowired - private IVirtualRealityIbpService iVirtualRealityIBPService; + @Autowired + private IVirtualRealityIbpService iVirtualRealityIBPService; - @Autowired - private SimulationSupportService simulationSupportService; + @Autowired + private SimulationSupportService simulationSupportService; - @Autowired - private IVirtualRealityPslService iVirtualRealityPslService; - @Autowired - private SimulationService simulationService; - @Autowired - private SimulationManager simulationManager; - @Autowired - private MemberManager memberManager; + @Autowired + private IVirtualRealityPslService iVirtualRealityPslService; + @Autowired + private SimulationService simulationService; + @Autowired + private SimulationManager simulationManager; + @Autowired + private MemberManager memberManager; - /** - * 根据产品类型创建仿真 - */ - @GetMapping("") - public String simulation(Long mapId, String prdType, - @RequestAttribute(name = AuthenticateInterceptor.LOGIN_INFO_KEY) - LoginUserInfoVO loginUserInfoVO) { - String simulation = this.groupSimulationService.simulation(mapId, prdType, loginUserInfoVO); - return simulation; - } - - /** - * 创建实训仿真 - */ - @GetMapping(path = "/training/{trainingId}") - public String trainingSimulation(@PathVariable Long trainingId, - @RequestAttribute(name = AuthenticateInterceptor.LOGIN_INFO_KEY) - LoginUserInfoVO loginUserInfoVO) { - return this.groupSimulationService.trainingSimulation(trainingId, loginUserInfoVO); - } - - /** - * 创建考试仿真 - */ - @GetMapping(path = "/exam/{examId}") - public String examSimulate(@PathVariable Long examId, - @RequestAttribute(name = AuthenticateInterceptor.LOGIN_INFO_KEY) - LoginUserInfoVO loginUserInfoVO) { - return this.groupSimulationService.examSimulation(examId, loginUserInfoVO); - } - - /** - * 获取客户端已经进入仿真的用户仿真所在group - */ - @GetMapping(path = "/running") - public List getRunningSimulationBySubscribeUser(@RequestAttribute AccountVO user) { - return this.groupSimulationService.getUserRunningSimulationGroups(user); - } - - /** - * 根据仿真group获取仿真基础信息 - */ - @GetMapping("/{group}") - public SimulationVO getSimulationBasicInfo(@PathVariable String group) { - return this.groupSimulationService.getSimulationBasicInfo(group); - } - - /** - * 获取用户在仿真中的用户信息 - */ - @GetMapping("/{group}/simulationUser") - public SimulationUserVO getSimulationUserInfo(@PathVariable String group, - @RequestAttribute(name = AuthenticateInterceptor.LOGIN_USER_KEY) - AccountVO accountVO) { - return this.groupSimulationService.getSimulationUserInfo(group, accountVO); - } - - /** - * 获取所有仿真用户 - */ - @GetMapping("/{group}/simulationUsers") - public List queryAllSimulationUsers(@PathVariable String group) { - return this.groupSimulationService.queryAllSimulationUsers(group); - } - - /** - * 根据仿真group获取仿真地图数据 - */ - @GetMapping("/{group}/mapData") - public MapVO getSimulationMapData(@PathVariable String group) { - return this.groupSimulationService.getSimulationMapData(group); - } - - /** - * 根据group获取排序的车站列表(包含车辆段/停车场) - */ - @GetMapping("/{group}/stationWithDepot") - public List getSortedStationListWithDepot(@PathVariable String group) { - return this.groupSimulationService.getSortedStationListWithDepot(group); - } - - /** - * 加载指定运行计划到仿真中 - */ - @PutMapping("/{group}/load/runPlan/{templateId}") - public void loadRunPlan(@PathVariable String group, @PathVariable Long templateId) { - this.groupSimulationService.loadRunPlan(group, templateId); - } - - /** - * 加载草稿运行图 - */ - @PutMapping("/{simulationId}/load/draftRunPlan/{draftRunPlanId}") - public void loadDraftRunPlan(@PathVariable String simulationId, - @PathVariable long draftRunPlanId) { - this.simulationService.loadDraftRunPlan(simulationId, draftRunPlanId); - } - - /** - * 根据仿真group获取仿真运行图 - */ - @GetMapping("/{group}/runPlan") - public RunPlanEChartsDataVO getSimulationRunPlan(@PathVariable String group) { - return this.groupSimulationService.getSimulationRunPlan(group); - } - - /** - * 获取仿真运行图车次号列表 - */ - @GetMapping("/{group}/tripNumbers") - public List getSimulationRunPlanTripNumbers(@PathVariable String group) { - return this.groupSimulationService.getSimulationRunPlanTripNumbers(group); - } - - /** - * 根据车次号获取服务号 - */ - @GetMapping("/{group}/serviceNumber") - public List getServiceNumberByTripNumber(@PathVariable String group, String tripNumber) { - return this.groupSimulationService.getServiceNumberByTripNumber(group, tripNumber); - } - - /** - * 根据车次号获取计划车次信息 - */ - @GetMapping("/{group}/planTripInfo") - public PlanTripNumberVO getPlanTripByTripNumber(@PathVariable String group, String tripNumber) { - return this.groupSimulationService.getPlanTripByTripNumber(group, tripNumber); - } - - /** - * 根据服务号和车次号获取计划车次信息 - */ - @GetMapping("/{group}/planTripInfoBySt") - public PlanTripNumberVO planTripInfoBySt(@PathVariable String group, String serviceNumber, - String tripNumber) { - return this.groupSimulationService.planTripInfoByServiceAndTripNumber(group, serviceNumber, - tripNumber); - } - - /** - * 仿真操作 - */ - @PostMapping("/{group}/operate/{type}") - public Object operate(@PathVariable @NotBlank String group, @PathVariable @NotNull String type, - @RequestBody(required = false) Map param, @RequestAttribute AccountVO user) { - if (null == param) { - param = new HashMap<>(); + /** + * 根据产品类型创建仿真 + */ + @GetMapping("") + public String simulation(Long mapId, String prdType, + @RequestAttribute(name = AuthenticateInterceptor.LOGIN_INFO_KEY) + LoginUserInfoVO loginUserInfoVO) { + String simulation = this.groupSimulationService.simulation(mapId, prdType, loginUserInfoVO); + return simulation; } - return this.groupSimulationService.operate(group, type, param, user); - } - /** - * 仿真指令 - */ - @PostMapping("/{group}/command") - public void command(@PathVariable String group, - @RequestBody @Validated CommandInitiateVO initiateVO, @RequestAttribute AccountVO user) { - Simulation simulation = this.groupSimulationService.getSimulationByGroup(group); - SimulationMember member = simulation.getSimulationMemberByUserId(user.getId()); - this.groupSimulationService.command(simulation, initiateVO, member); - } - - /** - * 根据计划时间获取此时间点可以加载的最大列车数量 - */ - @GetMapping("/{group}/loadTrainNumber") - public int getLoadTrainNumber(@PathVariable String group, - @DateTimeFormat(pattern = "HH:mm:ss") LocalTime time) { - BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertNotNull(time, "时间不能为空"); - return this.groupSimulationService.getGivenTimeCouldLoadedTrainNumber(group, time); - } - - /** - * 按计划行车 - */ - @PostMapping("/{group}/ranAsPlan") - public void runAsPlan(@PathVariable String group, @RequestBody @Validated RunAsPlanParam param) { - this.groupSimulationService.runAsPlan(group, param); - } - - /** - * 修改仿真系统时间 - */ - @PutMapping("/{group}/modifySystemTime") - public void modifySystemTime(@PathVariable String group, @RequestBody RunAsPlanParam param) { - this.groupSimulationService.modifySystemTime(group, param.getTime()); - } - - /** - * 退出计划 - */ - @PostMapping("/{group}/planOver") - public void planOver(@PathVariable String group) { - this.groupSimulationService.planOver(group); - } - - /** - * 退出仿真(主要是非房主用户退出综合演练用) - */ - @PutMapping("/{simulationId}/exit") - public void exitSimulation(@PathVariable String simulationId, @RequestAttribute AccountVO user) { - this.groupSimulationService.exitSimulation(simulationId, user); - } - - /** - * 销毁仿真。 由系统管理员或老师在仿真监管功能中使用 - */ - @DeleteMapping("/{simulationId}/destroy") - public void destroySimulation(@PathVariable String simulationId) { - this.groupSimulationService.clearSimulation(simulationId); - } - - /** - * 加载剧本并扮演成员(已发布的剧本) - */ - @PutMapping(path = "/{group}/script/{scriptId}") - public void loadScriptAndPlayMember(@PathVariable String group, - @PathVariable Long scriptId, - String memberId, - ScriptBO.Mode mode, - @RequestAttribute AccountVO user) { - this.groupSimulationService.loadScriptAndPlayMember(group, scriptId, memberId, mode, user); - } - - /** - * 退出剧本 - */ - @PutMapping(path = "/{group}/exitScript") - public void exitScript(@PathVariable @NotBlank String group, @RequestAttribute AccountVO user) { - this.groupSimulationService.exitScript(group, user); - } - - /** - * 获取所有仿真成员列表 - */ - @GetMapping(path = "/{group}/members") - public List getSimulationMembers(@PathVariable @NotBlank String group) { - return this.groupSimulationService.getSimulationMembers(group); - } - - /** - * 获取仿真设备故障列表 - */ - @GetMapping(path = "/{group}/deviceFaultInfos") - public List getSimulationDeviceFaultInfoList( - @PathVariable @NotBlank String group) { - return this.groupSimulationService.getSimulationDeviceFaultInfoList(group); - } - - /** - * 取消自动故障 - */ - @PutMapping(path = "/{group}/faultMode/{id}") - public void setFaultMode(@PathVariable @NotBlank String group, - @PathVariable(required = false) Integer id) { - if (Objects.isNull(id)) { - this.groupSimulationService.clearAllAutoFault(group); - return; + /** + * 创建实训仿真 + */ + @GetMapping(path = "/training/{trainingId}") + public String trainingSimulation(@PathVariable Long trainingId, + @RequestAttribute(name = AuthenticateInterceptor.LOGIN_INFO_KEY) + LoginUserInfoVO loginUserInfoVO) { + return this.groupSimulationService.trainingSimulation(trainingId, loginUserInfoVO); } - this.groupSimulationService.cancelAutoFault(group, id); - } - /** - * 设置自动故障 - */ - @PostMapping(path = "/{group}/faultMode") - public Integer setFaultMode(@PathVariable @NotBlank String group, - @RequestBody FaultRuleVO ruleVO) { - return this.groupSimulationService.setFaultMode(group, ruleVO); - } + /** + * 创建考试仿真 + */ + @GetMapping(path = "/exam/{examId}") + public String examSimulate(@PathVariable Long examId, + @RequestAttribute(name = AuthenticateInterceptor.LOGIN_INFO_KEY) + LoginUserInfoVO loginUserInfoVO) { + return this.groupSimulationService.examSimulation(examId, loginUserInfoVO); + } - /** - * 查询已设置所有的自动触发故障 - */ - @GetMapping(path = "/{group}/faultMode/faultRule") - public Set getNotTriggerAutoFault(@PathVariable @NotBlank String group) { - return this.groupSimulationService.getTriggerAutoFaults(group); - } + /** + * 获取客户端已经进入仿真的用户仿真所在group + */ + @GetMapping(path = "/running") + public List getRunningSimulationBySubscribeUser(@RequestAttribute AccountVO user) { + return this.groupSimulationService.getUserRunningSimulationGroups(user); + } - /** - * 查询所有目的地码 - */ - @GetMapping("/{group}/destinationCode/list") - public List getAllDestinationCode(@PathVariable String group) { - return this.groupSimulationService.getAllDestinationCode(group); - } + /** + * 根据仿真group获取仿真基础信息 + */ + @GetMapping("/{group}") + public SimulationVO getSimulationBasicInfo(@PathVariable String group) { + return this.groupSimulationService.getSimulationBasicInfo(group); + } - /** - * 获取IBP盘状态 - */ - @GetMapping("/{group}/{stationCode}/ibp/status") - public IbpStatus getIbpStatus(@PathVariable String group, @PathVariable String stationCode) { - return iVirtualRealityIBPService.getIbpStatus(group, stationCode); - } + /** + * 获取用户在仿真中的用户信息 + */ + @GetMapping("/{group}/simulationUser") + public SimulationUserVO getSimulationUserInfo(@PathVariable String group, + @RequestAttribute(name = AuthenticateInterceptor.LOGIN_USER_KEY) + AccountVO accountVO) { + return this.groupSimulationService.getSimulationUserInfo(group, accountVO); + } + + /** + * 获取所有仿真用户 + */ + @GetMapping("/{group}/simulationUsers") + public List queryAllSimulationUsers(@PathVariable String group) { + return this.groupSimulationService.queryAllSimulationUsers(group); + } + + /** + * 根据仿真group获取仿真地图数据 + */ + @GetMapping("/{group}/mapData") + public MapVO getSimulationMapData(@PathVariable String group) { + return this.groupSimulationService.getSimulationMapData(group); + } + + /** + * 根据group获取排序的车站列表(包含车辆段/停车场) + */ + @GetMapping("/{group}/stationWithDepot") + public List getSortedStationListWithDepot(@PathVariable String group) { + return this.groupSimulationService.getSortedStationListWithDepot(group); + } + + /** + * 加载指定运行计划到仿真中 + */ + @PutMapping("/{group}/load/runPlan/{templateId}") + public void loadRunPlan(@PathVariable String group, @PathVariable Long templateId) { + this.groupSimulationService.loadRunPlan(group, templateId); + } + + /** + * 加载草稿运行图 + */ + @PutMapping("/{simulationId}/load/draftRunPlan/{draftRunPlanId}") + public void loadDraftRunPlan(@PathVariable String simulationId, + @PathVariable long draftRunPlanId) { + this.simulationService.loadDraftRunPlan(simulationId, draftRunPlanId); + } + + /** + * 根据仿真group获取仿真运行图 + */ + @GetMapping("/{group}/runPlan") + public RunPlanEChartsDataVO getSimulationRunPlan(@PathVariable String group) { + return this.groupSimulationService.getSimulationRunPlan(group); + } + + /** + * 获取仿真运行图车次号列表 + */ + @GetMapping("/{group}/tripNumbers") + public List getSimulationRunPlanTripNumbers(@PathVariable String group) { + return this.groupSimulationService.getSimulationRunPlanTripNumbers(group); + } + + /** + * 根据车次号获取服务号 + */ + @GetMapping("/{group}/serviceNumber") + public List getServiceNumberByTripNumber(@PathVariable String group, String tripNumber) { + return this.groupSimulationService.getServiceNumberByTripNumber(group, tripNumber); + } + + /** + * 根据车次号获取计划车次信息 + */ + @GetMapping("/{group}/planTripInfo") + public PlanTripNumberVO getPlanTripByTripNumber(@PathVariable String group, String tripNumber) { + return this.groupSimulationService.getPlanTripByTripNumber(group, tripNumber); + } + + /** + * 根据服务号和车次号获取计划车次信息 + */ + @GetMapping("/{group}/planTripInfoBySt") + public PlanTripNumberVO planTripInfoBySt(@PathVariable String group, String serviceNumber, + String tripNumber) { + return this.groupSimulationService.planTripInfoByServiceAndTripNumber(group, serviceNumber, + tripNumber); + } + + /** + * 仿真操作 + */ + @PostMapping("/{group}/operate/{type}") + public Object operate(@PathVariable @NotBlank String group, @PathVariable @NotNull String type, + @RequestBody(required = false) Map param, @RequestAttribute AccountVO user) { + if (null == param) { + param = new HashMap<>(); + } + return this.groupSimulationService.operate(group, type, param, user); + } + + /** + * 仿真指令 + */ + @PostMapping("/{group}/command") + public void command(@PathVariable String group, + @RequestBody @Validated CommandInitiateVO initiateVO, @RequestAttribute AccountVO user) { + Simulation simulation = this.groupSimulationService.getSimulationByGroup(group); + SimulationMember member = simulation.getSimulationMemberByUserId(user.getId()); + this.groupSimulationService.command(simulation, initiateVO, member); + } + + /** + * 根据计划时间获取此时间点可以加载的最大列车数量 + */ + @GetMapping("/{group}/loadTrainNumber") + public int getLoadTrainNumber(@PathVariable String group, + @DateTimeFormat(pattern = "HH:mm:ss") LocalTime time) { + BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertNotNull(time, "时间不能为空"); + return this.groupSimulationService.getGivenTimeCouldLoadedTrainNumber(group, time); + } + + /** + * 按计划行车 + */ + @PostMapping("/{group}/ranAsPlan") + public void runAsPlan(@PathVariable String group, @RequestBody @Validated RunAsPlanParam param) { + this.groupSimulationService.runAsPlan(group, param); + } + + /** + * 修改仿真系统时间 + */ + @PutMapping("/{group}/modifySystemTime") + public void modifySystemTime(@PathVariable String group, @RequestBody RunAsPlanParam param) { + this.groupSimulationService.modifySystemTime(group, param.getTime()); + } + + /** + * 退出计划 + */ + @PostMapping("/{group}/planOver") + public void planOver(@PathVariable String group) { + this.groupSimulationService.planOver(group); + } + + /** + * 退出仿真(主要是非房主用户退出综合演练用) + */ + @PutMapping("/{simulationId}/exit") + public void exitSimulation(@PathVariable String simulationId, @RequestAttribute AccountVO user) { + this.groupSimulationService.exitSimulation(simulationId, user); + } + + /** + * 销毁仿真。 由系统管理员或老师在仿真监管功能中使用 + */ + @DeleteMapping("/{simulationId}/destroy") + public void destroySimulation(@PathVariable String simulationId) { + this.groupSimulationService.clearSimulation(simulationId); + } + + /** + * 加载剧本并扮演成员(已发布的剧本) + */ + @PutMapping(path = "/{group}/script/{scriptId}") + public void loadScriptAndPlayMember(@PathVariable String group, + @PathVariable Long scriptId, + String memberId, + ScriptBO.Mode mode, + @RequestAttribute AccountVO user) { + this.groupSimulationService.loadScriptAndPlayMember(group, scriptId, memberId, mode, user); + } + + /** + * 退出剧本 + */ + @PutMapping(path = "/{group}/exitScript") + public void exitScript(@PathVariable @NotBlank String group, @RequestAttribute AccountVO user) { + this.groupSimulationService.exitScript(group, user); + } + + /** + * 获取所有仿真成员列表 + */ + @GetMapping(path = "/{group}/members") + public List getSimulationMembers(@PathVariable @NotBlank String group) { + return this.groupSimulationService.getSimulationMembers(group); + } + + /** + * 获取仿真设备故障列表 + */ + @GetMapping(path = "/{group}/deviceFaultInfos") + public List getSimulationDeviceFaultInfoList( + @PathVariable @NotBlank String group) { + return this.groupSimulationService.getSimulationDeviceFaultInfoList(group); + } + + /** + * 取消自动故障 + */ + @PutMapping(path = "/{group}/faultMode/{id}") + public void setFaultMode(@PathVariable @NotBlank String group, + @PathVariable(required = false) Integer id) { + if (Objects.isNull(id)) { + this.groupSimulationService.clearAllAutoFault(group); + return; + } + this.groupSimulationService.cancelAutoFault(group, id); + } + + /** + * 设置自动故障 + */ + @PostMapping(path = "/{group}/faultMode") + public Integer setFaultMode(@PathVariable @NotBlank String group, + @RequestBody FaultRuleVO ruleVO) { + return this.groupSimulationService.setFaultMode(group, ruleVO); + } + + /** + * 查询已设置所有的自动触发故障 + */ + @GetMapping(path = "/{group}/faultMode/faultRule") + public Set getNotTriggerAutoFault(@PathVariable @NotBlank String group) { + return this.groupSimulationService.getTriggerAutoFaults(group); + } + + /** + * 查询所有目的地码 + */ + @GetMapping("/{group}/destinationCode/list") + public List getAllDestinationCode(@PathVariable String group) { + return this.groupSimulationService.getAllDestinationCode(group); + } + + /** + * 获取IBP盘状态 + */ + @GetMapping("/{group}/{stationCode}/ibp/status") + public IbpStatus getIbpStatus(@PathVariable String group, @PathVariable String stationCode) { + return iVirtualRealityIBPService.getIbpStatus(group, stationCode); + } // /** // * 按下IBP盘按钮 @@ -400,90 +386,90 @@ public class SimulationV1Controller { // iVirtualRealityIBPService.releaseTheElement(group, stationCode, buttonCode); // } - /** - * 查询报警列表 - */ - @GetMapping(path = "/{group}/alarm") - public List listAlarm(@PathVariable String group, String level, - @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime startTime, - @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime endTime) { - return groupSimulationService.listAlarm(group, level, startTime, endTime); - } + /** + * 查询报警列表 + */ + @GetMapping(path = "/{group}/alarm") + public List listAlarm(@PathVariable String group, String level, + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime startTime, + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime endTime) { + return groupSimulationService.listAlarm(group, level, startTime, endTime); + } - /** - * 仿真报警确认 - */ - @PutMapping(path = "/{group}/alarm/confirm") - public void AlarmConfirm(@PathVariable String group, @RequestBody List codes, - @RequestAttribute AccountVO user) { - groupSimulationService.alarmConfirm(group, codes, user); - } + /** + * 仿真报警确认 + */ + @PutMapping(path = "/{group}/alarm/confirm") + public void AlarmConfirm(@PathVariable String group, @RequestBody List codes, + @RequestAttribute AccountVO user) { + groupSimulationService.alarmConfirm(group, codes, user); + } - /** - * 仿真客流数据切换 - */ - @PutMapping(path = "/{group}/passengerFlow/{passengerFlowId}") - public void AlarmConfirm(@PathVariable String group, @PathVariable Long passengerFlowId) { - groupSimulationService.changePassengerFlow(group, passengerFlowId); - } + /** + * 仿真客流数据切换 + */ + @PutMapping(path = "/{group}/passengerFlow/{passengerFlowId}") + public void AlarmConfirm(@PathVariable String group, @PathVariable Long passengerFlowId) { + groupSimulationService.changePassengerFlow(group, passengerFlowId); + } - /** - * 获取仿真日志 - */ - @GetMapping("/{group}/log") - public PageVO getLog(@PathVariable String group, - SimulationLogPagedQueryVO queryVO) { - return groupSimulationService.getLog(group, queryVO); - } + /** + * 获取仿真日志 + */ + @GetMapping("/{group}/log") + public PageVO getLog(@PathVariable String group, + SimulationLogPagedQueryVO queryVO) { + return groupSimulationService.getLog(group, queryVO); + } - /** - * 获取机器人驾驶参数 - */ - @GetMapping("/{simulationId}/driveParam/{groupNumber}") - public DriveParamVO getDriveParam(@PathVariable String simulationId, - @PathVariable String groupNumber) { - return groupSimulationService.getDriveParam(simulationId, groupNumber); - } + /** + * 获取机器人驾驶参数 + */ + @GetMapping("/{simulationId}/driveParam/{groupNumber}") + public DriveParamVO getDriveParam(@PathVariable String simulationId, + @PathVariable String groupNumber) { + return groupSimulationService.getDriveParam(simulationId, groupNumber); + } - /* ----------------------- 泰雷兹操作辅助接口 ----------------------- */ + /* ----------------------- 泰雷兹操作辅助接口 ----------------------- */ - /** - * 查询进路路径 - */ - @GetMapping("/{group}/querySectionPaths") - public List> querySectionPaths(@PathVariable String group, String groupNumber, - String standCode, String signalCode) { - return simulationSupportService.queryRoutePaths(group, groupNumber, standCode, signalCode); - } + /** + * 查询进路路径 + */ + @GetMapping("/{group}/querySectionPaths") + public List> querySectionPaths(@PathVariable String group, String groupNumber, + String standCode, String signalCode) { + return simulationSupportService.queryRoutePaths(group, groupNumber, standCode, signalCode); + } - /** - * 查询列车或运行线经过的站台 - */ - @GetMapping("/{group}/queryStands/trainOrDestination") - public List queryStandsThatTrainGoingThrough(@PathVariable String group, - String groupNumber, String destinationCode) { - return simulationSupportService.queryStandsThatTrainGoingThrough(group, groupNumber, - destinationCode); - } + /** + * 查询列车或运行线经过的站台 + */ + @GetMapping("/{group}/queryStands/trainOrDestination") + public List queryStandsThatTrainGoingThrough(@PathVariable String group, + String groupNumber, String destinationCode) { + return simulationSupportService.queryStandsThatTrainGoingThrough(group, groupNumber, + destinationCode); + } - /** - * 查询为该列车已建立的进路 - */ - @GetMapping("/{group}/queryEstablishedRoutes/{groupNumber}") - public List queryEstablishedRoutes(@PathVariable String group, - @PathVariable String groupNumber) { - return simulationSupportService.queryEstablishedRoutes(group, groupNumber); - } + /** + * 查询为该列车已建立的进路 + */ + @GetMapping("/{group}/queryEstablishedRoutes/{groupNumber}") + public List queryEstablishedRoutes(@PathVariable String group, + @PathVariable String groupNumber) { + return simulationSupportService.queryEstablishedRoutes(group, groupNumber); + } - /* ----------------------- PSL盘接口 ----------------------- */ + /* ----------------------- PSL盘接口 ----------------------- */ - /** - * 获取PSL盘状态 - */ - @GetMapping("/{group}/{standCode}/psl/status") - public PslStatus getPslStatus(@PathVariable String group, @PathVariable String standCode) { - return iVirtualRealityPslService.getStatus(group, standCode); - } + /** + * 获取PSL盘状态 + */ + @GetMapping("/{group}/{standCode}/psl/status") + public PslStatus getPslStatus(@PathVariable String group, @PathVariable String standCode) { + return iVirtualRealityPslService.getStatus(group, standCode); + } // /** // * 按下PSL盘按钮 @@ -493,169 +479,169 @@ public class SimulationV1Controller { // iVirtualRealityPslService.pressTheButton(group, standCode, button); // } - /* ----------------------- ISCS接口 ----------------------- */ + /* ----------------------- ISCS接口 ----------------------- */ - /** - * 条件查询仿真中的ISCS系统资源 - */ - @GetMapping("/{group}/iscs/systemResources") - public List getAllIscsSystemResources(@PathVariable String group, - IscsSystemResourcesQueryVO queryVO) { - return groupSimulationService.getAllIscsSystemResources(group, queryVO); - } + /** + * 条件查询仿真中的ISCS系统资源 + */ + @GetMapping("/{group}/iscs/systemResources") + public List getAllIscsSystemResources(@PathVariable String group, + IscsSystemResourcesQueryVO queryVO) { + return groupSimulationService.getAllIscsSystemResources(group, queryVO); + } - /** - * 查询所有pa系统的定时播放任务 - */ - @GetMapping("/{group}/iscs/paTimedPlay") - public List getPaTimedPlay(@PathVariable String group, String stationCode) { - return groupSimulationService.getAllPaTimedPlayInfo(group, stationCode); - } + /** + * 查询所有pa系统的定时播放任务 + */ + @GetMapping("/{group}/iscs/paTimedPlay") + public List getPaTimedPlay(@PathVariable String group, String stationCode) { + return groupSimulationService.getAllPaTimedPlayInfo(group, stationCode); + } - /* ----------------------- 仿真新接口 ----------------------- */ + /* ----------------------- 仿真新接口 ----------------------- */ - /** - * 仿真创建接口(新) - */ - /*@Deprecated + /** + * 根据功能配置创建仿真 + */ + @Deprecated @PostMapping("/new/{mapId}") public String createSimulation(@PathVariable long mapId, @RequestBody @Validated SimulationWorkParamVO paramVO, @RequestAttribute(name = AuthenticateInterceptor.LOGIN_INFO_KEY) - LoginUserInfoVO loginUserInfoVO) { - return simulationService.createSimulation(mapId, null, paramVO, loginUserInfoVO); - }*/ - - /** - * 根据地图功能id创建仿真 - */ - @PostMapping("/new/mapFunction/{mapFunctionId}") - public String createSimulationByMapFunction(@PathVariable long mapFunctionId, - @RequestAttribute LoginUserInfoVO loginInfo) { - return simulationService.createSimulation(mapFunctionId, loginInfo); - } - - /** - * 按计划行车(新) - */ - @PostMapping("/new/{simulationId}/runAsPlan") - public void runAsPlanNew(@PathVariable String simulationId, - @RequestBody @Validated RunAsPlanParam param) { - simulationService.runAsPlan(simulationId, param); - } - - /** - * 重置仿真(新) - */ - @PutMapping("/new/{simulationId}/reset") - public void reset(@PathVariable String simulationId) { - simulationService.reset(simulationId); - Simulation simulation = simulationManager.getById(simulationId, Simulation.class); - // 写在这里为了不与加载实训时冲突,如果写入reset方法,实训加载会多次处理,会有问题 - memberManager.loadExtraMembers(simulation, null); - } - - /** - * 根据地图和功能ID获取仿真GroupId - * - * @return 仿真GroupId - */ - @GetMapping("/new/map/{mapId}/function/{functionId}") - public String querySimulationByMapIdAndMapFunction(@PathVariable("mapId") long mapId - , @PathVariable("functionId") long mapFunctionId) { - return simulationService.querySimulationByMapIdAndMapFunction(mapId, mapFunctionId); - } - - /** - * 按组织查询存在的仿真(监管仿真) - */ - @GetMapping("/supervise") - public List listSimulationByOrg( - @RequestAttribute(name = AuthenticateInterceptor.LOGIN_INFO_KEY) LoginUserInfoVO loginUserInfoVO, - SimulationInfoQueryVO queryVO) { - return simulationService.listSimulationByOrg(loginUserInfoVO.getTopOrgId(), queryVO); - } - - /** - * 分页,按组织查询存在的仿真(监管仿真) - */ - @GetMapping("/paged/supervise") - public PageVO pagedSuperviseSimulation( - @RequestAttribute(name = AuthenticateInterceptor.LOGIN_INFO_KEY) LoginUserInfoVO loginUserInfoVO, - SimulationInfoQueryVO queryVO) { - return simulationService.pagedSimulationByOrg(loginUserInfoVO.getTopOrgId(), queryVO); - } - - /** - * 获取所有存在的仿真 - */ - @GetMapping("/list") - public List queryInfo(SimulationInfoQueryVO queryVO) { - List simulationList = this.simulationManager.getSimulationList(); - Stream stream = simulationList.stream(); - if (StringUtils.hasText(queryVO.getGroup())) { - stream = stream.filter(simulation -> simulation.getId().contains(queryVO.getGroup())); + LoginUserInfoVO loginUserInfoVO) { + return simulationService.createSimulation(mapId, paramVO, loginUserInfoVO); } - if (StringUtils.hasText(queryVO.getUserName())) { - stream = stream.filter(simulation -> simulation.getSimulationUsers().stream() - .anyMatch(user -> user.getName().contains(queryVO.getUserName()))); + + /** + * 根据地图功能id创建仿真 + */ + @PostMapping("/new/mapFunction/{mapFunctionId}") + public String createSimulationByMapFunction(@PathVariable long mapFunctionId, + @RequestAttribute LoginUserInfoVO loginInfo) { + return simulationService.createSimulation(mapFunctionId, loginInfo, true).getId(); } - return stream.map(Simulation::convertToVO).collect(Collectors.toList()); - } - /** - * 暂停 - */ - @PutMapping("/{id}/pause") - public void pause(@PathVariable String id) { - this.simulationManager.pause(id); - } + /** + * 按计划行车(新) + */ + @PostMapping("/new/{simulationId}/runAsPlan") + public void runAsPlanNew(@PathVariable String simulationId, + @RequestBody @Validated RunAsPlanParam param) { + simulationService.runAsPlan(simulationId, param); + } - /** - * 开始 - */ - @PutMapping("/{id}/start") - public void start(@PathVariable String id) { - this.simulationManager.start(id); - } + /** + * 重置仿真(新) + */ + @PutMapping("/new/{simulationId}/reset") + public void reset(@PathVariable String simulationId) { + simulationService.reset(simulationId); + Simulation simulation = simulationManager.getById(simulationId, Simulation.class); + // 写在这里为了不与加载实训时冲突,如果写入reset方法,实训加载会多次处理,会有问题 + memberManager.loadExtraMembers(simulation, null); + } - /** - * 调整倍速 - */ - @PutMapping("/{id}/updateSpeed/{speed}") - public void updateSpeed(@PathVariable String id, @PathVariable int speed) { - this.simulationManager.updateSpeed(id, speed); - } + /** + * 根据地图和功能ID获取仿真GroupId + * + * @return 仿真GroupId + */ + @GetMapping("/new/map/{mapId}/function/{functionId}") + public String querySimulationByMapIdAndMapFunction(@PathVariable("mapId") long mapId + , @PathVariable("functionId") long mapFunctionId) { + return simulationService.querySimulationByMapIdAndMapFunction(mapId, mapFunctionId); + } - /** - * 获取仿真中所有仿真用户 - */ - @GetMapping("/{id}/users") - public List getSimulationUsers( - @PathVariable String id) { - return this.simulationManager.getSimulationUsers(id).stream() - .map(club.joylink.rtss.simulation.SimulationUser::convertToVO) - .collect(Collectors.toList()); - } + /** + * 按组织查询存在的仿真(监管仿真) + */ + @GetMapping("/supervise") + public List listSimulationByOrg( + @RequestAttribute(name = AuthenticateInterceptor.LOGIN_INFO_KEY) LoginUserInfoVO loginUserInfoVO, + SimulationInfoQueryVO queryVO) { + return simulationService.listSimulationByOrg(loginUserInfoVO.getTopOrgId(), queryVO); + } - /** - * 监控仿真 - */ - @PostMapping("/{simulationId}/monitor") - public void monitor(@PathVariable String simulationId, @RequestAttribute AccountVO user) { - simulationService.monitor(simulationId, user); - } + /** + * 分页,按组织查询存在的仿真(监管仿真) + */ + @GetMapping("/paged/supervise") + public PageVO pagedSuperviseSimulation( + @RequestAttribute(name = AuthenticateInterceptor.LOGIN_INFO_KEY) LoginUserInfoVO loginUserInfoVO, + SimulationInfoQueryVO queryVO) { + return simulationService.pagedSimulationByOrg(loginUserInfoVO.getTopOrgId(), queryVO); + } - /** - * 查询"我"已加入的仿真 - */ - @GetMapping("/joined/by/me") - public SimulationVO querySimulationJoinedByMe(@RequestAttribute LoginUserInfoVO loginInfo) { - return simulationService.querySimulationJoinedByUser(loginInfo.getAccountVO().getId()); - } + /** + * 获取所有存在的仿真 + */ + @GetMapping("/list") + public List queryInfo(SimulationInfoQueryVO queryVO) { + List simulationList = this.simulationManager.getSimulationList(); + Stream stream = simulationList.stream(); + if (StringUtils.hasText(queryVO.getGroup())) { + stream = stream.filter(simulation -> simulation.getId().contains(queryVO.getGroup())); + } + if (StringUtils.hasText(queryVO.getUserName())) { + stream = stream.filter(simulation -> simulation.getSimulationUsers().stream() + .anyMatch(user -> user.getName().contains(queryVO.getUserName()))); + } + return stream.map(Simulation::convertToVO).collect(Collectors.toList()); + } - @GetMapping("/{simulationId}/{memberId}/unreceivedMessages") - public void sendUnreceivedMessages(@PathVariable String simulationId, - @PathVariable String memberId) { - simulationService.sendUnreceivedMessages(simulationId, memberId); - } + /** + * 暂停 + */ + @PutMapping("/{id}/pause") + public void pause(@PathVariable String id) { + this.simulationManager.pause(id); + } + + /** + * 开始 + */ + @PutMapping("/{id}/start") + public void start(@PathVariable String id) { + this.simulationManager.start(id); + } + + /** + * 调整倍速 + */ + @PutMapping("/{id}/updateSpeed/{speed}") + public void updateSpeed(@PathVariable String id, @PathVariable int speed) { + this.simulationManager.updateSpeed(id, speed); + } + + /** + * 获取仿真中所有仿真用户 + */ + @GetMapping("/{id}/users") + public List getSimulationUsers( + @PathVariable String id) { + return this.simulationManager.getSimulationUsers(id).stream() + .map(club.joylink.rtss.simulation.SimulationUser::convertToVO) + .collect(Collectors.toList()); + } + + /** + * 监控仿真 + */ + @PostMapping("/{simulationId}/monitor") + public void monitor(@PathVariable String simulationId, @RequestAttribute AccountVO user) { + simulationService.monitor(simulationId, user); + } + + /** + * 查询"我"已加入的仿真 + */ + @GetMapping("/joined/by/me") + public SimulationVO querySimulationJoinedByMe(@RequestAttribute LoginUserInfoVO loginInfo) { + return simulationService.querySimulationJoinedByUser(loginInfo.getAccountVO().getId()); + } + + @GetMapping("/{simulationId}/{memberId}/unreceivedMessages") + public void sendUnreceivedMessages(@PathVariable String simulationId, + @PathVariable String memberId) { + simulationService.sendUnreceivedMessages(simulationId, memberId); + } } diff --git a/src/main/java/club/joylink/rtss/services/training2/Training2RuleService.java b/src/main/java/club/joylink/rtss/services/training2/Training2RuleService.java index 5b4a29d8b..83d357341 100644 --- a/src/main/java/club/joylink/rtss/services/training2/Training2RuleService.java +++ b/src/main/java/club/joylink/rtss/services/training2/Training2RuleService.java @@ -1,8 +1,6 @@ package club.joylink.rtss.services.training2; import club.joylink.rtss.constants.MapStatus; -import club.joylink.rtss.constants.Project; -import club.joylink.rtss.controller.advice.AuthenticateInterceptor; import club.joylink.rtss.dao.MapInfoDAO; import club.joylink.rtss.dao.PublishedTraining2DAO; import club.joylink.rtss.dao.RtsMapFunctionDAO; @@ -11,36 +9,29 @@ import club.joylink.rtss.entity.MapInfo; import club.joylink.rtss.entity.MapInfoExample; import club.joylink.rtss.entity.RtsMapFunction; import club.joylink.rtss.entity.RtsMapFunctionExample; -import club.joylink.rtss.entity.training2.*; +import club.joylink.rtss.entity.training2.PublishedTraining2Example; +import club.joylink.rtss.entity.training2.PublishedTraining2WithBLOBs; +import club.joylink.rtss.entity.training2.RtsTraining2RuleExample; +import club.joylink.rtss.entity.training2.RtsTraining2RuleWithBLOBs; import club.joylink.rtss.services.mapFunction.RtsMapFunctionService; import club.joylink.rtss.services.project.ProjectService; import club.joylink.rtss.simulation.SimulationManager; import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.SimulationService; import club.joylink.rtss.simulation.cbtc.data.map.MapNamedElement; -import club.joylink.rtss.simulation.cbtc.data.map.Route; -import club.joylink.rtss.simulation.cbtc.data.map.Stand; -import club.joylink.rtss.simulation.cbtc.data.map.Switch; import club.joylink.rtss.util.JsonUtils; import club.joylink.rtss.vo.LoginUserInfoVO; import club.joylink.rtss.vo.client.training2.ScoringRuleVO; -import club.joylink.rtss.vo.project.ProjectVO; -import club.joylink.rtss.vo.training2.rule.BgSceneStatusRule; -import club.joylink.rtss.vo.training2.rule.MapLocationRule; import club.joylink.rtss.vo.training2.rule.StepRule; import club.joylink.rtss.vo.training2.rule.Training2Rule; -import com.fasterxml.jackson.core.JsonParseException; import lombok.extern.slf4j.Slf4j; import org.apache.logging.log4j.util.BiConsumer; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; -import org.springframework.web.bind.annotation.RequestAttribute; -import org.springframework.web.bind.annotation.RequestBody; import java.util.*; -import java.util.function.Consumer; import java.util.stream.Collectors; /** @@ -85,7 +76,7 @@ public class Training2RuleService { * @return 生成结果 */ public List generateTrainingByRule(String groupId) { - Simulation simulation = simulationManager.getById(groupId , Simulation.class); + Simulation simulation = simulationManager.getById(groupId, Simulation.class); Long mapId = simulation.getBuildParams().getMap().getId(); if (runningMapIdSet.contains(mapId)) { return Arrays.asList("该地图正在生成实训!"); @@ -131,7 +122,6 @@ public class Training2RuleService { } /** - * * @param mapId * @param functionId * @return @@ -144,7 +134,7 @@ public class Training2RuleService { /** * 根据地图ID生成实训 */ - public List generateTrainingByMapId(List mapIdList, LoginUserInfoVO loginUserInfoVO){ + public List generateTrainingByMapId(List mapIdList, LoginUserInfoVO loginUserInfoVO) { // 地图列表 MapInfoExample example = new MapInfoExample(); MapInfoExample.Criteria criteria = example.createCriteria().andStatusEqualTo(MapStatus.Online.getCode()); @@ -223,7 +213,7 @@ public class Training2RuleService { List> publishTrainingIdList = publishedTraining2DAO.selectTrainingByRuleId( ruleIdList, mapList.stream().map(MapInfo::getId).collect(Collectors.toList())); Map> publishTrainingIdMap = publishTrainingIdList.stream().collect( - Collectors.groupingBy(m -> m.get("mapId"), Collectors.mapping(m -> m.get("id") , Collectors.toList()))); + Collectors.groupingBy(m -> m.get("mapId"), Collectors.mapping(m -> m.get("id"), Collectors.toList()))); List errorMsgList = new ArrayList<>(); loopMapListGenerateTraining(loginUserInfoVO, mapList, lineCodeRuleMap, errorMsgList, publishTrainingIdMap); @@ -237,7 +227,7 @@ public class Training2RuleService { List errorMsgList = new ArrayList<>(); mapRuleIdMap.forEach((k, v) -> { // 地图信息 - MapInfo mapInfo = mapInfoDAO.selectByPrimaryKey(k); + MapInfo mapInfo = mapInfoDAO.selectByPrimaryKey(k); // 规则列表 RtsTraining2RuleExample rtsTraining2RuleExample = new RtsTraining2RuleExample(); rtsTraining2RuleExample.createCriteria().andIdIn(v).andLineCodeEqualTo(mapInfo.getLineCode()); @@ -246,8 +236,8 @@ public class Training2RuleService { // 获取客户端参数 List entities = getRtsMapFunctions(k); if (!CollectionUtils.isEmpty(entities)) { - List> ruleNameMapList = ruleList.stream().map(r -> { - Map map = new HashMap<>(); + List> ruleNameMapList = ruleList.stream().map(r -> { + Map map = new HashMap<>(); map.put("ruleName", r.getName()); map.put("client", r.getClient()); return map; @@ -255,7 +245,7 @@ public class Training2RuleService { // 需要删除的列表 List delTrainingIdList = publishedTraining2DAO.selectTrainingIdByRuleNameAndMapId(ruleNameMapList, k); try { - Simulation simulation = simulationService.createSimulationPojo(entities.get(0).getId(), loginUserInfoVO, false); + Simulation simulation = simulationService.createSimulation(entities.get(0).getId(), loginUserInfoVO, false); errorMsgList.addAll(generateTraining(simulation, ruleList, delTrainingIdList, delPublishTrainingByIds)); } catch (Exception e) { log.error("创建仿真失败", e); @@ -288,7 +278,7 @@ public class Training2RuleService { bloBs.setId(rule.getId()); bloBs.setScoreRule(JsonUtils.writeValueAsString(detailVOList)); return bloBs; - }).collect(Collectors.toList()); + }).collect(Collectors.toList()); rtsTraining2RuleMapper.updateScoreRule(ruleScoreList); } @@ -302,7 +292,7 @@ public class Training2RuleService { List entities = getRtsMapFunctions(mapInfo.getId()); if (!CollectionUtils.isEmpty(entities) && !CollectionUtils.isEmpty(lineCodeRuleMap.get(mapInfo.getLineCode()))) { try { - Simulation simulation = simulationService.createSimulationPojo(entities.get(0).getId(), loginUserInfoVO, false); + Simulation simulation = simulationService.createSimulation(entities.get(0).getId(), loginUserInfoVO, false); if (CollectionUtils.isEmpty(deleteTrainingIdMap)) { errorMsgList.addAll(generateTraining(simulation, lineCodeRuleMap.get(mapInfo.getLineCode()), null, delPublishTrainingByMapId)); } else { @@ -318,8 +308,9 @@ public class Training2RuleService { /** * 生成实训方法 - * @param simulation 对应地图仿真 - * @param ruleList 生成规则 + * + * @param simulation 对应地图仿真 + * @param ruleList 生成规则 * @param delTrainingIds 要删除已发布的实训ID * @param delConsumer 删除实训方法 * @return @@ -358,11 +349,11 @@ public class Training2RuleService { publishedTraining2DAO.insertList(training2WithBLOBs); } catch (RuntimeException e) { log.error("实训反序列化失败", e); - errorMsgList.add(String.format("地图%d实训[%s]反序列化,实训ID【%d】", mapId, rule.getName(), rule.getId(),Locale.ENGLISH)); + errorMsgList.add(String.format("地图%d实训[%s]反序列化,实训ID【%d】", mapId, rule.getName(), rule.getId(), Locale.ENGLISH)); } catch (Exception e) { log.error("实训生成失败", e); errorMsgList.add(String.format("地图%d实训[%s]生成失败,设备信息【%s】,原因:%s", mapId, - rule.getName(), rule.getDeviceRule(),e.getMessage(),Locale.ENGLISH)); + rule.getName(), rule.getDeviceRule(), e.getMessage(), Locale.ENGLISH)); } } } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationService.java index 665a26097..9a21e5d99 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationService.java @@ -6,7 +6,6 @@ import club.joylink.rtss.simulation.vo.SimulationInfoVO; import club.joylink.rtss.vo.AccountVO; import club.joylink.rtss.vo.LoginUserInfoVO; import club.joylink.rtss.vo.client.PageVO; -import club.joylink.rtss.vo.client.mapFunction.MapFunctionVO; import club.joylink.rtss.vo.client.simulationv1.RunAsPlanParam; import club.joylink.rtss.vo.client.simulationv1.SimulationInfoQueryVO; import lombok.NonNull; @@ -18,9 +17,7 @@ public interface SimulationService { /** * 创建仿真 */ - String createSimulation(long mapId, MapFunctionVO mapFunctionVO, @NonNull LoginUserInfoVO loginUserInfoVO, Map createUserType); - - String createSimulation(Long mapFunctionId, LoginUserInfoVO loginInfo); + String createSimulation(long mapId, SimulationWorkParamVO workParamVO, @NonNull LoginUserInfoVO loginUserInfoVO); /** * 给仿真添加功能 @@ -44,7 +41,8 @@ public interface SimulationService { /** * 根据地图和功能ID获取仿真GroupId - * @param mapId 地图ID + * + * @param mapId 地图ID * @param mapFunctionId 功能ID * @return 仿真GroupId */ @@ -53,7 +51,8 @@ public interface SimulationService { /** * 根据地图和功能ID获取仿真GroupId返回仿真对象 - * @param mapId 地图ID + * + * @param mapId 地图ID * @param mapFunctionId 功能ID * @return 仿真GroupId */ @@ -64,17 +63,15 @@ public interface SimulationService { */ void monitor(String simulationId, AccountVO user); - Simulation createSimulationPojo(long mapId, MapFunctionVO mapFunctionVO, @NonNull LoginUserInfoVO loginUserInfoVO, Map createUserType); - /** * 后台创建仿真 * * @param mapFunctionId mapFunctionId 功能ID - * @param loginInfo 登录信息 - * @param checkAuth 是否检查权限 + * @param loginInfo 登录信息 + * @param checkAuth 是否检查权限 * @return 仿真对象 */ - Simulation createSimulationPojo(Long mapFunctionId, LoginUserInfoVO loginInfo, boolean checkAuth); + Simulation createSimulation(Long mapFunctionId, LoginUserInfoVO loginInfo, boolean checkAuth); void loadDraftRunPlan(String simulationId, long draftRunPlanId); diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationServiceImpl.java b/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationServiceImpl.java index ac701a897..c59bae9d4 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationServiceImpl.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationServiceImpl.java @@ -80,19 +80,20 @@ public class SimulationServiceImpl implements SimulationService { @Override - public String createSimulation(long mapId, MapFunctionVO mapFunctionVO, @NonNull LoginUserInfoVO loginUserInfoVO, Map createUserType) { - return createSimulationPojo(mapId,mapFunctionVO, loginUserInfoVO, createUserType).getId(); + public String createSimulation(long mapId, SimulationWorkParamVO workParamVO, @NonNull LoginUserInfoVO loginUserInfoVO) { + BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertNotTrue(workParamVO.containsRealDeviceItem(), "此途径创建的仿真不能连接真实设备"); + return createSimulation(mapId, null, workParamVO, loginUserInfoVO, null).getId(); } //只获取所有与该功能相关的权限信息 - private List filterUserPermission(List subjectVOList, MapFunctionVO functionVO, LoginUserInfoVO loginUserInfoVO){ + private List filterUserPermission(List subjectVOList, MapFunctionVO functionVO, LoginUserInfoVO loginUserInfoVO) { List newVoList = Lists.newArrayList(); for (PermissionSubjectVO subjectVO : subjectVOList) { - if(subjectVO.getStartTime().isAfter(LocalDateTime.now())){ - log.info("权限主体id:[{}] 用户id:[{}] 开始时间:[{}]未到时间",subjectVO.getId(),subjectVO.getSubjectId(),subjectVO.getStartTime()); + if (subjectVO.getStartTime().isAfter(LocalDateTime.now())) { + log.info("权限主体id:[{}] 用户id:[{}] 开始时间:[{}]未到时间", subjectVO.getId(), subjectVO.getSubjectId(), subjectVO.getStartTime()); continue; } - if(!CollectionUtils.isEmpty(subjectVO.getSystemAbilityList())){ + if (!CollectionUtils.isEmpty(subjectVO.getSystemAbilityList())) { /* if(Objects.equals(PermissionTypeEnum.PROJECT.getValue(),subjectVO.getPermissionType())){ if(Objects.equals(subjectVO.getPermissionProjectCode(),loginUserInfoVO.getProject().toLowerCase())){ newVoList.add(subjectVO); @@ -103,15 +104,15 @@ public class SimulationServiceImpl implements SimulationService { newVoList.add(subjectVO); } }else{*/ - for (PermissionSystemAbilityVO permissionSystemAbilityVO : subjectVO.getSystemAbilityList()) { - if(Objects.equals(permissionSystemAbilityVO.getAbilityId(), functionVO.getId())) { - newVoList.add(subjectVO); - break; - } + for (PermissionSystemAbilityVO permissionSystemAbilityVO : subjectVO.getSystemAbilityList()) { + if (Objects.equals(permissionSystemAbilityVO.getAbilityId(), functionVO.getId())) { + newVoList.add(subjectVO); + break; } + } // } - }else { - log.error("权限主体对应的功能是空 主体id:[{}],subjectId:[{}],subjectType:[{}]",subjectVO.getId(),subjectVO.getSubjectId(),subjectVO.getSubjectType()); + } else { + log.error("权限主体对应的功能是空 主体id:[{}],subjectId:[{}],subjectType:[{}]", subjectVO.getId(), subjectVO.getSubjectId(), subjectVO.getSubjectType()); } } return newVoList; @@ -119,122 +120,71 @@ public class SimulationServiceImpl implements SimulationService { /** * 检测用户对应的权限是否满足 + * * @param functionVO * @param loginInfo - */ - private Map checkUserPermission(MapFunctionVO functionVO, LoginUserInfoVO loginInfo){ - if(loginInfo.getAccountVO().isAdmin()){ + private Map checkUserPermission(MapFunctionVO functionVO, LoginUserInfoVO loginInfo) { + if (loginInfo.getAccountVO().isAdmin()) { return Collections.emptyMap(); } LoginUserInfoVO newLoginUser = loginInfo; - if(loginInfo.getAccountVO().isThirdChildAccount()){ + if (loginInfo.getAccountVO().isThirdChildAccount()) { AccountVO user = this.iSysUserService.queryUserByAccountForMaster(loginInfo.getAccountVO().getParentAccount()); - BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(Objects.nonNull(user),"未找到主账号相关权限"); + BusinessExceptionAssertEnum.DATA_NOT_EXIST.assertTrue(Objects.nonNull(user), "未找到主账号相关权限"); newLoginUser = new LoginUserInfoVO(); user.setCompanyId(loginInfo.getAccountVO().getCompanyId()); newLoginUser.setAccountVO(user); newLoginUser.setProjectInfo(loginInfo.getProjectInfo()); } - List subjectVOList = this.subjectService.findPermissionWithMapIdAndUserInfo(functionVO.getMapId(),newLoginUser); + List subjectVOList = this.subjectService.findPermissionWithMapIdAndUserInfo(functionVO.getMapId(), newLoginUser); - List newVOLIst = this.filterUserPermission(subjectVOList,functionVO,newLoginUser); - if(CollectionUtils.isEmpty(newVOLIst)){ - log.error("未找到对应的权限数据mapId[{}],functionId[{}],userId[{}]",functionVO.getMapId(),functionVO.getId(),newLoginUser.getAccountVO().getId()); - BusinessExceptionAssertEnum.INSUFFICIENT_PERMISSIONS.assertNotTrue(true,"未找到该权限"); + List newVOLIst = this.filterUserPermission(subjectVOList, functionVO, newLoginUser); + if (CollectionUtils.isEmpty(newVOLIst)) { + log.error("未找到对应的权限数据mapId[{}],functionId[{}],userId[{}]", functionVO.getMapId(), functionVO.getId(), newLoginUser.getAccountVO().getId()); + BusinessExceptionAssertEnum.INSUFFICIENT_PERMISSIONS.assertNotTrue(true, "未找到该权限"); } - Map resultMap2 = Maps.newHashMap(); - Map> subjectMapList = newVOLIst.stream().collect(Collectors.groupingBy(PermissionSubjectVO::getSubjectType)); + Map resultMap2 = Maps.newHashMap(); + Map> subjectMapList = newVOLIst.stream().collect(Collectors.groupingBy(PermissionSubjectVO::getSubjectType)); for (PermissionSubjectTypeEnum st : PermissionSubjectTypeEnum.SORT_ENUM) { List tmpSubjectVOList = subjectMapList.get(st.name()); - if(CollectionUtils.isEmpty(tmpSubjectVOList)){ + if (CollectionUtils.isEmpty(tmpSubjectVOList)) { continue; } - List canUseSubjectList = this.findCanUsedPermission(tmpSubjectVOList,functionVO,loginInfo); - BusinessExceptionAssertEnum.INSUFFICIENT_PERMISSIONS.assertNotTrue(CollectionUtils.isEmpty(canUseSubjectList),"该权限过期"); + List canUseSubjectList = this.findCanUsedPermission(tmpSubjectVOList, functionVO, loginInfo); + BusinessExceptionAssertEnum.INSUFFICIENT_PERMISSIONS.assertNotTrue(CollectionUtils.isEmpty(canUseSubjectList), "该权限过期"); for (PermissionSubjectVO subjectVO : canUseSubjectList) { - String key = String.format("%s-%s",st.name(),subjectVO.getId()); + String key = String.format("%s-%s", st.name(), subjectVO.getId()); List findSimList = this.simulationManager.finder(key); - resultMap2.put(key,false); - if(findSimList.size() +1 <= subjectVO.getAmount()){ - resultMap2.put(key,true); + resultMap2.put(key, false); + if (findSimList.size() + 1 <= subjectVO.getAmount()) { + resultMap2.put(key, true); break; } } - if(resultMap2.values().stream().anyMatch(d->Objects.equals(true,d))){ + if (resultMap2.values().stream().anyMatch(d -> Objects.equals(true, d))) { break; } } - BusinessExceptionAssertEnum.INSUFFICIENT_PERMISSIONS.assertNotTrue(resultMap2.values().stream().allMatch(d->Objects.equals(false,d)),"仿真生成数量过载"); + BusinessExceptionAssertEnum.INSUFFICIENT_PERMISSIONS.assertNotTrue(resultMap2.values().stream().allMatch(d -> Objects.equals(false, d)), "仿真生成数量过载"); return resultMap2; } - private List findCanUsedPermission(List newVOLIst, MapFunctionVO functionVO, LoginUserInfoVO loginInfo){ - List canUseSubjectList = newVOLIst.stream().filter(d->Objects.equals(true,d.getForever())).collect(Collectors.toList()); - if(CollectionUtils.isEmpty(canUseSubjectList)){ - List timeOverIdList = newVOLIst.stream().filter(d->Objects.nonNull(d.getEndTime()) && d.getEndTime().isAfter(LocalDateTime.now())) - .map(d->d.getId()) + private List findCanUsedPermission(List newVOLIst, MapFunctionVO functionVO, LoginUserInfoVO loginInfo) { + List canUseSubjectList = newVOLIst.stream().filter(d -> Objects.equals(true, d.getForever())).collect(Collectors.toList()); + if (CollectionUtils.isEmpty(canUseSubjectList)) { + List timeOverIdList = newVOLIst.stream().filter(d -> Objects.nonNull(d.getEndTime()) && d.getEndTime().isAfter(LocalDateTime.now())) + .map(d -> d.getId()) .collect(Collectors.toList()); - if(CollectionUtils.isEmpty(timeOverIdList)){ - log.error("mapId[{}],functionId[{}] userId[{}] 权限过期",functionVO.getMapId(),functionVO.getId(),loginInfo.getAccountVO().getId()); + if (CollectionUtils.isEmpty(timeOverIdList)) { + log.error("mapId[{}],functionId[{}] userId[{}] 权限过期", functionVO.getMapId(), functionVO.getId(), loginInfo.getAccountVO().getId()); return Collections.emptyList(); } - canUseSubjectList = newVOLIst.stream().filter(d->timeOverIdList.contains(d.getId())).collect(Collectors.toList()); + canUseSubjectList = newVOLIst.stream().filter(d -> timeOverIdList.contains(d.getId())).collect(Collectors.toList()); } return canUseSubjectList; } - private boolean checkUserPermissionDetail(List newVOLIst, MapFunctionVO functionVO, LoginUserInfoVO loginInfo){ - boolean isForever = newVOLIst.stream().anyMatch(d->Objects.equals(true,d.getForever())); - if(Objects.equals(false,isForever)){ - boolean timeOver = newVOLIst.stream().allMatch(d->Objects.nonNull(d.getEndTime()) && d.getEndTime().isBefore(LocalDateTime.now())); - if(timeOver){ - log.error("mapId[{}],functionId[{}] userId[{}] 权限过期",functionVO.getMapId(),functionVO.getId(),loginInfo.getAccountVO().getId()); -// BusinessExceptionAssertEnum.INSUFFICIENT_PERMISSIONS.assertNotTrue(timeOver,"该权限过期"); - return false; - } - return true; - } - return true; - } - - private String checkUserExistSimulation(MapFunctionVO mapFunctionVO, AccountVO user){ - List userExistGroup = this.groupSimulationService.getUserRunningSimulationGroups(user); - if(!CollectionUtils.isEmpty(userExistGroup)){ - Optional optional = userExistGroup.stream() - .map(d->this.groupSimulationService.getSimulationByGroup(d)) - .filter(d->Objects.equals(d.getMapFunctionId(), mapFunctionVO.getId())).findAny(); - if(optional.isPresent()){ - BusinessExceptionAssertEnum.OPERATION_REPEAT.assertNotTrue(mapFunctionVO.getParamVO().getDomConfig().isHasExam(),"考试只能单独用户操作"); - Simulation simulation = optional.get(); - return simulation.getId(); - } - BusinessExceptionAssertEnum.OPERATION_REPEAT.assertNotTrue(userExistGroup.size() >= 1,"用户重复创建仿真"); - } - return null; - } - @Override - public String createSimulation(Long mapFunctionId, LoginUserInfoVO loginInfo) { - MapFunctionVO mapFunctionVO = rtsMapFunctionService.get(mapFunctionId); -/* String group = this.checkUserExistSimulation(mapFunctionVO,loginInfo.getAccountVO()); - if(StringUtils.isNotEmpty(group)){ - return group; - }*/ - Long mapId = mapFunctionVO.getMapId(); - Map createUserType = this.checkUserPermission(mapFunctionVO,loginInfo); - SimulationWorkParamVO workParamVO = mapFunctionVO.getParamVO(); - - if (workParamVO.containsRealDeviceItem()) { - //有实体设备加载项的地图功能(实训室)同时只能存在一个 - Stream stream = simulationManager.getSimulationStream(Simulation.class); - Optional oldSimulationOptional = stream - .filter(sim -> Objects.equals(sim.getMapFunctionId(), mapFunctionId)) - .findFirst(); - oldSimulationOptional.ifPresent(simulation -> simulationManager.destroy(simulation.getId())); - } - - return createSimulation(mapId, mapFunctionVO, loginInfo,createUserType); - } @Override public void addItems(@NonNull String simulationId, Map itemMap) { @@ -285,7 +235,7 @@ public class SimulationServiceImpl implements SimulationService { /** * 根据地图、功能ID获取仿真ID * - * @param mapId 地图ID + * @param mapId 地图ID * @param mapFunctionId 功能ID * @return 仿真ID */ @@ -316,9 +266,8 @@ public class SimulationServiceImpl implements SimulationService { simulationWorkServiceManager.addSimulationUser(simulation, simulationUser); } - @Override - public Simulation createSimulationPojo(long mapId, MapFunctionVO mapFunctionVO, @NonNull LoginUserInfoVO loginUserInfoVO, Map createUserType) { - SimulationWorkParamVO workParamVO = mapFunctionVO.getParamVO(); + private Simulation createSimulation(long mapId, MapFunctionVO mapFunctionVO, @NonNull SimulationWorkParamVO workParamVO, + @NonNull LoginUserInfoVO loginUserInfoVO, Map createUserType) { //获取仿真工作服务 SimulationWorkService initService = simulationWorkServiceManager.getWorkService(workParamVO.getType()); @@ -359,12 +308,12 @@ public class SimulationServiceImpl implements SimulationService { } @Override - public Simulation createSimulationPojo(Long mapFunctionId, LoginUserInfoVO loginInfo, boolean checkAuth) { + public Simulation createSimulation(Long mapFunctionId, LoginUserInfoVO loginInfo, boolean checkAuth) { MapFunctionVO mapFunctionVO = rtsMapFunctionService.get(mapFunctionId); Long mapId = mapFunctionVO.getMapId(); - Map createUserType = Maps.newHashMap(); + Map createUserType = Maps.newHashMap(); if (checkAuth) { - createUserType = this.checkUserPermission(mapFunctionVO,loginInfo); + createUserType = this.checkUserPermission(mapFunctionVO, loginInfo); } SimulationWorkParamVO workParamVO = mapFunctionVO.getParamVO(); @@ -377,7 +326,7 @@ public class SimulationServiceImpl implements SimulationService { oldSimulationOptional.ifPresent(simulation -> simulationManager.destroy(simulation.getId())); } - return createSimulationPojo(mapId, mapFunctionVO, loginInfo, createUserType); + return createSimulation(mapId, mapFunctionVO, mapFunctionVO.getParamVO(), loginInfo, createUserType); } @Override