diff --git a/src/main/java/club/joylink/rtss/controller/paper/PaperUserController.java b/src/main/java/club/joylink/rtss/controller/paper/PaperUserController.java index 520ece401..66fbda318 100644 --- a/src/main/java/club/joylink/rtss/controller/paper/PaperUserController.java +++ b/src/main/java/club/joylink/rtss/controller/paper/PaperUserController.java @@ -18,112 +18,119 @@ import java.util.List; @RestController @RequestMapping("/api/v2/paper") public class PaperUserController { - @Autowired - private PaperUserService paperUserService; - @Autowired - private PaperUserCreateService paperUserCreateService; - @Autowired - private PaperUserLoadQuestionService paperUserLoadQuestionService; - @Autowired - private PaperUserSubmitAnswerService paperUserSubmitAnswerService; - @Autowired - private PaperUserFindPageService paperUserFindPageService; - /** - * 根据试卷蓝图生成用户的试卷 - * - * @param pcId 试卷蓝图id - */ - @PostMapping("/{pcId}") - public CreatePaperRspVo createPaper(@PathVariable("pcId") Long pcId, @RequestAttribute AccountVO user) { - return this.paperUserCreateService.createPaper(pcId, user); - } + @Autowired + private PaperUserService paperUserService; + @Autowired + private PaperUserCreateService paperUserCreateService; + @Autowired + private PaperUserLoadQuestionService paperUserLoadQuestionService; + @Autowired + private PaperUserSubmitAnswerService paperUserSubmitAnswerService; + @Autowired + private PaperUserFindPageService paperUserFindPageService; - /** - * 获取用户试卷完整信息 - * - * @param puId 用户试卷id - */ - @GetMapping("/user/{puId}") - public PaperUserWholeVo findPaperUser(@PathVariable("puId") Long puId, @RequestAttribute AccountVO user) { - return this.paperUserService.findPaperUser(puId); - } + /** + * 根据试卷蓝图生成用户的试卷 + * + * @param pcId 试卷蓝图id + */ + @PostMapping("/{pcId}") + public CreatePaperRspVo createPaper(@PathVariable("pcId") Long pcId, + @RequestAttribute AccountVO user) { + return this.paperUserCreateService.createPaper(pcId, user); + } + + /** + * 获取用户试卷完整信息 + * + * @param puId 用户试卷id + */ + @GetMapping("/user/{puId}") + public PaperUserWholeVo findPaperUser(@PathVariable("puId") Long puId, + @RequestAttribute AccountVO user) { + return this.paperUserService.findPaperUser(puId); + } + /** + * 用户交卷 + * + * @param puId 用户试卷id + */ + @PostMapping("/user/{puId}/submit") + public PaperSubmitRspVo paperSubmit(@PathVariable("puId") Long puId, + @RequestAttribute AccountVO user) { + return this.paperUserService.paperSubmit(puId, user); + } - /** - * 用户交卷 - * - * @param puId 用户试卷id - */ - @PostMapping("/user/{puId}/submit") - public PaperSubmitRspVo paperSubmit(@PathVariable("puId") Long puId,@RequestAttribute AccountVO user) { - return this.paperUserService.paperSubmit(puId); - } + /** + * 加载用户试卷试题 + * + * @param groupType 试卷试题大类型:1-理论题,2-实训题 + * @param qId 试题id + * @param puId 试卷id + * @return + */ + @GetMapping("/user/question/{groupType}/{qId}/{puId}") + public PaperQuestionLoadRspVo loadQuestion(@PathVariable("groupType") Integer groupType, + @PathVariable("qId") Long qId, @PathVariable("puId") Long puId, + @RequestAttribute AccountVO user) { + PaperQType.GroupType pgType = PaperQType.GroupType.getItem(groupType); + return this.paperUserLoadQuestionService.loadQuestion(pgType, qId, puId, user); + } - /** - * 加载用户试卷试题 - * @param groupType 试卷试题大类型:1-理论题,2-实训题 - * @param qId 试题id - * @param puId 试卷id - * @return - */ - @GetMapping("/user/question/{groupType}/{qId}/{puId}") - public PaperQuestionLoadRspVo loadQuestion(@PathVariable("groupType") Integer groupType, @PathVariable("qId") Long qId,@PathVariable("puId") Long puId, @RequestAttribute AccountVO user) { - PaperQType.GroupType pgType = PaperQType.GroupType.getItem(groupType); - return this.paperUserLoadQuestionService.loadQuestion(pgType, qId,puId, user); - } + /** + * 用户提交答案 + *

+ * 对于理论题:用户完成一道题提交一道题的答案;
对于实训题:用户完成实训操作后,由实训系统自己评判实训是否成功完成,前端提交实训是否成功完成的结果即可。 + */ + @PostMapping("/user/question/answer") + public PaperSubmitAnswerRspVo submitAnswer(@RequestBody PaperSubmitAnswerReqVo req, + @RequestAttribute AccountVO user) { + return this.paperUserSubmitAnswerService.submitAnswer(req, user); + } - /** - * 用户提交答案 - *

- * 对于理论题:用户完成一道题提交一道题的答案;
- * 对于实训题:用户完成实训操作后,由实训系统自己评判实训是否成功完成,前端提交实训是否成功完成的结果即可。 - */ - @PostMapping("/user/question/answer") - public PaperSubmitAnswerRspVo submitAnswer(@RequestBody PaperSubmitAnswerReqVo req, @RequestAttribute AccountVO user) { - return this.paperUserSubmitAnswerService.submitAnswer(req, user); - } - - /** - * 分页查询某个试卷蓝图的所有用户试卷基本信息 - */ + /** + * 分页查询某个试卷蓝图的所有用户试卷基本信息 + */ /* @PostMapping("/user/page/composition") public PageVO findPaperUserByPage(@RequestBody FindPaperUserForCompositionReqVo req, @RequestAttribute AccountVO user) { return this.paperUserFindPageService.findPaperUserByPage(req); }*/ - /** - * 查看某个班级的某个试卷蓝图的所有学生试卷 - */ - @GetMapping("/user/page") - public PageVO findPaperUserByPageForClass(@ModelAttribute PageUserDetailQuery req) { - return this.paperUserFindPageService.findPaperUserByPageForClass(req); - } + /** + * 查看某个班级的某个试卷蓝图的所有学生试卷 + */ + @GetMapping("/user/page") + public PageVO findPaperUserByPageForClass( + @ModelAttribute PageUserDetailQuery req) { + return this.paperUserFindPageService.findPaperUserByPageForClass(req); + } - /** - * 查看某个班级的某个试卷蓝图的所有学生试卷 (柱状图) - * @param req - * @return - */ - @GetMapping("/user/curve") - public CurveForClassVO curveForClass(@ModelAttribute PageUserDetailQuery req) { - return this.paperUserFindPageService.curveForClass(req); - } + /** + * 查看某个班级的某个试卷蓝图的所有学生试卷 (柱状图) + * + * @param req + * @return + */ + @GetMapping("/user/curve") + public CurveForClassVO curveForClass(@ModelAttribute PageUserDetailQuery req) { + return this.paperUserFindPageService.curveForClass(req); + } - @PostMapping("/question/label") - public Collection paperAllLabel(@RequestBody FindCountForQuestionReqVo req){ - return this.paperUserService.findAllLabel(req); - } + @PostMapping("/question/label") + public Collection paperAllLabel(@RequestBody FindCountForQuestionReqVo req) { + return this.paperUserService.findAllLabel(req); + } - /** - * 查看组织下某个类型题的数量 - * 参数 tags 目前只支持单个 - */ - @PostMapping("/question/count") - public Long findCountForQuestion( @RequestBody FindCountForQuestionReqVo req) { + /** + * 查看组织下某个类型题的数量 参数 tags 目前只支持单个 + */ + @PostMapping("/question/count") + public Long findCountForQuestion(@RequestBody FindCountForQuestionReqVo req) { // req.setOrgId(orgId); - return this.paperUserService.findCountForQuestion(req); - } + return this.paperUserService.findCountForQuestion(req); + } } diff --git a/src/main/java/club/joylink/rtss/services/paper/PaperUserService.java b/src/main/java/club/joylink/rtss/services/paper/PaperUserService.java index a47888179..508fd44a7 100644 --- a/src/main/java/club/joylink/rtss/services/paper/PaperUserService.java +++ b/src/main/java/club/joylink/rtss/services/paper/PaperUserService.java @@ -3,11 +3,13 @@ package club.joylink.rtss.services.paper; import club.joylink.rtss.constants.BusinessConsts; import club.joylink.rtss.dao.PublishedTraining2DAO; import club.joylink.rtss.dao.paper.*; +import club.joylink.rtss.entity.UserExam; import club.joylink.rtss.entity.paper.*; import club.joylink.rtss.entity.paper.question.PaperQuestion; import club.joylink.rtss.entity.paper.question.PaperQuestionExample; import club.joylink.rtss.entity.training2.PublishedTraining2; import club.joylink.rtss.entity.training2.PublishedTraining2Example; +import club.joylink.rtss.event.UserExamRecordEvent; import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.exception.PaperExceptionAssert; import club.joylink.rtss.services.training2.Training2PublishService; @@ -43,101 +45,109 @@ import java.util.stream.Collectors; @Service @Slf4j public class PaperUserService { - @Autowired - private PaperCompositionDAO compositionDAO; - @Autowired - private PaperRuleDAO ruleDAO; - @Autowired - private PaperUserDAO paperUserDAO; - @Autowired - private PaperUserQuestionDAO paperUserQuestionDAO; - @Autowired - private PaperCompositionService compositionService; - @Autowired - private PaperQuestionDAO pagerQuestionDAO; - @Autowired - private PublishedTraining2DAO trainingDAO; - @Autowired - private PagerQuestionService paperQuestionService; - @Autowired - private Training2PublishService training2PublishService; - /** - * 获取理论或实操的所有标签 - * @param req - * @return - */ - public Collection findAllLabel(FindCountForQuestionReqVo req){ - if(req.getGroupType() == PaperQType.GroupType.Common){ - return paperQuestionService.findAllLable(req.getOrgId(),req.getSubType().name().toLowerCase()); - }else if(PaperQType.GroupType.Training.equals(req.getGroupType())){ + @Autowired + private PaperCompositionDAO compositionDAO; + @Autowired + private PaperRuleDAO ruleDAO; + @Autowired + private PaperUserDAO paperUserDAO; + @Autowired + private PaperUserQuestionDAO paperUserQuestionDAO; + @Autowired + private PaperCompositionService compositionService; + @Autowired + private PaperQuestionDAO pagerQuestionDAO; + @Autowired + private PublishedTraining2DAO trainingDAO; + @Autowired + private PagerQuestionService paperQuestionService; + @Autowired + private Training2PublishService training2PublishService; + + /** + * 获取理论或实操的所有标签 + * + * @param req + * @return + */ + public Collection findAllLabel(FindCountForQuestionReqVo req) { + if (req.getGroupType() == PaperQType.GroupType.Common) { + return paperQuestionService.findAllLable(req.getOrgId(), + req.getSubType().name().toLowerCase()); + } else if (PaperQType.GroupType.Training.equals(req.getGroupType())) { // BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertNotTrue(req.getSubType() == PaperQType.SubType.Scene,"不支持此操作"); - return this.training2PublishService.findAllLabel(req.getMapId(),req.getOrgId(),req.getSubType().name().toUpperCase(),req.getTrainingClient()); - } - return Collections.emptyList(); + return this.training2PublishService.findAllLabel(req.getMapId(), req.getOrgId(), + req.getSubType().name().toUpperCase(), req.getTrainingClient()); } - /** - * 获取组织某个类型题的数量 - */ - @Transactional(readOnly = true) - public Long findCountForQuestion(FindCountForQuestionReqVo req){ - if(PaperQType.GroupType.Common.equals(req.getGroupType())){ - String tagStr=req.getTags(); - BusinessConsts.TheoryType theoryType = this.getPaperQuestionType(req.getSubType()); - return paperQuestionService.queryCount(req.getOrgId(),theoryType,tagStr); - }else if(PaperQType.GroupType.Training.equals(req.getGroupType())){ + return Collections.emptyList(); + } + + /** + * 获取组织某个类型题的数量 + */ + @Transactional(readOnly = true) + public Long findCountForQuestion(FindCountForQuestionReqVo req) { + if (PaperQType.GroupType.Common.equals(req.getGroupType())) { + String tagStr = req.getTags(); + BusinessConsts.TheoryType theoryType = this.getPaperQuestionType(req.getSubType()); + return paperQuestionService.queryCount(req.getOrgId(), theoryType, tagStr); + } else if (PaperQType.GroupType.Training.equals(req.getGroupType())) { // PaperExceptionAssert.PdValid.assertTrue(!PaperQType.GroupType.Training.equals(groupType),"不支持查询实训题数量"); - BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertNotTrue(req.getSubType() == PaperQType.SubType.Scene,"不支持此操作"); - return training2PublishService.queryCountForLabel(req); - } - return 0L; - } - /** - * 获取用户试卷完整信息 - * - * @param puId 用户试卷id - */ - @Transactional(readOnly = true) - public PaperUserWholeVo findPaperUser(Long puId) { - PaperUser paper = paperUserDAO.selectByPrimaryKey(puId); - PaperExceptionAssert.PuExisted.assertNotNull(paper, "用户试卷不存在"); - // - PaperComposition composition = compositionDAO.selectByPrimaryKey(paper.getPcId()); - List ruleList = compositionService.findRuleByPcId(composition.getId()); - List userQuestionList = this.findUserSortedQuestions(puId); - // - PaperUserWholeVo rsp = new PaperUserWholeVo(); - rsp.setComposition(PaperCompositionConvertor.convert(composition, ruleList)); - rsp.setPaper(PaperUserConvertor.convert(paper)); - rsp.setQuestionList(userQuestionList.stream().map(PaperUserQuestionConvertor::convert).collect(Collectors.toList())); - rsp.setSystemTime(System.currentTimeMillis()); - return rsp; + BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertNotTrue( + req.getSubType() == PaperQType.SubType.Scene, "不支持此操作"); + return training2PublishService.queryCountForLabel(req); } + return 0L; + } - /** - * 删除用户试卷 - * - * @param puId 用户试卷id - */ - @Transactional(rollbackFor = Exception.class) - public void deletePaperUser(Long puId) { - this.deletePaperQuestion(puId); - //删除试卷 - paperUserDAO.deleteByPrimaryKey(puId); - } + /** + * 获取用户试卷完整信息 + * + * @param puId 用户试卷id + */ + @Transactional(readOnly = true) + public PaperUserWholeVo findPaperUser(Long puId) { + PaperUser paper = paperUserDAO.selectByPrimaryKey(puId); + PaperExceptionAssert.PuExisted.assertNotNull(paper, "用户试卷不存在"); + // + PaperComposition composition = compositionDAO.selectByPrimaryKey(paper.getPcId()); + List ruleList = compositionService.findRuleByPcId(composition.getId()); + List userQuestionList = this.findUserSortedQuestions(puId); + // + PaperUserWholeVo rsp = new PaperUserWholeVo(); + rsp.setComposition(PaperCompositionConvertor.convert(composition, ruleList)); + rsp.setPaper(PaperUserConvertor.convert(paper)); + rsp.setQuestionList(userQuestionList.stream().map(PaperUserQuestionConvertor::convert) + .collect(Collectors.toList())); + rsp.setSystemTime(System.currentTimeMillis()); + return rsp; + } - private void deletePaperQuestion(Long puId){ - //删除试卷试题关联表 - PaperUserQuestionExample puqExample = new PaperUserQuestionExample(); - puqExample.createCriteria().andPuIdEqualTo(puId); - paperUserQuestionDAO.deleteByExample(puqExample); - } + /** + * 删除用户试卷 + * + * @param puId 用户试卷id + */ + @Transactional(rollbackFor = Exception.class) + public void deletePaperUser(Long puId) { + this.deletePaperQuestion(puId); + //删除试卷 + paperUserDAO.deleteByPrimaryKey(puId); + } - /** - * 开始答题 - * - * @param puId 用户试卷id - */ + private void deletePaperQuestion(Long puId) { + //删除试卷试题关联表 + PaperUserQuestionExample puqExample = new PaperUserQuestionExample(); + puqExample.createCriteria().andPuIdEqualTo(puId); + paperUserQuestionDAO.deleteByExample(puqExample); + } + + /** + * 开始答题 + * + * @param puId 用户试卷id + */ /* @Transactional(rollbackFor = Exception.class) public void paperStart(Long puId) { @@ -151,182 +161,193 @@ public class PaperUserService { } */ - /** - * 用户交卷 - * - * @param puId 用户试卷id - */ - @Transactional(rollbackFor = Exception.class) - public PaperSubmitRspVo paperSubmit(Long puId) { - PaperUser paper = paperUserDAO.selectByPrimaryKey(puId); - PaperExceptionAssert.PuExisted.assertNotNull(paper, "该用户的试卷不存在,puId = " + puId); - PaperExceptionAssert.PuStart.assertNotNull(paper.getStartTime(), "用户未开始答题"); - PaperExceptionAssert.PuNotSubmit.assertNull(paper.getEndTime(), "用户已经交卷"); - LocalDateTime now = LocalDateTime.now(); + /** + * 用户交卷 + * + * @param puId 用户试卷id + */ + @Transactional(rollbackFor = Exception.class) + public PaperSubmitRspVo paperSubmit(Long puId, AccountVO user) { + PaperUser paper = paperUserDAO.selectByPrimaryKey(puId); + PaperExceptionAssert.PuExisted.assertNotNull(paper, "该用户的试卷不存在,puId = " + puId); + PaperExceptionAssert.PuStart.assertNotNull(paper.getStartTime(), "用户未开始答题"); + PaperExceptionAssert.PuNotSubmit.assertNull(paper.getEndTime(), "用户已经交卷"); + LocalDateTime now = LocalDateTime.now(); - //统计最终结果 - PaperComposition composition = compositionDAO.selectByPrimaryKey(paper.getPcId()); - List ruleList = compositionService.findRuleByPcId(paper.getPcId()); - Map ruleIdMap = ruleList.stream().collect(Collectors.toMap(PaperRule::getId,Function.identity())); + //统计最终结果 + PaperComposition composition = compositionDAO.selectByPrimaryKey(paper.getPcId()); + List ruleList = compositionService.findRuleByPcId(paper.getPcId()); + Map ruleIdMap = ruleList.stream() + .collect(Collectors.toMap(PaperRule::getId, Function.identity())); - List userQuestionList = findUserSortedQuestions(puId); - int scoreCommon = 0; - int scoreTraining = 0; - long paperTime = Duration.between(paper.getStartTime(), now).toMinutes();//实际做题时长min - for (PaperUserQuestion uq : userQuestionList) { - PaperRule rule = ruleIdMap.get(uq.getRuleId()); + List userQuestionList = findUserSortedQuestions(puId); + int scoreCommon = 0; + int scoreTraining = 0; + long paperTime = Duration.between(paper.getStartTime(), now).toMinutes();//实际做题时长min + for (PaperUserQuestion uq : userQuestionList) { + PaperRule rule = ruleIdMap.get(uq.getRuleId()); - switch (PaperQType.GroupType.getItem(uq.getType())) { - case Common: - scoreCommon += calculateCommonScore(uq, rule);break; - case Training: - scoreTraining += calculateTrainingScore(uq, rule);break; - } - } + switch (PaperQType.GroupType.getItem(uq.getType())) { + case Common: + scoreCommon += calculateCommonScore(uq, rule); + break; + case Training: + scoreTraining += calculateTrainingScore(uq, rule); + break; + } + } - //记录交卷时间 - PaperUser endPaper = new PaperUser(); - endPaper.setId(puId); - endPaper.setEndTime(now); - endPaper.setScore(scoreCommon + scoreTraining); - paperUserDAO.updateByPrimaryKeySelective(endPaper); + //记录交卷时间 + PaperUser endPaper = new PaperUser(); + endPaper.setId(puId); + endPaper.setEndTime(now); + endPaper.setScore(scoreCommon + scoreTraining); + paperUserDAO.updateByPrimaryKeySelective(endPaper); // this.deletePaperQuestion(puId); - // - PaperSubmitRspVo rsp = new PaperSubmitRspVo(); - rsp.setPuId(puId); - rsp.setName(composition.getName()); - rsp.setOrgId(composition.getOrgId()); - rsp.setDuration(paperTime); - rsp.setScore(scoreCommon + scoreTraining); - rsp.setCommonScore(scoreCommon); - rsp.setTrainingScore(scoreTraining); - rsp.setPassScore(composition.getPassScore()); - return rsp; - } + // + PaperSubmitRspVo rsp = new PaperSubmitRspVo(); + rsp.setPuId(puId); + rsp.setName(composition.getName()); + rsp.setOrgId(composition.getOrgId()); + rsp.setDuration(paperTime); + rsp.setScore(scoreCommon + scoreTraining); + rsp.setCommonScore(scoreCommon); + rsp.setTrainingScore(scoreTraining); + rsp.setPassScore(composition.getPassScore()); +// UserExam ue = new UserExam(); +// ue.setExamId(); +// ue.setUserId(user.getAccount()); + //TODO 需要将 UserExam 发送 {@link UserExamService.submit 方法} +// this.applicationContext.publishEvent(new UserExamRecordEvent(userExam)); + return rsp; + } - /** - * 获取题的最终得分 - */ - private int calculateCommonScore(PaperUserQuestion puq, PaperRule rule) { - if (PaperQuestionState.Right.equals(PaperQuestionState.getItem(puq.getState()))) {//题答对时 - return rule.getScore(); - } - return 0; + /** + * 获取题的最终得分 + */ + private int calculateCommonScore(PaperUserQuestion puq, PaperRule rule) { + if (PaperQuestionState.Right.equals(PaperQuestionState.getItem(puq.getState()))) {//题答对时 + return rule.getScore(); } + return 0; + } - public static int getPercentage(double score,int sumScore,int ruleScore) { - if(score >= sumScore){ - return ruleScore; - } - return new BigDecimal((score / sumScore) * ruleScore).setScale(0,RoundingMode.HALF_UP).intValue(); + public static int getPercentage(double score, int sumScore, int ruleScore) { + if (score >= sumScore) { + return ruleScore; + } + return new BigDecimal((score / sumScore) * ruleScore).setScale(0, RoundingMode.HALF_UP) + .intValue(); /*double t = score / sumScore; if(t <=0.5){ return (int)Math.round(t * ruleScore); } return (int)Math.floor(t * ruleScore);*/ - } + } - /** - * 获取题的最终得分 - */ - private int calculateTrainingScore(PaperUserQuestion puq,PaperRule rule) { - if(Objects.equals(puq.getSubType(), PaperQType.SubType.Single.getValue()) && PaperQuestionState.Right.equals(PaperQuestionState.getItem(puq.getState()))){ - return rule.getScore(); - }else if(Objects.equals(puq.getSubType(), PaperQType.SubType.Scene.getValue())){ - if(Strings.isNullOrEmpty(puq.getTmpAnswer())){ - return 0; - } - PaperSubmitAnswerReqVo.AnswerDetail answerDetail = JsonUtils.read(puq.getTmpAnswer(),PaperSubmitAnswerReqVo.AnswerDetail.class); - int sumScore = answerDetail.getSumScore(); - double totalScore = answerDetail.getTrainDetail().stream().mapToDouble(PaperTrainAnswerDetail::getScore).sum(); - return getPercentage(totalScore,sumScore,rule.getScore()); - } + /** + * 获取题的最终得分 + */ + private int calculateTrainingScore(PaperUserQuestion puq, PaperRule rule) { + if (Objects.equals(puq.getSubType(), PaperQType.SubType.Single.getValue()) + && PaperQuestionState.Right.equals(PaperQuestionState.getItem(puq.getState()))) { + return rule.getScore(); + } else if (Objects.equals(puq.getSubType(), PaperQType.SubType.Scene.getValue())) { + if (Strings.isNullOrEmpty(puq.getTmpAnswer())) { return 0; + } + PaperSubmitAnswerReqVo.AnswerDetail answerDetail = JsonUtils.read(puq.getTmpAnswer(), + PaperSubmitAnswerReqVo.AnswerDetail.class); + int sumScore = answerDetail.getSumScore(); + double totalScore = answerDetail.getTrainDetail().stream() + .mapToDouble(PaperTrainAnswerDetail::getScore).sum(); + return getPercentage(totalScore, sumScore, rule.getScore()); } + return 0; + } + /** + * 获取用户试卷试题(已排序) + * + * @param puId 用户试卷id + */ + @Transactional(readOnly = true) + public List findUserSortedQuestions(Long puId) { + PaperUserQuestionExample example = new PaperUserQuestionExample(); + example.createCriteria().andPuIdEqualTo(puId); + example.setOrderByClause(" id asc "); + List findList = paperUserQuestionDAO.selectByExample(example); + findList.sort(Comparator.comparing(PaperUserQuestion::getId)); + return findList; + } - /** - * 获取用户试卷试题(已排序) - * - * @param puId 用户试卷id - */ - @Transactional(readOnly = true) - public List findUserSortedQuestions(Long puId) { - PaperUserQuestionExample example = new PaperUserQuestionExample(); - example.createCriteria().andPuIdEqualTo(puId); - example.setOrderByClause(" id asc "); - List findList = paperUserQuestionDAO.selectByExample(example); - findList.sort(Comparator.comparing(PaperUserQuestion::getId)); - return findList; + /** + * @param pcId 试卷蓝图id + * @param userId 用户id + */ + @Transactional(readOnly = true) + public PaperUser findByUserIdAndPcId(Long userId, Long pcId) { + PaperUserExample example = new PaperUserExample(); + example.createCriteria().andPcIdEqualTo(pcId).andUserIdEqualTo(userId); + List list = paperUserDAO.selectByExample(example); + if (CollectionUtils.isEmpty(list)) { + return null; + } else { + return list.get(0); } + } - /** - * @param pcId 试卷蓝图id - * @param userId 用户id - */ - @Transactional(readOnly = true) - public PaperUser findByUserIdAndPcId(Long userId, Long pcId) { - PaperUserExample example = new PaperUserExample(); - example.createCriteria().andPcIdEqualTo(pcId).andUserIdEqualTo(userId); - List list = paperUserDAO.selectByExample(example); - if (CollectionUtils.isEmpty(list)) { - return null; - } else { - return list.get(0); - } + public PaperQType.SubType getPaperQuestionType(PaperQuestion question) { + BusinessConsts.TheoryType theoryType = BusinessConsts.TheoryType.valueOf(question.getType()); + switch (theoryType) { + case select: + return PaperQType.SubType.Select; + case judge: + return PaperQType.SubType.Judge; + case multi: + return PaperQType.SubType.Multi; } + return null; + } - public PaperQType.SubType getPaperQuestionType(PaperQuestion question) { - BusinessConsts.TheoryType theoryType = BusinessConsts.TheoryType.valueOf(question.getType()); - switch (theoryType) { - case select: - return PaperQType.SubType.Select; - case judge: - return PaperQType.SubType.Judge; - case multi: - return PaperQType.SubType.Multi; - } - return null; + public BusinessConsts.TheoryType getPaperQuestionType(PaperQType.SubType qt) { + switch (qt) { + case Judge: + return BusinessConsts.TheoryType.judge; + case Select: + return BusinessConsts.TheoryType.select; + case Multi: + return BusinessConsts.TheoryType.multi; } + return null; + } - public BusinessConsts.TheoryType getPaperQuestionType(PaperQType.SubType qt) { - switch (qt) { - case Judge: - return BusinessConsts.TheoryType.judge; - case Select: - return BusinessConsts.TheoryType.select; - case Multi: - return BusinessConsts.TheoryType.multi; - } - return null; + /** + * 实训类型(单操 single;场景scene) + */ + public PaperQType.SubType getTrainingType(PublishedTraining2 training) { + if (!StringUtils.hasText(training.getType())) { + log.error("发布列车类型为空 实训id[{}],实训名称[{}]", training.getId(), training.getName()); + return null; } + switch (training.getType().toLowerCase()) { + case "single": + return PaperQType.SubType.Single; + case "scene": + return PaperQType.SubType.Scene; + } + return null; + } - /** - * 实训类型(单操 single;场景scene) - */ - public PaperQType.SubType getTrainingType(PublishedTraining2 training) { - if(!StringUtils.hasText(training.getType())){ - log.error("发布列车类型为空 实训id[{}],实训名称[{}]",training.getId(),training.getName()); - return null; - } - switch (training.getType().toLowerCase()) { - case "single": - return PaperQType.SubType.Single; - case "scene": - return PaperQType.SubType.Scene; - } - return null; - } - - public String getTrainingType(PaperQType.SubType training) { - switch (training) { - case Single: - return "single"; - case Scene: - return "scene"; - } - return null; + public String getTrainingType(PaperQType.SubType training) { + switch (training) { + case Single: + return "single"; + case Scene: + return "scene"; } + return null; + } }