diff --git a/src/main/kotlin/com/psr/psr/notification/service/NotificationService.kt b/src/main/kotlin/com/psr/psr/notification/service/NotificationService.kt index 2c8d291..018f33c 100644 --- a/src/main/kotlin/com/psr/psr/notification/service/NotificationService.kt +++ b/src/main/kotlin/com/psr/psr/notification/service/NotificationService.kt @@ -80,19 +80,19 @@ class NotificationService( } // 2달 뒤 요청상태 입력 요망 알림 - fun send2MonthOrderNoti(productName: String, orderer: User, ordererName: String, orderId: Long) { + fun send2MonthOrderNoti(productName: String, orderReceiver: User, ordererName: String, orderId: Long) { val messageBody = ordererName + TWO_MONTH_ORDER_SENTENCE notificationRepository.save(notiAssembler.toEntity( - orderer, + orderReceiver, productName, messageBody, orderId, NotificationType.TWO_MONTH_ORDER )) - if (isPushNotiAvailable(orderer)) { + if (isPushNotiAvailable(orderReceiver)) { val message: FcmMessage = notiAssembler.makeMessage( - orderer.deviceToken!!, + orderReceiver.deviceToken!!, productName, messageBody, orderId, diff --git a/src/main/kotlin/com/psr/psr/order/repository/OrderRepository.kt b/src/main/kotlin/com/psr/psr/order/repository/OrderRepository.kt index 41eea8d..7950455 100644 --- a/src/main/kotlin/com/psr/psr/order/repository/OrderRepository.kt +++ b/src/main/kotlin/com/psr/psr/order/repository/OrderRepository.kt @@ -7,6 +7,7 @@ import org.springframework.data.domain.Page import org.springframework.data.domain.Pageable import org.springframework.data.jpa.repository.JpaRepository import org.springframework.stereotype.Repository +import java.time.LocalDate @Repository interface OrderRepository: JpaRepository { @@ -16,4 +17,5 @@ interface OrderRepository: JpaRepository { fun findByUserAndStatus(orderer: User, status: String, pageable: Pageable): Page fun findByProductUserAndStatus(seller: User, status: String, pageable: Pageable): Page fun deleteByUser(user: User) + fun findByCreatedAt_DateAndOrderStatusAndStatus(date: LocalDate, orderStatus: OrderStatus, status: String): List } \ No newline at end of file diff --git a/src/main/kotlin/com/psr/psr/order/service/OrderService.kt b/src/main/kotlin/com/psr/psr/order/service/OrderService.kt index 3626775..8bbdf72 100644 --- a/src/main/kotlin/com/psr/psr/order/service/OrderService.kt +++ b/src/main/kotlin/com/psr/psr/order/service/OrderService.kt @@ -5,7 +5,10 @@ import com.psr.psr.global.Constant.UserStatus.UserStatus.ACTIVE_STATUS import com.psr.psr.global.exception.BaseException import com.psr.psr.global.exception.BaseResponseCode import com.psr.psr.notification.service.NotificationService -import com.psr.psr.order.dto.* +import com.psr.psr.order.dto.OrderAssembler +import com.psr.psr.order.dto.OrderListRes +import com.psr.psr.order.dto.OrderReq +import com.psr.psr.order.dto.OrderRes import com.psr.psr.order.entity.Order import com.psr.psr.order.entity.OrderStatus import com.psr.psr.order.repository.OrderRepository @@ -14,7 +17,9 @@ import com.psr.psr.product.repository.ProductRepository import com.psr.psr.user.entity.User import org.springframework.data.domain.Page import org.springframework.data.domain.Pageable +import org.springframework.scheduling.annotation.Scheduled import org.springframework.stereotype.Service +import java.time.LocalDate @Service class OrderService( @@ -76,4 +81,38 @@ class OrderService( if (status != null) notificationService.sendChangeOrderStatusNoti(order.product.name, order.product.user, saveOrder.orderStatus, order.id!!) } + + // 2달 뒤 요청상태 입력 요망 알림(오후 1시마다 실행) + @Scheduled(cron = "0 0 13 * * ?", zone = "Asia/Seoul") + fun notify2MonthOrders() { + // 진행 중인 요청 + orderRepository.findByCreatedAt_DateAndOrderStatusAndStatus( + LocalDate.now(), + OrderStatus.PROGRESSING, + ACTIVE_STATUS + ) + .forEach { + notificationService.send2MonthOrderNoti( + it.product.name, + it.product.user, + it.ordererName, + it.id!! + ) + } + + // 대기중인 요청 + orderRepository.findByCreatedAt_DateAndOrderStatusAndStatus( + LocalDate.now(), + OrderStatus.ORDER_WAITING, + ACTIVE_STATUS + ) + .forEach { + notificationService.send2MonthOrderNoti( + it.product.name, + it.product.user, + it.ordererName, + it.id!! + ) + } + } } \ No newline at end of file