Skip to content

Commit

Permalink
imp: 디스코드 알림에 활성 유저 랭킹 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
DongGeon0908 committed Sep 2, 2024
1 parent ad8b0d9 commit 1a4e255
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 9 deletions.
1 change: 1 addition & 0 deletions sql/DDL.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -94,6 +97,7 @@ class HeroStatisticsJob(
}
val userInfoCountByCreatedAt = async(Dispatchers.IO) {
userInfoRepository.countByCreatedAtBetween(fromDate, toDate)

}
val userInfoTotalCount = async(Dispatchers.IO) {
userInfoRepository.count()
Expand All @@ -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))
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<SystemActionLog, Long> {
interface SystemActionLogRepository : JpaRepository<SystemActionLog, Long>, SystemActionLogQRepository {
fun countByCreatedAtBetween(startAt: LocalDateTime, endAt: LocalDateTime): Long
}

@Transactional(readOnly = true)
interface SystemActionLogQRepository {
fun countActiveUserTop3(fromCreatedAt: LocalDateTime, toCreatedAt: LocalDateTime): List<CountActiveUser>
}

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<CountActiveUser> {
return JPAQuery<QSystemActionLog>(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()
}
}
Original file line number Diff line number Diff line change
@@ -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,
)

0 comments on commit 1a4e255

Please sign in to comment.