test #348
@@ -26,6 +26,7 @@ class AdminChargeStatusQueryRepository(private val queryFactory: JPAQueryFactory
|
|||||||
),
|
),
|
||||||
"%Y-%m-%d"
|
"%Y-%m-%d"
|
||||||
)
|
)
|
||||||
|
val currency = Expressions.stringTemplate("RIGHT({0}, 3)", payment.locale)
|
||||||
|
|
||||||
return queryFactory
|
return queryFactory
|
||||||
.select(
|
.select(
|
||||||
@@ -33,7 +34,8 @@ class AdminChargeStatusQueryRepository(private val queryFactory: JPAQueryFactory
|
|||||||
formattedDate,
|
formattedDate,
|
||||||
payment.price.sum(),
|
payment.price.sum(),
|
||||||
payment.id.count(),
|
payment.id.count(),
|
||||||
payment.paymentGateway
|
payment.paymentGateway,
|
||||||
|
currency
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.from(payment)
|
.from(payment)
|
||||||
@@ -45,7 +47,7 @@ class AdminChargeStatusQueryRepository(private val queryFactory: JPAQueryFactory
|
|||||||
.and(charge.status.eq(ChargeStatus.CHARGE))
|
.and(charge.status.eq(ChargeStatus.CHARGE))
|
||||||
.and(payment.status.eq(PaymentStatus.COMPLETE))
|
.and(payment.status.eq(PaymentStatus.COMPLETE))
|
||||||
)
|
)
|
||||||
.groupBy(formattedDate, payment.paymentGateway)
|
.groupBy(formattedDate, payment.paymentGateway, currency)
|
||||||
.orderBy(formattedDate.desc())
|
.orderBy(formattedDate.desc())
|
||||||
.fetch()
|
.fetch()
|
||||||
}
|
}
|
||||||
|
@@ -20,35 +20,40 @@ class AdminChargeStatusService(val repository: AdminChargeStatusQueryRepository)
|
|||||||
.withZoneSameInstant(ZoneId.of("UTC"))
|
.withZoneSameInstant(ZoneId.of("UTC"))
|
||||||
.toLocalDateTime()
|
.toLocalDateTime()
|
||||||
|
|
||||||
var totalChargeAmount = 0.toBigDecimal()
|
val totalsByCurrency = mutableMapOf<String, Pair<java.math.BigDecimal, Long>>()
|
||||||
var totalChargeCount = 0L
|
|
||||||
|
|
||||||
val chargeStatusList = repository.getChargeStatus(startDate, endDate)
|
val chargeStatusList = repository.getChargeStatus(startDate, endDate)
|
||||||
.map {
|
.map {
|
||||||
val chargeAmount = it.amount
|
val chargeAmount = it.amount
|
||||||
val chargeCount = it.chargeCount
|
val chargeCount = it.chargeCount
|
||||||
|
val currency = it.currency
|
||||||
|
|
||||||
totalChargeAmount += chargeAmount
|
val prev = totalsByCurrency[currency] ?: (0.toBigDecimal() to 0L)
|
||||||
totalChargeCount += chargeCount
|
totalsByCurrency[currency] = (prev.first + chargeAmount) to (prev.second + chargeCount)
|
||||||
|
|
||||||
GetChargeStatusResponse(
|
GetChargeStatusResponse(
|
||||||
date = it.date,
|
date = it.date,
|
||||||
chargeAmount = chargeAmount,
|
chargeAmount = chargeAmount,
|
||||||
chargeCount = chargeCount,
|
chargeCount = chargeCount,
|
||||||
pg = it.paymentGateWay.name
|
pg = it.paymentGateWay.name,
|
||||||
|
currency = currency
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
.toMutableList()
|
.toMutableList()
|
||||||
|
|
||||||
chargeStatusList.add(
|
val summaryRows = totalsByCurrency.entries
|
||||||
0,
|
.sortedBy { it.key }
|
||||||
|
.map { (currency, total) ->
|
||||||
GetChargeStatusResponse(
|
GetChargeStatusResponse(
|
||||||
date = "합계",
|
date = "합계",
|
||||||
chargeAmount = totalChargeAmount,
|
chargeAmount = total.first,
|
||||||
chargeCount = totalChargeCount,
|
chargeCount = total.second,
|
||||||
pg = ""
|
pg = "",
|
||||||
)
|
currency = currency
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
chargeStatusList.addAll(0, summaryRows)
|
||||||
|
|
||||||
return chargeStatusList.toList()
|
return chargeStatusList.toList()
|
||||||
}
|
}
|
||||||
|
@@ -8,5 +8,6 @@ data class GetChargeStatusQueryDto @QueryProjection constructor(
|
|||||||
val date: String,
|
val date: String,
|
||||||
val amount: BigDecimal,
|
val amount: BigDecimal,
|
||||||
val chargeCount: Long,
|
val chargeCount: Long,
|
||||||
val paymentGateWay: PaymentGateway
|
val paymentGateWay: PaymentGateway,
|
||||||
|
val currency: String
|
||||||
)
|
)
|
||||||
|
@@ -6,5 +6,6 @@ data class GetChargeStatusResponse(
|
|||||||
val date: String,
|
val date: String,
|
||||||
val chargeAmount: BigDecimal,
|
val chargeAmount: BigDecimal,
|
||||||
val chargeCount: Long,
|
val chargeCount: Long,
|
||||||
val pg: String
|
val pg: String,
|
||||||
|
val currency: String
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user