комит
This commit is contained in:
@@ -114,7 +114,8 @@ public class AcademicCalendarGridService {
|
||||
|
||||
private void validateWeek(AcademicYear academicYear, LocalDate date, Integer weekNumber) {
|
||||
long daysFromYearStart = ChronoUnit.DAYS.between(academicYear.getStartDate(), date);
|
||||
int expectedWeek = Math.toIntExact(daysFromYearStart / 7 + 1);
|
||||
int daysBeforeYearStartInFirstWeek = academicYear.getStartDate().getDayOfWeek().getValue() - 1;
|
||||
int expectedWeek = Math.toIntExact((daysBeforeYearStartInFirstWeek + daysFromYearStart) / 7 + 1);
|
||||
if (weekNumber != expectedWeek) {
|
||||
throw new IllegalArgumentException("Номер недели не соответствует дате учебного года");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
-- Недели календарного учебного графика выровнены по ISO-неделе:
|
||||
-- понедельник — первый день, воскресенье — последний.
|
||||
UPDATE academic_calendar_days AS calendar_day
|
||||
SET week_number = (
|
||||
(
|
||||
calendar_day.date
|
||||
- academic_year.start_date
|
||||
+ EXTRACT(ISODOW FROM academic_year.start_date)::INTEGER
|
||||
- 1
|
||||
) / 7
|
||||
) + 1
|
||||
FROM academic_calendars AS calendar
|
||||
JOIN academic_years AS academic_year
|
||||
ON academic_year.id = calendar.academic_year_id
|
||||
WHERE calendar_day.calendar_id = calendar.id
|
||||
AND calendar_day.week_number IS DISTINCT FROM (
|
||||
(
|
||||
calendar_day.date
|
||||
- academic_year.start_date
|
||||
+ EXTRACT(ISODOW FROM academic_year.start_date)::INTEGER
|
||||
- 1
|
||||
) / 7
|
||||
) + 1;
|
||||
Reference in New Issue
Block a user