[BE] [FEAT] 베팅 정산 시스템 고도화 및 낙관적 락 재시도 어노테이션 도입#190
Hidden character warning
Conversation
WalkthroughBetRound과 UserBet에 무승부(draw) 처리 로직을 추가하고, 낙관적 재시도 어노테이션( Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant OptimisticRetryAspect
participant BettingService
participant Database
participant PointHistoryService
Client->>BettingService: settleUserBets()
BettingService->>OptimisticRetryAspect: (proxy) doRetry(...)
OptimisticRetryAspect->>BettingService: proceed()
BettingService->>Database: find active BetRounds & price data
Database-->>BettingService: BetRounds, prices
BettingService->>BettingService: determineResult() per round
alt result == null (draw)
BettingService->>Database: find UserBets by round(s)
Database-->>BettingService: UserBets
loop each UserBet
BettingService->>UserBet: draw()
BettingService->>PointHistoryService: createPointHistory(refund)
PointHistoryService-->>Database: persist history
Database-->>BettingService: saved
end
else result != null
BettingService->>Database: find UserBets by round(s)
Database-->>BettingService: UserBets
loop winners/losers
BettingService->>BettingService: calculateReward()
BettingService->>PointHistoryService: createPointHistory(payout)
PointHistoryService-->>Database: persist history
Database-->>BettingService: saved
end
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
backend/src/main/java/org/sejongisc/backend/betting/service/BettingScheduler.java (1)
9-27: 월요일 판정 타임존을 스케줄 타임존과 일치시키세요.
@Scheduled는 Asia/Seoul인데LocalDate.now()는 JVM 기본 타임존을 사용합니다. 서버 타임존이 다르면 월요일 여부가 어긋날 수 있어요.ZoneId.of("Asia/Seoul")로 맞추는 게 안전합니다.🔧 제안 수정
import java.time.DayOfWeek; import java.time.LocalDate; +import java.time.ZoneId; @@ - if (LocalDate.now().getDayOfWeek() == DayOfWeek.MONDAY) { + if (LocalDate.now(ZoneId.of("Asia/Seoul")).getDayOfWeek() == DayOfWeek.MONDAY) { bettingService.createBetRound(Scope.WEEKLY); }
|
|
고생하셨습니다 ! 타임존 토끼 리뷰는 반영된 것일까요 ?? |
|
@cksdid202 |
backend/src/main/java/org/sejongisc/backend/betting/service/BettingService.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In
`@backend/src/main/java/org/sejongisc/backend/betting/service/BettingService.java`:
- Around line 299-308: The draw-refund path currently calls
pointHistoryService.createPointHistory(...) unconditionally which throws for
amount == 0 (free bets) and also when calculateReward(...) returns 0; before
calling createPointHistory in the round.isDraw() branch, check that the refund
amount is > 0 (compute refund = bet.isFree ? 0 : calculateReward(...)/or
bet.getStakePoints()) and only call pointHistoryService.createPointHistory(...)
when refund > 0, then call bet.draw(); ensure you reference the bet.isFree field
(not bet.isFree()) and validate calculateReward(...) output to avoid creating a
0-point history.
backend/src/main/java/org/sejongisc/backend/betting/service/BettingService.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In
`@backend/src/main/java/org/sejongisc/backend/betting/service/BettingService.java`:
- Around line 311-321: The reward can be zero due to defensive calculateReward
behavior, which later causes pointHistoryService.createPointHistory to throw;
update BettingService around the bet handling (the block using calculateReward,
bet.win, and pointHistoryService.createPointHistory) to validate the computed
reward is > 0 before calling createPointHistory (and only call bet.win if reward
> 0), and if reward == 0 either log a warning and skip creating point history or
handle as an application-level error according to existing conventions so you
never pass a zero amount into createPointHistory.
🧹 Nitpick comments (1)
backend/src/main/java/org/sejongisc/backend/betting/service/BettingService.java (1)
330-359: 배당률 계산 로직이 명확합니다.파리뮤추얼 방식의 배당률 계산이 올바르게 구현되었습니다.
floor연산으로 인한 잔여 포인트 처리는 TODO에 명시된 대로 복식부기 도입 시 보완하면 될 것 같습니다.잔여 포인트 처리를 위한 시스템 계정 연동 로직이 필요하시면 도움드릴 수 있습니다.
Summary by CodeRabbit
New Features
Bug Fixes
Refactor
✏️ Tip: You can customize this high-level summary in your review settings.