11package com .back .domain .mission .service ;
22
33import com .back .domain .mission .entity .*;
4- import com .back .domain .mission .event .*;
5- import com .back .domain .mission .repository .*;
4+ import com .back .domain .mission .event .DailyCompletedEvent ;
5+ import com .back .domain .mission .event .MissionCompletedEvent ;
6+ import com .back .domain .mission .event .WeeklyCompletedEvent ;
7+ import com .back .domain .mission .repository .DailyCompletionLogRepository ;
8+ import com .back .domain .mission .repository .MissionCompletionLogRepository ;
9+ import com .back .domain .mission .repository .SubGoalCompletionLogRepository ;
10+ import com .back .domain .reward .entity .RewardType ;
11+ import com .back .domain .reward .service .RewardService ;
612import com .back .domain .statistics .service .StatisticsService ;
713import com .back .global .util .TimeProvider ;
814import lombok .RequiredArgsConstructor ;
@@ -27,8 +33,8 @@ public class CompletionCheckService {
2733
2834 private final StatisticsService statisticsService ;
2935 private final ApplicationEventPublisher applicationEventPublisher ;
36+ private final RewardService rewardService ;
3037
31- // Task 완료 시: 모든 완료 조건 체크
3238 public void checkAllCompletions (Integer memberId , Task task , LocalDate date ) {
3339 SubGoal subGoal = task .getSubGoal ();
3440 Mission mission = subGoal .getMission ();
@@ -38,7 +44,6 @@ public void checkAllCompletions(Integer memberId, Task task, LocalDate date) {
3844 checkMissionCompletion (memberId , mission );
3945 }
4046
41- // Task 취소 시: 완료 상태 재검증
4247 public void recheckAfterCancellation (Integer memberId , Task task , LocalDate date ) {
4348 SubGoal subGoal = task .getSubGoal ();
4449 Mission mission = subGoal .getMission ();
@@ -48,23 +53,28 @@ public void recheckAfterCancellation(Integer memberId, Task task, LocalDate date
4853 recheckMissionCompletion (memberId , mission );
4954 }
5055
56+ // ========== 데일리 ==========
5157
52- // 데일리 완료 체크
5358 private void checkDailyCompletion (Integer memberId , LocalDate date ) {
5459 if (dailyCompletionLogRepository .existsByMemberIdAndCompletedDate (memberId , date )) {
5560 return ;
5661 }
5762
5863 Integer progress = calculateService .calculateDailyProgress (memberId , date );
5964
60- if (progress >= 100 ) {
65+ if (progress >= 80 ) {
6166 dailyCompletionLogRepository .save (DailyCompletionLog .builder ()
6267 .memberId (memberId )
6368 .completedDate (date )
6469 .build ());
6570
6671 statisticsService .onDailyCompleted (memberId , date );
6772
73+ try {
74+ rewardService .giveRewardByType (memberId , RewardType .DAILYCLEAR );
75+ } catch (Exception ignored ) {
76+ }
77+
6878 applicationEventPublisher .publishEvent (DailyCompletedEvent .builder ()
6979 .memberId (memberId )
7080 .completedDate (date )
@@ -80,22 +90,23 @@ private void recheckDailyCompletion(Integer memberId, LocalDate date) {
8090
8191 Integer progress = calculateService .calculateDailyProgress (memberId , date );
8292
83- if (progress < 100 ) {
93+ if (progress < 80 ) {
8494 dailyCompletionLogRepository .delete (logOpt .get ());
8595 statisticsService .onDailyCancelled (memberId , date );
96+
8697 }
8798 }
8899
100+ // ========== 주차 ==========
89101
90- // 주차 완료 체크
91102 private void checkWeeklyCompletion (Integer memberId , SubGoal subGoal ) {
92103 if (subGoalCompletionLogRepository .existsBySubGoalIdAndMemberId (subGoal .getId (), memberId )) {
93104 return ;
94105 }
95106
96107 Integer progress = calculateService .calculateWeekProgressForMember (subGoal , memberId );
97108
98- if (progress >= 100 ) {
109+ if (progress >= 80 ) {
99110 subGoalCompletionLogRepository .save (SubGoalCompletionLog .builder ()
100111 .subGoalId (subGoal .getId ())
101112 .memberId (memberId )
@@ -105,6 +116,11 @@ private void checkWeeklyCompletion(Integer memberId, SubGoal subGoal) {
105116
106117 statisticsService .onWeeklyCompleted (memberId );
107118
119+ try {
120+ rewardService .giveRewardByType (memberId , RewardType .WEEKLYCLEAR );
121+ } catch (Exception ignored ) {
122+ }
123+
108124 applicationEventPublisher .publishEvent (WeeklyCompletedEvent .builder ()
109125 .memberId (memberId )
110126 .subGoalId (subGoal .getId ())
@@ -123,21 +139,22 @@ private void recheckWeeklyCompletion(Integer memberId, SubGoal subGoal) {
123139
124140 Integer progress = calculateService .calculateWeekProgressForMember (subGoal , memberId );
125141
126- if (progress < 100 ) {
142+ if (progress < 80 ) {
127143 subGoalCompletionLogRepository .delete (logOpt .get ());
128144 statisticsService .onWeeklyCancelled (memberId );
129145 }
130146 }
131147
132- // 미션 완료 체크
148+ // ========== 미션 ==========
149+
133150 private void checkMissionCompletion (Integer memberId , Mission mission ) {
134151 if (missionCompletionLogRepository .existsByMissionIdAndMemberId (mission .getId (), memberId )) {
135152 return ;
136153 }
137154
138155 Integer progress = calculateService .calculateMissionProgressForMember (mission , memberId );
139156
140- if (progress >= 100 ) {
157+ if (progress >= 80 ) {
141158 LocalDate today = timeProvider .today ();
142159
143160 missionCompletionLogRepository .save (MissionCompletionLog .builder ()
@@ -148,6 +165,11 @@ private void checkMissionCompletion(Integer memberId, Mission mission) {
148165
149166 statisticsService .onMissionCompleted (memberId , mission .isPartyMission ());
150167
168+ try {
169+ rewardService .giveRewardByType (memberId , RewardType .CHALLENGECLEAR );
170+ } catch (Exception ignored ) {
171+ }
172+
151173 applicationEventPublisher .publishEvent (MissionCompletedEvent .builder ()
152174 .missionId (mission .getId ())
153175 .memberId (memberId )
@@ -156,6 +178,7 @@ private void checkMissionCompletion(Integer memberId, Mission mission) {
156178 .completedDate (today )
157179 .build ());
158180
181+
159182 if (!mission .isPartyMission () && !mission .isCompleted ()) {
160183 mission .setCompleted (true );
161184 }
@@ -170,10 +193,11 @@ private void recheckMissionCompletion(Integer memberId, Mission mission) {
170193
171194 Integer progress = calculateService .calculateMissionProgressForMember (mission , memberId );
172195
173- if (progress < 100 ) {
196+ if (progress < 80 ) {
174197 missionCompletionLogRepository .delete (logOpt .get ());
175198 statisticsService .onMissionCancelled (memberId , mission .isPartyMission ());
176199
200+
177201 if (!mission .isPartyMission ()) {
178202 mission .setCompleted (false );
179203 }
0 commit comments