diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/admin/charge/AdminChargeStatusQueryRepository.kt b/src/main/kotlin/kr/co/vividnext/sodalive/admin/charge/AdminChargeStatusQueryRepository.kt index f1ec63c..6c9519d 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/admin/charge/AdminChargeStatusQueryRepository.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/admin/charge/AdminChargeStatusQueryRepository.kt @@ -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() } diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/admin/charge/AdminChargeStatusService.kt b/src/main/kotlin/kr/co/vividnext/sodalive/admin/charge/AdminChargeStatusService.kt index f1b5e7e..67f4891 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/admin/charge/AdminChargeStatusService.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/admin/charge/AdminChargeStatusService.kt @@ -20,35 +20,40 @@ class AdminChargeStatusService(val repository: AdminChargeStatusQueryRepository) .withZoneSameInstant(ZoneId.of("UTC")) .toLocalDateTime() - var totalChargeAmount = 0.toBigDecimal() - var totalChargeCount = 0L + val totalsByCurrency = mutableMapOf>() 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() } diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/admin/charge/GetChargeStatusQueryDto.kt b/src/main/kotlin/kr/co/vividnext/sodalive/admin/charge/GetChargeStatusQueryDto.kt index 22bdd4c..c173892 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/admin/charge/GetChargeStatusQueryDto.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/admin/charge/GetChargeStatusQueryDto.kt @@ -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 ) diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/admin/charge/GetChargeStatusResponse.kt b/src/main/kotlin/kr/co/vividnext/sodalive/admin/charge/GetChargeStatusResponse.kt index 75dffcb..3d914a9 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/admin/charge/GetChargeStatusResponse.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/admin/charge/GetChargeStatusResponse.kt @@ -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 )