|
@@ -1,20 +1,18 @@
|
|
|
package nju.seec.helper.aspect.record;
|
|
package nju.seec.helper.aspect.record;
|
|
|
|
|
|
|
|
-import com.google.common.collect.Lists;
|
|
|
|
|
import nju.seec.helper.api.bok.RecordApi;
|
|
import nju.seec.helper.api.bok.RecordApi;
|
|
|
-import nju.seec.helper.api.bok.dto.RecordDTO;
|
|
|
|
|
import nju.seec.helper.api.dataanalysis.ExerciseApi;
|
|
import nju.seec.helper.api.dataanalysis.ExerciseApi;
|
|
|
-import nju.seec.helper.api.dataanalysis.dto.ExerciseRecordDTO;
|
|
|
|
|
import nju.seec.helper.aspect.auth.LoginUser;
|
|
import nju.seec.helper.aspect.auth.LoginUser;
|
|
|
import nju.seec.helper.dto.quiz.QuizStudentAnswerDTO;
|
|
import nju.seec.helper.dto.quiz.QuizStudentAnswerDTO;
|
|
|
import nju.seec.helper.vo.quiz.QuizStudentAnswerVO;
|
|
import nju.seec.helper.vo.quiz.QuizStudentAnswerVO;
|
|
|
import org.aspectj.lang.annotation.AfterReturning;
|
|
import org.aspectj.lang.annotation.AfterReturning;
|
|
|
import org.aspectj.lang.annotation.Aspect;
|
|
import org.aspectj.lang.annotation.Aspect;
|
|
|
-import org.springframework.scheduling.annotation.Async;
|
|
|
|
|
|
|
+import org.aspectj.lang.annotation.Pointcut;
|
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
+import java.util.Objects;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @author cst
|
|
* @author cst
|
|
@@ -30,26 +28,52 @@ public class ExerciseRecordAspect {
|
|
|
this.recordApi = recordApi;
|
|
this.recordApi = recordApi;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- @Async
|
|
|
|
|
- @AfterReturning(value = "@annotation(exerciseRecord) && args(user,..,quizStudentAnswerDTO)", returning = "quizStudentAnswerVO", argNames = "exerciseRecord,user,quizStudentAnswerDTO,quizStudentAnswerVO")
|
|
|
|
|
- public void reportExerciseRecordEvent(ExerciseRecord exerciseRecord, LoginUser user, QuizStudentAnswerDTO quizStudentAnswerDTO, QuizStudentAnswerVO quizStudentAnswerVO) {
|
|
|
|
|
|
|
+ @Pointcut(value = "@annotation(exerciseRecord) && args(user,..,quizStudentAnswerDTO)", argNames = "exerciseRecord,user,quizStudentAnswerDTO")
|
|
|
|
|
+ public void pointCut(ExerciseRecord exerciseRecord, LoginUser user, QuizStudentAnswerDTO quizStudentAnswerDTO) {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @AfterReturning(value = "pointCut(exerciseRecord,user,quizStudentAnswerDTO)", returning = "quizStudentAnswerVO", argNames = "exerciseRecord,user,quizStudentAnswerDTO,quizStudentAnswerVO")
|
|
|
|
|
+ public void reportRecordToData(ExerciseRecord exerciseRecord, LoginUser user, QuizStudentAnswerDTO quizStudentAnswerDTO, QuizStudentAnswerVO quizStudentAnswerVO) {
|
|
|
|
|
+ String userId = String.valueOf(user.getPid());
|
|
|
|
|
+ Map<String, QuizStudentAnswerVO.QuestionStudentAnswerInfo> questionStudentAnswerInfoMap = quizStudentAnswerVO.getAnswers();
|
|
|
|
|
+ exerciseApi.reportExercise(
|
|
|
|
|
+ quizStudentAnswerDTO
|
|
|
|
|
+ .getRecords()
|
|
|
|
|
+ .entrySet()
|
|
|
|
|
+ .stream()
|
|
|
|
|
+ .map(answerRecordDTOEntry -> {
|
|
|
|
|
+ String questionId = answerRecordDTOEntry.getKey();
|
|
|
|
|
+ QuizStudentAnswerDTO.AnswerRecordDTO answerRecordDTO = answerRecordDTOEntry.getValue();
|
|
|
|
|
+ QuizStudentAnswerVO.QuestionStudentAnswerInfo studentAnswerInfo = questionStudentAnswerInfoMap.get(questionId);
|
|
|
|
|
+ return studentAnswerInfo != null
|
|
|
|
|
+ ? exerciseApi.createExerciseRecordDTO(userId, questionId, answerRecordDTO.getStartAt(), answerRecordDTO.getEndAt(), studentAnswerInfo.getCorrect())
|
|
|
|
|
+ : null;
|
|
|
|
|
+ })
|
|
|
|
|
+ .filter(Objects::nonNull)
|
|
|
|
|
+ .collect(Collectors.toList())
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @AfterReturning(value = "pointCut(exerciseRecord,user,quizStudentAnswerDTO)", returning = "quizStudentAnswerVO", argNames = "exerciseRecord,user,quizStudentAnswerDTO,quizStudentAnswerVO")
|
|
|
|
|
+ public void reportRecordToBok(ExerciseRecord exerciseRecord, LoginUser user, QuizStudentAnswerDTO quizStudentAnswerDTO, QuizStudentAnswerVO quizStudentAnswerVO) {
|
|
|
String userId = String.valueOf(user.getPid());
|
|
String userId = String.valueOf(user.getPid());
|
|
|
Map<String, QuizStudentAnswerVO.QuestionStudentAnswerInfo> questionStudentAnswerInfoMap = quizStudentAnswerVO.getAnswers();
|
|
Map<String, QuizStudentAnswerVO.QuestionStudentAnswerInfo> questionStudentAnswerInfoMap = quizStudentAnswerVO.getAnswers();
|
|
|
- int size = quizStudentAnswerDTO.getRecords().size();
|
|
|
|
|
- List<ExerciseRecordDTO> exerciseRecords = Lists.newArrayListWithExpectedSize(size);
|
|
|
|
|
- List<RecordDTO> records = Lists.newArrayListWithExpectedSize(size);
|
|
|
|
|
- quizStudentAnswerDTO
|
|
|
|
|
- .getRecords()
|
|
|
|
|
- .forEach((key, value) -> {
|
|
|
|
|
- QuizStudentAnswerVO.QuestionStudentAnswerInfo studentAnswerInfo = questionStudentAnswerInfoMap.get(key);
|
|
|
|
|
- if (studentAnswerInfo != null) {
|
|
|
|
|
- Boolean pass = studentAnswerInfo.getCorrect();
|
|
|
|
|
- Object answer = studentAnswerInfo.getAnswer();
|
|
|
|
|
- exerciseRecords.add(exerciseApi.createExerciseRecordDTO(userId, key, value.getStartAt(), value.getEndAt(), pass));
|
|
|
|
|
- records.add(recordApi.createRecordDTO(userId, key, answer, pass, value.getStartAt(), value.getEndAt()));
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- exerciseApi.reportExercise(exerciseRecords);
|
|
|
|
|
- recordApi.reportUserRecord(records);
|
|
|
|
|
|
|
+ recordApi.reportUserRecord(
|
|
|
|
|
+ quizStudentAnswerDTO
|
|
|
|
|
+ .getRecords()
|
|
|
|
|
+ .entrySet()
|
|
|
|
|
+ .stream()
|
|
|
|
|
+ .map(answerRecordDTOEntry -> {
|
|
|
|
|
+ String questionId = answerRecordDTOEntry.getKey();
|
|
|
|
|
+ QuizStudentAnswerDTO.AnswerRecordDTO answerRecordDTO = answerRecordDTOEntry.getValue();
|
|
|
|
|
+ QuizStudentAnswerVO.QuestionStudentAnswerInfo studentAnswerInfo = questionStudentAnswerInfoMap.get(questionId);
|
|
|
|
|
+ return studentAnswerInfo != null
|
|
|
|
|
+ ? recordApi.createRecordDTO(userId, questionId, studentAnswerInfo.getAnswer(), studentAnswerInfo.getCorrect(), answerRecordDTO.getStartAt(), answerRecordDTO.getEndAt())
|
|
|
|
|
+ : null;
|
|
|
|
|
+ })
|
|
|
|
|
+ .filter(Objects::nonNull)
|
|
|
|
|
+ .collect(Collectors.toList())
|
|
|
|
|
+ );
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|