|
9 | 9 | import com.dnd.sub.domain.subscription.dto.GetMySubscriptionDto; |
10 | 10 | import com.dnd.sub.domain.subscription.dto.GetPaymentSoonDto; |
11 | 11 | import com.dnd.sub.domain.subscription.dto.response.GetPaymentTotalResponse; |
| 12 | +import com.dnd.sub.domain.subscription.entity.PayCycleUnitType; |
12 | 13 | import com.dnd.sub.domain.subscription.entity.QSubscription; |
13 | 14 | import com.dnd.sub.domain.subscription.entity.Subscription; |
14 | 15 | import com.querydsl.core.BooleanBuilder; |
@@ -121,54 +122,88 @@ public GetPaymentTotalResponse findPaymentTotal(Long memberId) { |
121 | 122 | Subscription sub = tuple.get(s); |
122 | 123 | Integer price = tuple.get(pp.price); |
123 | 124 |
|
124 | | - if(sub.getStartedAt() == null){ |
| 125 | + if (sub.getStartedAt() == null) { |
125 | 126 | continue; |
126 | 127 | } |
127 | 128 | int personalPrice = price / sub.getParticipantCount(); |
128 | | - LocalDate prevPayDay = sub.getPreviousPaymentDay(); |
129 | | - LocalDate nextPayDay = sub.getNextPaymentDay(); |
130 | | - |
131 | | - // 이전 결제일이 이번달인 경우 |
132 | | - boolean isPrevThisMonth = false; |
133 | | - if (prevPayDay != null) { |
134 | | - isPrevThisMonth = !prevPayDay.isBefore(startDay) && |
135 | | - !prevPayDay.isAfter(endDay); |
| 129 | + PayCycleUnitType cycleUnit = sub.getPayCycleUnit(); |
| 130 | + |
| 131 | + if (cycleUnit == PayCycleUnitType.WEEK) { |
| 132 | + LocalDate prevPayDay = sub.getPreviousPaymentDay(); |
| 133 | + |
| 134 | + if (prevPayDay != null) { |
| 135 | + LocalDate currentPaymentDay = prevPayDay; |
| 136 | + |
| 137 | + // 과거 방향으로 결제한 금액 |
| 138 | + while (!currentPaymentDay.isBefore(startDay)) { |
| 139 | + if (!currentPaymentDay.isAfter(endDay) && !currentPaymentDay.isAfter(today)) { |
| 140 | + totalAmount += personalPrice; |
| 141 | + usedAmount += personalPrice; |
| 142 | + } |
| 143 | + currentPaymentDay = currentPaymentDay.minusWeeks(1); |
| 144 | + } |
| 145 | + |
| 146 | + // 미래 방향으로 결제할 금액 |
| 147 | + LocalDate nextPayDay = sub.getNextPaymentDay(); |
| 148 | + if (nextPayDay != null) { |
| 149 | + currentPaymentDay = nextPayDay; |
| 150 | + while (!currentPaymentDay.isAfter(endDay)) { |
| 151 | + if (!currentPaymentDay.isBefore(startDay) && currentPaymentDay.isAfter(today)) { |
| 152 | + totalAmount += personalPrice; |
| 153 | + remainingAmount += personalPrice; |
| 154 | + } |
| 155 | + currentPaymentDay = currentPaymentDay.plusWeeks(1); |
| 156 | + } |
| 157 | + } |
| 158 | + } |
136 | 159 | } |
137 | | - // 다음 결제일이 이번달인 경우 |
138 | | - boolean isNextThisMonth = false; |
139 | | - if (nextPayDay != null) { |
140 | | - isNextThisMonth = !nextPayDay.isBefore(startDay) && |
| 160 | + else { |
| 161 | + LocalDate prevPayDay = sub.getPreviousPaymentDay(); |
| 162 | + LocalDate nextPayDay = sub.getNextPaymentDay(); |
| 163 | + |
| 164 | + // 이전 결제일이 이번달인 경우 |
| 165 | + boolean isPrevThisMonth = false; |
| 166 | + if (prevPayDay != null) { |
| 167 | + isPrevThisMonth = !prevPayDay.isBefore(startDay) && |
| 168 | + !prevPayDay.isAfter(endDay); |
| 169 | + } |
| 170 | + // 다음 결제일이 이번달인 경우 |
| 171 | + boolean isNextThisMonth = false; |
| 172 | + if (nextPayDay != null) { |
| 173 | + isNextThisMonth = !nextPayDay.isBefore(startDay) && |
141 | 174 | !nextPayDay.isAfter(endDay) && |
142 | 175 | nextPayDay.isAfter(today); |
143 | | - } |
| 176 | + } |
144 | 177 |
|
145 | | - boolean isPrevPay = isPrevThisMonth && !prevPayDay.isAfter(today); |
| 178 | + boolean isPrevPay = isPrevThisMonth && !prevPayDay.isAfter(today); |
146 | 179 |
|
147 | | - if (isPrevThisMonth || isNextThisMonth) { |
148 | | - totalAmount += personalPrice; |
149 | | - } |
| 180 | + if (isPrevThisMonth || isNextThisMonth) { |
| 181 | + totalAmount += personalPrice; |
| 182 | + } |
150 | 183 |
|
151 | | - if (isPrevPay) { |
152 | | - usedAmount += personalPrice; |
153 | | - } |
| 184 | + if (isPrevPay) { |
| 185 | + usedAmount += personalPrice; |
| 186 | + } |
154 | 187 |
|
155 | | - if (isNextThisMonth) { |
156 | | - remainingAmount += personalPrice; |
| 188 | + if (isNextThisMonth) { |
| 189 | + remainingAmount += personalPrice; |
| 190 | + } |
157 | 191 | } |
158 | 192 | } |
159 | 193 |
|
160 | | - int progressPercentage = 0; |
161 | | - if (totalAmount > 0) { |
162 | | - progressPercentage = (100 * usedAmount) / totalAmount; |
163 | | - } |
| 194 | + int progressPercentage = 0; |
| 195 | + if (totalAmount > 0) { |
| 196 | + progressPercentage = (100 * usedAmount) / totalAmount; |
| 197 | + } |
164 | 198 |
|
165 | | - return new GetPaymentTotalResponse( |
| 199 | + return new GetPaymentTotalResponse( |
166 | 200 | tuples.get(0).get(m.name), |
167 | 201 | totalAmount, |
168 | 202 | remainingAmount, |
169 | 203 | progressPercentage, |
170 | 204 | subCount |
171 | | - ); |
| 205 | + ); |
| 206 | + |
172 | 207 | } |
173 | 208 |
|
174 | 209 | private List<GetMySubscriptionDto> findSubscriptions(BooleanBuilder builder, |
|
0 commit comments