|
|
@@ -5,9 +5,11 @@ import nju.seec.helper.dto.QuestionStudentAnswerDTO;
|
|
|
import nju.seec.helper.entity.*;
|
|
|
import nju.seec.helper.service.QuizService;
|
|
|
import nju.seec.helper.util.BOKUtil;
|
|
|
+import nju.seec.helper.util.enums.ExceptionType;
|
|
|
import nju.seec.helper.util.enums.QuizState;
|
|
|
import nju.seec.helper.util.enums.SlideState;
|
|
|
import nju.seec.helper.util.enums.UserType;
|
|
|
+import nju.seec.helper.util.exception.HelperException;
|
|
|
import nju.seec.helper.vo.quiz.QuestionVO;
|
|
|
import nju.seec.helper.vo.quiz.QuizResultVO;
|
|
|
import nju.seec.helper.vo.quiz.QuizVO;
|
|
|
@@ -68,7 +70,7 @@ public class QuizServiceImpl implements QuizService {
|
|
|
@Override
|
|
|
public String deleteQuiz(Long quizId) {
|
|
|
Quiz quiz =quizDAO.findQuizById(quizId);
|
|
|
- if(quiz.getState()!=QuizState.NOT_STARTED){return "can't delete started quiz!";}
|
|
|
+ if(quiz.getState()!=QuizState.NOT_STARTED){throw HelperException.of(ExceptionType.FORBIDDEN,"不能删除已经开始的测试!");}
|
|
|
quizDAO.delete(quiz);
|
|
|
return "delete success";
|
|
|
}
|
|
|
@@ -78,7 +80,7 @@ public class QuizServiceImpl implements QuizService {
|
|
|
public Quiz modifyQuiz(Long quizId, String name, List<String> questions, SlideState quizTime, String slideId) {
|
|
|
|
|
|
Quiz quiz =quizDAO.findQuizById(quizId);
|
|
|
- if(quiz.getState()!=QuizState.NOT_STARTED){throw new RuntimeException("can't delete started quiz!");}
|
|
|
+ if(quiz.getState()!=QuizState.NOT_STARTED){throw HelperException.of(ExceptionType.FORBIDDEN,"不能修改已经开始的测试!");}
|
|
|
if(name!=null) quiz.setName(name);
|
|
|
if(questions!=null) quiz.setQuestions(questions);
|
|
|
if(quizTime!=null) {
|
|
|
@@ -118,9 +120,9 @@ public class QuizServiceImpl implements QuizService {
|
|
|
|
|
|
@Override
|
|
|
public List<QuizResultVO> getQuizResult(Long quizId) {
|
|
|
- Assert.notNull(quizId,"QUIZ ID can't be null!");
|
|
|
+ Assert.notNull(quizId,"错误的测试!");
|
|
|
final Quiz quiz = quizDAO.findQuizById(quizId);
|
|
|
- if(quiz.getState()!=QuizState.CLOSED){throw new RuntimeException("quiz not close!");}
|
|
|
+ if(quiz.getState()!=QuizState.CLOSED){throw new RuntimeException("测试未关闭,无法得到测试结果");}
|
|
|
List<QuizResultVO> retList=new ArrayList<>();
|
|
|
final List<StudentScore> studentScoreList = quiz.getStudentScore();
|
|
|
Map<Integer,List<QuizStudentAnswer>> IdQuizStudentAnswerMap=new HashMap<>();
|
|
|
@@ -145,9 +147,9 @@ public class QuizServiceImpl implements QuizService {
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public Integer upStudentAnswer(Long quizId, Integer uid, List<QuestionStudentAnswerDTO> answers) {
|
|
|
- Assert.notNull(quizId,"QUIZ ID can't be null!");
|
|
|
+ Assert.notNull(quizId,"错误的测试!");
|
|
|
final Quiz quiz = quizDAO.findQuizById(quizId);
|
|
|
- if(quiz.getState()!=QuizState.ONGOING){throw new RuntimeException("can't put not ONGOING quiz answer!");}
|
|
|
+ if(quiz.getState()!=QuizState.ONGOING){throw HelperException.of(ExceptionType.FORBIDDEN,"不能提交尚未开始的作业!");}
|
|
|
User student =new User();student.setId(uid);
|
|
|
Set<QuizStudentAnswer> QuizAnswers = quizStudentAnswerDAO.findByStudentAndQuiz(student,quiz);
|
|
|
Set<String> questionIdSet = new HashSet<>(quiz.getQuestions());
|
|
|
@@ -178,7 +180,7 @@ public class QuizServiceImpl implements QuizService {
|
|
|
|
|
|
@Override
|
|
|
public Page<Quiz> getAllBasicQuizBySlide(Integer slideId, Pageable pageable, QuizState state, Integer uid) {
|
|
|
- Assert.notNull(slideId,"slide can't be null");
|
|
|
+ Assert.notNull(slideId,"错误的幻灯片!");
|
|
|
Slide slide=new Slide();
|
|
|
slide.setId(slideId);
|
|
|
if(state!=null)
|
|
|
@@ -292,14 +294,14 @@ public class QuizServiceImpl implements QuizService {
|
|
|
}
|
|
|
@Override
|
|
|
public QuizVO combineQuiz(Long quizId){
|
|
|
- Assert.notNull(quizId,"QUIZ ID can't be null!");
|
|
|
+ Assert.notNull(quizId,"错误的测试!");
|
|
|
final Quiz quizById = quizDAO.findQuizById(quizId);
|
|
|
final List<QuestionVO> questionVOS = bokUtil.BokFindByIdIn(quizById.getQuestions());
|
|
|
return new QuizVO(quizById,questionVOS);
|
|
|
}
|
|
|
@Override
|
|
|
public QuizVO combineQuizWithAnswer(Long quizId, Integer uid,UserType userType){
|
|
|
- Assert.notNull(quizId,"QUIZ ID can't be null!");
|
|
|
+ Assert.notNull(quizId,"错误的测试!");
|
|
|
final Quiz quizById = quizDAO.findQuizById(quizId);
|
|
|
User student =new User();
|
|
|
student.setId(uid);
|