|
@@ -7,6 +7,7 @@ import org.hswebframework.ezorm.rdb.mapping.ReactiveRepository;
|
|
|
import org.hswebframework.ezorm.rdb.mapping.ReactiveUpdate;
|
|
|
import org.hswebframework.ezorm.rdb.mapping.defaults.SaveResult;
|
|
|
import org.hswebframework.web.api.crud.entity.PagerResult;
|
|
|
+import org.hswebframework.web.api.crud.entity.QueryParamEntity;
|
|
|
import org.reactivestreams.Publisher;
|
|
|
import org.springframework.transaction.ReactiveTransactionManager;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -88,13 +89,13 @@ public interface ReactiveCrudService<E, K> {
|
|
|
}
|
|
|
|
|
|
@Transactional(readOnly = true)
|
|
|
- default Flux<E> query(Mono<? extends QueryParam> queryParamMono) {
|
|
|
+ default Flux<E> query(Mono<? extends QueryParamEntity> queryParamMono) {
|
|
|
return queryParamMono
|
|
|
.flatMapMany(this::query);
|
|
|
}
|
|
|
|
|
|
@Transactional(readOnly = true)
|
|
|
- default Flux<E> query(QueryParam param) {
|
|
|
+ default Flux<E> query(QueryParamEntity param) {
|
|
|
return getRepository()
|
|
|
.createQuery()
|
|
|
.setParam(param)
|
|
@@ -102,40 +103,50 @@ public interface ReactiveCrudService<E, K> {
|
|
|
}
|
|
|
|
|
|
@Transactional(readOnly = true)
|
|
|
- default Mono<PagerResult<E>> queryPager(QueryParam queryParamMono) {
|
|
|
+ default Mono<PagerResult<E>> queryPager(QueryParamEntity queryParamMono) {
|
|
|
return queryPager(queryParamMono, Function.identity());
|
|
|
}
|
|
|
|
|
|
@Transactional(readOnly = true)
|
|
|
- default <T> Mono<PagerResult<T>> queryPager(QueryParam param, Function<E, T> mapper) {
|
|
|
+ default <T> Mono<PagerResult<T>> queryPager(QueryParamEntity query, Function<E, T> mapper) {
|
|
|
+ if (query.getTotal() != null) {
|
|
|
+ return getRepository()
|
|
|
+ .createQuery()
|
|
|
+ .setParam(query.rePaging(query.getTotal()))
|
|
|
+ .fetch()
|
|
|
+ .map(mapper)
|
|
|
+ .collectList()
|
|
|
+ .map(list -> PagerResult.of(query.getTotal(), list, query));
|
|
|
+ }
|
|
|
return getRepository()
|
|
|
.createQuery()
|
|
|
- .setParam(param)
|
|
|
+ .setParam(query)
|
|
|
.count()
|
|
|
.flatMap(total -> {
|
|
|
if (total == 0) {
|
|
|
- return Mono.just(PagerResult.of(0, Collections.emptyList(), param));
|
|
|
+ return Mono.just(PagerResult.empty());
|
|
|
}
|
|
|
- return query(Mono.just(param.rePaging(total))).map(mapper)
|
|
|
+ return query(query.clone().rePaging(total))
|
|
|
+ .map(mapper)
|
|
|
.collectList()
|
|
|
- .map(list -> PagerResult.of(total, list, param));
|
|
|
+ .map(list -> PagerResult.of(total, list, query));
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@Transactional(readOnly = true)
|
|
|
- default <T> Mono<PagerResult<T>> queryPager(Mono<? extends QueryParam> queryParamMono, Function<E, T> mapper) {
|
|
|
+ default <T> Mono<PagerResult<T>> queryPager(Mono<? extends QueryParamEntity> queryParamMono, Function<E, T> mapper) {
|
|
|
return queryParamMono
|
|
|
- .cast(QueryParam.class)
|
|
|
+ .cast(QueryParamEntity.class)
|
|
|
.flatMap(param -> queryPager(param, mapper));
|
|
|
}
|
|
|
|
|
|
@Transactional(readOnly = true)
|
|
|
- default Mono<PagerResult<E>> queryPager(Mono<? extends QueryParam> queryParamMono) {
|
|
|
+ default Mono<PagerResult<E>> queryPager(Mono<? extends QueryParamEntity> queryParamMono) {
|
|
|
return queryPager(queryParamMono, Function.identity());
|
|
|
}
|
|
|
|
|
|
@Transactional(readOnly = true)
|
|
|
- default Mono<Integer> count(QueryParam queryParam) {
|
|
|
+ default Mono<Integer> count(QueryParamEntity queryParam) {
|
|
|
return getRepository()
|
|
|
.createQuery()
|
|
|
.setParam(queryParam)
|
|
@@ -143,7 +154,7 @@ public interface ReactiveCrudService<E, K> {
|
|
|
}
|
|
|
|
|
|
@Transactional(readOnly = true)
|
|
|
- default Mono<Integer> count(Mono<? extends QueryParam> queryParamMono) {
|
|
|
+ default Mono<Integer> count(Mono<? extends QueryParamEntity> queryParamMono) {
|
|
|
return queryParamMono.flatMap(this::count);
|
|
|
}
|
|
|
|