Skip to content

Commit

Permalink
[Refactor/#390] 이메일 전송 배치 전송 설정에 따라 조회하도록 수정 (#391)
Browse files Browse the repository at this point in the history
* feat: DayCode 추가

* refactor: 이메일 전송 배치 전송 설정에 따라 조회하도록 수정
  • Loading branch information
belljun3395 authored Sep 10, 2024
1 parent c3645c2 commit 9fbc7ff
Show file tree
Hide file tree
Showing 4 changed files with 306 additions and 8 deletions.
3 changes: 3 additions & 0 deletions api/src/main/kotlin/com/few/api/web/support/DayCode.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.few.api.web.support

/**
* @see com.few.data.common.code.DayCode
*/
enum class DayCode(val code: String, val days: String) {
MON("0000001", ""),
TUE("0000010", ""),
Expand Down
140 changes: 140 additions & 0 deletions batch/src/main/kotlin/com/few/batch/data/common/code/BatchDayCode.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
package com.few.batch.data.common.code

/**
* @see com.few.data.common.code.DayCode
*/
enum class BatchDayCode(val code: String, val days: String) {
MON("0000001", ""),
TUE("0000010", ""),
MON_TUE("0000011", "월,화"),
WED("0000100", ""),
MON_WED("0000101", "월,수"),
TUE_WED("0000110", "화,수"),
MON_TUE_WED("0000111", "월,화,수"),
THU("0001000", ""),
MON_THU("0001001", "월,목"),
TUE_THU("0001010", "화,목"),
MON_TUE_THU("0001011", "월,화,목"),
WED_THU("0001100", "수,목"),
MON_WED_THU("0001101", "월,수,목"),
TUE_WED_THU("0001110", "화,수,목"),
MON_TUE_WED_THU("0001111", "월,화,수,목"),
FRI("0010000", ""),
MON_FRI("0010001", "월,금"),
TUE_FRI("0010010", "화,금"),
MON_TUE_FRI("0010011", "월,화,금"),
WED_FRI("0010100", "수,금"),
MON_WED_FRI("0010101", "월,수,금"),
TUE_WED_FRI("0010110", "화,수,금"),
MON_TUE_WED_FRI("0010111", "월,화,수,금"),
THU_FRI("0011000", "목,금"),
MON_THU_FRI("0011001", "월,목,금"),
TUE_THU_FRI("0011010", "화,목,금"),
MON_TUE_THU_FRI("0011011", "월,화,목,금"),
WED_THU_FRI("0011100", "수,목,금"),
MON_WED_THU_FRI("0011101", "월,수,목,금"),
TUE_WED_THU_FRI("0011110", "화,수,목,금"),
MON_TUE_WED_THU_FRI("0011111", "월,화,수,목,금"),
SAT("0100000", ""),
MON_SAT("0100001", "월,토"),
TUE_SAT("0100010", "화,토"),
MON_TUE_SAT("0100011", "월,화,토"),
WED_SAT("0100100", "수,토"),
MON_WED_SAT("0100101", "월,수,토"),
TUE_WED_SAT("0100110", "화,수,토"),
MON_TUE_WED_SAT("0100111", "월,화,수,토"),
THU_SAT("0101000", "목,토"),
MON_THU_SAT("0101001", "월,목,토"),
TUE_THU_SAT("0101010", "화,목,토"),
MON_TUE_THU_SAT("0101011", "월,화,목,토"),
WED_THU_SAT("0101100", "수,목,토"),
MON_WED_THU_SAT("0101101", "월,수,목,토"),
TUE_WED_THU_SAT("0101110", "화,수,목,토"),
MON_TUE_WED_THU_SAT("0101111", "월,화,수,목,토"),
FRI_SAT("0110000", "금,토"),
MON_FRI_SAT("0110001", "월,금,토"),
TUE_FRI_SAT("0110010", "화,금,토"),
MON_TUE_FRI_SAT("0110011", "월,화,금,토"),
WED_FRI_SAT("0110100", "수,금,토"),
MON_WED_FRI_SAT("0110101", "월,수,금,토"),
TUE_WED_FRI_SAT("0110110", "화,수,금,토"),
MON_TUE_WED_FRI_SAT("0110111", "월,화,수,금,토"),
THU_FRI_SAT("0111000", "목,금,토"),
MON_THU_FRI_SAT("0111001", "월,목,금,토"),
TUE_THU_FRI_SAT("0111010", "화,목,금,토"),
MON_TUE_THU_FRI_SAT("0111011", "월,화,목,금,토"),
WED_THU_FRI_SAT("0111100", "수,목,금,토"),
MON_WED_THU_FRI_SAT("0111101", "월,수,목,금,토"),
TUE_WED_THU_FRI_SAT("0111110", "화,수,목,금,토"),
MON_TUE_WED_THU_FRI_SAT("0111111", "월,화,수,목,금,토"),
SUN("1000000", ""),
MON_SUN("1000001", "월,일"),
TUE_SUN("1000010", "화,일"),
MON_TUE_SUN("1000011", "월,화,일"),
WED_SUN("1000100", "수,일"),
MON_WED_SUN("1000101", "월,수,일"),
TUE_WED_SUN("1000110", "화,수,일"),
MON_TUE_WED_SUN("1000111", "월,화,수,일"),
THU_SUN("1001000", "목,일"),
MON_THU_SUN("1001001", "월,목,일"),
TUE_THU_SUN("1001010", "화,목,일"),
MON_TUE_THU_SUN("1001011", "월,화,목,일"),
WED_THU_SUN("1001100", "수,목,일"),
MON_WED_THU_SUN("1001101", "월,수,목,일"),
TUE_WED_THU_SUN("1001110", "화,수,목,일"),
MON_TUE_WED_THU_SUN("1001111", "월,화,수,목,일"),
FRI_SUN("1010000", "금,일"),
MON_FRI_SUN("1010001", "월,금,일"),
TUE_FRI_SUN("1010010", "화,금,일"),
MON_TUE_FRI_SUN("1010011", "월,화,금,일"),
WED_FRI_SUN("1010100", "수,금,일"),
MON_WED_FRI_SUN("1010101", "월,수,금,일"),
TUE_WED_FRI_SUN("1010110", "화,수,금,일"),
MON_TUE_WED_FRI_SUN("1010111", "월,화,수,금,일"),
THU_FRI_SUN("1011000", "목,금,일"),
MON_THU_FRI_SUN("1011001", "월,목,금,일"),
TUE_THU_FRI_SUN("1011010", "화,목,금,일"),
MON_TUE_THU_FRI_SUN("1011011", "월,화,목,금,일"),
WED_THU_FRI_SUN("1011100", "수,목,금,일"),
MON_WED_THU_FRI_SUN("1011101", "월,수,목,금,일"),
TUE_WED_THU_FRI_SUN("1011110", "화,수,목,금,일"),
MON_TUE_WED_THU_FRI_SUN("1011111", "월,화,수,목,금,일"),
SAT_SUN("1100000", "토,일"),
MON_SAT_SUN("1100001", "월,토,일"),
TUE_SAT_SUN("1100010", "화,토,일"),
MON_TUE_SAT_SUN("1100011", "월,화,토,일"),
WED_SAT_SUN("1100100", "수,토,일"),
MON_WED_SAT_SUN("1100101", "월,수,토,일"),
TUE_WED_SAT_SUN("1100110", "화,수,토,일"),
MON_TUE_WED_SAT_SUN("1100111", "월,화,수,토,일"),
THU_SAT_SUN("1101000", "목,토,일"),
MON_THU_SAT_SUN("1101001", "월,목,토,일"),
TUE_THU_SAT_SUN("1101010", "화,목,토,일"),
MON_TUE_THU_SAT_SUN("1101011", "월,화,목,토,일"),
WED_THU_SAT_SUN("1101100", "수,목,토,일"),
MON_WED_THU_SAT_SUN("1101101", "월,수,목,토,일"),
TUE_WED_THU_SAT_SUN("1101110", "화,수,목,토,일"),
MON_TUE_WED_THU_SAT_SUN("1101111", "월,화,수,목,토,일"),
FRI_SAT_SUN("1110000", "금,토,일"),
MON_FRI_SAT_SUN("1110001", "월,금,토,일"),
TUE_FRI_SAT_SUN("1110010", "화,금,토,일"),
MON_TUE_FRI_SAT_SUN("1110011", "월,화,금,토,일"),
WED_FRI_SAT_SUN("1110100", "수,금,토,일"),
MON_WED_FRI_SAT_SUN("1110101", "월,수,금,토,일"),
TUE_WED_FRI_SAT_SUN("1110110", "화,수,금,토,일"),
MON_TUE_WED_FRI_SAT_SUN("1110111", "월,화,수,금,토,일"),
THU_FRI_SAT_SUN("1111000", "목,금,토,일"),
MON_THU_FRI_SAT_SUN("1111001", "월,목,금,토,일"),
TUE_THU_FRI_SAT_SUN("1111010", "화,목,금,토,일"),
MON_TUE_THU_FRI_SAT_SUN("1111011", "월,화,목,금,토,일"),
WED_THU_FRI_SAT_SUN("1111100", "수,목,금,토,일"),
MON_WED_THU_FRI_SAT_SUN("1111101", "월,수,목,금,토,일"),
TUE_WED_THU_FRI_SAT_SUN("1111110", "화,수,목,금,토,일"),
MON_TUE_WED_THU_FRI_SAT_SUN("1111111", "월,화,수,목,금,토,일"),
;
companion object {
fun fromCode(code: String): BatchDayCode {
return entries.first { it.code == code }
}
}
}
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)
}
}
141 changes: 141 additions & 0 deletions data/src/main/kotlin/com/few/data/common/code/DayCode.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
package com.few.data.common.code

/**
* @see com.few.api.web.support.DayCode
* @see com.few.batch.data.common.code.BatchDayCode
*/
enum class DayCode(val code: String, val days: String) {
MON("0000001", ""),
TUE("0000010", ""),
MON_TUE("0000011", "월,화"),
WED("0000100", ""),
MON_WED("0000101", "월,수"),
TUE_WED("0000110", "화,수"),
MON_TUE_WED("0000111", "월,화,수"),
THU("0001000", ""),
MON_THU("0001001", "월,목"),
TUE_THU("0001010", "화,목"),
MON_TUE_THU("0001011", "월,화,목"),
WED_THU("0001100", "수,목"),
MON_WED_THU("0001101", "월,수,목"),
TUE_WED_THU("0001110", "화,수,목"),
MON_TUE_WED_THU("0001111", "월,화,수,목"),
FRI("0010000", ""),
MON_FRI("0010001", "월,금"),
TUE_FRI("0010010", "화,금"),
MON_TUE_FRI("0010011", "월,화,금"),
WED_FRI("0010100", "수,금"),
MON_WED_FRI("0010101", "월,수,금"),
TUE_WED_FRI("0010110", "화,수,금"),
MON_TUE_WED_FRI("0010111", "월,화,수,금"),
THU_FRI("0011000", "목,금"),
MON_THU_FRI("0011001", "월,목,금"),
TUE_THU_FRI("0011010", "화,목,금"),
MON_TUE_THU_FRI("0011011", "월,화,목,금"),
WED_THU_FRI("0011100", "수,목,금"),
MON_WED_THU_FRI("0011101", "월,수,목,금"),
TUE_WED_THU_FRI("0011110", "화,수,목,금"),
MON_TUE_WED_THU_FRI("0011111", "월,화,수,목,금"),
SAT("0100000", ""),
MON_SAT("0100001", "월,토"),
TUE_SAT("0100010", "화,토"),
MON_TUE_SAT("0100011", "월,화,토"),
WED_SAT("0100100", "수,토"),
MON_WED_SAT("0100101", "월,수,토"),
TUE_WED_SAT("0100110", "화,수,토"),
MON_TUE_WED_SAT("0100111", "월,화,수,토"),
THU_SAT("0101000", "목,토"),
MON_THU_SAT("0101001", "월,목,토"),
TUE_THU_SAT("0101010", "화,목,토"),
MON_TUE_THU_SAT("0101011", "월,화,목,토"),
WED_THU_SAT("0101100", "수,목,토"),
MON_WED_THU_SAT("0101101", "월,수,목,토"),
TUE_WED_THU_SAT("0101110", "화,수,목,토"),
MON_TUE_WED_THU_SAT("0101111", "월,화,수,목,토"),
FRI_SAT("0110000", "금,토"),
MON_FRI_SAT("0110001", "월,금,토"),
TUE_FRI_SAT("0110010", "화,금,토"),
MON_TUE_FRI_SAT("0110011", "월,화,금,토"),
WED_FRI_SAT("0110100", "수,금,토"),
MON_WED_FRI_SAT("0110101", "월,수,금,토"),
TUE_WED_FRI_SAT("0110110", "화,수,금,토"),
MON_TUE_WED_FRI_SAT("0110111", "월,화,수,금,토"),
THU_FRI_SAT("0111000", "목,금,토"),
MON_THU_FRI_SAT("0111001", "월,목,금,토"),
TUE_THU_FRI_SAT("0111010", "화,목,금,토"),
MON_TUE_THU_FRI_SAT("0111011", "월,화,목,금,토"),
WED_THU_FRI_SAT("0111100", "수,목,금,토"),
MON_WED_THU_FRI_SAT("0111101", "월,수,목,금,토"),
TUE_WED_THU_FRI_SAT("0111110", "화,수,목,금,토"),
MON_TUE_WED_THU_FRI_SAT("0111111", "월,화,수,목,금,토"),
SUN("1000000", ""),
MON_SUN("1000001", "월,일"),
TUE_SUN("1000010", "화,일"),
MON_TUE_SUN("1000011", "월,화,일"),
WED_SUN("1000100", "수,일"),
MON_WED_SUN("1000101", "월,수,일"),
TUE_WED_SUN("1000110", "화,수,일"),
MON_TUE_WED_SUN("1000111", "월,화,수,일"),
THU_SUN("1001000", "목,일"),
MON_THU_SUN("1001001", "월,목,일"),
TUE_THU_SUN("1001010", "화,목,일"),
MON_TUE_THU_SUN("1001011", "월,화,목,일"),
WED_THU_SUN("1001100", "수,목,일"),
MON_WED_THU_SUN("1001101", "월,수,목,일"),
TUE_WED_THU_SUN("1001110", "화,수,목,일"),
MON_TUE_WED_THU_SUN("1001111", "월,화,수,목,일"),
FRI_SUN("1010000", "금,일"),
MON_FRI_SUN("1010001", "월,금,일"),
TUE_FRI_SUN("1010010", "화,금,일"),
MON_TUE_FRI_SUN("1010011", "월,화,금,일"),
WED_FRI_SUN("1010100", "수,금,일"),
MON_WED_FRI_SUN("1010101", "월,수,금,일"),
TUE_WED_FRI_SUN("1010110", "화,수,금,일"),
MON_TUE_WED_FRI_SUN("1010111", "월,화,수,금,일"),
THU_FRI_SUN("1011000", "목,금,일"),
MON_THU_FRI_SUN("1011001", "월,목,금,일"),
TUE_THU_FRI_SUN("1011010", "화,목,금,일"),
MON_TUE_THU_FRI_SUN("1011011", "월,화,목,금,일"),
WED_THU_FRI_SUN("1011100", "수,목,금,일"),
MON_WED_THU_FRI_SUN("1011101", "월,수,목,금,일"),
TUE_WED_THU_FRI_SUN("1011110", "화,수,목,금,일"),
MON_TUE_WED_THU_FRI_SUN("1011111", "월,화,수,목,금,일"),
SAT_SUN("1100000", "토,일"),
MON_SAT_SUN("1100001", "월,토,일"),
TUE_SAT_SUN("1100010", "화,토,일"),
MON_TUE_SAT_SUN("1100011", "월,화,토,일"),
WED_SAT_SUN("1100100", "수,토,일"),
MON_WED_SAT_SUN("1100101", "월,수,토,일"),
TUE_WED_SAT_SUN("1100110", "화,수,토,일"),
MON_TUE_WED_SAT_SUN("1100111", "월,화,수,토,일"),
THU_SAT_SUN("1101000", "목,토,일"),
MON_THU_SAT_SUN("1101001", "월,목,토,일"),
TUE_THU_SAT_SUN("1101010", "화,목,토,일"),
MON_TUE_THU_SAT_SUN("1101011", "월,화,목,토,일"),
WED_THU_SAT_SUN("1101100", "수,목,토,일"),
MON_WED_THU_SAT_SUN("1101101", "월,수,목,토,일"),
TUE_WED_THU_SAT_SUN("1101110", "화,수,목,토,일"),
MON_TUE_WED_THU_SAT_SUN("1101111", "월,화,수,목,토,일"),
FRI_SAT_SUN("1110000", "금,토,일"),
MON_FRI_SAT_SUN("1110001", "월,금,토,일"),
TUE_FRI_SAT_SUN("1110010", "화,금,토,일"),
MON_TUE_FRI_SAT_SUN("1110011", "월,화,금,토,일"),
WED_FRI_SAT_SUN("1110100", "수,금,토,일"),
MON_WED_FRI_SAT_SUN("1110101", "월,수,금,토,일"),
TUE_WED_FRI_SAT_SUN("1110110", "화,수,금,토,일"),
MON_TUE_WED_FRI_SAT_SUN("1110111", "월,화,수,금,토,일"),
THU_FRI_SAT_SUN("1111000", "목,금,토,일"),
MON_THU_FRI_SAT_SUN("1111001", "월,목,금,토,일"),
TUE_THU_FRI_SAT_SUN("1111010", "화,목,금,토,일"),
MON_TUE_THU_FRI_SAT_SUN("1111011", "월,화,목,금,토,일"),
WED_THU_FRI_SAT_SUN("1111100", "수,목,금,토,일"),
MON_WED_THU_FRI_SAT_SUN("1111101", "월,수,목,금,토,일"),
TUE_WED_THU_FRI_SAT_SUN("1111110", "화,수,목,금,토,일"),
MON_TUE_WED_THU_FRI_SAT_SUN("1111111", "월,화,수,목,금,토,일"),
;
companion object {
fun fromCode(code: String): DayCode {
return entries.first { it.code == code }
}
}
}

0 comments on commit 9fbc7ff

Please sign in to comment.