Merge pull request 'test' (#184) from test into main

Reviewed-on: #184
This commit is contained in:
klaus 2024-05-28 16:09:51 +00:00
commit 2c176825fd
11 changed files with 333 additions and 471 deletions

View File

@ -34,4 +34,18 @@ class AdminCalculateController(private val service: AdminCalculateService) {
@RequestParam startDateStr: String,
@RequestParam endDateStr: String
) = ApiResponse.ok(service.getCalculateContentDonationList(startDateStr, endDateStr))
@GetMapping("/community-post")
fun getCalculateCommunityPost(
@RequestParam startDateStr: String,
@RequestParam endDateStr: String,
pageable: Pageable
) = ApiResponse.ok(
service.getCalculateCommunityPost(
startDateStr,
endDateStr,
pageable.offset,
pageable.pageSize.toLong()
)
)
}

View File

@ -8,6 +8,7 @@ import kr.co.vividnext.sodalive.can.use.CanUsage
import kr.co.vividnext.sodalive.can.use.QUseCan.useCan
import kr.co.vividnext.sodalive.content.QAudioContent.audioContent
import kr.co.vividnext.sodalive.content.order.QOrder.order
import kr.co.vividnext.sodalive.explorer.profile.creatorCommunity.QCreatorCommunity.creatorCommunity
import kr.co.vividnext.sodalive.live.room.QLiveRoom.liveRoom
import kr.co.vividnext.sodalive.member.QMember.member
import org.springframework.stereotype.Repository
@ -152,4 +153,53 @@ class AdminCalculateQueryRepository(private val queryFactory: JPAQueryFactory) {
.orderBy(member.id.asc(), donationFormattedDate.desc())
.fetch()
}
fun getCalculateCommunityPostTotalCount(startDate: LocalDateTime?, endDate: LocalDateTime?): Int {
val formattedDate = getFormattedDate(useCan.createdAt)
return queryFactory
.select(creatorCommunity.id)
.from(useCan)
.innerJoin(useCan.communityPost, creatorCommunity)
.innerJoin(creatorCommunity.member, member)
.where(
useCan.isRefund.isFalse
.and(useCan.canUsage.eq(CanUsage.PAID_COMMUNITY_POST))
.and(useCan.createdAt.goe(startDate))
.and(useCan.createdAt.loe(endDate))
)
.groupBy(formattedDate, creatorCommunity.id)
.fetch()
.size
}
fun getCalculateCommunityPostList(
startDate: LocalDateTime?,
endDate: LocalDateTime?,
offset: Long,
limit: Long
): List<GetCalculateCommunityPostQueryData> {
val formattedDate = getFormattedDate(useCan.createdAt)
return queryFactory
.select(
QGetCalculateCommunityPostQueryData(
member.nickname,
Expressions.stringTemplate("substring({0}, 1, 10)", creatorCommunity.content),
formattedDate,
useCan.id.count(),
useCan.can.add(useCan.rewardCan).sum()
)
)
.from(useCan)
.innerJoin(useCan.communityPost, creatorCommunity)
.innerJoin(creatorCommunity.member, member)
.where(
useCan.isRefund.isFalse
.and(useCan.canUsage.eq(CanUsage.PAID_COMMUNITY_POST))
.and(useCan.createdAt.goe(startDate))
.and(useCan.createdAt.loe(endDate))
)
.groupBy(formattedDate, creatorCommunity.id)
.orderBy(member.id.asc(), formattedDate.desc())
.fetch()
}
}

View File

@ -1,14 +1,10 @@
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.creator.admin.calculate.GetCreatorCalculateCommunityPostResponse
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) {
@ -18,73 +14,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)
@ -93,59 +28,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)
@ -157,45 +45,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)
}
@ -209,61 +59,28 @@ 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
.map { it.toGetCalculateContentDonationResponse() }
}
// 결제수수료 : 6.6%
val paymentFee = totalKrw * 0.066f
fun getCalculateCommunityPost(
startDateStr: String,
endDateStr: String,
offset: Long,
limit: Long
): GetCreatorCalculateCommunityPostResponse {
val startDate = startDateStr.convertLocalDateTime()
val endDate = endDateStr.convertLocalDateTime(hour = 23, minute = 59, second = 59)
// 정산금액
// 유료콘텐츠 (원화 - 결제수수료) 의 90%
// 무료콘텐츠 (원화 - 결제수수료) 의 70%
val settlementAmount = if (it.price > 0) {
(totalKrw.toFloat() - paymentFee) * 0.9
} else {
(totalKrw.toFloat() - paymentFee) * 0.7
}
val totalCount = repository.getCalculateCommunityPostTotalCount(startDate, endDate)
val items = repository
.getCalculateCommunityPostList(startDate, endDate, offset, limit)
.map { it.toGetCalculateCommunityPostResponse() }
// 원천세 = 정산금액의 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()
return GetCreatorCalculateCommunityPostResponse(totalCount, items)
}
}

View File

@ -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()
)
}
}

View File

@ -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()
)
}
}

View File

@ -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()
)
}
}

View File

@ -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()
)
}
}

View File

@ -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,

View File

@ -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(

View File

@ -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)
}

View File

@ -1,9 +1,26 @@
package kr.co.vividnext.sodalive.extensions
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.ZoneId
import java.time.format.DateTimeFormatter
fun String.convertLocalDateTime(format: String): LocalDateTime {
val dateTimeFormatter = DateTimeFormatter.ofPattern(format)
return LocalDateTime.parse(this, dateTimeFormatter)
}
fun String.convertLocalDateTime(
format: String = "yyyy-MM-dd",
currentTimeZoneStr: String = "Asia/Seoul",
hour: Int = 0,
minute: Int = 0,
second: Int = 0
): LocalDateTime {
val dateTimeFormatter = DateTimeFormatter.ofPattern(format)
return LocalDate.parse(this, dateTimeFormatter)
.atTime(hour, minute, second)
.atZone(ZoneId.of(currentTimeZoneStr))
.withZoneSameInstant(ZoneId.of("UTC"))
.toLocalDateTime()
}