From b3a183fa2932c9b10c5dd2227379a0902830e123 Mon Sep 17 00:00:00 2001 From: cokie Date: Tue, 30 Jan 2024 18:08:44 +0800 Subject: [PATCH] =?UTF-8?q?:fire:=20feat:=20=E8=8E=B7=E5=8F=96=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E7=BB=9F=E8=AE=A1=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../micro/api/user/dto/UserStatisticsDTO.kt | 3 +++ .../domain/model/entity/UserStatisticsDO.kt | 2 ++ .../domain/service/impl/AuthServiceImpl.kt | 24 ++++++++++++------- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/tokisaki-api/src/main/kotlin/io/micro/api/user/dto/UserStatisticsDTO.kt b/tokisaki-api/src/main/kotlin/io/micro/api/user/dto/UserStatisticsDTO.kt index 3cbd872..17f7fd3 100644 --- a/tokisaki-api/src/main/kotlin/io/micro/api/user/dto/UserStatisticsDTO.kt +++ b/tokisaki-api/src/main/kotlin/io/micro/api/user/dto/UserStatisticsDTO.kt @@ -10,4 +10,7 @@ class UserStatisticsDTO { @Schema(title = "在线人数") var onlineUserCount: Int? = null + @Schema(title = "注册人数") + var enrollUserCount: Long? = null + } \ No newline at end of file diff --git a/tokisaki-server/src/main/kotlin/io/micro/server/auth/domain/model/entity/UserStatisticsDO.kt b/tokisaki-server/src/main/kotlin/io/micro/server/auth/domain/model/entity/UserStatisticsDO.kt index 66da0b5..d9ae0d6 100644 --- a/tokisaki-server/src/main/kotlin/io/micro/server/auth/domain/model/entity/UserStatisticsDO.kt +++ b/tokisaki-server/src/main/kotlin/io/micro/server/auth/domain/model/entity/UserStatisticsDO.kt @@ -6,4 +6,6 @@ class UserStatisticsDO : BaseDomainEntity() { var onlineUserCount: Int? = null + var enrollUserCount: Long? = null + } \ 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 91f523b..29c4642 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 @@ -113,17 +113,23 @@ class AuthServiceImpl(private val authRepository: IAuthRepository) : AuthService .flatMap { authRepository.updateUserAuthorityRelation(id, it.toList()) } } + @WithTransaction override fun getUserStatistics(): Uni { - return authRepository.findAllUserLastLoginTime() - .map { lastLoginTime -> - val currentTimeMillis = System.currentTimeMillis() - lastLoginTime.filterValues { - Duration.ofMillis(currentTimeMillis - it).toMinutes() < ONLINE_SURVIVAL_MINUTES - }.count() + return Uni.createFrom().item(UserStatisticsDO()) + .flatMap { statistics -> + authRepository.findAllUserLastLoginTime() + .map { lastLoginTime -> + val currentTimeMillis = System.currentTimeMillis() + val count = lastLoginTime.filterValues { + Duration.ofMillis(currentTimeMillis - it).toMinutes() < ONLINE_SURVIVAL_MINUTES + }.count() + statistics.apply { onlineUserCount = count } + } + } - .map { - UserStatisticsDO().apply { - onlineUserCount = it + .flatMap { statistics -> + authRepository.countUser().map { + statistics.apply { enrollUserCount = it } } } }