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 f956175..2231204 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 @@ -28,4 +28,10 @@ class AdminCalculateController(private val service: AdminCalculateService) { fun getCumulativeSalesByContent(pageable: Pageable) = ApiResponse.ok( service.getCumulativeSalesByContent(pageable.offset, pageable.pageSize.toLong()) ) + + @GetMapping("/content-donation-list") + fun getCalculateContentDonationList( + @RequestParam startDateStr: String, + @RequestParam endDateStr: String + ) = ApiResponse.ok(service.getCalculateContentDonationList(startDateStr, endDateStr)) } 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 c3d178b..6012482 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 @@ -4,6 +4,7 @@ import com.querydsl.core.types.dsl.DateTimePath import com.querydsl.core.types.dsl.Expressions import com.querydsl.core.types.dsl.StringTemplate import com.querydsl.jpa.impl.JPAQueryFactory +import kr.co.vividnext.sodalive.can.use.CanUsage import kr.co.vividnext.sodalive.can.use.QUseCan.useCan import kr.co.vividnext.sodalive.can.use.QUseCanCalculate.useCanCalculate import kr.co.vividnext.sodalive.can.use.UseCanCalculateStatus @@ -123,4 +124,36 @@ class AdminCalculateQueryRepository(private val queryFactory: JPAQueryFactory) { .orderBy(member.id.desc(), audioContent.id.desc()) .fetch() } + + fun getCalculateContentDonationList( + startDate: LocalDateTime, + endDate: LocalDateTime + ): List { + val donationFormattedDate = getFormattedDate(useCan.createdAt) + return queryFactory + .select( + QGetCalculateContentDonationQueryData( + member.nickname, + audioContent.title, + getFormattedDate(audioContent.createdAt), + donationFormattedDate, + useCan.id.count(), + useCan.can.add(useCan.rewardCan).sum() + ) + ) + .from(useCanCalculate) + .innerJoin(useCanCalculate.useCan, useCan) + .innerJoin(useCan.audioContent, audioContent) + .innerJoin(audioContent.member, member) + .where( + useCanCalculate.status.eq(UseCanCalculateStatus.RECEIVED) + .and(useCan.isRefund.isFalse) + .and(useCan.canUsage.eq(CanUsage.DONATION)) + .and(useCan.createdAt.goe(startDate)) + .and(useCan.createdAt.loe(endDate)) + ) + .groupBy(donationFormattedDate, audioContent.id) + .orderBy(donationFormattedDate.desc()) + .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 5f859b6..593d877 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 @@ -191,4 +191,60 @@ class AdminCalculateService(private val repository: AdminCalculateQueryRepositor return GetCumulativeSalesByContentResponse(totalCount, items) } + + @Transactional(readOnly = true) + @Cacheable( + cacheNames = ["cache_ttl_3_hours"], + key = "'calculateContentDonationList:' + " + "#startDateStr + ':' + #endDateStr" + ) + fun getCalculateContentDonationList( + startDateStr: String, + endDateStr: String + ): List { + val dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd") + val startDate = LocalDate.parse(startDateStr, dateTimeFormatter).atTime(0, 0, 0) + .atZone(ZoneId.of("Asia/Seoul")) + .withZoneSameInstant(ZoneId.of("UTC")) + .toLocalDateTime() + + val endDate = LocalDate.parse(endDateStr, dateTimeFormatter).atTime(23, 59, 59) + .atZone(ZoneId.of("Asia/Seoul")) + .withZoneSameInstant(ZoneId.of("UTC")) + .toLocalDateTime() + + return repository + .getCalculateContentDonationList(startDate, endDate) + .asSequence() + .map { + // 원화 = totalCoin * 100 ( 캔 1개 = 100원 ) + val totalKrw = it.totalCan * 100 + + // 결제수수료 : 6.6% + val paymentFee = totalKrw * 0.066f + + // 정산금액 = (원화 - 결제수수료) 의 70% + val settlementAmount = (totalKrw.toFloat() - paymentFee) * 0.7 + + // 원천세 = 정산금액의 3.3% + val tax = settlementAmount * 0.033 + + // 입금액 + val depositAmount = settlementAmount - tax + + GetCalculateContentDonationResponse( + nickname = it.nickname, + title = it.title, + registrationDate = it.registrationDate, + donationDate = it.donationDate, + numberOfDonation = it.numberOfDonation.toInt(), + totalCan = it.totalCan, + totalKrw = totalKrw, + paymentFee = paymentFee.roundToInt(), + settlementAmount = settlementAmount.roundToInt(), + tax = tax.roundToInt(), + depositAmount = depositAmount.roundToInt() + ) + } + .toList() + } } diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/admin/calculate/GetCalculateContentDonationQueryData.kt b/src/main/kotlin/kr/co/vividnext/sodalive/admin/calculate/GetCalculateContentDonationQueryData.kt new file mode 100644 index 0000000..0dc5168 --- /dev/null +++ b/src/main/kotlin/kr/co/vividnext/sodalive/admin/calculate/GetCalculateContentDonationQueryData.kt @@ -0,0 +1,18 @@ +package kr.co.vividnext.sodalive.admin.calculate + +import com.querydsl.core.annotations.QueryProjection + +data class GetCalculateContentDonationQueryData @QueryProjection constructor( + // 등록 크리에이터 닉네임 + val nickname: String, + // 콘텐츠 제목 + val title: String, + // 콘텐츠 등록 날짜 + val registrationDate: String, + // 후원 날짜 + val donationDate: String, + // 인원 + val numberOfDonation: Long, + // 합계 + val totalCan: Int +) diff --git a/src/main/kotlin/kr/co/vividnext/sodalive/admin/calculate/GetCalculateContentDonationResponse.kt b/src/main/kotlin/kr/co/vividnext/sodalive/admin/calculate/GetCalculateContentDonationResponse.kt new file mode 100644 index 0000000..a74b753 --- /dev/null +++ b/src/main/kotlin/kr/co/vividnext/sodalive/admin/calculate/GetCalculateContentDonationResponse.kt @@ -0,0 +1,17 @@ +package kr.co.vividnext.sodalive.admin.calculate + +import com.fasterxml.jackson.annotation.JsonProperty + +data class GetCalculateContentDonationResponse( + @JsonProperty("nickname") val nickname: String, + @JsonProperty("title") val title: String, + @JsonProperty("registrationDate") val registrationDate: String, + @JsonProperty("donationDate") val donationDate: String, + @JsonProperty("numberOfDonation") val numberOfDonation: Int, + @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 +)