fix: 구매하지 않은 콘텐츠에 댓글을 써도 ORDER_CONTENT_COMMENT 이벤트가 있으면 유저 행동 데이터에 기록되는 버그 수정
This commit is contained in:
parent
af352256e9
commit
dc13053825
|
@ -5,6 +5,7 @@ import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.cancel
|
import kotlinx.coroutines.cancel
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import kr.co.vividnext.sodalive.content.order.OrderRepository
|
import kr.co.vividnext.sodalive.content.order.OrderRepository
|
||||||
import kr.co.vividnext.sodalive.fcm.FcmService
|
import kr.co.vividnext.sodalive.fcm.FcmService
|
||||||
import kr.co.vividnext.sodalive.point.MemberPoint
|
import kr.co.vividnext.sodalive.point.MemberPoint
|
||||||
|
@ -48,109 +49,141 @@ class UserActionService(
|
||||||
) {
|
) {
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
val now = LocalDateTime.now()
|
val now = LocalDateTime.now()
|
||||||
transactionTemplate.execute {
|
val policy = policyRepository.findByActionTypeAndIsActiveTrue(actionType, now)
|
||||||
repository.save(
|
if (policy != null) {
|
||||||
UserActionLog(
|
val policyType = policy.policyType
|
||||||
|
val todayAt15 = now.toLocalDate().atTime(15, 0)
|
||||||
|
val policyTypeDailyStartDate = if (now.toLocalTime().isBefore(todayAt15.toLocalTime())) {
|
||||||
|
now.toLocalDate().minusDays(1).atTime(15, 0)
|
||||||
|
} else {
|
||||||
|
todayAt15
|
||||||
|
}
|
||||||
|
|
||||||
|
val isValidPolicyTypeDailyAndDailyStartDateAfterPolicyStartDate =
|
||||||
|
policyType == PolicyType.DAILY && policyTypeDailyStartDate >= policy.startDate
|
||||||
|
val order = if (contentId != null) {
|
||||||
|
orderRepository.findByMemberIdAndContentId(
|
||||||
memberId = memberId,
|
memberId = memberId,
|
||||||
actionType = actionType,
|
contentId = contentId,
|
||||||
contentCommentId = contentCommentId
|
createdAt = if (isValidPolicyTypeDailyAndDailyStartDateAfterPolicyStartDate) {
|
||||||
|
policyTypeDailyStartDate
|
||||||
|
} else {
|
||||||
|
policy.startDate
|
||||||
|
}
|
||||||
)
|
)
|
||||||
)
|
} else {
|
||||||
repository.flush()
|
null
|
||||||
|
}
|
||||||
|
if (actionType == ActionType.ORDER_CONTENT_COMMENT && order == null) return@launch
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isAuth) {
|
withContext(Dispatchers.IO) {
|
||||||
try {
|
transactionTemplate.execute {
|
||||||
transactionTemplate.execute {
|
repository.save(
|
||||||
entityManager.clear()
|
UserActionLog(
|
||||||
val policy = policyRepository.findByActionTypeAndIsActiveTrue(actionType, now)
|
memberId = memberId,
|
||||||
if (policy != null) {
|
actionType = actionType,
|
||||||
val policyType = policy.policyType
|
contentCommentId = contentCommentId
|
||||||
val todayAt15 = now.toLocalDate().atTime(15, 0)
|
)
|
||||||
val policyTypeDailyStartDate = if (now.toLocalTime().isBefore(todayAt15.toLocalTime())) {
|
)
|
||||||
now.toLocalDate().minusDays(1).atTime(15, 0)
|
repository.flush()
|
||||||
} else {
|
}
|
||||||
todayAt15
|
}
|
||||||
}
|
|
||||||
|
|
||||||
val isValidPolicyTypeDailyAndDailyStartDateAfterPolicyStartDate =
|
withContext(Dispatchers.IO) {
|
||||||
policyType == PolicyType.DAILY && policyTypeDailyStartDate >= policy.startDate
|
if (isAuth) {
|
||||||
val order = if (contentId != null) {
|
try {
|
||||||
orderRepository.findByMemberIdAndContentId(
|
transactionTemplate.execute {
|
||||||
|
entityManager.clear()
|
||||||
|
if (policy != null) {
|
||||||
|
val policyType = policy.policyType
|
||||||
|
val todayAt15 = now.toLocalDate().atTime(15, 0)
|
||||||
|
val policyTypeDailyStartDate =
|
||||||
|
if (now.toLocalTime().isBefore(todayAt15.toLocalTime())) {
|
||||||
|
now.toLocalDate().minusDays(1).atTime(15, 0)
|
||||||
|
} else {
|
||||||
|
todayAt15
|
||||||
|
}
|
||||||
|
|
||||||
|
val isValidPolicyTypeDailyAndDailyStartDateAfterPolicyStartDate =
|
||||||
|
policyType == PolicyType.DAILY && policyTypeDailyStartDate >= policy.startDate
|
||||||
|
val order = if (contentId != null) {
|
||||||
|
orderRepository.findByMemberIdAndContentId(
|
||||||
|
memberId = memberId,
|
||||||
|
contentId = contentId,
|
||||||
|
createdAt = if (isValidPolicyTypeDailyAndDailyStartDateAfterPolicyStartDate) {
|
||||||
|
policyTypeDailyStartDate
|
||||||
|
} else {
|
||||||
|
policy.startDate
|
||||||
|
}
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
if (actionType == ActionType.ORDER_CONTENT_COMMENT && order == null) return@execute
|
||||||
|
|
||||||
|
val actionCount = repository.countByMemberIdAndActionTypeAndCreatedAtBetween(
|
||||||
memberId = memberId,
|
memberId = memberId,
|
||||||
contentId = contentId,
|
actionType = actionType,
|
||||||
createdAt = if (isValidPolicyTypeDailyAndDailyStartDateAfterPolicyStartDate) {
|
startDate = if (isValidPolicyTypeDailyAndDailyStartDateAfterPolicyStartDate) {
|
||||||
policyTypeDailyStartDate
|
policyTypeDailyStartDate
|
||||||
} else {
|
} else {
|
||||||
policy.startDate
|
policy.startDate
|
||||||
|
},
|
||||||
|
endDate = policy.endDate ?: now
|
||||||
|
)
|
||||||
|
if (actionCount < policy.threshold) return@execute
|
||||||
|
|
||||||
|
val grantedCount = grantLogRepository.countByMemberIdAndPolicyIdAndStartDate(
|
||||||
|
memberId,
|
||||||
|
policy.id!!,
|
||||||
|
startDate = if (isValidPolicyTypeDailyAndDailyStartDateAfterPolicyStartDate) {
|
||||||
|
policyTypeDailyStartDate
|
||||||
|
} else {
|
||||||
|
policy.startDate
|
||||||
|
},
|
||||||
|
orderId = order?.id
|
||||||
|
)
|
||||||
|
if (grantedCount >= policy.availableCount) return@execute
|
||||||
|
|
||||||
|
val point = if (actionType == ActionType.ORDER_CONTENT_COMMENT && order != null) {
|
||||||
|
order.can
|
||||||
|
} else {
|
||||||
|
policy.pointAmount
|
||||||
|
}
|
||||||
|
|
||||||
|
if (point > 0) {
|
||||||
|
grantLogRepository.save(
|
||||||
|
PointGrantLog(
|
||||||
|
memberId = memberId,
|
||||||
|
point = point,
|
||||||
|
actionType = actionType,
|
||||||
|
policyId = policy.id!!,
|
||||||
|
orderId = order?.id
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
memberPointRepository.save(
|
||||||
|
MemberPoint(
|
||||||
|
memberId = memberId,
|
||||||
|
point = point,
|
||||||
|
actionType = actionType,
|
||||||
|
expiresAt = now.plusDays(3)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
if (pushTokenList.isNotEmpty()) {
|
||||||
|
fcmService.sendPointGranted(
|
||||||
|
pushTokenList,
|
||||||
|
point
|
||||||
|
)
|
||||||
}
|
}
|
||||||
)
|
|
||||||
} else {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
if (actionType == ActionType.ORDER_CONTENT_COMMENT && order == null) return@execute
|
|
||||||
|
|
||||||
val actionCount = repository.countByMemberIdAndActionTypeAndCreatedAtBetween(
|
|
||||||
memberId = memberId,
|
|
||||||
actionType = actionType,
|
|
||||||
startDate = if (isValidPolicyTypeDailyAndDailyStartDateAfterPolicyStartDate) {
|
|
||||||
policyTypeDailyStartDate
|
|
||||||
} else {
|
|
||||||
policy.startDate
|
|
||||||
},
|
|
||||||
endDate = policy.endDate ?: now
|
|
||||||
)
|
|
||||||
if (actionCount < policy.threshold) return@execute
|
|
||||||
|
|
||||||
val grantedCount = grantLogRepository.countByMemberIdAndPolicyIdAndStartDate(
|
|
||||||
memberId,
|
|
||||||
policy.id!!,
|
|
||||||
startDate = if (isValidPolicyTypeDailyAndDailyStartDateAfterPolicyStartDate) {
|
|
||||||
policyTypeDailyStartDate
|
|
||||||
} else {
|
|
||||||
policy.startDate
|
|
||||||
},
|
|
||||||
orderId = order?.id
|
|
||||||
)
|
|
||||||
if (grantedCount >= policy.availableCount) return@execute
|
|
||||||
|
|
||||||
val point = if (actionType == ActionType.ORDER_CONTENT_COMMENT && order != null) {
|
|
||||||
order.can
|
|
||||||
} else {
|
|
||||||
policy.pointAmount
|
|
||||||
}
|
|
||||||
|
|
||||||
if (point > 0) {
|
|
||||||
grantLogRepository.save(
|
|
||||||
PointGrantLog(
|
|
||||||
memberId = memberId,
|
|
||||||
point = point,
|
|
||||||
actionType = actionType,
|
|
||||||
policyId = policy.id!!,
|
|
||||||
orderId = order?.id
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
memberPointRepository.save(
|
|
||||||
MemberPoint(
|
|
||||||
memberId = memberId,
|
|
||||||
point = point,
|
|
||||||
actionType = actionType,
|
|
||||||
expiresAt = now.plusDays(3)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
if (pushTokenList.isNotEmpty()) {
|
|
||||||
fcmService.sendPointGranted(
|
|
||||||
pushTokenList,
|
|
||||||
point
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
logger.warn("포인트 지급 또는 알림 실패: ${e.message}")
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
|
||||||
logger.warn("포인트 지급 또는 알림 실패: ${e.message}")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue