|
|
@@ -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);
|
|
|
}
|