2222import java .time .LocalDateTime ;
2323import java .time .temporal .TemporalAdjusters ;
2424import java .util .ArrayList ;
25+ import java .util .Comparator ;
2526import java .util .List ;
2627import java .util .Optional ;
2728import lombok .RequiredArgsConstructor ;
@@ -77,7 +78,7 @@ public ActionChange findMostIncreasedPositiveActionChange(Long memberId, Long ro
7778 NumberExpression <Long > lastMonthNotes = countLastMonthNotes (today );
7879 NumberExpression <Long > increaseCount = thisMonthNotes .subtract (lastMonthNotes );
7980
80- return queryFactory
81+ List < ActionChange > results = queryFactory
8182 .select (new QActionChange (action , increaseCount .longValue ()))
8283 .from (note )
8384 .join (note .action , action )
@@ -86,8 +87,12 @@ public ActionChange findMostIncreasedPositiveActionChange(Long memberId, Long ro
8687 .and (isReceiver (memberId ))
8788 .and (actionCategory .emotionType .eq (EmotionType .POSITIVE )))
8889 .groupBy (action )
89- .orderBy (increaseCount .desc ())
90- .fetchFirst ();
90+ .fetch ();
91+
92+ return results .stream ()
93+ .sorted (Comparator .comparing (ActionChange ::getChange ).reversed ())
94+ .findFirst ()
95+ .orElse (null );
9196 }
9297
9398 @ Override
@@ -97,7 +102,7 @@ public ActionChange findMostDecreasedNegativeActionChange(Long memberId, Long ro
97102 NumberExpression <Long > lastMonthNotes = countLastMonthNotes (today );
98103 NumberExpression <Long > decreaseCount = thisMonthNotes .subtract (lastMonthNotes );
99104
100- return queryFactory
105+ List < ActionChange > results = queryFactory
101106 .select (new QActionChange (action , decreaseCount .longValue ()))
102107 .from (note )
103108 .join (note .action , action )
@@ -106,8 +111,12 @@ public ActionChange findMostDecreasedNegativeActionChange(Long memberId, Long ro
106111 .and (isReceiver (memberId ))
107112 .and (actionCategory .emotionType .eq (EmotionType .NEGATIVE )))
108113 .groupBy (action )
109- .orderBy (decreaseCount .asc ())
110- .fetchFirst ();
114+ .fetch ();
115+
116+ return results .stream ()
117+ .sorted (Comparator .comparing (ActionChange ::getChange ))
118+ .findFirst ()
119+ .orElse (null );
111120 }
112121
113122 @ Override
0 commit comments