This commit is contained in:
Klaus 2024-04-03 15:22:56 +09:00
parent 8d185c274a
commit aad4f8dbb5
1 changed files with 122 additions and 133 deletions

View File

@ -2,10 +2,8 @@ package kr.co.vividnext.sodalive.creator.admin.calculate
import kr.co.vividnext.sodalive.admin.calculate.CumulativeSalesByContentItem import kr.co.vividnext.sodalive.admin.calculate.CumulativeSalesByContentItem
import kr.co.vividnext.sodalive.admin.calculate.GetCalculateContentDonationResponse 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.GetCalculateLiveResponse
import kr.co.vividnext.sodalive.admin.calculate.GetCumulativeSalesByContentResponse import kr.co.vividnext.sodalive.admin.calculate.GetCumulativeSalesByContentResponse
import kr.co.vividnext.sodalive.can.use.CanUsage
import kr.co.vividnext.sodalive.common.SodaException import kr.co.vividnext.sodalive.common.SodaException
import kr.co.vividnext.sodalive.content.order.OrderType import kr.co.vividnext.sodalive.content.order.OrderType
import kr.co.vividnext.sodalive.member.Member import kr.co.vividnext.sodalive.member.Member
@ -20,88 +18,80 @@ import kotlin.math.roundToInt
@Service @Service
class CreatorAdminCalculateService(private val repository: CreatorAdminCalculateQueryRepository) { class CreatorAdminCalculateService(private val repository: CreatorAdminCalculateQueryRepository) {
@Transactional(readOnly = true) @Transactional(readOnly = true)
@Cacheable(
cacheNames = ["default"],
key = "'creatorCalculateLive:' + " + "#member + ':' + #startDateStr + ':' + #endDateStr"
)
fun getCalculateLive(startDateStr: String, endDateStr: String, member: Member): List<GetCalculateLiveResponse> { fun getCalculateLive(startDateStr: String, endDateStr: String, member: Member): List<GetCalculateLiveResponse> {
throw SodaException("점검중입니다.") throw SodaException("점검중입니다.")
val dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd") // val dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd")
val startDate = LocalDate.parse(startDateStr, dateTimeFormatter).atTime(0, 0, 0) // val startDate = LocalDate.parse(startDateStr, dateTimeFormatter).atTime(0, 0, 0)
.atZone(ZoneId.of("Asia/Seoul")) // .atZone(ZoneId.of("Asia/Seoul"))
.withZoneSameInstant(ZoneId.of("UTC")) // .withZoneSameInstant(ZoneId.of("UTC"))
.toLocalDateTime() // .toLocalDateTime()
//
val endDate = LocalDate.parse(endDateStr, dateTimeFormatter).atTime(23, 59, 59) // val endDate = LocalDate.parse(endDateStr, dateTimeFormatter).atTime(23, 59, 59)
.atZone(ZoneId.of("Asia/Seoul")) // .atZone(ZoneId.of("Asia/Seoul"))
.withZoneSameInstant(ZoneId.of("UTC")) // .withZoneSameInstant(ZoneId.of("UTC"))
.toLocalDateTime() // .toLocalDateTime()
//
return repository // return repository
.getCalculateLive(startDate, endDate, member.id!!) // .getCalculateLive(startDate, endDate, member.id!!)
.asSequence() // .asSequence()
.map { // .map {
val canUsageStr = when (it.canUsage) { // val canUsageStr = when (it.canUsage) {
CanUsage.LIVE -> { // CanUsage.LIVE -> {
"유료" // "유료"
} // }
//
CanUsage.SPIN_ROULETTE -> { // CanUsage.SPIN_ROULETTE -> {
"룰렛" // "룰렛"
} // }
//
else -> { // else -> {
"후원" // "후원"
} // }
} // }
//
val numberOfPeople = if (it.canUsage == CanUsage.LIVE) { // val numberOfPeople = if (it.canUsage == CanUsage.LIVE) {
it.memberCount.toInt() // it.memberCount.toInt()
} else { // } else {
0 // 0
} // }
//
// 원화 = totalCoin * 100 ( 캔 1개 = 100원 ) // // 원화 = totalCoin * 100 ( 캔 1개 = 100원 )
val totalKrw = it.totalAmount * 100 // val totalKrw = it.totalAmount * 100
//
// 결제수수료 : 6.6% // // 결제수수료 : 6.6%
val paymentFee = totalKrw * 0.066f // val paymentFee = totalKrw * 0.066f
//
// 정산금액 = (원화 - 결제수수료) 의 70% // // 정산금액 = (원화 - 결제수수료) 의 70%
val settlementAmount = (totalKrw.toFloat() - paymentFee) * 0.7 // val settlementAmount = (totalKrw.toFloat() - paymentFee) * 0.7
//
// 원천세 = 정산금액의 3.3% // // 원천세 = 정산금액의 3.3%
val tax = settlementAmount * 0.033 // val tax = settlementAmount * 0.033
//
// 입금액 // // 입금액
val depositAmount = settlementAmount - tax // val depositAmount = settlementAmount - tax
//
GetCalculateLiveResponse( // GetCalculateLiveResponse(
email = it.email, // email = it.email,
nickname = it.nickname, // nickname = it.nickname,
date = it.date, // date = it.date,
title = it.title, // title = it.title,
entranceFee = it.entranceFee, // entranceFee = it.entranceFee,
canUsageStr = canUsageStr, // canUsageStr = canUsageStr,
numberOfPeople = numberOfPeople, // numberOfPeople = numberOfPeople,
totalAmount = it.totalAmount, // totalAmount = it.totalAmount,
totalKrw = totalKrw, // totalKrw = totalKrw,
paymentFee = paymentFee.roundToInt(), // paymentFee = paymentFee.roundToInt(),
settlementAmount = settlementAmount.roundToInt(), // settlementAmount = settlementAmount.roundToInt(),
tax = tax.roundToInt(), // tax = tax.roundToInt(),
depositAmount = depositAmount.roundToInt() // depositAmount = depositAmount.roundToInt()
) // )
} // }
.toList() // .toList()
return listOf()
} }
@Transactional(readOnly = true) @Transactional(readOnly = true)
@Cacheable(
cacheNames = ["cache_ttl_3_hours"],
key = "'creatorCalculateContentList:' + " +
"#startDateStr + ':' + #endDateStr + ':' + #memberId + ':' + #offset + ':' + #limit"
)
fun getCalculateContentList( fun getCalculateContentList(
startDateStr: String, startDateStr: String,
endDateStr: String, endDateStr: String,
@ -110,62 +100,61 @@ class CreatorAdminCalculateService(private val repository: CreatorAdminCalculate
limit: Long limit: Long
): GetCalculateContentListResponse { ): GetCalculateContentListResponse {
throw SodaException("점검중입니다.") throw SodaException("점검중입니다.")
// 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 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()
val dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd") return GetCalculateContentListResponse(0, listOf())
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 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()
return GetCalculateContentListResponse(totalCount, items)
} }
@Transactional(readOnly = true) @Transactional(readOnly = true)