From 5dfacdc8daad568f435476529fecdbfe7d0b8356 Mon Sep 17 00:00:00 2001 From: yujiyea Date: Thu, 31 Oct 2024 23:34:00 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=ED=86=B5=EA=B3=84=20=EC=98=A4?= =?UTF-8?q?=EB=A5=98=20=EC=88=98=EC=A0=95(=EC=82=AD=EC=A0=9C=EB=90=9C=20TO?= =?UTF-8?q?DO=EB=8F=84=20=EB=B3=B4=EC=9E=84)=20&=20=ED=9A=8C=EC=9B=90?= =?UTF-8?q?=EA=B0=80=EC=9E=85=20=EC=8B=9C=20=EC=95=84=EC=9D=B4=ED=85=9C=20?= =?UTF-8?q?=EB=8B=A4=20=EC=A3=BC=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/service/CustomUserDetailService.java | 10 +++++----- .../mada/todo/repository/ChartRepository.java | 16 ++++++++-------- 2 files changed, 13 insertions(+), 13 deletions(-) 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);