diff --git a/src/main/java/com/umc/mada/auth/service/CustomUserDetailService.java b/src/main/java/com/umc/mada/auth/service/CustomUserDetailService.java index 2200933..4d96759 100644 --- a/src/main/java/com/umc/mada/auth/service/CustomUserDetailService.java +++ b/src/main/java/com/umc/mada/auth/service/CustomUserDetailService.java @@ -105,6 +105,11 @@ private User createUser(OAuth2Attributes oAuth2Attributes, String authProvider){ } private void setUserData(User user){ + List customItems = customRepository.findAll(); + customItems.forEach(item->wearingItemRepository.save(WearingItem.builder().user(user).customItem(item).build())); + } + + private void setUserDataDefault(User user){ //사용자 캐릭터 디폴트 설정하기 List defaultItems = customRepository.findByUnlockCondition(CustomItem.ItemUnlockCondition.DEFAULT); @@ -112,11 +117,6 @@ private void setUserData(User user){ wearingItemRepository.save(WearingItem.builder().user(user).customItem(defaultItem).build()); } -// wearingItemRepository.save(WearingItem.builder().user(user).customItem(customRepository.findById(10L).orElseThrow(()-> new RuntimeException("기본 색상 ID가 없습니다."))).build()); -// wearingItemRepository.save(WearingItem.builder().user(user).customItem(customRepository.findById(48L).orElseThrow(()-> new RuntimeException("기본 색상 ID가 없습니다."))).build()); -// wearingItemRepository.save(WearingItem.builder().user(user).customItem(customRepository.findById(49L).orElseThrow(()-> new RuntimeException("기본 색상 ID가 없습니다."))).build()); -// wearingItemRepository.save(WearingItem.builder().user(user).customItem(customRepository.findById(50L).orElseThrow(()-> new RuntimeException("기본 색상 ID가 없습니다."))).build()); - //사용자 기본 제공 커스텀 아이템 세팅하기 List basicItems = customRepository.findByUnlockCondition(CustomItem.ItemUnlockCondition.BASIC); for(CustomItem basicItem : basicItems){ diff --git a/src/main/java/com/umc/mada/todo/repository/ChartRepository.java b/src/main/java/com/umc/mada/todo/repository/ChartRepository.java index b1c1306..b3f37c2 100644 --- a/src/main/java/com/umc/mada/todo/repository/ChartRepository.java +++ b/src/main/java/com/umc/mada/todo/repository/ChartRepository.java @@ -12,10 +12,10 @@ import java.util.List; public interface ChartRepository extends JpaRepository { - @Query(value = "select A.category_id as categoryId, A.category_name as categoryName, A.color, COUNT(A.category_name) as count, ROUND(COUNT(A.category_name) / (SELECT COUNT(*) FROM TODO WHERE user_id = :uid and complete = 1 and (date between :startDate and :endDate))*100, 0)as rate\n" + + @Query(value = "select A.category_id as categoryId, A.category_name as categoryName, A.color, COUNT(A.category_name) as count, ROUND(COUNT(A.category_name) / (SELECT COUNT(*) FROM TODO WHERE user_id = :uid and (date between :startDate and :endDate) and is_deleted = FALSE and complete = 1)*100, 0)as rate\n" + "from (select T.user_id, T.date, T.complete, C.category_name, C.id as category_id, C.color as color\n" + " from TODO T join CATEGORY C on C.id = T.category_id\n" + - " where T.user_id = :uid and (T.date between :startDate and :endDate)) A\n" + + " where T.user_id = :uid and (T.date between :startDate and :endDate) and T.is_deleted = FALSE) A\n" + "where A.complete = 1\n" + "GROUP BY A.category_id\n" + "ORDER BY rate DESC;", nativeQuery = true) @@ -24,14 +24,14 @@ public interface ChartRepository extends JpaRepository { @Query(value = "select COUNT(category_id) as count\n" + "from (select T.user_id, T.date, T.complete,C.id as category_id\n" + " from TODO T join CATEGORY C on C.id = T.category_id\n" + - " where T.user_id = :uid and (T.date between :startDate and :endDate)) A\n" + + " where T.user_id = :uid and (T.date between :startDate and :endDate) and T.is_deleted = FALSE) A\n" + "where user_id = :uid and category_id = :categoryId and date between :startDate and :endDate and complete = 1\n" + "GROUP BY category_id;", nativeQuery = true) PreviousCategoryStatisticsVO statisticsOnPreviousCategories(@Param("uid") Long uid, @Param("startDate") LocalDate startDate , @Param("endDate") LocalDate endDate, @Param("categoryId") int categoryId); @Query(value = "select date as todoDate, COUNT(*) as count\n" + "from TODO\n" + - "where user_id = :uid and date between :startDate and :endDate and complete = 1\n" + + "where user_id = :uid and date between :startDate and :endDate and is_deleted = FALSE and complete = 1\n" + "GROUP BY date\n" + "ORDER BY date desc;", nativeQuery = true) // @Query("select t.date, count(t) from Todo t where t.userId = :user and t.date between :startDate and :endDate and t.complete=true GROUP BY t.date order by t.date") @@ -41,7 +41,7 @@ public interface ChartRepository extends JpaRepository { @Query(value = "select A.date, COUNT(*) as count, ROUND(COUNT(*)/(select COUNT(*) as count from TODO T where T.user_id = :uid and T.date = A.date GROUP BY T.date)*100, 1) as rate\n" + "from TODO A\n" + - "where user_id = :uid and (A.date between :startDate and :endDate) and A.complete=1\n" + + "where user_id = :uid and (A.date between :startDate and :endDate) and is_deleted = FALSE and A.complete=1\n" + "group by A.date\n" + "order by A.date desc;", nativeQuery = true) List dayStatisticsOnAchievementRate(@Param("uid") Long uid, @Param("startDate") LocalDate startDate , @Param("endDate") LocalDate endDate); @@ -51,15 +51,15 @@ public interface ChartRepository extends JpaRepository { " DATE_FORMAT(T.date, '%Y%U') AS weekDate,\n" + " COUNT(T.id) as count, ROUND(COUNT(*)/(select COUNT(*) as count from TODO A where A.user_id = :uid and DATE_FORMAT(A.date, '%Y%U') = weekDate GROUP BY DATE_FORMAT(A.date, '%Y%U'))*100, 1) as rate\n" + "from TODO T\n" + - "where T.user_id = :uid and T.date between :startDate and :endDate and T.complete=1\n" + + "where T.user_id = :uid and T.date between :startDate and :endDate and T.is_deleted = FALSE and T.complete=1\n" + "GROUP BY weekDate\n" + "ORDER BY weekDate desc;", nativeQuery = true) List weeklyTodoBarGraphAndRateStatistics(@Param("uid") Long uid, @Param("startDate") LocalDate startDate , @Param("endDate") LocalDate endDate); @Query(value = "select DATE_FORMAT(A.date, '%Y-%m') AS monthDate, COUNT(*) as count, \n" + - " ROUND(COUNT(*)/(select COUNT(*) as count from TODO T where T.user_id = :uid and DATE_FORMAT(T.date, '%Y-%m') = monthDate GROUP BY DATE_FORMAT(T.date, '%Y-%m'))*100, 1) as rate\n" + + " ROUND(COUNT(*)/(select COUNT(*) as count from TODO T where T.user_id = :uid and DATE_FORMAT(T.date, '%Y-%m') = monthDate GROUP BY DATE_FORMAT(T.date, '%Y-%m') and T.is_deleted = FALSE)*100, 1) as rate\n" + "from TODO A\n" + - "where user_id = :uid and (A.date between :startDate and :endDate) and A.complete=1\n" + + "where user_id = :uid and (A.date between :startDate and :endDate) and is_deleted = FALSE and A.complete=1\n" + "group by monthDate\n" + "ORDER BY monthDate desc;", nativeQuery = true) List monthlyTodoBarGraphAndRateStatistics(@Param("uid") Long uid, @Param("startDate") LocalDate startDate , @Param("endDate") LocalDate endDate);