|
@@ -32,38 +32,29 @@ public class EventAspect {
|
|
|
public EventAspect(CourseDAO courseDAO, QuizDAO quizDAO, EventApi eventApi) {
|
|
public EventAspect(CourseDAO courseDAO, QuizDAO quizDAO, EventApi eventApi) {
|
|
|
this.eventHandleMap = ImmutableMap.of(
|
|
this.eventHandleMap = ImmutableMap.of(
|
|
|
EventType.LESSON, ImmutableMap.of(
|
|
EventType.LESSON, ImmutableMap.of(
|
|
|
- EventAction.PARTICIPATE, ((joinPoint, user) -> {
|
|
|
|
|
- Stream.of(joinPoint.getArgs())
|
|
|
|
|
- .filter(o -> o instanceof Long)
|
|
|
|
|
- .map(o -> (Long) o)
|
|
|
|
|
- .findFirst()
|
|
|
|
|
- .ifPresent(courseId ->
|
|
|
|
|
- eventApi.reportEvent(eventApi.createParticipateClassEventDTO(String.valueOf(user.getPid()), LocalDateTime.now(), courseDAO.findCourseById(courseId)))
|
|
|
|
|
- )
|
|
|
|
|
- ;
|
|
|
|
|
- }))
|
|
|
|
|
|
|
+ EventAction.PARTICIPATE, ((joinPoint, user) -> Stream.of(joinPoint.getArgs())
|
|
|
|
|
+ .filter(o -> o instanceof Long)
|
|
|
|
|
+ .map(o -> (Long) o)
|
|
|
|
|
+ .findFirst()
|
|
|
|
|
+ .ifPresent(courseId ->
|
|
|
|
|
+ eventApi.reportEvent(eventApi.createParticipateClassEventDTO(String.valueOf(user.getPid()), LocalDateTime.now(), courseDAO.findCourseById(courseId)))
|
|
|
|
|
+ )))
|
|
|
, EventType.POST, ImmutableMap.of(
|
|
, EventType.POST, ImmutableMap.of(
|
|
|
- EventAction.INITIATE, ((joinPoint, user) -> {
|
|
|
|
|
- Stream.of(joinPoint.getArgs())
|
|
|
|
|
- .filter(o -> o instanceof CommentDTO)
|
|
|
|
|
- .map(o -> (CommentDTO) o)
|
|
|
|
|
- .findFirst()
|
|
|
|
|
- .ifPresent(commentDTO ->
|
|
|
|
|
- eventApi.reportEvent(eventApi.createInitPostEventDTO(String.valueOf(user.getPid()), LocalDateTime.now(), Objects.requireNonNull(commentDTO).getTitle()))
|
|
|
|
|
- )
|
|
|
|
|
- ;
|
|
|
|
|
- }))
|
|
|
|
|
|
|
+ EventAction.INITIATE, ((joinPoint, user) -> Stream.of(joinPoint.getArgs())
|
|
|
|
|
+ .filter(o -> o instanceof CommentDTO)
|
|
|
|
|
+ .map(o -> (CommentDTO) o)
|
|
|
|
|
+ .findFirst()
|
|
|
|
|
+ .ifPresent(commentDTO ->
|
|
|
|
|
+ eventApi.reportEvent(eventApi.createInitPostEventDTO(String.valueOf(user.getPid()), LocalDateTime.now(), Objects.requireNonNull(commentDTO).getTitle()))
|
|
|
|
|
+ )))
|
|
|
, EventType.QUIZ, ImmutableMap.of(
|
|
, EventType.QUIZ, ImmutableMap.of(
|
|
|
- EventAction.COMPLETE, ((joinPoint, user) -> {
|
|
|
|
|
- Stream.of(joinPoint.getArgs())
|
|
|
|
|
- .filter(o -> o instanceof Long)
|
|
|
|
|
- .map(o -> (Long) o)
|
|
|
|
|
- .findFirst()
|
|
|
|
|
- .ifPresent(quizId ->
|
|
|
|
|
- eventApi.reportEvent(eventApi.createCompleteQuizEventDTO(String.valueOf(user.getPid()), LocalDateTime.now(), quizDAO.findQuizById(quizId)))
|
|
|
|
|
- )
|
|
|
|
|
- ;
|
|
|
|
|
- }))
|
|
|
|
|
|
|
+ EventAction.COMPLETE, ((joinPoint, user) -> Stream.of(joinPoint.getArgs())
|
|
|
|
|
+ .filter(o -> o instanceof Long)
|
|
|
|
|
+ .map(o -> (Long) o)
|
|
|
|
|
+ .findFirst()
|
|
|
|
|
+ .ifPresent(quizId ->
|
|
|
|
|
+ eventApi.reportEvent(eventApi.createCompleteQuizEventDTO(String.valueOf(user.getPid()), LocalDateTime.now(), quizDAO.findQuizById(quizId)))
|
|
|
|
|
+ )))
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -75,13 +66,13 @@ public class EventAspect {
|
|
|
* @param joinPoint 插入点
|
|
* @param joinPoint 插入点
|
|
|
* @param user 登录用户
|
|
* @param user 登录用户
|
|
|
*/
|
|
*/
|
|
|
- @Transactional(readOnly = true)
|
|
|
|
|
void handleEvent(JoinPoint joinPoint, LoginUser user);
|
|
void handleEvent(JoinPoint joinPoint, LoginUser user);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private final EventHandler doNothing = (joinPoint, user) -> {
|
|
private final EventHandler doNothing = (joinPoint, user) -> {
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+ @Transactional(readOnly = true)
|
|
|
@SneakyThrows
|
|
@SneakyThrows
|
|
|
@AfterReturning("@annotation(event) && args(user,..)")
|
|
@AfterReturning("@annotation(event) && args(user,..)")
|
|
|
public void reportEvent(JoinPoint joinPoint, Event event, LoginUser user) {
|
|
public void reportEvent(JoinPoint joinPoint, Event event, LoginUser user) {
|