diff --git a/pass-batch/build.gradle b/pass-batch/build.gradle index 56976e95..e0fccaec 100644 --- a/pass-batch/build.gradle +++ b/pass-batch/build.gradle @@ -32,6 +32,8 @@ dependencies { implementation 'org.mapstruct:mapstruct:1.5.2.Final' annotationProcessor 'org.mapstruct:mapstruct-processor:1.5.2.Final' + implementation 'org.apache.commons:commons-lang3:3.12.0' + runtimeOnly 'com.h2database:h2' runtimeOnly 'com.mysql:mysql-connector-j' @@ -40,6 +42,7 @@ dependencies { testCompileOnly 'org.projectlombok:lombok' testAnnotationProcessor 'org.projectlombok:lombok' + testImplementation 'org.apache.commons:commons-lang3:3.12.0' } tasks.named('test') { diff --git a/pass-batch/src/main/java/com/example/passbatch/repository/notification/NotificationEntity.java b/pass-batch/src/main/java/com/example/passbatch/repository/notification/NotificationEntity.java new file mode 100644 index 00000000..edcf9e06 --- /dev/null +++ b/pass-batch/src/main/java/com/example/passbatch/repository/notification/NotificationEntity.java @@ -0,0 +1,27 @@ +package com.example.passbatch.repository.notification; + +import com.example.passbatch.repository.BaseEntity; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + +import javax.persistence.*; +import java.time.LocalDateTime; + +@Getter +@Setter +@ToString +@Entity +@Table(name = "notification") +public class NotificationEntity extends BaseEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) // 기본 키 생성을 DB에 위임합니다. (AUTO_INCREMENT) + private Integer notificationSeq; + private String uuid; + + private NotificationEvent event; + private String text; + private boolean sent; + private LocalDateTime sentAt; + +} \ No newline at end of file diff --git a/pass-batch/src/main/java/com/example/passbatch/repository/notification/NotificationEvent.java b/pass-batch/src/main/java/com/example/passbatch/repository/notification/NotificationEvent.java new file mode 100644 index 00000000..7346d55c --- /dev/null +++ b/pass-batch/src/main/java/com/example/passbatch/repository/notification/NotificationEvent.java @@ -0,0 +1,5 @@ +package com.example.passbatch.repository.notification; + +public enum NotificationEvent { + BEFORE_CLASS +} \ No newline at end of file diff --git a/pass-batch/src/main/java/com/example/passbatch/repository/notification/NotificationModelMapper.java b/pass-batch/src/main/java/com/example/passbatch/repository/notification/NotificationModelMapper.java new file mode 100644 index 00000000..54a339d4 --- /dev/null +++ b/pass-batch/src/main/java/com/example/passbatch/repository/notification/NotificationModelMapper.java @@ -0,0 +1,30 @@ +package com.example.passbatch.repository.notification; + +import com.example.passbatch.repository.booking.BookingEntity; +import com.example.passbatch.utils.LocalDateTimeUtils; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Named; +import org.mapstruct.ReportingPolicy; +import org.mapstruct.factory.Mappers; + +import java.time.LocalDateTime; + +// ReportingPolicy.IGNORE: 일치하지 않은 필드를 무시합니다. +@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE) +public interface NotificationModelMapper { + NotificationModelMapper INSTANCE = Mappers.getMapper(NotificationModelMapper.class); + + // 필드명이 같지 않거나 custom하게 매핑해주기 위해서는 @Mapping을 추가해주면 됩니다. + @Mapping(target = "uuid", source = "bookingEntity.userEntity.uuid") + @Mapping(target = "text", source = "bookingEntity.startedAt", qualifiedByName = "text") + NotificationEntity toNotificationEntity(BookingEntity bookingEntity, NotificationEvent event); + + // 알람 보낼 메시지 생성 + @Named("text") + default String text(LocalDateTime startedAt) { + return String.format("안녕하세요. %s 수업 시작합니다. 수업 전 출석 체크 부탁드립니다. \uD83D\uDE0A", LocalDateTimeUtils.format(startedAt)); + + } + +} \ No newline at end of file diff --git a/pass-batch/src/main/java/com/example/passbatch/repository/notification/NotificationRepository.java b/pass-batch/src/main/java/com/example/passbatch/repository/notification/NotificationRepository.java new file mode 100644 index 00000000..0e3eb341 --- /dev/null +++ b/pass-batch/src/main/java/com/example/passbatch/repository/notification/NotificationRepository.java @@ -0,0 +1,6 @@ +package com.example.passbatch.repository.notification; + +import org.springframework.data.jpa.repository.JpaRepository; + +public interface NotificationRepository extends JpaRepository { +} \ No newline at end of file diff --git a/pass-batch/src/main/java/com/example/passbatch/utils/LocalDateTimeUtils.java b/pass-batch/src/main/java/com/example/passbatch/utils/LocalDateTimeUtils.java new file mode 100644 index 00000000..0d9c6014 --- /dev/null +++ b/pass-batch/src/main/java/com/example/passbatch/utils/LocalDateTimeUtils.java @@ -0,0 +1,37 @@ +package com.example.passbatch.utils; + +import org.apache.commons.lang3.StringUtils; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.time.temporal.WeekFields; +import java.util.Locale; + +public class LocalDateTimeUtils { + public static final DateTimeFormatter YYYY_MM_DD_HH_MM = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); + public static final DateTimeFormatter YYYY_MM_DD = DateTimeFormatter.ofPattern("yyyyMMdd"); + + public static String format(final LocalDateTime localDateTime) { + return localDateTime.format(YYYY_MM_DD_HH_MM); + + } + + public static String format(final LocalDateTime localDateTime, DateTimeFormatter formatter) { + return localDateTime.format(formatter); + + } + + public static LocalDateTime parse(final String localDateTimeString) { + if (StringUtils.isBlank(localDateTimeString)) { + return null; + } + return LocalDateTime.parse(localDateTimeString, YYYY_MM_DD_HH_MM); + + } + + public static int getWeekOfYear(final LocalDateTime localDateTime) { + return localDateTime.get(WeekFields.of(Locale.KOREA).weekOfYear()); + + } + +} \ No newline at end of file