Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import dsm.pick2024.domain.admin.port.`in`.AdminFacadeUseCase
import dsm.pick2024.domain.admin.port.`in`.QueryMainInfoUseCase
import dsm.pick2024.domain.admin.presentation.dto.response.QueryMainInfoResponse
import dsm.pick2024.domain.selfstudy.port.out.QuerySelfStudyPort
import dsm.pick2024.global.common.TimeUtils
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import java.time.LocalDate

@Service
class QueryMainInfoService(
Expand All @@ -19,7 +19,7 @@ class QueryMainInfoService(
val admin = adminFacadeUseCase.currentAdmin()

val todaySelfStudy = querySelfStudyPort
.findByTeacherNameAndDate(admin.name, LocalDate.now())
.findByTeacherNameAndDate(admin.name, TimeUtils.nowLocalDate())

return QueryMainInfoResponse(
selfStudyFloor = todaySelfStudy?.floor ?: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import dsm.pick2024.domain.classroom.exception.FloorNotFoundException
import dsm.pick2024.domain.classroom.port.`in`.QueryFloorClassroomUseCase
import dsm.pick2024.domain.classroom.port.out.QueryClassroomPort
import dsm.pick2024.domain.classroom.presentation.dto.response.QueryClassroomResponse
import org.joda.time.LocalDate
import dsm.pick2024.global.common.TimeUtils
import org.springframework.stereotype.Service
import java.time.DayOfWeek

@Service
class QueryFloorClassroomService(
Expand All @@ -19,11 +20,11 @@ class QueryFloorClassroomService(
floor: Int,
status: Status
): List<QueryClassroomResponse> {
val today = LocalDate.now().dayOfWeek
val today = TimeUtils.nowLocalDate().dayOfWeek

val classrooms = when (floor) {
2, 3, 4 -> {
val filteredClassrooms = if (today == 2 || today == 5) {
val filteredClassrooms = if (today == DayOfWeek.TUESDAY || today == DayOfWeek.FRIDAY) {
queryClassroomPort.queryFloorClassroomWithAttendance(floor)
} else {
queryClassroomPort.queryFloorClassroom(floor)
Expand All @@ -37,7 +38,7 @@ class QueryFloorClassroomService(
}

return classrooms.map { classroom ->
val move = if (today == 2 || today == 5) {
val move = if (today == DayOfWeek.TUESDAY || today == DayOfWeek.FRIDAY) {
attendanceFinderUseCase.findByUserIdOrThrow(classroom.userId).place ?: ""
} else {
"${classroom.grade}-${classroom.classNum}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import dsm.pick2024.domain.attendance.port.`in`.AttendanceFinderUseCase
import dsm.pick2024.domain.classroom.port.`in`.QueryGradeClassroomUseCase
import dsm.pick2024.domain.classroom.port.out.QueryClassroomPort
import dsm.pick2024.domain.classroom.presentation.dto.response.QueryClassroomResponse
import org.joda.time.LocalDate
import dsm.pick2024.global.common.TimeUtils
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import java.time.DayOfWeek

@Service
class QueryGradeClassroomService(
Expand All @@ -18,11 +19,11 @@ class QueryGradeClassroomService(
grade: Int,
classNum: Int
): List<QueryClassroomResponse> {
val today = LocalDate.now().dayOfWeek
val today = TimeUtils.nowLocalDate().dayOfWeek

return queryClassroomPort.queryGradeClassroom(grade, classNum)
.map { classroom ->
val move = if (today == 2 || today == 5) {
val move = if (today == DayOfWeek.TUESDAY || today == DayOfWeek.FRIDAY) {
attendanceFinderUseCase.findByUserIdOrThrow(classroom.userId).place ?: ""
} else {
"${classroom.grade}-${classroom.classNum}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import dsm.pick2024.domain.notice.domain.Notice
import dsm.pick2024.domain.notice.port.`in`.CreateNoticeUseCase
import dsm.pick2024.domain.notice.port.out.NoticeSavePort
import dsm.pick2024.domain.notice.presentation.dto.request.NoticeRequest
import dsm.pick2024.global.common.TimeUtils
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import java.time.LocalDateTime
import java.time.ZoneId

@Service
class CreateNoticeService(
Expand All @@ -24,7 +23,7 @@ class CreateNoticeService(
Notice(
adminId = admin.id,
teacherName = admin.name,
createAt = LocalDateTime.now(ZoneId.of("Asia/Seoul")),
createAt = TimeUtils.nowLocalDateTime(),
title = request.title,
content = request.content
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dsm.pick2024.domain.schedule.service
import dsm.pick2024.domain.schedule.port.`in`.SaveScheduleUseCase
import dsm.pick2024.domain.schedule.port.out.DeleteSchedulePort
import dsm.pick2024.domain.schedule.port.out.SaveSchedulePort
import dsm.pick2024.global.common.TimeUtils
import dsm.pick2024.global.config.cache.CacheName
import dsm.pick2024.infrastructure.feign.neis.NeisScheduleFeignClientService
import org.springframework.cache.annotation.CacheEvict
Expand Down Expand Up @@ -30,11 +31,11 @@ class SaveScheduleService(
}

private fun formatDate(): Pair<String, String> {
val today = LocalDate.now()
val kstToday = TimeUtils.nowLocalDate()

val start = LocalDate.of(today.year - 1, 1, 1)
val start = LocalDate.of(kstToday.year - 1, 1, 1)

val end = LocalDate.of(today.year + 1, 3, 1)
val end = LocalDate.of(kstToday.year + 1, 3, 1)

val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import dsm.pick2024.domain.selfstudy.entity.QSelfStudyJpaEntity
import dsm.pick2024.domain.selfstudy.mapper.SelfStudyMapper
import dsm.pick2024.domain.selfstudy.persistence.repository.SelfStudyRepository
import dsm.pick2024.domain.selfstudy.port.out.SelfStudyPort
import dsm.pick2024.global.common.TimeUtils
import org.springframework.stereotype.Component
import java.time.LocalDate
import java.time.Month
Expand Down Expand Up @@ -40,17 +41,17 @@ class SelfStudyPersistenceAdapterPort(
}

override fun findByTodayTeacher(teacher: String): SelfStudy? {
val day = LocalDate.now()
val nullCheck =
val today = TimeUtils.nowLocalDate()
val entity =
jpaQueryFactory
.selectFrom(QSelfStudyJpaEntity.selfStudyJpaEntity)
.where(
QSelfStudyJpaEntity.selfStudyJpaEntity.date.eq(day),
QSelfStudyJpaEntity.selfStudyJpaEntity.date.eq(today),
QSelfStudyJpaEntity.selfStudyJpaEntity.teacherName.eq(teacher)
)
.fetchOne()

return nullCheck?.let { selfStudyMapper.toDomain(it) }
return entity?.let { selfStudyMapper.toDomain(it) }
}

override fun findByDaySelfStudy(date: LocalDate) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import dsm.pick2024.domain.admin.port.`in`.AdminFinderUseCase
import dsm.pick2024.domain.outbox.port.`in`.OutboxFacadeUseCase
import dsm.pick2024.domain.selfstudy.port.`in`.SelfStudyFinderUseCase
import dsm.pick2024.domain.selfstudy.port.`in`.SendNotificationSelfStudyTeacherUseCase
import dsm.pick2024.global.common.TimeUtils
import org.springframework.stereotype.Service
import java.time.LocalDate

@Service
class SendNotificationSelfStudyTeacher(
Expand All @@ -14,15 +14,15 @@ class SendNotificationSelfStudyTeacher(
private val outboxFacadeUseCase: OutboxFacadeUseCase
) : SendNotificationSelfStudyTeacherUseCase {
override fun execute() {
val selfStudies = selfStudyFinderUseCase.findByDaySelfStudyOrThrow(LocalDate.now()).map { it }
val selfStudies = selfStudyFinderUseCase.findByDaySelfStudyOrThrow(TimeUtils.nowLocalDate())

selfStudies.map {
val admin = adminFinderUseCase.findByAdminNameOrThrow(it.teacherName)
selfStudies.forEach { selfStudy ->
val admin = adminFinderUseCase.findByAdminNameOrThrow(selfStudy.teacherName)
admin.deviceToken?.let { token ->
outboxFacadeUseCase.sendNotification(
deviceToken = token,
title = "[PiCK] 자습감독 알림",
body = "${admin.name}선생님은 오늘 ${it.floor}층 자습감독 선생님입니다."
body = "${admin.name}선생님은 오늘 ${selfStudy.floor}층 자습감독 선생님입니다."
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import dsm.pick2024.domain.timetable.port.`in`.QueryTeacherTimetableUseCase
import dsm.pick2024.domain.timetable.port.out.QueryTimeTablePort
import dsm.pick2024.domain.timetable.presentation.dto.response.DayTimetableResponse
import dsm.pick2024.domain.timetable.presentation.dto.response.PeriodTimetableResponse
import dsm.pick2024.global.common.TimeUtils
import dsm.pick2024.infrastructure.s3.FileUtil
import dsm.pick2024.infrastructure.s3.PathList
import java.time.DayOfWeek
import java.time.LocalDate
import java.time.ZoneId
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

Expand All @@ -20,7 +20,7 @@ class QueryTeacherTimetableService(

@Transactional(readOnly = true)
override fun queryTeacherTimetable(grade: Int, classNum: Int): List<DayTimetableResponse> {
val startOfWeek = getStartOfWeek(LocalDate.now(ZoneId.of("Asia/Seoul")))
val startOfWeek = getStartOfWeek(TimeUtils.nowLocalDate())

return (0 until 5).map { i ->
val date = startOfWeek.plusDays(i.toLong())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import dsm.pick2024.domain.weekendmeal.enums.Status
import dsm.pick2024.domain.weekendmeal.port.`in`.NotificationWeekendMealUseCase
import dsm.pick2024.domain.weekendmeal.port.`in`.WeekendMealFinderUseCase
import dsm.pick2024.domain.weekendmeal.port.out.WeekendMealPeriodPort
import dsm.pick2024.global.common.TimeUtils
import org.springframework.stereotype.Service
import java.time.LocalDate

@Service
class NotificationWeekendMealService(
Expand All @@ -22,10 +22,11 @@ class NotificationWeekendMealService(
}

override fun execute() {
val weekendMealPeriod = weekendMealPeriodPort.queryWeekendPeriodByDate(LocalDate.now())
val today = TimeUtils.nowLocalDate()
val weekendMealPeriod = weekendMealPeriodPort.queryWeekendPeriodByDate(today)
if (weekendMealPeriod != null) {
val users = queryUserPort.findAll()
when (LocalDate.now()) {
when (today) {
weekendMealPeriod.end -> {
users.map {
val status = weekendMealFinderUseCase.findByUserIdOrThrow(it.id).status
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import dsm.pick2024.domain.weekendmeal.enums.Status.NO
import dsm.pick2024.domain.weekendmeal.enums.Status.OK
import dsm.pick2024.domain.weekendmeal.port.`in`.PrintExcelWeekendMealUseCase
import dsm.pick2024.domain.weekendmeal.port.out.QueryWeekendMealPort
import java.time.LocalDate
import dsm.pick2024.global.common.TimeUtils
import org.apache.poi.ss.usermodel.BorderStyle
import org.apache.poi.ss.usermodel.CellStyle
import org.apache.poi.ss.usermodel.FillPatternType
Expand All @@ -29,7 +29,8 @@ class PrintAllExcelWeekendMealService(

@Transactional(readOnly = true)
override fun execute(response: HttpServletResponse) {
val month = LocalDate.now().monthValue + 1
val kstNow = TimeUtils.nowLocalDate()
val month = kstNow.plusMonths(1).monthValue
val workbook: Workbook = XSSFWorkbook()

// 주말급식 정보
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import dsm.pick2024.domain.weekendmeal.enums.Status.NO
import dsm.pick2024.domain.weekendmeal.enums.Status.OK
import dsm.pick2024.domain.weekendmeal.port.`in`.PrintExcelClassWeekendMealUseCase
import dsm.pick2024.domain.weekendmeal.port.out.QueryWeekendMealPort
import java.time.LocalDate
import dsm.pick2024.global.common.TimeUtils
import javax.servlet.http.HttpServletResponse
import org.apache.poi.ss.usermodel.BorderStyle
import org.apache.poi.ss.usermodel.CellStyle
Expand All @@ -29,7 +29,8 @@ class PrintClassExcelWeekendMealService(

@Transactional(readOnly = true)
override fun execute(response: HttpServletResponse, grade: Int, classNum: Int) {
val month = LocalDate.now().monthValue + 1
val kstNow = TimeUtils.nowLocalDate()
val month = kstNow.plusMonths(1).monthValue
val workbook: Workbook = XSSFWorkbook()
val sheet: Sheet = workbook.createSheet("주말급식-신청명단").apply {
defaultColumnWidth = 15
Expand Down
16 changes: 16 additions & 0 deletions src/main/kotlin/dsm/pick2024/global/common/TimeUtils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package dsm.pick2024.global.common

import java.time.LocalDate
import java.time.LocalDateTime
import java.time.ZoneId

object TimeUtils {
val KST_ZONE_ID: ZoneId = ZoneId.of("Asia/Seoul")

fun nowLocalDate(): LocalDate {
return LocalDate.now(KST_ZONE_ID)
}
fun nowLocalDateTime(): LocalDateTime {
return LocalDateTime.now(KST_ZONE_ID)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dsm.pick2024.infrastructure.feign.neis
import com.google.gson.Gson
import dsm.pick2024.domain.meal.domain.Meal
import dsm.pick2024.domain.meal.enum.MealType
import dsm.pick2024.global.common.TimeUtils
import dsm.pick2024.infrastructure.feign.neis.client.NeisFeignClient
import dsm.pick2024.infrastructure.feign.neis.dto.response.NeisFeignClientMealServiceDietInfoResponse
import dsm.pick2024.infrastructure.feign.neis.property.NeisFeignClientRequestProperty
Expand All @@ -19,7 +20,8 @@ class NeisMealFeignClientService(
) {

fun getNeisInfoToEntity(): MutableList<Meal> {
val nextMonth = LocalDate.now().plusMonths(1)
val kstToday = TimeUtils.nowLocalDate()
val nextMonth = kstToday.plusMonths(1)

val neisMealServiceDietInfoString =
neisFeignClient.getMealServiceDietInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dsm.pick2024.infrastructure.feign.neis

import com.google.gson.Gson
import dsm.pick2024.domain.timetable.domain.Timetable
import dsm.pick2024.global.common.TimeUtils
import dsm.pick2024.infrastructure.feign.neis.client.NeisFeignClient
import dsm.pick2024.infrastructure.feign.neis.dto.response.NeisFeignClientTimetableResponse
import dsm.pick2024.infrastructure.feign.neis.property.NeisFeignClientRequestProperty
Expand All @@ -17,7 +18,7 @@ class NeisTimetableFeignClientService(
private val neisFeignClient: NeisFeignClient
) {
fun getNeisInfoToEntity(baseDay: Long): MutableList<Timetable>? {
val runDay = LocalDate.now().plusDays(baseDay)
val runDay = TimeUtils.nowLocalDate().plusDays(baseDay)
val neisTimetableServiceInfoString =
neisFeignClient.hisTimetable(
key = neisKey,
Expand Down