Skip to content

Commit

Permalink
feat: check order status and send msg
Browse files Browse the repository at this point in the history
  • Loading branch information
Kang1221 committed Sep 9, 2024
1 parent b17c1a5 commit 27d374c
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package co.orange.ddanzi.repository;

import co.orange.ddanzi.domain.order.Order;
import co.orange.ddanzi.domain.order.enums.OrderStatus;
import co.orange.ddanzi.domain.product.Item;
import co.orange.ddanzi.domain.user.User;
import io.lettuce.core.dynamic.annotation.Param;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;

Expand All @@ -18,4 +20,7 @@ public interface OrderRepository extends JpaRepository<Order, String> {
Optional<Order> findByItem(@Param("item") Item item);

Integer countAllByBuyer(User user);

@Query("SELECT o FROM Order o WHERE o.status = :orderStatus AND o.updatedAt <= :dateTime")
List<Order> findOverLimitTimeOrders(OrderStatus orderStatus, LocalDateTime dateTime);
}
54 changes: 41 additions & 13 deletions src/main/java/co/orange/ddanzi/service/OrderService.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,15 @@ public class OrderService {
private final PaymentRepository paymentRepository;
private final DiscountRepository discountRepository;

private final AddressService addressService;
private final TermService termService;
private final OrderOptionDetailService orderOptionDetailService;
private final HistoryService historyService;
private final FcmService fcmService;

@Autowired
AddressService addressService;
@Autowired
TermService termService;
@Autowired
@Lazy
PaymentService paymentService;
@Autowired
OrderOptionDetailService orderOptionDetailService;
@Autowired
HistoryService historyService;
private FcmService fcmService;


@Transactional
public ApiResponse<?> checkOrderProduct(String productId){
Expand Down Expand Up @@ -167,6 +162,41 @@ public Order getOrderRecord(String orderId){
return orderRepository.findById(orderId).orElseThrow(() -> new OrderNotFoundException());
}

/**
* 환불 API 붙이기!!!!!!
*
*
*/
public void checkOrderPlacedOrder(){
LocalDateTime oneDayLimit = LocalDateTime.now().minusHours(24);
List<Order> orderPlaceOrders = orderRepository.findOverLimitTimeOrders(OrderStatus.ORDER_PLACE, oneDayLimit);
for(Order order : orderPlaceOrders){
fcmService.sendMessageToUser(order.getItem().getSeller(), FcmCase.A2);
fcmService.sendMessageToUser(order.getBuyer(), FcmCase.B1);
order.updateStatus(OrderStatus.CANCELLED);
}
}

public void checkShippingOrder(){
LocalDateTime threeDayLimit = LocalDateTime.now().minusHours(72);
List<Order> shippingOrders = orderRepository.findOverLimitTimeOrders(OrderStatus.SHIPPING, threeDayLimit);
for(Order order : shippingOrders){
fcmService.sendMessageToUser(order.getBuyer(), FcmCase.B3);
order.updateStatus(OrderStatus.DELAYED_SHIPPING);
}
}

public void checkDelayedShippingOrder(){
LocalDateTime sixDayLimit = LocalDateTime.now().minusHours(72);
List<Order> delayedShippingOrders = orderRepository.findOverLimitTimeOrders(OrderStatus.DELAYED_SHIPPING, sixDayLimit);
for(Order order : delayedShippingOrders){
fcmService.sendMessageToUser(order.getBuyer(), FcmCase.B4);
order.updateStatus(OrderStatus.WARNING);
}
}



private String createModifiedProductName(String productName){
return productName.replaceAll("[^ㄱ-ㅎㅏ-ㅣ가-힣a-zA-Z0-9,._\\s ]", "");
}
Expand Down Expand Up @@ -203,7 +233,7 @@ private OrderResponseDto setOrderResponseDto(User user, Order order, Item item,
Product product = item.getProduct();
Discount discount = discountRepository.findById(product.getId()).orElseThrow(() -> new DiscountNotFoundException());

OrderResponseDto responseDto = OrderResponseDto.builder()
return OrderResponseDto.builder()
.orderId(order.getId())
.orderStatus(order.getStatus())
.productName(product.getName())
Expand All @@ -217,8 +247,6 @@ private OrderResponseDto setOrderResponseDto(User user, Order order, Item item,
.charge(payment.getCharge())
.totalPrice(payment.getTotalPrice())
.build();

return responseDto;
}

public Integer getMyOrderCount(User user){
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/co/orange/ddanzi/service/SchedulerService.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public class SchedulerService {

@Autowired
ItemService itemService;
@Autowired
OrderService orderService;

/**
* 매일 자정마다 만료된 아이템 체크.
Expand All @@ -23,4 +25,27 @@ public void updateExpiredItems() {
log.info("Updating expired items");
itemService.updateExpiredItems();
}


/**
* 1시간마다 실행
* */
@Scheduled(fixedRate = 3600000)
public void scheduleCheckOrderPlacedOrder() {
log.info("입금 후 1일(24시간)이 지났는데, 판매확정이 되지 않은 주문 확인");
orderService.checkOrderPlacedOrder();
}

@Scheduled(fixedRate = 3600000)
public void scheduleCheckShippingOrder() {
log.info("판매확정 후 3일 (72시간)이 지났는데, 구매확정이 되지 않은 주문 확인");
orderService.checkShippingOrder();
}


@Scheduled(fixedRate = 3600000)
public void scheduleCheckDelayedShippingOrder() {
log.info("판매확정 후 6일 (144시간)이 지났는데, 구매확정이 되지 않았고, 신고도 하지 않은 주문 확인");
orderService.checkDelayedShippingOrder();
}
}

0 comments on commit 27d374c

Please sign in to comment.