diff --git a/dms-core/src/main/kotlin/team/aliens/dms/domain/studyroom/spi/vo/StudentSeatInfo.kt b/dms-core/src/main/kotlin/team/aliens/dms/domain/studyroom/spi/vo/StudentSeatInfo.kt index 8e9d5d964..6562007f6 100644 --- a/dms-core/src/main/kotlin/team/aliens/dms/domain/studyroom/spi/vo/StudentSeatInfo.kt +++ b/dms-core/src/main/kotlin/team/aliens/dms/domain/studyroom/spi/vo/StudentSeatInfo.kt @@ -3,11 +3,14 @@ package team.aliens.dms.domain.studyroom.spi.vo import java.util.UUID class StudentSeatInfo( - val studentId: UUID, - val studentName: String, val studentGrade: Int, val studentClassRoom: Int, val studentNumber: Int, - val seatFullName: String?, - val timeSlotId: UUID? -) + val studentName: String, + val seats: List? +) { + class SeatInfo( + val seatFullName: String?, + val timeSlotId: UUID? + ) +} diff --git a/dms-core/src/main/kotlin/team/aliens/dms/domain/studyroom/usecase/ExportStudyRoomApplicationStatusUseCase.kt b/dms-core/src/main/kotlin/team/aliens/dms/domain/studyroom/usecase/ExportStudyRoomApplicationStatusUseCase.kt index f98306296..ea0fccecb 100644 --- a/dms-core/src/main/kotlin/team/aliens/dms/domain/studyroom/usecase/ExportStudyRoomApplicationStatusUseCase.kt +++ b/dms-core/src/main/kotlin/team/aliens/dms/domain/studyroom/usecase/ExportStudyRoomApplicationStatusUseCase.kt @@ -14,9 +14,11 @@ import team.aliens.dms.domain.studyroom.spi.StudyRoomQuerySchoolPort import team.aliens.dms.domain.studyroom.spi.StudyRoomQueryStudentPort import team.aliens.dms.domain.studyroom.spi.StudyRoomQueryUserPort import team.aliens.dms.domain.studyroom.spi.StudyRoomSecurityPort +import team.aliens.dms.domain.studyroom.spi.vo.StudentSeatApplicationVO import team.aliens.dms.domain.studyroom.spi.vo.StudentSeatInfo import team.aliens.dms.domain.user.exception.UserNotFoundException import java.time.LocalDateTime +import java.util.UUID @ReadOnlyUseCase class ExportStudyRoomApplicationStatusUseCase( @@ -33,23 +35,21 @@ class ExportStudyRoomApplicationStatusUseCase( val manager = queryUserPort.queryUserById(currentUserId) ?: throw UserNotFoundException val students = queryStudentPort.queryStudentsBySchoolId(manager.schoolId) - val studentSeatApplicationsMap = queryStudyRoomPort.querySeatApplicationsByStudentIdIn( - studentIds = students.map { it.id } - ).associateBy { it.studentId } + val studentSeatApplicationsMap = getStudentSeatApplicationsMap(students) val studentSeats = students.map { student -> - val seat = studentSeatApplicationsMap[student.id] StudentSeatInfo( - studentId = student.id, - studentName = student.name, studentGrade = student.grade, studentClassRoom = student.classRoom, studentNumber = student.number, - seatFullName = seat?.let { - StudyRoom.precessName(it.studyRoomFloor, it.studyRoomName) + - " " + Seat.processName(it.seatNumber, it.seatTypeName) - }, - timeSlotId = seat?.timeSlotId + studentName = student.name, + seats = studentSeatApplicationsMap[student.id]?.map { + StudentSeatInfo.SeatInfo( + seatFullName = StudyRoom.precessName(it.studyRoomFloor, it.studyRoomName) + + " " + Seat.processName(it.seatNumber, it.seatTypeName), + timeSlotId = it.timeSlotId + ) + } ) } @@ -62,6 +62,16 @@ class ExportStudyRoomApplicationStatusUseCase( ) } + private fun getStudentSeatApplicationsMap(students: List) = + mutableMapOf>().apply { + queryStudyRoomPort.querySeatApplicationsByStudentIdIn( + studentIds = students.map { it.id } + ).map { + get(it.studentId) + ?.run { this.add(it) } ?: put(it.studentId, mutableListOf(it)) + } + } + private fun getStudyRoomApplicationStatusFile( file: java.io.File?, timeSlots: List, @@ -71,10 +81,7 @@ class ExportStudyRoomApplicationStatusUseCase( baseFile = file, timeSlots = timeSlots, studentSeatsMap = studentSeats.associateBy { - Pair( - Student.processGcn(it.studentGrade, it.studentClassRoom, it.studentNumber), - it.studentName - ) + Pair(Student.processGcn(it.studentGrade, it.studentClassRoom, it.studentNumber), it.studentName) } ) } ?: writeFilePort.writeStudyRoomApplicationStatusExcelFile( diff --git a/dms-core/src/main/kotlin/team/aliens/dms/domain/studyroom/usecase/StudentQueryStudyRoomsUseCase.kt b/dms-core/src/main/kotlin/team/aliens/dms/domain/studyroom/usecase/StudentQueryStudyRoomsUseCase.kt index 981045869..f18d89e1d 100644 --- a/dms-core/src/main/kotlin/team/aliens/dms/domain/studyroom/usecase/StudentQueryStudyRoomsUseCase.kt +++ b/dms-core/src/main/kotlin/team/aliens/dms/domain/studyroom/usecase/StudentQueryStudyRoomsUseCase.kt @@ -1,6 +1,5 @@ package team.aliens.dms.domain.studyroom.usecase -import java.util.UUID import team.aliens.dms.common.annotation.ReadOnlyUseCase import team.aliens.dms.domain.school.validateSameSchool import team.aliens.dms.domain.student.exception.StudentNotFoundException @@ -13,6 +12,7 @@ import team.aliens.dms.domain.studyroom.spi.StudyRoomQueryStudentPort import team.aliens.dms.domain.studyroom.spi.StudyRoomQueryUserPort import team.aliens.dms.domain.studyroom.spi.StudyRoomSecurityPort import team.aliens.dms.domain.user.exception.UserNotFoundException +import java.util.UUID @ReadOnlyUseCase class StudentQueryStudyRoomsUseCase( @@ -41,10 +41,10 @@ class StudentQueryStudyRoomsUseCase( availableGrade = it.availableGrade, availableSex = it.availableSex, inUseHeadcount = it.inUseHeadcount, - totalAvailableSeat = it.totalAvailableSeat, - isMine = appliedSeat?.studyRoomId == it.id - ) - } + totalAvailableSeat = it.totalAvailableSeat, + isMine = appliedSeat?.studyRoomId == it.id + ) + } return StudentQueryStudyRoomsResponse( studyRooms = studyRooms diff --git a/dms-core/src/test/kotlin/team/aliens/dms/domain/studyroom/usecase/ExportStudyRoomStudentsApplicationStatusUseCaseTests.kt b/dms-core/src/test/kotlin/team/aliens/dms/domain/studyroom/usecase/ExportStudyRoomStudentsApplicationStatusUseCaseTests.kt index 11cf9bfcf..9d743f80c 100644 --- a/dms-core/src/test/kotlin/team/aliens/dms/domain/studyroom/usecase/ExportStudyRoomStudentsApplicationStatusUseCaseTests.kt +++ b/dms-core/src/test/kotlin/team/aliens/dms/domain/studyroom/usecase/ExportStudyRoomStudentsApplicationStatusUseCaseTests.kt @@ -3,6 +3,8 @@ package team.aliens.dms.domain.studyroom.usecase import io.mockk.every import io.mockk.mockk import io.mockk.slot +import java.io.File +import java.util.UUID import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertAll @@ -21,8 +23,6 @@ import team.aliens.dms.domain.studyroom.spi.vo.StudentSeatInfo import team.aliens.dms.domain.studyroom.stub.createTimeSlotStub import team.aliens.dms.domain.user.exception.UserNotFoundException import team.aliens.dms.domain.user.stub.createUserStub -import java.io.File -import java.util.UUID class ExportStudyRoomStudentsApplicationStatusUseCaseTests { @@ -115,7 +115,7 @@ class ExportStudyRoomStudentsApplicationStatusUseCaseTests { { assertEquals(studentSeatInfo.studentGrade, studentStub.grade) }, { assertEquals(studentSeatInfo.studentClassRoom, studentStub.classRoom) }, { assertEquals(studentSeatInfo.studentNumber, studentStub.number) }, - { assertEquals(studentSeatInfo.timeSlotId, studentSeatApplicationVOStub.timeSlotId) }, + { assertEquals(studentSeatInfo.seats?.get(0)?.timeSlotId, studentSeatApplicationVOStub.timeSlotId) }, { assert(response.fileName.startsWith("${schoolStub.name.replace(" ", "")}_자습실_신청상태_")) } ) } @@ -152,7 +152,7 @@ class ExportStudyRoomStudentsApplicationStatusUseCaseTests { { assertEquals(studentSeatInfo.studentGrade, studentStub.grade) }, { assertEquals(studentSeatInfo.studentClassRoom, studentStub.classRoom) }, { assertEquals(studentSeatInfo.studentNumber, studentStub.number) }, - { assertEquals(studentSeatInfo.timeSlotId, studentSeatApplicationVOStub.timeSlotId) }, + { assertEquals(studentSeatInfo.seats?.get(0)?.timeSlotId, studentSeatApplicationVOStub.timeSlotId) }, { assert(response.fileName.startsWith("${schoolStub.name.replace(" ", "")}_자습실_신청상태_")) } ) } diff --git a/dms-infrastructure/src/main/kotlin/team/aliens/dms/thirdparty/parser/ExcelAdapter.kt b/dms-infrastructure/src/main/kotlin/team/aliens/dms/thirdparty/parser/ExcelAdapter.kt index d7e3bfa6e..2e7e9ae56 100644 --- a/dms-infrastructure/src/main/kotlin/team/aliens/dms/thirdparty/parser/ExcelAdapter.kt +++ b/dms-infrastructure/src/main/kotlin/team/aliens/dms/thirdparty/parser/ExcelAdapter.kt @@ -1,5 +1,9 @@ package team.aliens.dms.thirdparty.parser +import java.io.ByteArrayOutputStream +import java.io.File +import java.time.format.DateTimeFormatter +import java.util.UUID import org.apache.poi.hssf.usermodel.HSSFWorkbook import org.apache.poi.ss.usermodel.Cell import org.apache.poi.ss.usermodel.CellStyle @@ -27,9 +31,6 @@ import team.aliens.dms.domain.studyroom.model.TimeSlot import team.aliens.dms.domain.studyroom.spi.vo.StudentSeatInfo import team.aliens.dms.thirdparty.parser.exception.ExcelExtensionMismatchException import team.aliens.dms.thirdparty.parser.exception.ExcelInvalidFileException -import java.io.ByteArrayOutputStream -import java.io.File -import java.time.format.DateTimeFormatter @Component class ExcelAdapter : ParseFilePort, WriteFilePort { @@ -47,6 +48,7 @@ class ExcelAdapter : ParseFilePort, WriteFilePort { val excelData = row.run { VerifiedStudent( + id = UUID.randomUUID(), schoolName = schoolName, gcn = Student.processGcn( grade = getIntValue(0), @@ -157,7 +159,7 @@ class ExcelAdapter : ParseFilePort, WriteFilePort { val row = worksheet.getRow(i) if (row.isFirstCellBlank()) continue - val studentSeat = row.run { + val studentSeats = row.run { try { studentSeatsMap[ Pair( @@ -169,16 +171,13 @@ class ExcelAdapter : ParseFilePort, WriteFilePort { e.printStackTrace() throw BadExcelFormatException } - } + }?.seats - val timeSlotIdx = studentSeat?.timeSlotId?.let { - timeSlots.indexOfFirst { it.id == studentSeat.timeSlotId } - } insertDatasAtRow( row = row, startIdx = columnCount, - datas = (timeSlots.indices).map { - if (it == timeSlotIdx) studentSeat.seatFullName else null + datas = timeSlots.map { timeSlot -> + studentSeats?.singleOrNull { it.timeSlotId == timeSlot.id }?.seatFullName }, style = getDefaultCellStyle(workbook) ) @@ -215,22 +214,21 @@ class ExcelAdapter : ParseFilePort, WriteFilePort { ): ByteArray { val attributes = listOf("학년", "반", "번호", "이름", *timeSlots.map { it.name }.toTypedArray()) - val remainInfosList = studentSeats.map { studentSeat -> - val timeSlotIdx = studentSeat.timeSlotId?.let { timeSlots.indexOfFirst { ts -> ts.id == it } } + val seatInfosList = studentSeats.map { studentSeat -> listOf( studentSeat.studentGrade.toString(), studentSeat.studentClassRoom.toString(), studentSeat.studentNumber.toString(), studentSeat.studentName, - *(timeSlots.indices) - .map { i -> if (i == timeSlotIdx) studentSeat.seatFullName else null } - .toTypedArray(), + *timeSlots.map { timeSlot -> + studentSeat.seats?.singleOrNull { it.timeSlotId == timeSlot.id }?.seatFullName + }.toTypedArray(), ) } return createExcelSheet( attributes = attributes, - datasList = remainInfosList + datasList = seatInfosList ) } diff --git a/dms-infrastructure/src/test/kotlin/team/aliens/dms/thirdparty/parser/ExcelAdapterTests.kt b/dms-infrastructure/src/test/kotlin/team/aliens/dms/thirdparty/parser/ExcelAdapterTests.kt index fd75fb842..0002df71a 100644 --- a/dms-infrastructure/src/test/kotlin/team/aliens/dms/thirdparty/parser/ExcelAdapterTests.kt +++ b/dms-infrastructure/src/test/kotlin/team/aliens/dms/thirdparty/parser/ExcelAdapterTests.kt @@ -3,6 +3,9 @@ package team.aliens.dms.thirdparty.parser import io.mockk.every import io.mockk.slot import io.mockk.spyk +import java.time.LocalDateTime +import java.time.LocalTime +import java.util.UUID import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertAll @@ -12,9 +15,6 @@ import team.aliens.dms.domain.remain.dto.StudentRemainInfo import team.aliens.dms.domain.student.model.Sex import team.aliens.dms.domain.studyroom.model.TimeSlot import team.aliens.dms.domain.studyroom.spi.vo.StudentSeatInfo -import java.time.LocalDateTime -import java.time.LocalTime -import java.util.UUID class ExcelAdapterTests { @@ -119,13 +119,16 @@ class ExcelAdapterTests { private val studentSeatInfosStub by lazy { listOf( StudentSeatInfo( - studentId = UUID.randomUUID(), studentName = "", studentGrade = 1, studentClassRoom = 2, studentNumber = 3, - seatFullName = "", - timeSlotId = timeSlotStub.id + seats = listOf( + StudentSeatInfo.SeatInfo( + seatFullName = "", + timeSlotId = UUID.randomUUID() + ) + ) ) ) }