Skip to content

Commit

Permalink
Merge pull request #153 from MADA-UMC/develop
Browse files Browse the repository at this point in the history
refactor: 통계 오류 수정(삭제된 TODO도 보임) & 회원가입 시 아이템 다 주도록 수정
  • Loading branch information
yujiyea authored Oct 31, 2024
2 parents cc6deef + 81c9755 commit fa3d03a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,18 @@ private User createUser(OAuth2Attributes oAuth2Attributes, String authProvider){
}

private void setUserData(User user){
List<CustomItem> customItems = customRepository.findAll();
customItems.forEach(item->wearingItemRepository.save(WearingItem.builder().user(user).customItem(item).build()));
}

private void setUserDataDefault(User user){
//사용자 캐릭터 디폴트 설정하기
List<CustomItem> defaultItems = customRepository.findByUnlockCondition(CustomItem.ItemUnlockCondition.DEFAULT);

for(CustomItem defaultItem: defaultItems){
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<CustomItem> basicItems = customRepository.findByUnlockCondition(CustomItem.ItemUnlockCondition.BASIC);
for(CustomItem basicItem : basicItems){
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/com/umc/mada/todo/repository/ChartRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
import java.util.List;

public interface ChartRepository extends JpaRepository<Todo, Integer> {
@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)
Expand All @@ -24,14 +24,14 @@ public interface ChartRepository extends JpaRepository<Todo, Integer> {
@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")
Expand All @@ -41,7 +41,7 @@ public interface ChartRepository extends JpaRepository<Todo, Integer> {

@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<AchievementRateStatisticsVO> dayStatisticsOnAchievementRate(@Param("uid") Long uid, @Param("startDate") LocalDate startDate , @Param("endDate") LocalDate endDate);
Expand All @@ -51,15 +51,15 @@ public interface ChartRepository extends JpaRepository<Todo, Integer> {
" 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<WeeklyBarGraphAndRateStatisticsVO> 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<MonthlyBarGraphAndRateStatisticsVO> monthlyTodoBarGraphAndRateStatistics(@Param("uid") Long uid, @Param("startDate") LocalDate startDate , @Param("endDate") LocalDate endDate);
Expand Down

0 comments on commit fa3d03a

Please sign in to comment.