Compare commits
35
Commits
dev
...
83f3c50a3b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
83f3c50a3b | ||
|
|
ba576a8497 | ||
|
|
3bfd8e436c | ||
|
|
44c5f51fd5 | ||
|
|
620c2bb0d9 | ||
|
|
7e306661f2 | ||
|
|
5b57639cb2 | ||
|
|
672f35c16a | ||
|
|
1b2cf91c5b | ||
|
|
d9e78f1a72 | ||
|
|
8e3e169984 | ||
|
|
5bcf6e26a4 | ||
|
|
7a7f7b47e1 | ||
|
|
dfadb0e32d | ||
|
|
0bf4741b6a | ||
|
|
840bd58b35 | ||
|
|
6b28c74df3 | ||
|
|
fb2d3ba763 | ||
|
|
1c33f0855b | ||
|
|
3a934d975b | ||
|
|
bd7ca6ff1c | ||
|
|
7a41a68e23 | ||
|
|
526cc25e0e | ||
|
|
20bc61b5fe | ||
|
|
ef9105266a | ||
|
|
3907fcbffb | ||
|
|
1ef00dcfff | ||
|
|
52d0518892 | ||
|
|
a15712c150 | ||
|
|
1a6b894ff3 | ||
|
|
cd2fc12911 | ||
|
|
493ecd3021 | ||
|
|
7340f02102 | ||
|
|
68fefae774 | ||
|
|
ffb3f20774 |
+3
@@ -18,6 +18,9 @@ public interface IGroupCourseRepository {
|
||||
Mono<PageResponse<GroupCourse>> findByPage(PageRequest pageRequest);
|
||||
Mono<PageResponse<GroupCourse>> findByPageAndNotDeleted(PageRequest pageRequest);
|
||||
|
||||
Mono<PageResponse<GroupCourse>> findByPageWithKeyword(PageRequest pageRequest);
|
||||
Mono<PageResponse<GroupCourse>> findByPageWithKeywordAndNotDeleted(PageRequest pageRequest);
|
||||
|
||||
Mono<GroupCourse> save(GroupCourse groupCourse);
|
||||
|
||||
Mono<GroupCourse> update(GroupCourse groupCourse);
|
||||
|
||||
+81
@@ -10,6 +10,7 @@ import cn.novalon.gym.manage.groupcourse.entity.GroupCourseEntity;
|
||||
import cn.novalon.gym.manage.groupcourse.repository.IGroupCourseRepository;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.r2dbc.core.R2dbcEntityTemplate;
|
||||
import org.springframework.data.relational.core.query.Criteria;
|
||||
import org.springframework.data.relational.core.query.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import reactor.core.publisher.Flux;
|
||||
@@ -178,4 +179,84 @@ public class GroupCourseRepository implements IGroupCourseRepository {
|
||||
return Mono.empty();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<PageResponse<GroupCourse>> findByPageWithKeyword(PageRequest pageRequest) {
|
||||
int page = pageRequest.getPage();
|
||||
int size = pageRequest.getSize();
|
||||
String sort = pageRequest.getSort();
|
||||
String order = pageRequest.getOrder();
|
||||
String keyword = pageRequest.getKeyword();
|
||||
|
||||
Sort sortObj = Sort.unsorted();
|
||||
if (sort != null && !sort.isEmpty()) {
|
||||
sortObj = Sort.by(Sort.Direction.fromString(order), sort);
|
||||
}
|
||||
|
||||
org.springframework.data.domain.PageRequest pageable = org.springframework.data.domain.PageRequest.of(page, size, sortObj);
|
||||
|
||||
Criteria criteria = Criteria.empty();
|
||||
if (keyword != null && !keyword.isEmpty()) {
|
||||
criteria = criteria.or(Criteria.where("course_name").like("%" + keyword + "%"))
|
||||
.or(Criteria.where("location").like("%" + keyword + "%"))
|
||||
.or(Criteria.where("description").like("%" + keyword + "%"));
|
||||
}
|
||||
|
||||
Query query = Query.query(criteria);
|
||||
|
||||
return r2dbcEntityTemplate.select(GroupCourseEntity.class)
|
||||
.matching(query.with(pageable))
|
||||
.all()
|
||||
.collectList()
|
||||
.zipWith(r2dbcEntityTemplate.count(query, GroupCourseEntity.class))
|
||||
.map(tuple -> {
|
||||
long total = tuple.getT2();
|
||||
int totalPages = (int) Math.ceil((double) total / size);
|
||||
List<GroupCourse> courseList = tuple.getT1().stream()
|
||||
.map(groupCourseConverter::toDomain)
|
||||
.toList();
|
||||
return new PageResponse<>(courseList, totalPages, total, page, size);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<PageResponse<GroupCourse>> findByPageWithKeywordAndNotDeleted(PageRequest pageRequest) {
|
||||
int page = pageRequest.getPage();
|
||||
int size = pageRequest.getSize();
|
||||
String sort = pageRequest.getSort();
|
||||
String order = pageRequest.getOrder();
|
||||
String keyword = pageRequest.getKeyword();
|
||||
|
||||
Sort sortObj = Sort.unsorted();
|
||||
if (sort != null && !sort.isEmpty()) {
|
||||
sortObj = Sort.by(Sort.Direction.fromString(order), sort);
|
||||
}
|
||||
|
||||
org.springframework.data.domain.PageRequest pageable = org.springframework.data.domain.PageRequest.of(page, size, sortObj);
|
||||
|
||||
Criteria criteria = Criteria.where("deleted_at").isNull();
|
||||
if (keyword != null && !keyword.isEmpty()) {
|
||||
criteria = criteria.and(
|
||||
Criteria.where("course_name").like("%" + keyword + "%")
|
||||
.or(Criteria.where("location").like("%" + keyword + "%"))
|
||||
.or(Criteria.where("description").like("%" + keyword + "%"))
|
||||
);
|
||||
}
|
||||
|
||||
Query query = Query.query(criteria);
|
||||
|
||||
return r2dbcEntityTemplate.select(GroupCourseEntity.class)
|
||||
.matching(query.with(pageable))
|
||||
.all()
|
||||
.collectList()
|
||||
.zipWith(r2dbcEntityTemplate.count(query, GroupCourseEntity.class))
|
||||
.map(tuple -> {
|
||||
long total = tuple.getT2();
|
||||
int totalPages = (int) Math.ceil((double) total / size);
|
||||
List<GroupCourse> courseList = tuple.getT1().stream()
|
||||
.map(groupCourseConverter::toDomain)
|
||||
.toList();
|
||||
return new PageResponse<>(courseList, totalPages, total, page, size);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
+9
-2
@@ -139,10 +139,17 @@ public class GroupCourseService implements IGroupCourseService {
|
||||
Mono.defer(() -> {
|
||||
logger.debug("缓存未命中,查询数据库 - findByPage: key={}", cacheKey);
|
||||
Mono<PageResponse<GroupCourse>> resultMono;
|
||||
|
||||
boolean hasKeyword = keyword != null && !keyword.isEmpty();
|
||||
|
||||
if (includeDeleted) {
|
||||
resultMono = groupCourseRepository.findByPage(pageRequest);
|
||||
resultMono = hasKeyword
|
||||
? groupCourseRepository.findByPageWithKeyword(pageRequest)
|
||||
: groupCourseRepository.findByPage(pageRequest);
|
||||
} else {
|
||||
resultMono = groupCourseRepository.findByPageAndNotDeleted(pageRequest);
|
||||
resultMono = hasKeyword
|
||||
? groupCourseRepository.findByPageWithKeywordAndNotDeleted(pageRequest)
|
||||
: groupCourseRepository.findByPageAndNotDeleted(pageRequest);
|
||||
}
|
||||
|
||||
return resultMono.flatMap(pageResponse -> {
|
||||
|
||||
Reference in New Issue
Block a user