【实训执行逻辑、更新步骤参数修改】

This commit is contained in:
weizhihong 2023-02-15 18:13:53 +08:00
parent 6689da99ee
commit e748120a8d
6 changed files with 47 additions and 19 deletions

View File

@ -131,8 +131,8 @@ public class TrainingDraftV2Controller {
*/ */
@PutMapping("/{group}/{trainingId}/step/update") @PutMapping("/{group}/{trainingId}/step/update")
public void updateSteps(@PathVariable("group") String group, @PathVariable("trainingId") Long trainingId public void updateSteps(@PathVariable("group") String group, @PathVariable("trainingId") Long trainingId
, @RequestBody List<Step2VO> step2VOList) { , @RequestBody UpdateStepReqVo reqParam) {
training2DraftService.updateSteps(group, trainingId, step2VOList); training2DraftService.updateSteps(group, trainingId, reqParam);
} }
/** /**

View File

@ -383,7 +383,7 @@ public class Training2DraftService {
* 修改实训所有步骤 * 修改实训所有步骤
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void updateSteps(String group, Long trainingId, List<Step2VO> step2VOList) { public void updateSteps(String group, Long trainingId, UpdateStepReqVo reqParam) {
DraftTraining2WithBLOBs draftTraining2 = trainingDao.selectByPrimaryKey(trainingId); DraftTraining2WithBLOBs draftTraining2 = trainingDao.selectByPrimaryKey(trainingId);
if (draftTraining2 == null) { if (draftTraining2 == null) {
throw new SimulationException(SimulationExceptionType.Data_Not_Exist, "实训不存在"); throw new SimulationException(SimulationExceptionType.Data_Not_Exist, "实训不存在");
@ -392,6 +392,7 @@ public class Training2DraftService {
Simulation simulation = this.groupSimulationService.getSimulationByGroup(group); Simulation simulation = this.groupSimulationService.getSimulationByGroup(group);
DraftTraining2WithBLOBs updateObj = new DraftTraining2WithBLOBs(); DraftTraining2WithBLOBs updateObj = new DraftTraining2WithBLOBs();
updateObj.setId(trainingId); updateObj.setId(trainingId);
List<Step2VO> step2VOList = reqParam.getStep2VOList();
if (CollectionUtils.isEmpty(step2VOList)) { if (CollectionUtils.isEmpty(step2VOList)) {
updateObj.setStepJson(StringUtil.EMPTY_STRING); updateObj.setStepJson(StringUtil.EMPTY_STRING);
updateObj.setScoringRuleJson(StringUtil.EMPTY_STRING); updateObj.setScoringRuleJson(StringUtil.EMPTY_STRING);
@ -404,13 +405,10 @@ public class Training2DraftService {
handleStepId(draftTraining2, step2VOList); handleStepId(draftTraining2, step2VOList);
updateObj.setStepJson(JsonUtils.writeValueAsString(step2VOList)); updateObj.setStepJson(JsonUtils.writeValueAsString(step2VOList));
// 扮演者集合 // 扮演者集合
List<String> playerList = step2VOList.stream(). if (CollectionUtils.isEmpty(reqParam.getPlayerIdList())) {
filter(s -> !StringUtils.isEmpty(s.getMemberId())).map(s -> s.getMemberId())
.distinct().sorted().collect(Collectors.toList());
if (CollectionUtils.isEmpty(playerList)) {
throw new SimulationException(SimulationExceptionType.Data_Not_Exist, "错误数据:无扮演者"); throw new SimulationException(SimulationExceptionType.Data_Not_Exist, "错误数据:无扮演者");
} }
updateObj.setPlayerIdJson(JsonUtils.writeValueAsString(playerList)); updateObj.setPlayerIdJson(JsonUtils.writeValueAsString(reqParam.getPlayerIdList()));
// 背景 // 背景
StorageSimulation scenesSaving = new StorageSimulation(simulation, true); StorageSimulation scenesSaving = new StorageSimulation(simulation, true);
updateObj.setFinalScenesJson(JsonUtils.writeValueAsString(scenesSaving)); updateObj.setFinalScenesJson(JsonUtils.writeValueAsString(scenesSaving));

View File

@ -642,20 +642,22 @@ public class Training2Service {
*/ */
private boolean tryDoOperation(Simulation simulation, Step2 step, Operation2.SimCommand2 operation2) { private boolean tryDoOperation(Simulation simulation, Step2 step, Operation2.SimCommand2 operation2) {
boolean isRobot = step.getSimulationMember().isRobot(); // 角色是否是机器人 boolean isRobot = step.getSimulationMember().isRobot(); // 角色是否是机器人
long simCurTime = simulation.getCorrectSystemTimeStamp();
// 未操作过 // 未操作过
if (Step2.StepStatus.isUndo(operation2.getStatus())) { if (Step2.StepStatus.isUndo(operation2.getStatus())) {
if (isRobot) { boolean isExec = true; // 是否要执行
atsOperationDispatcher.execute(simulation, step.getSimulationMember(), operation2.getOperationType().name() if (operation2.getSimTime() != null) {
, operation2.getParams()); isExec = (simCurTime == operation2.getSimTime() || operation2.getSimTime() < simCurTime);
return true; }
} else { // 非机器人暂停仿真等待用户操作 if (isExec) {
if (operation2.getSimTime() != null) { if (isRobot || operation2.isSpecial()) { // 特殊操作直接执行
long simCurTime = simulation.getCorrectSystemTimeStamp(); atsOperationDispatcher.execute(simulation, step.getSimulationMember(), operation2.getOperationType().name()
// 如果时间到达操作时间或者在1s内则暂停仿真 , operation2.getParams());
if (simCurTime == operation2.getSimTime() || operation2.getSimTime() < simCurTime) { return true;
simulation.onlyPause(); } else { // 非机器人暂停仿真等待用户操作
} simulation.onlyPause();
} }
} else {
return false; return false;
} }
} }

View File

@ -24,6 +24,9 @@ public abstract class Operation2 {
@Setter @Setter
private Expression failureCondition; private Expression failureCondition;
@Setter
boolean special;
/** /**
* 开始时间 * 开始时间
*/ */
@ -151,6 +154,9 @@ public abstract class Operation2 {
if (vo.getFailureCondition() != null) { if (vo.getFailureCondition() != null) {
this.setFailureCondition(vo.getFailureCondition().convert2BO(simulation.getRepository())); this.setFailureCondition(vo.getFailureCondition().convert2BO(simulation.getRepository()));
} }
if (vo.getSpecial() != null) {
this.setSpecial(vo.getSpecial());
}
} }
} }
@ -188,6 +194,9 @@ public abstract class Operation2 {
if (vo.getCompletionCondition() != null) { if (vo.getCompletionCondition() != null) {
this.setCompletionCondition(vo.getCompletionCondition().convert2BO(simulation.getRepository())); this.setCompletionCondition(vo.getCompletionCondition().convert2BO(simulation.getRepository()));
} }
if (vo.getSpecial() != null) {
this.setSpecial(vo.getSpecial());
}
} }
} }
} }

View File

@ -34,6 +34,11 @@ public abstract class Operation2VO {
*/ */
ExpressionVO failureCondition; ExpressionVO failureCondition;
/**
* 特殊操作直接执行
*/
Boolean special;
public abstract Operation2 convert2BO(Simulation simulation); public abstract Operation2 convert2BO(Simulation simulation);
/** /**

View File

@ -0,0 +1,14 @@
package club.joylink.rtss.vo.training2.draft;
import club.joylink.rtss.vo.client.training2.Step2VO;
import lombok.Data;
import java.util.List;
@Data
public class UpdateStepReqVo {
private List<Step2VO> step2VOList;
private List<String> playerIdList;
}