瀏覽代碼

refactor: 加入关键字检索

ChenSiTong 6 年之前
父節點
當前提交
c7e7873682

+ 11 - 9
src/main/java/nju/seec/helper/service/impl/CourseServiceImpl.java

@@ -22,6 +22,7 @@ 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;
 
 /**
@@ -169,10 +170,10 @@ public class CourseServiceImpl implements CourseService {
 
     private void checkSameCourseName(Long courseId, Long teacherId, String name) {
         long exists = courseDAO.count((Specification<Course>) (root, query, cb) ->
-                cb.and(cb.notEqual(root.get("id"), courseId),
-                        cb.equal(root.get("teacher").get("id"), teacherId),
-                        cb.equal(root.get("deleteAt"), 0L),
-                        cb.equal(root.get("name"), name)
+                cb.and(cb.notEqual(root.get("id"), courseId)
+                        , cb.equal(root.get("teacher").get("id"), teacherId)
+                        , cb.equal(root.get("deleteAt"), 0L)
+                        , cb.equal(root.get("name"), name)
                 ));
         if (exists > 0) {
             throw HelperException.of(ExceptionType.CONFLICT, "该课程名已使用");
@@ -182,9 +183,10 @@ public class CourseServiceImpl implements CourseService {
     private Page<Course> findByTeacherIdAndKey(Long teacherId, String key, Pageable pageable) {
         return courseDAO.findAll(
                 (Specification<Course>) (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);
     }
 
@@ -194,7 +196,7 @@ 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.or(cb.like(root.get("name"), keyPattern), cb.like(root.join("teacher", JoinType.LEFT).get("name"), keyPattern))
                 ),
                 pageable);
     }
@@ -206,7 +208,7 @@ public class CourseServiceImpl implements CourseService {
                 (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))
+                        , cb.or(cb.like(root.get("name"), keyPattern), cb.like(root.join("teacher", JoinType.LEFT).get("name"), keyPattern))
                 ),
                 pageable);
     }

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

@@ -91,7 +91,7 @@ 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.or(cb.like(root.get("title"), keyPattern), cb.like(root.get("content"), keyPattern))
                 ),
                 pageable);
     }

+ 3 - 2
src/main/java/nju/seec/helper/service/impl/QuizServiceImpl.java

@@ -10,6 +10,7 @@ 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;
@@ -196,7 +197,7 @@ public class QuizServiceImpl implements QuizService {
                         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))
+                        , cb.like(root.get("name"), StringUtils.keyPattern(key))
                 ),
                 pageable);
     }
@@ -206,7 +207,7 @@ public class QuizServiceImpl implements QuizService {
                 (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.like(root.get("name"), StringUtils.keyPattern(key))
                 ),
                 pageable);
     }

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

@@ -274,7 +274,7 @@ public class SlideServiceImpl implements SlideService {
                 (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.like(root.get("name"), StringUtils.keyPattern(key))
                 ),
                 pageable);
     }
@@ -284,7 +284,7 @@ public class SlideServiceImpl implements SlideService {
                 (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.like(root.get("name"), StringUtils.keyPattern(key))
                 ),
                 pageable);
     }
@@ -294,7 +294,7 @@ public class SlideServiceImpl implements SlideService {
                 (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.like(root.get("name"), StringUtils.keyPattern(key))
                         , cb.not(root.get("state").in(exclusiveStates))
                 ),
                 pageable);