|
@@ -1,12 +1,7 @@
|
|
|
package com.hosea.service.infra.tenant;
|
|
|
|
|
|
-import com.alibaba.cola.dto.PageQuery;
|
|
|
import com.alibaba.cola.dto.PageResponse;
|
|
|
-import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
-import com.baomidou.mybatisplus.core.metadata.OrderItem;
|
|
|
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
-import com.hosea.common.utils.CollUtil;
|
|
|
-import com.hosea.common.utils.StrUtil;
|
|
|
+import com.hosea.cloud.mybatis.plus.PageConversion;
|
|
|
import com.hosea.service.app.tenant.executor.TenantComplexQuery;
|
|
|
import com.hosea.service.domain.tenant.Tenant;
|
|
|
import com.hosea.service.domain.tenant.TenantRepository;
|
|
@@ -16,10 +11,7 @@ import com.hosea.service.user.client.dto.request.TenantListPageQuery;
|
|
|
import jakarta.annotation.Resource;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
-import java.util.Collection;
|
|
|
import java.util.Optional;
|
|
|
-import java.util.function.BiFunction;
|
|
|
-import java.util.function.Function;
|
|
|
|
|
|
/**
|
|
|
* 租户-资源接口实现
|
|
@@ -57,56 +49,9 @@ public class TenantRepositoryImpl implements TenantRepository, TenantComplexQuer
|
|
|
|
|
|
@Override
|
|
|
public PageResponse<TenantDTO> list(TenantListPageQuery query) {
|
|
|
- return page(query,
|
|
|
+ return PageConversion.page(query,
|
|
|
(pageQuery, page) -> tenantMapper.list(page, pageQuery.getName(), pageQuery.getCode()),
|
|
|
TenantConversion.INSTANCE::toDto
|
|
|
);
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * 执行分页查询
|
|
|
- *
|
|
|
- * @param query 查询条件
|
|
|
- * @param mapper 执行的SQL
|
|
|
- * @param conversion 结果转换
|
|
|
- */
|
|
|
- public static <T, R, P extends PageQuery> PageResponse<R> page(P query, BiFunction<P, IPage<T>, IPage<T>> mapper, Function<? super T, R> conversion) {
|
|
|
- return pageToPageResponse(mapper.apply(query, pageQueryToPage(query, new Page<>())), conversion);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 把COLA的分页转MyBatis的分页
|
|
|
- */
|
|
|
- public static <T> IPage<T> pageQueryToPage(PageQuery query, Page<T> page) {
|
|
|
- page.setSize(query.getPageSize());
|
|
|
- page.setCurrent(query.getPageIndex());
|
|
|
- Optional.ofNullable(query.getOrderBy())
|
|
|
- .filter(StrUtil::isNotBlank)
|
|
|
- .ifPresent(orderBy -> {
|
|
|
- if (StrUtil.equalsIgnoreCase(query.getOrderDirection(), PageQuery.DESC)) {
|
|
|
- page.addOrder(OrderItem.desc(orderBy));
|
|
|
- } else {
|
|
|
- page.addOrder(OrderItem.asc(orderBy));
|
|
|
- }
|
|
|
- });
|
|
|
- return page;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * MyBatis的分页结果转COLA的结果
|
|
|
- */
|
|
|
- public static <T, R> PageResponse<R> pageToPageResponse(IPage<T> page, Function<? super T, R> conversion) {
|
|
|
- PageResponse<R> resp = new PageResponse<>();
|
|
|
- resp.setSuccess(true);
|
|
|
- resp.setPageIndex((int) page.getCurrent());
|
|
|
- resp.setPageSize((int) page.getSize());
|
|
|
- resp.setTotalCount((int) page.getTotal());
|
|
|
- resp.setData(Optional.ofNullable(page.getRecords())
|
|
|
- .filter(CollUtil::isNotEmpty)
|
|
|
- .stream()
|
|
|
- .flatMap(Collection::stream)
|
|
|
- .map(conversion)
|
|
|
- .toList());
|
|
|
- return resp;
|
|
|
- }
|
|
|
}
|