Compare commits

..

4 Commits

8 changed files with 236 additions and 35 deletions

View File

@@ -0,0 +1,20 @@
# 관리자 정산 콘텐츠 크리에이터별 조회 SQL 오류 수정 작업 계획
- [x] `/admin/calculate/content-by-creator` 호출 경로(Controller/Service/Repository)와 SQL 생성 지점을 확인한다.
- [x] `ONLY_FULL_GROUP_BY` 위반 원인(`content_settlement_ratio` 비집계 컬럼)을 제거하는 최소 수정안을 적용한다.
- [x] 수정된 쿼리가 기존 응답 스키마/정산 계산 로직과 호환되는지 코드 레벨로 검증한다.
- [x] `lsp_diagnostics`, 관련 테스트, 빌드를 실행해 정상 동작을 검증한다.
## 검증 기록
### 1차 수정
- 무엇을: `AdminCalculateQueryRepository#getCalculateContentByCreator``groupBy``member.id`에서 `member.id, creatorSettlementRatio.contentSettlementRatio`로 수정해 SELECT의 비집계 컬럼(`contentSettlementRatio`)이 GROUP BY에 포함되도록 변경했다.
- 왜: `/admin/calculate/content-by-creator` 조회 시 `creator_settlement_ratio.content_settlement_ratio`가 SELECT 절에 존재하지만 GROUP BY에 없어 MySQL `ONLY_FULL_GROUP_BY` 모드에서 SQLSyntaxErrorException이 발생했기 때문이다.
- 어떻게:
- 경로/원인 확인: `AdminCalculateController#getCalculateContentByCreator` -> `AdminCalculateService#getCalculateContentByCreator` -> `AdminCalculateQueryRepository#getCalculateContentByCreator` 호출 체인을 확인했다.
- 코드 수정: `src/main/kotlin/kr/co/vividnext/sodalive/admin/calculate/AdminCalculateQueryRepository.kt`의 콘텐츠 크리에이터별 조회 쿼리 `groupBy`를 보완했다.
- 검증 실행 결과:
- `lsp_diagnostics` (`AdminCalculateQueryRepository.kt`) -> Kotlin LSP 미설정으로 진단 불가
- `./gradlew test` -> 성공
- `./gradlew build -x test` -> 성공
- `./gradlew tasks --all` -> 성공

View File

@@ -0,0 +1,14 @@
- [x] 페이징 미적용 관리자 정산 API 식별
- [x] Controller에 Pageable 파라미터 추가 및 Service 호출에 offset/limit 전달
- [x] Service/Repository 쿼리에 offset/limit 반영
- [x] 정적 진단 및 테스트/빌드 검증
## 검증 기록
### 1차 구현
- 무엇을: 관리자 정산 API 중 페이징이 없던 `/admin/calculate/live`, `/admin/calculate/content-list`, `/admin/calculate/content-donation-list``Pageable` 기반 페이징을 추가하고, 응답을 `totalCount + items` 구조로 변경했다. 또한 동일 쿼리를 사용하는 엑셀 다운로드 로직이 기존과 동일하게 전체 데이터를 내려주도록 totalCount 기반 전체 조회 방식으로 맞췄다.
- 왜: 조회 건수가 많아질 수 있는 정산 목록 API에서 페이지 단위 조회를 지원해 응답 크기와 조회 성능을 안정적으로 관리하기 위해서다.
- 어떻게:
- 정적 진단: `lsp_diagnostics`로 Kotlin 파일 진단을 시도했으나, 실행 환경에 Kotlin LSP가 설정되어 있지 않아 수행 불가(도구 에러 확인).
- 테스트: `./gradlew test` 실행, `BUILD SUCCESSFUL` 확인.
- 빌드: `./gradlew build -x test` 실행, `BUILD SUCCESSFUL` 확인.

View File

@@ -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(

View File

@@ -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()
}
@@ -361,7 +453,7 @@ class AdminCalculateQueryRepository(private val queryFactory: JPAQueryFactory) {
.and(order.createdAt.loe(endDate))
.and(order.isActive.isTrue)
)
.groupBy(member.id)
.groupBy(member.id, creatorSettlementRatio.contentSettlementRatio)
.orderBy(member.id.desc())
.offset(offset)
.limit(limit)

View File

@@ -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)
.map { it.toGetCalculateLiveResponse() }
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)
.map { it.toGetCalculateContentResponse() }
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)
.map { it.toGetCalculateContentDonationResponse() }
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 = "콘텐츠 후원 정산",

View File

@@ -0,0 +1,6 @@
package kr.co.vividnext.sodalive.admin.calculate
data class GetCalculateContentDonationListResponse(
val totalCount: Int,
val items: List<GetCalculateContentDonationResponse>
)

View File

@@ -0,0 +1,6 @@
package kr.co.vividnext.sodalive.admin.calculate
data class GetCalculateContentListResponse(
val totalCount: Int,
val items: List<GetCalculateContentResponse>
)

View File

@@ -0,0 +1,6 @@
package kr.co.vividnext.sodalive.admin.calculate
data class GetCalculateLiveListResponse(
val totalCount: Int,
val items: List<GetCalculateLiveResponse>
)