Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

재학생 수강신청 기간 빈자리 알림 버그 픽스 #220

Merged
merged 1 commit into from
Feb 2, 2024
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 @@ -3,5 +3,5 @@ package com.wafflestudio.snu4t.sugangsnu.job.vacancynotification.data
data class RegistrationStatus(
val courseNumber: String,
val lectureNumber: String,
val registrationCount: Int
val registrationCount: Int,
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.wafflestudio.snu4t.common.enum.Semester
import com.wafflestudio.snu4t.common.push.UrlScheme
import com.wafflestudio.snu4t.common.push.dto.PushMessage
import com.wafflestudio.snu4t.coursebook.data.Coursebook
import com.wafflestudio.snu4t.lectures.data.Lecture
import com.wafflestudio.snu4t.lectures.service.LectureService
import com.wafflestudio.snu4t.notification.data.NotificationType
import com.wafflestudio.snu4t.notification.service.PushWithNotificationService
Expand Down Expand Up @@ -60,8 +61,6 @@ class VacancyNotifierServiceImpl(
val lectures =
lectureService.getLecturesByYearAndSemesterAsFlow(coursebook.year, coursebook.semester).toList()
val lectureMap = lectures.associateBy { lecture -> lecture.courseNumber + "##" + lecture.lectureNumber }
val isCurrentStudentRegistrationPeriod =
coursebook.semester == Semester.SPRING && LocalDate.now().dayOfMonth < 15

// 수강 사이트 부하를 분산하기 위해 강의 전체를 20등분해서 각각 요청
(1..pageCount).chunked(pageCount / 20).forEach { chunkedPages ->
Expand All @@ -74,21 +73,17 @@ class VacancyNotifierServiceImpl(
val lectureAndRegistrationStatus = (lectureMap.keys intersect registrationStatusMap.keys)
.map { lectureMap[it]!! to registrationStatusMap[it]!! }

val notiTargetLectures = lectureAndRegistrationStatus.filter { (lecture, _) ->
if (isCurrentStudentRegistrationPeriod) {
lecture.quota - (lecture.freshmanQuota ?: 0) == lecture.registrationCount
} else {
lecture.quota == lecture.registrationCount
}
}.filter { (lecture, status) -> lecture.registrationCount > status.registrationCount }
val notiTargetLectures = lectureAndRegistrationStatus
.filter { (lecture, _) -> lecture.isFull() }
.filter { (lecture, status) -> lecture.registrationCount > status.registrationCount }
.map { (lecture, _) -> lecture }

val updated = lectureAndRegistrationStatus
.filter { (lecture, status) -> lecture.registrationCount != status.registrationCount }
.map { (lecture, status) ->
lecture.apply {
registrationCount = status.registrationCount
wasFull = wasFull || lecture.registrationCount == lecture.quota
wasFull = wasFull || lecture.isFull()
}
}
lectureService.upsertLectures(updated)
Expand Down Expand Up @@ -122,6 +117,16 @@ class VacancyNotifierServiceImpl(
return VacancyNotificationJobResult.SUCCESS
}

private fun Lecture.isFull(): Boolean {
val isCurrentStudentRegistrationPeriod =
this.semester == Semester.SPRING && LocalDate.now().dayOfMonth < 15
return if (isCurrentStudentRegistrationPeriod) {
this.quota - (this.freshmanQuota ?: 0) == this.registrationCount
} else {
this.quota == this.registrationCount
}
}

private suspend fun getPageCount(): Int {
val firstPageContent = getSugangSnuSearchContent(1)
val totalCount =
Expand Down Expand Up @@ -152,10 +157,13 @@ class VacancyNotifierServiceImpl(
info.select("ul.course-info > li:nth-of-type(2) > span:nth-of-type(1) > em")
.text()
.split("/").first().toInt()
val hasVacancy =
info.select("""ul.course-info > li:nth-of-type(3) > span[data-dialog-target="remaining-place-dialog"]""")
.isNotEmpty()
RegistrationStatus(
courseNumber = courseNumber,
lectureNumber = lectureNumber,
registrationCount = registrationCount
registrationCount = registrationCount,
)
}
}
Expand Down
7 changes: 4 additions & 3 deletions core/src/main/resources/application-common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ spring:
enabled: false
host:
database:
logging:
level:
org.springframework.data.mongodb.core.ReactiveMongoTemplate: DEBUG

google:
firebase:
Expand Down Expand Up @@ -60,6 +57,10 @@ google:
bundle-id:
app-store-id:

logging:
level:
org.springframework.data.mongodb.core.ReactiveMongoTemplate: DEBUG

---

spring:
Expand Down
Loading