diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/admin/chat/calculate/AdminChatCalculateQueryRepository.kt b/src/main/kotlin/kr/co/vividnext/sodalive/admin/chat/calculate/AdminChatCalculateQueryRepository.kt index 241310c..402a07e 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/admin/chat/calculate/AdminChatCalculateQueryRepository.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/admin/chat/calculate/AdminChatCalculateQueryRepository.kt @@ -68,4 +68,24 @@ class AdminChatCalculateQueryRepository( .limit(limit) .fetch() } + + fun getCharacterCalculateTotalCount( + startUtc: LocalDateTime, + endInclusiveUtc: LocalDateTime + ): Int { + return queryFactory + .select(chatCharacter.id) + .from(useCan) + .innerJoin(useCan.characterImage, characterImage) + .innerJoin(characterImage.chatCharacter, chatCharacter) + .where( + useCan.isRefund.isFalse + .and(useCan.canUsage.`in`(CanUsage.CHARACTER_IMAGE_PURCHASE, CanUsage.CHAT_MESSAGE_PURCHASE)) + .and(useCan.createdAt.goe(startUtc)) + .and(useCan.createdAt.loe(endInclusiveUtc)) + ) + .groupBy(chatCharacter.id) + .fetch() + .size + } } diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/admin/chat/calculate/AdminChatCalculateService.kt b/src/main/kotlin/kr/co/vividnext/sodalive/admin/chat/calculate/AdminChatCalculateService.kt index 39aad0d..e9b95c4 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/admin/chat/calculate/AdminChatCalculateService.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/admin/chat/calculate/AdminChatCalculateService.kt @@ -21,7 +21,7 @@ class AdminChatCalculateService( sort: ChatCharacterCalculateSort, offset: Long, pageSize: Int - ): List { + ): ChatCharacterCalculateResponse { // 날짜 유효성 검증 (KST 기준) val startDate = LocalDate.parse(startDateStr, dateFormatter) val endDate = LocalDate.parse(endDateStr, dateFormatter) @@ -35,7 +35,9 @@ class AdminChatCalculateService( val startUtc = startDateStr.convertLocalDateTime() val endInclusiveUtc = endDateStr.convertLocalDateTime(hour = 23, minute = 59, second = 59) + val totalCount = repository.getCharacterCalculateTotalCount(startUtc, endInclusiveUtc) val rows = repository.getCharacterCalculate(startUtc, endInclusiveUtc, sort, offset, pageSize.toLong()) - return rows.map { it.toItem() } + val items = rows.map { it.toItem() } + return ChatCharacterCalculateResponse(totalCount, items) } } diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/admin/chat/calculate/ChatCharacterCalculateDtos.kt b/src/main/kotlin/kr/co/vividnext/sodalive/admin/chat/calculate/ChatCharacterCalculateDtos.kt index 17076a9..8fa38b7 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/admin/chat/calculate/ChatCharacterCalculateDtos.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/admin/chat/calculate/ChatCharacterCalculateDtos.kt @@ -20,7 +20,7 @@ data class ChatCharacterCalculateQueryData @QueryProjection constructor( val messagePurchaseCan: Int? ) -// 응답 DTO +// 응답 DTO (아이템) data class ChatCharacterCalculateItem( @JsonProperty("characterId") val characterId: Long, @JsonProperty("characterImage") val characterImage: String?, @@ -32,6 +32,12 @@ data class ChatCharacterCalculateItem( @JsonProperty("settlementKrw") val settlementKrw: Int ) +// 응답 DTO (전체) +data class ChatCharacterCalculateResponse( + @JsonProperty("totalCount") val totalCount: Int, + @JsonProperty("items") val items: List +) + fun ChatCharacterCalculateQueryData.toItem(): ChatCharacterCalculateItem { val image = imagePurchaseCan ?: 0 val message = messagePurchaseCan ?: 0