| | |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.gkhy.exam.common.api.CommonPage; |
| | | import com.gkhy.exam.common.domain.entity.SysUser; |
| | | import com.gkhy.exam.common.enums.PaperStudentStateEnum; |
| | | import com.gkhy.exam.common.enums.PrivatizeEnum; |
| | | import com.gkhy.exam.common.enums.QuestionTypeEnum; |
| | | import com.gkhy.exam.common.enums.UserTypeEnum; |
| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.time.LocalDateTime; |
| | | import java.time.ZoneOffset; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | |
| | | @Override |
| | | public CommonPage selectQuestionList(ExQuestion question) { |
| | | if(question.getBankId()==null){ |
| | | throw new ApiException("题库id不能为空"); |
| | | } |
| | | ExQuestionBank questionBank=questionBankMapper.selectById(question.getBankId()); |
| | | if(!questionBank.getPrivatize().equals(PrivatizeEnum.PUBLIC.getCode())){ |
| | | SysUser currentUser=SecurityUtils.getLoginUser().getUser(); |
| | | if(!currentUser.getUserType().equals(UserTypeEnum.SYSTEM_USER.getCode())){ |
| | | if(!question.getCompanyId().equals(currentUser.getCompanyId())){ |
| | | throw new ApiException("无权限查看其它企业题目"); |
| | | } |
| | | } |
| | | // if(question.getBankId()==null){ |
| | | // throw new ApiException("题库id不能为空"); |
| | | // } |
| | | // ExQuestionBank questionBank=questionBankMapper.selectById(question.getBankId()); |
| | | // if(!questionBank.getPrivatize().equals(PrivatizeEnum.PUBLIC.getCode())){ |
| | | // SysUser currentUser=SecurityUtils.getLoginUser().getUser(); |
| | | // if(!currentUser.getUserType().equals(UserTypeEnum.SYSTEM_USER.getCode())){ |
| | | // if(!question.getCompanyId().equals(currentUser.getCompanyId())){ |
| | | // throw new ApiException("无权限查看其它企业题目"); |
| | | // } |
| | | // } |
| | | // } |
| | | SysUser currentUser=SecurityUtils.getLoginUser().getUser(); |
| | | if(!currentUser.getUserType().equals(UserTypeEnum.SYSTEM_USER.getCode())){ |
| | | question.setCompanyId(currentUser.getCompanyId()); |
| | | } |
| | | PageUtils.startPage(); |
| | | List<ExQuestion> questionList=baseMapper.selectQuestionList(question); |
| | |
| | | |
| | | @Override |
| | | public ExQuestion selectQuestionById(Long questionId) { |
| | | ExQuestion question= baseMapper.selectById(questionId); |
| | | ExQuestion question= baseMapper.selectByQuestionId(questionId); |
| | | if(question.getPrivatize().equals(PrivatizeEnum.PUBLIC.getCode())){ |
| | | return question; |
| | | } |
| | |
| | | public int insertQuestion(ExQuestion question) { |
| | | checkUserAllowed(question); |
| | | SysUser user= SecurityUtils.getLoginUser().getUser(); |
| | | int totalCount=questionBankMapper.selectCountByBankId(question.getBankId()); |
| | | if(totalCount>1000){ |
| | | throw new ApiException("题库题目数量超过1000,不能再新增"); |
| | | } |
| | | //公开的题库新增题目,题目也是公开 |
| | | ExQuestionBank questionBank=questionBankMapper.selectById(question.getBankId()); |
| | | if(user.getUserType().equals(UserTypeEnum.SYSTEM_USER.getCode())||questionBank.getPrivatize().equals(PrivatizeEnum.PUBLIC.getCode())){ |
| | | if(user.getUserType().equals(UserTypeEnum.SYSTEM_USER.getCode())&&questionBank.getPrivatize().equals(PrivatizeEnum.PRIVATE.getCode())){ |
| | | throw new ApiException("管理员不允许在私有题库创建题目"); |
| | | }else if (user.getUserType().equals(UserTypeEnum.SYSTEM_USER.getCode())&&questionBank.getPrivatize().equals(PrivatizeEnum.PUBLIC.getCode())){ |
| | | question.setPrivatize(PrivatizeEnum.PUBLIC.getCode()); |
| | | }else{ |
| | | question.setCompanyId(user.getCompanyId()); |
| | | question.setPrivatize(PrivatizeEnum.PRIVATE.getCode()); |
| | | } |
| | | validData(question); |
| | | question.setCreateBy(user.getUsername()); |
| | | int row=baseMapper.insert(question); |
| | | if(row<1){ |
| | | throw new ApiException("新增题目失败"); |
| | |
| | | public int updateQuestion(ExQuestion question) { |
| | | validData(question); |
| | | checkUserAllowed(question); |
| | | question.setUpdateBy(SecurityUtils.getUsername()); |
| | | int row=baseMapper.updateById(question); |
| | | if(row<1){ |
| | | throw new ApiException("编辑题目失败"); |
| | |
| | | } |
| | | |
| | | public void validData(ExQuestion question){ |
| | | if(!question.getQuestionType().equals(QuestionTypeEnum.JUDGE.getCode())){ |
| | | if(!question.getQuestionType().equals(QuestionTypeEnum.JUDGE.getCode())&&!question.getQuestionType().equals(QuestionTypeEnum.EASY.getCode())){ |
| | | if(StringUtils.isBlank(question.getContent())){ |
| | | throw new ApiException("题目内容不能为空"); |
| | | } |
| | |
| | | if(currentUser.getUserType().equals(UserTypeEnum.STUDENT.getCode())){ |
| | | throw new ApiException("没有权限操作"); |
| | | } |
| | | if(!currentUser.getCompanyId().equals(question.getCompanyId())){ |
| | | if(question.getCompanyId()!=null&&!currentUser.getCompanyId().equals(question.getCompanyId())){ |
| | | throw new ApiException("没有权限操作其他企业题目"); |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<Map> getExerciseQuestionList(Long bankId, Integer exerciseType) { |
| | | return baseMapper.getExerciseQuestionList(bankId,exerciseType,SecurityUtils.getUserId()); |
| | | public List<Map> getExerciseQuestionList(Long bankId) { |
| | | return baseMapper.getExerciseQuestionList(bankId,SecurityUtils.getUserId()); |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | @Override |
| | | public List<ExQuestion> getExerciseQuestionByIds(List<Long> questionIds) { |
| | | if(questionIds==null|| questionIds.isEmpty()){ |
| | | throw new ApiException("题目id列表不能为空"); |
| | | } |
| | | if(questionIds.size()>30){ |
| | | throw new ApiException("批量id数量超过阀值"); |
| | | } |
| | | return baseMapper.getExeriseQuestionByIds(questionIds,SecurityUtils.getUserId()); |
| | | } |
| | | |
| | |
| | | if(paperStudent==null){ |
| | | throw new ApiException("您分配的试卷未查询到"); |
| | | } |
| | | Long currentDateTime=System.currentTimeMillis(); |
| | | if(viewType==1){//更新考试开始时间 |
| | | Long startTime=System.currentTimeMillis(); |
| | | if(paperStudent.getCompleted()==1){ |
| | | if(paperStudent.getState()!= PaperStudentStateEnum.WAIT_EXAM.getCode()){ |
| | | throw new ApiException("考试已完成,不能重复考试"); |
| | | } |
| | | if(paperStudent.getStartTime()!=null) {//判断考卷是否已完成 |
| | | ExExamPaper examPaper = examPaperMapper.selectById(paperStudent.getPaperId()); |
| | | if(examPaper.getLimit()==1) { |
| | | Long currentDateTime = System.currentTimeMillis(); |
| | | if (currentDateTime-paperStudent.getStartTime()>=examPaper.getLimitTime()*60*1000){ |
| | | paperStudent.setCompleted(1); |
| | | paperStudentMapper.updateById(paperStudent); |
| | | throw new ApiException("考试已超时,不能再考试"); |
| | | } |
| | | ExExamPaper examPaper = examPaperMapper.selectById(paperStudent.getPaperId()); |
| | | if(examPaper.getLimited()==1){ |
| | | if(paperStudent.getStartTime()!=null && (currentDateTime-paperStudent.getStartTime()>=examPaper.getLimitTime()*60*1000)){ |
| | | // paperStudent.setCompleted(1); |
| | | // paperStudentMapper.updateById(paperStudent); |
| | | throw new ApiException("考试已超时,不能再考试"); |
| | | } |
| | | LocalDateTime deadline = examPaper.getDeadline(); |
| | | if(currentDateTime-deadline.toInstant(ZoneOffset.of("+8")).toEpochMilli()>0){ |
| | | // paperStudent.setCompleted(1); |
| | | // paperStudentMapper.updateById(paperStudent); |
| | | throw new ApiException("已过考试截止时间,不能再考试"); |
| | | } |
| | | } |
| | | int row=paperStudentMapper.updateById(new ExPaperStudent().setPaperId(paperStudent.getPaperId()).setStudentId(paperStudent.getStudentId()).setStartTime(startTime)); |
| | | if(row<1){ |
| | | throw new ApiException("设置考试开始时间失败"); |
| | | if(paperStudent.getStartTime()==null) { |
| | | int row = paperStudentMapper.updateById(new ExPaperStudent().setId(paperStudent.getId()).setPaperId(paperStudent.getPaperId()).setStudentId(paperStudent.getStudentId()).setStartTime(currentDateTime)); |
| | | if (row < 1) { |
| | | throw new ApiException("设置考试开始时间失败"); |
| | | } |
| | | } |
| | | }else{ |
| | | if(!Objects.equals(paperStudent.getState(), PaperStudentStateEnum.DONE_REVIEW.getCode())){ |
| | | // if(paperStudent.getStartTime()!=null) {//判断考卷是否已完成 |
| | | // ExExamPaper examPaper = examPaperMapper.selectById(paperStudent.getPaperId()); |
| | | // if(examPaper.getLimited()==1) { |
| | | // if (currentDateTime-paperStudent.getStartTime()>=examPaper.getLimitTime()*60*1000){ |
| | | // paperStudent.setCompleted(1); |
| | | // paperStudentMapper.updateById(paperStudent); |
| | | // } |
| | | // } |
| | | // } |
| | | throw new ApiException("试卷未审批完,无法查看"); |
| | | } |
| | | } |
| | | return baseMapper.getPaperQuestionList(paperId,paperStudent.getCompleted(),SecurityUtils.getUserId()); |
| | | return baseMapper.getPaperQuestionList(paperId,paperStudent.getState(),SecurityUtils.getUserId(),viewType); |
| | | } |
| | | |
| | | @Override |
| | |
| | | if(paperStudent==null){ |
| | | throw new ApiException("您分配的试卷未查询到"); |
| | | } |
| | | return baseMapper.getPaperQuestionById(paperId,questionId,paperStudent.getCompleted(),SecurityUtils.getUserId()); |
| | | return baseMapper.getPaperQuestionById(paperId,questionId,paperStudent.getState(),SecurityUtils.getUserId()); |
| | | } |
| | | |
| | | @Override |
| | | public List<ExQuestion> getPaperQuestionByIds(Long paperId, List<Long> questionIds) { |
| | | if(questionIds.size()>30){ |
| | | throw new ApiException("批量id数量超过阀值"); |
| | | } |
| | | LambdaQueryWrapper<ExPaperStudent> lambdaQueryWrapper = Wrappers.<ExPaperStudent>lambdaQuery() |
| | | .eq(ExPaperStudent::getPaperId, paperId) |
| | | .eq(ExPaperStudent::getStudentId, SecurityUtils.getUserId()); |
| | |
| | | if(paperStudent==null){ |
| | | throw new ApiException("您分配的试卷未查询到"); |
| | | } |
| | | return baseMapper.getPaperQuestionByIds(paperId,questionIds,paperStudent.getCompleted(),SecurityUtils.getUserId()); |
| | | return baseMapper.getPaperQuestionByIds(paperId,questionIds,paperStudent.getState(),SecurityUtils.getUserId()); |
| | | } |
| | | |
| | | @Override |
| | | public List<Long> getExerciseErrorQuestionList(Long bankId) { |
| | | return baseMapper.getExerciseErrorQuestionList(bankId,SecurityUtils.getUserId()); |
| | | } |
| | | |
| | | @Override |
| | | public List<ExQuestion> selectQuestionByPaperId(Long paperId) { |
| | | return baseMapper.selectQuestionByPaperId(paperId); |
| | | } |
| | | } |