fix(calculate): 관리자 정산 목록 조회와 엑셀 다운로드에 페이징 기반 조회를 적용한다

This commit is contained in:
2026-03-05 14:12:35 +09:00
parent 96ab4da1b0
commit c422bb3d6e
3 changed files with 183 additions and 34 deletions

View File

@@ -21,8 +21,16 @@ class AdminCalculateController(private val service: AdminCalculateService) {
@GetMapping("/live") @GetMapping("/live")
fun getCalculateLive( fun getCalculateLive(
@RequestParam startDateStr: String, @RequestParam startDateStr: String,
@RequestParam endDateStr: String @RequestParam endDateStr: String,
) = ApiResponse.ok(service.getCalculateLive(startDateStr, endDateStr)) pageable: Pageable
) = ApiResponse.ok(
service.getCalculateLive(
startDateStr,
endDateStr,
pageable.offset,
pageable.pageSize.toLong()
)
)
@GetMapping("/live/excel") @GetMapping("/live/excel")
fun downloadCalculateLiveExcel( fun downloadCalculateLiveExcel(
@@ -36,8 +44,16 @@ class AdminCalculateController(private val service: AdminCalculateService) {
@GetMapping("/content-list") @GetMapping("/content-list")
fun getCalculateContentList( fun getCalculateContentList(
@RequestParam startDateStr: String, @RequestParam startDateStr: String,
@RequestParam endDateStr: String @RequestParam endDateStr: String,
) = ApiResponse.ok(service.getCalculateContentList(startDateStr, endDateStr)) pageable: Pageable
) = ApiResponse.ok(
service.getCalculateContentList(
startDateStr,
endDateStr,
pageable.offset,
pageable.pageSize.toLong()
)
)
@GetMapping("/content-list/excel") @GetMapping("/content-list/excel")
fun downloadCalculateContentListExcel( fun downloadCalculateContentListExcel(
@@ -56,8 +72,16 @@ class AdminCalculateController(private val service: AdminCalculateService) {
@GetMapping("/content-donation-list") @GetMapping("/content-donation-list")
fun getCalculateContentDonationList( fun getCalculateContentDonationList(
@RequestParam startDateStr: String, @RequestParam startDateStr: String,
@RequestParam endDateStr: String @RequestParam endDateStr: String,
) = ApiResponse.ok(service.getCalculateContentDonationList(startDateStr, endDateStr)) pageable: Pageable
) = ApiResponse.ok(
service.getCalculateContentDonationList(
startDateStr,
endDateStr,
pageable.offset,
pageable.pageSize.toLong()
)
)
@GetMapping("/content-donation-list/excel") @GetMapping("/content-donation-list/excel")
fun downloadCalculateContentDonationListExcel( fun downloadCalculateContentDonationListExcel(

View File

@@ -18,7 +18,33 @@ import java.time.LocalDateTime
@Repository @Repository
class AdminCalculateQueryRepository(private val queryFactory: JPAQueryFactory) { class AdminCalculateQueryRepository(private val queryFactory: JPAQueryFactory) {
fun getCalculateLive(startDate: LocalDateTime, endDate: LocalDateTime): List<GetCalculateLiveQueryData> { fun getCalculateLiveTotalCount(startDate: LocalDateTime, endDate: LocalDateTime): Int {
return queryFactory
.select(liveRoom.id)
.from(useCan)
.innerJoin(useCan.room, liveRoom)
.innerJoin(liveRoom.member, member)
.leftJoin(creatorSettlementRatio)
.on(
member.id.eq(creatorSettlementRatio.member.id)
.and(creatorSettlementRatio.deletedAt.isNull)
)
.where(
useCan.isRefund.isFalse
.and(useCan.createdAt.goe(startDate))
.and(useCan.createdAt.loe(endDate))
)
.groupBy(liveRoom.id, useCan.canUsage, creatorSettlementRatio.liveSettlementRatio)
.fetch()
.size
}
fun getCalculateLive(
startDate: LocalDateTime,
endDate: LocalDateTime,
offset: Long,
limit: Long
): List<GetCalculateLiveQueryData> {
val formattedDate = getFormattedDate(liveRoom.beginDateTime) val formattedDate = getFormattedDate(liveRoom.beginDateTime)
return queryFactory return queryFactory
@@ -50,10 +76,50 @@ class AdminCalculateQueryRepository(private val queryFactory: JPAQueryFactory) {
) )
.groupBy(liveRoom.id, useCan.canUsage, creatorSettlementRatio.liveSettlementRatio) .groupBy(liveRoom.id, useCan.canUsage, creatorSettlementRatio.liveSettlementRatio)
.orderBy(member.nickname.desc(), liveRoom.id.desc(), useCan.canUsage.desc(), formattedDate.desc()) .orderBy(member.nickname.desc(), liveRoom.id.desc(), useCan.canUsage.desc(), formattedDate.desc())
.offset(offset)
.limit(limit)
.fetch() .fetch()
} }
fun getCalculateContentList(startDate: LocalDateTime, endDate: LocalDateTime): List<GetCalculateContentQueryData> { fun getCalculateContentListTotalCount(startDate: LocalDateTime, endDate: LocalDateTime): Int {
val orderFormattedDate = getFormattedDate(order.createdAt)
val pointGroup = CaseBuilder()
.`when`(order.point.loe(0)).then(0)
.otherwise(1)
return queryFactory
.select(audioContent.id)
.from(order)
.innerJoin(order.audioContent, audioContent)
.innerJoin(audioContent.member, member)
.leftJoin(creatorSettlementRatio)
.on(
member.id.eq(creatorSettlementRatio.member.id)
.and(creatorSettlementRatio.deletedAt.isNull)
)
.where(
order.createdAt.goe(startDate)
.and(order.createdAt.loe(endDate))
.and(order.isActive.isTrue)
)
.groupBy(
audioContent.id,
order.type,
orderFormattedDate,
order.can,
pointGroup,
creatorSettlementRatio.contentSettlementRatio
)
.fetch()
.size
}
fun getCalculateContentList(
startDate: LocalDateTime,
endDate: LocalDateTime,
offset: Long,
limit: Long
): List<GetCalculateContentQueryData> {
val orderFormattedDate = getFormattedDate(order.createdAt) val orderFormattedDate = getFormattedDate(order.createdAt)
val pointGroup = CaseBuilder() val pointGroup = CaseBuilder()
.`when`(order.point.loe(0)).then(0) .`when`(order.point.loe(0)).then(0)
@@ -96,6 +162,8 @@ class AdminCalculateQueryRepository(private val queryFactory: JPAQueryFactory) {
creatorSettlementRatio.contentSettlementRatio creatorSettlementRatio.contentSettlementRatio
) )
.orderBy(member.id.desc(), orderFormattedDate.desc(), audioContent.id.asc()) .orderBy(member.id.desc(), orderFormattedDate.desc(), audioContent.id.asc())
.offset(offset)
.limit(limit)
.fetch() .fetch()
} }
@@ -167,11 +235,33 @@ class AdminCalculateQueryRepository(private val queryFactory: JPAQueryFactory) {
.fetch() .fetch()
} }
fun getCalculateContentDonationListTotalCount(startDate: LocalDateTime, endDate: LocalDateTime): Int {
val donationFormattedDate = getFormattedDate(useCan.createdAt)
return queryFactory
.select(audioContent.id)
.from(useCan)
.innerJoin(useCan.audioContent, audioContent)
.innerJoin(audioContent.member, member)
.where(
useCan.isRefund.isFalse
.and(useCan.canUsage.eq(CanUsage.DONATION))
.and(useCan.createdAt.goe(startDate))
.and(useCan.createdAt.loe(endDate))
)
.groupBy(donationFormattedDate, audioContent.id)
.fetch()
.size
}
fun getCalculateContentDonationList( fun getCalculateContentDonationList(
startDate: LocalDateTime, startDate: LocalDateTime,
endDate: LocalDateTime endDate: LocalDateTime,
offset: Long,
limit: Long
): List<GetCalculateContentDonationQueryData> { ): List<GetCalculateContentDonationQueryData> {
val donationFormattedDate = getFormattedDate(useCan.createdAt) val donationFormattedDate = getFormattedDate(useCan.createdAt)
return queryFactory return queryFactory
.select( .select(
QGetCalculateContentDonationQueryData( QGetCalculateContentDonationQueryData(
@@ -195,6 +285,8 @@ class AdminCalculateQueryRepository(private val queryFactory: JPAQueryFactory) {
) )
.groupBy(donationFormattedDate, audioContent.id) .groupBy(donationFormattedDate, audioContent.id)
.orderBy(member.id.asc(), donationFormattedDate.desc(), audioContent.id.desc()) .orderBy(member.id.asc(), donationFormattedDate.desc(), audioContent.id.desc())
.offset(offset)
.limit(limit)
.fetch() .fetch()
} }

View File

@@ -15,29 +15,43 @@ class AdminCalculateService(private val repository: AdminCalculateQueryRepositor
@Transactional(readOnly = true) @Transactional(readOnly = true)
@Cacheable( @Cacheable(
cacheNames = ["cache_ttl_3_hours"], cacheNames = ["cache_ttl_3_hours"],
key = "'calculateLive:' + " + "#startDateStr + ':' + #endDateStr" key = "'calculateLive:' + " + "#startDateStr + ':' + #endDateStr + ':' + #offset + ':' + #limit"
) )
fun getCalculateLive(startDateStr: String, endDateStr: String): List<GetCalculateLiveResponse> { fun getCalculateLive(
startDateStr: String,
endDateStr: String,
offset: Long,
limit: Long
): GetCalculateLiveListResponse {
val startDate = startDateStr.convertLocalDateTime() val startDate = startDateStr.convertLocalDateTime()
val endDate = endDateStr.convertLocalDateTime(hour = 23, minute = 59, second = 59) val endDate = endDateStr.convertLocalDateTime(hour = 23, minute = 59, second = 59)
val totalCount = repository.getCalculateLiveTotalCount(startDate, endDate)
return repository val items = repository
.getCalculateLive(startDate, endDate) .getCalculateLive(startDate, endDate, offset, limit)
.map { it.toGetCalculateLiveResponse() } .map { it.toGetCalculateLiveResponse() }
return GetCalculateLiveListResponse(totalCount, items)
} }
@Transactional(readOnly = true) @Transactional(readOnly = true)
@Cacheable( @Cacheable(
cacheNames = ["cache_ttl_3_hours"], cacheNames = ["cache_ttl_3_hours"],
key = "'calculateContent:' + " + "#startDateStr + ':' + #endDateStr" key = "'calculateContent:' + " + "#startDateStr + ':' + #endDateStr + ':' + #offset + ':' + #limit"
) )
fun getCalculateContentList(startDateStr: String, endDateStr: String): List<GetCalculateContentResponse> { fun getCalculateContentList(
startDateStr: String,
endDateStr: String,
offset: Long,
limit: Long
): GetCalculateContentListResponse {
val startDate = startDateStr.convertLocalDateTime() val startDate = startDateStr.convertLocalDateTime()
val endDate = endDateStr.convertLocalDateTime(hour = 23, minute = 59, second = 59) val endDate = endDateStr.convertLocalDateTime(hour = 23, minute = 59, second = 59)
val totalCount = repository.getCalculateContentListTotalCount(startDate, endDate)
return repository val items = repository
.getCalculateContentList(startDate, endDate) .getCalculateContentList(startDate, endDate, offset, limit)
.map { it.toGetCalculateContentResponse() } .map { it.toGetCalculateContentResponse() }
return GetCalculateContentListResponse(totalCount, items)
} }
@Transactional(readOnly = true) @Transactional(readOnly = true)
@@ -57,18 +71,22 @@ class AdminCalculateService(private val repository: AdminCalculateQueryRepositor
@Transactional(readOnly = true) @Transactional(readOnly = true)
@Cacheable( @Cacheable(
cacheNames = ["cache_ttl_3_hours"], cacheNames = ["cache_ttl_3_hours"],
key = "'calculateContentDonationList2:' + " + "#startDateStr + ':' + #endDateStr" key = "'calculateContentDonationList2:' + " + "#startDateStr + ':' + #endDateStr + ':' + #offset + ':' + #limit"
) )
fun getCalculateContentDonationList( fun getCalculateContentDonationList(
startDateStr: String, startDateStr: String,
endDateStr: String endDateStr: String,
): List<GetCalculateContentDonationResponse> { offset: Long,
limit: Long
): GetCalculateContentDonationListResponse {
val startDate = startDateStr.convertLocalDateTime() val startDate = startDateStr.convertLocalDateTime()
val endDate = endDateStr.convertLocalDateTime(hour = 23, minute = 59, second = 59) val endDate = endDateStr.convertLocalDateTime(hour = 23, minute = 59, second = 59)
val totalCount = repository.getCalculateContentDonationListTotalCount(startDate, endDate)
return repository val items = repository
.getCalculateContentDonationList(startDate, endDate) .getCalculateContentDonationList(startDate, endDate, offset, limit)
.map { it.toGetCalculateContentDonationResponse() } .map { it.toGetCalculateContentDonationResponse() }
return GetCalculateContentDonationListResponse(totalCount, items)
} }
@Transactional(readOnly = true) @Transactional(readOnly = true)
@@ -147,9 +165,14 @@ class AdminCalculateService(private val repository: AdminCalculateQueryRepositor
@Transactional(readOnly = true) @Transactional(readOnly = true)
fun downloadCalculateLiveExcel(startDateStr: String, endDateStr: String): StreamingResponseBody { fun downloadCalculateLiveExcel(startDateStr: String, endDateStr: String): StreamingResponseBody {
val (startDate, endDate) = toDateRange(startDateStr, endDateStr) val (startDate, endDate) = toDateRange(startDateStr, endDateStr)
val items = repository val totalCount = repository.getCalculateLiveTotalCount(startDate, endDate)
.getCalculateLive(startDate, endDate) val items = if (totalCount == 0) {
.map { it.toGetCalculateLiveResponse() } emptyList()
} else {
repository
.getCalculateLive(startDate, endDate, 0L, totalCount.toLong())
.map { it.toGetCalculateLiveResponse() }
}
return createExcelStream( return createExcelStream(
sheetName = "라이브 정산", sheetName = "라이브 정산",
@@ -191,9 +214,14 @@ class AdminCalculateService(private val repository: AdminCalculateQueryRepositor
@Transactional(readOnly = true) @Transactional(readOnly = true)
fun downloadCalculateContentListExcel(startDateStr: String, endDateStr: String): StreamingResponseBody { fun downloadCalculateContentListExcel(startDateStr: String, endDateStr: String): StreamingResponseBody {
val (startDate, endDate) = toDateRange(startDateStr, endDateStr) val (startDate, endDate) = toDateRange(startDateStr, endDateStr)
val items = repository val totalCount = repository.getCalculateContentListTotalCount(startDate, endDate)
.getCalculateContentList(startDate, endDate) val items = if (totalCount == 0) {
.map { it.toGetCalculateContentResponse() } emptyList()
} else {
repository
.getCalculateContentList(startDate, endDate, 0L, totalCount.toLong())
.map { it.toGetCalculateContentResponse() }
}
return createExcelStream( return createExcelStream(
sheetName = "콘텐츠 정산", sheetName = "콘텐츠 정산",
@@ -235,9 +263,14 @@ class AdminCalculateService(private val repository: AdminCalculateQueryRepositor
@Transactional(readOnly = true) @Transactional(readOnly = true)
fun downloadCalculateContentDonationListExcel(startDateStr: String, endDateStr: String): StreamingResponseBody { fun downloadCalculateContentDonationListExcel(startDateStr: String, endDateStr: String): StreamingResponseBody {
val (startDate, endDate) = toDateRange(startDateStr, endDateStr) val (startDate, endDate) = toDateRange(startDateStr, endDateStr)
val items = repository val totalCount = repository.getCalculateContentDonationListTotalCount(startDate, endDate)
.getCalculateContentDonationList(startDate, endDate) val items = if (totalCount == 0) {
.map { it.toGetCalculateContentDonationResponse() } emptyList()
} else {
repository
.getCalculateContentDonationList(startDate, endDate, 0L, totalCount.toLong())
.map { it.toGetCalculateContentDonationResponse() }
}
return createExcelStream( return createExcelStream(
sheetName = "콘텐츠 후원 정산", sheetName = "콘텐츠 후원 정산",