Skip to content

Commit

Permalink
#161 hotfix: 잘못된 jpa 쿼리 -> queryDSL로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
psyeon1120 committed Aug 30, 2023
1 parent 32918fd commit a71803c
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 13 deletions.
8 changes: 8 additions & 0 deletions src/main/kotlin/com/psr/psr/order/repository/OrderCustom.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.psr.psr.order.repository

import com.psr.psr.order.entity.Order
import com.psr.psr.order.entity.OrderStatus

interface OrderCustom {
fun find2MonthAgoOrders(orderStatus: OrderStatus): List<Order>
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@ 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<Order, Long> {
interface OrderRepository: JpaRepository<Order, Long>, OrderCustom {
fun findByIdAndStatus(orderId: Long, status: String): Order?
fun findByUserAndOrderStatusAndStatus(orderer: User, orderStatus: OrderStatus, status: String, pageable: Pageable): Page<Order>
fun findByProductUserAndOrderStatusAndStatus(seller: User, orderStatus: OrderStatus, status: String, pageable: Pageable): Page<Order>
fun findByUserAndStatus(orderer: User, status: String, pageable: Pageable): Page<Order>
fun findByProductUserAndStatus(seller: User, status: String, pageable: Pageable): Page<Order>
fun deleteByUser(user: User)
fun findByCreatedAt_DateAndOrderStatusAndStatus(date: LocalDate, orderStatus: OrderStatus, status: String): List<Order>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.psr.psr.order.repository

import com.psr.psr.global.Constant.UserStatus.UserStatus.ACTIVE_STATUS
import com.psr.psr.order.entity.Order
import com.psr.psr.order.entity.OrderStatus
import com.psr.psr.order.entity.QOrder.order
import com.querydsl.core.types.dsl.Expressions
import com.querydsl.jpa.impl.JPAQueryFactory
import org.springframework.stereotype.Component

import java.time.LocalDate

@Component
class OrderRepositoryImpl(
private val queryFactory: JPAQueryFactory
): OrderCustom {
override fun find2MonthAgoOrders(orderStatus: OrderStatus): List<Order> {
val dateTemplate = Expressions.dateTemplate(LocalDate::class.java, "date({0})", order.createdAt)
val date = LocalDate.now().minusMonths(2)
return queryFactory
.selectFrom(order)
.where(dateTemplate.eq(date)
.and(order.orderStatus.eq(orderStatus))
.and(order.status.eq(ACTIVE_STATUS)))
.fetch()
}

}
12 changes: 2 additions & 10 deletions src/main/kotlin/com/psr/psr/order/service/OrderService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,7 @@ class OrderService(
@Scheduled(cron = "0 0 13 * * ?", zone = "Asia/Seoul")
fun notify2MonthOrders() {
// 진행 중인 요청
orderRepository.findByCreatedAt_DateAndOrderStatusAndStatus(
LocalDate.now(),
OrderStatus.PROGRESSING,
ACTIVE_STATUS
)
orderRepository.find2MonthAgoOrders(OrderStatus.PROGRESSING)
.forEach {
notificationService.send2MonthOrderNoti(
it.product.name,
Expand All @@ -101,11 +97,7 @@ class OrderService(
}

// 대기중인 요청
orderRepository.findByCreatedAt_DateAndOrderStatusAndStatus(
LocalDate.now(),
OrderStatus.ORDER_WAITING,
ACTIVE_STATUS
)
orderRepository.find2MonthAgoOrders(OrderStatus.ORDER_WAITING)
.forEach {
notificationService.send2MonthOrderNoti(
it.product.name,
Expand Down

0 comments on commit a71803c

Please sign in to comment.