Skip to content

Commit df9973d

Browse files
Merge pull request #161 from MoonJongHyeon1095/dev
fix: EC2 정지 현상 문제원인 파악중
2 parents 8b4dedf + bb0afe0 commit df9973d

File tree

19 files changed

+1145
-161
lines changed

19 files changed

+1145
-161
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,15 @@
11
# BE
2+
<br>
3+
<h2><b>tech stack</b></h3>
4+
<p>
5+
<img src="https://img.shields.io/badge/Spring Boot-6DB33F?style=for-the-badge&logo=Spring Boot&logoColor=white">
6+
<img src="https://img.shields.io/badge/Spring Security-6DB33F?style=for-the-badge&logo=Spring Security&logoColor=white">
7+
<img src="https://img.shields.io/badge/Web Socket-010101?style=for-the-badge&logo=Web Socket&logoColor=white">
8+
<img src="https://img.shields.io/badge/Rabbit MQ-FF6600?style=for-the-badge&logo=rabbitmq&logoColor=white">
9+
<br>
10+
<img src="https://img.shields.io/badge/NginX-009639?style=for-the-badge&logo=NGINX&logoColor=white">
11+
<img src="https://img.shields.io/badge/Docker-2496ED?style=for-the-badge&logo=Docker&logoColor=white">
12+
<img src="https://img.shields.io/badge/MySQL-4479A1?style=for-the-badge&logo=MySQL&logoColor=white">
13+
<img src="https://img.shields.io/badge/Amazon AWS-FF9900?style=for-the-badge&logo=Amazon AWS&logoColor=white">
14+
<img src="https://img.shields.io/badge/Github Actions-2088FF?style=for-the-badge&logo=Github Actions&logoColor=white">
15+
<br>

build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ dependencies {
5858
// Spring Batch
5959
implementation 'org.springframework.boot:spring-boot-starter-batch'
6060
testImplementation 'org.springframework.batch:spring-batch-test'
61+
62+
//h2
63+
testImplementation 'com.h2database:h2'
64+
6165
}
6266

6367
tasks.named('test') {

src/main/java/com/github/commerce/config/batch/UpdateCustomerGradeScheduler.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ public class UpdateCustomerGradeScheduler { //매월 1일 오전 12:00:00 구매
2323
@Autowired
2424
private Job updateCustomerGradeJob;
2525

26-
//TODO. 일단은 매일 오전 12시로 해놓고 시연할 때는 30초로 간격 줄이기
27-
@Scheduled(cron = "*/10 * * * * *", zone = "Asia/Seoul") //초 분 시 일 월 요일 (*: 매번) - 매월 1일 오전 12:00:00 구매 금액에 따른 회원 등급 조정
26+
@Scheduled(cron = "0 0 0 1 * *", zone = "Asia/Seoul") //초 분 시 일 월 요일 (*: 매번) - 매월 1일 오전 12:00:00 구매 금액에 따른 회원 등급 조정
2827
public void updateCustomerGradeJobRun() throws JobInstanceAlreadyCompleteException, JobExecutionAlreadyRunningException, JobParametersInvalidException, JobRestartException {
2928

3029
JobParameters jobParameters = new JobParameters(

src/main/java/com/github/commerce/config/security/WebSecurityConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class WebSecurityConfig {
3434
private final JwtUtil jwtUtil;
3535
private final UserDetailsServiceImpl userDetailsService;
3636
private static final String[] PERMIT_URL_ARRAY = {
37-
"/","/v1/api/user/**","/v1/api/product/**","/v1/api/coupon","/GuerrillaCommerce",
37+
"/","/v1/api/user/**","/v1/api/product/**","/v1/api/coupon","/GuerrillaCommerce", "/v1/api/navi",
3838
"/api/v2/**", "/swagger-ui.html", "/swagger/**","/swagger-resources/**", "/webjars/**", "/v2/api-docs"
3939
};
4040

src/main/java/com/github/commerce/entity/Product.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.commerce.entity;
22

3+
import com.github.commerce.web.dto.product.GetProductDto;
34
import com.github.commerce.web.dto.product.ProductRequest;
45
import com.google.gson.Gson;
56
import lombok.*;
@@ -17,6 +18,24 @@
1718
@AllArgsConstructor
1819
@Builder
1920
@Entity
21+
@SqlResultSetMapping(
22+
name = "GetProductDtoMapping",
23+
classes = @ConstructorResult(
24+
targetClass = GetProductDto.class,
25+
columns = {
26+
@ColumnResult(name = "id", type = Long.class),
27+
@ColumnResult(name = "name", type = String.class),
28+
@ColumnResult(name = "price", type = Integer.class),
29+
@ColumnResult(name = "created_at", type = LocalDateTime.class),
30+
@ColumnResult(name = "product_category", type = String.class),
31+
@ColumnResult(name = "age_category", type = String.class),
32+
@ColumnResult(name = "gender_category", type = String.class),
33+
@ColumnResult(name = "left_amount", type = Integer.class),
34+
@ColumnResult(name = "thumbnail_url", type = String.class),
35+
@ColumnResult(name = "shop_name", type = String.class)
36+
}
37+
)
38+
)
2039
@Table(name = "products")
2140
public class Product {
2241
@Id
Lines changed: 241 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,241 @@
1+
package com.github.commerce.repository.product;
2+
3+
import com.github.commerce.web.dto.product.GetProductDto;
4+
import org.springframework.data.domain.Pageable;
5+
import org.springframework.stereotype.Repository;
6+
7+
import javax.persistence.EntityManager;
8+
import javax.persistence.PersistenceContext;
9+
import javax.persistence.Query;
10+
import java.util.List;
11+
12+
@Repository
13+
public class ProductRepositoryCustom {
14+
15+
@PersistenceContext
16+
private EntityManager entityManager;
17+
18+
public List<GetProductDto> findByProductCategorySortByCreatedAt(
19+
String inputProductCategory,
20+
String inputAgeCategory,
21+
String inputGenderCategory,
22+
Pageable pageable) {
23+
24+
String sql = "SELECT p.id, p.name, p.price, p.created_at, " +
25+
"p.product_category, p.age_category, p.gender_category, " +
26+
"p.left_amount, p.thumbnail_url, s.shop_name " +
27+
"FROM commerce.products p LEFT JOIN commerce.sellers s ON p.sellers_id = s.id " +
28+
"WHERE p.product_category = :inputProductCategory " +
29+
"AND (:inputAgeCategory IS NULL OR p.age_category = :inputAgeCategory) " +
30+
"AND (:inputGenderCategory IS NULL OR p.gender_category = :inputGenderCategory) " +
31+
"AND p.is_deleted = false " +
32+
"ORDER BY p.created_at DESC";
33+
34+
Query query = entityManager.createNativeQuery(sql, "GetProductDtoMapping");
35+
query.setParameter("inputProductCategory", inputProductCategory);
36+
query.setParameter("inputAgeCategory", inputAgeCategory);
37+
query.setParameter("inputGenderCategory", inputGenderCategory);
38+
query.setFirstResult((int) pageable.getOffset());
39+
query.setMaxResults(pageable.getPageSize());
40+
41+
//noinspection unchecked
42+
return query.getResultList();
43+
}
44+
45+
public List<GetProductDto> findByProductCategorySortByPrice(
46+
String inputProductCategory,
47+
String inputAgeCategory,
48+
String inputGenderCategory,
49+
Pageable pageable) {
50+
51+
String sql = "SELECT p.id, p.name, p.price, p.created_at, " +
52+
"p.product_category, p.age_category, p.gender_category, " +
53+
"p.left_amount, p.thumbnail_url, s.shop_name " +
54+
"FROM commerce.products p LEFT JOIN commerce.sellers s ON p.sellers_id = s.id " +
55+
"WHERE p.product_category = :inputProductCategory " +
56+
"AND (:inputAgeCategory IS NULL OR p.age_category = :inputAgeCategory) " +
57+
"AND (:inputGenderCategory IS NULL OR p.gender_category = :inputGenderCategory) " +
58+
"AND p.is_deleted = false " +
59+
"ORDER BY p.price ASC";
60+
61+
Query query = entityManager.createNativeQuery(sql, "GetProductDtoMapping");
62+
query.setParameter("inputProductCategory", inputProductCategory);
63+
query.setParameter("inputAgeCategory", inputAgeCategory);
64+
query.setParameter("inputGenderCategory", inputGenderCategory);
65+
query.setFirstResult((int) pageable.getOffset());
66+
query.setMaxResults(pageable.getPageSize());
67+
68+
//noinspection unchecked
69+
return query.getResultList();
70+
}
71+
72+
public List<GetProductDto> findByProductCategorySortById(
73+
String inputProductCategory,
74+
String inputAgeCategory,
75+
String inputGenderCategory,
76+
Pageable pageable) {
77+
78+
String sql = "SELECT p.id, p.name, p.price, p.created_at, " +
79+
"p.product_category, p.age_category, p.gender_category, " +
80+
"p.left_amount, p.thumbnail_url, s.shop_name " +
81+
"FROM commerce.products p LEFT JOIN commerce.sellers s ON p.sellers_id = s.id " +
82+
"WHERE p.product_category = :inputProductCategory " +
83+
"AND (:inputAgeCategory IS NULL OR p.age_category = :inputAgeCategory) " +
84+
"AND (:inputGenderCategory IS NULL OR p.gender_category = :inputGenderCategory) " +
85+
"AND p.is_deleted = false " +
86+
"ORDER BY p.id ASC";
87+
88+
Query query = entityManager.createNativeQuery(sql, "GetProductDtoMapping");
89+
query.setParameter("inputProductCategory", inputProductCategory);
90+
query.setParameter("inputAgeCategory", inputAgeCategory);
91+
query.setParameter("inputGenderCategory", inputGenderCategory);
92+
query.setFirstResult((int) pageable.getOffset());
93+
query.setMaxResults(pageable.getPageSize());
94+
95+
//noinspection unchecked
96+
return query.getResultList();
97+
}
98+
99+
public List<GetProductDto> findAllSortByCreatedAt(
100+
String inputAgeCategory,
101+
String inputGenderCategory,
102+
Pageable pageable) {
103+
String sql = "SELECT p.id, p.name, p.price, p.created_at, " +
104+
"p.product_category, p.age_category, p.gender_category, " +
105+
"p.left_amount, p.thumbnail_url, s.shop_name " +
106+
"FROM commerce.products p LEFT JOIN commerce.sellers s ON p.sellers_id = s.id " +
107+
"WHERE (:inputAgeCategory IS NULL OR p.age_category = :inputAgeCategory) " +
108+
"AND (:inputGenderCategory IS NULL OR p.gender_category = :inputGenderCategory) " +
109+
"AND p.is_deleted = false " +
110+
"ORDER BY p.created_at DESC";
111+
112+
Query query = entityManager.createNativeQuery(sql, "GetProductDtoMapping");
113+
query.setParameter("inputAgeCategory", inputAgeCategory);
114+
query.setParameter("inputGenderCategory", inputGenderCategory);
115+
query.setFirstResult((int) pageable.getOffset());
116+
query.setMaxResults(pageable.getPageSize());
117+
118+
//noinspection unchecked
119+
return query.getResultList();
120+
}
121+
122+
public List<GetProductDto> findAllSortByPrice(
123+
String inputAgeCategory,
124+
String inputGenderCategory,
125+
Pageable pageable) {
126+
String sql = "SELECT p.id, p.name, p.price, p.created_at, " +
127+
"p.product_category, p.age_category, p.gender_category, " +
128+
"p.left_amount, p.thumbnail_url, s.shop_name " +
129+
"FROM commerce.products p LEFT JOIN commerce.sellers s ON p.sellers_id = s.id " +
130+
"WHERE (:inputAgeCategory IS NULL OR p.age_category = :inputAgeCategory) " +
131+
"AND (:inputGenderCategory IS NULL OR p.gender_category = :inputGenderCategory) " +
132+
"AND p.is_deleted = false " +
133+
"ORDER BY p.price ASC";
134+
135+
Query query = entityManager.createNativeQuery(sql, "GetProductDtoMapping");
136+
query.setParameter("inputAgeCategory", inputAgeCategory);
137+
query.setParameter("inputGenderCategory", inputGenderCategory);
138+
query.setFirstResult((int) pageable.getOffset());
139+
query.setMaxResults(pageable.getPageSize());
140+
141+
//noinspection unchecked
142+
return query.getResultList();
143+
}
144+
145+
public List<GetProductDto> findAllSortById(
146+
String inputAgeCategory,
147+
String inputGenderCategory,
148+
Pageable pageable) {
149+
String sql = "SELECT p.id, p.name, p.price, p.created_at, " +
150+
"p.product_category, p.age_category, p.gender_category, " +
151+
"p.left_amount, p.thumbnail_url, s.shop_name " +
152+
"FROM commerce.products p LEFT JOIN commerce.sellers s ON p.sellers_id = s.id " +
153+
"WHERE (:inputAgeCategory IS NULL OR p.age_category = :inputAgeCategory) " +
154+
"AND (:inputGenderCategory IS NULL OR p.gender_category = :inputGenderCategory) " +
155+
"AND p.is_deleted = false " +
156+
"ORDER BY p.id ASC";
157+
158+
Query query = entityManager.createNativeQuery(sql, "GetProductDtoMapping");
159+
query.setParameter("inputAgeCategory", inputAgeCategory);
160+
query.setParameter("inputGenderCategory", inputGenderCategory);
161+
query.setFirstResult((int) pageable.getOffset());
162+
query.setMaxResults(pageable.getPageSize());
163+
164+
//noinspection unchecked
165+
return query.getResultList();
166+
}
167+
168+
public List<GetProductDto> searchProductSortByPrice(
169+
String searchToken,
170+
String inputAgeCategory,
171+
String inputGenderCategory,
172+
Pageable pageable) {
173+
String sql = "SELECT p.id, p.name, p.price, p.created_at, " +
174+
"p.product_category, p.age_category, p.gender_category, " +
175+
"p.left_amount, p.thumbnail_url, s.shop_name " +
176+
"FROM commerce.products p LEFT JOIN commerce.sellers s ON p.sellers_id = s.id " +
177+
"WHERE (:inputAgeCategory IS NULL OR p.age_category = :inputAgeCategory) " +
178+
"AND (:inputGenderCategory IS NULL OR p.gender_category = :inputGenderCategory) " +
179+
"AND p.is_deleted = false " +
180+
"AND p.name LIKE :searchToken " +
181+
"ORDER BY p.price ASC";
182+
183+
Query query = entityManager.createNativeQuery(sql, "GetProductDtoMapping");
184+
query.setParameter("searchToken", searchToken);
185+
query.setParameter("inputAgeCategory", inputAgeCategory);
186+
query.setParameter("inputGenderCategory", inputGenderCategory);
187+
query.setFirstResult((int) pageable.getOffset());
188+
query.setMaxResults(pageable.getPageSize());
189+
190+
//noinspection unchecked
191+
return query.getResultList();
192+
}
193+
194+
195+
public List<GetProductDto> searchProductSortByCreatedAt(String searchToken, String inputAgeCategory, String inputGenderCategory, Pageable pageable)
196+
{
197+
String sql = "SELECT p.id, p.name, p.price, p.created_at, " +
198+
"p.product_category, p.age_category, p.gender_category, " +
199+
"p.left_amount, p.thumbnail_url, s.shop_name " +
200+
"FROM commerce.products p LEFT JOIN commerce.sellers s ON p.sellers_id = s.id " +
201+
"WHERE (:inputAgeCategory IS NULL OR p.age_category = :inputAgeCategory) " +
202+
"AND (:inputGenderCategory IS NULL OR p.gender_category = :inputGenderCategory) " +
203+
"AND p.is_deleted = false " +
204+
"AND p.name LIKE :searchToken " +
205+
"ORDER BY p.created_at DESC";
206+
207+
Query query = entityManager.createNativeQuery(sql, "GetProductDtoMapping");
208+
query.setParameter("searchToken", searchToken);
209+
query.setParameter("inputAgeCategory", inputAgeCategory);
210+
query.setParameter("inputGenderCategory", inputGenderCategory);
211+
query.setFirstResult((int) pageable.getOffset());
212+
query.setMaxResults(pageable.getPageSize());
213+
214+
//noinspection unchecked
215+
return query.getResultList();
216+
217+
}
218+
219+
public List<GetProductDto> searchProductSortById(String searchToken, String inputAgeCategory, String inputGenderCategory, Pageable pageable) {
220+
String sql = "SELECT p.id, p.name, p.price, p.created_at, " +
221+
"p.product_category, p.age_category, p.gender_category, " +
222+
"p.left_amount, p.thumbnail_url, s.shop_name " +
223+
"FROM commerce.products p LEFT JOIN commerce.sellers s ON p.sellers_id = s.id " +
224+
"WHERE (:inputAgeCategory IS NULL OR p.age_category = :inputAgeCategory) " +
225+
"AND (:inputGenderCategory IS NULL OR p.gender_category = :inputGenderCategory) " +
226+
"AND p.is_deleted = false " +
227+
"AND p.name LIKE :searchToken " +
228+
"ORDER BY p.id ASC";
229+
230+
Query query = entityManager.createNativeQuery(sql, "GetProductDtoMapping");
231+
query.setParameter("searchToken", searchToken);
232+
query.setParameter("inputAgeCategory", inputAgeCategory);
233+
query.setParameter("inputGenderCategory", inputGenderCategory);
234+
query.setFirstResult((int) pageable.getOffset());
235+
query.setMaxResults(pageable.getPageSize());
236+
237+
//noinspection unchecked
238+
return query.getResultList();
239+
240+
}
241+
}

src/main/java/com/github/commerce/service/cart/CartService.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import com.github.commerce.entity.Product;
55
import com.github.commerce.entity.User;
66
import com.github.commerce.repository.cart.CartRepository;
7-
import com.github.commerce.repository.product.ProductRepository;
87
import com.github.commerce.service.cart.util.ValidatCartMethod;
98
import com.github.commerce.web.dto.cart.CartDto;
109
import com.github.commerce.web.dto.cart.CartRmqDto;
@@ -21,9 +20,6 @@
2120
import org.springframework.transaction.annotation.Transactional;
2221

2322
import java.time.LocalDate;
24-
import java.time.LocalDateTime;
25-
import java.time.ZoneId;
26-
import java.time.ZonedDateTime;
2723
import java.util.ArrayList;
2824
import java.util.List;
2925
import java.util.Map;
@@ -36,7 +32,6 @@ public class CartService {
3632
private final CartRepository cartRepository;
3733
private final ValidatCartMethod validatCartMethod;
3834
private final RabbitTemplate rabbitTemplate;
39-
private final ProductRepository productRepository;
4035

4136
@Transactional(readOnly = true)
4237
public List<Map<LocalDate, List<CartDto>>> getAllCarts(Long userId){
@@ -159,12 +154,4 @@ public String deleteOne(Long cartId, Long userId){
159154
return validatedCart.getId() + "번 장바구니 삭제";
160155
}
161156

162-
public LocalDateTime getKoreanTime(){
163-
ZoneId koreanZone = ZoneId.of("Asia/Seoul");
164-
ZonedDateTime koreanTime = ZonedDateTime.now(koreanZone);
165-
166-
// Convert it to LocalDateTime
167-
return koreanTime.toLocalDateTime();
168-
169-
}
170157
}

0 commit comments

Comments
 (0)