From 92168958461ef672a9ba4cba7a7c95e1d782e8ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=80=E1=85=AF=E1=86=AB=E1=84=83=E1=85=A5=E1=86=A8?= =?UTF-8?q?=E1=84=8C=E1=85=AE?= Date: Tue, 26 Dec 2023 23:33:39 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20BaseTimeEntity=20LocalDateTime=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD=EB=90=98=EC=96=B4=20=ED=95=B4?= =?UTF-8?q?=EB=8B=B9=20=EB=B3=80=EA=B2=BD=EB=B6=84=20=EB=B3=91=ED=95=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/catcher/datasource/user/UserJpaRepository.java | 10 ++++++++-- .../catcher/datasource/user/UserRepositoryImpl.java | 9 +++------ .../com/catcher/infrastructure/utils/CriteriaUtil.java | 7 +++---- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/catcher/datasource/user/UserJpaRepository.java b/src/main/java/com/catcher/datasource/user/UserJpaRepository.java index 20ac31b..9a136f5 100644 --- a/src/main/java/com/catcher/datasource/user/UserJpaRepository.java +++ b/src/main/java/com/catcher/datasource/user/UserJpaRepository.java @@ -8,6 +8,8 @@ import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; +import java.time.LocalDateTime; +import java.time.ZoneId; import java.time.ZonedDateTime; import java.util.List; import java.util.Map; @@ -25,7 +27,7 @@ public interface UserJpaRepository extends JpaRepository { "FROM User u " + "WHERE u.createdAt BETWEEN :startDate AND :endDate " + "GROUP BY date(u.createdAt)") - List> countNewUsersPerDay(@Param("startDate") ZonedDateTime startDate, @Param("endDate") ZonedDateTime endDate); + List> countNewUsersPerDay(@Param("startDate") LocalDateTime startDate, @Param("endDate") LocalDateTime endDate); @Query("SELECT new map(date(u.createdAt) as date, COUNT(u) as count) " + "FROM User u " + @@ -33,12 +35,16 @@ public interface UserJpaRepository extends JpaRepository { "GROUP BY date(u.createdAt)") List> countDeletedUsersPerDay(@Param("startDate") ZonedDateTime startDate, @Param("endDate") ZonedDateTime endDate); + default List> countDeletedUsersPerDay(@Param("startDate") LocalDateTime startDate, @Param("endDate") LocalDateTime endDate) { + return countDeletedUsersPerDay(startDate.atZone(ZoneId.systemDefault()), endDate.atZone(ZoneId.systemDefault())); + } + @Query("SELECT new map(date(ush.createdAt) as date, COUNT(DISTINCT u) as count) " + "FROM UserStatusChangeHistory ush " + "JOIN ush.user u " + "WHERE ush.createdAt BETWEEN :startDate AND :endDate " + "AND ush.action = com.catcher.core.domain.UserStatus.REPORTED " + "GROUP BY date(ush.createdAt)") - List> countReportedUsersPerDay(@Param("startDate") ZonedDateTime startDate, @Param("endDate") ZonedDateTime endDate); + List> countReportedUsersPerDay(@Param("startDate") LocalDateTime startDate, @Param("endDate") LocalDateTime endDate); } diff --git a/src/main/java/com/catcher/datasource/user/UserRepositoryImpl.java b/src/main/java/com/catcher/datasource/user/UserRepositoryImpl.java index e5c069f..e835a95 100644 --- a/src/main/java/com/catcher/datasource/user/UserRepositoryImpl.java +++ b/src/main/java/com/catcher/datasource/user/UserRepositoryImpl.java @@ -10,10 +10,7 @@ import org.springframework.data.jpa.domain.Specification; import org.springframework.stereotype.Repository; -import java.time.LocalDate; -import java.time.LocalTime; -import java.time.ZoneId; -import java.time.ZonedDateTime; +import java.time.*; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -72,7 +69,7 @@ private Map initMap(final LocalDate startDate, final LocalDate end */ private Map returnMap(final LocalDate startDate, final LocalDate endDate, GroupedByDateQueryFunction groupedByDateQueryFunction) { final var resultMap = initMap(startDate, endDate); - final List> queryResults = groupedByDateQueryFunction.apply(startDate.atStartOfDay(ZoneId.systemDefault()), endDate.atTime(LocalTime.MAX).atZone(ZoneId.systemDefault())); + final List> queryResults = groupedByDateQueryFunction.apply(startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX)); queryResults.forEach(result -> { resultMap.put(result.get("date").toString(), (Long) result.get("count")); @@ -83,7 +80,7 @@ private Map returnMap(final LocalDate startDate, final LocalDate e @FunctionalInterface public interface GroupedByDateQueryFunction { - List> apply(ZonedDateTime start, ZonedDateTime end); + List> apply(LocalDateTime start, LocalDateTime end); } @Override diff --git a/src/main/java/com/catcher/infrastructure/utils/CriteriaUtil.java b/src/main/java/com/catcher/infrastructure/utils/CriteriaUtil.java index 7c92d6f..9c7c488 100644 --- a/src/main/java/com/catcher/infrastructure/utils/CriteriaUtil.java +++ b/src/main/java/com/catcher/infrastructure/utils/CriteriaUtil.java @@ -6,7 +6,6 @@ import java.time.LocalDate; import java.time.LocalTime; -import java.time.ZoneId; import java.util.ArrayList; import java.util.List; @@ -25,9 +24,9 @@ public static Specification generateQueryBuilder(final GeneralSearchFilte if (startDate != null && endDate != null) { predicates.add(criteriaBuilder.between( root.get(DEFAULT_SEARCH_DATE_COLUMN), - startDate.atStartOfDay(ZoneId.systemDefault()), - endDate.atTime(LocalTime.MAX).atZone(ZoneId.systemDefault()) - )); + startDate.atStartOfDay(), + endDate.atTime(LocalTime.MAX)) + ); } return criteriaBuilder.and(predicates.toArray(new Predicate[0]));