44import org .springframework .data .domain .Pageable ;
55import org .springframework .data .jpa .domain .Specification ;
66import org .springframework .data .jpa .repository .JpaRepository ;
7+ import org .springframework .data .jpa .repository .Query ;
8+ import org .springframework .data .repository .query .Param ;
79import store .lastdance .domain .expense .ExpenseAnalysisHistory ;
810import store .lastdance .domain .user .User ;
11+ import store .lastdance .dto .admin .ExpenseAnalyzerFeedbackStatsDTO ;
912
1013import java .time .LocalDateTime ;
1114import java .util .List ;
@@ -21,4 +24,46 @@ public interface ExpenseAnalysisHistoryRepository extends JpaRepository<ExpenseA
2124 List <ExpenseAnalysisHistory > findByCreatedAtBetween (LocalDateTime startDate , LocalDateTime endDate );
2225
2326 Page <ExpenseAnalysisHistory > findAll (Specification <ExpenseAnalysisHistory > spec , Pageable pageable );
24- }
27+
28+ @ Query ("SELECT new store.lastdance.dto.admin.ExpenseAnalyzerFeedbackStatsDTO(" +
29+ " COALESCE(SUM(CASE WHEN e.up = true OR e.down = true THEN 1 ELSE 0 END), 0L), " +
30+ " COALESCE(SUM(CASE WHEN e.up = true THEN 1 ELSE 0 END), 0L), " +
31+ " COALESCE(SUM(CASE WHEN e.down = true THEN 1 ELSE 0 END), 0L), " +
32+ " 0.0, " + // satisfactionRate will be calculated in service layer
33+ " null) " + // trends will be calculated in service layer
34+ "FROM ExpenseAnalysisHistory e" )
35+ ExpenseAnalyzerFeedbackStatsDTO getFeedbackStatsSummary ();
36+
37+ @ Query ("SELECT new store.lastdance.dto.admin.ExpenseAnalyzerFeedbackStatsDTO(" +
38+ " COALESCE(SUM(CASE WHEN e.up = true OR e.down = true THEN 1 ELSE 0 END), 0L), " +
39+ " COALESCE(SUM(CASE WHEN e.up = true THEN 1 ELSE 0 END), 0L), " +
40+ " COALESCE(SUM(CASE WHEN e.down = true THEN 1 ELSE 0 END), 0L), " +
41+ " 0.0, " + // satisfactionRate will be calculated in service layer
42+ " null) " + // trends will be calculated in service layer
43+ "FROM ExpenseAnalysisHistory e WHERE e.createdAt BETWEEN :startDate AND :endDate" )
44+ ExpenseAnalyzerFeedbackStatsDTO getFeedbackStatsSummaryBetween (@ Param ("startDate" ) LocalDateTime startDate , @ Param ("endDate" ) LocalDateTime endDate );
45+ @ Query ("SELECT new store.lastdance.dto.admin.FeedbackTrendDTO(" +
46+ " YEAR(e.createdAt), " +
47+ " MONTH(e.createdAt), " +
48+ " DAY(e.createdAt), " +
49+ " COUNT(e), " +
50+ " COALESCE(SUM(CASE WHEN e.up = true THEN 1 ELSE 0 END), 0L), " +
51+ " COALESCE(SUM(CASE WHEN e.down = true THEN 1 ELSE 0 END), 0L)) " +
52+ "FROM ExpenseAnalysisHistory e " +
53+ "WHERE e.createdAt BETWEEN :startDate AND :endDate " +
54+ "GROUP BY YEAR(e.createdAt), MONTH(e.createdAt), DAY(e.createdAt) " +
55+ "ORDER BY YEAR(e.createdAt), MONTH(e.createdAt), DAY(e.createdAt)" )
56+ List <store .lastdance .dto .admin .FeedbackTrendDTO > findFeedbackTrendsBetween (@ Param ("startDate" ) LocalDateTime startDate , @ Param ("endDate" ) LocalDateTime endDate );
57+
58+ @ Query ("SELECT new store.lastdance.dto.admin.FeedbackTrendDTO(" +
59+ " YEAR(e.createdAt), " +
60+ " MONTH(e.createdAt), " +
61+ " DAY(e.createdAt), " +
62+ " COUNT(e), " +
63+ " COALESCE(SUM(CASE WHEN e.up = true THEN 1 ELSE 0 END), 0L), " +
64+ " COALESCE(SUM(CASE WHEN e.down = true THEN 1 ELSE 0 END), 0L)) " +
65+ "FROM ExpenseAnalysisHistory e " +
66+ "GROUP BY YEAR(e.createdAt), MONTH(e.createdAt), DAY(e.createdAt) " +
67+ "ORDER BY YEAR(e.createdAt), MONTH(e.createdAt), DAY(e.createdAt)" )
68+ List <store .lastdance .dto .admin .FeedbackTrendDTO > findFeedbackTrends ();
69+ }
0 commit comments