From c4e58890eaf02211f2c7253fbeceb8e857d9d959 Mon Sep 17 00:00:00 2001 From: Klaus Date: Sat, 6 Jul 2024 00:15:40 +0900 Subject: [PATCH] =?UTF-8?q?=ED=81=AC=EB=A6=AC=EC=97=90=EC=9D=B4=ED=84=B0?= =?UTF-8?q?=20=EA=B8=B0=EC=A4=80=20=EB=9D=BC=EC=9D=B4=EB=B8=8C=20=ED=95=A9?= =?UTF-8?q?=EA=B3=84=20=EC=A0=95=EC=82=B0=20API=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../calculate/AdminCalculateController.kt | 14 ++++++ .../AdminCalculateQueryRepository.kt | 40 +++++++++++++++++ .../admin/calculate/AdminCalculateService.kt | 17 +++++++ .../GetCalculateLiveByCreatorItem.kt | 14 ++++++ .../GetCalculateLiveByCreatorQueryData.kt | 44 +++++++++++++++++++ .../GetCalculateLiveByCreatorResponse.kt | 6 +++ 6 files changed, 135 insertions(+) create mode 100644 src/main/kotlin/kr/co/vividnext/sodalive/admin/calculate/GetCalculateLiveByCreatorItem.kt create mode 100644 src/main/kotlin/kr/co/vividnext/sodalive/admin/calculate/GetCalculateLiveByCreatorQueryData.kt create mode 100644 src/main/kotlin/kr/co/vividnext/sodalive/admin/calculate/GetCalculateLiveByCreatorResponse.kt diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/admin/calculate/AdminCalculateController.kt b/src/main/kotlin/kr/co/vividnext/sodalive/admin/calculate/AdminCalculateController.kt index 30dbe37..35bf0a4 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/admin/calculate/AdminCalculateController.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/admin/calculate/AdminCalculateController.kt @@ -48,4 +48,18 @@ class AdminCalculateController(private val service: AdminCalculateService) { pageable.pageSize.toLong() ) ) + + @GetMapping("/live-by-creator") + fun getCalculateLiveByCreator( + @RequestParam startDateStr: String, + @RequestParam endDateStr: String, + pageable: Pageable + ) = ApiResponse.ok( + service.getCalculateLiveByCreator( + startDateStr, + endDateStr, + pageable.offset, + pageable.pageSize.toLong() + ) + ) } diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/admin/calculate/AdminCalculateQueryRepository.kt b/src/main/kotlin/kr/co/vividnext/sodalive/admin/calculate/AdminCalculateQueryRepository.kt index a4d25f3..c8e700c 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/admin/calculate/AdminCalculateQueryRepository.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/admin/calculate/AdminCalculateQueryRepository.kt @@ -224,4 +224,44 @@ class AdminCalculateQueryRepository(private val queryFactory: JPAQueryFactory) { .limit(limit) .fetch() } + + fun getCalculateLiveByCreatorTotalCount(startDate: LocalDateTime, endDate: LocalDateTime): Int { + return queryFactory + .select(member.id) + .from(useCan) + .innerJoin(useCan.room, liveRoom) + .innerJoin(liveRoom.member, member) + .leftJoin(creatorSettlementRatio) + .on(member.id.eq(creatorSettlementRatio.member.id)) + .groupBy(member.id) + .fetch() + .size + } + + fun getCalculateLiveByCreator( + startDate: LocalDateTime, + endDate: LocalDateTime, + offset: Long, + limit: Long + ): List { + return queryFactory + .select( + QGetCalculateLiveByCreatorQueryData( + member.email, + member.nickname, + useCan.can.add(useCan.rewardCan).sum(), + creatorSettlementRatio.liveSettlementRatio + ) + ) + .from(useCan) + .innerJoin(useCan.room, liveRoom) + .innerJoin(liveRoom.member, member) + .leftJoin(creatorSettlementRatio) + .on(member.id.eq(creatorSettlementRatio.member.id)) + .groupBy(member.id) + .orderBy(useCan.can.add(useCan.rewardCan).desc()) + .offset(offset) + .limit(limit) + .fetch() + } } diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/admin/calculate/AdminCalculateService.kt b/src/main/kotlin/kr/co/vividnext/sodalive/admin/calculate/AdminCalculateService.kt index 75b8c50..985cd5a 100644 --- a/src/main/kotlin/kr/co/vividnext/sodalive/admin/calculate/AdminCalculateService.kt +++ b/src/main/kotlin/kr/co/vividnext/sodalive/admin/calculate/AdminCalculateService.kt @@ -88,4 +88,21 @@ class AdminCalculateService(private val repository: AdminCalculateQueryRepositor return GetCreatorCalculateCommunityPostResponse(totalCount, items) } + + fun getCalculateLiveByCreator( + startDateStr: String, + endDateStr: String, + offset: Long, + limit: Long + ) = run { + val startDate = startDateStr.convertLocalDateTime() + val endDate = endDateStr.convertLocalDateTime(hour = 23, minute = 59, second = 59) + + val totalCount = repository.getCalculateLiveByCreatorTotalCount(startDate, endDate) + val items = repository + .getCalculateLiveByCreator(startDate, endDate, offset, limit) + .map { it.toGetCalculateLiveByCreator() } + + GetCalculateLiveByCreatorResponse(totalCount, items) + } } diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/admin/calculate/GetCalculateLiveByCreatorItem.kt b/src/main/kotlin/kr/co/vividnext/sodalive/admin/calculate/GetCalculateLiveByCreatorItem.kt new file mode 100644 index 0000000..4d87621 --- /dev/null +++ b/src/main/kotlin/kr/co/vividnext/sodalive/admin/calculate/GetCalculateLiveByCreatorItem.kt @@ -0,0 +1,14 @@ +package kr.co.vividnext.sodalive.admin.calculate + +import com.fasterxml.jackson.annotation.JsonProperty + +data class GetCalculateLiveByCreatorItem( + @JsonProperty("email") val email: String, + @JsonProperty("nickname") val nickname: String, + @JsonProperty("totalCan") val totalCan: Int, + @JsonProperty("totalKrw") val totalKrw: Int, + @JsonProperty("paymentFee") val paymentFee: Int, + @JsonProperty("settlementAmount") val settlementAmount: Int, + @JsonProperty("tax") val tax: Int, + @JsonProperty("depositAmount") val depositAmount: Int +) diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/admin/calculate/GetCalculateLiveByCreatorQueryData.kt b/src/main/kotlin/kr/co/vividnext/sodalive/admin/calculate/GetCalculateLiveByCreatorQueryData.kt new file mode 100644 index 0000000..5e1bb86 --- /dev/null +++ b/src/main/kotlin/kr/co/vividnext/sodalive/admin/calculate/GetCalculateLiveByCreatorQueryData.kt @@ -0,0 +1,44 @@ +package kr.co.vividnext.sodalive.admin.calculate + +import com.querydsl.core.annotations.QueryProjection +import java.math.BigDecimal +import java.math.RoundingMode + +data class GetCalculateLiveByCreatorQueryData @QueryProjection constructor( + val email: String, + val nickname: String, + val totalCan: Int, + val settlementRatio: Int? +) { + fun toGetCalculateLiveByCreator(): GetCalculateLiveByCreatorItem { + // 원화 = totalCoin * 100 ( 캔 1개 = 100원 ) + val totalKrw = BigDecimal(totalCan).multiply(BigDecimal(100)) + + // 결제수수료 : 6.6% + val paymentFee = totalKrw.multiply(BigDecimal(0.066)) + + // 정산금액 = (원화 - 결제수수료) 의 70% + val settlementAmount = if (settlementRatio != null) { + totalKrw.subtract(paymentFee).multiply(BigDecimal(settlementRatio).divide(BigDecimal(100.0))) + } else { + totalKrw.subtract(paymentFee).multiply(BigDecimal(0.7)) + } + + // 원천세 = 정산금액의 3.3% + val tax = settlementAmount.multiply(BigDecimal(0.033)) + + // 입금액 + val depositAmount = settlementAmount.subtract(tax) + + return GetCalculateLiveByCreatorItem( + email = email, + nickname = nickname, + totalCan = totalCan, + totalKrw = totalKrw.toInt(), + paymentFee = paymentFee.setScale(0, RoundingMode.HALF_UP).toInt(), + settlementAmount = settlementAmount.setScale(0, RoundingMode.HALF_UP).toInt(), + tax = tax.setScale(0, RoundingMode.HALF_UP).toInt(), + depositAmount = depositAmount.setScale(0, RoundingMode.HALF_UP).toInt() + ) + } +} diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/admin/calculate/GetCalculateLiveByCreatorResponse.kt b/src/main/kotlin/kr/co/vividnext/sodalive/admin/calculate/GetCalculateLiveByCreatorResponse.kt new file mode 100644 index 0000000..cd93b59 --- /dev/null +++ b/src/main/kotlin/kr/co/vividnext/sodalive/admin/calculate/GetCalculateLiveByCreatorResponse.kt @@ -0,0 +1,6 @@ +package kr.co.vividnext.sodalive.admin.calculate + +data class GetCalculateLiveByCreatorResponse( + val totalCount: Int, + val items: List +)