Browse Source

improvement: 修改部分检索条件,提高检索性能

ChenSiTong 6 years ago
parent
commit
b1bffe93c6

+ 1 - 1
src/main/java/nju/seec/helper/service/impl/CommentServiceImpl.java

@@ -53,7 +53,7 @@ public class CommentServiceImpl implements CommentService {
         // 增加通知
         Slide slide = slideDAO.findSlideById(comment.getSlideId());
         if (!user.getId().equals(slide.getTeacher().getId())) {
-            messageService.createMessage(Collections.singleton(slide.getTeacher().getId()), MessageType.COMMENT_NEW, String.format("课程 [%s] 的课件 [%s] 在第%d页有新评论", slide.getCourse().getName(), slide.getName(), comment.getPageNumber()), slide.getId());
+            messageService.createMessage(Collections.singleton(slide.getTeacher().getId()), MessageType.COMMENT_NEW, String.format("[%s] - [%s] 在第%d页有新评论", slide.getCourse().getName(), slide.getName(), comment.getPageNumber()), slide.getId());
         }
 
         return new CommentVO(comment);

+ 1 - 4
src/main/java/nju/seec/helper/service/impl/CourseFileServiceImpl.java

@@ -1,7 +1,6 @@
 package nju.seec.helper.service.impl;
 
 import lombok.SneakyThrows;
-import nju.seec.helper.dao.ChooseDAO;
 import nju.seec.helper.dao.CourseDAO;
 import nju.seec.helper.dao.CourseFileDAO;
 import nju.seec.helper.dto.course.CourseFileDTO;
@@ -36,17 +35,15 @@ public class CourseFileServiceImpl implements CourseFileService {
 
     private final CourseDAO courseDAO;
     private final CourseFileDAO courseFileDAO;
-    private final ChooseDAO chooseDAO;
 
     private final CourseService courseService;
 
     private final FileUtils fileUtils;
     private final RedisCacheUtils cacheUtils;
 
-    public CourseFileServiceImpl(CourseDAO courseDAO, CourseFileDAO courseFileDAO, ChooseDAO chooseDAO, CourseService courseService, FileUtils fileUtils, RedisCacheUtils cacheUtils) {
+    public CourseFileServiceImpl(CourseDAO courseDAO, CourseFileDAO courseFileDAO, CourseService courseService, FileUtils fileUtils, RedisCacheUtils cacheUtils) {
         this.courseDAO = courseDAO;
         this.courseFileDAO = courseFileDAO;
-        this.chooseDAO = chooseDAO;
         this.courseService = courseService;
         this.fileUtils = fileUtils;
         this.cacheUtils = cacheUtils;

+ 7 - 6
src/main/java/nju/seec/helper/service/impl/CourseServiceImpl.java

@@ -22,7 +22,6 @@ import org.springframework.data.jpa.domain.Specification;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
-import javax.persistence.criteria.JoinType;
 import java.util.Set;
 
 /**
@@ -194,8 +193,9 @@ public class CourseServiceImpl implements CourseService {
 
         return courseDAO.findAll(
                 (Specification<Course>) (root, query, cb) -> cb.and(
-                        cb.equal(root.get("deleteAt"), 0L),
-                        cb.or(cb.like(root.get("name"), keyPattern), cb.like(root.join("teacher", JoinType.LEFT).get("name"), keyPattern))),
+                        cb.equal(root.get("deleteAt"), 0L)
+//                        , cb.or(cb.like(root.get("name"), keyPattern), cb.like(root.join("teacher", JoinType.LEFT).get("name"), keyPattern))
+                ),
                 pageable);
     }
 
@@ -204,9 +204,10 @@ public class CourseServiceImpl implements CourseService {
 
         return courseDAO.findAll(
                 (Specification<Course>) (root, query, cb) -> cb.and(
-                        root.get("id").in(courseIds),
-                        cb.equal(root.get("deleteAt"), 0L),
-                        cb.or(cb.like(root.get("name"), keyPattern), cb.like(root.join("teacher", JoinType.LEFT).get("name"), keyPattern))),
+                        root.get("id").in(courseIds)
+                        , cb.equal(root.get("deleteAt"), 0L)
+//                        , cb.or(cb.like(root.get("name"), keyPattern), cb.like(root.join("teacher", JoinType.LEFT).get("name"), keyPattern))
+                ),
                 pageable);
     }
 }

+ 4 - 3
src/main/java/nju/seec/helper/service/impl/NoticeServiceImpl.java

@@ -51,7 +51,7 @@ public class NoticeServiceImpl implements NoticeService {
                 .setContent(noticeDTO.getContent());
 
         Set<Long> studentIds = chooseDAO.findStudentIdsByCourseId(noticeDTO.getCourseId());
-        messageService.createMessage(studentIds, MessageType.NOTICE_NEW, String.format("课程 [%s] 发布了标题为 [%s] 的公告", course.getName(), notice.getTitle()), null);
+        messageService.createMessage(studentIds, MessageType.NOTICE_NEW, String.format("[%s] 发布了新公告", course.getName()), null);
         return new NoticeVO(noticeDAO.save(notice));
     }
 
@@ -90,8 +90,9 @@ public class NoticeServiceImpl implements NoticeService {
 
         return noticeDAO.findAll(
                 (Specification<Notice>) (root, query, cb) -> cb.and(
-                        cb.equal(root.get("courseId"), courseId),
-                        cb.or(cb.like(root.get("title"), keyPattern), cb.like(root.get("content"), keyPattern))),
+                        cb.equal(root.get("courseId"), courseId)
+//                        , cb.or(cb.like(root.get("title"), keyPattern), cb.like(root.get("content"), keyPattern))
+                ),
                 pageable);
     }
 }

+ 13 - 12
src/main/java/nju/seec/helper/service/impl/QuizServiceImpl.java

@@ -10,7 +10,6 @@ import nju.seec.helper.entity.Slide;
 import nju.seec.helper.service.MessageService;
 import nju.seec.helper.service.QuizService;
 import nju.seec.helper.service.util.AuthUtils;
-import nju.seec.helper.service.util.StringUtils;
 import nju.seec.helper.util.enums.*;
 import nju.seec.helper.util.exception.HelperException;
 import nju.seec.helper.vo.quiz.QuizVO;
@@ -194,19 +193,21 @@ public class QuizServiceImpl implements QuizService {
     private Page<Quiz> findByCourseIdInAndStateAndKey(Set<Long> courseIds, QuizState state, String key, Pageable pageable) {
         return quizDAO.findAll(
                 (Specification<Quiz>) (root, query, cb) -> cb.and(
-                        root.get("course").get("id").in(courseIds),
-                        cb.equal(root.get("deleteAt"), 0L),
-                        cb.equal(root.get("state"), state),
-                        cb.like(root.get("name"), StringUtils.keyPattern(key))),
+                        root.get("course").get("id").in(courseIds)
+                        , cb.equal(root.get("deleteAt"), 0L)
+                        , cb.equal(root.get("state"), state)
+//                        , cb.like(root.get("name"), StringUtils.keyPattern(key))
+                ),
                 pageable);
     }
 
     private Page<Quiz> findBySlideIdAndKey(Long slideId, String key, Pageable pageable) {
         return quizDAO.findAll(
                 (Specification<Quiz>) (root, query, cb) -> cb.and(
-                        cb.equal(root.get("slide").get("id"), slideId),
-                        cb.equal(root.get("deleteAt"), 0L),
-                        cb.like(root.get("name"), StringUtils.keyPattern(key))),
+                        cb.equal(root.get("slide").get("id"), slideId)
+                        , cb.equal(root.get("deleteAt"), 0L)
+//                        , cb.like(root.get("name"), StringUtils.keyPattern(key))
+                ),
                 pageable);
     }
 
@@ -214,10 +215,10 @@ public class QuizServiceImpl implements QuizService {
     private Page<Quiz> findBySlideIdAndStateNotInAndKey(Long slideId, Set<QuizState> exclusiveStates, String key, Pageable pageable) {
         return quizDAO.findAll(
                 (Specification<Quiz>) (root, query, cb) -> cb.and(
-                        cb.equal(root.get("slide").get("id"), slideId),
-                        cb.equal(root.get("deleteAt"), 0L),
-                        cb.like(root.get("name"), StringUtils.keyPattern(key)),
-                        cb.not(root.get("state").in(exclusiveStates))),
+                        cb.equal(root.get("slide").get("id"), slideId)
+                        , cb.equal(root.get("deleteAt"), 0L)
+//                        , cb.like(root.get("name"), StringUtils.keyPattern(key))
+                        , cb.not(root.get("state").in(exclusiveStates))),
                 pageable);
     }
 }

+ 1 - 1
src/main/java/nju/seec/helper/service/impl/ReplyServiceImpl.java

@@ -63,7 +63,7 @@ public class ReplyServiceImpl implements ReplyService {
         // 增加通知
         if (!user.getId().equals(comment.getUser().getId())) {
             Slide slide = slideDAO.findSlideById(comment.getSlideId());
-            messageService.createMessage(Collections.singleton(comment.getUser().getId()), MessageType.COMMENT_REPLY, String.format("您在课件 [%s] 第%d页发表的讨论帖已收到回复", slide.getName(), comment.getPageNumber()), slide.getId());
+            messageService.createMessage(Collections.singleton(comment.getUser().getId()), MessageType.COMMENT_REPLY, String.format("您在 [%s] - [%s] 第%d页发表的讨论帖已收到回复", slide.getCourse().getName(), slide.getName(), comment.getPageNumber()), slide.getId());
         }
 
         return new ReplyVO(reply);

+ 13 - 11
src/main/java/nju/seec/helper/service/impl/SlideServiceImpl.java

@@ -148,7 +148,7 @@ public class SlideServiceImpl implements SlideService {
         // 增加通知
         if (slide.getState() == SlideState.IN_CLASS) {
             Set<Long> studentIds = chooseDAO.findStudentIdsByCourseId(slide.getCourse().getId());
-            messageService.createMessage(studentIds, MessageType.SLIDE_IN_CLASS, String.format("课程 [%s] 的课件 [%s] 已开课", slide.getCourse().getName(), slide.getName()), slide.getId());
+            messageService.createMessage(studentIds, MessageType.SLIDE_IN_CLASS, String.format(" [%s] - [%s] 已开课", slide.getCourse().getName(), slide.getName()), slide.getId());
         }
 
         // 修改Slide状态同时推进quiz状态
@@ -272,28 +272,30 @@ public class SlideServiceImpl implements SlideService {
     private Page<Slide> findByTeacherIdAndKey(Long teacherId, String key, Pageable pageable) {
         return slideDAO.findAll(
                 (Specification<Slide>) (root, query, cb) -> cb.and(
-                        cb.equal(root.get("teacher").get("id"), teacherId),
-                        cb.equal(root.get("deleteAt"), 0L),
-                        cb.like(root.get("name"), StringUtils.keyPattern(key))),
+                        cb.equal(root.get("teacher").get("id"), teacherId)
+                        , cb.equal(root.get("deleteAt"), 0L)
+//                        , cb.like(root.get("name"), StringUtils.keyPattern(key))
+                ),
                 pageable);
     }
 
     private Page<Slide> findByCourseIdAndKey(Long courseId, String key, Pageable pageable) {
         return slideDAO.findAll(
                 (Specification<Slide>) (root, query, cb) -> cb.and(
-                        cb.equal(root.get("course").get("id"), courseId),
-                        cb.equal(root.get("deleteAt"), 0L),
-                        cb.like(root.get("name"), StringUtils.keyPattern(key))),
+                        cb.equal(root.get("course").get("id"), courseId)
+                        , cb.equal(root.get("deleteAt"), 0L)
+//                        , cb.like(root.get("name"), StringUtils.keyPattern(key))
+                ),
                 pageable);
     }
 
     private Page<Slide> findByCourseIdAndKeyAndStateNotIn(Long courseId, Set<SlideState> exclusiveStates, String key, Pageable pageable) {
         return slideDAO.findAll(
                 (Specification<Slide>) (root, query, cb) -> cb.and(
-                        cb.equal(root.get("course").get("id"), courseId),
-                        cb.equal(root.get("deleteAt"), 0L),
-                        cb.like(root.get("name"), StringUtils.keyPattern(key)),
-                        cb.not(root.get("state").in(exclusiveStates))
+                        cb.equal(root.get("course").get("id"), courseId)
+                        , cb.equal(root.get("deleteAt"), 0L)
+//                        , cb.like(root.get("name"), StringUtils.keyPattern(key))
+                        , cb.not(root.get("state").in(exclusiveStates))
                 ),
                 pageable);
     }