From a0fb4013d85fc51e83754b2f0a21fe0920d71a8d Mon Sep 17 00:00:00 2001 From: cokie Date: Wed, 31 Jan 2024 20:15:02 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20feat:=20=E4=BC=98=E5=8C=96=E5=AD=97?= =?UTF-8?q?=E5=85=B8=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/http/dict/SystemDictController.java | 7 +++++-- .../repository/ISystemDictRepository.kt | 10 +++++++--- .../dict/domain/service/SystemDictService.kt | 2 +- .../service/impl/SystemDictServiceImpl.kt | 14 +++++++++----- .../server/dict/infra/dao/ISystemDictDAO.kt | 5 +++++ .../dict/infra/dao/impl/SystemDictDAO.kt | 9 +++++++++ .../infra/repository/SystemDictRepository.kt | 19 +++++++++++++++---- 7 files changed, 51 insertions(+), 15 deletions(-) diff --git a/tokisaki-api/src/main/java/io/micro/api/http/dict/SystemDictController.java b/tokisaki-api/src/main/java/io/micro/api/http/dict/SystemDictController.java index 89a08ac..c744168 100644 --- a/tokisaki-api/src/main/java/io/micro/api/http/dict/SystemDictController.java +++ b/tokisaki-api/src/main/java/io/micro/api/http/dict/SystemDictController.java @@ -29,8 +29,11 @@ public class SystemDictController { @Operation(summary = "查询系统数据字典") @GET - public Uni>> getSystemDictPage(@QueryParam("page") @DefaultValue("1") int page, @QueryParam("size") @DefaultValue("10") int size) { - return systemDictService.findDictPage(Pageable.of(page, size)) + public Uni>> getSystemDictPage( + @QueryParam("keyword") String keyword, + @QueryParam("page") @DefaultValue("1") int page, + @QueryParam("size") @DefaultValue("10") int size) { + return systemDictService.findDictPage(keyword, Pageable.of(page, size)) .map(paged -> { List list = paged.getFirst().stream() .map(it -> systemDictConverter.systemDictDO2QuerySystemDictDTO(it)) diff --git a/tokisaki-server/src/main/kotlin/io/micro/server/dict/domain/repository/ISystemDictRepository.kt b/tokisaki-server/src/main/kotlin/io/micro/server/dict/domain/repository/ISystemDictRepository.kt index 5277a0a..06d7ea8 100644 --- a/tokisaki-server/src/main/kotlin/io/micro/server/dict/domain/repository/ISystemDictRepository.kt +++ b/tokisaki-server/src/main/kotlin/io/micro/server/dict/domain/repository/ISystemDictRepository.kt @@ -1,14 +1,18 @@ package io.micro.server.dict.domain.repository +import io.micro.core.rest.Pageable import io.micro.server.dict.domain.model.entity.SystemDictDO -import io.quarkus.panache.common.Page import io.smallrye.mutiny.Uni interface ISystemDictRepository { - fun findSystemDictPage(page: Page): Uni> + fun findSystemDictByKeyLike(keyword: String, pageable: Pageable): Uni> - fun countSystemDictPage(): Uni + fun findSystemDict(pageable: Pageable): Uni> + + fun countSystemDict(): Uni + + fun countSystemDictByKeyLike(keyword: String): Uni fun findById(id: Long): Uni diff --git a/tokisaki-server/src/main/kotlin/io/micro/server/dict/domain/service/SystemDictService.kt b/tokisaki-server/src/main/kotlin/io/micro/server/dict/domain/service/SystemDictService.kt index d60d084..3b3e1f7 100644 --- a/tokisaki-server/src/main/kotlin/io/micro/server/dict/domain/service/SystemDictService.kt +++ b/tokisaki-server/src/main/kotlin/io/micro/server/dict/domain/service/SystemDictService.kt @@ -6,7 +6,7 @@ import io.smallrye.mutiny.Uni interface SystemDictService { - fun findDictPage(pageable: Pageable): Uni, Long>> + fun findDictPage(keyword: String?, pageable: Pageable): Uni, Long>> fun saveOrUpdateDict(systemDictDO: SystemDictDO): Uni diff --git a/tokisaki-server/src/main/kotlin/io/micro/server/dict/domain/service/impl/SystemDictServiceImpl.kt b/tokisaki-server/src/main/kotlin/io/micro/server/dict/domain/service/impl/SystemDictServiceImpl.kt index fce0334..da693ca 100644 --- a/tokisaki-server/src/main/kotlin/io/micro/server/dict/domain/service/impl/SystemDictServiceImpl.kt +++ b/tokisaki-server/src/main/kotlin/io/micro/server/dict/domain/service/impl/SystemDictServiceImpl.kt @@ -6,7 +6,6 @@ import io.micro.server.dict.domain.repository.ISystemDictRepository import io.micro.server.dict.domain.service.SystemDictService import io.quarkus.hibernate.reactive.panache.common.WithSession import io.quarkus.hibernate.reactive.panache.common.WithTransaction -import io.quarkus.panache.common.Page import io.smallrye.mutiny.Uni import jakarta.enterprise.context.ApplicationScoped @@ -14,10 +13,15 @@ import jakarta.enterprise.context.ApplicationScoped class SystemDictServiceImpl(private val systemDictRepository: ISystemDictRepository) : SystemDictService { @WithSession - override fun findDictPage(pageable: Pageable): Uni, Long>> { - val page = Page.of(pageable.current - 1, pageable.limit) - return systemDictRepository.findSystemDictPage(page).flatMap { list -> - systemDictRepository.countSystemDictPage().map { list to it } + override fun findDictPage(keyword: String?, pageable: Pageable): Uni, Long>> { + return if (!keyword.isNullOrBlank()) { + systemDictRepository.findSystemDictByKeyLike(keyword, pageable).flatMap { list -> + systemDictRepository.countSystemDictByKeyLike(keyword).map { list to it } + } + } else { + systemDictRepository.findSystemDict(pageable).flatMap { list -> + systemDictRepository.countSystemDict().map { list to it } + } } } diff --git a/tokisaki-server/src/main/kotlin/io/micro/server/dict/infra/dao/ISystemDictDAO.kt b/tokisaki-server/src/main/kotlin/io/micro/server/dict/infra/dao/ISystemDictDAO.kt index 24411b4..ec52264 100644 --- a/tokisaki-server/src/main/kotlin/io/micro/server/dict/infra/dao/ISystemDictDAO.kt +++ b/tokisaki-server/src/main/kotlin/io/micro/server/dict/infra/dao/ISystemDictDAO.kt @@ -2,10 +2,15 @@ package io.micro.server.dict.infra.dao import io.micro.server.dict.infra.po.SystemDictEntity import io.quarkus.hibernate.reactive.panache.kotlin.PanacheRepository +import io.quarkus.panache.common.Page import io.smallrye.mutiny.Uni interface ISystemDictDAO : PanacheRepository { fun selectByKey(key: String): Uni + fun selectByKeyLike(key: String, page: Page): Uni> + + fun countByKeyLike(key: String): Uni + } \ No newline at end of file diff --git a/tokisaki-server/src/main/kotlin/io/micro/server/dict/infra/dao/impl/SystemDictDAO.kt b/tokisaki-server/src/main/kotlin/io/micro/server/dict/infra/dao/impl/SystemDictDAO.kt index a738c7f..39e69af 100644 --- a/tokisaki-server/src/main/kotlin/io/micro/server/dict/infra/dao/impl/SystemDictDAO.kt +++ b/tokisaki-server/src/main/kotlin/io/micro/server/dict/infra/dao/impl/SystemDictDAO.kt @@ -2,6 +2,7 @@ package io.micro.server.dict.infra.dao.impl import io.micro.server.dict.infra.dao.ISystemDictDAO import io.micro.server.dict.infra.po.SystemDictEntity +import io.quarkus.panache.common.Page import io.smallrye.mutiny.Uni import jakarta.enterprise.context.ApplicationScoped @@ -12,4 +13,12 @@ class SystemDictDAO : ISystemDictDAO { return find("key = ?1", key).singleResult() } + override fun selectByKeyLike(key: String, page: Page): Uni> { + return find("key like concat('%', ?1, '%')", key).page(page).list() + } + + override fun countByKeyLike(key: String): Uni { + return find("key like concat('%', ?1, '%')", key).count() + } + } \ No newline at end of file diff --git a/tokisaki-server/src/main/kotlin/io/micro/server/dict/infra/repository/SystemDictRepository.kt b/tokisaki-server/src/main/kotlin/io/micro/server/dict/infra/repository/SystemDictRepository.kt index 5fed142..71c44dd 100644 --- a/tokisaki-server/src/main/kotlin/io/micro/server/dict/infra/repository/SystemDictRepository.kt +++ b/tokisaki-server/src/main/kotlin/io/micro/server/dict/infra/repository/SystemDictRepository.kt @@ -1,5 +1,6 @@ package io.micro.server.dict.infra.repository +import io.micro.core.rest.Pageable import io.micro.core.util.converter import io.micro.server.dict.domain.model.entity.SystemDictDO import io.micro.server.dict.domain.repository.ISystemDictRepository @@ -15,17 +16,27 @@ class SystemDictRepository( private val systemDictConverter: SystemDictConverter ) : ISystemDictRepository { - override fun findSystemDictPage(page: Page): Uni> { + override fun findSystemDictByKeyLike(keyword: String, pageable: Pageable): Uni> { + val page = Page.of(pageable.current - 1, pageable.limit) + return systemDictDAO.selectByKeyLike(keyword, page) + .map { it.converter(systemDictConverter::systemDictEntity2SystemDictDO) } + } + + override fun findSystemDict(pageable: Pageable): Uni> { + val page = Page.of(pageable.current - 1, pageable.limit) return systemDictDAO.findAll() - .page(page) - .list() + .page(page).list() .map { it.converter(systemDictConverter::systemDictEntity2SystemDictDO) } } - override fun countSystemDictPage(): Uni { + override fun countSystemDict(): Uni { return systemDictDAO.findAll().count() } + override fun countSystemDictByKeyLike(keyword: String): Uni { + return systemDictDAO.countByKeyLike(keyword) + } + override fun findById(id: Long): Uni { return systemDictDAO.findById(id).map(systemDictConverter::systemDictEntity2SystemDictDO) }