Skip to content

Commit

Permalink
refactor: 이메일 전송 배치 전송 설정에 따라 조회하도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
belljun3395 committed Sep 10, 2024
1 parent 573e27d commit 49bbf11
Showing 1 changed file with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package com.few.batch.service.article.reader

import com.few.batch.data.common.code.BatchDayCode
import com.few.batch.service.article.dto.WorkBookSubscriberItem
import jooq.jooq_dsl.tables.Subscription
import jooq.jooq_dsl.tables.Subscription.SUBSCRIPTION
import org.jooq.DSLContext
import org.springframework.stereotype.Component
import org.springframework.transaction.annotation.Transactional
import java.time.DayOfWeek
import java.time.LocalDate
import java.time.LocalTime
import java.time.ZoneId

@Component
class WorkBookSubscriberReader(
Expand All @@ -14,16 +19,25 @@ class WorkBookSubscriberReader(
/** 구독 테이블에서 학습지를 구독하고 있는 회원의 정보를 조회한다.*/
@Transactional(readOnly = true)
fun execute(): List<WorkBookSubscriberItem> {
val subscriptionT = Subscription.SUBSCRIPTION
val time = LocalTime.now(ZoneId.of("Asia/Seoul")).hour.let { LocalTime.of(it, 0, 0) }
val date = LocalDate.now(ZoneId.of("Asia/Seoul"))
val sendDay =
if ((date.dayOfWeek == DayOfWeek.SATURDAY) || (date.dayOfWeek == DayOfWeek.SUNDAY)) {
BatchDayCode.MON_TUE_WED_THU_FRI_SAT_SUN.code
} else {
BatchDayCode.MON_TUE_WED_THU_FRI.code
}

return dslContext.select(
subscriptionT.MEMBER_ID.`as`(WorkBookSubscriberItem::memberId.name),
subscriptionT.TARGET_WORKBOOK_ID.`as`(WorkBookSubscriberItem::targetWorkBookId.name),
subscriptionT.PROGRESS.`as`(WorkBookSubscriberItem::progress.name)
SUBSCRIPTION.MEMBER_ID.`as`(WorkBookSubscriberItem::memberId.name),
SUBSCRIPTION.TARGET_WORKBOOK_ID.`as`(WorkBookSubscriberItem::targetWorkBookId.name),
SUBSCRIPTION.PROGRESS.`as`(WorkBookSubscriberItem::progress.name)
)
.from(subscriptionT)
.where(subscriptionT.TARGET_MEMBER_ID.isNull)
.and(subscriptionT.DELETED_AT.isNull)
.from(SUBSCRIPTION)
.where(SUBSCRIPTION.SEND_TIME.eq(time))
.and(SUBSCRIPTION.SEND_DAY.eq(sendDay))
.and(SUBSCRIPTION.TARGET_MEMBER_ID.isNull)
.and(SUBSCRIPTION.DELETED_AT.isNull)
.fetchInto(WorkBookSubscriberItem::class.java)
}
}

0 comments on commit 49bbf11

Please sign in to comment.