Merge remote-tracking branch 'origin/test' into test

This commit is contained in:
joylink_zhangsai 2023-05-26 16:01:28 +08:00
commit 8acadcd71f
2 changed files with 355 additions and 327 deletions

View File

@ -18,112 +18,119 @@ import java.util.List;
@RestController @RestController
@RequestMapping("/api/v2/paper") @RequestMapping("/api/v2/paper")
public class PaperUserController { public class PaperUserController {
@Autowired
private PaperUserService paperUserService;
@Autowired
private PaperUserCreateService paperUserCreateService;
@Autowired
private PaperUserLoadQuestionService paperUserLoadQuestionService;
@Autowired
private PaperUserSubmitAnswerService paperUserSubmitAnswerService;
@Autowired
private PaperUserFindPageService paperUserFindPageService;
/** @Autowired
* 根据试卷蓝图生成用户的试卷 private PaperUserService paperUserService;
* @Autowired
* @param pcId 试卷蓝图id private PaperUserCreateService paperUserCreateService;
*/ @Autowired
@PostMapping("/{pcId}") private PaperUserLoadQuestionService paperUserLoadQuestionService;
public CreatePaperRspVo createPaper(@PathVariable("pcId") Long pcId, @RequestAttribute AccountVO user) { @Autowired
return this.paperUserCreateService.createPaper(pcId, user); private PaperUserSubmitAnswerService paperUserSubmitAnswerService;
} @Autowired
private PaperUserFindPageService paperUserFindPageService;
/** /**
* 获取用户试卷完整信息 * 根据试卷蓝图生成用户的试卷
* *
* @param puId 用户试卷id * @param pcId 试卷蓝图id
*/ */
@GetMapping("/user/{puId}") @PostMapping("/{pcId}")
public PaperUserWholeVo findPaperUser(@PathVariable("puId") Long puId, @RequestAttribute AccountVO user) { public CreatePaperRspVo createPaper(@PathVariable("pcId") Long pcId,
return this.paperUserService.findPaperUser(puId); @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 * @param groupType 试卷试题大类型:1-理论题2-实训题
*/ * @param qId 试题id
@PostMapping("/user/{puId}/submit") * @param puId 试卷id
public PaperSubmitRspVo paperSubmit(@PathVariable("puId") Long puId,@RequestAttribute AccountVO user) { * @return
return this.paperUserService.paperSubmit(puId); */
} @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-实训题 * <p>
* @param qId 试题id * 对于理论题用户完成一道题提交一道题的答案<br> 对于实训题用户完成实训操作后由实训系统自己评判实训是否成功完成前端提交实训是否成功完成的结果即可
* @param puId 试卷id */
* @return @PostMapping("/user/question/answer")
*/ public PaperSubmitAnswerRspVo submitAnswer(@RequestBody PaperSubmitAnswerReqVo req,
@GetMapping("/user/question/{groupType}/{qId}/{puId}") @RequestAttribute AccountVO user) {
public PaperQuestionLoadRspVo loadQuestion(@PathVariable("groupType") Integer groupType, @PathVariable("qId") Long qId,@PathVariable("puId") Long puId, @RequestAttribute AccountVO user) { return this.paperUserSubmitAnswerService.submitAnswer(req, user);
PaperQType.GroupType pgType = PaperQType.GroupType.getItem(groupType); }
return this.paperUserLoadQuestionService.loadQuestion(pgType, qId,puId, user);
}
/** /**
* 用户提交答案 * 分页查询某个试卷蓝图的所有用户试卷基本信息
* <p> */
* 对于理论题用户完成一道题提交一道题的答案<br>
* 对于实训题用户完成实训操作后由实训系统自己评判实训是否成功完成前端提交实训是否成功完成的结果即可
*/
@PostMapping("/user/question/answer")
public PaperSubmitAnswerRspVo submitAnswer(@RequestBody PaperSubmitAnswerReqVo req, @RequestAttribute AccountVO user) {
return this.paperUserSubmitAnswerService.submitAnswer(req, user);
}
/**
* 分页查询某个试卷蓝图的所有用户试卷基本信息
*/
/* @PostMapping("/user/page/composition") /* @PostMapping("/user/page/composition")
public PageVO<PaperUserInfoVo> findPaperUserByPage(@RequestBody FindPaperUserForCompositionReqVo req, @RequestAttribute AccountVO user) { public PageVO<PaperUserInfoVo> findPaperUserByPage(@RequestBody FindPaperUserForCompositionReqVo req, @RequestAttribute AccountVO user) {
return this.paperUserFindPageService.findPaperUserByPage(req); return this.paperUserFindPageService.findPaperUserByPage(req);
}*/ }*/
/** /**
* 查看某个班级的某个试卷蓝图的所有学生试卷 * 查看某个班级的某个试卷蓝图的所有学生试卷
*/ */
@GetMapping("/user/page") @GetMapping("/user/page")
public PageVO<PageUserDetailVO> findPaperUserByPageForClass(@ModelAttribute PageUserDetailQuery req) { public PageVO<PageUserDetailVO> findPaperUserByPageForClass(
return this.paperUserFindPageService.findPaperUserByPageForClass(req); @ModelAttribute PageUserDetailQuery req) {
} return this.paperUserFindPageService.findPaperUserByPageForClass(req);
}
/** /**
* 查看某个班级的某个试卷蓝图的所有学生试卷 (柱状图) * 查看某个班级的某个试卷蓝图的所有学生试卷 (柱状图)
* @param req *
* @return * @param req
*/ * @return
@GetMapping("/user/curve") */
public CurveForClassVO curveForClass(@ModelAttribute PageUserDetailQuery req) { @GetMapping("/user/curve")
return this.paperUserFindPageService.curveForClass(req); public CurveForClassVO curveForClass(@ModelAttribute PageUserDetailQuery req) {
} return this.paperUserFindPageService.curveForClass(req);
}
@PostMapping("/question/label") @PostMapping("/question/label")
public Collection<String> paperAllLabel(@RequestBody FindCountForQuestionReqVo req){ public Collection<String> paperAllLabel(@RequestBody FindCountForQuestionReqVo req) {
return this.paperUserService.findAllLabel(req); return this.paperUserService.findAllLabel(req);
} }
/** /**
* 查看组织下某个类型题的数量 * 查看组织下某个类型题的数量 参数 tags 目前只支持单个
* 参数 tags 目前只支持单个 */
*/ @PostMapping("/question/count")
@PostMapping("/question/count") public Long findCountForQuestion(@RequestBody FindCountForQuestionReqVo req) {
public Long findCountForQuestion( @RequestBody FindCountForQuestionReqVo req) {
// req.setOrgId(orgId); // req.setOrgId(orgId);
return this.paperUserService.findCountForQuestion(req); return this.paperUserService.findCountForQuestion(req);
} }
} }

View File

@ -3,11 +3,13 @@ package club.joylink.rtss.services.paper;
import club.joylink.rtss.constants.BusinessConsts; import club.joylink.rtss.constants.BusinessConsts;
import club.joylink.rtss.dao.PublishedTraining2DAO; import club.joylink.rtss.dao.PublishedTraining2DAO;
import club.joylink.rtss.dao.paper.*; import club.joylink.rtss.dao.paper.*;
import club.joylink.rtss.entity.UserExam;
import club.joylink.rtss.entity.paper.*; import club.joylink.rtss.entity.paper.*;
import club.joylink.rtss.entity.paper.question.PaperQuestion; import club.joylink.rtss.entity.paper.question.PaperQuestion;
import club.joylink.rtss.entity.paper.question.PaperQuestionExample; import club.joylink.rtss.entity.paper.question.PaperQuestionExample;
import club.joylink.rtss.entity.training2.PublishedTraining2; import club.joylink.rtss.entity.training2.PublishedTraining2;
import club.joylink.rtss.entity.training2.PublishedTraining2Example; import club.joylink.rtss.entity.training2.PublishedTraining2Example;
import club.joylink.rtss.event.UserExamRecordEvent;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.exception.PaperExceptionAssert; import club.joylink.rtss.exception.PaperExceptionAssert;
import club.joylink.rtss.services.training2.Training2PublishService; import club.joylink.rtss.services.training2.Training2PublishService;
@ -43,101 +45,109 @@ import java.util.stream.Collectors;
@Service @Service
@Slf4j @Slf4j
public class PaperUserService { 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;
/** @Autowired
* 获取理论或实操的所有标签 private PaperCompositionDAO compositionDAO;
* @param req @Autowired
* @return private PaperRuleDAO ruleDAO;
*/ @Autowired
public Collection<String> findAllLabel(FindCountForQuestionReqVo req){ private PaperUserDAO paperUserDAO;
if(req.getGroupType() == PaperQType.GroupType.Common){ @Autowired
return paperQuestionService.findAllLable(req.getOrgId(),req.getSubType().name().toLowerCase()); private PaperUserQuestionDAO paperUserQuestionDAO;
}else if(PaperQType.GroupType.Training.equals(req.getGroupType())){ @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<String> 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,"不支持此操作"); // 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 this.training2PublishService.findAllLabel(req.getMapId(), req.getOrgId(),
} req.getSubType().name().toUpperCase(), req.getTrainingClient());
return Collections.emptyList();
} }
/** return Collections.emptyList();
* 获取组织某个类型题的数量 }
*/
@Transactional(readOnly = true) /**
public Long findCountForQuestion(FindCountForQuestionReqVo req){ * 获取组织某个类型题的数量
if(PaperQType.GroupType.Common.equals(req.getGroupType())){ */
String tagStr=req.getTags(); @Transactional(readOnly = true)
BusinessConsts.TheoryType theoryType = this.getPaperQuestionType(req.getSubType()); public Long findCountForQuestion(FindCountForQuestionReqVo req) {
return paperQuestionService.queryCount(req.getOrgId(),theoryType,tagStr); if (PaperQType.GroupType.Common.equals(req.getGroupType())) {
}else if(PaperQType.GroupType.Training.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),"不支持查询实训题数量"); // PaperExceptionAssert.PdValid.assertTrue(!PaperQType.GroupType.Training.equals(groupType),"不支持查询实训题数量");
BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertNotTrue(req.getSubType() == PaperQType.SubType.Scene,"不支持此操作"); BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertNotTrue(
return training2PublishService.queryCountForLabel(req); 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<PaperRule> ruleList = compositionService.findRuleByPcId(composition.getId());
List<PaperUserQuestion> 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;
} }
return 0L;
}
/** /**
* 删除用户试卷 * 获取用户试卷完整信息
* *
* @param puId 用户试卷id * @param puId 用户试卷id
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(readOnly = true)
public void deletePaperUser(Long puId) { public PaperUserWholeVo findPaperUser(Long puId) {
this.deletePaperQuestion(puId); PaperUser paper = paperUserDAO.selectByPrimaryKey(puId);
//删除试卷 PaperExceptionAssert.PuExisted.assertNotNull(paper, "用户试卷不存在");
paperUserDAO.deleteByPrimaryKey(puId); //
} PaperComposition composition = compositionDAO.selectByPrimaryKey(paper.getPcId());
List<PaperRule> ruleList = compositionService.findRuleByPcId(composition.getId());
List<PaperUserQuestion> 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); * @param puId 用户试卷id
paperUserQuestionDAO.deleteByExample(puqExample); */
} @Transactional(rollbackFor = Exception.class)
public void deletePaperUser(Long puId) {
this.deletePaperQuestion(puId);
//删除试卷
paperUserDAO.deleteByPrimaryKey(puId);
}
/** private void deletePaperQuestion(Long puId) {
* 开始答题 //删除试卷试题关联表
* PaperUserQuestionExample puqExample = new PaperUserQuestionExample();
* @param puId 用户试卷id puqExample.createCriteria().andPuIdEqualTo(puId);
*/ paperUserQuestionDAO.deleteByExample(puqExample);
}
/**
* 开始答题
*
* @param puId 用户试卷id
*/
/* /*
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void paperStart(Long puId) { public void paperStart(Long puId) {
@ -151,182 +161,193 @@ public class PaperUserService {
} }
*/ */
/** /**
* 用户交卷 * 用户交卷
* *
* @param puId 用户试卷id * @param puId 用户试卷id
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public PaperSubmitRspVo paperSubmit(Long puId) { public PaperSubmitRspVo paperSubmit(Long puId, AccountVO user) {
PaperUser paper = paperUserDAO.selectByPrimaryKey(puId); PaperUser paper = paperUserDAO.selectByPrimaryKey(puId);
PaperExceptionAssert.PuExisted.assertNotNull(paper, "该用户的试卷不存在puId = " + puId); PaperExceptionAssert.PuExisted.assertNotNull(paper, "该用户的试卷不存在puId = " + puId);
PaperExceptionAssert.PuStart.assertNotNull(paper.getStartTime(), "用户未开始答题"); PaperExceptionAssert.PuStart.assertNotNull(paper.getStartTime(), "用户未开始答题");
PaperExceptionAssert.PuNotSubmit.assertNull(paper.getEndTime(), "用户已经交卷"); PaperExceptionAssert.PuNotSubmit.assertNull(paper.getEndTime(), "用户已经交卷");
LocalDateTime now = LocalDateTime.now(); LocalDateTime now = LocalDateTime.now();
//统计最终结果 //统计最终结果
PaperComposition composition = compositionDAO.selectByPrimaryKey(paper.getPcId()); PaperComposition composition = compositionDAO.selectByPrimaryKey(paper.getPcId());
List<PaperRule> ruleList = compositionService.findRuleByPcId(paper.getPcId()); List<PaperRule> ruleList = compositionService.findRuleByPcId(paper.getPcId());
Map<Long, PaperRule> ruleIdMap = ruleList.stream().collect(Collectors.toMap(PaperRule::getId,Function.identity())); Map<Long, PaperRule> ruleIdMap = ruleList.stream()
.collect(Collectors.toMap(PaperRule::getId, Function.identity()));
List<PaperUserQuestion> userQuestionList = findUserSortedQuestions(puId); List<PaperUserQuestion> userQuestionList = findUserSortedQuestions(puId);
int scoreCommon = 0; int scoreCommon = 0;
int scoreTraining = 0; int scoreTraining = 0;
long paperTime = Duration.between(paper.getStartTime(), now).toMinutes();//实际做题时长min long paperTime = Duration.between(paper.getStartTime(), now).toMinutes();//实际做题时长min
for (PaperUserQuestion uq : userQuestionList) { for (PaperUserQuestion uq : userQuestionList) {
PaperRule rule = ruleIdMap.get(uq.getRuleId()); PaperRule rule = ruleIdMap.get(uq.getRuleId());
switch (PaperQType.GroupType.getItem(uq.getType())) { switch (PaperQType.GroupType.getItem(uq.getType())) {
case Common: case Common:
scoreCommon += calculateCommonScore(uq, rule);break; scoreCommon += calculateCommonScore(uq, rule);
case Training: break;
scoreTraining += calculateTrainingScore(uq, rule);break; case Training:
} scoreTraining += calculateTrainingScore(uq, rule);
} break;
}
}
//记录交卷时间 //记录交卷时间
PaperUser endPaper = new PaperUser(); PaperUser endPaper = new PaperUser();
endPaper.setId(puId); endPaper.setId(puId);
endPaper.setEndTime(now); endPaper.setEndTime(now);
endPaper.setScore(scoreCommon + scoreTraining); endPaper.setScore(scoreCommon + scoreTraining);
paperUserDAO.updateByPrimaryKeySelective(endPaper); paperUserDAO.updateByPrimaryKeySelective(endPaper);
// this.deletePaperQuestion(puId); // this.deletePaperQuestion(puId);
// //
PaperSubmitRspVo rsp = new PaperSubmitRspVo(); PaperSubmitRspVo rsp = new PaperSubmitRspVo();
rsp.setPuId(puId); rsp.setPuId(puId);
rsp.setName(composition.getName()); rsp.setName(composition.getName());
rsp.setOrgId(composition.getOrgId()); rsp.setOrgId(composition.getOrgId());
rsp.setDuration(paperTime); rsp.setDuration(paperTime);
rsp.setScore(scoreCommon + scoreTraining); rsp.setScore(scoreCommon + scoreTraining);
rsp.setCommonScore(scoreCommon); rsp.setCommonScore(scoreCommon);
rsp.setTrainingScore(scoreTraining); rsp.setTrainingScore(scoreTraining);
rsp.setPassScore(composition.getPassScore()); rsp.setPassScore(composition.getPassScore());
return rsp; // 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) { private int calculateCommonScore(PaperUserQuestion puq, PaperRule rule) {
if (PaperQuestionState.Right.equals(PaperQuestionState.getItem(puq.getState()))) {//题答对时 if (PaperQuestionState.Right.equals(PaperQuestionState.getItem(puq.getState()))) {//题答对时
return rule.getScore(); return rule.getScore();
}
return 0;
} }
return 0;
}
public static int getPercentage(double score,int sumScore,int ruleScore) { public static int getPercentage(double score, int sumScore, int ruleScore) {
if(score >= sumScore){ if (score >= sumScore) {
return ruleScore; return ruleScore;
} }
return new BigDecimal((score / sumScore) * ruleScore).setScale(0,RoundingMode.HALF_UP).intValue(); return new BigDecimal((score / sumScore) * ruleScore).setScale(0, RoundingMode.HALF_UP)
.intValue();
/*double t = score / sumScore; /*double t = score / sumScore;
if(t <=0.5){ if(t <=0.5){
return (int)Math.round(t * ruleScore); return (int)Math.round(t * ruleScore);
} }
return (int)Math.floor(t * ruleScore);*/ return (int)Math.floor(t * ruleScore);*/
} }
/** /**
* 获取题的最终得分 * 获取题的最终得分
*/ */
private int calculateTrainingScore(PaperUserQuestion puq,PaperRule rule) { private int calculateTrainingScore(PaperUserQuestion puq, PaperRule rule) {
if(Objects.equals(puq.getSubType(), PaperQType.SubType.Single.getValue()) && PaperQuestionState.Right.equals(PaperQuestionState.getItem(puq.getState()))){ if (Objects.equals(puq.getSubType(), PaperQType.SubType.Single.getValue())
return rule.getScore(); && PaperQuestionState.Right.equals(PaperQuestionState.getItem(puq.getState()))) {
}else if(Objects.equals(puq.getSubType(), PaperQType.SubType.Scene.getValue())){ return rule.getScore();
if(Strings.isNullOrEmpty(puq.getTmpAnswer())){ } else if (Objects.equals(puq.getSubType(), PaperQType.SubType.Scene.getValue())) {
return 0; if (Strings.isNullOrEmpty(puq.getTmpAnswer())) {
}
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; 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<PaperUserQuestion> findUserSortedQuestions(Long puId) {
PaperUserQuestionExample example = new PaperUserQuestionExample();
example.createCriteria().andPuIdEqualTo(puId);
example.setOrderByClause(" id asc ");
List<PaperUserQuestion> findList = paperUserQuestionDAO.selectByExample(example);
findList.sort(Comparator.comparing(PaperUserQuestion::getId));
return findList;
}
/** /**
* 获取用户试卷试题(已排序) * @param pcId 试卷蓝图id
* * @param userId 用户id
* @param puId 用户试卷id */
*/ @Transactional(readOnly = true)
@Transactional(readOnly = true) public PaperUser findByUserIdAndPcId(Long userId, Long pcId) {
public List<PaperUserQuestion> findUserSortedQuestions(Long puId) { PaperUserExample example = new PaperUserExample();
PaperUserQuestionExample example = new PaperUserQuestionExample(); example.createCriteria().andPcIdEqualTo(pcId).andUserIdEqualTo(userId);
example.createCriteria().andPuIdEqualTo(puId); List<PaperUser> list = paperUserDAO.selectByExample(example);
example.setOrderByClause(" id asc "); if (CollectionUtils.isEmpty(list)) {
List<PaperUserQuestion> findList = paperUserQuestionDAO.selectByExample(example); return null;
findList.sort(Comparator.comparing(PaperUserQuestion::getId)); } else {
return findList; return list.get(0);
} }
}
/** public PaperQType.SubType getPaperQuestionType(PaperQuestion question) {
* @param pcId 试卷蓝图id BusinessConsts.TheoryType theoryType = BusinessConsts.TheoryType.valueOf(question.getType());
* @param userId 用户id switch (theoryType) {
*/ case select:
@Transactional(readOnly = true) return PaperQType.SubType.Select;
public PaperUser findByUserIdAndPcId(Long userId, Long pcId) { case judge:
PaperUserExample example = new PaperUserExample(); return PaperQType.SubType.Judge;
example.createCriteria().andPcIdEqualTo(pcId).andUserIdEqualTo(userId); case multi:
List<PaperUser> list = paperUserDAO.selectByExample(example); return PaperQType.SubType.Multi;
if (CollectionUtils.isEmpty(list)) {
return null;
} else {
return list.get(0);
}
} }
return null;
}
public PaperQType.SubType getPaperQuestionType(PaperQuestion question) { public BusinessConsts.TheoryType getPaperQuestionType(PaperQType.SubType qt) {
BusinessConsts.TheoryType theoryType = BusinessConsts.TheoryType.valueOf(question.getType()); switch (qt) {
switch (theoryType) { case Judge:
case select: return BusinessConsts.TheoryType.judge;
return PaperQType.SubType.Select; case Select:
case judge: return BusinessConsts.TheoryType.select;
return PaperQType.SubType.Judge; case Multi:
case multi: return BusinessConsts.TheoryType.multi;
return PaperQType.SubType.Multi;
}
return null;
} }
return null;
}
public BusinessConsts.TheoryType getPaperQuestionType(PaperQType.SubType qt) { /**
switch (qt) { * 实训类型单操 single场景scene
case Judge: */
return BusinessConsts.TheoryType.judge; public PaperQType.SubType getTrainingType(PublishedTraining2 training) {
case Select: if (!StringUtils.hasText(training.getType())) {
return BusinessConsts.TheoryType.select; log.error("发布列车类型为空 实训id[{}],实训名称[{}]", training.getId(), training.getName());
case Multi: return null;
return BusinessConsts.TheoryType.multi;
}
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) {
* 实训类型单操 single场景scene switch (training) {
*/ case Single:
public PaperQType.SubType getTrainingType(PublishedTraining2 training) { return "single";
if(!StringUtils.hasText(training.getType())){ case Scene:
log.error("发布列车类型为空 实训id[{}],实训名称[{}]",training.getId(),training.getName()); return "scene";
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;
} }
return null;
}
} }