Bläddra i källkod

feat:新增quizStudentAnswer几个接口

sky 5 år sedan
förälder
incheckning
8ff5c63ec2

+ 31 - 0
src/main/java/nju/seec/helper/controller/QuizController.java

@@ -18,10 +18,14 @@ import nju.seec.helper.vo.quiz.QuizStudentAnswerStatisticVO;
 import nju.seec.helper.vo.quiz.QuizStudentAnswerVO;
 import nju.seec.helper.vo.quiz.QuizVO;
 import org.springframework.data.domain.Pageable;
+import org.springframework.data.repository.query.Param;
 import org.springframework.data.web.PageableDefault;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
+import java.sql.Timestamp;
+import java.util.List;
+
 /**
  * 测试
  *
@@ -153,4 +157,31 @@ public class QuizController {
     public QuizStudentAnswerStatisticVO getQuizStatistic(LoginUser user, @PathVariable Long quizId) {
         return quizStudentAnswerService.getQuizStudentAnswerStatistic(user, quizId);
     }
+
+    /**
+     * 根据统一门户用户Id获取用户所有作答记录
+     * @author Sky
+     * */
+    @GetMapping("/quiz-records/pid/{studentPid}")
+    public List<QuizStudentAnswerVO> getQuizRecordsByStudentPid(@PathVariable Long studentPid) {
+        return quizStudentAnswerService.getQuizStudentAnswersByStudentPid(studentPid);
+    }
+
+    /**
+     * 根据用户Id获取用户所有作答记录
+     * @author Sky
+     * */
+    @GetMapping("/quiz-records/id/{studentId}")
+    public List<QuizStudentAnswerVO> getQuizRecordsByStudentId(@PathVariable Long studentId) {
+        return quizStudentAnswerService.getQuizStudentAnswersByStudentId(studentId);
+    }
+
+    /**
+     * 所有作答记录
+     * @author Sky
+     * */
+    @GetMapping("/quiz-records/all")
+    public List<QuizStudentAnswerVO> getAllQuizRecords(@RequestParam("start") String start, @RequestParam("end") String end) {
+        return quizStudentAnswerService.getAllQuizStudentAnswersByTime(start, end);
+    }
 }

+ 20 - 0
src/main/java/nju/seec/helper/dao/QuizStudentAnswerDAO.java

@@ -8,10 +8,13 @@ import org.springframework.data.domain.Pageable;
 import org.springframework.data.jpa.domain.Specification;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.data.jpa.repository.Query;
 import org.springframework.stereotype.Repository;
 import org.springframework.util.StringUtils;
 
 import javax.persistence.criteria.JoinType;
+import java.sql.Timestamp;
+import java.time.LocalDateTime;
 import java.util.List;
 import java.util.Optional;
 
@@ -64,4 +67,21 @@ public interface QuizStudentAnswerDAO extends JpaRepository<QuizStudentAnswer, L
      * @return
      */
     List<QuizStudentAnswer> findByQuiz(Quiz quiz);
+
+
+    /**
+     * 根据用户Id检索
+     *
+     * @author Sky
+     */
+    List<QuizStudentAnswer> findByStudentId(Long student_id);
+
+
+    /**
+     * 根据时间检索
+     *
+     * @author Sky
+     */
+    @Query("select q from QuizStudentAnswer q where q.submitAt >= :start and q.submitAt < :end")/* TODO*/
+     List<QuizStudentAnswer>  findBetweenTime(LocalDateTime start, LocalDateTime end);
 }

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

@@ -26,6 +26,7 @@ import java.util.Map;
 @Table(name = "quiz_student_answer", uniqueConstraints = @UniqueConstraint(name = "quiz_student_unique", columnNames = {"quiz_id", "student_id"}))
 @DynamicUpdate
 @DynamicInsert
+@Where(clause = "quiz_id in (select q.id from quiz q where q.delete_at = 0 and q.slide_id in (select s.id from slide s where s.delete_at = 0) and q.course_id in (select c.id from course c where c.delete_at = 0))")
 public class QuizStudentAnswer {
     @Id
     @GeneratedValue(strategy = GenerationType.IDENTITY)

+ 20 - 0
src/main/java/nju/seec/helper/service/QuizStudentAnswerService.java

@@ -7,6 +7,9 @@ import nju.seec.helper.vo.quiz.QuizStudentAnswerVO;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Pageable;
 
+import java.sql.Timestamp;
+import java.util.List;
+
 /**
  * @author cst
  */
@@ -49,4 +52,21 @@ public interface QuizStudentAnswerService {
      * @return
      */
     QuizStudentAnswerStatisticVO getQuizStudentAnswerStatistic(LoginUser user, Long quizId);
+
+    /**
+     * 获取用户在该系统的做题记录 by pid
+     * @author Sky
+     * */
+    List<QuizStudentAnswerVO> getQuizStudentAnswersByStudentPid(Long studentPid);
+
+    /**
+     * 获取用户在该系统的做题记录 by id
+     * @author Sky
+     * */
+    List<QuizStudentAnswerVO> getQuizStudentAnswersByStudentId(Long studentId);
+
+    /**
+     * 获取所有做题记录
+     * */
+    List<QuizStudentAnswerVO> getAllQuizStudentAnswersByTime(String start, String end);
 }

+ 53 - 2
src/main/java/nju/seec/helper/service/impl/QuizStudentAnswerServiceImpl.java

@@ -24,9 +24,12 @@ import org.springframework.transaction.annotation.Transactional;
 
 import java.math.BigDecimal;
 import java.math.RoundingMode;
-import java.util.List;
-import java.util.Map;
+import java.sql.Timestamp;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.*;
 import java.util.concurrent.atomic.AtomicInteger;
+import java.util.stream.Collectors;
 
 /**
  * @author cst
@@ -133,4 +136,52 @@ public class QuizStudentAnswerServiceImpl implements QuizStudentAnswerService {
 
         return QuizStudentAnswerStatisticVO.of(quizId, scores, submitNums);
     }
+
+    /**
+     * 根据用户Pid查做题记录
+     * @author Sky
+     * */
+    @Override
+    public List<QuizStudentAnswerVO> getQuizStudentAnswersByStudentPid(Long studentPid) {
+        Optional<User> user = userDAO.findByPid(studentPid);
+        Long studentId = null;
+        if(user.isPresent()) {
+            studentId = (Long)user.get().getId();
+            return this.getQuizStudentAnswersByStudentId(studentId);
+        } else {
+            return new ArrayList<>();
+        }
+    }
+
+    /**
+     * 根据用户Id查做题记录
+     * @author Sky
+     * */
+    @Override
+    public List<QuizStudentAnswerVO> getQuizStudentAnswersByStudentId(Long studentId) {
+        return quizStudentAnswerDAO.findByStudentId(studentId).stream().map(
+                qsadao -> new QuizStudentAnswerVO(qsadao,questionService.getQuestionsByIds(quizDAO.findQuizById(qsadao.getQuiz().getId()).getQuestions()))
+        ).collect(Collectors.toList());
+    }
+
+
+    /**
+     * 查所有做题记录
+     * @author Sky
+     * */
+    @Override
+    public List<QuizStudentAnswerVO> getAllQuizStudentAnswersByTime(String start, String end) { //TODO
+        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+        try {
+            LocalDateTime startTime = LocalDateTime.parse(start, dtf);
+            LocalDateTime endTime = LocalDateTime.parse(end, dtf);
+            System.out.println(startTime + " " + endTime);
+            return quizStudentAnswerDAO.findBetweenTime(startTime, endTime).stream().map(
+                    qsadao -> new QuizStudentAnswerVO(qsadao,questionService.getQuestionsByIds(quizDAO.findQuizById(qsadao.getQuiz().getId()).getQuestions()))
+            ).collect(Collectors.toList());
+        } catch (java.lang.IllegalArgumentException e) {
+            e.printStackTrace();
+        }
+        return new LinkedList<>();
+    }
 }

+ 4 - 2
src/main/java/nju/seec/helper/service/impl/RecordServiceImpl.java

@@ -30,15 +30,17 @@ public class RecordServiceImpl implements RecordService {
 
     @Override
     public List<ExerciseRecord> getAllRecords() {
-        return userDAO.findByPidNotNull()
+        return userDAO.findByPidNotNull() /* 找到在bok中有记录的user */
                 .stream()
-                .flatMap(user -> getRecordsByUserId(String.valueOf(user.getPid())).stream())
+                .flatMap(user -> getRecordsByUserId(String.valueOf(user.getPid())).stream()) /* 去bok取user的做题记录 */
                 .collect(Collectors.toList());
     }
 
     @Override
     public List<ExerciseRecord> getRecordsByUserId(String userId) {
+        /* 去bok取user的所有做题记录 */
         RecordQuestionVO recordQuestionVO = recordApi.getUserRecordQuestions(userId, PageRequest.of(0, Integer.MAX_VALUE));
+        /* 转个格式 */
         return recordQuestionVO.getRecords().stream().map(recordVO -> exerciseApi.createExerciseRecordDTO(recordVO.getUserId(), recordVO.getQuestionId(), recordVO.getStartAt(), recordVO.getFinishAt(), recordVO.getPass())).collect(Collectors.toList());
     }
 }

+ 1 - 0
src/main/java/nju/seec/helper/vo/quiz/QuizStudentAnswerVO.java

@@ -1,6 +1,7 @@
 package nju.seec.helper.vo.quiz;
 
 import lombok.AllArgsConstructor;
+import lombok.Builder;
 import lombok.Data;
 import lombok.NonNull;
 import nju.seec.helper.entity.QuizStudentAnswer;

+ 1 - 1
src/main/resources/application-dev.yml

@@ -3,7 +3,7 @@ spring:
     url: jdbc:mysql://localhost:3306/helper?setUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true
     driver-class-name: com.mysql.cj.jdbc.Driver
     username: root
-    password: 123456
+    password: root
   jpa:
     open-in-view: true
     hibernate:

+ 3 - 3
src/main/resources/application.yml

@@ -1,3 +1,3 @@
-#spring:
-#  profiles:
-#    active: dev
+spring:
+  profiles:
+    active: dev