feat(channel-donation-calculate): 채널 후원 정산 응답에 기간 합계를 추가한다

This commit is contained in:
2026-02-26 19:44:37 +09:00
parent 19d3544c72
commit e6ecf8aca1
17 changed files with 213 additions and 2 deletions

View File

@@ -16,6 +16,29 @@ import java.time.LocalDateTime
class AdminChannelDonationCalculateQueryRepository(
private val queryFactory: JPAQueryFactory
) {
fun getChannelDonationByCreatorTotal(
startDate: LocalDateTime,
endDate: LocalDateTime
): GetAdminChannelDonationSettlementTotalQueryData {
return queryFactory
.select(
QGetAdminChannelDonationSettlementTotalQueryData(
useCan.id.countDistinct(),
useCanCalculate.can.sum()
)
)
.from(useCanCalculate)
.innerJoin(useCanCalculate.useCan, useCan)
.innerJoin(member)
.on(member.id.eq(useCanCalculate.recipientCreatorId))
.where(baseWhereCondition(startDate, endDate))
.fetchOne()
?: GetAdminChannelDonationSettlementTotalQueryData(
count = 0L,
totalCan = 0
)
}
fun getChannelDonationByCreatorTotalCount(startDate: LocalDateTime, endDate: LocalDateTime): Int {
val formattedDate = getFormattedDate(useCan.createdAt)
val distinctGroupKey = Expressions.stringTemplate(

View File

@@ -18,11 +18,12 @@ class AdminChannelDonationCalculateService(
val startDate = startDateStr.convertLocalDateTime()
val endDate = endDateStr.convertLocalDateTime(hour = 23, minute = 59, second = 59)
val total = repository.getChannelDonationByCreatorTotal(startDate, endDate).toResponseTotal()
val totalCount = repository.getChannelDonationByCreatorTotalCount(startDate, endDate)
val items = repository
.getChannelDonationByCreator(startDate, endDate, offset, limit)
.map { it.toResponseItem() }
return GetAdminChannelDonationSettlementResponse(totalCount, items)
return GetAdminChannelDonationSettlementResponse(totalCount, total, items)
}
}

View File

@@ -2,5 +2,6 @@ package kr.co.vividnext.sodalive.admin.calculate.channelDonation
data class GetAdminChannelDonationSettlementResponse(
val totalCount: Int,
val total: GetAdminChannelDonationSettlementTotal,
val items: List<GetAdminChannelDonationSettlementItem>
)

View File

@@ -0,0 +1,13 @@
package kr.co.vividnext.sodalive.admin.calculate.channelDonation
import com.fasterxml.jackson.annotation.JsonProperty
data class GetAdminChannelDonationSettlementTotal(
@JsonProperty("count") val count: Int,
@JsonProperty("totalCan") val totalCan: Int,
@JsonProperty("krw") val krw: Int,
@JsonProperty("fee") val fee: Int,
@JsonProperty("settlementAmount") val settlementAmount: Int,
@JsonProperty("withholdingTax") val withholdingTax: Int,
@JsonProperty("depositAmount") val depositAmount: Int
)

View File

@@ -0,0 +1,24 @@
package kr.co.vividnext.sodalive.admin.calculate.channelDonation
import com.querydsl.core.annotations.QueryProjection
import kr.co.vividnext.sodalive.calculate.channelDonation.ChannelDonationSettlementCalculator
data class GetAdminChannelDonationSettlementTotalQueryData @QueryProjection constructor(
val count: Long?,
val totalCan: Int?
) {
fun toResponseTotal(): GetAdminChannelDonationSettlementTotal {
val totalCan = totalCan ?: 0
val settlement = ChannelDonationSettlementCalculator.calculate(totalCan)
return GetAdminChannelDonationSettlementTotal(
count = (count ?: 0L).toInt(),
totalCan = totalCan,
krw = settlement.krw,
fee = settlement.fee,
settlementAmount = settlement.settlementAmount,
withholdingTax = settlement.withholdingTax,
depositAmount = settlement.depositAmount
)
}
}

View File

@@ -15,6 +15,28 @@ import java.time.LocalDateTime
class CreatorAdminChannelDonationCalculateQueryRepository(
private val queryFactory: JPAQueryFactory
) {
fun getChannelDonationSettlementTotal(
startDate: LocalDateTime,
endDate: LocalDateTime,
memberId: Long
): GetCreatorChannelDonationSettlementTotalQueryData {
return queryFactory
.select(
QGetCreatorChannelDonationSettlementTotalQueryData(
useCan.id.countDistinct(),
useCanCalculate.can.sum()
)
)
.from(useCanCalculate)
.innerJoin(useCanCalculate.useCan, useCan)
.where(baseWhereCondition(startDate, endDate, memberId))
.fetchOne()
?: GetCreatorChannelDonationSettlementTotalQueryData(
count = 0L,
totalCan = 0
)
}
fun getChannelDonationTotalCount(startDate: LocalDateTime, endDate: LocalDateTime, memberId: Long): Int {
val formattedDate = getFormattedDate(useCan.createdAt)

View File

@@ -20,11 +20,12 @@ class CreatorAdminChannelDonationCalculateService(
val startDate = startDateStr.convertLocalDateTime()
val endDate = endDateStr.convertLocalDateTime(hour = 23, minute = 59, second = 59)
val total = repository.getChannelDonationSettlementTotal(startDate, endDate, memberId).toResponseTotal()
val totalCount = repository.getChannelDonationTotalCount(startDate, endDate, memberId)
val items = repository
.getChannelDonation(startDate, endDate, memberId, offset, limit)
.map { it.toResponseItem(creatorNickname) }
return GetCreatorChannelDonationSettlementResponse(totalCount, items)
return GetCreatorChannelDonationSettlementResponse(totalCount, total, items)
}
}

View File

@@ -2,5 +2,6 @@ package kr.co.vividnext.sodalive.creator.admin.calculate.channelDonation
data class GetCreatorChannelDonationSettlementResponse(
val totalCount: Int,
val total: GetCreatorChannelDonationSettlementTotal,
val items: List<GetCreatorChannelDonationSettlementItem>
)

View File

@@ -0,0 +1,13 @@
package kr.co.vividnext.sodalive.creator.admin.calculate.channelDonation
import com.fasterxml.jackson.annotation.JsonProperty
data class GetCreatorChannelDonationSettlementTotal(
@JsonProperty("count") val count: Int,
@JsonProperty("totalCan") val totalCan: Int,
@JsonProperty("krw") val krw: Int,
@JsonProperty("fee") val fee: Int,
@JsonProperty("settlementAmount") val settlementAmount: Int,
@JsonProperty("withholdingTax") val withholdingTax: Int,
@JsonProperty("depositAmount") val depositAmount: Int
)

View File

@@ -0,0 +1,24 @@
package kr.co.vividnext.sodalive.creator.admin.calculate.channelDonation
import com.querydsl.core.annotations.QueryProjection
import kr.co.vividnext.sodalive.calculate.channelDonation.ChannelDonationSettlementCalculator
data class GetCreatorChannelDonationSettlementTotalQueryData @QueryProjection constructor(
val count: Long?,
val totalCan: Int?
) {
fun toResponseTotal(): GetCreatorChannelDonationSettlementTotal {
val totalCan = totalCan ?: 0
val settlement = ChannelDonationSettlementCalculator.calculate(totalCan)
return GetCreatorChannelDonationSettlementTotal(
count = (count ?: 0L).toInt(),
totalCan = totalCan,
krw = settlement.krw,
fee = settlement.fee,
settlementAmount = settlement.settlementAmount,
withholdingTax = settlement.withholdingTax,
depositAmount = settlement.depositAmount
)
}
}