@@ -35,7 +35,6 @@ public String addToWaitingQueue(Long storeId, String userId, Integer partySize,
3535 String queueKey = RedisKeyUtils .buildWaitingKeyPrefix () + storeId ;
3636 String partyKey = RedisKeyUtils .buildWaitingPartySizeKeyPrefix () + storeId ;
3737 String statusKey = RedisKeyUtils .buildWaitingStatusKeyPrefix () + storeId ;
38-
3938 String seqKey = RedisKeyUtils .buildReservationSeqKey (storeId );
4039 String numberMapKey = RedisKeyUtils .buildReservationNumberKey (storeId );
4140
@@ -44,18 +43,7 @@ public String addToWaitingQueue(Long storeId, String userId, Integer partySize,
4443
4544 if (Boolean .TRUE .equals (added )) {
4645
47- // 2) 일일 시퀀스: 날짜별로 초기화하려면
48- String today = LocalDate .now ().format (DateTimeFormatter .BASIC_ISO_DATE ); // YYYYMMDD
49- String dailySeqKey = seqKey + ":" + today ; // ex. reservation:seq:5:20250728
50-
51- // atomic increment
52- Long seq = redisTemplate .opsForValue ().increment (dailySeqKey , 1 );
53-
54- // 3) 4자리 0패딩
55- String seqStr = String .format ("%04d" , seq );
56-
57- // 4) 최종 ID 조합
58- reservationId = storeId + "-" + today + "-" + seqStr ;
46+ reservationId = GenerateReservationNumber (seqKey , storeId );
5947
6048 // 5) Hash에 저장
6149 redisTemplate .opsForHash ().put (numberMapKey , userId , reservationId );
@@ -69,6 +57,8 @@ public String addToWaitingQueue(Long storeId, String userId, Integer partySize,
6957 redisTemplate .expire (queueKey , ttl );
7058 redisTemplate .expire (partyKey , ttl );
7159 redisTemplate .expire (statusKey , ttl );
60+ redisTemplate .expire (seqKey , ttl );
61+ redisTemplate .expire (numberMapKey , ttl );
7262 } else {
7363 Object stored = redisTemplate .opsForHash ().get (numberMapKey , userId );
7464 reservationId = stored != null ? stored .toString () : null ;
@@ -193,6 +183,7 @@ public String getReservationId(Long storeId, String userId) {
193183 return val != null ? val .toString () : null ;
194184 }
195185
186+ // 6) TTL 계산: 다음날 03:00 까지 남은 시간
196187 public Duration calculateTTLUntilNext03AM () {
197188 // 6-1) Asia/Seoul 기준으로 오늘 자정(내일 00:00) 구하기
198189 ZoneId zone = ZoneId .of ("Asia/Seoul" );
@@ -204,6 +195,24 @@ public Duration calculateTTLUntilNext03AM() {
204195
205196 return Duration .ofSeconds (secondsUntilMidnight );
206197 }
198+
199+ // 예약 번호 생성
200+ public String GenerateReservationNumber (String seqKey , Long storeId ) {
201+ // 2) 일일 시퀀스: 날짜별로 초기화하려면
202+ String today = LocalDate .now ().format (DateTimeFormatter .BASIC_ISO_DATE ); // YYYYMMDD
203+ String dailySeqKey = seqKey + ":" + today ; // ex. reservation:seq:5:20250728
204+
205+ // atomic increment
206+ Long seq = redisTemplate .opsForValue ().increment (dailySeqKey , 1 );
207+
208+ // 3) 4자리 0패딩
209+ String seqStr = String .format ("%04d" , seq );
210+
211+ // 4) 최종 ID 조합
212+ String reservationId = storeId + "-" + today + "-" + seqStr ;
213+
214+ return reservationId ;
215+ }
207216}
208217
209218
0 commit comments