-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ad8b0d9
commit 1a4e255
Showing
4 changed files
with
73 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 46 additions & 1 deletion
47
src/main/kotlin/com/hero/alignlab/domain/log/infrastructure/SystemActionLogRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/kotlin/com/hero/alignlab/domain/log/infrastructure/model/CountActiveUser.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |