Skip to content

Commit

Permalink
Merge pull request #407 from DSM-PICK/issue
Browse files Browse the repository at this point in the history
🔀 :: (PiCK-긴급) 여러 이슈 해결
  • Loading branch information
rudeh2926 authored Nov 12, 2024
2 parents e14cb03 + f3a129c commit 819a674
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ enum class AttendanceStatus {
DISALLOWED, // 무단
PICNIC, // 현체
EMPLOYMENT, // 취업
GO_HOME //귀가
GO_HOME, //귀가
DROPOUT //자퇴
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dsm.pick2024.domain.attendance.persistence
import com.querydsl.jpa.impl.JPAQueryFactory
import dsm.pick2024.domain.attendance.domain.Attendance
import dsm.pick2024.domain.attendance.entity.QAttendanceJpaEntity
import dsm.pick2024.domain.attendance.enums.AttendanceStatus
import dsm.pick2024.domain.attendance.mapper.AttendanceMapper
import dsm.pick2024.domain.attendance.persistence.repository.AttendanceRepository
import dsm.pick2024.domain.attendance.port.out.AttendancePort
Expand Down Expand Up @@ -49,7 +50,8 @@ class AttendancePersistenceAdapter(
jpaQueryFactory
.selectFrom(QAttendanceJpaEntity.attendanceJpaEntity)
.where(
QAttendanceJpaEntity.attendanceJpaEntity.club.eq(club)
QAttendanceJpaEntity.attendanceJpaEntity.club.eq(club),
QAttendanceJpaEntity.attendanceJpaEntity.period6.ne(AttendanceStatus.DROPOUT)
)
.fetch()
.map { attendanceMapper.toDomain(it) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ class QueryClubAttendanceService(
classNum = it.classNum,
num = it.num,
status = returnStatus,
classroomName = classroomName!!
classroomName = classroomName
)
}.sortedWith(
compareBy({ it.grade }, { it.classNum }, { it.num })
)
}
private fun returnStatus(period: Int, attendance: Attendance): AttendanceStatus {
return when (period) {
6 -> attendance!!.period6
7 -> attendance!!.period7
8 -> attendance!!.period8
9 -> attendance!!.period9
10 -> attendance!!.period10
6 -> attendance.period6
7 -> attendance.period7
8 -> attendance.period8
9 -> attendance.period9
10 -> attendance.period10
else -> throw InvalidPeriodException
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class ResetAttendanceService(

private fun getStatus(currentStatus: AttendanceStatus) =
when (currentStatus) {
AttendanceStatus.PICNIC, AttendanceStatus.EMPLOYMENT -> currentStatus
AttendanceStatus.DROPOUT, AttendanceStatus.PICNIC, AttendanceStatus.EMPLOYMENT -> currentStatus
else -> AttendanceStatus.ATTENDANCE
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,8 @@ class SchedulePersistenceAdapter(
val entities = schedule.map { scheduleMapper.toEntity(it) }
scheduleRepository.saveAll(entities)
}

override fun deleteAll() {
scheduleRepository.deleteAll()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ interface ScheduleRepository : Repository<ScheduleJpaEntity, UUID> {
fun saveAll(entity: Iterable<ScheduleJpaEntity>)

fun findAllByDate(date: LocalDate): List<ScheduleJpaEntity>?

fun deleteAll()
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package dsm.pick2024.domain.schedule.port.`in`

interface SaveScheduleUseCase {
fun saveNeisInfoToDatabase(start: String, end: String)
fun saveNeisInfoToDatabase()
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ import java.util.UUID

interface DeleteSchedulePort {
fun deleteById(id: UUID)

fun deleteAll()
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,7 @@ class ScheduleController(

@Operation(summary = "나이스 학사일정 저장 api")
@PostMapping("/save")
fun saveSchedule(
@RequestParam(name = "start") start: String,
@RequestParam(name = "end") end: String
) = scheduleUseCase.saveNeisInfoToDatabase(start, end)
fun saveSchedule() = scheduleUseCase.saveNeisInfoToDatabase()

@Operation(summary = "일 별 학사일정조회 api")
@GetMapping("/date")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,43 @@
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.config.cache.CacheName
import dsm.pick2024.infrastructure.feign.NeisScheduleFeignClientService
import org.springframework.cache.annotation.CacheEvict
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import java.time.LocalDate
import java.time.format.DateTimeFormatter

@Service
class SaveScheduleService(
private val saveSchedulePort: SaveSchedulePort,
private val deleteSchedulePort: DeleteSchedulePort,
private val neisScheduleFeignClientService: NeisScheduleFeignClientService
) : SaveScheduleUseCase {

@CacheEvict(value = [CacheName.SCHEDULES], allEntries = true)
@Transactional
override fun saveNeisInfoToDatabase(start: String, end: String) {
override fun saveNeisInfoToDatabase() {
val (start, end) = formatDate()
deleteSchedulePort.deleteAll()
val scheduleForSave =
neisScheduleFeignClientService.getNeisInfoToEntity(start, end)

scheduleForSave?.let { saveSchedulePort.saveFeignSchedule(it) }
}

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

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

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

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

return start.format(formatter) to end.format(formatter)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class ChangeStatusService(
private fun updatePeriodStatus(statusType: StatusType): AttendanceStatus {
return when (statusType) {
PICNIC -> AttendanceStatus.PICNIC
DROPOUT -> AttendanceStatus.DROPOUT
EMPLOYMENT -> AttendanceStatus.EMPLOYMENT
else -> AttendanceStatus.ATTENDANCE
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import org.springframework.transaction.annotation.Transactional

@Service
class ResetStatusService(
private val querystatusPort: QueryStatusPort,
private val queryStatusPort: QueryStatusPort,
private val saveStatusPort: SaveStatusPort
) : ResetStatusUseCase {

@Transactional(readOnly = true)
override fun reset() {
val allStudent = querystatusPort.findAll()
val allStudent = queryStatusPort.findAll()
val update = mutableListOf<Status>()

allStudent.map { it ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import dsm.pick2024.domain.application.port.out.DeleteApplicationPort
import dsm.pick2024.domain.attendance.port.`in`.ResetAttendanceUseCase
import dsm.pick2024.domain.classroom.port.out.DeleteClassRoomPort
import dsm.pick2024.domain.meal.port.`in`.MealUseCase
import dsm.pick2024.domain.schedule.port.`in`.SaveScheduleUseCase
import dsm.pick2024.domain.status.port.`in`.ResetStatusUseCase
import dsm.pick2024.domain.timetable.port.`in`.SaveTimetableUseCase
import dsm.pick2024.domain.timetable.port.out.DeleteTimeTablePort
Expand All @@ -20,7 +21,8 @@ class ScheduleService(
private val mealUseCase: MealUseCase,
private val resetAttendanceUseCase: ResetAttendanceUseCase,
private val resetStatusUseCase: ResetStatusUseCase,
private val saveTimetableUseCase: SaveTimetableUseCase
private val saveTimetableUseCase: SaveTimetableUseCase,
private val saveScheduleUseCase: SaveScheduleUseCase
) {
@Scheduled(cron = "0 30 20 * * ?", zone = "Asia/Seoul")
fun deleteTable() {
Expand All @@ -36,13 +38,18 @@ class ScheduleService(

@Scheduled(cron = "0 00 21 * * ?", zone = "Asia/Seoul")
fun resetTable() {
resetAttendanceUseCase.resetAttendance()
resetStatusUseCase.reset()
resetAttendanceUseCase.resetAttendance()
}

@Scheduled(cron = "0 0 14 * * SUN")
fun saveTimetable() {
deleteTimetablePort.deleteAll()
saveTimetableUseCase.saveTimetable()
}

@Scheduled(cron = "0 0 8 * * ?")
fun saveSchedule() {
saveScheduleUseCase.saveNeisInfoToDatabase()
}
}

0 comments on commit 819a674

Please sign in to comment.