From cf16ea58d1790d22a17331b9a19c54f60ee374d7 Mon Sep 17 00:00:00 2001 From: Minseok <93303181+emes-g@users.noreply.github.com> Date: Tue, 20 Aug 2024 14:09:44 +0900 Subject: [PATCH] =?UTF-8?q?Feat:=208=EC=9B=94=204=EC=A3=BC=EC=B0=A8=20?= =?UTF-8?q?=EB=9E=AD=ED=82=B9=20=EC=88=98=EB=8F=99=20=EB=B0=98=EC=98=81=20?= =?UTF-8?q?(#153)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 매주 월요일 18시에 기본으로 진행되지만, 이번 주만 월, 화요일을 바탕으로 주간 랭킹 생성 --- src/main/java/store/itpick/backend/util/DateUtils.java | 6 ++++++ src/main/java/store/itpick/backend/util/Redis.java | 8 +++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/java/store/itpick/backend/util/DateUtils.java b/src/main/java/store/itpick/backend/util/DateUtils.java index 6f7eae7..88e285e 100644 --- a/src/main/java/store/itpick/backend/util/DateUtils.java +++ b/src/main/java/store/itpick/backend/util/DateUtils.java @@ -29,6 +29,12 @@ public static LocalDate getMondayOfPreviousWeek() { return aWeekAgo.minusDays(diffFromMonday); } + public static LocalDate getMondayOfThisWeek() { + LocalDate thisWeek = LocalDate.now(); + int diffFromMonday = thisWeek.getDayOfWeek().getValue() - 1; // 월요일 0, 화요일 1, ..., 일요일 6 + return thisWeek.minusDays(diffFromMonday); + } + public static LocalDate stringToLocalDate(String date) { int year = Integer.parseInt("20" + date.substring(0, 2)); int month = Integer.parseInt(date.substring(2, 4)); diff --git a/src/main/java/store/itpick/backend/util/Redis.java b/src/main/java/store/itpick/backend/util/Redis.java index 5e9f79c..137e525 100644 --- a/src/main/java/store/itpick/backend/util/Redis.java +++ b/src/main/java/store/itpick/backend/util/Redis.java @@ -61,10 +61,11 @@ public void saveDay() { public void saveWeek() { ZSetOperations zSetOperations = redisTemplate.opsForZSet(); - LocalDate mondayOfPreviousWeek = DateUtils.getMondayOfPreviousWeek(); // 지난주 월요일 +// LocalDate mondayOfPreviousWeek = DateUtils.getMondayOfPreviousWeek(); // 지난주 월요일 + LocalDate mondayOfPreviousWeek = DateUtils.getMondayOfThisWeek(); // 이번주 월요일 DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyMMdd"); List> dayKeyListOfPreviousWeek = new ArrayList<>(); - for (int i = 0; i < 7; i++) { + for (int i = 0; i < 2; i++) { // 월, 화만 LocalDate dayOfPreviousWeek = mondayOfPreviousWeek.plusDays(i); // 지난주 월요일부터 일요일까지 // 해당 날짜의 모든 커뮤니티의 키를 담고 있는 리스트 @@ -97,7 +98,8 @@ public void saveTotalRanking(PeriodType periodType) { String date = switch (periodType) { case BY_REAL_TIME -> "not needed"; case BY_DAY -> DateUtils.localDateToString(LocalDate.now()); - case BY_WEEK -> DateUtils.localDateToString(DateUtils.getMondayOfPreviousWeek()); +// case BY_WEEK -> DateUtils.localDateToString(DateUtils.getMondayOfPreviousWeek()); + case BY_WEEK -> DateUtils.localDateToString(DateUtils.getMondayOfThisWeek()); }; String totalKey = makeKey(CommunityType.TOTAL, periodType, date); redisTemplate.delete(totalKey); // (혹시 존재했을지 모르는) 기존 키 삭제