|
|
@@ -1,20 +1,18 @@
|
|
|
package nju.seec.helper.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.text.StrBuilder;
|
|
|
import com.google.common.collect.Lists;
|
|
|
+import nju.seec.helper.api.dataanalysis.EventAction;
|
|
|
import nju.seec.helper.api.dataanalysis.EventType;
|
|
|
import nju.seec.helper.dao.*;
|
|
|
-import nju.seec.helper.entity.Comment;
|
|
|
-import nju.seec.helper.entity.Course;
|
|
|
-import nju.seec.helper.entity.User;
|
|
|
+import nju.seec.helper.entity.*;
|
|
|
+import nju.seec.helper.enums.UserRole;
|
|
|
import nju.seec.helper.service.EventService;
|
|
|
import nju.seec.helper.vo.EventVO;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
-import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
-import java.util.Set;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @author cst
|
|
|
@@ -25,38 +23,66 @@ public class EventServiceImpl implements EventService {
|
|
|
private final ChooseDAO chooseDAO;
|
|
|
private final UserDAO userDAO;
|
|
|
private final CommentDAO commentDAO;
|
|
|
- private final QuizDAO quizDAO;
|
|
|
private final QuizStudentAnswerDAO quizStudentAnswerDAO;
|
|
|
|
|
|
- public EventServiceImpl(CourseDAO courseDAO, ChooseDAO chooseDAO, UserDAO userDAO, CommentDAO commentDAO, QuizDAO quizDAO, QuizStudentAnswerDAO quizStudentAnswerDAO) {
|
|
|
+ public EventServiceImpl(CourseDAO courseDAO, ChooseDAO chooseDAO, UserDAO userDAO, CommentDAO commentDAO, QuizStudentAnswerDAO quizStudentAnswerDAO) {
|
|
|
this.courseDAO = courseDAO;
|
|
|
this.chooseDAO = chooseDAO;
|
|
|
this.userDAO = userDAO;
|
|
|
this.commentDAO = commentDAO;
|
|
|
- this.quizDAO = quizDAO;
|
|
|
this.quizStudentAnswerDAO = quizStudentAnswerDAO;
|
|
|
}
|
|
|
|
|
|
@Transactional(readOnly = true)
|
|
|
@Override
|
|
|
public List<EventVO> getAllEvents() {
|
|
|
-// List<EventVO> eventVOList = Lists.newArrayList();
|
|
|
-// List<Course> courses = courseDAO.findAll();
|
|
|
-// courses.forEach(course -> {
|
|
|
-// Set<Long> studentIds = chooseDAO.findStudentIdsByCourseId(course.getId());
|
|
|
-// eventVOList.addAll(studentIds.parallelStream()
|
|
|
-// .map(studentId -> userDAO.findUserById(studentId))
|
|
|
-// .filter(user -> user.getPid() != null)
|
|
|
-// .map(user -> EventVO.of(user.getPid(), EventType.LESSON, ))
|
|
|
-// .collect(Collectors.toSet()))
|
|
|
-// studentIds.forEach(studentId -> {
|
|
|
-// User user = userDAO.findUserById(studentId);
|
|
|
-// if (user.getPid() != null) {
|
|
|
-// eventVOList.addAll();
|
|
|
-// }
|
|
|
-// });
|
|
|
-// });
|
|
|
-// List<Comment> comments = commentDAO.findAll();
|
|
|
- return Collections.emptyList();
|
|
|
+ List<EventVO> eventVOList = Lists.newArrayList();
|
|
|
+ List<Course> courses = courseDAO.findAll();
|
|
|
+ courses.forEach(course -> {
|
|
|
+ List<Choose> chooses = chooseDAO.findByCourseId(course.getId());
|
|
|
+ chooses.forEach(
|
|
|
+ choose -> {
|
|
|
+ User student = userDAO.findUserById(choose.getStudentId());
|
|
|
+ if (student.getPid() != null) {
|
|
|
+ eventVOList.add(new EventVO()
|
|
|
+ .setUserId(String.valueOf(student.getPid()))
|
|
|
+ .setTime(choose.getChooseAt())
|
|
|
+ .setType(EventType.LESSON)
|
|
|
+ .setAction(EventAction.PARTICIPATE)
|
|
|
+ .setDescription(course.getName())
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ );
|
|
|
+ });
|
|
|
+ List<Comment> comments = commentDAO.findAll();
|
|
|
+ comments.forEach(comment -> {
|
|
|
+ User user = comment.getUser();
|
|
|
+ if (user.getPid() != null && user.getRole() == UserRole.STUDENT) {
|
|
|
+ eventVOList.add(new EventVO()
|
|
|
+ .setUserId(String.valueOf(user.getPid()))
|
|
|
+ .setTime(comment.getCreateAt())
|
|
|
+ .setType(EventType.POST)
|
|
|
+ .setAction(EventAction.INITIATE)
|
|
|
+ .setDescription(comment.getTitle())
|
|
|
+ );
|
|
|
+ }
|
|
|
+ });
|
|
|
+ List<QuizStudentAnswer> quizStudentAnswers = quizStudentAnswerDAO.findAll();
|
|
|
+ quizStudentAnswers.forEach(quizStudentAnswer -> {
|
|
|
+ User student = quizStudentAnswer.getStudent();
|
|
|
+ if (student.getPid() != null) {
|
|
|
+ Quiz quiz = quizStudentAnswer.getQuiz();
|
|
|
+ Course course = quiz.getCourse();
|
|
|
+ eventVOList.add(new EventVO()
|
|
|
+ .setUserId(String.valueOf(student.getPid()))
|
|
|
+ .setTime(quizStudentAnswer.getSubmitAt())
|
|
|
+ .setType(EventType.QUIZ)
|
|
|
+ .setAction(EventAction.COMPLETE)
|
|
|
+ .setDescription(StrBuilder.create().append(course.getName()).append(";").append(quiz.getName()).toStringAndReset())
|
|
|
+ );
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return eventVOList;
|
|
|
}
|
|
|
}
|