fix(calculate): 관리자 정산 목록 조회와 엑셀 다운로드에 페이징 기반 조회를 적용한다
This commit is contained in:
@@ -21,8 +21,16 @@ class AdminCalculateController(private val service: AdminCalculateService) {
|
||||
@GetMapping("/live")
|
||||
fun getCalculateLive(
|
||||
@RequestParam startDateStr: String,
|
||||
@RequestParam endDateStr: String
|
||||
) = ApiResponse.ok(service.getCalculateLive(startDateStr, endDateStr))
|
||||
@RequestParam endDateStr: String,
|
||||
pageable: Pageable
|
||||
) = ApiResponse.ok(
|
||||
service.getCalculateLive(
|
||||
startDateStr,
|
||||
endDateStr,
|
||||
pageable.offset,
|
||||
pageable.pageSize.toLong()
|
||||
)
|
||||
)
|
||||
|
||||
@GetMapping("/live/excel")
|
||||
fun downloadCalculateLiveExcel(
|
||||
@@ -36,8 +44,16 @@ class AdminCalculateController(private val service: AdminCalculateService) {
|
||||
@GetMapping("/content-list")
|
||||
fun getCalculateContentList(
|
||||
@RequestParam startDateStr: String,
|
||||
@RequestParam endDateStr: String
|
||||
) = ApiResponse.ok(service.getCalculateContentList(startDateStr, endDateStr))
|
||||
@RequestParam endDateStr: String,
|
||||
pageable: Pageable
|
||||
) = ApiResponse.ok(
|
||||
service.getCalculateContentList(
|
||||
startDateStr,
|
||||
endDateStr,
|
||||
pageable.offset,
|
||||
pageable.pageSize.toLong()
|
||||
)
|
||||
)
|
||||
|
||||
@GetMapping("/content-list/excel")
|
||||
fun downloadCalculateContentListExcel(
|
||||
@@ -56,8 +72,16 @@ class AdminCalculateController(private val service: AdminCalculateService) {
|
||||
@GetMapping("/content-donation-list")
|
||||
fun getCalculateContentDonationList(
|
||||
@RequestParam startDateStr: String,
|
||||
@RequestParam endDateStr: String
|
||||
) = ApiResponse.ok(service.getCalculateContentDonationList(startDateStr, endDateStr))
|
||||
@RequestParam endDateStr: String,
|
||||
pageable: Pageable
|
||||
) = ApiResponse.ok(
|
||||
service.getCalculateContentDonationList(
|
||||
startDateStr,
|
||||
endDateStr,
|
||||
pageable.offset,
|
||||
pageable.pageSize.toLong()
|
||||
)
|
||||
)
|
||||
|
||||
@GetMapping("/content-donation-list/excel")
|
||||
fun downloadCalculateContentDonationListExcel(
|
||||
|
||||
@@ -18,7 +18,33 @@ import java.time.LocalDateTime
|
||||
|
||||
@Repository
|
||||
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)
|
||||
|
||||
return queryFactory
|
||||
@@ -50,10 +76,50 @@ class AdminCalculateQueryRepository(private val queryFactory: JPAQueryFactory) {
|
||||
)
|
||||
.groupBy(liveRoom.id, useCan.canUsage, creatorSettlementRatio.liveSettlementRatio)
|
||||
.orderBy(member.nickname.desc(), liveRoom.id.desc(), useCan.canUsage.desc(), formattedDate.desc())
|
||||
.offset(offset)
|
||||
.limit(limit)
|
||||
.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 pointGroup = CaseBuilder()
|
||||
.`when`(order.point.loe(0)).then(0)
|
||||
@@ -96,6 +162,8 @@ class AdminCalculateQueryRepository(private val queryFactory: JPAQueryFactory) {
|
||||
creatorSettlementRatio.contentSettlementRatio
|
||||
)
|
||||
.orderBy(member.id.desc(), orderFormattedDate.desc(), audioContent.id.asc())
|
||||
.offset(offset)
|
||||
.limit(limit)
|
||||
.fetch()
|
||||
}
|
||||
|
||||
@@ -167,11 +235,33 @@ class AdminCalculateQueryRepository(private val queryFactory: JPAQueryFactory) {
|
||||
.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(
|
||||
startDate: LocalDateTime,
|
||||
endDate: LocalDateTime
|
||||
endDate: LocalDateTime,
|
||||
offset: Long,
|
||||
limit: Long
|
||||
): List<GetCalculateContentDonationQueryData> {
|
||||
val donationFormattedDate = getFormattedDate(useCan.createdAt)
|
||||
|
||||
return queryFactory
|
||||
.select(
|
||||
QGetCalculateContentDonationQueryData(
|
||||
@@ -195,6 +285,8 @@ class AdminCalculateQueryRepository(private val queryFactory: JPAQueryFactory) {
|
||||
)
|
||||
.groupBy(donationFormattedDate, audioContent.id)
|
||||
.orderBy(member.id.asc(), donationFormattedDate.desc(), audioContent.id.desc())
|
||||
.offset(offset)
|
||||
.limit(limit)
|
||||
.fetch()
|
||||
}
|
||||
|
||||
|
||||
@@ -15,29 +15,43 @@ class AdminCalculateService(private val repository: AdminCalculateQueryRepositor
|
||||
@Transactional(readOnly = true)
|
||||
@Cacheable(
|
||||
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 endDate = endDateStr.convertLocalDateTime(hour = 23, minute = 59, second = 59)
|
||||
|
||||
return repository
|
||||
.getCalculateLive(startDate, endDate)
|
||||
val totalCount = repository.getCalculateLiveTotalCount(startDate, endDate)
|
||||
val items = repository
|
||||
.getCalculateLive(startDate, endDate, offset, limit)
|
||||
.map { it.toGetCalculateLiveResponse() }
|
||||
|
||||
return GetCalculateLiveListResponse(totalCount, items)
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
@Cacheable(
|
||||
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 endDate = endDateStr.convertLocalDateTime(hour = 23, minute = 59, second = 59)
|
||||
|
||||
return repository
|
||||
.getCalculateContentList(startDate, endDate)
|
||||
val totalCount = repository.getCalculateContentListTotalCount(startDate, endDate)
|
||||
val items = repository
|
||||
.getCalculateContentList(startDate, endDate, offset, limit)
|
||||
.map { it.toGetCalculateContentResponse() }
|
||||
|
||||
return GetCalculateContentListResponse(totalCount, items)
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
@@ -57,18 +71,22 @@ class AdminCalculateService(private val repository: AdminCalculateQueryRepositor
|
||||
@Transactional(readOnly = true)
|
||||
@Cacheable(
|
||||
cacheNames = ["cache_ttl_3_hours"],
|
||||
key = "'calculateContentDonationList2:' + " + "#startDateStr + ':' + #endDateStr"
|
||||
key = "'calculateContentDonationList2:' + " + "#startDateStr + ':' + #endDateStr + ':' + #offset + ':' + #limit"
|
||||
)
|
||||
fun getCalculateContentDonationList(
|
||||
startDateStr: String,
|
||||
endDateStr: String
|
||||
): List<GetCalculateContentDonationResponse> {
|
||||
endDateStr: String,
|
||||
offset: Long,
|
||||
limit: Long
|
||||
): GetCalculateContentDonationListResponse {
|
||||
val startDate = startDateStr.convertLocalDateTime()
|
||||
val endDate = endDateStr.convertLocalDateTime(hour = 23, minute = 59, second = 59)
|
||||
|
||||
return repository
|
||||
.getCalculateContentDonationList(startDate, endDate)
|
||||
val totalCount = repository.getCalculateContentDonationListTotalCount(startDate, endDate)
|
||||
val items = repository
|
||||
.getCalculateContentDonationList(startDate, endDate, offset, limit)
|
||||
.map { it.toGetCalculateContentDonationResponse() }
|
||||
|
||||
return GetCalculateContentDonationListResponse(totalCount, items)
|
||||
}
|
||||
|
||||
@Transactional(readOnly = true)
|
||||
@@ -147,9 +165,14 @@ class AdminCalculateService(private val repository: AdminCalculateQueryRepositor
|
||||
@Transactional(readOnly = true)
|
||||
fun downloadCalculateLiveExcel(startDateStr: String, endDateStr: String): StreamingResponseBody {
|
||||
val (startDate, endDate) = toDateRange(startDateStr, endDateStr)
|
||||
val items = repository
|
||||
.getCalculateLive(startDate, endDate)
|
||||
val totalCount = repository.getCalculateLiveTotalCount(startDate, endDate)
|
||||
val items = if (totalCount == 0) {
|
||||
emptyList()
|
||||
} else {
|
||||
repository
|
||||
.getCalculateLive(startDate, endDate, 0L, totalCount.toLong())
|
||||
.map { it.toGetCalculateLiveResponse() }
|
||||
}
|
||||
|
||||
return createExcelStream(
|
||||
sheetName = "라이브 정산",
|
||||
@@ -191,9 +214,14 @@ class AdminCalculateService(private val repository: AdminCalculateQueryRepositor
|
||||
@Transactional(readOnly = true)
|
||||
fun downloadCalculateContentListExcel(startDateStr: String, endDateStr: String): StreamingResponseBody {
|
||||
val (startDate, endDate) = toDateRange(startDateStr, endDateStr)
|
||||
val items = repository
|
||||
.getCalculateContentList(startDate, endDate)
|
||||
val totalCount = repository.getCalculateContentListTotalCount(startDate, endDate)
|
||||
val items = if (totalCount == 0) {
|
||||
emptyList()
|
||||
} else {
|
||||
repository
|
||||
.getCalculateContentList(startDate, endDate, 0L, totalCount.toLong())
|
||||
.map { it.toGetCalculateContentResponse() }
|
||||
}
|
||||
|
||||
return createExcelStream(
|
||||
sheetName = "콘텐츠 정산",
|
||||
@@ -235,9 +263,14 @@ class AdminCalculateService(private val repository: AdminCalculateQueryRepositor
|
||||
@Transactional(readOnly = true)
|
||||
fun downloadCalculateContentDonationListExcel(startDateStr: String, endDateStr: String): StreamingResponseBody {
|
||||
val (startDate, endDate) = toDateRange(startDateStr, endDateStr)
|
||||
val items = repository
|
||||
.getCalculateContentDonationList(startDate, endDate)
|
||||
val totalCount = repository.getCalculateContentDonationListTotalCount(startDate, endDate)
|
||||
val items = if (totalCount == 0) {
|
||||
emptyList()
|
||||
} else {
|
||||
repository
|
||||
.getCalculateContentDonationList(startDate, endDate, 0L, totalCount.toLong())
|
||||
.map { it.toGetCalculateContentDonationResponse() }
|
||||
}
|
||||
|
||||
return createExcelStream(
|
||||
sheetName = "콘텐츠 후원 정산",
|
||||
|
||||
Reference in New Issue
Block a user