fix(admin/charge): 통화별 리스트와 합계 행 추가 및 전체 합계 로직 수정

- 기존 로직은 통화 구분 없이 전체 합계를 계산·표시하여 통화가 혼재된 데이터에서 오해의 소지가 있었음.
- 관리 화면 요구사항: 통화(currency)별 합계를 명확히 제공.
This commit is contained in:
2025-10-11 02:31:15 +09:00
parent c497f321bb
commit 38c50a4f8a
4 changed files with 27 additions and 18 deletions

View File

@@ -26,6 +26,7 @@ class AdminChargeStatusQueryRepository(private val queryFactory: JPAQueryFactory
),
"%Y-%m-%d"
)
val currency = Expressions.stringTemplate("RIGHT({0}, 3)", payment.locale)
return queryFactory
.select(
@@ -33,7 +34,8 @@ class AdminChargeStatusQueryRepository(private val queryFactory: JPAQueryFactory
formattedDate,
payment.price.sum(),
payment.id.count(),
payment.paymentGateway
payment.paymentGateway,
currency
)
)
.from(payment)
@@ -45,7 +47,7 @@ class AdminChargeStatusQueryRepository(private val queryFactory: JPAQueryFactory
.and(charge.status.eq(ChargeStatus.CHARGE))
.and(payment.status.eq(PaymentStatus.COMPLETE))
)
.groupBy(formattedDate, payment.paymentGateway)
.groupBy(formattedDate, payment.paymentGateway, currency)
.orderBy(formattedDate.desc())
.fetch()
}

View File

@@ -20,35 +20,40 @@ class AdminChargeStatusService(val repository: AdminChargeStatusQueryRepository)
.withZoneSameInstant(ZoneId.of("UTC"))
.toLocalDateTime()
var totalChargeAmount = 0.toBigDecimal()
var totalChargeCount = 0L
val totalsByCurrency = mutableMapOf<String, Pair<java.math.BigDecimal, Long>>()
val chargeStatusList = repository.getChargeStatus(startDate, endDate)
.map {
val chargeAmount = it.amount
val chargeCount = it.chargeCount
val currency = it.currency
totalChargeAmount += chargeAmount
totalChargeCount += chargeCount
val prev = totalsByCurrency[currency] ?: (0.toBigDecimal() to 0L)
totalsByCurrency[currency] = (prev.first + chargeAmount) to (prev.second + chargeCount)
GetChargeStatusResponse(
date = it.date,
chargeAmount = chargeAmount,
chargeCount = chargeCount,
pg = it.paymentGateWay.name
pg = it.paymentGateWay.name,
currency = currency
)
}
.toMutableList()
chargeStatusList.add(
0,
GetChargeStatusResponse(
date = "합계",
chargeAmount = totalChargeAmount,
chargeCount = totalChargeCount,
pg = ""
)
)
val summaryRows = totalsByCurrency.entries
.sortedBy { it.key }
.map { (currency, total) ->
GetChargeStatusResponse(
date = "합계",
chargeAmount = total.first,
chargeCount = total.second,
pg = "",
currency = currency
)
}
chargeStatusList.addAll(0, summaryRows)
return chargeStatusList.toList()
}

View File

@@ -8,5 +8,6 @@ data class GetChargeStatusQueryDto @QueryProjection constructor(
val date: String,
val amount: BigDecimal,
val chargeCount: Long,
val paymentGateWay: PaymentGateway
val paymentGateWay: PaymentGateway,
val currency: String
)

View File

@@ -6,5 +6,6 @@ data class GetChargeStatusResponse(
val date: String,
val chargeAmount: BigDecimal,
val chargeCount: Long,
val pg: String
val pg: String,
val currency: String
)