refactor(can): 캔 사용 내역 조회 로직을 쿼리 기반으로 개선한다
This commit is contained in:
@@ -1,11 +1,9 @@
|
||||
package kr.co.vividnext.sodalive.can
|
||||
|
||||
import kr.co.vividnext.sodalive.can.charge.ChargeStatus
|
||||
import kr.co.vividnext.sodalive.can.payment.PaymentGateway
|
||||
import kr.co.vividnext.sodalive.can.use.CanUsage
|
||||
import kr.co.vividnext.sodalive.common.CountryContext
|
||||
import kr.co.vividnext.sodalive.member.Member
|
||||
import kr.co.vividnext.sodalive.member.MemberRepository
|
||||
import org.springframework.data.domain.Pageable
|
||||
import org.springframework.stereotype.Service
|
||||
import java.time.ZoneId
|
||||
@@ -14,8 +12,7 @@ import java.time.format.DateTimeFormatter
|
||||
@Service
|
||||
class CanService(
|
||||
private val repository: CanRepository,
|
||||
private val countryContext: CountryContext,
|
||||
private val memberRepository: MemberRepository
|
||||
private val countryContext: CountryContext
|
||||
) {
|
||||
fun getCans(isNotSelectedCurrency: Boolean): List<CanResponse> {
|
||||
val currency = if (isNotSelectedCurrency) {
|
||||
@@ -42,88 +39,94 @@ class CanService(
|
||||
timezone: String,
|
||||
container: String
|
||||
): List<GetCanUseStatusResponseItem> {
|
||||
val useCanList = repository.getCanUseStatus(member, pageable)
|
||||
.filter { (it.can + it.rewardCan) > 0 }
|
||||
.filter {
|
||||
when (container) {
|
||||
"aos" -> {
|
||||
it.useCanCalculates.any { useCanCalculate ->
|
||||
useCanCalculate.paymentGateway == PaymentGateway.PG ||
|
||||
useCanCalculate.paymentGateway == PaymentGateway.PAYVERSE ||
|
||||
useCanCalculate.paymentGateway == PaymentGateway.GOOGLE_IAP
|
||||
}
|
||||
}
|
||||
|
||||
"ios" -> {
|
||||
it.useCanCalculates.any { useCanCalculate ->
|
||||
useCanCalculate.paymentGateway == PaymentGateway.PG ||
|
||||
useCanCalculate.paymentGateway == PaymentGateway.PAYVERSE ||
|
||||
useCanCalculate.paymentGateway == PaymentGateway.APPLE_IAP
|
||||
}
|
||||
}
|
||||
|
||||
else -> it.useCanCalculates.any { useCanCalculate ->
|
||||
useCanCalculate.paymentGateway == PaymentGateway.PG ||
|
||||
useCanCalculate.paymentGateway == PaymentGateway.PAYVERSE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val channelDonationCreatorIds = useCanList
|
||||
.asSequence()
|
||||
.filter { it.canUsage == CanUsage.CHANNEL_DONATION }
|
||||
.mapNotNull { it.useCanCalculates.firstOrNull()?.recipientCreatorId }
|
||||
.distinct()
|
||||
.toList()
|
||||
|
||||
val channelDonationCreatorNicknameMap = if (channelDonationCreatorIds.isEmpty()) {
|
||||
emptyMap()
|
||||
} else {
|
||||
memberRepository.findAllById(channelDonationCreatorIds).associate { it.id!! to it.nickname }
|
||||
val zoneId = try {
|
||||
ZoneId.of(timezone)
|
||||
} catch (_: Exception) {
|
||||
ZoneId.of("UTC")
|
||||
}
|
||||
|
||||
return useCanList
|
||||
return repository.getCanUseStatus(member, pageable, container)
|
||||
.map {
|
||||
val title: String = when (it.canUsage) {
|
||||
CanUsage.HEART, CanUsage.DONATION, CanUsage.SPIN_ROULETTE -> {
|
||||
if (it.room != null) {
|
||||
"[라이브 후원] ${it.room!!.member!!.nickname}"
|
||||
} else if (it.audioContent != null) {
|
||||
"[콘텐츠 후원] ${it.audioContent!!.member!!.nickname}"
|
||||
if (it.roomMemberNickname != null) {
|
||||
"[라이브 후원] ${it.roomMemberNickname}"
|
||||
} else if (it.audioContentMemberNickname != null) {
|
||||
"[콘텐츠 후원] ${it.audioContentMemberNickname}"
|
||||
} else {
|
||||
"[후원]"
|
||||
}
|
||||
}
|
||||
|
||||
CanUsage.CHANNEL_DONATION -> {
|
||||
val creatorId = it.useCanCalculates.firstOrNull()?.recipientCreatorId
|
||||
val creatorNickname = creatorId?.let { id -> channelDonationCreatorNicknameMap[id] }
|
||||
|
||||
if (creatorNickname.isNullOrBlank()) {
|
||||
if (it.recipientCreatorNickname.isNullOrBlank()) {
|
||||
"[채널 후원]"
|
||||
} else {
|
||||
"[채널 후원] $creatorNickname"
|
||||
"[채널 후원] ${it.recipientCreatorNickname}"
|
||||
}
|
||||
}
|
||||
|
||||
CanUsage.LIVE -> {
|
||||
"[라이브] ${it.room!!.title}"
|
||||
if (it.roomTitle != null) {
|
||||
"[라이브] ${it.roomTitle}"
|
||||
} else if (it.roomMemberNickname != null) {
|
||||
"[라이브] ${it.roomMemberNickname}"
|
||||
} else {
|
||||
"[라이브]"
|
||||
}
|
||||
}
|
||||
|
||||
CanUsage.CHANGE_NICKNAME -> "닉네임 변경"
|
||||
CanUsage.ALARM_SLOT -> "알람 슬롯 구매"
|
||||
CanUsage.ORDER_CONTENT -> "[콘텐츠 구매] ${it.audioContent!!.title}"
|
||||
CanUsage.PAID_COMMUNITY_POST -> "[게시글 보기] ${it.communityPost?.member?.nickname ?: ""}"
|
||||
CanUsage.AUDITION_VOTE -> "[오디션 투표] ${it.auditionApplicant?.role?.audition?.title ?: ""}"
|
||||
CanUsage.CHAT_MESSAGE_PURCHASE -> "[메시지 구매] ${it.characterImage?.chatCharacter?.name ?: ""}"
|
||||
CanUsage.CHARACTER_IMAGE_PURCHASE -> "[캐릭터 이미지 구매] ${it.characterImage?.chatCharacter?.name ?: ""}"
|
||||
CanUsage.ORDER_CONTENT -> {
|
||||
if (it.audioContentTitle != null) {
|
||||
"[콘텐츠 구매] ${it.audioContentTitle}"
|
||||
} else if (it.audioContentMemberNickname != null) {
|
||||
"[콘텐츠 구매] ${it.audioContentMemberNickname}"
|
||||
} else {
|
||||
"[콘텐츠 구매]"
|
||||
}
|
||||
}
|
||||
|
||||
CanUsage.PAID_COMMUNITY_POST -> {
|
||||
if (it.communityPostMemberNickname != null) {
|
||||
"[게시글 보기] ${it.communityPostMemberNickname}"
|
||||
} else {
|
||||
"[게시글 보기]"
|
||||
}
|
||||
}
|
||||
|
||||
CanUsage.AUDITION_VOTE -> {
|
||||
if (it.auditionTitle != null) {
|
||||
"[오디션 투표] ${it.auditionTitle}"
|
||||
} else {
|
||||
"[오디션 투표]"
|
||||
}
|
||||
}
|
||||
|
||||
CanUsage.CHAT_MESSAGE_PURCHASE -> {
|
||||
if (it.characterName != null) {
|
||||
"[메시지 구매] ${it.characterName}"
|
||||
} else {
|
||||
"[메시지 구매]"
|
||||
}
|
||||
}
|
||||
|
||||
CanUsage.CHARACTER_IMAGE_PURCHASE -> {
|
||||
if (it.characterName != null) {
|
||||
"[캐릭터 이미지 구매] ${it.characterName}"
|
||||
} else {
|
||||
"[캐릭터 이미지 구매]"
|
||||
}
|
||||
}
|
||||
|
||||
CanUsage.CHAT_QUOTA_PURCHASE -> "캐릭터 톡 이용권 구매"
|
||||
CanUsage.CHAT_ROOM_RESET -> "캐릭터 톡 초기화"
|
||||
}
|
||||
|
||||
val createdAt = it.createdAt!!
|
||||
val createdAt = it.createdAt
|
||||
.atZone(ZoneId.of("UTC"))
|
||||
.withZoneSameInstant(ZoneId.of(timezone))
|
||||
.withZoneSameInstant(zoneId)
|
||||
|
||||
GetCanUseStatusResponseItem(
|
||||
title = title,
|
||||
@@ -141,6 +144,12 @@ class CanService(
|
||||
timezone: String,
|
||||
container: String
|
||||
): List<GetCanChargeStatusResponseItem> {
|
||||
val zoneId = try {
|
||||
ZoneId.of(timezone)
|
||||
} catch (e: Exception) {
|
||||
ZoneId.of("UTC")
|
||||
}
|
||||
|
||||
return repository.getCanChargeStatus(member, pageable, container)
|
||||
.map {
|
||||
val canTitle = it.title ?: ""
|
||||
@@ -170,9 +179,9 @@ class CanService(
|
||||
}
|
||||
}
|
||||
|
||||
val createdAt = it.createdAt!!
|
||||
val createdAt = (it.createdAt ?: it.updatedAt!!)
|
||||
.atZone(ZoneId.of("UTC"))
|
||||
.withZoneSameInstant(ZoneId.of(timezone))
|
||||
.withZoneSameInstant(zoneId)
|
||||
|
||||
GetCanChargeStatusResponseItem(
|
||||
canTitle = canTitle,
|
||||
|
||||
Reference in New Issue
Block a user