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]));