Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#321/Fix] 완료된 구독 기록을 갱신하는 문제 해결 #324

Merged
merged 5 commits into from
Aug 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.few.email.service.article.dto.Content
import com.few.email.service.article.dto.SendArticleEmailArgs
import jooq.jooq_dsl.tables.*
import org.jooq.DSLContext
import org.jooq.UpdateConditionStep
import org.jooq.impl.DSL
import org.springframework.stereotype.Component
import org.springframework.transaction.annotation.Transactional
Expand Down Expand Up @@ -201,24 +202,32 @@ class WorkBookSubscriberWriter(
memberSuccessRecords[it.memberId] == true
}

val successMemberIds = memberSuccessRecords.filter { it.value }.keys
/** 이메일 전송에 성공한 구독자들의 진행률을 업데이트한다.*/
dslContext.update(subscriptionT)
.set(subscriptionT.PROGRESS, subscriptionT.PROGRESS.add(1))
.where(subscriptionT.MEMBER_ID.`in`(successMemberIds))
.and(subscriptionT.TARGET_WORKBOOK_ID.`in`(targetWorkBookIds))
.execute()
val successMemberIds = memberSuccessRecords.filter { it.value }.keys
val updateTargetMemberRecords = items.filter { it.memberId in successMemberIds }
val updateQueries = mutableListOf<UpdateConditionStep<*>>()
for (updateTargetMemberRecord in updateTargetMemberRecords) {
updateQueries.add(
dslContext.update(subscriptionT)
.set(subscriptionT.PROGRESS, updateTargetMemberRecord.progress + 1)
.where(subscriptionT.MEMBER_ID.eq(updateTargetMemberRecord.memberId))
.and(subscriptionT.TARGET_WORKBOOK_ID.eq(updateTargetMemberRecord.targetWorkBookId))
)
}
dslContext.batch(updateQueries).execute()

/** 마지막 학습지를 받은 구독자들은 구독을 해지한다.*/
// todo refactoring to batch update
val receiveLastDayQueries = mutableListOf<UpdateConditionStep<*>>()
for (receiveLastDayMember in receiveLastDayMembers) {
dslContext.update(subscriptionT)
.set(subscriptionT.DELETED_AT, LocalDateTime.now())
.set(subscriptionT.UNSUBS_OPINION, "receive.all")
.where(subscriptionT.MEMBER_ID.eq(receiveLastDayMember.memberId))
.and(subscriptionT.TARGET_WORKBOOK_ID.eq(receiveLastDayMember.targetWorkBookId))
.execute()
receiveLastDayQueries.add(
dslContext.update(subscriptionT)
.set(subscriptionT.DELETED_AT, LocalDateTime.now())
.set(subscriptionT.UNSUBS_OPINION, "receive.all")
.where(subscriptionT.MEMBER_ID.eq(receiveLastDayMember.memberId))
.and(subscriptionT.TARGET_WORKBOOK_ID.eq(receiveLastDayMember.targetWorkBookId))
)
}
dslContext.batch(receiveLastDayQueries).execute()

return if (failRecords.isNotEmpty()) {
mapOf("records" to memberSuccessRecords, "fail" to failRecords)
Expand Down
Loading