1+ package com .backend .global .initdata ;
2+
3+ import com .backend .domain .bid .repository .BidRepository ;
4+ import com .backend .domain .member .repository .MemberRepository ;
5+ import com .backend .domain .notification .service .NotificationQueueService ;
6+ import com .backend .domain .product .entity .Product ;
7+ import com .backend .domain .product .repository .jpa .ProductImageRepository ;
8+ import com .backend .domain .product .repository .jpa .ProductRepository ;
9+ import com .backend .domain .product .service .ProductSyncService ;
10+ import lombok .RequiredArgsConstructor ;
11+ import org .springframework .beans .factory .annotation .Autowired ;
12+ import org .springframework .boot .ApplicationRunner ;
13+ import org .springframework .context .annotation .Bean ;
14+ import org .springframework .context .annotation .Lazy ;
15+ import org .springframework .context .annotation .Profile ;
16+ import org .springframework .security .crypto .password .PasswordEncoder ;
17+ import org .springframework .stereotype .Component ;
18+ import org .springframework .transaction .annotation .Transactional ;
19+
20+ import java .time .LocalDateTime ;
21+
22+ @ Profile ("prod" )
23+ @ Component
24+ @ RequiredArgsConstructor
25+ public class ProdInitData {
26+
27+ @ Autowired
28+ @ Lazy
29+ private ProdInitData self ;
30+
31+ private final PasswordEncoder passwordEncoder ;
32+ private final MemberRepository memberRepository ;
33+ private final ProductRepository productRepository ;
34+ private final ProductImageRepository productImageRepository ;
35+ private final BidRepository bidRepository ;
36+ private final ProductSyncService productSyncService ;
37+ private final NotificationQueueService notificationQueueService ;
38+
39+ @ Bean
40+ ApplicationRunner prodInitDataApplicationRunner () {
41+ return args -> {
42+ self .work1 ();
43+ productSyncService .indexAllProducts ();
44+ };
45+ }
46+
47+ @ Transactional
48+ public void work1 () {
49+ if (memberRepository .findByEmail ("member2@example.com" ).isEmpty ()) {
50+ return ;
51+ }
52+
53+ Product product = productRepository .findById (24L ).get ();
54+ if (product .getEndTime ().isAfter (LocalDateTime .of (2025 , 10 , 16 , 0 , 9 , 59 ))) {
55+ return ;
56+ }
57+ product .setEndTime (LocalDateTime .of (2025 , 10 , 16 , 0 , 9 , 59 ));
58+ }
59+ }
0 commit comments