|
|
@@ -1,57 +0,0 @@
|
|
|
-package nju.seec.helper.aspect.event;
|
|
|
-
|
|
|
-import nju.seec.helper.api.dataanalysis.ExerciseApi;
|
|
|
-import nju.seec.helper.api.dataanalysis.ExerciseRecord;
|
|
|
-import nju.seec.helper.aspect.auth.LoginUser;
|
|
|
-import nju.seec.helper.dto.quiz.QuizStudentAnswerDTO;
|
|
|
-import nju.seec.helper.vo.quiz.QuizStudentAnswerVO;
|
|
|
-import org.aspectj.lang.JoinPoint;
|
|
|
-import org.aspectj.lang.annotation.AfterReturning;
|
|
|
-import org.aspectj.lang.annotation.Aspect;
|
|
|
-import org.springframework.stereotype.Component;
|
|
|
-
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Objects;
|
|
|
-import java.util.stream.Collectors;
|
|
|
-
|
|
|
-/**
|
|
|
- * @author cst
|
|
|
- */
|
|
|
-@Aspect
|
|
|
-@Component
|
|
|
-public class ExerciseRecordEventAspect {
|
|
|
- private final ExerciseApi exerciseApi;
|
|
|
-
|
|
|
- public ExerciseRecordEventAspect(ExerciseApi exerciseApi) {
|
|
|
- this.exerciseApi = exerciseApi;
|
|
|
- }
|
|
|
-
|
|
|
- @AfterReturning(pointcut = "@annotation(exerciseRecordEvent)", returning = "quizStudentAnswerVO")
|
|
|
- public void reportExerciseRecordEvent(JoinPoint joinPoint, ExerciseRecordEvent exerciseRecordEvent, QuizStudentAnswerVO quizStudentAnswerVO) {
|
|
|
- Object[] args = joinPoint.getArgs();
|
|
|
- LoginUser user = null;
|
|
|
- QuizStudentAnswerDTO quizStudentAnswerDTO = null;
|
|
|
- for (Object arg : args) {
|
|
|
- if (arg instanceof LoginUser) {
|
|
|
- user = (LoginUser) arg;
|
|
|
- }
|
|
|
- if (arg instanceof QuizStudentAnswerDTO) {
|
|
|
- quizStudentAnswerDTO = (QuizStudentAnswerDTO) arg;
|
|
|
- }
|
|
|
- }
|
|
|
- String userId = String.valueOf(Objects.requireNonNull(user).getPid());
|
|
|
- Map<String, QuizStudentAnswerVO.QuestionStudentAnswerInfo> questionStudentAnswerInfoMap = quizStudentAnswerVO.getAnswers();
|
|
|
- List<ExerciseRecord> exerciseRecords =
|
|
|
- Objects.requireNonNull(quizStudentAnswerDTO)
|
|
|
- .getRecords()
|
|
|
- .entrySet()
|
|
|
- .parallelStream()
|
|
|
- .map(answerRecordEntry ->
|
|
|
- exerciseApi.createExerciseRecord(
|
|
|
- userId, answerRecordEntry.getKey(), answerRecordEntry.getValue().getStartAt(), answerRecordEntry.getValue().getEndAt(), questionStudentAnswerInfoMap.get(answerRecordEntry.getKey()).getCorrect()
|
|
|
- ))
|
|
|
- .collect(Collectors.toList());
|
|
|
- exerciseApi.reportExercise(exerciseRecords);
|
|
|
- }
|
|
|
-}
|