| | |
| | | examPaper.setCreateBy(SecurityUtils.getUsername()); |
| | | if(examPaper.getLimitTime()>0){ |
| | | examPaper.setLimit(1); |
| | | }else{ |
| | | examPaper.setLimit(0); |
| | | } |
| | | int row=baseMapper.insert(examPaper); |
| | | if(row<1){ |
| | |
| | | } |
| | | |
| | | private List<ExPaperQuestion> getPaperQuestions(Long paperId,Long bankId,Integer questionMethod,Integer questionCount,Integer questionScore, QuestionTypeEnum questionTypeEnum) { |
| | | SysUser user=SecurityUtils.getLoginUser().getUser(); |
| | | Integer totalQuestionCount=questionMapper.selectCountByBankId(user.getCompanyId(), bankId, questionTypeEnum.getCode()); |
| | | SysUser currentUser=SecurityUtils.getLoginUser().getUser(); |
| | | Integer totalQuestionCount=questionMapper.selectCountByBankId(currentUser.getCompanyId(), bankId, questionTypeEnum.getCode()); |
| | | if(totalQuestionCount< questionCount){ |
| | | throw new ApiException(String.format("所选题库<%s>数量不足,无法分配",questionTypeEnum.getInfo())); |
| | | } |
| | | List<ExQuestion> questions=new ArrayList<>(); |
| | | if(Objects.equals(questionMethod, QuestionAssignEnum.RANDOM.getCode())){//随机分配 |
| | | questions=questionMapper.selectRandomQuestion(user.getCompanyId(), bankId,questionTypeEnum.getCode(), questionCount); |
| | | questions=questionMapper.selectRandomQuestion(currentUser.getCompanyId(), bankId,questionTypeEnum.getCode(), questionCount); |
| | | }else{//顺序分配 |
| | | int totalPage=questionCount/ questionMethod;//不能整除,忽略最后一页 |
| | | int totalPage=questionCount/questionMethod;//不能整除,忽略最后一页 |
| | | Random random=new Random(); |
| | | int startIndex=random.nextInt(totalPage)+1; |
| | | questions=questionMapper.selectQuestionWithLimit(user.getCompanyId(), bankId,questionTypeEnum.getCode(),startIndex, questionCount); |
| | | questions=questionMapper.selectQuestionWithLimit(currentUser.getCompanyId(), bankId,questionTypeEnum.getCode(),startIndex, questionCount); |
| | | } |
| | | List<ExPaperQuestion> paperQuestionList=questions.stream().map(item -> { |
| | | ExPaperQuestion exPaperQuestion=new ExPaperQuestion(); |
| | |
| | | |
| | | @Override |
| | | public int updateExamPaper(ExExamPaper examPaper) { |
| | | checkUserAllowed(examPaper); |
| | | if(!checkNameUnique(examPaper)){ |
| | | throw new ApiException("试卷名称已存在"); |
| | | } |
| | |
| | | throw new ApiException("该试卷下已分配学员,不能编辑"); |
| | | } |
| | | examPaper.setCode(null);//编号不能修改 |
| | | if(examPaper.getLimitTime()==0){ |
| | | if(examPaper.getLimitTime()>0){ |
| | | examPaper.setLimit(1); |
| | | }else{ |
| | | examPaper.setLimit(0); |
| | | } |
| | | int row=baseMapper.updateById(examPaper); |
| | |
| | | |
| | | @Override |
| | | public int deleteExamPaperById(Long paperId) { |
| | | checkUserAllowed(baseMapper.selectById(paperId)); |
| | | //查询该试卷分配的学员人数 |
| | | if(checkPaperHasStudent(paperId)){ |
| | | throw new ApiException("该试卷下已分配学员,不能删除"); |
| | | } |
| | | int row=baseMapper.deleteById(paperId); |
| | | int row=baseMapper.deletePaperById(paperId); |
| | | if(row<1){ |
| | | throw new ApiException("删除试卷失败"); |
| | | } |
| | | //删除考卷试题 |
| | | paperQuestionMapper.deletebyPapaerId(paperId); |
| | | // paperQuestionMapper.deletebyPapaerId(paperId); |
| | | return row; |
| | | } |
| | | |
| | |
| | | |
| | | @Override |
| | | public int changeExamPaperStatus(Long paperId, Integer status) { |
| | | checkUserAllowed(baseMapper.selectById(paperId)); |
| | | return baseMapper.updateById(new ExExamPaper().setId(paperId).setStatus(status).setUpdateBy(SecurityUtils.getUsername())); |
| | | } |
| | | |
| | | |
| | | |
| | | } |