Skip to content

Commit

Permalink
fix: BaseTimeEntity LocalDateTime으로 변경되어 해당 변경분 병합
Browse files Browse the repository at this point in the history
  • Loading branch information
권덕주 committed Dec 26, 2023
1 parent 3d5d866 commit 9216895
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
10 changes: 8 additions & 2 deletions src/main/java/com/catcher/datasource/user/UserJpaRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,20 +27,24 @@ public interface UserJpaRepository extends JpaRepository<User, Long> {
"FROM User u " +
"WHERE u.createdAt BETWEEN :startDate AND :endDate " +
"GROUP BY date(u.createdAt)")
List<Map<String, Object>> countNewUsersPerDay(@Param("startDate") ZonedDateTime startDate, @Param("endDate") ZonedDateTime endDate);
List<Map<String, Object>> 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 " +
"WHERE u.deletedAt BETWEEN :startDate AND :endDate " +
"GROUP BY date(u.createdAt)")
List<Map<String, Object>> countDeletedUsersPerDay(@Param("startDate") ZonedDateTime startDate, @Param("endDate") ZonedDateTime endDate);

default List<Map<String, Object>> 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<Map<String, Object>> countReportedUsersPerDay(@Param("startDate") ZonedDateTime startDate, @Param("endDate") ZonedDateTime endDate);
List<Map<String, Object>> countReportedUsersPerDay(@Param("startDate") LocalDateTime startDate, @Param("endDate") LocalDateTime endDate);

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -72,7 +69,7 @@ private Map<String, Long> initMap(final LocalDate startDate, final LocalDate end
*/
private Map<String, Long> returnMap(final LocalDate startDate, final LocalDate endDate, GroupedByDateQueryFunction groupedByDateQueryFunction) {
final var resultMap = initMap(startDate, endDate);
final List<Map<String, Object>> queryResults = groupedByDateQueryFunction.apply(startDate.atStartOfDay(ZoneId.systemDefault()), endDate.atTime(LocalTime.MAX).atZone(ZoneId.systemDefault()));
final List<Map<String, Object>> queryResults = groupedByDateQueryFunction.apply(startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));

queryResults.forEach(result -> {
resultMap.put(result.get("date").toString(), (Long) result.get("count"));
Expand All @@ -83,7 +80,7 @@ private Map<String, Long> returnMap(final LocalDate startDate, final LocalDate e

@FunctionalInterface
public interface GroupedByDateQueryFunction {
List<Map<String, Object>> apply(ZonedDateTime start, ZonedDateTime end);
List<Map<String, Object>> apply(LocalDateTime start, LocalDateTime end);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import java.time.LocalDate;
import java.time.LocalTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -25,9 +24,9 @@ public static <T> Specification<T> 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]));
Expand Down

0 comments on commit 9216895

Please sign in to comment.