From 1a4e2551a74ed901a046d509ac27bce5228d14a4 Mon Sep 17 00:00:00 2001 From: DongGeon0908 Date: Mon, 2 Sep 2024 21:17:27 +0900 Subject: [PATCH] =?UTF-8?q?imp:=20=EB=94=94=EC=8A=A4=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=95=8C=EB=A6=BC=EC=97=90=20=ED=99=9C=EC=84=B1=20=EC=9C=A0?= =?UTF-8?q?=EC=A0=80=20=EB=9E=AD=ED=82=B9=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/DDL.sql | 1 + .../batch/statistics/job/HeroStatisticsJob.kt | 26 ++++++---- .../SystemActionLogRepository.kt | 47 ++++++++++++++++++- .../infrastructure/model/CountActiveUser.kt | 8 ++++ 4 files changed, 73 insertions(+), 9 deletions(-) create mode 100644 src/main/kotlin/com/hero/alignlab/domain/log/infrastructure/model/CountActiveUser.kt diff --git a/sql/DDL.sql b/sql/DDL.sql index d4a1349..c4a0d42 100644 --- a/sql/DDL.sql +++ b/sql/DDL.sql @@ -18,6 +18,7 @@ CREATE TABLE `system_action_log` `modified_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT 'system log'; +CREATE INDEX idx__uid ON system_action_log (uid); -- 이미지 CREATE TABLE `image_metadata` diff --git a/src/main/kotlin/com/hero/alignlab/batch/statistics/job/HeroStatisticsJob.kt b/src/main/kotlin/com/hero/alignlab/batch/statistics/job/HeroStatisticsJob.kt index dce06f5..29e6499 100644 --- a/src/main/kotlin/com/hero/alignlab/batch/statistics/job/HeroStatisticsJob.kt +++ b/src/main/kotlin/com/hero/alignlab/batch/statistics/job/HeroStatisticsJob.kt @@ -64,6 +64,9 @@ class HeroStatisticsJob( val syslogTotalCount = async(Dispatchers.IO) { systemActionLogRepository.count() } + val countActiveUserTop3 = async(Dispatchers.IO) { + systemActionLogRepository.countActiveUserTop3(fromDate, toDate) + } /** 포즈 */ val poseNotificationCountByCreatedAt = async(Dispatchers.IO) { @@ -94,6 +97,7 @@ class HeroStatisticsJob( } val userInfoCountByCreatedAt = async(Dispatchers.IO) { userInfoRepository.countByCreatedAtBetween(fromDate, toDate) + } val userInfoTotalCount = async(Dispatchers.IO) { userInfoRepository.count() @@ -109,32 +113,38 @@ class HeroStatisticsJob( val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss") + val text = countActiveUserTop3.await().joinToString("\n") { + "- uid: ${it.uid} / count: ${it.count}" + } + val message = """ - $title [${fromDate.format(formatter)} ~ ${toDate.format(formatter)}] + **$title [${fromDate.format(formatter)} ~ ${toDate.format(formatter)}]** - 그룹 + **그룹** - 그룹 생성수 : ${groupCountByCreatedAt.await()}건 [총합: ${groupTotalCount.await()}건] - 그룹 유저 생성수 : ${groupUserCountByCreatedAt.await()}건 [총합: ${groupUserTotalCount.await()}건] - 문의하기 + **문의하기** - 문의하기 생성수 : ${discussionCountByCreatedAt.await()}건 [총합: ${discussionTotalCount.await()}건] - API + **API** - api 호출량 : ${syslogCountByCreatedAt.await()}건 [총합: ${syslogTotalCount.await()}건] - 포즈 + **포즈** - 포즈 알림 설정수 : ${poseNotificationCountByCreatedAt.await()}건 [총합: ${poseNotificationTotalCount.await()}건] - 포즈 스냅샷 생성수 : ${poseSnapshotCountByCreatedAt.await()}건 [총합: ${poseSnapshotTotalCount.await()}건] - 회원 + **회원** - 일반 회원가입수 : ${credentialUserInfoCountByCreatedAt.await()}건 [총합: ${credentialUserInfoCountTotalCount.await()}건] - OAuth 회원가입수 : ${oAuthUserInfoCountByCreatedAt.await()}건 [총합: ${oAuthUserInfoTotalCount.await()}건] - 유저 생성수 : ${userInfoCountByCreatedAt.await()}건 [총합: ${userInfoTotalCount.await()}건] - 이미지 + **이미지** - 이미지 생성수 : ${imageCountByCreatedAt.await()}건 [총합: ${imageTotalCount.await()}건] + + **이용자 현황** + - ${countActiveUserTop3.await().joinToString(" | ") { "uid : ${it.uid} count : ${it.count}" }} """.trimIndent() - discordWebhookService.sendMessage(SendMessageRequest(message)) } } diff --git a/src/main/kotlin/com/hero/alignlab/domain/log/infrastructure/SystemActionLogRepository.kt b/src/main/kotlin/com/hero/alignlab/domain/log/infrastructure/SystemActionLogRepository.kt index a5f1f5e..6e7fb7e 100644 --- a/src/main/kotlin/com/hero/alignlab/domain/log/infrastructure/SystemActionLogRepository.kt +++ b/src/main/kotlin/com/hero/alignlab/domain/log/infrastructure/SystemActionLogRepository.kt @@ -1,13 +1,58 @@ package com.hero.alignlab.domain.log.infrastructure +import com.hero.alignlab.common.extension.isGoe +import com.hero.alignlab.common.extension.isLoe +import com.hero.alignlab.domain.log.domain.QSystemActionLog import com.hero.alignlab.domain.log.domain.SystemActionLog +import com.hero.alignlab.domain.log.infrastructure.model.CountActiveUser +import com.hero.alignlab.domain.log.infrastructure.model.QCountActiveUser +import com.querydsl.jpa.impl.JPAQuery +import jakarta.persistence.EntityManager +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.beans.factory.annotation.Qualifier import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.data.jpa.repository.support.QuerydslRepositorySupport import org.springframework.stereotype.Repository import org.springframework.transaction.annotation.Transactional import java.time.LocalDateTime @Transactional(readOnly = true) @Repository -interface SystemActionLogRepository : JpaRepository { +interface SystemActionLogRepository : JpaRepository, SystemActionLogQRepository { fun countByCreatedAtBetween(startAt: LocalDateTime, endAt: LocalDateTime): Long } + +@Transactional(readOnly = true) +interface SystemActionLogQRepository { + fun countActiveUserTop3(fromCreatedAt: LocalDateTime, toCreatedAt: LocalDateTime): List +} + +class SystemActionLogRepositoryImpl : SystemActionLogQRepository, + QuerydslRepositorySupport(SystemActionLog::class.java) { + @Autowired + @Qualifier("heroEntityManager") + override fun setEntityManager(entityManager: EntityManager) { + super.setEntityManager(entityManager) + } + + private val qSystemActionLog = QSystemActionLog.systemActionLog + + override fun countActiveUserTop3(fromCreatedAt: LocalDateTime, toCreatedAt: LocalDateTime): List { + return JPAQuery(entityManager) + .select( + QCountActiveUser( + qSystemActionLog.uid, + qSystemActionLog.id.count() + ) + ).from(qSystemActionLog) + .where( + qSystemActionLog.uid.isNotNull, + qSystemActionLog.createdAt.isGoe(fromCreatedAt), + qSystemActionLog.createdAt.isLoe(toCreatedAt) + ) + .groupBy(qSystemActionLog.uid) + .orderBy(qSystemActionLog.id.count().desc()) + .limit(3) + .fetch() + } +} diff --git a/src/main/kotlin/com/hero/alignlab/domain/log/infrastructure/model/CountActiveUser.kt b/src/main/kotlin/com/hero/alignlab/domain/log/infrastructure/model/CountActiveUser.kt new file mode 100644 index 0000000..7273829 --- /dev/null +++ b/src/main/kotlin/com/hero/alignlab/domain/log/infrastructure/model/CountActiveUser.kt @@ -0,0 +1,8 @@ +package com.hero.alignlab.domain.log.infrastructure.model + +import com.querydsl.core.annotations.QueryProjection + +data class CountActiveUser @QueryProjection constructor( + val uid: Long, + val count: Long, +)