diff --git a/src/main/java/club/joylink/rtss/controller/training2/TrainingDraftV2Controller.java b/src/main/java/club/joylink/rtss/controller/training2/TrainingDraftV2Controller.java index a6718c6a8..aa7a48f2c 100644 --- a/src/main/java/club/joylink/rtss/controller/training2/TrainingDraftV2Controller.java +++ b/src/main/java/club/joylink/rtss/controller/training2/TrainingDraftV2Controller.java @@ -81,9 +81,9 @@ public class TrainingDraftV2Controller { /** * 重置当前用户的某个实训草稿的内容 */ - @DeleteMapping("/reset/{trainingId}") - public void resetTraining(@PathVariable("trainingId") Long trainingId, @RequestAttribute AccountVO user) { - this.training2DraftService.resetTraining(trainingId,user.getId()); + @DeleteMapping("{groupId}/reset/{trainingId}") + public void resetTraining(@PathVariable("groupId") String groupId, @PathVariable("trainingId") Long trainingId, @RequestAttribute AccountVO user) { + this.training2DraftService.resetTraining(groupId, trainingId, user.getId()); } /** diff --git a/src/main/java/club/joylink/rtss/services/training2/Training2DraftService.java b/src/main/java/club/joylink/rtss/services/training2/Training2DraftService.java index dc25ac7eb..e941111dd 100644 --- a/src/main/java/club/joylink/rtss/services/training2/Training2DraftService.java +++ b/src/main/java/club/joylink/rtss/services/training2/Training2DraftService.java @@ -7,6 +7,7 @@ import club.joylink.rtss.entity.training2.DraftTraining2WithBLOBs; import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.simulation.cbtc.GroupSimulationService; import club.joylink.rtss.simulation.cbtc.Simulation; +import club.joylink.rtss.simulation.cbtc.SimulationService; import club.joylink.rtss.simulation.cbtc.data.storage.StorageSimulation; import club.joylink.rtss.simulation.cbtc.exception.SimulationException; import club.joylink.rtss.simulation.cbtc.exception.SimulationExceptionType; @@ -46,6 +47,8 @@ public class Training2DraftService { private DraftTraining2DAO trainingDao; @Autowired private GroupSimulationService groupSimulationService; + @Autowired + private SimulationService simulationService; /** * 根据基本信息创建实训 @@ -136,11 +139,15 @@ public class Training2DraftService { Simulation simulation = this.groupSimulationService.getSimulationByGroup(simulationId); StorageSimulation scenesSaving = new StorageSimulation(simulation, true); //保存背景 - b.setBgSceneJson((JsonUtils.writeValueAsString(scenesSaving))); - b.setMemberJson(JsonUtils.writeValueAsString(SimulationMemberVO.convert2VOList(simulation.getSimulationMembers()))); + String bgSceneJson = JsonUtils.writeValueAsString(scenesSaving); + String memberJson = JsonUtils.writeValueAsString(SimulationMemberVO.convert2VOList(simulation.getSimulationMembers())); + b.setBgSceneJson(bgSceneJson); + b.setMemberJson(memberJson); b.setUpdateTime(LocalDateTime.now()); - // this.trainingDao.updateByExampleSelective(b, example); + //修改仿真中实训信息 + simulation.getTraining2().setBgSceneJson(bgSceneJson); + simulation.getTraining2().setMembersJson(memberJson); } /** @@ -157,15 +164,17 @@ public class Training2DraftService { b.setBgSceneJson(""); b.setFinalScenesJson(""); b.setUpdateTime(LocalDateTime.now()); - // this.trainingDao.updateByExampleSelective(b, example); + // 重置仿真中背景信息 + Simulation simulation = this.groupSimulationService.getSimulationByGroup(req.getGroupId()); + simulation.getTraining2().setBgSceneJson(null); } /** * 重置用户实训草稿 */ @Transactional(rollbackFor = Exception.class) - public void resetTraining(Long trainingId, Long userId) { + public void resetTraining(String groupId, Long trainingId, Long userId) { DraftTraining2Example example = new DraftTraining2Example(); example.createCriteria().andCreatorIdEqualTo(userId).andIdEqualTo(trainingId); List find = this.trainingDao.selectByExample(example); @@ -185,6 +194,15 @@ public class Training2DraftService { b.setStepJson(""); // this.trainingDao.updateByExampleSelective(b, example); + // 重置仿真中背景信息 + Simulation simulation = this.groupSimulationService.getSimulationByGroup(groupId); + simulation.getTraining2().setBgSceneJson(null); + simulation.getTraining2().setMapLocationJson(null); + simulation.getTraining2().setSteps(null); + simulation.getTraining2().setMembersJson(null); + simulation.getTraining2().setPlayerIds(null); + simulation.getTraining2().setScoringRules(null); + simulationService.reset(groupId); } /** diff --git a/src/main/java/club/joylink/rtss/vo/training2/draft/ResetTraining2BackgroudReqVo.java b/src/main/java/club/joylink/rtss/vo/training2/draft/ResetTraining2BackgroudReqVo.java index 1c390d672..484c11353 100644 --- a/src/main/java/club/joylink/rtss/vo/training2/draft/ResetTraining2BackgroudReqVo.java +++ b/src/main/java/club/joylink/rtss/vo/training2/draft/ResetTraining2BackgroudReqVo.java @@ -19,4 +19,7 @@ public class ResetTraining2BackgroudReqVo { @NotBlank(message = "实训草稿id不能为空") @JsonSerialize(using = ToStringSerializer.class) private Long id; + + @NotBlank(message = "仿真id不能为空") + private String groupId; }