Skip to content

Commit

Permalink
Merge pull request #161 from MoonJongHyeon1095/dev
Browse files Browse the repository at this point in the history
fix: EC2 정지 현상 문제원인 파악중
  • Loading branch information
MoonJongHyeon1095 authored Nov 18, 2023
2 parents 8b4dedf + bb0afe0 commit df9973d
Show file tree
Hide file tree
Showing 19 changed files with 1,145 additions and 161 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
# BE
<br>
<h2><b>tech stack</b></h3>
<p>
<img src="https://img.shields.io/badge/Spring Boot-6DB33F?style=for-the-badge&logo=Spring Boot&logoColor=white">
<img src="https://img.shields.io/badge/Spring Security-6DB33F?style=for-the-badge&logo=Spring Security&logoColor=white">
<img src="https://img.shields.io/badge/Web Socket-010101?style=for-the-badge&logo=Web Socket&logoColor=white">
<img src="https://img.shields.io/badge/Rabbit MQ-FF6600?style=for-the-badge&logo=rabbitmq&logoColor=white">
<br>
<img src="https://img.shields.io/badge/NginX-009639?style=for-the-badge&logo=NGINX&logoColor=white">
<img src="https://img.shields.io/badge/Docker-2496ED?style=for-the-badge&logo=Docker&logoColor=white">
<img src="https://img.shields.io/badge/MySQL-4479A1?style=for-the-badge&logo=MySQL&logoColor=white">
<img src="https://img.shields.io/badge/Amazon AWS-FF9900?style=for-the-badge&logo=Amazon AWS&logoColor=white">
<img src="https://img.shields.io/badge/Github Actions-2088FF?style=for-the-badge&logo=Github Actions&logoColor=white">
<br>
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ dependencies {
// Spring Batch
implementation 'org.springframework.boot:spring-boot-starter-batch'
testImplementation 'org.springframework.batch:spring-batch-test'

//h2
testImplementation 'com.h2database:h2'

}

tasks.named('test') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ public class UpdateCustomerGradeScheduler { //매월 1일 오전 12:00:00 구매
@Autowired
private Job updateCustomerGradeJob;

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

JobParameters jobParameters = new JobParameters(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class WebSecurityConfig {
private final JwtUtil jwtUtil;
private final UserDetailsServiceImpl userDetailsService;
private static final String[] PERMIT_URL_ARRAY = {
"/","/v1/api/user/**","/v1/api/product/**","/v1/api/coupon","/GuerrillaCommerce",
"/","/v1/api/user/**","/v1/api/product/**","/v1/api/coupon","/GuerrillaCommerce", "/v1/api/navi",
"/api/v2/**", "/swagger-ui.html", "/swagger/**","/swagger-resources/**", "/webjars/**", "/v2/api-docs"
};

Expand Down
19 changes: 19 additions & 0 deletions src/main/java/com/github/commerce/entity/Product.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.commerce.entity;

import com.github.commerce.web.dto.product.GetProductDto;
import com.github.commerce.web.dto.product.ProductRequest;
import com.google.gson.Gson;
import lombok.*;
Expand All @@ -17,6 +18,24 @@
@AllArgsConstructor
@Builder
@Entity
@SqlResultSetMapping(
name = "GetProductDtoMapping",
classes = @ConstructorResult(
targetClass = GetProductDto.class,
columns = {
@ColumnResult(name = "id", type = Long.class),
@ColumnResult(name = "name", type = String.class),
@ColumnResult(name = "price", type = Integer.class),
@ColumnResult(name = "created_at", type = LocalDateTime.class),
@ColumnResult(name = "product_category", type = String.class),
@ColumnResult(name = "age_category", type = String.class),
@ColumnResult(name = "gender_category", type = String.class),
@ColumnResult(name = "left_amount", type = Integer.class),
@ColumnResult(name = "thumbnail_url", type = String.class),
@ColumnResult(name = "shop_name", type = String.class)
}
)
)
@Table(name = "products")
public class Product {
@Id
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
package com.github.commerce.repository.product;

import com.github.commerce.web.dto.product.GetProductDto;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import java.util.List;

@Repository
public class ProductRepositoryCustom {

@PersistenceContext
private EntityManager entityManager;

public List<GetProductDto> findByProductCategorySortByCreatedAt(
String inputProductCategory,
String inputAgeCategory,
String inputGenderCategory,
Pageable pageable) {

String sql = "SELECT p.id, p.name, p.price, p.created_at, " +
"p.product_category, p.age_category, p.gender_category, " +
"p.left_amount, p.thumbnail_url, s.shop_name " +
"FROM commerce.products p LEFT JOIN commerce.sellers s ON p.sellers_id = s.id " +
"WHERE p.product_category = :inputProductCategory " +
"AND (:inputAgeCategory IS NULL OR p.age_category = :inputAgeCategory) " +
"AND (:inputGenderCategory IS NULL OR p.gender_category = :inputGenderCategory) " +
"AND p.is_deleted = false " +
"ORDER BY p.created_at DESC";

Query query = entityManager.createNativeQuery(sql, "GetProductDtoMapping");
query.setParameter("inputProductCategory", inputProductCategory);
query.setParameter("inputAgeCategory", inputAgeCategory);
query.setParameter("inputGenderCategory", inputGenderCategory);
query.setFirstResult((int) pageable.getOffset());
query.setMaxResults(pageable.getPageSize());

//noinspection unchecked
return query.getResultList();
}

public List<GetProductDto> findByProductCategorySortByPrice(
String inputProductCategory,
String inputAgeCategory,
String inputGenderCategory,
Pageable pageable) {

String sql = "SELECT p.id, p.name, p.price, p.created_at, " +
"p.product_category, p.age_category, p.gender_category, " +
"p.left_amount, p.thumbnail_url, s.shop_name " +
"FROM commerce.products p LEFT JOIN commerce.sellers s ON p.sellers_id = s.id " +
"WHERE p.product_category = :inputProductCategory " +
"AND (:inputAgeCategory IS NULL OR p.age_category = :inputAgeCategory) " +
"AND (:inputGenderCategory IS NULL OR p.gender_category = :inputGenderCategory) " +
"AND p.is_deleted = false " +
"ORDER BY p.price ASC";

Query query = entityManager.createNativeQuery(sql, "GetProductDtoMapping");
query.setParameter("inputProductCategory", inputProductCategory);
query.setParameter("inputAgeCategory", inputAgeCategory);
query.setParameter("inputGenderCategory", inputGenderCategory);
query.setFirstResult((int) pageable.getOffset());
query.setMaxResults(pageable.getPageSize());

//noinspection unchecked
return query.getResultList();
}

public List<GetProductDto> findByProductCategorySortById(
String inputProductCategory,
String inputAgeCategory,
String inputGenderCategory,
Pageable pageable) {

String sql = "SELECT p.id, p.name, p.price, p.created_at, " +
"p.product_category, p.age_category, p.gender_category, " +
"p.left_amount, p.thumbnail_url, s.shop_name " +
"FROM commerce.products p LEFT JOIN commerce.sellers s ON p.sellers_id = s.id " +
"WHERE p.product_category = :inputProductCategory " +
"AND (:inputAgeCategory IS NULL OR p.age_category = :inputAgeCategory) " +
"AND (:inputGenderCategory IS NULL OR p.gender_category = :inputGenderCategory) " +
"AND p.is_deleted = false " +
"ORDER BY p.id ASC";

Query query = entityManager.createNativeQuery(sql, "GetProductDtoMapping");
query.setParameter("inputProductCategory", inputProductCategory);
query.setParameter("inputAgeCategory", inputAgeCategory);
query.setParameter("inputGenderCategory", inputGenderCategory);
query.setFirstResult((int) pageable.getOffset());
query.setMaxResults(pageable.getPageSize());

//noinspection unchecked
return query.getResultList();
}

public List<GetProductDto> findAllSortByCreatedAt(
String inputAgeCategory,
String inputGenderCategory,
Pageable pageable) {
String sql = "SELECT p.id, p.name, p.price, p.created_at, " +
"p.product_category, p.age_category, p.gender_category, " +
"p.left_amount, p.thumbnail_url, s.shop_name " +
"FROM commerce.products p LEFT JOIN commerce.sellers s ON p.sellers_id = s.id " +
"WHERE (:inputAgeCategory IS NULL OR p.age_category = :inputAgeCategory) " +
"AND (:inputGenderCategory IS NULL OR p.gender_category = :inputGenderCategory) " +
"AND p.is_deleted = false " +
"ORDER BY p.created_at DESC";

Query query = entityManager.createNativeQuery(sql, "GetProductDtoMapping");
query.setParameter("inputAgeCategory", inputAgeCategory);
query.setParameter("inputGenderCategory", inputGenderCategory);
query.setFirstResult((int) pageable.getOffset());
query.setMaxResults(pageable.getPageSize());

//noinspection unchecked
return query.getResultList();
}

public List<GetProductDto> findAllSortByPrice(
String inputAgeCategory,
String inputGenderCategory,
Pageable pageable) {
String sql = "SELECT p.id, p.name, p.price, p.created_at, " +
"p.product_category, p.age_category, p.gender_category, " +
"p.left_amount, p.thumbnail_url, s.shop_name " +
"FROM commerce.products p LEFT JOIN commerce.sellers s ON p.sellers_id = s.id " +
"WHERE (:inputAgeCategory IS NULL OR p.age_category = :inputAgeCategory) " +
"AND (:inputGenderCategory IS NULL OR p.gender_category = :inputGenderCategory) " +
"AND p.is_deleted = false " +
"ORDER BY p.price ASC";

Query query = entityManager.createNativeQuery(sql, "GetProductDtoMapping");
query.setParameter("inputAgeCategory", inputAgeCategory);
query.setParameter("inputGenderCategory", inputGenderCategory);
query.setFirstResult((int) pageable.getOffset());
query.setMaxResults(pageable.getPageSize());

//noinspection unchecked
return query.getResultList();
}

public List<GetProductDto> findAllSortById(
String inputAgeCategory,
String inputGenderCategory,
Pageable pageable) {
String sql = "SELECT p.id, p.name, p.price, p.created_at, " +
"p.product_category, p.age_category, p.gender_category, " +
"p.left_amount, p.thumbnail_url, s.shop_name " +
"FROM commerce.products p LEFT JOIN commerce.sellers s ON p.sellers_id = s.id " +
"WHERE (:inputAgeCategory IS NULL OR p.age_category = :inputAgeCategory) " +
"AND (:inputGenderCategory IS NULL OR p.gender_category = :inputGenderCategory) " +
"AND p.is_deleted = false " +
"ORDER BY p.id ASC";

Query query = entityManager.createNativeQuery(sql, "GetProductDtoMapping");
query.setParameter("inputAgeCategory", inputAgeCategory);
query.setParameter("inputGenderCategory", inputGenderCategory);
query.setFirstResult((int) pageable.getOffset());
query.setMaxResults(pageable.getPageSize());

//noinspection unchecked
return query.getResultList();
}

public List<GetProductDto> searchProductSortByPrice(
String searchToken,
String inputAgeCategory,
String inputGenderCategory,
Pageable pageable) {
String sql = "SELECT p.id, p.name, p.price, p.created_at, " +
"p.product_category, p.age_category, p.gender_category, " +
"p.left_amount, p.thumbnail_url, s.shop_name " +
"FROM commerce.products p LEFT JOIN commerce.sellers s ON p.sellers_id = s.id " +
"WHERE (:inputAgeCategory IS NULL OR p.age_category = :inputAgeCategory) " +
"AND (:inputGenderCategory IS NULL OR p.gender_category = :inputGenderCategory) " +
"AND p.is_deleted = false " +
"AND p.name LIKE :searchToken " +
"ORDER BY p.price ASC";

Query query = entityManager.createNativeQuery(sql, "GetProductDtoMapping");
query.setParameter("searchToken", searchToken);
query.setParameter("inputAgeCategory", inputAgeCategory);
query.setParameter("inputGenderCategory", inputGenderCategory);
query.setFirstResult((int) pageable.getOffset());
query.setMaxResults(pageable.getPageSize());

//noinspection unchecked
return query.getResultList();
}


public List<GetProductDto> searchProductSortByCreatedAt(String searchToken, String inputAgeCategory, String inputGenderCategory, Pageable pageable)
{
String sql = "SELECT p.id, p.name, p.price, p.created_at, " +
"p.product_category, p.age_category, p.gender_category, " +
"p.left_amount, p.thumbnail_url, s.shop_name " +
"FROM commerce.products p LEFT JOIN commerce.sellers s ON p.sellers_id = s.id " +
"WHERE (:inputAgeCategory IS NULL OR p.age_category = :inputAgeCategory) " +
"AND (:inputGenderCategory IS NULL OR p.gender_category = :inputGenderCategory) " +
"AND p.is_deleted = false " +
"AND p.name LIKE :searchToken " +
"ORDER BY p.created_at DESC";

Query query = entityManager.createNativeQuery(sql, "GetProductDtoMapping");
query.setParameter("searchToken", searchToken);
query.setParameter("inputAgeCategory", inputAgeCategory);
query.setParameter("inputGenderCategory", inputGenderCategory);
query.setFirstResult((int) pageable.getOffset());
query.setMaxResults(pageable.getPageSize());

//noinspection unchecked
return query.getResultList();

}

public List<GetProductDto> searchProductSortById(String searchToken, String inputAgeCategory, String inputGenderCategory, Pageable pageable) {
String sql = "SELECT p.id, p.name, p.price, p.created_at, " +
"p.product_category, p.age_category, p.gender_category, " +
"p.left_amount, p.thumbnail_url, s.shop_name " +
"FROM commerce.products p LEFT JOIN commerce.sellers s ON p.sellers_id = s.id " +
"WHERE (:inputAgeCategory IS NULL OR p.age_category = :inputAgeCategory) " +
"AND (:inputGenderCategory IS NULL OR p.gender_category = :inputGenderCategory) " +
"AND p.is_deleted = false " +
"AND p.name LIKE :searchToken " +
"ORDER BY p.id ASC";

Query query = entityManager.createNativeQuery(sql, "GetProductDtoMapping");
query.setParameter("searchToken", searchToken);
query.setParameter("inputAgeCategory", inputAgeCategory);
query.setParameter("inputGenderCategory", inputGenderCategory);
query.setFirstResult((int) pageable.getOffset());
query.setMaxResults(pageable.getPageSize());

//noinspection unchecked
return query.getResultList();

}
}
13 changes: 0 additions & 13 deletions src/main/java/com/github/commerce/service/cart/CartService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.github.commerce.entity.Product;
import com.github.commerce.entity.User;
import com.github.commerce.repository.cart.CartRepository;
import com.github.commerce.repository.product.ProductRepository;
import com.github.commerce.service.cart.util.ValidatCartMethod;
import com.github.commerce.web.dto.cart.CartDto;
import com.github.commerce.web.dto.cart.CartRmqDto;
Expand All @@ -21,9 +20,6 @@
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand All @@ -36,7 +32,6 @@ public class CartService {
private final CartRepository cartRepository;
private final ValidatCartMethod validatCartMethod;
private final RabbitTemplate rabbitTemplate;
private final ProductRepository productRepository;

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

public LocalDateTime getKoreanTime(){
ZoneId koreanZone = ZoneId.of("Asia/Seoul");
ZonedDateTime koreanTime = ZonedDateTime.now(koreanZone);

// Convert it to LocalDateTime
return koreanTime.toLocalDateTime();

}
}
Loading

0 comments on commit df9973d

Please sign in to comment.