Browse Source

feat: 6/11 api 完成

XuShengTao 6 năm trước cách đây
mục cha
commit
183e554f51

+ 2 - 0
src/main/java/nju/seec/helper/HelperApplication.java

@@ -3,6 +3,7 @@ package nju.seec.helper;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
+import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
 import org.springframework.transaction.annotation.EnableTransactionManagement;
 
 /**
@@ -10,6 +11,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
  */
 @ConfigurationPropertiesScan("nju.seec.helper.config.properties")
 @EnableTransactionManagement
+@EnableJpaAuditing
 @SpringBootApplication
 public class HelperApplication {
     public static void main(String[] args) {

+ 3 - 1
src/main/java/nju/seec/helper/controller/ControllerAdvice.java

@@ -27,7 +27,9 @@ public class ControllerAdvice {
 
     @ExceptionHandler(Exception.class)
     public ResponseEntity<ErrorResponse> handleException(Exception e) {
+        //todo: 方便调试
         log.error(e.getLocalizedMessage());
-        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(ErrorResponse.of("系统异常,请重试"));
+        e.printStackTrace();
+        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(ErrorResponse.of("系统异常,请重试:"+e.getLocalizedMessage()));
     }
 }

+ 34 - 45
src/main/java/nju/seec/helper/controller/QuizController.java

@@ -9,6 +9,8 @@ import nju.seec.helper.dto.LoginUser;
 import nju.seec.helper.dto.QuizAnswerDTO;
 import nju.seec.helper.dto.QuizDTO;
 import nju.seec.helper.dto.QuizUpdateDTO;
+import nju.seec.helper.entity.Quiz;
+import nju.seec.helper.service.QuizService;
 import nju.seec.helper.util.BOKUtil;
 import nju.seec.helper.util.enums.QuestionKindState;
 import nju.seec.helper.util.enums.QuizState;
@@ -21,11 +23,13 @@ import nju.seec.helper.vo.quiz.QuestionVO;
 import nju.seec.helper.vo.quiz.QuizVO;
 import nju.seec.helper.vo.quiz.TrueOrFalseQuestionVO;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Pageable;
 import org.springframework.data.web.PageableDefault;
 import org.springframework.web.bind.annotation.*;
 
 import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * 测试
@@ -41,47 +45,37 @@ public class QuizController {
     private SlideDAO slideDAO;
     @Autowired
     private BOKUtil bokUtil;
-
-    @GetMapping("/test")
-    public Object test() {
-        List list=new ArrayList();
-        list.add("1001");
-        list.add("1002");
-        list.add("1003");
-        return bokUtil.BokFindByIdIn(list);
-    }
+    @Autowired
+    private QuizService quizService;
 
     /**
-     * 获得测试列表 Stub
+     * 获得测试列表
      */
-    @Auth(roles = {UserType.STUDENT}, message = "获得测试列表")
+    @Auth(roles = {UserType.STUDENT,UserType.TEACHER}, message = "获得测试列表")
     @GetMapping("")
     public Map getBasicQuizList(LoginUser user, String slideId, boolean subscribe,
                       QuizState state	, @PageableDefault(Integer.MAX_VALUE) Pageable pageable) {
-        List quizs=new ArrayList<QuizVO>();
-        quizs.add(QuizVO.builder().questionNumber(1).state(QuizState.NOT_STARTED)
-                .name("第一次测试").QuizId("1").quizTime(SlideState.IN_CLASS)
-                .courseVO(new CourseVO(courseDAO.getOne(1)))
-                .slide(new SlideVO(slideDAO.getOne(1))).build());
+        List<QuizVO> quizs=new ArrayList<QuizVO>();
         Map ret=new LinkedHashMap(2);
+        Page<Quiz> page;
+        if(slideId!=null){
+            page = quizService.getAllBasicQuizBySlide(Integer.valueOf(slideId), pageable, state, user.getId());
+           }else{
+            page = quizService.getAllBasicQuizByUser( pageable, state, user.getId());
+        }
+        quizs.addAll(page.getContent().stream().map(QuizVO::new).collect(Collectors.toList()));
+        ret.put("page",PageResponse.PageInfo.of(page.getNumber(), page.getSize(), page.getTotalPages(), Long.valueOf(page.getTotalElements()).intValue()));
         ret.put("quizs",quizs);
-        ret.put("page",PageResponse.PageInfo.of(1,5,1,1));
         return ret;
     }
 
     /**
-     * 获得某一测试的详细内容 Stub
+     * 获得某一测试的详细内容
      */
-    @Auth(roles = {UserType.STUDENT}, message = "获得某一测试的详细内容")
+    @Auth(roles = {UserType.STUDENT,UserType.TEACHER}, message = "获得某一测试的详细内容")
     @GetMapping("/{quizId}")
     public QuizVO GetOneQuiz(LoginUser user, @PathVariable("quizId") String quizId) {
-        List<QuestionVO> Questions=new ArrayList<>();
-        Questions.add(ChoiceQ());
-        Questions.add(TFQ());
-        return QuizVO.builder().questionNumber(1).state(QuizState.NOT_STARTED)
-                .name("第一次测试").QuizId("1").quizTime(SlideState.IN_CLASS)
-                .courseVO(new CourseVO(courseDAO.getOne(1)))
-                .slide(new SlideVO(slideDAO.getOne(1))).questions(Questions).build();
+        return quizService.combineQuizWithAnswer(Long.valueOf(quizId),user.getId(),user.getType());
     }
 
     /**
@@ -89,39 +83,34 @@ public class QuizController {
      */
     @Auth(roles = {UserType.TEACHER}, message = "创建测试")
     @PostMapping("")
-    public QuizVO CreateQuiz(LoginUser user, QuizDTO newQuiz) {
-        List<QuestionVO> Questions=new ArrayList<>();
-        Questions.add(ChoiceQ());
-        Questions.add(TFQ());
-        return QuizVO.builder().questionNumber(1).state(QuizState.NOT_STARTED)
-                .name("第一次测试").QuizId("1").quizTime(SlideState.IN_CLASS)
-                .courseVO(new CourseVO(courseDAO.getOne(1)))
-                .slide(new SlideVO(slideDAO.getOne(1))).questions(Questions).build();
+    public QuizVO CreateQuiz(LoginUser user,@RequestBody QuizDTO newQuiz) {
+        System.out.println(newQuiz);
+        final Quiz quiz = quizService.CreateQuiz(newQuiz.getName(), user.getId(), newQuiz.getQuizTime(),
+                Integer.valueOf(newQuiz.getSlideId()), newQuiz.getQuestions());
+        return quizService.combineQuiz(quiz.getId());
     }
 
     /**
-     * 修改测试 (仅限未开始时可以修改) Stub
+     * 修改测试 (仅限未开始时可以修改)
      */
     @Auth(roles = {UserType.TEACHER}, message = "修改测试")
     @PutMapping("/{quizId}")
-    public QuizVO updateQuiz(LoginUser user, QuizUpdateDTO newQuiz, @PathVariable("quizId") String quizId) {
-        List<QuestionVO> Questions=new ArrayList<>();
-        Questions.add(ChoiceQ());
-        Questions.add(TFQ());
-        return QuizVO.builder().questionNumber(1).state(QuizState.NOT_STARTED)
-                .name("第一次测试").QuizId("1").quizTime(SlideState.IN_CLASS)
-                .courseVO(new CourseVO(courseDAO.getOne(1)))
-                .slide(new SlideVO(slideDAO.getOne(1))).questions(Questions).build();
+    public QuizVO updateQuiz(LoginUser user, @RequestBody QuizUpdateDTO newQuiz, @PathVariable("quizId") String quizId) {
+
+        Quiz ret = quizService.modifyQuiz(Long.valueOf(quizId),newQuiz.getName(),
+                newQuiz.getQuestions(),newQuiz.getQuizTime(),newQuiz.getSlideId());
+        return quizService.combineQuiz(ret.getId());
     }
 
     /**
-     * 删除测试 (仅限未开始时可以删除) Stub
+     * 删除测试 (仅限未开始时可以删除)
      */
     @Auth(roles = {UserType.TEACHER}, message = "删除测试")
     @DeleteMapping("/{quizId}")
     public Map deleteQuiz(LoginUser user, @PathVariable("quizId") String quizId) {
         Map map=new HashMap();
-        map.put("message","success");
+        String message = quizService.deleteQuiz(Long.valueOf(quizId));
+        map.put("message",message);
         return map;
     }
 

+ 3 - 1
src/main/java/nju/seec/helper/controller/response/PageResponse.java

@@ -16,7 +16,9 @@ public class PageResponse<T> {
     private PageInfo page;
 
     public static <T> PageResponse<T> of(Page<T> page) {
-        return new PageResponse<>(page.getContent(), PageInfo.of(page.getNumber(), page.getSize(), page.getTotalPages(), page.getNumberOfElements()));
+        return new PageResponse<>(page.getContent(),
+                PageInfo.of(page.getNumber(), page.getSize(),
+                        page.getTotalPages(), page.getNumberOfElements()));
     }
 
     @Data

+ 11 - 2
src/main/java/nju/seec/helper/dao/QuizDAO.java

@@ -3,11 +3,16 @@ package nju.seec.helper.dao;
 import nju.seec.helper.entity.Course;
 import nju.seec.helper.entity.Quiz;
 import nju.seec.helper.entity.Slide;
+import nju.seec.helper.entity.User;
 import nju.seec.helper.util.enums.ExceptionType;
+import nju.seec.helper.util.enums.QuizState;
 import nju.seec.helper.util.exception.HelperException;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
 import org.springframework.data.jpa.repository.JpaRepository;
 
 import java.util.Collection;
+import java.util.Optional;
 import java.util.Set;
 
 public interface QuizDAO extends JpaRepository<Quiz,Long> {
@@ -15,6 +20,10 @@ public interface QuizDAO extends JpaRepository<Quiz,Long> {
         return this.findById(id)
                 .orElseThrow(() -> HelperException.of(ExceptionType.NOT_FOUND, "找不到测试"));
     }
-    Set<Quiz> findAllBySlide(Slide slide);
-    Set<Quiz> findAllByCourseIn(Collection<Course> course);
+    Page<Quiz> findAllBySlideAndState(Slide slide, QuizState state, Pageable pageable);
+    Page<Quiz> findAllBySlide(Slide slide, Pageable pageable);
+    Page<Quiz> findAllByCourseIn(Collection<Course> course, Pageable pageable);
+    Page<Quiz> findAllByCourseInAndState(Collection<Course> course, QuizState state,Pageable pageable);
+    Page<Quiz> findByTeacher(User teacher, Pageable pageable);
+    Page<Quiz> findByTeacherAndState(User teacher, QuizState state, Pageable pageable);
 }

+ 1 - 1
src/main/java/nju/seec/helper/dto/QuizDTO.java

@@ -22,6 +22,6 @@ public class QuizDTO {
     @NotBlank
     String slideId;
     @NotBlank
-    List questions;
+    List<String> questions;
 
 }

+ 1 - 6
src/main/java/nju/seec/helper/dto/QuizUpdateDTO.java

@@ -15,15 +15,10 @@ import java.util.List;
 //}
 @Data
 public class QuizUpdateDTO {
-    @NotBlank
     String id;
-    @NotBlank
     String name;
-    @NotNull
     SlideState quizTime;
-    @NotBlank
     String slideId;
-    @NotBlank
-    List questions;
+    List<String> questions;
 
 }

+ 3 - 3
src/main/java/nju/seec/helper/entity/Quiz.java

@@ -27,15 +27,15 @@ public class Quiz {
     @Column(name = "name", nullable = false)
     private String name;
 
-    @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
+    @ManyToOne(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
     @JoinColumn(name="slide",referencedColumnName="id")
     private Slide slide;
 
-    @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
+    @ManyToOne(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
     @JoinColumn(name="course",referencedColumnName="id")
     private Course course;
 
-    @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
+    @ManyToOne(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
     @JoinColumn(name="teacher",referencedColumnName="id")
     private User teacher;
 

+ 2 - 2
src/main/java/nju/seec/helper/entity/QuizStudentAnswer.java

@@ -18,11 +18,11 @@ public class QuizStudentAnswer {
     @Column(name = "id")
     private Long id;
 
-    @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
+    @ManyToOne(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
     @JoinColumn(name="quiz",referencedColumnName="id")
     private Quiz quiz;
 
-    @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
+    @ManyToOne(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
     @JoinColumn(name="student",referencedColumnName="id")
     private User student;
 

+ 27 - 0
src/main/java/nju/seec/helper/service/QuizService.java

@@ -1,5 +1,32 @@
 package nju.seec.helper.service;
 
+import nju.seec.helper.entity.Quiz;
+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.vo.quiz.QuizVO;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.Collection;
+import java.util.List;
+
 public interface QuizService {
 
+    @Transactional
+    Quiz CreateQuiz(String name, Integer uid, SlideState quizTime,
+                    Integer slideId, List<String> questions);
+
+    Page<Quiz> getAllBasicQuizBySlide(Integer slideId, Pageable pageable, QuizState state, Integer uid);
+
+    QuizVO combineQuiz(Long quizId);
+
+    QuizVO combineQuizWithAnswer(Long quizId, Integer uid, UserType type);
+
+    String deleteQuiz(Long quizId);
+
+    Quiz modifyQuiz(Long quizId, String name, List<String> questions, SlideState quizTime, String slideId);
+
+    Page<Quiz> getAllBasicQuizByUser(Pageable pageable, QuizState state, Integer uid);
 }

+ 118 - 9
src/main/java/nju/seec/helper/service/impl/QuizServiceImpl.java

@@ -1,22 +1,24 @@
 package nju.seec.helper.service.impl;
 
-import nju.seec.helper.dao.QuizDAO;
-import nju.seec.helper.dao.QuizStudentAnswerDAO;
-import nju.seec.helper.dao.SlideDAO;
+import nju.seec.helper.dao.*;
 import nju.seec.helper.dto.LoginUser;
 import nju.seec.helper.entity.*;
 import nju.seec.helper.service.QuizService;
 import nju.seec.helper.util.BOKUtil;
 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.vo.quiz.QuestionVO;
 import nju.seec.helper.vo.quiz.QuizVO;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.Assert;
 
 import java.util.*;
+import java.util.stream.Collectors;
 
 @Service
 public class QuizServiceImpl implements QuizService {
@@ -27,9 +29,16 @@ public class QuizServiceImpl implements QuizService {
     @Autowired
     private QuizStudentAnswerDAO quizStudentAnswerDAO;
     @Autowired
+    private ChooseDAO chooseDAO;
+    @Autowired
+    private CourseDAO courseDAO;
+    @Autowired
+    private UserDAO userDAO;
+    @Autowired
     private BOKUtil bokUtil;
+    @Override
     @Transactional
-    public QuizVO CreateQuiz(String name, Integer uid, SlideState quizTime,
+    public Quiz CreateQuiz(String name, Integer uid, SlideState quizTime,
                              Integer slideId, List<String> questions){
         User teacher =new User();
         teacher.setId(uid);
@@ -44,25 +53,123 @@ public class QuizServiceImpl implements QuizService {
         quiz.setQuizTime(quizTime);
         quiz.setSlide(slide);
         quiz.setTeacher(teacher);
-        quiz.setState(quizTime.getNum()<slide.getState().getNum()?QuizState.CLOSED:QuizState.ONGOING);
+
+        checkQuizState(quiz,slide);
+
         quiz=quizDAO.saveAndFlush(quiz);
-        return combineQuiz(quiz.getId());
+        return quiz;
+    }
+    @Override
+    public String deleteQuiz(Long quizId) {
+        Quiz quiz =quizDAO.findQuizById(quizId);
+        if(quiz.getState()!=QuizState.NOT_STARTED){return "can't delete started quiz!";}
+        quizDAO.delete(quiz);
+        return "delete success";
+    }
+
+    @Override
+    @Transactional
+    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(name!=null) quiz.setName(name);
+        if(questions!=null) quiz.setQuestions(questions);
+        if(quizTime!=null) {
+            quiz.setQuizTime(quizTime);
+            checkQuizState(quiz,quiz.getSlide());
+        }
+        final Quiz quiz1 = quizDAO.saveAndFlush(quiz);
+        return quiz1;
+
+    }
+
+    @Override
+    public Page<Quiz> getAllBasicQuizByUser(Pageable pageable, QuizState state, Integer uid) {
+        User user=userDAO.findUserById(uid);
+        //todo: 这里写的太狗屎了,可以用重写sql或者用实例查询
+        if(user.getType().equals(UserType.STUDENT)){
+            final Set<Integer> courseIdsByStudentId = chooseDAO.findCourseIdsByStudentId(uid);
+            final Set<Course> collect = courseIdsByStudentId.stream().map(i -> {
+                Course c = new Course();
+                c.setId(i);
+                return c;
+            }).collect(Collectors.toSet());
+            if(state!=null){
+                return quizDAO.findAllByCourseInAndState(collect,state,pageable);
+            }else{
+                return quizDAO.findAllByCourseIn(collect,pageable);
+            }
+        }else{
+            if(state!=null){
+                return quizDAO.findByTeacherAndState(user,state,pageable);
+            }else{
+                return quizDAO.findByTeacher(user,pageable);
+            }
+
+        }
+
+    }
+
+    @Override
+    public Page<Quiz> getAllBasicQuizBySlide(Integer slideId, Pageable pageable, QuizState state, Integer uid) {
+        Assert.notNull(slideId,"slide can't be null");
+        Slide slide=new Slide();
+        slide.setId(slideId);
+        if(state!=null)
+            return quizDAO.findAllBySlideAndState(slide,state, pageable);
+        else
+            return quizDAO.findAllBySlide(slide,pageable);
     }
 
+    public void checkQuizState(Quiz quiz,Slide slide){
+        int QuizTime=quiz.getQuizTime().getNum();
+        int slideTime=slide.getState().getNum();
+        if(quiz.getId()==null)
+            //未持久化的quiz
+            quiz.setState(slideTime<QuizTime?QuizState.NOT_STARTED:QuizState.ONGOING);
+        else {
+            //持久化后,不仅仅需要推进状态,还需要判分等步骤
+            if(slideTime<QuizTime){
+                //未开始
+                quiz.setState(QuizState.NOT_STARTED);
+            }else if(slideTime==QuizTime){
+                quiz.setState(QuizState.ONGOING);
+            }else{
+                quiz.setState(QuizState.CLOSED);
+            }
+
+        }
+    }
+
+    @Override
     public QuizVO combineQuiz(Long quizId){
         Assert.notNull(quizId,"QUIZ ID can't be null!");
         final Quiz quizById = quizDAO.findQuizById(quizId);
         final List<QuestionVO> questionVOS = bokUtil.BokFindByIdIn(quizById.getQuestions());
+        System.out.println(questionVOS);
         QuizVO ret= new QuizVO(quizById,questionVOS);
         return ret;
     }
-    public QuizVO combineQuizWithAnswer(Long quizId, Integer uid){
+    @Override
+    public QuizVO combineQuizWithAnswer(Long quizId, Integer uid,UserType userType){
         Assert.notNull(quizId,"QUIZ ID can't be null!");
         final Quiz quizById = quizDAO.findQuizById(quizId);
         User student =new User();
         student.setId(uid);
-        final Set<QuizStudentAnswer> QuizAnswers = quizStudentAnswerDAO.findByQuizAndStudent(quizById, student);
+
+        if(userType.equals(UserType.TEACHER)){
+            //向老师展示
+            List<QuestionVO> questionVOS = bokUtil.BokFindByIdIn(quizById.getQuestions());
+            return new QuizVO(quizById,questionVOS);
+        }
+        if(quizById.getState().equals(QuizState.NOT_STARTED)){
+            //未开始看不到题目
+            return new QuizVO(quizById);
+        }
+
         List<QuestionVO> questionVOS = bokUtil.BokFindByIdIn(quizById.getQuestions());
+        final Set<QuizStudentAnswer> QuizAnswers = quizStudentAnswerDAO.findByQuizAndStudent(quizById, student);
         Map<String,QuizStudentAnswer> qsaMap=new HashMap<>(QuizAnswers.size());
         for(QuizStudentAnswer qsa: QuizAnswers){
             qsaMap.put(qsa.getQuestionId(),qsa);
@@ -71,9 +178,11 @@ public class QuizServiceImpl implements QuizService {
             if(qsaMap.get(vo.getQuestionId())!=null){
                 vo.exAddAnswer(qsaMap.get(vo.getQuestionId()));
             }
-
         }
+
         QuizVO ret= new QuizVO(quizById,questionVOS);
         return ret;
     }
+
+
 }

+ 5 - 1
src/main/java/nju/seec/helper/util/BOKUtil.java

@@ -48,6 +48,8 @@ public class BOKUtil {
     }
 
     public List<QuestionVO> BokFindByIdIn(List<String> Ids) {
+        //todo: 缓存Ids
+
         Map<String,String> urlParams=new HashMap<>();
         String idsStr=Ids.stream().reduce((a,b)->{return a+","+b;}).orElse("");
         urlParams.put("id",idsStr);
@@ -55,9 +57,11 @@ public class BOKUtil {
         urlParams.put("page","1");
         try {
             Map ret = (Map)restRequestUtil.sendPostGet(
-                    searchUrl+"findByIdIn?id={id}&sort={sort}&size={size}&page={page}", urlParams);
+                    searchUrl+"findByIdIn?id={id}&size={size}&page={page}", urlParams);
             List<Map> tqs= ((List)((Map)ret.get("_embedded")).get("choiceQuestions"));
             List<QuestionVO> collect = parseBody(tqs);
+
+            // todo: 重排序
             return (collect);
 
         }catch (Exception e){

+ 12 - 1
src/main/java/nju/seec/helper/vo/quiz/QuizVO.java

@@ -1,6 +1,7 @@
 package nju.seec.helper.vo.quiz;
 
 
+import com.fasterxml.jackson.annotation.JsonInclude;
 import com.fasterxml.jackson.annotation.JsonProperty;
 import lombok.AllArgsConstructor;
 import lombok.Builder;
@@ -35,10 +36,11 @@ public class QuizVO {
     @JsonProperty(value = "questionNumber")
     private Integer questionNumber;
     @JsonProperty(value = "questions")
+    @JsonInclude(JsonInclude.Include.NON_NULL)
     private List<QuestionVO> questions;
 
     public QuizVO(Quiz quiz,List<QuestionVO> questions) {
-        QuizId = quiz.getId().toString();
+        this.QuizId = quiz.getId().toString();
         this.name = quiz.getName();
         this.state = quiz.getState();
         this.courseVO = new CourseVO(quiz.getCourse());
@@ -47,6 +49,15 @@ public class QuizVO {
         this.questionNumber = questions.size();
         this.questions = questions;
     }
+    public QuizVO(Quiz quiz) {
+        this.QuizId = quiz.getId().toString();
+        this.name = quiz.getName();
+        this.state = quiz.getState();
+        this.courseVO = new CourseVO(quiz.getCourse());
+        this.quizTime = quiz.getQuizTime();
+        this.slide = new SlideVO(quiz.getSlide());
+        this.questionNumber = quiz.getQuestions().size();
+    }
 }
 // http://47.100.18.120:3000/SEEC-BOK/API-DOC/src/master/helper/serializer/QuizSerializer.md
 // /** 已实现的枚举类 */