赛题模块训练接口调试修改
This commit is contained in:
parent
7fb4199e1b
commit
cbb52ddbd7
|
@ -2,14 +2,12 @@ package club.joylink.rtss.bo.race;
|
|||
|
||||
import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
|
||||
import club.joylink.rtss.vo.race.RaceApplication;
|
||||
import club.joylink.rtss.vo.race.RaceApplication.ResultNode;
|
||||
import club.joylink.rtss.vo.race.RaceApplication.ResultNode.Builder;
|
||||
import club.joylink.rtss.vo.race.RaceTask;
|
||||
import club.joylink.rtss.vo.race.RaceTask.RacePaperSingleModuleGroupTask;
|
||||
import club.joylink.rtss.vo.race.RaceTask.RaceTaskChildVO;
|
||||
import club.joylink.rtss.vo.race.RaceTask.RaceTaskChildVO.ChildNodeType;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import lombok.Data;
|
||||
|
||||
|
@ -43,8 +41,17 @@ public class RaceContent {
|
|||
this.taskTree = taskTree;
|
||||
this.result = RaceApplication.RacePracticeResult.newBuilder();
|
||||
result.setCustomModuleId(taskTree.getCustomModuleId());
|
||||
List<Builder> nodeBuilderList = result.getNodeBuilderList();
|
||||
buildResultNodeTree(taskTree.getChildList(), nodeBuilderList);
|
||||
for (RaceTaskChildVO childVO : taskTree.getChildList()) {
|
||||
Builder nodeBuilder = result.addNodeBuilder();
|
||||
nodeBuilder.setName(childVO.getName());
|
||||
nodeBuilder.setType(childVO.getNodeType());
|
||||
//构建任务映射
|
||||
if (ChildNodeType.TASK == childVO.getNodeType()) {
|
||||
resultNodeMap.put(childVO.getId(), nodeBuilder);
|
||||
}
|
||||
//递归
|
||||
buildResultNodeTree(childVO, nodeBuilder);
|
||||
}
|
||||
}
|
||||
|
||||
public Builder getResultNode(long taskId) {
|
||||
|
@ -54,20 +61,18 @@ public class RaceContent {
|
|||
return builder;
|
||||
}
|
||||
|
||||
private void buildResultNodeTree(List<RaceTaskChildVO> childrenList,
|
||||
List<Builder> nodeBuilderList) {
|
||||
for (RaceTaskChildVO childVO : childrenList) {
|
||||
private void buildResultNodeTree(RaceTaskChildVO children, Builder parentNode) {
|
||||
for (RaceTaskChildVO childVO : children.getChildrenList()) {
|
||||
//构建对应的结果Node
|
||||
Builder nodeBuilder = ResultNode.newBuilder();
|
||||
Builder nodeBuilder = parentNode.addChildBuilder();
|
||||
nodeBuilder.setName(childVO.getName());
|
||||
nodeBuilder.setType(childVO.getNodeType());
|
||||
nodeBuilderList.add(nodeBuilder);
|
||||
//构建任务映射
|
||||
if (ChildNodeType.TASK == childVO.getNodeType()) {
|
||||
resultNodeMap.put(childVO.getId(), nodeBuilder);
|
||||
}
|
||||
//递归
|
||||
buildResultNodeTree(childVO.getChildrenList(), nodeBuilder.getChildBuilderList());
|
||||
buildResultNodeTree(childVO, nodeBuilder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,9 +3,12 @@ package club.joylink.rtss.controller.racetr;
|
|||
import club.joylink.rtss.services.race.RaceApplicationService;
|
||||
import club.joylink.rtss.vo.AccountVO;
|
||||
import club.joylink.rtss.vo.LoginUserInfoVO;
|
||||
import club.joylink.rtss.vo.paper.PaperTrainAnswerDetail;
|
||||
import club.joylink.rtss.vo.race.RaceApplication;
|
||||
import club.joylink.rtss.vo.race.RaceTask;
|
||||
import club.joylink.rtss.vo.race.RaceTaskFinishParamDTO;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import java.util.List;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
|
@ -19,6 +22,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|||
*/
|
||||
@RestController
|
||||
@RequestMapping("/api/race")
|
||||
@AllArgsConstructor
|
||||
public class RaceApplicationController {
|
||||
|
||||
private RaceApplicationService raceApplicationService;
|
||||
|
@ -32,8 +36,8 @@ public class RaceApplicationController {
|
|||
* @return 训练的信息
|
||||
*/
|
||||
@PostMapping("/{paperId}/{moduleId}")
|
||||
public Object start(@PathVariable long paperId, @PathVariable int moduleId,
|
||||
@RequestAttribute AccountVO user) {
|
||||
public RaceTask.RacePaperSingleModuleGroupTask start(@PathVariable long paperId,
|
||||
@PathVariable int moduleId, @RequestAttribute AccountVO user) {
|
||||
return raceApplicationService.start(paperId, moduleId, user.getId());
|
||||
}
|
||||
|
||||
|
@ -54,11 +58,12 @@ public class RaceApplicationController {
|
|||
*
|
||||
* @param taskId 任务ID
|
||||
* @param paramDTO 完成任务所需的参数。主要就是需要前端做判定的操作/步骤
|
||||
* @return
|
||||
*/
|
||||
@PutMapping("/{taskId}/finish")
|
||||
public void finishTask(@PathVariable long taskId, @RequestBody RaceTaskFinishParamDTO paramDTO,
|
||||
@RequestAttribute AccountVO user) {
|
||||
raceApplicationService.finishTask(taskId, paramDTO, user);
|
||||
public List<PaperTrainAnswerDetail> finishTask(@PathVariable long taskId,
|
||||
@RequestBody RaceTaskFinishParamDTO paramDTO, @RequestAttribute AccountVO user) {
|
||||
return raceApplicationService.finishTask(taskId, paramDTO, user);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -66,20 +71,21 @@ public class RaceApplicationController {
|
|||
*
|
||||
* @return 评分结果
|
||||
*/
|
||||
@PutMapping("/finish")
|
||||
public RaceApplication.RacePracticeResult finish(@RequestAttribute AccountVO user) {
|
||||
return raceApplicationService.finish(user.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户正在进行的竞赛信息
|
||||
* <p>
|
||||
* 目前想到的使用场景就是页面刷新后
|
||||
*
|
||||
* @return 竞赛信息
|
||||
*/
|
||||
@GetMapping("")
|
||||
public Object getRaceInfo() {
|
||||
return null;
|
||||
}
|
||||
// /**
|
||||
// * 获取用户正在进行的竞赛信息
|
||||
// * <p>
|
||||
// * 目前想到的使用场景就是页面刷新后
|
||||
// *
|
||||
// * @return 竞赛信息
|
||||
// */
|
||||
// @GetMapping("")
|
||||
// public Object getRaceInfo() {
|
||||
// return null;
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
package club.joylink.rtss.services.race;
|
||||
|
||||
import club.joylink.rtss.bo.race.RaceContent;
|
||||
import club.joylink.rtss.entity.racetr.RacetrScene;
|
||||
import club.joylink.rtss.entity.training2.DraftTraining2WithBLOBs;
|
||||
import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
|
||||
import club.joylink.rtss.services.training2.Training2Service;
|
||||
import club.joylink.rtss.simulation.cbtc.GroupSimulationService;
|
||||
import club.joylink.rtss.simulation.cbtc.SimulationLifeCycleService;
|
||||
import club.joylink.rtss.simulation.cbtc.member.MemberManager;
|
||||
import club.joylink.rtss.simulation.cbtc.training2.Training2.Type;
|
||||
import club.joylink.rtss.util.JsonUtils;
|
||||
import club.joylink.rtss.vo.AccountVO;
|
||||
import club.joylink.rtss.vo.LoginUserInfoVO;
|
||||
|
@ -16,25 +15,20 @@ import club.joylink.rtss.vo.race.RaceApplication.ResultNode.Builder;
|
|||
import club.joylink.rtss.vo.race.RaceSceneOuterClass;
|
||||
import club.joylink.rtss.vo.race.RaceTask;
|
||||
import club.joylink.rtss.vo.race.RaceTaskFinishParamDTO;
|
||||
import club.joylink.rtss.websocket.StompMessageService;
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class RaceApplicationService {
|
||||
|
||||
private RacePaperService racePaperService;
|
||||
private GroupSimulationService groupSimulationService;
|
||||
private MemberManager memberManager;
|
||||
private SimulationLifeCycleService simulationLifeCycleService;
|
||||
private ApplicationContext applicationContext;
|
||||
private StompMessageService stompMessageService;
|
||||
private Training2Service training2Service;
|
||||
private RaceSceneService raceSceneService;
|
||||
|
||||
|
@ -58,45 +52,52 @@ public class RaceApplicationService {
|
|||
}
|
||||
|
||||
public void loadScene(String simulationId, long sceneId, LoginUserInfoVO loginInfo) {
|
||||
RaceContent content = getContent(loginInfo.getAccountVO().getId());
|
||||
//获取场景数据
|
||||
RaceSceneOuterClass.StorageSimulation scene;
|
||||
RacetrScene scene = raceSceneService.findById(sceneId);
|
||||
RaceSceneOuterClass.StorageSimulation sceneProto;
|
||||
try {
|
||||
scene = RaceSceneOuterClass.Scene
|
||||
.parseFrom(raceSceneService.findById(sceneId).getProto()).getStorageSimulation();
|
||||
sceneProto = RaceSceneOuterClass.Scene.parseFrom(scene.getProto()).getStorageSimulation();
|
||||
} catch (InvalidProtocolBufferException e) {
|
||||
throw BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.exception("场景数据解析出错", e);
|
||||
}
|
||||
//场景数据转实训数据
|
||||
DraftTraining2WithBLOBs draftTraining2 = new DraftTraining2WithBLOBs();
|
||||
draftTraining2.setBgSceneJson(scene.getBgSceneJson());
|
||||
// draftTraining2.setOperaJson(scene.get); operaJson没了
|
||||
draftTraining2.setStepJson(scene.getStepJson());
|
||||
draftTraining2.setScoringRuleJson(scene.getScoringRuleJson());
|
||||
draftTraining2.setMemberJson(scene.getMemberJson());
|
||||
draftTraining2.setPlayerIdJson(JsonUtils.writeValueAsString(scene.getPlayerIdsList()));
|
||||
// draftTraining2.setClient(scene); client没了
|
||||
training2Service.trainingDataValid.accept(draftTraining2);
|
||||
draftTraining2.setName(scene.getName());
|
||||
draftTraining2.setBgSceneJson(sceneProto.getBgSceneJson());
|
||||
// draftTraining2.setOperaJson(sceneProto.get); operaJson没了
|
||||
draftTraining2.setStepJson(sceneProto.getStepJson());
|
||||
draftTraining2.setScoringRuleJson(sceneProto.getScoringRuleJson());
|
||||
draftTraining2.setMemberJson(sceneProto.getMemberJson());
|
||||
draftTraining2.setPlayerIdJson(JsonUtils.writeValueAsString(sceneProto.getPlayerIdsList()));
|
||||
// draftTraining2.setClient(sceneProto); client没了
|
||||
draftTraining2.setType(Type.SCENE.name()); //数据里没存,暂时固定用此类型
|
||||
training2Service.trainingDataValid(draftTraining2);
|
||||
//加载实训
|
||||
training2Service.simulationLoadTraining(simulationId, draftTraining2, loginInfo);
|
||||
}
|
||||
|
||||
public void finishTask(long taskId, RaceTaskFinishParamDTO paramDTO, AccountVO user) {
|
||||
public List<PaperTrainAnswerDetail> finishTask(long taskId, RaceTaskFinishParamDTO paramDTO,
|
||||
AccountVO user) {
|
||||
if (paramDTO == null) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
RaceContent content = getContent(user.getId());
|
||||
List<PaperTrainAnswerDetail> result = training2Service.finishTraining2(
|
||||
paramDTO.getSimulationId(), user, paramDTO.getScoreList());
|
||||
Builder resultNode = content.getResultNode(taskId);
|
||||
int fullScore = 0;
|
||||
int score = 0;
|
||||
float fullScore = 0;
|
||||
float score = 0;
|
||||
for (PaperTrainAnswerDetail paperTrainAnswerDetail : result) {
|
||||
fullScore += paperTrainAnswerDetail.getRuleScore();
|
||||
score += paperTrainAnswerDetail.getScore();
|
||||
if (paperTrainAnswerDetail.getRuleScore() != null) {
|
||||
fullScore += paperTrainAnswerDetail.getRuleScore();
|
||||
}
|
||||
if (paperTrainAnswerDetail.getScore() != null) {
|
||||
score += paperTrainAnswerDetail.getScore();
|
||||
}
|
||||
}
|
||||
resultNode.setFullScore(fullScore);
|
||||
resultNode.setScore(score);
|
||||
return result;
|
||||
}
|
||||
|
||||
public RacePracticeResult finish(long userId) {
|
||||
|
|
|
@ -938,6 +938,13 @@ public class Training2Service {
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 和上面的对象是相同作用,将此Service注入其它Bean后,上面的对象是null
|
||||
*/
|
||||
public void trainingDataValid(DraftTraining2WithBLOBs training) {
|
||||
trainingDataValid.accept(training);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检验语音输入是否正确
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
package club.joylink.rtss.bo.race;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
import club.joylink.rtss.vo.race.RaceApplication.RacePracticeResult;
|
||||
import club.joylink.rtss.vo.race.RaceApplication.ResultNode;
|
||||
import club.joylink.rtss.vo.race.RaceTask.RacePaperSingleModuleGroupTask;
|
||||
import club.joylink.rtss.vo.race.RaceTask.RacePaperSingleModuleGroupTask.Builder;
|
||||
import club.joylink.rtss.vo.race.RaceTask.RaceTaskChildVO;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class RaceContentTest {
|
||||
|
||||
@Test
|
||||
public void newInstance() {
|
||||
Builder builder = RacePaperSingleModuleGroupTask.newBuilder();
|
||||
for (int i = 0; i < 2; i++) {
|
||||
RaceTaskChildVO.Builder childBuilder = builder.addChildBuilder();
|
||||
childBuilder.setId(i);
|
||||
for (int j = 0; j < 3; j++) {
|
||||
childBuilder.addChildren(RaceTaskChildVO.newBuilder().setId(j));
|
||||
}
|
||||
}
|
||||
RaceContent content = new RaceContent(1, 1, 1, builder.build());
|
||||
RacePracticeResult result = content.getResult().build();
|
||||
|
||||
assertNotNull(result);
|
||||
assertEquals(2, result.getNodeList().size());
|
||||
for (ResultNode node : result.getNodeList()) {
|
||||
assertEquals(3, node.getChildList().size());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue