11package com .back .domain .mission .service ;
22
33import com .back .domain .mission .entity .*;
4+ import com .back .domain .mission .enums .TaskStatus ;
45import com .back .domain .mission .event .DailyCompletedEvent ;
56import com .back .domain .mission .event .MissionCompletedEvent ;
67import com .back .domain .mission .event .WeeklyCompletedEvent ;
78import com .back .domain .mission .repository .DailyCompletionLogRepository ;
89import com .back .domain .mission .repository .MissionCompletionLogRepository ;
910import com .back .domain .mission .repository .SubGoalCompletionLogRepository ;
11+ import com .back .domain .mission .repository .TaskLogRepository ;
1012import com .back .domain .reward .entity .RewardType ;
1113import com .back .domain .reward .service .RewardService ;
1214import com .back .domain .statistics .service .StatisticsService ;
@@ -34,7 +36,7 @@ public class CompletionCheckService {
3436 private final StatisticsService statisticsService ;
3537 private final ApplicationEventPublisher applicationEventPublisher ;
3638 private final RewardService rewardService ;
37-
39+ private final TaskLogRepository taskLogRepository ;
3840 public void checkAllCompletions (Integer memberId , Task task , LocalDate date ) {
3941 SubGoal subGoal = task .getSubGoal ();
4042 Mission mission = subGoal .getMission ();
@@ -55,59 +57,27 @@ public void recheckAfterCancellation(Integer memberId, Task task, LocalDate date
5557
5658 // ========== 데일리 ==========
5759 private void checkDailyCompletion (Integer memberId , LocalDate date ) {
58- System .out .println ("━━━━━━━━━━━━━━━━━━━━━━━━━━" );
59- System .out .println ("🔍 checkDailyCompletion 시작" );
60- System .out .println ("memberId: " + memberId );
61- System .out .println ("date: " + date );
62-
63- boolean alreadyCompleted = dailyCompletionLogRepository .existsByMemberIdAndCompletedDate (memberId , date );
64- System .out .println ("이미 완료?: " + alreadyCompleted );
65-
66- if (alreadyCompleted ) {
67- System .out .println ("❌ 이미 완료됨 - 리턴" );
68- System .out .println ("━━━━━━━━━━━━━━━━━━━━━━━━━━" );
60+ if (dailyCompletionLogRepository .existsByMemberIdAndCompletedDate (memberId , date )) {
6961 return ;
7062 }
7163
72- System .out .println ("데일리 진행률 계산 중..." );
73- Integer progress = calculateService .calculateDailyProgress (memberId , date );
74- System .out .println ("데일리 진행률: " + progress + "%" );
64+ Long completedCount = taskLogRepository .countByMemberIdAndDateAndStatus (
65+ memberId , date , TaskStatus .COMPLETED );
7566
76- if (progress >= 80 ) {
77- System .out .println ("✅ 진행률 80% 이상!" );
78-
79- System .out .println ("DailyCompletionLog 저장 중..." );
67+ if (completedCount >= 1 ) {
8068 dailyCompletionLogRepository .save (DailyCompletionLog .builder ()
8169 .memberId (memberId )
8270 .completedDate (date )
8371 .build ());
84- System .out .println ("✅ DailyCompletionLog 저장 완료!" );
8572
86- System .out .println ("통계 업데이트 중..." );
8773 statisticsService .onDailyCompleted (memberId , date );
88- System .out .println ("✅ 통계 업데이트 완료!" );
8974
90- System .out .println ("데일리 보상 지급 중..." );
91- try {
92- rewardService .giveRewardByType (memberId , RewardType .DAILYCLEAR );
93- System .out .println ("✅ 데일리 보상 지급 완료!" );
94- } catch (Exception e ) {
95- System .out .println ("❌ 데일리 보상 지급 실패: " + e .getMessage ());
96- e .printStackTrace ();
97- }
9875
99- System .out .println ("데일리 이벤트 발행 중..." );
10076 applicationEventPublisher .publishEvent (DailyCompletedEvent .builder ()
10177 .memberId (memberId )
10278 .completedDate (date )
10379 .build ());
104- System .out .println ("✅ 데일리 이벤트 발행 완료!" );
105-
106- System .out .println ("✅✅✅ checkDailyCompletion 전체 완료!" );
107- } else {
108- System .out .println ("❌ 진행률 부족: " + progress + "% < 80%" );
10980 }
110- System .out .println ("━━━━━━━━━━━━━━━━━━━━━━━━━━" );
11181 }
11282
11383 private void recheckDailyCompletion (Integer memberId , LocalDate date ) {
@@ -116,15 +86,13 @@ private void recheckDailyCompletion(Integer memberId, LocalDate date) {
11686
11787 if (logOpt .isEmpty ()) return ;
11888
119- Integer progress = calculateService .calculateDailyProgress (memberId , date );
89+ Long completedCount = taskLogRepository .countByMemberIdAndDateAndStatus (
90+ memberId , date , TaskStatus .COMPLETED );
12091
121- if (progress < 80 ) {
92+ if (completedCount < 1 ) {
12293 dailyCompletionLogRepository .delete (logOpt .get ());
12394 statisticsService .onDailyCancelled (memberId , date );
124- try {
125- rewardService .revokeRewardByType (memberId , RewardType .DAILYCLEAR );
126- } catch (Exception ignored ) {
127- }
95+
12896 }
12997 }
13098
0 commit comments