Skip to content

Commit

Permalink
🔥 feat: 获取用户统计数据
Browse files Browse the repository at this point in the history
  • Loading branch information
cokie committed Jan 30, 2024
1 parent b1e66e0 commit b3a183f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ class UserStatisticsDTO {
@Schema(title = "在线人数")
var onlineUserCount: Int? = null

@Schema(title = "注册人数")
var enrollUserCount: Long? = null

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ class UserStatisticsDO : BaseDomainEntity() {

var onlineUserCount: Int? = null

var enrollUserCount: Long? = null

}
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,23 @@ class AuthServiceImpl(private val authRepository: IAuthRepository) : AuthService
.flatMap { authRepository.updateUserAuthorityRelation(id, it.toList()) }
}

@WithTransaction
override fun getUserStatistics(): Uni<UserStatisticsDO> {
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 }
}
}
}
Expand Down

0 comments on commit b3a183f

Please sign in to comment.