관리자 - 충전이벤트
- 시간 계산을 Querydsl 코드에서 수행 - 등록/수정 시 이벤트 진행기간에 시간도 포함하도록 수정
This commit is contained in:
parent
287d133080
commit
b9063fb22f
|
@ -1,22 +1,51 @@
|
||||||
package kr.co.vividnext.sodalive.admin.event.charge
|
package kr.co.vividnext.sodalive.admin.event.charge
|
||||||
|
|
||||||
|
import com.querydsl.core.types.dsl.DateTimePath
|
||||||
|
import com.querydsl.core.types.dsl.Expressions
|
||||||
|
import com.querydsl.core.types.dsl.StringTemplate
|
||||||
import com.querydsl.jpa.impl.JPAQueryFactory
|
import com.querydsl.jpa.impl.JPAQueryFactory
|
||||||
import kr.co.vividnext.sodalive.admin.event.charge.QChargeEvent.chargeEvent
|
import kr.co.vividnext.sodalive.admin.event.charge.QChargeEvent.chargeEvent
|
||||||
import org.springframework.data.jpa.repository.JpaRepository
|
import org.springframework.data.jpa.repository.JpaRepository
|
||||||
import org.springframework.stereotype.Repository
|
import org.springframework.stereotype.Repository
|
||||||
|
import java.time.LocalDateTime
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
interface AdminChargeEventRepository : JpaRepository<ChargeEvent, Long>, AdminChargeEventQueryRepository
|
interface AdminChargeEventRepository : JpaRepository<ChargeEvent, Long>, AdminChargeEventQueryRepository
|
||||||
|
|
||||||
interface AdminChargeEventQueryRepository {
|
interface AdminChargeEventQueryRepository {
|
||||||
fun getChargeEventList(): List<ChargeEvent>
|
fun getChargeEventList(): List<GetChargeEventListResponse>
|
||||||
}
|
}
|
||||||
|
|
||||||
class AdminChargeEventQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : AdminChargeEventQueryRepository {
|
class AdminChargeEventQueryRepositoryImpl(private val queryFactory: JPAQueryFactory) : AdminChargeEventQueryRepository {
|
||||||
override fun getChargeEventList(): List<ChargeEvent> {
|
override fun getChargeEventList(): List<GetChargeEventListResponse> {
|
||||||
return queryFactory
|
return queryFactory
|
||||||
.selectFrom(chargeEvent)
|
.select(
|
||||||
|
QGetChargeEventListResponse(
|
||||||
|
chargeEvent.id,
|
||||||
|
chargeEvent.title,
|
||||||
|
getFormattedDate(chargeEvent.startDate),
|
||||||
|
getFormattedDate(chargeEvent.endDate),
|
||||||
|
chargeEvent.availableCount,
|
||||||
|
chargeEvent.addPercent.multiply(100).castToNum(Int::class.java),
|
||||||
|
chargeEvent.isActive
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.from(chargeEvent)
|
||||||
.orderBy(chargeEvent.createdAt.desc())
|
.orderBy(chargeEvent.createdAt.desc())
|
||||||
.fetch()
|
.fetch()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getFormattedDate(dateTimePath: DateTimePath<LocalDateTime>): StringTemplate {
|
||||||
|
return Expressions.stringTemplate(
|
||||||
|
"DATE_FORMAT({0}, {1})",
|
||||||
|
Expressions.dateTimeTemplate(
|
||||||
|
LocalDateTime::class.java,
|
||||||
|
"CONVERT_TZ({0},{1},{2})",
|
||||||
|
dateTimePath,
|
||||||
|
"UTC",
|
||||||
|
"Asia/Seoul"
|
||||||
|
),
|
||||||
|
"%Y-%m-%d %H:%i"
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import kr.co.vividnext.sodalive.common.SodaException
|
||||||
import org.springframework.data.repository.findByIdOrNull
|
import org.springframework.data.repository.findByIdOrNull
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
import org.springframework.transaction.annotation.Transactional
|
import org.springframework.transaction.annotation.Transactional
|
||||||
import java.time.LocalDate
|
import java.time.LocalDateTime
|
||||||
import java.time.ZoneId
|
import java.time.ZoneId
|
||||||
import java.time.format.DateTimeFormatter
|
import java.time.format.DateTimeFormatter
|
||||||
|
|
||||||
|
@ -13,13 +13,13 @@ import java.time.format.DateTimeFormatter
|
||||||
class AdminChargeEventService(private val repository: AdminChargeEventRepository) {
|
class AdminChargeEventService(private val repository: AdminChargeEventRepository) {
|
||||||
@Transactional
|
@Transactional
|
||||||
fun createChargeEvent(request: CreateChargeEventRequest): Long {
|
fun createChargeEvent(request: CreateChargeEventRequest): Long {
|
||||||
val dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd")
|
val dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")
|
||||||
val startDate = LocalDate.parse(request.startDateString, dateTimeFormatter).atTime(0, 0)
|
val startDate = LocalDateTime.parse(request.startDateString, dateTimeFormatter)
|
||||||
.atZone(ZoneId.of("Asia/Seoul"))
|
.atZone(ZoneId.of("Asia/Seoul"))
|
||||||
.withZoneSameInstant(ZoneId.of("UTC"))
|
.withZoneSameInstant(ZoneId.of("UTC"))
|
||||||
.toLocalDateTime()
|
.toLocalDateTime()
|
||||||
|
|
||||||
val endDate = LocalDate.parse(request.endDateString, dateTimeFormatter).atTime(23, 59, 59)
|
val endDate = LocalDateTime.parse(request.endDateString, dateTimeFormatter).withSecond(59)
|
||||||
.atZone(ZoneId.of("Asia/Seoul"))
|
.atZone(ZoneId.of("Asia/Seoul"))
|
||||||
.withZoneSameInstant(ZoneId.of("UTC"))
|
.withZoneSameInstant(ZoneId.of("UTC"))
|
||||||
.toLocalDateTime()
|
.toLocalDateTime()
|
||||||
|
@ -44,16 +44,16 @@ class AdminChargeEventService(private val repository: AdminChargeEventRepository
|
||||||
chargeEvent.title = request.title
|
chargeEvent.title = request.title
|
||||||
}
|
}
|
||||||
|
|
||||||
val dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd")
|
val dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm")
|
||||||
if (request.startDateString != null) {
|
if (request.startDateString != null) {
|
||||||
chargeEvent.startDate = LocalDate.parse(request.startDateString, dateTimeFormatter).atTime(0, 0)
|
chargeEvent.startDate = LocalDateTime.parse(request.startDateString, dateTimeFormatter)
|
||||||
.atZone(ZoneId.of("Asia/Seoul"))
|
.atZone(ZoneId.of("Asia/Seoul"))
|
||||||
.withZoneSameInstant(ZoneId.of("UTC"))
|
.withZoneSameInstant(ZoneId.of("UTC"))
|
||||||
.toLocalDateTime()
|
.toLocalDateTime()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request.endDateString != null) {
|
if (request.endDateString != null) {
|
||||||
chargeEvent.endDate = LocalDate.parse(request.endDateString, dateTimeFormatter).atTime(23, 59, 59)
|
chargeEvent.endDate = LocalDateTime.parse(request.endDateString, dateTimeFormatter).withSecond(59)
|
||||||
.atZone(ZoneId.of("Asia/Seoul"))
|
.atZone(ZoneId.of("Asia/Seoul"))
|
||||||
.withZoneSameInstant(ZoneId.of("UTC"))
|
.withZoneSameInstant(ZoneId.of("UTC"))
|
||||||
.toLocalDateTime()
|
.toLocalDateTime()
|
||||||
|
@ -74,27 +74,5 @@ class AdminChargeEventService(private val repository: AdminChargeEventRepository
|
||||||
|
|
||||||
fun getChargeEventList(): List<GetChargeEventListResponse> {
|
fun getChargeEventList(): List<GetChargeEventListResponse> {
|
||||||
return repository.getChargeEventList()
|
return repository.getChargeEventList()
|
||||||
.map {
|
|
||||||
val dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd")
|
|
||||||
val startDate = it.startDate
|
|
||||||
.atZone(ZoneId.of("UTC"))
|
|
||||||
.withZoneSameInstant(ZoneId.of("Asia/Seoul"))
|
|
||||||
.format(dateTimeFormatter)
|
|
||||||
|
|
||||||
val endDate = it.endDate
|
|
||||||
.atZone(ZoneId.of("UTC"))
|
|
||||||
.withZoneSameInstant(ZoneId.of("Asia/Seoul"))
|
|
||||||
.format(dateTimeFormatter)
|
|
||||||
|
|
||||||
GetChargeEventListResponse(
|
|
||||||
id = it.id!!,
|
|
||||||
title = it.title,
|
|
||||||
startDate = startDate,
|
|
||||||
endDate = endDate,
|
|
||||||
availableCount = it.availableCount,
|
|
||||||
addPercent = (it.addPercent * 100).toInt(),
|
|
||||||
isActive = it.isActive
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package kr.co.vividnext.sodalive.admin.event.charge
|
package kr.co.vividnext.sodalive.admin.event.charge
|
||||||
|
|
||||||
data class GetChargeEventListResponse(
|
import com.querydsl.core.annotations.QueryProjection
|
||||||
|
|
||||||
|
data class GetChargeEventListResponse @QueryProjection constructor(
|
||||||
val id: Long,
|
val id: Long,
|
||||||
val title: String,
|
val title: String,
|
||||||
val startDate: String,
|
val startDate: String,
|
||||||
|
|
Loading…
Reference in New Issue