Compare commits
No commits in common. "219f83dec06c93f345ef1daae7f3e9031862f391" and "a76a84123805bd392e6c53a5d475ab71e46b7a56" have entirely different histories.
219f83dec0
...
a76a841238
|
@ -13,17 +13,10 @@ import java.time.LocalDateTime
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
class AdminAdStatisticsRepository(private val queryFactory: JPAQueryFactory) {
|
class AdminAdStatisticsRepository(private val queryFactory: JPAQueryFactory) {
|
||||||
fun getAdStatisticsDataTotalCount(
|
fun getAdStatisticsDataTotalCount(): Int {
|
||||||
startDate: LocalDateTime,
|
|
||||||
endDate: LocalDateTime
|
|
||||||
): Int {
|
|
||||||
return queryFactory
|
return queryFactory
|
||||||
.select(adTrackingHistory.id.pid)
|
.select(adTrackingHistory.id.pid)
|
||||||
.from(adTrackingHistory)
|
.from(adTrackingHistory)
|
||||||
.where(
|
|
||||||
adTrackingHistory.id.createdAt.goe(startDate),
|
|
||||||
adTrackingHistory.id.createdAt.loe(endDate)
|
|
||||||
)
|
|
||||||
.groupBy(
|
.groupBy(
|
||||||
getFormattedDate(adTrackingHistory.id.createdAt),
|
getFormattedDate(adTrackingHistory.id.createdAt),
|
||||||
adTrackingHistory.mediaGroup,
|
adTrackingHistory.mediaGroup,
|
||||||
|
@ -122,7 +115,6 @@ class AdminAdStatisticsRepository(private val queryFactory: JPAQueryFactory) {
|
||||||
adTrackingHistory.id.pid,
|
adTrackingHistory.id.pid,
|
||||||
adTrackingHistory.pidName
|
adTrackingHistory.pidName
|
||||||
)
|
)
|
||||||
.orderBy(getFormattedDate(adTrackingHistory.id.createdAt).desc())
|
|
||||||
.offset(offset)
|
.offset(offset)
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
.fetch()
|
.fetch()
|
||||||
|
|
|
@ -16,7 +16,7 @@ class AdminAdStatisticsService(
|
||||||
val startDate = startDateStr.convertLocalDateTime()
|
val startDate = startDateStr.convertLocalDateTime()
|
||||||
val endDate = endDateStr.convertLocalDateTime(hour = 23, minute = 59, second = 59)
|
val endDate = endDateStr.convertLocalDateTime(hour = 23, minute = 59, second = 59)
|
||||||
|
|
||||||
val totalCount = repository.getAdStatisticsDataTotalCount(startDate, endDate)
|
val totalCount = repository.getAdStatisticsDataTotalCount()
|
||||||
val items = repository.getAdStatisticsDataList(startDate, endDate, offset, limit)
|
val items = repository.getAdStatisticsDataList(startDate, endDate, offset, limit)
|
||||||
|
|
||||||
return GetAdminAdStatisticsResponse(
|
return GetAdminAdStatisticsResponse(
|
||||||
|
|
|
@ -80,7 +80,6 @@ class AdminMemberStatisticsRepository(private val queryFactory: JPAQueryFactory)
|
||||||
member.createdAt.loe(endDate)
|
member.createdAt.loe(endDate)
|
||||||
)
|
)
|
||||||
.groupBy(getFormattedDate(member.createdAt))
|
.groupBy(getFormattedDate(member.createdAt))
|
||||||
.orderBy(getFormattedDate(member.createdAt).desc())
|
|
||||||
.offset(offset)
|
.offset(offset)
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
.fetch()
|
.fetch()
|
||||||
|
@ -105,7 +104,6 @@ class AdminMemberStatisticsRepository(private val queryFactory: JPAQueryFactory)
|
||||||
signOut.createdAt.loe(endDate)
|
signOut.createdAt.loe(endDate)
|
||||||
)
|
)
|
||||||
.groupBy(getFormattedDate(signOut.createdAt))
|
.groupBy(getFormattedDate(signOut.createdAt))
|
||||||
.orderBy(getFormattedDate(signOut.createdAt).desc())
|
|
||||||
.offset(offset)
|
.offset(offset)
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
.fetch()
|
.fetch()
|
||||||
|
@ -134,7 +132,6 @@ class AdminMemberStatisticsRepository(private val queryFactory: JPAQueryFactory)
|
||||||
charge.createdAt.loe(endDate)
|
charge.createdAt.loe(endDate)
|
||||||
)
|
)
|
||||||
.groupBy(getFormattedDate(charge.createdAt))
|
.groupBy(getFormattedDate(charge.createdAt))
|
||||||
.orderBy(getFormattedDate(charge.createdAt).desc())
|
|
||||||
.offset(offset)
|
.offset(offset)
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
.fetch()
|
.fetch()
|
||||||
|
|
|
@ -4,7 +4,6 @@ import kr.co.vividnext.sodalive.common.SodaException
|
||||||
import org.springframework.data.domain.Pageable
|
import org.springframework.data.domain.Pageable
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
import java.time.LocalDate
|
import java.time.LocalDate
|
||||||
import java.time.LocalDateTime
|
|
||||||
import java.time.LocalTime
|
import java.time.LocalTime
|
||||||
import java.time.ZoneId
|
import java.time.ZoneId
|
||||||
import java.time.format.DateTimeFormatter
|
import java.time.format.DateTimeFormatter
|
||||||
|
@ -17,16 +16,9 @@ class AdminMemberStatisticsService(private val repository: AdminMemberStatistics
|
||||||
endDateStr: String,
|
endDateStr: String,
|
||||||
pageable: Pageable
|
pageable: Pageable
|
||||||
): GetMemberStatisticsResponse {
|
): GetMemberStatisticsResponse {
|
||||||
val startDate = LocalDate.parse(startDateStr)
|
|
||||||
val endDate = LocalDate.parse(endDateStr)
|
|
||||||
val now = LocalDateTime.now()
|
|
||||||
.atZone(ZoneId.of("UTC"))
|
|
||||||
.withZoneSameInstant(ZoneId.of("Asia/Seoul"))
|
|
||||||
.toLocalDate()
|
|
||||||
|
|
||||||
val dateRange = getPagedDateRange(
|
val dateRange = getPagedDateRange(
|
||||||
startDate = startDate,
|
startDate = startDateStr,
|
||||||
endDate = endDate.coerceAtMost(now),
|
endDate = endDateStr,
|
||||||
page = pageable.pageNumber + 1,
|
page = pageable.pageNumber + 1,
|
||||||
pageSize = pageable.pageSize
|
pageSize = pageable.pageSize
|
||||||
)
|
)
|
||||||
|
@ -35,47 +27,47 @@ class AdminMemberStatisticsService(private val repository: AdminMemberStatistics
|
||||||
throw SodaException("잘못된 접근입니다.")
|
throw SodaException("잘못된 접근입니다.")
|
||||||
}
|
}
|
||||||
|
|
||||||
var startDateTime = startDate.atStartOfDay()
|
var startDate = LocalDate.parse(startDateStr).atStartOfDay()
|
||||||
.atZone(ZoneId.of("Asia/Seoul"))
|
.atZone(ZoneId.of("Asia/Seoul"))
|
||||||
.withZoneSameInstant(ZoneId.of("UTC"))
|
.withZoneSameInstant(ZoneId.of("UTC"))
|
||||||
.toLocalDateTime()
|
.toLocalDateTime()
|
||||||
|
|
||||||
var endDateTime = endDate.atTime(LocalTime.MAX)
|
var endDate = LocalDate.parse(endDateStr).atTime(LocalTime.MAX)
|
||||||
.atZone(ZoneId.of("Asia/Seoul"))
|
.atZone(ZoneId.of("Asia/Seoul"))
|
||||||
.withZoneSameInstant(ZoneId.of("UTC"))
|
.withZoneSameInstant(ZoneId.of("UTC"))
|
||||||
.toLocalDateTime()
|
.toLocalDateTime()
|
||||||
|
|
||||||
val totalSignUpCount = repository.getTotalSignUpCount(startDate = startDateTime, endDate = endDateTime)
|
val totalSignUpCount = repository.getTotalSignUpCount(startDate = startDate, endDate = endDate)
|
||||||
val totalSignOutCount = repository.getTotalSignOutCount(startDate = startDateTime, endDate = endDateTime)
|
val totalSignOutCount = repository.getTotalSignOutCount(startDate = startDate, endDate = endDate)
|
||||||
val totalPaymentMemberCount = repository.getPaymentMemberCount(startDate = startDateTime, endDate = endDateTime)
|
val totalPaymentMemberCount = repository.getPaymentMemberCount(startDate = startDate, endDate = endDate)
|
||||||
|
|
||||||
startDateTime = dateRange.startDate
|
startDate = dateRange.startDate
|
||||||
.atZone(ZoneId.of("Asia/Seoul"))
|
.atZone(ZoneId.of("Asia/Seoul"))
|
||||||
.withZoneSameInstant(ZoneId.of("UTC"))
|
.withZoneSameInstant(ZoneId.of("UTC"))
|
||||||
.toLocalDateTime()
|
.toLocalDateTime()
|
||||||
|
|
||||||
endDateTime = dateRange.endDate
|
endDate = dateRange.endDate
|
||||||
.atZone(ZoneId.of("Asia/Seoul"))
|
.atZone(ZoneId.of("Asia/Seoul"))
|
||||||
.withZoneSameInstant(ZoneId.of("UTC"))
|
.withZoneSameInstant(ZoneId.of("UTC"))
|
||||||
.toLocalDateTime()
|
.toLocalDateTime()
|
||||||
|
|
||||||
val signUpCountInRange = repository.getSignUpCountInRange(
|
val signUpCountInRange = repository.getSignUpCountInRange(
|
||||||
startDate = startDateTime,
|
startDate = startDate,
|
||||||
endDate = endDateTime,
|
endDate = endDate,
|
||||||
offset = pageable.offset,
|
offset = pageable.offset,
|
||||||
limit = pageable.pageSize.toLong()
|
limit = pageable.pageSize.toLong()
|
||||||
).associateBy({ it.date }, { it.memberCount })
|
).associateBy({ it.date }, { it.memberCount })
|
||||||
|
|
||||||
val signOutCountInRange = repository.getSignOutCountInRange(
|
val signOutCountInRange = repository.getSignOutCountInRange(
|
||||||
startDate = startDateTime,
|
startDate = startDate,
|
||||||
endDate = endDateTime,
|
endDate = endDate,
|
||||||
offset = pageable.offset,
|
offset = pageable.offset,
|
||||||
limit = pageable.pageSize.toLong()
|
limit = pageable.pageSize.toLong()
|
||||||
).associateBy({ it.date }, { it.memberCount })
|
).associateBy({ it.date }, { it.memberCount })
|
||||||
|
|
||||||
val paymentMemberCountInRange = repository.getPaymentMemberCountInRange(
|
val paymentMemberCountInRange = repository.getPaymentMemberCountInRange(
|
||||||
startDate = startDateTime,
|
startDate = startDate,
|
||||||
endDate = endDateTime,
|
endDate = endDate,
|
||||||
offset = pageable.offset,
|
offset = pageable.offset,
|
||||||
limit = pageable.pageSize.toLong()
|
limit = pageable.pageSize.toLong()
|
||||||
)
|
)
|
||||||
|
@ -83,8 +75,8 @@ class AdminMemberStatisticsService(private val repository: AdminMemberStatistics
|
||||||
val paymentMemberCountInRangeMap = paymentMemberCountInRange.associateBy({ it.date }, { it.memberCount })
|
val paymentMemberCountInRangeMap = paymentMemberCountInRange.associateBy({ it.date }, { it.memberCount })
|
||||||
|
|
||||||
val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd")
|
val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd")
|
||||||
val items = generateSequence(dateRange.endDate) { it.minusDays(1) }
|
val items = generateSequence(dateRange.startDate) { it.plusDays(1) }
|
||||||
.takeWhile { !it.isBefore(dateRange.startDate) }
|
.takeWhile { !it.isAfter(dateRange.endDate) }
|
||||||
.map {
|
.map {
|
||||||
val date = it.format(formatter)
|
val date = it.format(formatter)
|
||||||
GetMemberStatisticsItem(
|
GetMemberStatisticsItem(
|
||||||
|
@ -105,14 +97,17 @@ class AdminMemberStatisticsService(private val repository: AdminMemberStatistics
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getPagedDateRange(startDate: LocalDate, endDate: LocalDate, page: Int, pageSize: Int): PagedDateRange? {
|
private fun getPagedDateRange(startDate: String, endDate: String, page: Int, pageSize: Int): PagedDateRange? {
|
||||||
val totalDays = ChronoUnit.DAYS.between(startDate, endDate).toInt() + 1
|
val start = LocalDate.parse(startDate)
|
||||||
|
val end = LocalDate.parse(endDate)
|
||||||
|
|
||||||
|
val totalDays = ChronoUnit.DAYS.between(start, end).toInt() + 1
|
||||||
val totalPages = (totalDays + pageSize - 1) / pageSize // 전체 페이지 개수 계산
|
val totalPages = (totalDays + pageSize - 1) / pageSize // 전체 페이지 개수 계산
|
||||||
|
|
||||||
if (page < 1 || page > totalPages) return null // 페이지 범위를 벗어나면 null 반환
|
if (page < 1 || page > totalPages) return null // 페이지 범위를 벗어나면 null 반환
|
||||||
|
|
||||||
val rangeEnd = endDate.minusDays((page - 1) * pageSize.toLong()).atTime(LocalTime.MAX)
|
val rangeStart = start.plusDays((page - 1) * pageSize.toLong()).atStartOfDay()
|
||||||
val rangeStart = endDate.minusDays((page * pageSize - 1).toLong()).coerceAtLeast(startDate).atStartOfDay()
|
val rangeEnd = start.plusDays((page * pageSize - 1).toLong()).coerceAtMost(end).atTime(LocalTime.MAX)
|
||||||
|
|
||||||
return PagedDateRange(rangeStart, rangeEnd, totalDays)
|
return PagedDateRange(rangeStart, rangeEnd, totalDays)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue