From 8ad92a18b655c5ef05a8410f72cfffa74b099a65 Mon Sep 17 00:00:00 2001 From: cokie Date: Wed, 24 Jan 2024 15:42:14 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20feat:=20=E7=BC=93=E5=AD=98=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/auth/domain/repository/IAuthRepository.kt | 2 ++ .../micro/server/auth/domain/service/AuthService.kt | 2 ++ .../auth/domain/service/impl/AuthServiceImpl.kt | 12 ++++++++++++ .../server/auth/infra/repository/AuthRepository.kt | 6 ++++++ .../robot/domain/model/entity/FeatureFunctionDO.kt | 4 ++++ .../server/robot/domain/model/entity/RobotDO.kt | 2 +- .../domain/service/impl/RobotManagerServiceImpl.kt | 2 +- 7 files changed, 28 insertions(+), 2 deletions(-) diff --git a/tokisaki-server/src/main/kotlin/io/micro/server/auth/domain/repository/IAuthRepository.kt b/tokisaki-server/src/main/kotlin/io/micro/server/auth/domain/repository/IAuthRepository.kt index c42a461..d125867 100644 --- a/tokisaki-server/src/main/kotlin/io/micro/server/auth/domain/repository/IAuthRepository.kt +++ b/tokisaki-server/src/main/kotlin/io/micro/server/auth/domain/repository/IAuthRepository.kt @@ -38,6 +38,8 @@ interface IAuthRepository { fun findAuthorityByExample(authorityDO: AuthorityDO): Uni> + fun findAuthorityCacheByExample(authorityDO: AuthorityDO): Uni> + fun saveAuthority(authorityDO: AuthorityDO): Uni } \ No newline at end of file diff --git a/tokisaki-server/src/main/kotlin/io/micro/server/auth/domain/service/AuthService.kt b/tokisaki-server/src/main/kotlin/io/micro/server/auth/domain/service/AuthService.kt index 9849b96..a065120 100644 --- a/tokisaki-server/src/main/kotlin/io/micro/server/auth/domain/service/AuthService.kt +++ b/tokisaki-server/src/main/kotlin/io/micro/server/auth/domain/service/AuthService.kt @@ -23,6 +23,8 @@ interface AuthService { fun getAuthorityByCode(code: String): Uni + fun getAuthorityCacheByCode(code: String): Uni + fun addAuthority(authorityDO: AuthorityDO): Uni } \ No newline at end of file diff --git a/tokisaki-server/src/main/kotlin/io/micro/server/auth/domain/service/impl/AuthServiceImpl.kt b/tokisaki-server/src/main/kotlin/io/micro/server/auth/domain/service/impl/AuthServiceImpl.kt index 96607e5..8a979c8 100644 --- a/tokisaki-server/src/main/kotlin/io/micro/server/auth/domain/service/impl/AuthServiceImpl.kt +++ b/tokisaki-server/src/main/kotlin/io/micro/server/auth/domain/service/impl/AuthServiceImpl.kt @@ -70,6 +70,18 @@ class AuthServiceImpl(private val authRepository: IAuthRepository) : AuthService } } + @WithSession + override fun getAuthorityCacheByCode(code: String): Uni { + return authRepository.findAuthorityCacheByExample(AuthorityDO().also { it.value = code }) + .map { + if (it.isNotEmpty()) { + it.first() + } else { + null + } + } + } + @WithTransaction override fun addAuthority(authorityDO: AuthorityDO): Uni { return authRepository.findAuthorityByExample(AuthorityDO().also { it.value = authorityDO.value }) diff --git a/tokisaki-server/src/main/kotlin/io/micro/server/auth/infra/repository/AuthRepository.kt b/tokisaki-server/src/main/kotlin/io/micro/server/auth/infra/repository/AuthRepository.kt index b64d91e..7ccb1b9 100644 --- a/tokisaki-server/src/main/kotlin/io/micro/server/auth/infra/repository/AuthRepository.kt +++ b/tokisaki-server/src/main/kotlin/io/micro/server/auth/infra/repository/AuthRepository.kt @@ -9,6 +9,7 @@ import io.micro.server.auth.domain.repository.IAuthRepository import io.micro.server.auth.infra.converter.AuthConverter import io.micro.server.auth.infra.dao.impl.AuthorityDAO import io.micro.server.auth.infra.dao.impl.UserDAO +import io.quarkus.cache.CacheResult import io.quarkus.panache.common.Page import io.smallrye.mutiny.Uni import jakarta.enterprise.context.ApplicationScoped @@ -94,6 +95,11 @@ class AuthRepository( .map { it.converter(authConverter::authorityEntity2authorityDO) } } + @CacheResult(cacheName = "authority") + override fun findAuthorityCacheByExample(authorityDO: AuthorityDO): Uni> { + return findAuthorityByExample(authorityDO) + } + override fun saveAuthority(authorityDO: AuthorityDO): Uni { val entity = authConverter.authorityDO2authorityEntity(authorityDO).also { it.id = null } return authorityDAO.persist(entity).map(authConverter::authorityEntity2authorityDO) diff --git a/tokisaki-server/src/main/kotlin/io/micro/server/robot/domain/model/entity/FeatureFunctionDO.kt b/tokisaki-server/src/main/kotlin/io/micro/server/robot/domain/model/entity/FeatureFunctionDO.kt index 05c6ade..9c996ca 100644 --- a/tokisaki-server/src/main/kotlin/io/micro/server/robot/domain/model/entity/FeatureFunctionDO.kt +++ b/tokisaki-server/src/main/kotlin/io/micro/server/robot/domain/model/entity/FeatureFunctionDO.kt @@ -37,6 +37,10 @@ class FeatureFunctionDO { var memberId: Long? = null + var isMenu: Boolean = false + + var isUndefined: Boolean = false + companion object { const val BRACES = "{}" } diff --git a/tokisaki-server/src/main/kotlin/io/micro/server/robot/domain/model/entity/RobotDO.kt b/tokisaki-server/src/main/kotlin/io/micro/server/robot/domain/model/entity/RobotDO.kt index c86ca5f..25bfa48 100644 --- a/tokisaki-server/src/main/kotlin/io/micro/server/robot/domain/model/entity/RobotDO.kt +++ b/tokisaki-server/src/main/kotlin/io/micro/server/robot/domain/model/entity/RobotDO.kt @@ -66,7 +66,7 @@ class RobotDO : BaseDomainEntity() { it.args += args } } else { - null + FeatureFunctionDO().also { it.isUndefined = true } } } else { null diff --git a/tokisaki-server/src/main/kotlin/io/micro/server/robot/domain/service/impl/RobotManagerServiceImpl.kt b/tokisaki-server/src/main/kotlin/io/micro/server/robot/domain/service/impl/RobotManagerServiceImpl.kt index c3efed3..7c21c8b 100644 --- a/tokisaki-server/src/main/kotlin/io/micro/server/robot/domain/service/impl/RobotManagerServiceImpl.kt +++ b/tokisaki-server/src/main/kotlin/io/micro/server/robot/domain/service/impl/RobotManagerServiceImpl.kt @@ -280,7 +280,7 @@ class RobotManagerServiceImpl( val featureFunction = getFeatureFunction(event, latestRobot) if (featureFunction != null) { val authority = sessionFactory.withSession { - authService.getAuthorityByCode(featureFunction.code!!) + authService.getAuthorityCacheByCode(featureFunction.code!!) }.runSubscriptionOn { vertxContext.runOnContext(it) }.awaitSuspending() if (authority != null && authority.enabled == true) { val switch = sessionFactory.withSession {