From 7f44b48f0b5c4d16e166d97e78d73d261b0167d5 Mon Sep 17 00:00:00 2001 From: Jong1 <44349716+donsonioc2010@users.noreply.github.com> Date: Mon, 18 Sep 2023 12:31:30 +0900 Subject: [PATCH] [feat] Schedular Sample (#31) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore : HTML Library추가 - FontAwesome * feat : 경매 시작, 종료 Scheduler 구현 완료 - 현재 주입받아야할 메일, 그림관련 기능이 없어 실행되는 스케쥴링만 구현 완료 --- .../java/picasso/server/api/Application.java | 3 ++ .../scheduler/EndAuctionScheduler.java | 29 +++++++++++++++++++ .../scheduler/StartAuctionScheduler.java | 29 +++++++++++++++++++ .../resources/templates/fragment/config.html | 3 ++ .../common/util/DateStaticConstants.java | 5 ++++ 5 files changed, 69 insertions(+) create mode 100644 Api/src/main/java/picasso/server/api/auction/scheduler/EndAuctionScheduler.java create mode 100644 Api/src/main/java/picasso/server/api/auction/scheduler/StartAuctionScheduler.java create mode 100644 Common/src/main/java/picasso/server/common/util/DateStaticConstants.java diff --git a/Api/src/main/java/picasso/server/api/Application.java b/Api/src/main/java/picasso/server/api/Application.java index f6ae922e..cdea10be 100644 --- a/Api/src/main/java/picasso/server/api/Application.java +++ b/Api/src/main/java/picasso/server/api/Application.java @@ -7,11 +7,14 @@ import org.springframework.boot.autoconfigure.domain.EntityScan; import org.springframework.context.annotation.ComponentScan; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; +import org.springframework.scheduling.annotation.EnableScheduling; + // EnableJpaRepositories Reference : https://stackoverflow.com/questions/46732402/spring-boot-autowiring-of-beans-is-not-working-in-maven-multi-module-project @Slf4j @EntityScan("picasso.server.domain") @ComponentScan(basePackages = {"picasso.server"}) @EnableJpaRepositories(basePackages = {"picasso.server.domain"}) +@EnableScheduling // Schedule사용을 위한 Annotation @SpringBootApplication @RequiredArgsConstructor public class Application { diff --git a/Api/src/main/java/picasso/server/api/auction/scheduler/EndAuctionScheduler.java b/Api/src/main/java/picasso/server/api/auction/scheduler/EndAuctionScheduler.java new file mode 100644 index 00000000..fc4dbf67 --- /dev/null +++ b/Api/src/main/java/picasso/server/api/auction/scheduler/EndAuctionScheduler.java @@ -0,0 +1,29 @@ +package picasso.server.api.auction.scheduler; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; +import picasso.server.common.util.DateStaticConstants; + +import java.time.LocalDate; + +/** + * 18시에 경매 전 상태인 게시물들을 처리하는 스케쥴러 + */ + +@Slf4j +@Component +@EnableAsync +@RequiredArgsConstructor +public class EndAuctionScheduler { + @Scheduled(cron = "0 0 18 * * *", zone = DateStaticConstants.ZONE_SEOUL) + public void startAuction() { + log.info("End Todays Auctions Open : TodayDate >>> {}", LocalDate.now()); + + // TODO : 입찰자가 존재하는 경우 입찰 안내 메일 발송 로직 추가 및 상태값 변경 + + // TODO : 입찰자가 존재하지 않는 경우 유찰 안내 메일 발송 로직 추가 및 상태값 변경 + } +} diff --git a/Api/src/main/java/picasso/server/api/auction/scheduler/StartAuctionScheduler.java b/Api/src/main/java/picasso/server/api/auction/scheduler/StartAuctionScheduler.java new file mode 100644 index 00000000..c4ee6f6a --- /dev/null +++ b/Api/src/main/java/picasso/server/api/auction/scheduler/StartAuctionScheduler.java @@ -0,0 +1,29 @@ +package picasso.server.api.auction.scheduler; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; +import picasso.server.common.util.DateStaticConstants; + +import java.time.LocalDate; + +/** + * 9시에 경매 전 상태인 게시물들을 처리하는 스케쥴러 + */ + +@Slf4j +@Component +@EnableAsync +@RequiredArgsConstructor +public class StartAuctionScheduler { + + @Scheduled(cron = "0 0 9 * * *", zone = DateStaticConstants.ZONE_SEOUL) + public void startAuction() { + log.info("Starting Todays Auctions Open : TodayDate >>> {}", LocalDate.now()); + // TODO : 관리자 승인된 게시물 경매 시작 상태로 Status 변경 로직 추가 + + // TODO : 관리자 승인이 되지 않은 게시물 유찰상태로 변경Status로직 추가 및 메일발송 로직 추가 + } +} diff --git a/Api/src/main/resources/templates/fragment/config.html b/Api/src/main/resources/templates/fragment/config.html index 3ee1599f..533b93da 100644 --- a/Api/src/main/resources/templates/fragment/config.html +++ b/Api/src/main/resources/templates/fragment/config.html @@ -20,6 +20,9 @@ + + + Picasso diff --git a/Common/src/main/java/picasso/server/common/util/DateStaticConstants.java b/Common/src/main/java/picasso/server/common/util/DateStaticConstants.java new file mode 100644 index 00000000..27183e3f --- /dev/null +++ b/Common/src/main/java/picasso/server/common/util/DateStaticConstants.java @@ -0,0 +1,5 @@ +package picasso.server.common.util; + +public class DateStaticConstants { + public static final String ZONE_SEOUL = "Asia/Seoul"; +}