fix: 유저 행동 데이터에 따른 포인트 지급
- 본인인증을 한 유저만 포인트 정책에 따라 포인트를 지급하도록 수정
This commit is contained in:
parent
a36d9f02d8
commit
d3ec13e6c0
|
@ -43,6 +43,7 @@ class AudioContentCommentController(
|
||||||
|
|
||||||
userActionService.recordAction(
|
userActionService.recordAction(
|
||||||
memberId = member.id!!,
|
memberId = member.id!!,
|
||||||
|
isAuth = member.auth != null,
|
||||||
actionType = ActionType.CONTENT_COMMENT,
|
actionType = ActionType.CONTENT_COMMENT,
|
||||||
contentCommentId = commentId,
|
contentCommentId = commentId,
|
||||||
pushTokenList = pushTokenList
|
pushTokenList = pushTokenList
|
||||||
|
@ -50,6 +51,7 @@ class AudioContentCommentController(
|
||||||
|
|
||||||
userActionService.recordAction(
|
userActionService.recordAction(
|
||||||
memberId = member.id!!,
|
memberId = member.id!!,
|
||||||
|
isAuth = member.auth != null,
|
||||||
actionType = ActionType.ORDER_CONTENT_COMMENT,
|
actionType = ActionType.ORDER_CONTENT_COMMENT,
|
||||||
contentId = request.contentId,
|
contentId = request.contentId,
|
||||||
contentCommentId = commentId,
|
contentCommentId = commentId,
|
||||||
|
|
|
@ -65,6 +65,7 @@ class MemberController(
|
||||||
|
|
||||||
userActionService.recordAction(
|
userActionService.recordAction(
|
||||||
memberId = response.memberId,
|
memberId = response.memberId,
|
||||||
|
isAuth = false,
|
||||||
actionType = ActionType.SIGN_UP,
|
actionType = ActionType.SIGN_UP,
|
||||||
pushTokenList = if (request.pushToken != null) {
|
pushTokenList = if (request.pushToken != null) {
|
||||||
listOf(request.pushToken)
|
listOf(request.pushToken)
|
||||||
|
@ -358,6 +359,7 @@ class MemberController(
|
||||||
if (response.isNew) {
|
if (response.isNew) {
|
||||||
userActionService.recordAction(
|
userActionService.recordAction(
|
||||||
memberId = response.memberId,
|
memberId = response.memberId,
|
||||||
|
isAuth = false,
|
||||||
actionType = ActionType.SIGN_UP,
|
actionType = ActionType.SIGN_UP,
|
||||||
pushTokenList = if (request.pushToken != null) {
|
pushTokenList = if (request.pushToken != null) {
|
||||||
listOf(request.pushToken)
|
listOf(request.pushToken)
|
||||||
|
@ -393,6 +395,7 @@ class MemberController(
|
||||||
if (response.isNew) {
|
if (response.isNew) {
|
||||||
userActionService.recordAction(
|
userActionService.recordAction(
|
||||||
memberId = response.memberId,
|
memberId = response.memberId,
|
||||||
|
isAuth = false,
|
||||||
actionType = ActionType.SIGN_UP,
|
actionType = ActionType.SIGN_UP,
|
||||||
pushTokenList = if (request.pushToken != null) {
|
pushTokenList = if (request.pushToken != null) {
|
||||||
listOf(request.pushToken)
|
listOf(request.pushToken)
|
||||||
|
|
|
@ -40,6 +40,7 @@ class AuthController(
|
||||||
val pushTokenList = memberService.getPushTokenList(recipient = memberId)
|
val pushTokenList = memberService.getPushTokenList(recipient = memberId)
|
||||||
userActionService.recordAction(
|
userActionService.recordAction(
|
||||||
memberId = member.id!!,
|
memberId = member.id!!,
|
||||||
|
isAuth = true,
|
||||||
actionType = ActionType.USER_AUTHENTICATION,
|
actionType = ActionType.USER_AUTHENTICATION,
|
||||||
pushTokenList = pushTokenList
|
pushTokenList = pushTokenList
|
||||||
)
|
)
|
||||||
|
|
|
@ -27,6 +27,7 @@ class UserActionController(
|
||||||
val pushTokenList = memberService.getPushTokenList(recipient = memberId)
|
val pushTokenList = memberService.getPushTokenList(recipient = memberId)
|
||||||
service.recordAction(
|
service.recordAction(
|
||||||
memberId = memberId,
|
memberId = memberId,
|
||||||
|
isAuth = member.auth != null,
|
||||||
actionType = request.actionType,
|
actionType = request.actionType,
|
||||||
pushTokenList = pushTokenList
|
pushTokenList = pushTokenList
|
||||||
)
|
)
|
||||||
|
|
|
@ -31,6 +31,7 @@ class UserActionService(
|
||||||
|
|
||||||
fun recordAction(
|
fun recordAction(
|
||||||
memberId: Long,
|
memberId: Long,
|
||||||
|
isAuth: Boolean,
|
||||||
actionType: ActionType,
|
actionType: ActionType,
|
||||||
contentId: Long? = null,
|
contentId: Long? = null,
|
||||||
contentCommentId: Long? = null,
|
contentCommentId: Long? = null,
|
||||||
|
@ -49,96 +50,98 @@ class UserActionService(
|
||||||
repository.flush()
|
repository.flush()
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
if (isAuth) {
|
||||||
transactionTemplate.execute {
|
try {
|
||||||
val policy = policyRepository.findByActionTypeAndIsActiveTrue(actionType, now)
|
transactionTemplate.execute {
|
||||||
if (policy != null) {
|
val policy = policyRepository.findByActionTypeAndIsActiveTrue(actionType, now)
|
||||||
val policyType = policy.policyType
|
if (policy != null) {
|
||||||
val todayAt15 = now.toLocalDate().atTime(15, 0)
|
val policyType = policy.policyType
|
||||||
val policyTypeDailyStartDate = if (now.toLocalTime().isBefore(todayAt15.toLocalTime())) {
|
val todayAt15 = now.toLocalDate().atTime(15, 0)
|
||||||
now.toLocalDate().minusDays(1).atTime(15, 0)
|
val policyTypeDailyStartDate = if (now.toLocalTime().isBefore(todayAt15.toLocalTime())) {
|
||||||
} else {
|
now.toLocalDate().minusDays(1).atTime(15, 0)
|
||||||
todayAt15
|
} else {
|
||||||
}
|
todayAt15
|
||||||
|
}
|
||||||
|
|
||||||
val isValidPolicyTypeDailyAndDailyStartDateAfterPolicyStartDate =
|
val isValidPolicyTypeDailyAndDailyStartDateAfterPolicyStartDate =
|
||||||
policyType == PolicyType.DAILY && policyTypeDailyStartDate >= policy.startDate
|
policyType == PolicyType.DAILY && policyTypeDailyStartDate >= policy.startDate
|
||||||
val order = if (contentId != null) {
|
val order = if (contentId != null) {
|
||||||
orderRepository.findByMemberIdAndContentId(
|
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