Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#161 hotfix: 잘못된 jpa 쿼리 -> queryDSL로 변경 #162

Merged
merged 1 commit into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading