Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
rudeh2926 committed Nov 12, 2024
2 parents 3a12141 + a7c0b5f commit 729de1c
Show file tree
Hide file tree
Showing 14 changed files with 70 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import dsm.pick2024.domain.application.port.out.QueryAllApplicationPort
import dsm.pick2024.domain.application.port.out.QueryApplicationPort
import dsm.pick2024.domain.application.presentation.dto.response.QueryApplicationResponse
import dsm.pick2024.domain.classroom.exception.FloorNotFoundException
import org.joda.time.LocalDate
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

Expand All @@ -19,16 +18,11 @@ class QueryFloorApplicationService(

@Transactional(readOnly = true)
override fun queryFloorAndStatusApplication(floor: Int, status: Status): List<QueryApplicationResponse> {
val today = LocalDate.now().dayOfWeek

val applications = when (floor) {
2, 3, 4 -> {
val filteredClassrooms = if (today == 2 || today == 5) {
queryApplicationPort.queryApplicationWithAttendance(floor)
} else {
val filterClassroomList =
queryApplicationPort.findByFloorAndApplicationKind(floor, ApplicationKind.APPLICATION)
}
filteredClassrooms.filter { it.status == status }
filterClassroomList.filter { it.status == status }
}
5 -> {
queryAllApplicationPort.findAllByStatusAndApplicationKind(status, ApplicationKind.APPLICATION)
Expand Down
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 All @@ -27,11 +28,15 @@ class AttendancePersistenceAdapter(

override fun findAll() = attendanceJpaRepository.findAll().map { attendanceMapper.toDomain(it) }

override fun findByFloor(floor: Int): List<Attendance>? = attendanceJpaRepository.findByFloor(floor).map {
attendanceMapper.toDomain(
it
)
}
override fun findByFloor(floor: Int): List<Attendance>? =
jpaQueryFactory
.selectFrom(QAttendanceJpaEntity.attendanceJpaEntity)
.where(
QAttendanceJpaEntity.attendanceJpaEntity.floor.eq(floor),
QAttendanceJpaEntity.attendanceJpaEntity.period6.ne(AttendanceStatus.DROPOUT)
)
.fetch()
.map { attendanceMapper.toDomain(it) }

override fun findByGradeAndClassNum(
grade: Int,
Expand All @@ -40,7 +45,8 @@ class AttendancePersistenceAdapter(
.selectFrom(QAttendanceJpaEntity.attendanceJpaEntity)
.where(
QAttendanceJpaEntity.attendanceJpaEntity.grade.eq(grade),
QAttendanceJpaEntity.attendanceJpaEntity.classNum.eq(classNum)
QAttendanceJpaEntity.attendanceJpaEntity.classNum.eq(classNum),
QAttendanceJpaEntity.attendanceJpaEntity.period6.ne(AttendanceStatus.DROPOUT)
)
.fetch()
.map { attendanceMapper.toDomain(it) }
Expand All @@ -49,7 +55,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 @@ -35,7 +35,7 @@ class ChangeStatusService(
)
updateStatuses.add(updatedStatus)

if (requests.statusType in setOf(EMPLOYMENT, PICNIC, ATTENDANCE)) {
if (requests.statusType in setOf(EMPLOYMENT, PICNIC, ATTENDANCE, DROPOUT)) {
val attendance = queryAttendancePort.findByUserId(requests.userId)
?: throw UserNotFoundException

Expand All @@ -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 729de1c

Please sign in to comment.