parent
2f2437e14d
commit
4dc0a13203
|
@ -45,7 +45,7 @@ import kr.co.vividnext.sodalive.live.room.menu.CreateLiveMenuRequest
|
||||||
import kr.co.vividnext.sodalive.live.room.menu.LiveRoomMenuService
|
import kr.co.vividnext.sodalive.live.room.menu.LiveRoomMenuService
|
||||||
import kr.co.vividnext.sodalive.live.room.menu.UpdateLiveMenuRequest
|
import kr.co.vividnext.sodalive.live.room.menu.UpdateLiveMenuRequest
|
||||||
import kr.co.vividnext.sodalive.live.room.visit.LiveRoomVisitService
|
import kr.co.vividnext.sodalive.live.room.visit.LiveRoomVisitService
|
||||||
import kr.co.vividnext.sodalive.live.roulette.NewRouletteRepository
|
import kr.co.vividnext.sodalive.live.roulette.NewRouletteService
|
||||||
import kr.co.vividnext.sodalive.live.signature.SignatureCanRepository
|
import kr.co.vividnext.sodalive.live.signature.SignatureCanRepository
|
||||||
import kr.co.vividnext.sodalive.live.tag.LiveTagRepository
|
import kr.co.vividnext.sodalive.live.tag.LiveTagRepository
|
||||||
import kr.co.vividnext.sodalive.member.Gender
|
import kr.co.vividnext.sodalive.member.Gender
|
||||||
|
@ -76,9 +76,9 @@ import kotlin.concurrent.write
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
class LiveRoomService(
|
class LiveRoomService(
|
||||||
private val menuService: LiveRoomMenuService,
|
private val menuService: LiveRoomMenuService,
|
||||||
|
private val rouletteService: NewRouletteService,
|
||||||
|
|
||||||
private val repository: LiveRoomRepository,
|
private val repository: LiveRoomRepository,
|
||||||
private val rouletteRepository: NewRouletteRepository,
|
|
||||||
private val roomInfoRepository: LiveRoomInfoRedisRepository,
|
private val roomInfoRepository: LiveRoomInfoRedisRepository,
|
||||||
private val roomInfoRepositoryV2: LiveRoomInfoRedisRepositoryV2,
|
private val roomInfoRepositoryV2: LiveRoomInfoRedisRepositoryV2,
|
||||||
private val roomCancelRepository: LiveRoomCancelRepository,
|
private val roomCancelRepository: LiveRoomCancelRepository,
|
||||||
|
@ -835,15 +835,7 @@ class LiveRoomService(
|
||||||
.getNotificationUserIds(room.member!!.id!!)
|
.getNotificationUserIds(room.member!!.id!!)
|
||||||
.contains(member.id)
|
.contains(member.id)
|
||||||
|
|
||||||
var isActiveRoulette = false
|
val isActiveRoulette = rouletteService.hasActiveRoulette(creatorId = room.member!!.id!!)
|
||||||
val rouletteList = rouletteRepository.findByCreatorId(creatorId = room.member!!.id!!)
|
|
||||||
|
|
||||||
for (roulette in rouletteList) {
|
|
||||||
if (roulette.isActive) {
|
|
||||||
isActiveRoulette = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
val donationRankingTop3UserIds = if (room.member!!.isVisibleDonationRank) {
|
val donationRankingTop3UserIds = if (room.member!!.isVisibleDonationRank) {
|
||||||
explorerQueryRepository
|
explorerQueryRepository
|
||||||
|
@ -1241,15 +1233,8 @@ class LiveRoomService(
|
||||||
kickOutService.deleteKickOutData(roomId = room.id!!)
|
kickOutService.deleteKickOutData(roomId = room.id!!)
|
||||||
roomInfoRepositoryV2.deleteById(roomInfo.roomId)
|
roomInfoRepositoryV2.deleteById(roomInfo.roomId)
|
||||||
|
|
||||||
val rouletteList = rouletteRepository.findByCreatorId(creatorId = member.id!!)
|
|
||||||
if (rouletteList.isNotEmpty()) {
|
|
||||||
rouletteList.forEach {
|
|
||||||
it.isActive = false
|
|
||||||
rouletteRepository.save(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
menuService.deactivateAll(memberId = member.id!!)
|
menuService.deactivateAll(memberId = member.id!!)
|
||||||
|
rouletteService.deactivateAll(creatorId = member.id!!)
|
||||||
} else {
|
} else {
|
||||||
roomInfo.removeSpeaker(member)
|
roomInfo.removeSpeaker(member)
|
||||||
roomInfo.removeListener(member)
|
roomInfo.removeListener(member)
|
||||||
|
|
|
@ -16,6 +16,8 @@ import kr.co.vividnext.sodalive.live.room.LiveRoomRepository
|
||||||
import kr.co.vividnext.sodalive.member.Member
|
import kr.co.vividnext.sodalive.member.Member
|
||||||
import kr.co.vividnext.sodalive.member.MemberRepository
|
import kr.co.vividnext.sodalive.member.MemberRepository
|
||||||
import kr.co.vividnext.sodalive.member.MemberRole
|
import kr.co.vividnext.sodalive.member.MemberRole
|
||||||
|
import kr.co.vividnext.sodalive.v2.RouletteRepositoryV2
|
||||||
|
import kr.co.vividnext.sodalive.v2.RouletteV2
|
||||||
import org.springframework.data.repository.findByIdOrNull
|
import org.springframework.data.repository.findByIdOrNull
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
import org.springframework.transaction.annotation.Transactional
|
import org.springframework.transaction.annotation.Transactional
|
||||||
|
@ -27,15 +29,43 @@ class NewRouletteService(
|
||||||
|
|
||||||
private val canRepository: CanRepository,
|
private val canRepository: CanRepository,
|
||||||
private val repository: NewRouletteRepository,
|
private val repository: NewRouletteRepository,
|
||||||
|
private val repositoryV2: RouletteRepositoryV2,
|
||||||
private val roomRepository: LiveRoomRepository,
|
private val roomRepository: LiveRoomRepository,
|
||||||
private val memberRepository: MemberRepository,
|
private val memberRepository: MemberRepository,
|
||||||
private val chargeRepository: ChargeRepository,
|
private val chargeRepository: ChargeRepository,
|
||||||
private val useCanCalculateRepository: UseCanCalculateRepository
|
private val useCanCalculateRepository: UseCanCalculateRepository
|
||||||
) {
|
) {
|
||||||
|
private fun findByCreatorId(creatorId: Long): List<RouletteV2> {
|
||||||
|
var rouletteV2List = repositoryV2.findByCreatorId(creatorId)
|
||||||
|
|
||||||
|
if (rouletteV2List.isEmpty()) {
|
||||||
|
val rouletteV1List = repository.findByCreatorId(creatorId)
|
||||||
|
|
||||||
|
if (rouletteV1List.isNotEmpty()) {
|
||||||
|
rouletteV1List.forEach { rouletteV1 ->
|
||||||
|
val rouletteV2 = RouletteV2(
|
||||||
|
id = idGenerator.generateId(SEQUENCE_NAME),
|
||||||
|
creatorId = rouletteV1.creatorId,
|
||||||
|
can = rouletteV1.can,
|
||||||
|
isActive = rouletteV1.isActive,
|
||||||
|
items = rouletteV1.items
|
||||||
|
)
|
||||||
|
|
||||||
|
repositoryV2.save(rouletteV2)
|
||||||
|
repository.delete(rouletteV1)
|
||||||
|
}
|
||||||
|
|
||||||
|
rouletteV2List = repositoryV2.findByCreatorId(creatorId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return rouletteV2List
|
||||||
|
}
|
||||||
|
|
||||||
fun getAllRoulette(creatorId: Long, memberId: Long): List<GetNewRouletteResponse> {
|
fun getAllRoulette(creatorId: Long, memberId: Long): List<GetNewRouletteResponse> {
|
||||||
if (creatorId != memberId) throw SodaException("잘못된 요청입니다.")
|
if (creatorId != memberId) throw SodaException("잘못된 요청입니다.")
|
||||||
|
|
||||||
val rouletteList = repository.findByCreatorId(creatorId)
|
val rouletteList = findByCreatorId(creatorId)
|
||||||
|
|
||||||
return rouletteList.sortedBy { it.id }
|
return rouletteList.sortedBy { it.id }
|
||||||
.map {
|
.map {
|
||||||
|
@ -52,14 +82,14 @@ class NewRouletteService(
|
||||||
rouletteValidate(can = request.can, items = request.items)
|
rouletteValidate(can = request.can, items = request.items)
|
||||||
|
|
||||||
if (request.isActive) {
|
if (request.isActive) {
|
||||||
val rouletteList = repository.findByCreatorId(creatorId = memberId)
|
val rouletteList = findByCreatorId(creatorId = memberId)
|
||||||
rouletteList.forEach {
|
rouletteList.forEach {
|
||||||
it.isActive = false
|
it.isActive = false
|
||||||
repository.save(it)
|
repositoryV2.save(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val roulette = NewRoulette(
|
val roulette = RouletteV2(
|
||||||
id = idGenerator.generateId(SEQUENCE_NAME),
|
id = idGenerator.generateId(SEQUENCE_NAME),
|
||||||
creatorId = memberId,
|
creatorId = memberId,
|
||||||
can = request.can,
|
can = request.can,
|
||||||
|
@ -67,14 +97,14 @@ class NewRouletteService(
|
||||||
items = request.items
|
items = request.items
|
||||||
)
|
)
|
||||||
|
|
||||||
repository.save(roulette)
|
repositoryV2.save(roulette)
|
||||||
return request.isActive
|
return request.isActive
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateRoulette(memberId: Long, request: UpdateNewRouletteRequest): Boolean {
|
fun updateRoulette(memberId: Long, request: UpdateNewRouletteRequest): Boolean {
|
||||||
rouletteValidate(can = request.can, items = request.items)
|
rouletteValidate(can = request.can, items = request.items)
|
||||||
|
|
||||||
val rouletteList = repository.findByCreatorId(creatorId = memberId)
|
val rouletteList = findByCreatorId(creatorId = memberId)
|
||||||
|
|
||||||
if (rouletteList.isEmpty()) {
|
if (rouletteList.isEmpty()) {
|
||||||
throw SodaException("잘못된 요청입니다.")
|
throw SodaException("잘못된 요청입니다.")
|
||||||
|
@ -90,10 +120,10 @@ class NewRouletteService(
|
||||||
it.can = request.can
|
it.can = request.can
|
||||||
it.items = request.items
|
it.items = request.items
|
||||||
it.isActive = request.isActive
|
it.isActive = request.isActive
|
||||||
repository.save(it)
|
repositoryV2.save(it)
|
||||||
} else if (request.isActive) {
|
} else if (request.isActive) {
|
||||||
it.isActive = false
|
it.isActive = false
|
||||||
repository.save(it)
|
repositoryV2.save(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,13 +131,13 @@ class NewRouletteService(
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getRoulette(creatorId: Long, memberId: Long): GetRouletteResponse {
|
fun getRoulette(creatorId: Long, memberId: Long): GetRouletteResponse {
|
||||||
val rouletteList = repository.findByCreatorId(creatorId = creatorId)
|
val rouletteList = findByCreatorId(creatorId = creatorId)
|
||||||
|
|
||||||
if (rouletteList.isEmpty()) {
|
if (rouletteList.isEmpty()) {
|
||||||
throw SodaException("룰렛을 사용할 수 없습니다.")
|
throw SodaException("룰렛을 사용할 수 없습니다.")
|
||||||
}
|
}
|
||||||
|
|
||||||
var activeRoulette: NewRoulette? = null
|
var activeRoulette: RouletteV2? = null
|
||||||
for (roulette in rouletteList) {
|
for (roulette in rouletteList) {
|
||||||
if (roulette.isActive) {
|
if (roulette.isActive) {
|
||||||
activeRoulette = roulette
|
activeRoulette = roulette
|
||||||
|
@ -139,13 +169,13 @@ class NewRouletteService(
|
||||||
}
|
}
|
||||||
|
|
||||||
// STEP 2 - 룰렛 데이터 가져오기
|
// STEP 2 - 룰렛 데이터 가져오기
|
||||||
val rouletteList = repository.findByCreatorId(creatorId = host.id!!)
|
val rouletteList = findByCreatorId(creatorId = host.id!!)
|
||||||
|
|
||||||
if (rouletteList.isEmpty()) {
|
if (rouletteList.isEmpty()) {
|
||||||
throw SodaException("룰렛을 사용할 수 없습니다.")
|
throw SodaException("룰렛을 사용할 수 없습니다.")
|
||||||
}
|
}
|
||||||
|
|
||||||
var activeRoulette: NewRoulette? = null
|
var activeRoulette: RouletteV2? = null
|
||||||
for (roulette in rouletteList) {
|
for (roulette in rouletteList) {
|
||||||
if (roulette.isActive) {
|
if (roulette.isActive) {
|
||||||
activeRoulette = roulette
|
activeRoulette = roulette
|
||||||
|
@ -220,7 +250,28 @@ class NewRouletteService(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun hasActiveRoulette(creatorId: Long): Boolean {
|
||||||
|
val rouletteList = findByCreatorId(creatorId)
|
||||||
|
|
||||||
|
for (roulette in rouletteList) {
|
||||||
|
if (roulette.isActive) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
fun deactivateAll(creatorId: Long) {
|
||||||
|
val rouletteList = findByCreatorId(creatorId)
|
||||||
|
|
||||||
|
rouletteList.forEach {
|
||||||
|
it.isActive = false
|
||||||
|
repositoryV2.save(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val SEQUENCE_NAME = "newRoulette:sequence"
|
const val SEQUENCE_NAME = "Roulette:sequence"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
package kr.co.vividnext.sodalive.v2
|
||||||
|
|
||||||
|
import org.springframework.data.repository.CrudRepository
|
||||||
|
|
||||||
|
interface RouletteRepositoryV2 : CrudRepository<RouletteV2, Long> {
|
||||||
|
fun findByCreatorId(creatorId: Long): List<RouletteV2>
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
package kr.co.vividnext.sodalive.v2
|
||||||
|
|
||||||
|
import kr.co.vividnext.sodalive.live.roulette.RouletteItem
|
||||||
|
import org.springframework.data.redis.core.RedisHash
|
||||||
|
import org.springframework.data.redis.core.index.Indexed
|
||||||
|
import javax.persistence.Id
|
||||||
|
|
||||||
|
@RedisHash("Roulette")
|
||||||
|
data class RouletteV2(
|
||||||
|
@Id
|
||||||
|
val id: Long,
|
||||||
|
@Indexed
|
||||||
|
val creatorId: Long,
|
||||||
|
var can: Int,
|
||||||
|
var isActive: Boolean,
|
||||||
|
var items: List<RouletteItem> = mutableListOf()
|
||||||
|
)
|
Loading…
Reference in New Issue