From f9cacef7be724a37c579afdb4e3f7796aa329829 Mon Sep 17 00:00:00 2001 From: tlarbals824 Date: Mon, 25 Dec 2023 21:46:15 +0900 Subject: [PATCH 1/4] =?UTF-8?q?PET-278=20fix=20:=20=ED=81=AC=EB=A6=AC?= =?UTF-8?q?=EC=8A=A4=EB=A7=88=EC=8A=A4=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=A2=85=EB=A3=8C=20=EB=82=A0=EC=A7=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/pawith/event/christmas/ChristmasEventCloseHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Event/src/main/java/com/pawith/event/christmas/ChristmasEventCloseHandler.java b/Event/src/main/java/com/pawith/event/christmas/ChristmasEventCloseHandler.java index e56a9dfa..12252d7f 100644 --- a/Event/src/main/java/com/pawith/event/christmas/ChristmasEventCloseHandler.java +++ b/Event/src/main/java/com/pawith/event/christmas/ChristmasEventCloseHandler.java @@ -15,7 +15,7 @@ @Component public class ChristmasEventCloseHandler extends AbstractBatchSchedulingHandler { private static final Integer BATCH_SIZE = 100; - private static final String CRON_EXPRESSION = "0 0 0 26 12 *"; + private static final String CRON_EXPRESSION = "0 0 0 2 1 *"; private final ChristmasCategoryRepository christmasCategoryRepository; private final CategoryRepository categoryRepository; From b0d0f1a1e2449244cc248160e8f6035ab0ba5ded Mon Sep 17 00:00:00 2001 From: tlarbals824 Date: Mon, 25 Dec 2023 21:50:22 +0900 Subject: [PATCH 2/4] =?UTF-8?q?PET-278=20fix=20:=20=ED=81=AC=EB=A6=AC?= =?UTF-8?q?=EC=8A=A4=EB=A7=88=EC=8A=A4=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20?= =?UTF-8?q?=EA=B8=B0=EA=B0=84=20=EC=97=B0=EC=9E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pawith/event/christmas/ChristmasEventService.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Event/src/main/java/com/pawith/event/christmas/ChristmasEventService.java b/Event/src/main/java/com/pawith/event/christmas/ChristmasEventService.java index 18169eb4..d282ed0f 100644 --- a/Event/src/main/java/com/pawith/event/christmas/ChristmasEventService.java +++ b/Event/src/main/java/com/pawith/event/christmas/ChristmasEventService.java @@ -21,7 +21,14 @@ public class ChristmasEventService { private static final List EVENT_TODO_SCHEDULED_DATE_LIST = List.of( LocalDate.of(2023, 12, 23), LocalDate.of(2023, 12, 24), - LocalDate.of(2023, 12, 25) + LocalDate.of(2023, 12, 25), + LocalDate.of(2023, 12, 26), + LocalDate.of(2023, 12, 27), + LocalDate.of(2023, 12, 28), + LocalDate.of(2023, 12, 29), + LocalDate.of(2023, 12, 30), + LocalDate.of(2023, 12, 31), + LocalDate.of(2024, 1, 1) ); From 489a96ce1d4ec364ca5c8d05636b7c29895a05d3 Mon Sep 17 00:00:00 2001 From: tlarbals824 Date: Mon, 25 Dec 2023 22:06:01 +0900 Subject: [PATCH 3/4] =?UTF-8?q?PET-278=20fix=20:=20=ED=81=AC=EB=A6=AC?= =?UTF-8?q?=EC=8A=A4=EB=A7=88=EC=8A=A4=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20?= =?UTF-8?q?=EA=B8=B0=EA=B0=84=20=EB=A1=9C=EC=A7=81=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../christmas/ChristmasEventService.java | 22 ++++++------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/Event/src/main/java/com/pawith/event/christmas/ChristmasEventService.java b/Event/src/main/java/com/pawith/event/christmas/ChristmasEventService.java index d282ed0f..0558954c 100644 --- a/Event/src/main/java/com/pawith/event/christmas/ChristmasEventService.java +++ b/Event/src/main/java/com/pawith/event/christmas/ChristmasEventService.java @@ -18,19 +18,8 @@ public class ChristmasEventService { private static final String EVENT_CATEGORY_NAME = "크리스마스"; private static final String EVENT_TODO_DESCRIPTION = "포잇스마스 이벤트 참여하기"; - private static final List EVENT_TODO_SCHEDULED_DATE_LIST = List.of( - LocalDate.of(2023, 12, 23), - LocalDate.of(2023, 12, 24), - LocalDate.of(2023, 12, 25), - LocalDate.of(2023, 12, 26), - LocalDate.of(2023, 12, 27), - LocalDate.of(2023, 12, 28), - LocalDate.of(2023, 12, 29), - LocalDate.of(2023, 12, 30), - LocalDate.of(2023, 12, 31), - LocalDate.of(2024, 1, 1) - ); - + private static final LocalDate EVENT_START_DATE = LocalDate.of(2023, 12, 23); + private static final LocalDate EVENT_END_DATE = LocalDate.of(2024, 1, 2); private static final Long EVENT_CREATOR_ID = -1L; private final CategoryRepository categoryRepository; @@ -54,7 +43,9 @@ public void publishEvent(TodoTeam todoTeam){ final List allRegisters = registerRepository.findAllByTodoTeamId(todoTeam.getId()); final List eventTodoList = new ArrayList<>(); final List eventAssignList = new ArrayList<>(); - EVENT_TODO_SCHEDULED_DATE_LIST + + final List eventDateList = EVENT_START_DATE.datesUntil(EVENT_END_DATE).toList(); + eventDateList .forEach(eventDate -> { final Todo todo = Todo.builder() .category(saved) @@ -91,7 +82,8 @@ public void addNewRegisterAtChristmasEventTodo(Long todoTeamId, Long userId){ } public Boolean isEventDay(){ - return EVENT_TODO_SCHEDULED_DATE_LIST.contains(LocalDate.now()); + final LocalDate now = LocalDate.now(); + return now.isAfter(EVENT_START_DATE) && now.isBefore(EVENT_END_DATE); } } From 80db66ebe467d32b6437a87597ab3593ae601cc4 Mon Sep 17 00:00:00 2001 From: tlarbals824 Date: Mon, 25 Dec 2023 22:51:08 +0900 Subject: [PATCH 4/4] =?UTF-8?q?PET-278=20feat=20:=20=ED=81=AC=EB=A6=AC?= =?UTF-8?q?=EC=8A=A4=EB=A7=88=EC=8A=A4=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20?= =?UTF-8?q?=ED=88=AC=EB=91=90=20=EC=B6=94=EA=B0=80=20=EC=83=9D=EC=84=B1=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../christmas/ChristmasEventService.java | 46 ++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/Event/src/main/java/com/pawith/event/christmas/ChristmasEventService.java b/Event/src/main/java/com/pawith/event/christmas/ChristmasEventService.java index 0558954c..d3106ecc 100644 --- a/Event/src/main/java/com/pawith/event/christmas/ChristmasEventService.java +++ b/Event/src/main/java/com/pawith/event/christmas/ChristmasEventService.java @@ -3,9 +3,13 @@ import com.pawith.event.christmas.entity.ChristmasCategory; import com.pawith.event.christmas.repository.ChristmasCategoryRepository; import com.pawith.tododomain.entity.*; -import com.pawith.tododomain.repository.*; +import com.pawith.tododomain.repository.AssignRepository; +import com.pawith.tododomain.repository.CategoryRepository; +import com.pawith.tododomain.repository.RegisterRepository; +import com.pawith.tododomain.repository.TodoRepository; import com.pawith.tododomain.service.RegisterQueryService; import lombok.RequiredArgsConstructor; +import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; @@ -81,6 +85,46 @@ public void addNewRegisterAtChristmasEventTodo(Long todoTeamId, Long userId){ }); } + @Scheduled(cron = "0 0 0 26 12 *") + public void addNewTodoAtChristmasEventCategory(){ + final List allChristmasCategory = christmasCategoryRepository.findAll(); + List todoList = new ArrayList<>(); + List assignList = new ArrayList<>(); + allChristmasCategory.forEach(christmasCategory ->{ + final Long categoryId = christmasCategory.getCategoryId(); + categoryRepository.findById(categoryId).ifPresent(category -> { + final List eventDateList = new ArrayList<>(EVENT_START_DATE.datesUntil(EVENT_END_DATE).toList()); + final TodoTeam todoTeam = category.getTodoTeam(); + final List allRegisters = registerRepository.findAllByTodoTeamId(todoTeam.getId()); + todoRepository.findTodoListByCreatorIdAndTodoTeamIdQuery(EVENT_CREATOR_ID, todoTeam.getId()) + .forEach(todo -> { + final LocalDate scheduledDate = todo.getScheduledDate(); + eventDateList.remove(scheduledDate); + }); + + eventDateList.forEach(eventDate -> { + final Todo todo = Todo.builder() + .category(category) + .creatorId(EVENT_CREATOR_ID) + .description(EVENT_TODO_DESCRIPTION) + .scheduledDate(eventDate) + .build(); + todoList.add(todo); + List allAssign = allRegisters.stream() + .filter(Register::isRegistered) + .map(register -> Assign.builder() + .todo(todo) + .register(register) + .build()) + .toList(); + assignList.addAll(allAssign); + }); + }); + }); + todoRepository.saveAll(todoList); + assignRepository.saveAll(assignList); + } + public Boolean isEventDay(){ final LocalDate now = LocalDate.now(); return now.isAfter(EVENT_START_DATE) && now.isBefore(EVENT_END_DATE);