From 60b1b3026ce16ea8374f77f2fb7db98d10d90589 Mon Sep 17 00:00:00 2001 From: ddingmin Date: Mon, 20 May 2024 01:35:26 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=84=B8=EC=85=98=20=EB=B6=88=EC=B0=B8?= =?UTF-8?q?=EC=9E=90=20=EA=B2=B0=EC=84=9D=20=EC=B2=98=EB=A6=AC=20=EC=8A=A4?= =?UTF-8?q?=EC=BC=80=EC=A5=B4=EB=9F=AC=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/usecase/UpdateAbsenceMember.kt | 35 +++++++++++++++++++ .../restapi/config/aspect/SchedulerLogger.kt | 26 ++++++++++++++ .../makers/scheduler/AbsentMemberScheduler.kt | 26 ++++++++++++++ 3 files changed, 87 insertions(+) create mode 100644 src/main/kotlin/com/depromeet/makers/domain/usecase/UpdateAbsenceMember.kt create mode 100644 src/main/kotlin/com/depromeet/makers/presentation/restapi/config/aspect/SchedulerLogger.kt create mode 100644 src/main/kotlin/com/depromeet/makers/scheduler/AbsentMemberScheduler.kt diff --git a/src/main/kotlin/com/depromeet/makers/domain/usecase/UpdateAbsenceMember.kt b/src/main/kotlin/com/depromeet/makers/domain/usecase/UpdateAbsenceMember.kt new file mode 100644 index 0000000..e1cd0e6 --- /dev/null +++ b/src/main/kotlin/com/depromeet/makers/domain/usecase/UpdateAbsenceMember.kt @@ -0,0 +1,35 @@ +package com.depromeet.makers.domain.usecase + +import com.depromeet.makers.domain.gateway.AttendanceGateway +import com.depromeet.makers.domain.gateway.SessionGateway +import com.depromeet.makers.domain.model.AttendanceStatus +import com.depromeet.makers.util.logger +import java.time.LocalDateTime + +class UpdateAbsenceMember( + private val sessionGateway: SessionGateway, + private val attendanceGateway: AttendanceGateway, +) : UseCase { + data class UpdateAbsenceMemberInput( + val today: LocalDateTime, + ) + + override fun execute(input: UpdateAbsenceMemberInput) { + val logger = logger() + + val session = sessionGateway.findByStartTimeBetween(input.today, input.today.plusDays(1)) + if (session == null) { + return + } + + val attendances = attendanceGateway.findAllByGenerationAndWeek(session.generation, session.week) + attendances + .filter { + it.attendanceStatus == AttendanceStatus.ATTENDANCE_ON_HOLD + } + .forEach { + attendanceGateway.save(it.copy(attendanceStatus = AttendanceStatus.ABSENCE)) + logger.info("memberId: ${it.member.memberId} has been changed to ${AttendanceStatus.ATTENDANCE}") + } + } +} diff --git a/src/main/kotlin/com/depromeet/makers/presentation/restapi/config/aspect/SchedulerLogger.kt b/src/main/kotlin/com/depromeet/makers/presentation/restapi/config/aspect/SchedulerLogger.kt new file mode 100644 index 0000000..99caf0c --- /dev/null +++ b/src/main/kotlin/com/depromeet/makers/presentation/restapi/config/aspect/SchedulerLogger.kt @@ -0,0 +1,26 @@ +package com.depromeet.makers.presentation.restapi.config.aspect + +import com.depromeet.makers.util.logger +import org.aspectj.lang.ProceedingJoinPoint +import org.aspectj.lang.annotation.Around +import org.aspectj.lang.annotation.Aspect +import org.springframework.stereotype.Component + +@Aspect +@Component +class SchedulerLogger { + val logger = logger() + + @Around("@annotation(org.springframework.scheduling.annotation.Scheduled)") + fun logging(joinPoint: ProceedingJoinPoint): Any? { + val start = System.currentTimeMillis() + logger.info("Scheduler: ${joinPoint.target.javaClass.simpleName} start") + + val result = joinPoint.proceed() + + val end = System.currentTimeMillis() + logger.info("Scheduler: ${joinPoint.target.javaClass.simpleName} end, duration: ${end - start}ms") + + return result + } +} diff --git a/src/main/kotlin/com/depromeet/makers/scheduler/AbsentMemberScheduler.kt b/src/main/kotlin/com/depromeet/makers/scheduler/AbsentMemberScheduler.kt new file mode 100644 index 0000000..831baf8 --- /dev/null +++ b/src/main/kotlin/com/depromeet/makers/scheduler/AbsentMemberScheduler.kt @@ -0,0 +1,26 @@ +package com.depromeet.makers.scheduler + +import com.depromeet.makers.domain.usecase.UpdateAbsenceMember +import com.depromeet.makers.util.logger +import org.springframework.scheduling.annotation.Scheduled +import org.springframework.stereotype.Component +import java.time.LocalDate +import java.time.LocalDateTime +import java.time.LocalTime + +@Component +class AbsentMemberScheduler( + private val updateAbsenceMember: UpdateAbsenceMember +) { + + @Scheduled(cron = "0 0 20 ? * SAT") + fun scheduling() { + val logger = logger() + logger.info("Scheduler start") + + val today = LocalDateTime.of(LocalDate.now(), LocalTime.MIDNIGHT) + updateAbsenceMember.execute(UpdateAbsenceMember.UpdateAbsenceMemberInput(today)) + + logger.info("Scheduler end") + } +}