관리자, 크리에이터 관리자
- 정산 리스트 결과값 리팩토링
This commit is contained in:
		| @@ -1,15 +1,9 @@ | ||||
| package kr.co.vividnext.sodalive.admin.calculate | ||||
|  | ||||
| import kr.co.vividnext.sodalive.can.use.CanUsage | ||||
| import kr.co.vividnext.sodalive.content.order.OrderType | ||||
| import kr.co.vividnext.sodalive.extensions.convertLocalDateTime | ||||
| import org.springframework.cache.annotation.Cacheable | ||||
| import org.springframework.stereotype.Service | ||||
| import org.springframework.transaction.annotation.Transactional | ||||
| import java.time.LocalDate | ||||
| import java.time.ZoneId | ||||
| import java.time.format.DateTimeFormatter | ||||
| import kotlin.math.roundToInt | ||||
|  | ||||
| @Service | ||||
| class AdminCalculateService(private val repository: AdminCalculateQueryRepository) { | ||||
| @@ -19,73 +13,12 @@ class AdminCalculateService(private val repository: AdminCalculateQueryRepositor | ||||
|         key = "'calculateLive:' + " + "#startDateStr + ':' + #endDateStr" | ||||
|     ) | ||||
|     fun getCalculateLive(startDateStr: String, endDateStr: String): List<GetCalculateLiveResponse> { | ||||
|         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() | ||||
|         val startDate = startDateStr.convertLocalDateTime() | ||||
|         val endDate = endDateStr.convertLocalDateTime(hour = 23, minute = 59, second = 59) | ||||
|  | ||||
|         return repository | ||||
|             .getCalculateLive(startDate, endDate) | ||||
|             .asSequence() | ||||
|             .map { | ||||
|                 val canUsageStr = when (it.canUsage) { | ||||
|                     CanUsage.LIVE -> { | ||||
|                         "유료" | ||||
|                     } | ||||
|  | ||||
|                     CanUsage.SPIN_ROULETTE -> { | ||||
|                         "룰렛" | ||||
|                     } | ||||
|  | ||||
|                     else -> { | ||||
|                         "후원" | ||||
|                     } | ||||
|                 } | ||||
|  | ||||
|                 val numberOfPeople = if (it.canUsage == CanUsage.LIVE) { | ||||
|                     it.memberCount.toInt() | ||||
|                 } else { | ||||
|                     0 | ||||
|                 } | ||||
|  | ||||
|                 // 원화 = totalCoin * 100 ( 캔 1개 = 100원 ) | ||||
|                 val totalKrw = it.totalAmount * 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 | ||||
|  | ||||
|                 GetCalculateLiveResponse( | ||||
|                     email = it.email, | ||||
|                     nickname = it.nickname, | ||||
|                     date = it.date, | ||||
|                     title = it.title, | ||||
|                     entranceFee = it.entranceFee, | ||||
|                     canUsageStr = canUsageStr, | ||||
|                     numberOfPeople = numberOfPeople, | ||||
|                     totalAmount = it.totalAmount, | ||||
|                     totalKrw = totalKrw, | ||||
|                     paymentFee = paymentFee.roundToInt(), | ||||
|                     settlementAmount = settlementAmount.roundToInt(), | ||||
|                     tax = tax.roundToInt(), | ||||
|                     depositAmount = depositAmount.roundToInt() | ||||
|                 ) | ||||
|             } | ||||
|             .toList() | ||||
|             .map { it.toGetCalculateLiveResponse() } | ||||
|     } | ||||
|  | ||||
|     @Transactional(readOnly = true) | ||||
| @@ -94,59 +27,12 @@ class AdminCalculateService(private val repository: AdminCalculateQueryRepositor | ||||
|         key = "'calculateContent:' + " + "#startDateStr + ':' + #endDateStr" | ||||
|     ) | ||||
|     fun getCalculateContentList(startDateStr: String, endDateStr: String): List<GetCalculateContentResponse> { | ||||
|         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() | ||||
|         val startDate = startDateStr.convertLocalDateTime() | ||||
|         val endDate = endDateStr.convertLocalDateTime(hour = 23, minute = 59, second = 59) | ||||
|  | ||||
|         return repository | ||||
|             .getCalculateContentList(startDate, endDate) | ||||
|             .asSequence() | ||||
|             .map { | ||||
|                 val orderTypeStr = if (it.orderType == OrderType.RENTAL) { | ||||
|                     "대여" | ||||
|                 } else { | ||||
|                     "소장" | ||||
|                 } | ||||
|  | ||||
|                 // 원화 = 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 | ||||
|  | ||||
|                 GetCalculateContentResponse( | ||||
|                     nickname = it.nickname, | ||||
|                     title = it.title, | ||||
|                     registrationDate = it.registrationDate, | ||||
|                     saleDate = it.saleDate, | ||||
|                     orderType = orderTypeStr, | ||||
|                     orderPrice = it.orderPrice, | ||||
|                     numberOfPeople = it.numberOfPeople.toInt(), | ||||
|                     totalCan = it.totalCan, | ||||
|                     totalKrw = totalKrw, | ||||
|                     paymentFee = paymentFee.roundToInt(), | ||||
|                     settlementAmount = settlementAmount.roundToInt(), | ||||
|                     tax = tax.roundToInt(), | ||||
|                     depositAmount = depositAmount.roundToInt() | ||||
|                 ) | ||||
|             } | ||||
|             .toList() | ||||
|             .map { it.toGetCalculateContentResponse() } | ||||
|     } | ||||
|  | ||||
|     @Transactional(readOnly = true) | ||||
| @@ -158,45 +44,7 @@ class AdminCalculateService(private val repository: AdminCalculateQueryRepositor | ||||
|         val totalCount = repository.getCumulativeSalesByContentTotalCount() | ||||
|         val items = repository | ||||
|             .getCumulativeSalesByContent(offset, limit) | ||||
|             .asSequence() | ||||
|             .map { | ||||
|                 val orderTypeStr = if (it.orderType == OrderType.RENTAL) { | ||||
|                     "대여" | ||||
|                 } else { | ||||
|                     "소장" | ||||
|                 } | ||||
|  | ||||
|                 // 원화 = 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 | ||||
|  | ||||
|                 CumulativeSalesByContentItem( | ||||
|                     nickname = it.nickname, | ||||
|                     title = it.title, | ||||
|                     registrationDate = it.registrationDate, | ||||
|                     orderType = orderTypeStr, | ||||
|                     orderPrice = it.orderPrice, | ||||
|                     numberOfPeople = it.numberOfPeople.toInt(), | ||||
|                     totalCan = it.totalCan, | ||||
|                     totalKrw = totalKrw, | ||||
|                     paymentFee = paymentFee.roundToInt(), | ||||
|                     settlementAmount = settlementAmount.roundToInt(), | ||||
|                     tax = tax.roundToInt(), | ||||
|                     depositAmount = depositAmount.roundToInt() | ||||
|                 ) | ||||
|             } | ||||
|             .toList() | ||||
|             .map { it.toCumulativeSalesByContentItem() } | ||||
|  | ||||
|         return GetCumulativeSalesByContentResponse(totalCount, items) | ||||
|     } | ||||
| @@ -210,62 +58,12 @@ class AdminCalculateService(private val repository: AdminCalculateQueryRepositor | ||||
|         startDateStr: String, | ||||
|         endDateStr: String | ||||
|     ): List<GetCalculateContentDonationResponse> { | ||||
|         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() | ||||
|         val startDate = startDateStr.convertLocalDateTime() | ||||
|         val endDate = endDateStr.convertLocalDateTime(hour = 23, minute = 59, second = 59) | ||||
|  | ||||
|         return repository | ||||
|             .getCalculateContentDonationList(startDate, endDate) | ||||
|             .asSequence() | ||||
|             .map { | ||||
|                 // 원화 = totalCoin * 100 ( 캔 1개 = 100원 ) | ||||
|                 val totalKrw = it.totalCan * 100 | ||||
|  | ||||
|                 // 결제수수료 : 6.6% | ||||
|                 val paymentFee = totalKrw * 0.066f | ||||
|  | ||||
|                 // 정산금액 | ||||
|                 // 유료콘텐츠 (원화 - 결제수수료) 의 90% | ||||
|                 // 무료콘텐츠 (원화 - 결제수수료) 의 70% | ||||
|                 val settlementAmount = if (it.price > 0) { | ||||
|                     (totalKrw.toFloat() - paymentFee) * 0.9 | ||||
|                 } else { | ||||
|                     (totalKrw.toFloat() - paymentFee) * 0.7 | ||||
|                 } | ||||
|  | ||||
|                 // 원천세 = 정산금액의 3.3% | ||||
|                 val tax = settlementAmount * 0.033 | ||||
|  | ||||
|                 // 입금액 | ||||
|                 val depositAmount = settlementAmount - tax | ||||
|  | ||||
|                 GetCalculateContentDonationResponse( | ||||
|                     nickname = it.nickname, | ||||
|                     title = it.title, | ||||
|                     paidOrFree = if (it.price > 0) { | ||||
|                         "유료" | ||||
|                     } else { | ||||
|                         "무료" | ||||
|                     }, | ||||
|                     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() | ||||
|             .map { it.toGetCalculateContentDonationResponse() } | ||||
|     } | ||||
|  | ||||
|     fun getCalculateCommunityPost( | ||||
| @@ -279,25 +77,6 @@ class AdminCalculateService(private val repository: AdminCalculateQueryRepositor | ||||
|  | ||||
|         return repository | ||||
|             .getCalculateCommunityPostList(startDate, endDate, offset, limit) | ||||
|             .map { | ||||
|                 val totalKrw = it.totalCan * 100 | ||||
|                 val paymentFee = totalKrw * 0.066f | ||||
|                 val settlementAmount = (totalKrw.toFloat() - paymentFee) * 0.7 | ||||
|                 val tax = settlementAmount * 0.033 | ||||
|                 val depositAmount = settlementAmount - tax | ||||
|  | ||||
|                 GetCalculateCommunityPostResponse( | ||||
|                     nickname = it.nickname, | ||||
|                     title = it.title, | ||||
|                     date = it.date, | ||||
|                     numberOfPurchase = it.numberOfPurchase.toInt(), | ||||
|                     totalCan = it.totalCan, | ||||
|                     totalKrw = totalKrw, | ||||
|                     paymentFee = paymentFee.roundToInt(), | ||||
|                     settlementAmount = settlementAmount.roundToInt(), | ||||
|                     tax = tax.roundToInt(), | ||||
|                     depositAmount = depositAmount.roundToInt() | ||||
|                 ) | ||||
|             } | ||||
|             .map { it.toGetCalculateCommunityPostResponse() } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -1,6 +1,7 @@ | ||||
| package kr.co.vividnext.sodalive.admin.calculate | ||||
|  | ||||
| import com.querydsl.core.annotations.QueryProjection | ||||
| import kotlin.math.roundToInt | ||||
|  | ||||
| data class GetCalculateCommunityPostQueryData @QueryProjection constructor( | ||||
|     val nickname: String, | ||||
| @@ -8,4 +9,25 @@ data class GetCalculateCommunityPostQueryData @QueryProjection constructor( | ||||
|     val date: String, | ||||
|     val numberOfPurchase: Long, | ||||
|     val totalCan: Int | ||||
| ) | ||||
| ) { | ||||
|     fun toGetCalculateCommunityPostResponse(): GetCalculateCommunityPostResponse { | ||||
|         val totalKrw = totalCan * 100 | ||||
|         val paymentFee = totalKrw * 0.066f | ||||
|         val settlementAmount = (totalKrw.toFloat() - paymentFee) * 0.7 | ||||
|         val tax = settlementAmount * 0.033 | ||||
|         val depositAmount = settlementAmount - tax | ||||
|  | ||||
|         return GetCalculateCommunityPostResponse( | ||||
|             nickname = nickname, | ||||
|             title = title, | ||||
|             date = date, | ||||
|             numberOfPurchase = numberOfPurchase.toInt(), | ||||
|             totalCan = totalCan, | ||||
|             totalKrw = totalKrw, | ||||
|             paymentFee = paymentFee.roundToInt(), | ||||
|             settlementAmount = settlementAmount.roundToInt(), | ||||
|             tax = tax.roundToInt(), | ||||
|             depositAmount = depositAmount.roundToInt() | ||||
|         ) | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -1,6 +1,7 @@ | ||||
| package kr.co.vividnext.sodalive.admin.calculate | ||||
|  | ||||
| import com.querydsl.core.annotations.QueryProjection | ||||
| import kotlin.math.roundToInt | ||||
|  | ||||
| data class GetCalculateContentDonationQueryData @QueryProjection constructor( | ||||
|     // 등록 크리에이터 닉네임 | ||||
| @@ -17,4 +18,48 @@ data class GetCalculateContentDonationQueryData @QueryProjection constructor( | ||||
|     val numberOfDonation: Long, | ||||
|     // 합계 | ||||
|     val totalCan: Int | ||||
| ) | ||||
| ) { | ||||
|     fun toGetCalculateContentDonationResponse(): GetCalculateContentDonationResponse { | ||||
|         // 원화 = totalCoin * 100 ( 캔 1개 = 100원 ) | ||||
|         val totalKrw = totalCan * 100 | ||||
|  | ||||
|         // 결제수수료 : 6.6% | ||||
|         val paymentFee = totalKrw * 0.066f | ||||
|  | ||||
|         // 정산금액 | ||||
|         // 유료콘텐츠 (원화 - 결제수수료) 의 90% | ||||
|         // 무료콘텐츠 (원화 - 결제수수료) 의 70% | ||||
|         val settlementAmount = if (price > 0) { | ||||
|             (totalKrw.toFloat() - paymentFee) * 0.9 | ||||
|         } else { | ||||
|             (totalKrw.toFloat() - paymentFee) * 0.7 | ||||
|         } | ||||
|  | ||||
|         // 원천세 = 정산금액의 3.3% | ||||
|         val tax = settlementAmount * 0.033 | ||||
|  | ||||
|         // 입금액 | ||||
|         val depositAmount = settlementAmount - tax | ||||
|  | ||||
|         val paidOrFree = if (price > 0) { | ||||
|             "유료" | ||||
|         } else { | ||||
|             "무료" | ||||
|         } | ||||
|  | ||||
|         return GetCalculateContentDonationResponse( | ||||
|             nickname = nickname, | ||||
|             title = title, | ||||
|             paidOrFree = paidOrFree, | ||||
|             registrationDate = registrationDate, | ||||
|             donationDate = donationDate, | ||||
|             numberOfDonation = numberOfDonation.toInt(), | ||||
|             totalCan = totalCan, | ||||
|             totalKrw = totalKrw, | ||||
|             paymentFee = paymentFee.roundToInt(), | ||||
|             settlementAmount = settlementAmount.roundToInt(), | ||||
|             tax = tax.roundToInt(), | ||||
|             depositAmount = depositAmount.roundToInt() | ||||
|         ) | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -2,6 +2,7 @@ package kr.co.vividnext.sodalive.admin.calculate | ||||
|  | ||||
| import com.querydsl.core.annotations.QueryProjection | ||||
| import kr.co.vividnext.sodalive.content.order.OrderType | ||||
| import kotlin.math.roundToInt | ||||
|  | ||||
| data class GetCalculateContentQueryData @QueryProjection constructor( | ||||
|     // 등록 크리에이터 닉네임 | ||||
| @@ -20,4 +21,43 @@ data class GetCalculateContentQueryData @QueryProjection constructor( | ||||
|     val numberOfPeople: Long, | ||||
|     // 합계 | ||||
|     val totalCan: Int | ||||
| ) | ||||
| ) { | ||||
|     fun toGetCalculateContentResponse(): GetCalculateContentResponse { | ||||
|         val orderTypeStr = if (orderType == OrderType.RENTAL) { | ||||
|             "대여" | ||||
|         } else { | ||||
|             "소장" | ||||
|         } | ||||
|  | ||||
|         // 원화 = totalCoin * 100 ( 캔 1개 = 100원 ) | ||||
|         val totalKrw = 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 | ||||
|  | ||||
|         return GetCalculateContentResponse( | ||||
|             nickname = nickname, | ||||
|             title = title, | ||||
|             registrationDate = registrationDate, | ||||
|             saleDate = saleDate, | ||||
|             orderType = orderTypeStr, | ||||
|             orderPrice = orderPrice, | ||||
|             numberOfPeople = numberOfPeople.toInt(), | ||||
|             totalCan = totalCan, | ||||
|             totalKrw = totalKrw, | ||||
|             paymentFee = paymentFee.roundToInt(), | ||||
|             settlementAmount = settlementAmount.roundToInt(), | ||||
|             tax = tax.roundToInt(), | ||||
|             depositAmount = depositAmount.roundToInt() | ||||
|         ) | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -2,6 +2,7 @@ package kr.co.vividnext.sodalive.admin.calculate | ||||
|  | ||||
| import com.querydsl.core.annotations.QueryProjection | ||||
| import kr.co.vividnext.sodalive.can.use.CanUsage | ||||
| import kotlin.math.roundToInt | ||||
|  | ||||
| data class GetCalculateLiveQueryData @QueryProjection constructor( | ||||
|     val email: String, | ||||
| @@ -16,4 +17,57 @@ data class GetCalculateLiveQueryData @QueryProjection constructor( | ||||
|     val memberCount: Long, | ||||
|     // 합계 | ||||
|     val totalAmount: Int | ||||
| ) | ||||
| ) { | ||||
|     fun toGetCalculateLiveResponse(): GetCalculateLiveResponse { | ||||
|         val canUsageStr = when (canUsage) { | ||||
|             CanUsage.LIVE -> { | ||||
|                 "유료" | ||||
|             } | ||||
|  | ||||
|             CanUsage.SPIN_ROULETTE -> { | ||||
|                 "룰렛" | ||||
|             } | ||||
|  | ||||
|             else -> { | ||||
|                 "후원" | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         val numberOfPeople = if (canUsage == CanUsage.LIVE) { | ||||
|             memberCount.toInt() | ||||
|         } else { | ||||
|             0 | ||||
|         } | ||||
|  | ||||
|         // 원화 = totalCoin * 100 ( 캔 1개 = 100원 ) | ||||
|         val totalKrw = totalAmount * 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 | ||||
|  | ||||
|         return GetCalculateLiveResponse( | ||||
|             email = email, | ||||
|             nickname = nickname, | ||||
|             date = date, | ||||
|             title = title, | ||||
|             entranceFee = entranceFee, | ||||
|             canUsageStr = canUsageStr, | ||||
|             numberOfPeople = numberOfPeople, | ||||
|             totalAmount = totalAmount, | ||||
|             totalKrw = totalKrw, | ||||
|             paymentFee = paymentFee.roundToInt(), | ||||
|             settlementAmount = settlementAmount.roundToInt(), | ||||
|             tax = tax.roundToInt(), | ||||
|             depositAmount = depositAmount.roundToInt() | ||||
|         ) | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -3,6 +3,7 @@ package kr.co.vividnext.sodalive.admin.calculate | ||||
| import com.fasterxml.jackson.annotation.JsonProperty | ||||
| import com.querydsl.core.annotations.QueryProjection | ||||
| import kr.co.vividnext.sodalive.content.order.OrderType | ||||
| import kotlin.math.roundToInt | ||||
|  | ||||
| data class GetCumulativeSalesByContentQueryData @QueryProjection constructor( | ||||
|     // 등록 크리에이터 닉네임 | ||||
| @@ -19,7 +20,45 @@ data class GetCumulativeSalesByContentQueryData @QueryProjection constructor( | ||||
|     val numberOfPeople: Long, | ||||
|     // 합계 | ||||
|     val totalCan: Int | ||||
| ) | ||||
| ) { | ||||
|     fun toCumulativeSalesByContentItem(): CumulativeSalesByContentItem { | ||||
|         val orderTypeStr = if (orderType == OrderType.RENTAL) { | ||||
|             "대여" | ||||
|         } else { | ||||
|             "소장" | ||||
|         } | ||||
|  | ||||
|         // 원화 = totalCoin * 100 ( 캔 1개 = 100원 ) | ||||
|         val totalKrw = 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 | ||||
|  | ||||
|         return CumulativeSalesByContentItem( | ||||
|             nickname = nickname, | ||||
|             title = title, | ||||
|             registrationDate = registrationDate, | ||||
|             orderType = orderTypeStr, | ||||
|             orderPrice = orderPrice, | ||||
|             numberOfPeople = numberOfPeople.toInt(), | ||||
|             totalCan = totalCan, | ||||
|             totalKrw = totalKrw, | ||||
|             paymentFee = paymentFee.roundToInt(), | ||||
|             settlementAmount = settlementAmount.roundToInt(), | ||||
|             tax = tax.roundToInt(), | ||||
|             depositAmount = depositAmount.roundToInt() | ||||
|         ) | ||||
|     } | ||||
| } | ||||
|  | ||||
| data class GetCumulativeSalesByContentResponse( | ||||
|     @JsonProperty("totalCount") val totalCount: Int, | ||||
|   | ||||
| @@ -31,17 +31,7 @@ class CreatorAdminCalculateQueryRepository(private val queryFactory: JPAQueryFac | ||||
|         endDate: LocalDateTime, | ||||
|         memberId: Long | ||||
|     ): List<GetCalculateLiveQueryData> { | ||||
|         val formattedDate = Expressions.stringTemplate( | ||||
|             "DATE_FORMAT({0}, {1})", | ||||
|             Expressions.dateTimeTemplate( | ||||
|                 LocalDateTime::class.java, | ||||
|                 "CONVERT_TZ({0},{1},{2})", | ||||
|                 liveRoom.beginDateTime, | ||||
|                 "UTC", | ||||
|                 "Asia/Seoul" | ||||
|             ), | ||||
|             "%Y-%m-%d" | ||||
|         ) | ||||
|         val formattedDate = getFormattedDate(liveRoom.beginDateTime) | ||||
|  | ||||
|         return queryFactory | ||||
|             .select( | ||||
|   | ||||
| @@ -1,21 +1,12 @@ | ||||
| package kr.co.vividnext.sodalive.creator.admin.calculate | ||||
|  | ||||
| import kr.co.vividnext.sodalive.admin.calculate.CumulativeSalesByContentItem | ||||
| import kr.co.vividnext.sodalive.admin.calculate.GetCalculateCommunityPostResponse | ||||
| import kr.co.vividnext.sodalive.admin.calculate.GetCalculateContentDonationResponse | ||||
| import kr.co.vividnext.sodalive.admin.calculate.GetCalculateContentResponse | ||||
| import kr.co.vividnext.sodalive.admin.calculate.GetCalculateLiveResponse | ||||
| import kr.co.vividnext.sodalive.admin.calculate.GetCumulativeSalesByContentResponse | ||||
| import kr.co.vividnext.sodalive.can.use.CanUsage | ||||
| import kr.co.vividnext.sodalive.content.order.OrderType | ||||
| import kr.co.vividnext.sodalive.extensions.convertLocalDateTime | ||||
| import kr.co.vividnext.sodalive.member.Member | ||||
| import org.springframework.cache.annotation.Cacheable | ||||
| import org.springframework.stereotype.Service | ||||
| import org.springframework.transaction.annotation.Transactional | ||||
| import java.time.LocalDate | ||||
| import java.time.ZoneId | ||||
| import java.time.format.DateTimeFormatter | ||||
| import kotlin.math.roundToInt | ||||
|  | ||||
| @Service | ||||
| class CreatorAdminCalculateService(private val repository: CreatorAdminCalculateQueryRepository) { | ||||
| @@ -25,73 +16,12 @@ class CreatorAdminCalculateService(private val repository: CreatorAdminCalculate | ||||
|         key = "'creatorCalculateLive:v20240403_01:' + " + "#member + ':' + #startDateStr + ':' + #endDateStr" | ||||
|     ) | ||||
|     fun getCalculateLive(startDateStr: String, endDateStr: String, member: Member): List<GetCalculateLiveResponse> { | ||||
|         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() | ||||
|         val startDate = startDateStr.convertLocalDateTime() | ||||
|         val endDate = endDateStr.convertLocalDateTime(hour = 23, minute = 59, second = 59) | ||||
|  | ||||
|         return repository | ||||
|             .getCalculateLive(startDate, endDate, member.id!!) | ||||
|             .asSequence() | ||||
|             .map { | ||||
|                 val canUsageStr = when (it.canUsage) { | ||||
|                     CanUsage.LIVE -> { | ||||
|                         "유료" | ||||
|                     } | ||||
|  | ||||
|                     CanUsage.SPIN_ROULETTE -> { | ||||
|                         "룰렛" | ||||
|                     } | ||||
|  | ||||
|                     else -> { | ||||
|                         "후원" | ||||
|                     } | ||||
|                 } | ||||
|  | ||||
|                 val numberOfPeople = if (it.canUsage == CanUsage.LIVE) { | ||||
|                     it.memberCount.toInt() | ||||
|                 } else { | ||||
|                     0 | ||||
|                 } | ||||
|  | ||||
|                 // 원화 = totalCoin * 100 ( 캔 1개 = 100원 ) | ||||
|                 val totalKrw = it.totalAmount * 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 | ||||
|  | ||||
|                 GetCalculateLiveResponse( | ||||
|                     email = it.email, | ||||
|                     nickname = it.nickname, | ||||
|                     date = it.date, | ||||
|                     title = it.title, | ||||
|                     entranceFee = it.entranceFee, | ||||
|                     canUsageStr = canUsageStr, | ||||
|                     numberOfPeople = numberOfPeople, | ||||
|                     totalAmount = it.totalAmount, | ||||
|                     totalKrw = totalKrw, | ||||
|                     paymentFee = paymentFee.roundToInt(), | ||||
|                     settlementAmount = settlementAmount.roundToInt(), | ||||
|                     tax = tax.roundToInt(), | ||||
|                     depositAmount = depositAmount.roundToInt() | ||||
|                 ) | ||||
|             } | ||||
|             .toList() | ||||
|             .map { it.toGetCalculateLiveResponse() } | ||||
|     } | ||||
|  | ||||
|     @Transactional(readOnly = true) | ||||
| @@ -107,59 +37,12 @@ class CreatorAdminCalculateService(private val repository: CreatorAdminCalculate | ||||
|         offset: Long, | ||||
|         limit: Long | ||||
|     ): GetCalculateContentListResponse { | ||||
|         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() | ||||
|         val startDate = startDateStr.convertLocalDateTime() | ||||
|         val endDate = endDateStr.convertLocalDateTime(hour = 23, minute = 59, second = 59) | ||||
|  | ||||
|         val totalCount = repository.getCalculateContentListTotalCount(startDate, endDate, memberId) | ||||
|         val items = repository.getCalculateContentList(startDate, endDate, memberId, offset, limit) | ||||
|             .asSequence() | ||||
|             .map { | ||||
|                 val orderTypeStr = if (it.orderType == OrderType.RENTAL) { | ||||
|                     "대여" | ||||
|                 } else { | ||||
|                     "소장" | ||||
|                 } | ||||
|  | ||||
|                 // 원화 = 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 | ||||
|  | ||||
|                 GetCalculateContentResponse( | ||||
|                     nickname = it.nickname, | ||||
|                     title = it.title, | ||||
|                     registrationDate = it.registrationDate, | ||||
|                     saleDate = it.saleDate, | ||||
|                     orderType = orderTypeStr, | ||||
|                     orderPrice = it.orderPrice, | ||||
|                     numberOfPeople = it.numberOfPeople.toInt(), | ||||
|                     totalCan = it.totalCan, | ||||
|                     totalKrw = totalKrw, | ||||
|                     paymentFee = paymentFee.roundToInt(), | ||||
|                     settlementAmount = settlementAmount.roundToInt(), | ||||
|                     tax = tax.roundToInt(), | ||||
|                     depositAmount = depositAmount.roundToInt() | ||||
|                 ) | ||||
|             } | ||||
|             .toList() | ||||
|             .map { it.toGetCalculateContentResponse() } | ||||
|  | ||||
|         return GetCalculateContentListResponse(totalCount, items) | ||||
|     } | ||||
| @@ -173,45 +56,7 @@ class CreatorAdminCalculateService(private val repository: CreatorAdminCalculate | ||||
|         val totalCount = repository.getCumulativeSalesByContentTotalCount(memberId) | ||||
|         val items = repository | ||||
|             .getCumulativeSalesByContent(memberId, offset, limit) | ||||
|             .asSequence() | ||||
|             .map { | ||||
|                 val orderTypeStr = if (it.orderType == OrderType.RENTAL) { | ||||
|                     "대여" | ||||
|                 } else { | ||||
|                     "소장" | ||||
|                 } | ||||
|  | ||||
|                 // 원화 = 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 | ||||
|  | ||||
|                 CumulativeSalesByContentItem( | ||||
|                     nickname = it.nickname, | ||||
|                     title = it.title, | ||||
|                     registrationDate = it.registrationDate, | ||||
|                     orderType = orderTypeStr, | ||||
|                     orderPrice = it.orderPrice, | ||||
|                     numberOfPeople = it.numberOfPeople.toInt(), | ||||
|                     totalCan = it.totalCan, | ||||
|                     totalKrw = totalKrw, | ||||
|                     paymentFee = paymentFee.roundToInt(), | ||||
|                     settlementAmount = settlementAmount.roundToInt(), | ||||
|                     tax = tax.roundToInt(), | ||||
|                     depositAmount = depositAmount.roundToInt() | ||||
|                 ) | ||||
|             } | ||||
|             .toList() | ||||
|             .map { it.toCumulativeSalesByContentItem() } | ||||
|  | ||||
|         return GetCumulativeSalesByContentResponse(totalCount, items) | ||||
|     } | ||||
| @@ -229,67 +74,23 @@ class CreatorAdminCalculateService(private val repository: CreatorAdminCalculate | ||||
|         offset: Long, | ||||
|         limit: Long | ||||
|     ): GetCreatorCalculateContentDonationResponse { | ||||
|         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() | ||||
|         val startDate = startDateStr.convertLocalDateTime() | ||||
|         val endDate = endDateStr.convertLocalDateTime(hour = 23, minute = 59, second = 59) | ||||
|  | ||||
|         val totalCount = repository.getCalculateContentDonationListTotalCount(startDate, endDate, memberId) | ||||
|         val items = repository | ||||
|             .getCalculateContentDonationList(startDate, endDate, memberId, offset, limit) | ||||
|             .asSequence() | ||||
|             .map { | ||||
|                 // 원화 = totalCoin * 100 ( 캔 1개 = 100원 ) | ||||
|                 val totalKrw = it.totalCan * 100 | ||||
|  | ||||
|                 // 결제수수료 : 6.6% | ||||
|                 val paymentFee = totalKrw * 0.066f | ||||
|  | ||||
|                 // 정산금액 | ||||
|                 // 유료콘텐츠 (원화 - 결제수수료) 의 90% | ||||
|                 // 무료콘텐츠 (원화 - 결제수수료) 의 70% | ||||
|                 val settlementAmount = if (it.price > 0) { | ||||
|                     (totalKrw.toFloat() - paymentFee) * 0.9 | ||||
|                 } else { | ||||
|                     (totalKrw.toFloat() - paymentFee) * 0.7 | ||||
|                 } | ||||
|  | ||||
|                 // 원천세 = 정산금액의 3.3% | ||||
|                 val tax = settlementAmount * 0.033 | ||||
|  | ||||
|                 // 입금액 | ||||
|                 val depositAmount = settlementAmount - tax | ||||
|  | ||||
|                 GetCalculateContentDonationResponse( | ||||
|                     nickname = it.nickname, | ||||
|                     title = it.title, | ||||
|                     paidOrFree = if (it.price > 0) { | ||||
|                         "유료" | ||||
|                     } else { | ||||
|                         "무료" | ||||
|                     }, | ||||
|                     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() | ||||
|             .map { it.toGetCalculateContentDonationResponse() } | ||||
|  | ||||
|         return GetCreatorCalculateContentDonationResponse(totalCount, items) | ||||
|     } | ||||
|  | ||||
|     @Transactional(readOnly = true) | ||||
|     @Cacheable( | ||||
|         cacheNames = ["cache_ttl_3_hours"], | ||||
|         key = "'creatorCalculateCommunityPost:' + " + | ||||
|             "#startDateStr + ':' + #endDateStr + ':' + #memberId + ':' + #offset + ':' + #limit" | ||||
|     ) | ||||
|     fun getCalculateCommunityPost( | ||||
|         startDateStr: String, | ||||
|         endDateStr: String, | ||||
| @@ -297,40 +98,13 @@ class CreatorAdminCalculateService(private val repository: CreatorAdminCalculate | ||||
|         offset: Long, | ||||
|         limit: Long | ||||
|     ): GetCreatorCalculateCommunityPostResponse { | ||||
|         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() | ||||
|         val startDate = startDateStr.convertLocalDateTime() | ||||
|         val endDate = endDateStr.convertLocalDateTime(hour = 23, minute = 59, second = 59) | ||||
|  | ||||
|         val totalCount = repository.getCalculateCommunityPostTotalCount(startDate, endDate, memberId) | ||||
|         val items = repository | ||||
|             .getCalculateCommunityPostList(startDate, endDate, memberId, offset, limit) | ||||
|             .map { | ||||
|                 val totalKrw = it.totalCan * 100 | ||||
|                 val paymentFee = totalKrw * 0.066f | ||||
|                 val settlementAmount = (totalKrw.toFloat() - paymentFee) * 0.7 | ||||
|                 val tax = settlementAmount * 0.033 | ||||
|                 val depositAmount = settlementAmount - tax | ||||
|  | ||||
|                 GetCalculateCommunityPostResponse( | ||||
|                     nickname = it.nickname, | ||||
|                     title = it.title, | ||||
|                     date = it.date, | ||||
|                     numberOfPurchase = it.numberOfPurchase.toInt(), | ||||
|                     totalCan = it.totalCan, | ||||
|                     totalKrw = totalKrw, | ||||
|                     paymentFee = paymentFee.roundToInt(), | ||||
|                     settlementAmount = settlementAmount.roundToInt(), | ||||
|                     tax = tax.roundToInt(), | ||||
|                     depositAmount = depositAmount.roundToInt() | ||||
|                 ) | ||||
|             } | ||||
|             .map { it.toGetCalculateCommunityPostResponse() } | ||||
|  | ||||
|         return GetCreatorCalculateCommunityPostResponse(totalCount, items) | ||||
|     } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user