test #349
@@ -15,7 +15,7 @@ import java.time.LocalDateTime
|
|||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
class AdminChargeStatusQueryRepository(private val queryFactory: JPAQueryFactory) {
|
class AdminChargeStatusQueryRepository(private val queryFactory: JPAQueryFactory) {
|
||||||
fun getChargeStatus(startDate: LocalDateTime, endDate: LocalDateTime): List<GetChargeStatusQueryDto> {
|
fun getChargeStatus(startDate: LocalDateTime, endDate: LocalDateTime): List<GetChargeStatusResponse> {
|
||||||
val formattedDate = Expressions.stringTemplate(
|
val formattedDate = Expressions.stringTemplate(
|
||||||
"DATE_FORMAT({0}, {1})",
|
"DATE_FORMAT({0}, {1})",
|
||||||
Expressions.dateTimeTemplate(
|
Expressions.dateTimeTemplate(
|
||||||
@@ -31,11 +31,11 @@ class AdminChargeStatusQueryRepository(private val queryFactory: JPAQueryFactory
|
|||||||
|
|
||||||
return queryFactory
|
return queryFactory
|
||||||
.select(
|
.select(
|
||||||
QGetChargeStatusQueryDto(
|
QGetChargeStatusResponse(
|
||||||
formattedDate,
|
formattedDate,
|
||||||
payment.price.sum(),
|
payment.price.sum(),
|
||||||
payment.id.count(),
|
payment.id.count(),
|
||||||
payment.paymentGateway,
|
payment.paymentGateway.stringValue(),
|
||||||
currency.coalesce("KRW")
|
currency.coalesce("KRW")
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -53,6 +53,36 @@ class AdminChargeStatusQueryRepository(private val queryFactory: JPAQueryFactory
|
|||||||
.fetch()
|
.fetch()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getChargeStatusSummary(startDate: LocalDateTime, endDate: LocalDateTime): List<GetChargeStatusResponse> {
|
||||||
|
val currency = Expressions.stringTemplate(
|
||||||
|
"substring({0}, length({0}) - 2, 3)",
|
||||||
|
payment.locale
|
||||||
|
).coalesce("KRW")
|
||||||
|
|
||||||
|
return queryFactory
|
||||||
|
.select(
|
||||||
|
QGetChargeStatusResponse(
|
||||||
|
Expressions.stringTemplate("'합계'"), // date
|
||||||
|
payment.price.sum(),
|
||||||
|
payment.id.count(),
|
||||||
|
Expressions.stringTemplate("''"),
|
||||||
|
currency
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.from(payment)
|
||||||
|
.innerJoin(payment.charge, charge)
|
||||||
|
.leftJoin(charge.can, can1)
|
||||||
|
.where(
|
||||||
|
charge.createdAt.goe(startDate)
|
||||||
|
.and(charge.createdAt.loe(endDate))
|
||||||
|
.and(charge.status.eq(ChargeStatus.CHARGE))
|
||||||
|
.and(payment.status.eq(PaymentStatus.COMPLETE))
|
||||||
|
)
|
||||||
|
.groupBy(currency)
|
||||||
|
.orderBy(currency.asc())
|
||||||
|
.fetch()
|
||||||
|
}
|
||||||
|
|
||||||
fun getChargeStatusDetail(
|
fun getChargeStatusDetail(
|
||||||
startDate: LocalDateTime,
|
startDate: LocalDateTime,
|
||||||
endDate: LocalDateTime,
|
endDate: LocalDateTime,
|
||||||
@@ -70,7 +100,10 @@ class AdminChargeStatusQueryRepository(private val queryFactory: JPAQueryFactory
|
|||||||
),
|
),
|
||||||
"%Y-%m-%d %H:%i:%s"
|
"%Y-%m-%d %H:%i:%s"
|
||||||
)
|
)
|
||||||
val currencyExpr = Expressions.stringTemplate("substring({0}, length({0}) - 2, 3)", payment.locale)
|
val currencyExpr = Expressions.stringTemplate(
|
||||||
|
"substring({0}, length({0}) - 2, 3)",
|
||||||
|
payment.locale
|
||||||
|
).coalesce("KRW")
|
||||||
val whereBuilder = BooleanBuilder()
|
val whereBuilder = BooleanBuilder()
|
||||||
whereBuilder.and(charge.createdAt.goe(startDate))
|
whereBuilder.and(charge.createdAt.goe(startDate))
|
||||||
.and(charge.createdAt.loe(endDate))
|
.and(charge.createdAt.loe(endDate))
|
||||||
@@ -89,7 +122,7 @@ class AdminChargeStatusQueryRepository(private val queryFactory: JPAQueryFactory
|
|||||||
member.nickname,
|
member.nickname,
|
||||||
payment.method.coalesce(""),
|
payment.method.coalesce(""),
|
||||||
payment.price,
|
payment.price,
|
||||||
currencyExpr.coalesce(""),
|
currencyExpr,
|
||||||
formattedDate
|
formattedDate
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@@ -20,39 +20,8 @@ class AdminChargeStatusService(val repository: AdminChargeStatusQueryRepository)
|
|||||||
.withZoneSameInstant(ZoneId.of("UTC"))
|
.withZoneSameInstant(ZoneId.of("UTC"))
|
||||||
.toLocalDateTime()
|
.toLocalDateTime()
|
||||||
|
|
||||||
val totalsByCurrency = mutableMapOf<String, Pair<java.math.BigDecimal, Long>>()
|
val summaryRows = repository.getChargeStatusSummary(startDate, endDate)
|
||||||
|
val chargeStatusList = repository.getChargeStatus(startDate, endDate).toMutableList()
|
||||||
val chargeStatusList = repository.getChargeStatus(startDate, endDate)
|
|
||||||
.map {
|
|
||||||
val chargeAmount = it.amount
|
|
||||||
val chargeCount = it.chargeCount
|
|
||||||
val currency = it.currency
|
|
||||||
|
|
||||||
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,
|
|
||||||
currency = currency
|
|
||||||
)
|
|
||||||
}
|
|
||||||
.toMutableList()
|
|
||||||
|
|
||||||
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)
|
chargeStatusList.addAll(0, summaryRows)
|
||||||
|
|
||||||
return chargeStatusList.toList()
|
return chargeStatusList.toList()
|
||||||
|
@@ -1,13 +0,0 @@
|
|||||||
package kr.co.vividnext.sodalive.admin.charge
|
|
||||||
|
|
||||||
import com.querydsl.core.annotations.QueryProjection
|
|
||||||
import kr.co.vividnext.sodalive.can.payment.PaymentGateway
|
|
||||||
import java.math.BigDecimal
|
|
||||||
|
|
||||||
data class GetChargeStatusQueryDto @QueryProjection constructor(
|
|
||||||
val date: String,
|
|
||||||
val amount: BigDecimal,
|
|
||||||
val chargeCount: Long,
|
|
||||||
val paymentGateWay: PaymentGateway,
|
|
||||||
val currency: String
|
|
||||||
)
|
|
@@ -1,8 +1,9 @@
|
|||||||
package kr.co.vividnext.sodalive.admin.charge
|
package kr.co.vividnext.sodalive.admin.charge
|
||||||
|
|
||||||
|
import com.querydsl.core.annotations.QueryProjection
|
||||||
import java.math.BigDecimal
|
import java.math.BigDecimal
|
||||||
|
|
||||||
data class GetChargeStatusResponse(
|
data class GetChargeStatusResponse @QueryProjection constructor(
|
||||||
val date: String,
|
val date: String,
|
||||||
val chargeAmount: BigDecimal,
|
val chargeAmount: BigDecimal,
|
||||||
val chargeCount: Long,
|
val chargeCount: Long,
|
||||||
|
Reference in New Issue
Block a user