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 @@ -2,33 +2,34 @@ package com.wafflestudio.snutt.pre2025category.service

import com.wafflestudio.snutt.pre2025category.repository.CategoryPre2025Repository
import org.apache.poi.ss.usermodel.WorkbookFactory
import org.springframework.core.io.buffer.PooledDataBuffer
import org.springframework.stereotype.Service

@Service
class CategoryPre2025FetchService(
private val categoryPre2025Repository: CategoryPre2025Repository,
) {
suspend fun getCategoriesPre2025(): Map<String, String> {
val oldCategoriesXlsx = categoryPre2025Repository.fetchCategoriesPre2025()
val workbook = WorkbookFactory.create(oldCategoriesXlsx.asInputStream())
return workbook.sheetIterator().asSequence()
.flatMap { sheet ->
sheet.rowIterator().asSequence()
.drop(4)
.map { row ->
try {
val currentCourseNumber = row.getCell(7).stringCellValue
val oldCategory = row.getCell(1).stringCellValue
if (currentCourseNumber.isBlank() || oldCategory.isBlank()) {
return@map null
}
currentCourseNumber to oldCategory
} catch (e: Exception) {
null
val oldCategoriesXlsx: PooledDataBuffer = categoryPre2025Repository.fetchCategoriesPre2025()

try {
val workbook = WorkbookFactory.create(oldCategoriesXlsx.asInputStream())
return workbook.sheetIterator().asSequence()
.flatMap { sheet ->
sheet.rowIterator().asSequence()
.drop(4)
.mapNotNull { row ->
runCatching {
val currentCourseNumber = row.getCell(7).stringCellValue
val oldCategory = row.getCell(1).stringCellValue
check(currentCourseNumber.isNotBlank() && oldCategory.isNotBlank())
currentCourseNumber to oldCategory
}.getOrNull()
}
}
.filterNotNull()
}
.toMap()
}
.toMap()
} finally {
oldCategoriesXlsx.release()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.wafflestudio.snutt.sugangsnu.common.service

import com.wafflestudio.snutt.common.enum.Semester
import com.wafflestudio.snutt.lectures.data.Lecture
import com.wafflestudio.snutt.pre2025category.service.CategoryPre2025FetchService
import com.wafflestudio.snutt.sugangsnu.common.SugangSnuRepository
import com.wafflestudio.snutt.sugangsnu.common.utils.SugangSnuClassTimeUtils
import org.apache.poi.hssf.usermodel.HSSFWorkbook
Expand All @@ -19,6 +20,7 @@ interface SugangSnuFetchService {
@Service
class SugangSnuFetchServiceImpl(
private val sugangSnuRepository: SugangSnuRepository,
private val categoryPre2025FetchService: CategoryPre2025FetchService,
) : SugangSnuFetchService {
private val log = LoggerFactory.getLogger(javaClass)
private val quotaRegex = """(?<quota>\d+)(\s*\((?<quotaForCurrentStudent>\d+)\))?""".toRegex()
Expand All @@ -27,6 +29,7 @@ class SugangSnuFetchServiceImpl(
year: Int,
semester: Semester,
): List<Lecture> {
val courseNumberCategoryPre2025Map = categoryPre2025FetchService.getCategoriesPre2025()
val koreanLectureXlsx = sugangSnuRepository.getSugangSnuLectures(year, semester, "ko")
val englishLectureXlsx = sugangSnuRepository.getSugangSnuLectures(year, semester, "en")
val koreanSheet = HSSFWorkbook(koreanLectureXlsx.asInputStream()).getSheetAt(0)
Expand Down Expand Up @@ -69,6 +72,7 @@ class SugangSnuFetchServiceImpl(
department = extraDepartment ?: department
quota = extraLectureInfo.subInfo.quota ?: quota
remark = extraLectureInfo.subInfo.remark ?: remark
categoryPre2025 = courseNumberCategoryPre2025Map[lecture.courseNumber]
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import com.wafflestudio.snutt.lecturebuildings.service.LectureBuildingService
import com.wafflestudio.snutt.lectures.data.Lecture
import com.wafflestudio.snutt.lectures.service.LectureService
import com.wafflestudio.snutt.lectures.utils.ClassTimeUtils
import com.wafflestudio.snutt.pre2025category.service.CategoryPre2025FetchService
import com.wafflestudio.snutt.sugangsnu.common.SugangSnuRepository
import com.wafflestudio.snutt.sugangsnu.common.data.SugangSnuCoursebookCondition
import com.wafflestudio.snutt.sugangsnu.common.service.SugangSnuFetchService
Expand Down Expand Up @@ -47,7 +46,6 @@ interface SugangSnuSyncService {
@Service
class SugangSnuSyncServiceImpl(
private val sugangSnuFetchService: SugangSnuFetchService,
private val categoryPre2025FetchService: CategoryPre2025FetchService,
private val lectureService: LectureService,
private val timeTableRepository: TimetableRepository,
private val sugangSnuRepository: SugangSnuRepository,
Expand All @@ -59,14 +57,8 @@ class SugangSnuSyncServiceImpl(
private val log = LoggerFactory.getLogger(javaClass)

override suspend fun updateCoursebook(coursebook: Coursebook): List<UserLectureSyncResult> {
val courseNumberCategoryPre2025Map = categoryPre2025FetchService.getCategoriesPre2025()
val newLectures =
sugangSnuFetchService.getSugangSnuLectures(coursebook.year, coursebook.semester)
.map { lecture ->
lecture.apply {
categoryPre2025 = courseNumberCategoryPre2025Map[lecture.courseNumber]
}
}
val oldLectures =
lectureService.getLecturesByYearAndSemesterAsFlow(coursebook.year, coursebook.semester).toList()
val compareResult = compareLectures(newLectures, oldLectures)
Expand All @@ -81,14 +73,8 @@ class SugangSnuSyncServiceImpl(
}

override suspend fun addCoursebook(coursebook: Coursebook) {
val courseNumberCategoryPre2025Map = categoryPre2025FetchService.getCategoriesPre2025()
val newLectures =
sugangSnuFetchService.getSugangSnuLectures(coursebook.year, coursebook.semester)
.map { lecture ->
lecture.apply {
categoryPre2025 = courseNumberCategoryPre2025Map[lecture.courseNumber]
}
}
lectureService.upsertLectures(newLectures)
syncTagList(coursebook, newLectures)

Expand Down