From b74b1b4159f3b4cbd645b19e905a3a1266b5bb93 Mon Sep 17 00:00:00 2001 From: jooooonj Date: Wed, 20 Sep 2023 10:58:09 +0900 Subject: [PATCH 1/7] =?UTF-8?q?fix:=20=EA=B2=B0=EC=A0=9C=EB=90=98=EC=A7=80?= =?UTF-8?q?=20=EC=95=8A=EC=9D=80=20=EC=A3=BC=EB=AC=B8=20=EC=82=AD=EC=A0=9C?= =?UTF-8?q?=20job=20=EC=9D=B4=20=EC=A0=9C=EB=8C=80=EB=A1=9C=20=EC=8B=A4?= =?UTF-8?q?=ED=96=89=EB=90=98=EC=A7=80=20=EC=95=8A=EB=8A=94=20=EB=AC=B8?= =?UTF-8?q?=EC=A0=9C=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/orders/entity/Order.java | 8 -------- .../orders/repository/OrderRepository.java | 4 ++-- .../job/{JobConfig.java => JobScheduler.java} | 16 ++++++---------- .../CancelOrderJobConfig.java | 2 +- 4 files changed, 9 insertions(+), 21 deletions(-) rename src/main/java/project/trendpick_pro/global/job/{JobConfig.java => JobScheduler.java} (84%) diff --git a/src/main/java/project/trendpick_pro/domain/orders/entity/Order.java b/src/main/java/project/trendpick_pro/domain/orders/entity/Order.java index 8de538ac..70f56a47 100644 --- a/src/main/java/project/trendpick_pro/domain/orders/entity/Order.java +++ b/src/main/java/project/trendpick_pro/domain/orders/entity/Order.java @@ -94,14 +94,6 @@ public void cancel() { orderItem.cancel(); } - public void cancelTemp() { - this.orderStatus = OrderStatus.TEMP; - this.delivery.canceledDelivery(); - for (OrderItem orderItem : this.orderItems) { - orderItem.cancel(); - } - } - public String getOrderState(){ return switch (orderStatus.getValue()){ case "ORDERED"->"결제완료"; diff --git a/src/main/java/project/trendpick_pro/domain/orders/repository/OrderRepository.java b/src/main/java/project/trendpick_pro/domain/orders/repository/OrderRepository.java index 39b272fe..20247ef0 100644 --- a/src/main/java/project/trendpick_pro/domain/orders/repository/OrderRepository.java +++ b/src/main/java/project/trendpick_pro/domain/orders/repository/OrderRepository.java @@ -1,5 +1,6 @@ package project.trendpick_pro.domain.orders.repository; +import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; @@ -7,12 +8,11 @@ import project.trendpick_pro.domain.orders.entity.Order; import java.time.LocalDateTime; -import java.util.List; public interface OrderRepository extends JpaRepository, OrderRepositoryCustom { @Query("select o from Order o " + "where o.paymentKey IS NULL " + "and o.createdDate <= :expireDate") - List findAllByPaymentKeyIsNullAndCreatedDateIsBefore(@Param("expireDate") LocalDateTime expireDate, Pageable pageable); + Page findAllByPaymentKeyIsNullAndCreatedDateIsBefore(@Param("expireDate") LocalDateTime expireDate, Pageable pageable); } diff --git a/src/main/java/project/trendpick_pro/global/job/JobConfig.java b/src/main/java/project/trendpick_pro/global/job/JobScheduler.java similarity index 84% rename from src/main/java/project/trendpick_pro/global/job/JobConfig.java rename to src/main/java/project/trendpick_pro/global/job/JobScheduler.java index f2d1b401..f707c291 100644 --- a/src/main/java/project/trendpick_pro/global/job/JobConfig.java +++ b/src/main/java/project/trendpick_pro/global/job/JobScheduler.java @@ -3,20 +3,16 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.batch.core.*; -import org.springframework.batch.core.configuration.JobRegistry; import org.springframework.batch.core.launch.JobLauncher; import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException; import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException; import org.springframework.batch.core.repository.JobRestartException; -import org.springframework.batch.item.database.JdbcBatchItemWriter; import org.springframework.beans.factory.annotation.Qualifier; -import lombok.RequiredArgsConstructor; import org.springframework.batch.core.Job; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.JobParametersBuilder; -import org.springframework.batch.core.launch.JobLauncher; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; @@ -26,7 +22,7 @@ @Component @RequiredArgsConstructor @Slf4j -public class JobConfig { +public class JobScheduler { private final JobLauncher jobLauncher; //job을 실행시키는 주체 @Qualifier("makeRecommendProductJob") private final Job makeRecommendProductJob; @@ -55,11 +51,11 @@ public void performMakeRecommendProductJob() throws Exception { log.info(execution.getStatus().toString()); } - // 매일 02시에 전날 생성된 주문 객체중 결제 처리가 안된 객체를 일괄 삭제 처리한다. - @Scheduled(cron = "0 0 2 * * *") + // 10분마다 체크해서 주문이 생성된지 30분 이상 지났는데 결제 처리가 없으면 주문을 취소상태로 변경한다. + @Scheduled(fixedRate = 1000 * 60 * 10) public void performCancelOrderJob() throws JobInstanceAlreadyCompleteException, JobExecutionAlreadyRunningException, JobParametersInvalidException, JobRestartException { - LocalDateTime date = LocalDateTime.now().minusDays(1).with(LocalTime.MAX); //전날 11:59 -// LocalDateTime fake = LocalDateTime.now().plusDays(1); //테스트용 + LocalDateTime date = LocalDateTime.now().minusMinutes(30); +// LocalDateTime date = LocalDateTime.now().plusDays(1); //테스트용 JobParameters param = new JobParametersBuilder() .addLocalDateTime("date", date) //전날 11:59 @@ -69,7 +65,7 @@ public void performCancelOrderJob() throws JobInstanceAlreadyCompleteException, } - // 매일 04시에 일일정산을 통해 월 정산을 갱신해준다. + // 매일 04시에 당월의 주문 목록을 복사해서 정산용 주문 목록으로 만들어 저장한다. @Scheduled(cron = "0 0 4 * * *") // 실제 코드 public void performMakeRebateDataJob() throws Exception { String yearMonth = getPerformMakeRebateDataJobParam1Value(); // 실제 코드 diff --git a/src/main/java/project/trendpick_pro/global/job/cancelOrderJobConfig/CancelOrderJobConfig.java b/src/main/java/project/trendpick_pro/global/job/cancelOrderJobConfig/CancelOrderJobConfig.java index db3d0df6..69da6d51 100644 --- a/src/main/java/project/trendpick_pro/global/job/cancelOrderJobConfig/CancelOrderJobConfig.java +++ b/src/main/java/project/trendpick_pro/global/job/cancelOrderJobConfig/CancelOrderJobConfig.java @@ -43,7 +43,7 @@ public class CancelOrderJobConfig{ public Job cancelOrderJob(Step cancelOrderStep, JobRepository jobRepository) throws Exception { return new JobBuilder("cancelOrderJob", jobRepository) .start(cancelOrderStep) -// .incrementer(new RunIdIncrementer()) //계속해서 id 업데이트 (내용이같아도) + .incrementer(new RunIdIncrementer()) //계속해서 id 업데이트 (내용이같아도) .build(); } From 8170b48aa8d303fe5d8ee12cd018d0bb626e9f60 Mon Sep 17 00:00:00 2001 From: jooooonj Date: Wed, 20 Sep 2023 12:24:37 +0900 Subject: [PATCH 2/7] =?UTF-8?q?refactor:=20=EC=9E=A5=EB=B0=94=EA=B5=AC?= =?UTF-8?q?=EB=8B=88=20=EB=8B=B4=EA=B8=B0=20=EC=8B=9C=20=EA=B8=B0=EC=A1=B4?= =?UTF-8?q?=20=ED=8E=98=EC=9D=B4=EC=A7=80=20=EC=9C=A0=EC=A7=80=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/cart/controller/CartController.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/project/trendpick_pro/domain/cart/controller/CartController.java b/src/main/java/project/trendpick_pro/domain/cart/controller/CartController.java index bf95e5b6..6b650acd 100644 --- a/src/main/java/project/trendpick_pro/domain/cart/controller/CartController.java +++ b/src/main/java/project/trendpick_pro/domain/cart/controller/CartController.java @@ -1,6 +1,7 @@ package project.trendpick_pro.domain.cart.controller; +import jakarta.servlet.http.HttpServletRequest; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -38,13 +39,14 @@ public String showCart(Model model) { @PreAuthorize("hasAuthority({'MEMBER'})") @PostMapping("/add") - public String addItem(@ModelAttribute @Valid CartItemRequest cartItemRequests) { + public String addItem(@ModelAttribute @Valid CartItemRequest cartItemRequests, HttpServletRequest req) { RsData result = cartService.addCartItem(rq.getMember(), cartItemRequests); if(result.isFail()) - return rq.redirectWithMsg("/trendpick/products/list?main-category=상의",result); + return rq.historyBack(result); - return rq.redirectWithMsg("/trendpick/usr/cart/list", result); + String referer = req.getHeader("referer"); + return rq.redirectWithMsg(referer, result); } @PreAuthorize("hasAuthority({'MEMBER'})") From 7142353d2e7ff252f8a4d40385fe19b4574abddb Mon Sep 17 00:00:00 2001 From: jooooonj Date: Wed, 20 Sep 2023 12:25:43 +0900 Subject: [PATCH 3/7] =?UTF-8?q?refactor:=20=EC=A3=BC=EB=AC=B8=EC=84=9C?= =?UTF-8?q?=EB=A1=9C=20=EC=9D=B4=EB=8F=99=ED=95=98=EB=8A=94=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=EA=B3=84=EC=B8=B5?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/orders/contoller/OrderController.java | 10 +++++++--- .../domain/orders/service/OrderService.java | 1 + .../orders/service/impl/OrderServiceImpl.java | 16 ++++++++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/main/java/project/trendpick_pro/domain/orders/contoller/OrderController.java b/src/main/java/project/trendpick_pro/domain/orders/contoller/OrderController.java index cb380d30..be722d4c 100644 --- a/src/main/java/project/trendpick_pro/domain/orders/contoller/OrderController.java +++ b/src/main/java/project/trendpick_pro/domain/orders/contoller/OrderController.java @@ -29,10 +29,14 @@ public class OrderController { @PreAuthorize("hasAuthority({'MEMBER'})") @GetMapping("{orderId}/form") public String showOrderForm(@PathVariable("orderId") Long orderId, Model model){ - Order order = orderService.findById(orderId); - if(order.getPaymentKey() != null || order.getOrderState().equals("주문취소")) + RsData result = orderService.getOrderFormData(orderId); + if(result.getResultCode().equals("F-1")) + return rq.historyBack("주문중 오류가 발생했습니다. 다시 한 번 시도해주세요."); + + if(result.getResultCode().equals("F-2")) return rq.redirectWithMsg("/", "이미 처리된 주문입니다."); - model.addAttribute("order", order); + + model.addAttribute("order", result.getData()); return "trendpick/orders/order-form"; } diff --git a/src/main/java/project/trendpick_pro/domain/orders/service/OrderService.java b/src/main/java/project/trendpick_pro/domain/orders/service/OrderService.java index 6f6ee020..54032f9c 100644 --- a/src/main/java/project/trendpick_pro/domain/orders/service/OrderService.java +++ b/src/main/java/project/trendpick_pro/domain/orders/service/OrderService.java @@ -27,4 +27,5 @@ public interface OrderService { Order findById(Long id); Page findCanceledOrders(Member member, int offset); List findAllByCreatedDateBetweenOrderByIdAsc(LocalDateTime fromDate, LocalDateTime toDate); + RsData getOrderFormData(Long orderId); } \ No newline at end of file diff --git a/src/main/java/project/trendpick_pro/domain/orders/service/impl/OrderServiceImpl.java b/src/main/java/project/trendpick_pro/domain/orders/service/impl/OrderServiceImpl.java index eff83baf..6f15169b 100644 --- a/src/main/java/project/trendpick_pro/domain/orders/service/impl/OrderServiceImpl.java +++ b/src/main/java/project/trendpick_pro/domain/orders/service/impl/OrderServiceImpl.java @@ -156,6 +156,22 @@ public List findAllByCreatedDateBetweenOrderByIdAsc(LocalDateTime fro return orderItemRepository.findAllByCreatedDateBetween(fromDate, toDate); } + public RsData getOrderFormData(Long orderId) { + Order order; + try{ + order = findById(orderId); + if(order.getPaymentKey() != null || order.getOrderState().equals("주문취소")) + return RsData.of("F-2", "이미 처리된 주문입니다."); + + if(order.getOrderItems().isEmpty()) + return RsData.of("F-1", "주문 중에 오류가 발생했습니다. 다시 시도해주세요"); + } catch (OrderNotFoundException e){ + return RsData.of("F-1", "주문 중에 오류가 발생했습니다. 다시 시도해주세요"); + } + + return RsData.of("S-1", "유효성 검증 성공", order); + } + private Page settingOrderByMemberStatus(Member member, int offset) { Page findOrders; PageRequest pageable = PageRequest.of(offset, 10); From 1a2160da5a032842b9de642df831f94892b1bc07 Mon Sep 17 00:00:00 2001 From: jooooonj Date: Wed, 20 Sep 2023 12:26:41 +0900 Subject: [PATCH 4/7] =?UTF-8?q?fix:=20=EC=BF=A0=ED=8F=B0=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9=EC=9D=B4=20=EB=90=98=EC=A7=80=20=EC=95=8A=EC=95=98?= =?UTF-8?q?=EC=9D=84=20=EA=B2=BD=EC=9A=B0=EC=97=90=EB=8F=84=20coupon.use()?= =?UTF-8?q?=20=ED=98=B8=EC=B6=9C=ED=95=98=EB=8A=94=20=EB=B2=84=EA=B7=B8=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/tosspayment/service/PaymentService.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/project/trendpick_pro/global/tosspayment/service/PaymentService.java b/src/main/java/project/trendpick_pro/global/tosspayment/service/PaymentService.java index e40fe465..c244fa4c 100644 --- a/src/main/java/project/trendpick_pro/global/tosspayment/service/PaymentService.java +++ b/src/main/java/project/trendpick_pro/global/tosspayment/service/PaymentService.java @@ -53,10 +53,11 @@ public RsData processPayment(String paymentKey, Long orderId, Integer amount, St private void successPaymentProcess(String method, String paymentKey, Order order) { order.connectPayment("TossPayments" + method, paymentKey); - for (OrderItem orderItem : order.getOrderItems()) { favoriteTagService.updateTag(order.getMember(), orderItem.getProduct(), TagType.ORDER); - orderItem.getCouponCard().use(LocalDateTime.now()); //실제 쿠폰 사용 처리 + + if(orderItem.getCouponCard() != null) + orderItem.getCouponCard().use(LocalDateTime.now()); //실제 쿠폰 사용 처리 } } From 2eb640873ae21d4d26142a1da156d41abf58ee10 Mon Sep 17 00:00:00 2001 From: jooooonj Date: Wed, 20 Sep 2023 12:27:29 +0900 Subject: [PATCH 5/7] =?UTF-8?q?fix:=20=EC=9E=A5=EB=B0=94=EA=B5=AC=EB=8B=88?= =?UTF-8?q?=20->=20=EC=A3=BC=EB=AC=B8=EC=8B=9C=20OrderMaterial=20=EC=9D=B4?= =?UTF-8?q?=20=EC=A0=9C=EB=8C=80=EB=A1=9C=20=EC=83=9D=EC=84=B1=EB=90=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8A=94=20=EB=AC=B8=EC=A0=9C=20=ED=95=B4?= =?UTF-8?q?=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/kafka/outbox/entity/OrderMaterial.java | 6 +++++- .../global/kafka/outbox/service/OutboxMessageService.java | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/project/trendpick_pro/global/kafka/outbox/entity/OrderMaterial.java b/src/main/java/project/trendpick_pro/global/kafka/outbox/entity/OrderMaterial.java index a20e7bc7..a8276fb4 100644 --- a/src/main/java/project/trendpick_pro/global/kafka/outbox/entity/OrderMaterial.java +++ b/src/main/java/project/trendpick_pro/global/kafka/outbox/entity/OrderMaterial.java @@ -32,6 +32,10 @@ public OrderMaterial(Long productId, Integer quantity, String size, String color } public OrderMaterial(CartItem cartItem, String code){ - new OrderMaterial(cartItem.getProduct().getId(), cartItem.getQuantity(), cartItem.getSize(), cartItem.getColor(), code); + this.productId = cartItem.getProduct().getId(); + this.quantity = cartItem.getQuantity(); + this.size = cartItem.getSize(); + this.color = cartItem.getColor(); + this.code = code; } } diff --git a/src/main/java/project/trendpick_pro/global/kafka/outbox/service/OutboxMessageService.java b/src/main/java/project/trendpick_pro/global/kafka/outbox/service/OutboxMessageService.java index cd9f802e..70da163e 100644 --- a/src/main/java/project/trendpick_pro/global/kafka/outbox/service/OutboxMessageService.java +++ b/src/main/java/project/trendpick_pro/global/kafka/outbox/service/OutboxMessageService.java @@ -45,10 +45,12 @@ public List findOrderMaterial(String code){ } //주문 객쳉 생성 메시지 발행 + @Transactional public void publishOrderCreationMessage(String topic, String key, List orderMaterials, String code) { outboxMessageRepository.save(new OutboxMessage(topic, key, key, orderMaterials, code)); } + @Transactional //주문 처리 메시지 발행 public void publishOrderProcessMessage(String topic, String message, String payload, String email) { outboxMessageRepository.save(new OutboxMessage(topic, message, payload, email)); From b6c24690983b78cc64b46c0e31960d2d47ba3e7b Mon Sep 17 00:00:00 2001 From: jooooonj Date: Wed, 20 Sep 2023 12:36:12 +0900 Subject: [PATCH 6/7] =?UTF-8?q?docs:=20docker-compose.yml=20=EC=A0=9C?= =?UTF-8?q?=EC=99=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 22a87618..b3f1be53 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,6 @@ build/ !gradle/wrapper/gradle-wrapper.jar !**/src/main/**/build/ !**/src/test/**/build/ -docker-compose.yml ### STS ### .apt_generated From adcbceaa1e5bc821ec1efc7db299268b0fcd6ab0 Mon Sep 17 00:00:00 2001 From: jooooonj Date: Wed, 20 Sep 2023 12:36:29 +0900 Subject: [PATCH 7/7] =?UTF-8?q?docs:=20docker-compose.yml=20(=EC=B9=B4?= =?UTF-8?q?=ED=94=84=EC=B9=B4)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-compose.yml | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 docker-compose.yml diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..4a434818 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,33 @@ +version: '2.1' + +services: + zoo1: + image: confluentinc/cp-zookeeper:7.3.2 + hostname: zoo1 + container_name: zoo1 + ports: + - "2181:2181" + environment: + ZOOKEEPER_CLIENT_PORT: 2181 + ZOOKEEPER_SERVER_ID: 1 + ZOOKEEPER_SERVERS: zoo1:2888:3888 + + + kafka1: + image: confluentinc/cp-kafka:7.3.2 + hostname: kafka1 + container_name: kafka1 + ports: + - "9092:9092" + - "29092:29092" + environment: + KAFKA_ADVERTISED_LISTENERS: INTERNAL://kafka1:19092,EXTERNAL://${DOCKER_HOST_IP:-127.0.0.1}:9092,DOCKER://host.docker.internal:29092 + KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: INTERNAL:PLAINTEXT,EXTERNAL:PLAINTEXT,DOCKER:PLAINTEXT + KAFKA_INTER_BROKER_LISTENER_NAME: INTERNAL + KAFKA_ZOOKEEPER_CONNECT: "zoo1:2181" + KAFKA_BROKER_ID: 1 + KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1 + KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1 + KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1 + depends_on: + - zoo1 \ No newline at end of file