Compare commits

..

No commits in common. "0f48c71837c062ca5f24235f5117590b198576f5" and "3079998a5d76fb3fe979ea7e033eb8e09e2c916c" have entirely different histories.

2 changed files with 73 additions and 102 deletions

View File

@ -291,7 +291,6 @@ class OrderQueryRepositoryImpl(
order.audioContent.id.eq(contentId),
order.createdAt.after(createdAt)
)
.orderBy(order.id.desc())
.fetchFirst()
}
}

View File

@ -10,9 +10,7 @@ import kr.co.vividnext.sodalive.point.MemberPointRepository
import kr.co.vividnext.sodalive.point.PointGrantLog
import kr.co.vividnext.sodalive.point.PointGrantLogRepository
import kr.co.vividnext.sodalive.point.PointRewardPolicyRepository
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
import org.springframework.transaction.support.TransactionTemplate
import java.time.LocalDateTime
@Service
@ -22,7 +20,6 @@ class UserActionService(
private val policyRepository: PointRewardPolicyRepository,
private val grantLogRepository: PointGrantLogRepository,
private val memberPointRepository: MemberPointRepository,
private val transactionTemplate: TransactionTemplate,
private val fcmService: FcmService
) {
@ -37,13 +34,8 @@ class UserActionService(
) {
coroutineScope.launch {
val now = LocalDateTime.now()
transactionTemplate.execute {
repository.save(UserActionLog(memberId, actionType))
repository.flush()
}
try {
transactionTemplate.execute {
val policy = policyRepository.findByActionTypeAndIsActiveTrue(actionType, now)
if (policy != null) {
val policyType = policy.policyType
@ -58,39 +50,27 @@ class UserActionService(
orderRepository.findByMemberIdAndContentId(
memberId = memberId,
contentId = contentId,
createdAt = if (policyType == PolicyType.DAILY) {
policyTypeDailyStartDate
} else {
policy.startDate
}
createdAt = if (policyType == PolicyType.DAILY) policyTypeDailyStartDate else policy.startDate
)
} else {
null
}
if (actionType == ActionType.ORDER_CONTENT_COMMENT && order == null) return@execute
if (actionType == ActionType.ORDER_CONTENT_COMMENT && order == null) return@launch
val actionCount = repository.countByMemberIdAndActionTypeAndCreatedAtBetween(
memberId = memberId,
actionType = actionType,
startDate = if (policyType == PolicyType.DAILY) {
policyTypeDailyStartDate
} else {
policy.startDate
},
startDate = if (policyType == PolicyType.DAILY) policyTypeDailyStartDate else policy.startDate,
endDate = policy.endDate ?: now
)
if (actionCount < policy.threshold) return@execute
if (actionCount < policy.threshold) return@launch
val grantedCount = grantLogRepository.countByMemberIdAndPolicyIdAndStartDate(
memberId,
policy.id!!,
startDate = if (policyType == PolicyType.DAILY) {
policyTypeDailyStartDate
} else {
policy.startDate
}
startDate = if (policyType == PolicyType.DAILY) policyTypeDailyStartDate else policy.startDate
)
if (grantedCount >= policy.availableCount) return@execute
if (grantedCount >= policy.availableCount) return@launch
grantLogRepository.save(
PointGrantLog(
@ -131,13 +111,5 @@ class UserActionService(
}
}
}
} catch (e: Exception) {
logger.warn("포인트 지급 또는 알림 실패: ${e.message}")
}
}
}
companion object {
private val logger = LoggerFactory.getLogger(UserActionService::class.java)
}
}