From b5f66603bdb5ed813d4900e2b9d51b8b9bdb8f2a Mon Sep 17 00:00:00 2001 From: Klaus Date: Sat, 11 Oct 2025 04:39:15 +0900 Subject: [PATCH 1/4] =?UTF-8?q?refactor(admin-charge):=20QGetChargeStatusQ?= =?UTF-8?q?ueryDto=EC=9D=98=20currency=EA=B0=80=20null=EC=9D=B4=20?= =?UTF-8?q?=EB=90=98=EC=A7=80=20=EC=95=8A=EB=8F=84=EB=A1=9D=20coalesce("")?= =?UTF-8?q?=20=EC=82=AC=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sodalive/admin/charge/AdminChargeStatusQueryRepository.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 e3809e9..8a62836 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 @@ -36,7 +36,7 @@ class AdminChargeStatusQueryRepository(private val queryFactory: JPAQueryFactory payment.price.sum(), payment.id.count(), payment.paymentGateway, - currency + currency.coalesce("") ) ) .from(payment) From 3d29d2744188d202c076c10fd0e563afd8115f4d Mon Sep 17 00:00:00 2001 From: Klaus Date: Sat, 11 Oct 2025 04:52:58 +0900 Subject: [PATCH 2/4] =?UTF-8?q?refactor(admin-charge):=20QGetChargeStatusQ?= =?UTF-8?q?ueryDto=EC=9D=98=20currency=EA=B0=80=20null=EC=9D=B4=20?= =?UTF-8?q?=EB=90=98=EC=A7=80=20=EC=95=8A=EB=8F=84=EB=A1=9D=20coalesce("")?= =?UTF-8?q?=20=EC=82=AC=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sodalive/admin/charge/AdminChargeStatusQueryRepository.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 8a62836..84bd08e 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 @@ -48,7 +48,7 @@ class AdminChargeStatusQueryRepository(private val queryFactory: JPAQueryFactory .and(charge.status.eq(ChargeStatus.CHARGE)) .and(payment.status.eq(PaymentStatus.COMPLETE)) ) - .groupBy(formattedDate, payment.paymentGateway, currency) + .groupBy(formattedDate, payment.paymentGateway, currency.coalesce("")) .orderBy(formattedDate.desc()) .fetch() } From db0d3a6ef3142ef6758c58cbd1890a5c97d19ed5 Mon Sep 17 00:00:00 2001 From: Klaus Date: Sat, 11 Oct 2025 05:07:21 +0900 Subject: [PATCH 3/4] =?UTF-8?q?refactor(admin-charge):=20QGetChargeStatusQ?= =?UTF-8?q?ueryDto=EC=9D=98=20currency=EA=B0=80=20null=EC=9D=B4=EB=A9=B4?= =?UTF-8?q?=20KRW=EB=A1=9C=20=EC=84=A4=EC=A0=95=EB=90=98=EB=8F=84=EB=A1=9D?= =?UTF-8?q?=20coalesce("KRW")=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sodalive/admin/charge/AdminChargeStatusQueryRepository.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 84bd08e..2ba3e14 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 @@ -36,7 +36,7 @@ class AdminChargeStatusQueryRepository(private val queryFactory: JPAQueryFactory payment.price.sum(), payment.id.count(), payment.paymentGateway, - currency.coalesce("") + currency.coalesce("KRW") ) ) .from(payment) @@ -48,7 +48,7 @@ class AdminChargeStatusQueryRepository(private val queryFactory: JPAQueryFactory .and(charge.status.eq(ChargeStatus.CHARGE)) .and(payment.status.eq(PaymentStatus.COMPLETE)) ) - .groupBy(formattedDate, payment.paymentGateway, currency.coalesce("")) + .groupBy(formattedDate, payment.paymentGateway, currency.coalesce("KRW")) .orderBy(formattedDate.desc()) .fetch() } From 88c3a849729ffc76a804e572d9bf324783563b90 Mon Sep 17 00:00:00 2001 From: Klaus Date: Sat, 11 Oct 2025 05:41:14 +0900 Subject: [PATCH 4/4] =?UTF-8?q?perf(admin-charge):=20=ED=86=B5=ED=99=94?= =?UTF-8?q?=EB=B3=84=20=ED=95=A9=EA=B3=84=EB=A5=BC=20DB=20=EA=B7=B8?= =?UTF-8?q?=EB=A3=B9=20=EC=A7=91=EA=B3=84=EB=A1=9C=20=EC=9D=B4=EA=B4=80?= =?UTF-8?q?=ED=95=98=EC=97=AC=20=EC=A0=84=EC=86=A1=EB=9F=89/CPU=20?= =?UTF-8?q?=EA=B0=90=EC=86=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AdminChargeStatusQueryRepository.kt | 43 ++++++++++++++++--- .../admin/charge/AdminChargeStatusService.kt | 35 +-------------- .../admin/charge/GetChargeStatusQueryDto.kt | 13 ------ .../admin/charge/GetChargeStatusResponse.kt | 3 +- 4 files changed, 42 insertions(+), 52 deletions(-) delete mode 100644 src/main/kotlin/kr/co/vividnext/sodalive/admin/charge/GetChargeStatusQueryDto.kt 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 2ba3e14..df5d897 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 @@ -15,7 +15,7 @@ import java.time.LocalDateTime @Repository class AdminChargeStatusQueryRepository(private val queryFactory: JPAQueryFactory) { - fun getChargeStatus(startDate: LocalDateTime, endDate: LocalDateTime): List { + fun getChargeStatus(startDate: LocalDateTime, endDate: LocalDateTime): List { val formattedDate = Expressions.stringTemplate( "DATE_FORMAT({0}, {1})", Expressions.dateTimeTemplate( @@ -31,11 +31,11 @@ class AdminChargeStatusQueryRepository(private val queryFactory: JPAQueryFactory return queryFactory .select( - QGetChargeStatusQueryDto( + QGetChargeStatusResponse( formattedDate, payment.price.sum(), payment.id.count(), - payment.paymentGateway, + payment.paymentGateway.stringValue(), currency.coalesce("KRW") ) ) @@ -53,6 +53,36 @@ class AdminChargeStatusQueryRepository(private val queryFactory: JPAQueryFactory .fetch() } + fun getChargeStatusSummary(startDate: LocalDateTime, endDate: LocalDateTime): List { + 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( startDate: LocalDateTime, endDate: LocalDateTime, @@ -70,7 +100,10 @@ class AdminChargeStatusQueryRepository(private val queryFactory: JPAQueryFactory ), "%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() whereBuilder.and(charge.createdAt.goe(startDate)) .and(charge.createdAt.loe(endDate)) @@ -89,7 +122,7 @@ class AdminChargeStatusQueryRepository(private val queryFactory: JPAQueryFactory member.nickname, payment.method.coalesce(""), payment.price, - currencyExpr.coalesce(""), + currencyExpr, formattedDate ) ) 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 ceead40..18bf00d 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,39 +20,8 @@ class AdminChargeStatusService(val repository: AdminChargeStatusQueryRepository) .withZoneSameInstant(ZoneId.of("UTC")) .toLocalDateTime() - val totalsByCurrency = mutableMapOf>() - - 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 - ) - } - + val summaryRows = repository.getChargeStatusSummary(startDate, endDate) + val chargeStatusList = repository.getChargeStatus(startDate, endDate).toMutableList() 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 deleted file mode 100644 index c173892..0000000 --- a/src/main/kotlin/kr/co/vividnext/sodalive/admin/charge/GetChargeStatusQueryDto.kt +++ /dev/null @@ -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 -) 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 3d914a9..c7bcb0a 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 @@ -1,8 +1,9 @@ package kr.co.vividnext.sodalive.admin.charge +import com.querydsl.core.annotations.QueryProjection import java.math.BigDecimal -data class GetChargeStatusResponse( +data class GetChargeStatusResponse @QueryProjection constructor( val date: String, val chargeAmount: BigDecimal, val chargeCount: Long,