Изменил логику в группах, вместо семестра теперь пишется год начала обучения, чтобы курс и семестр считались на бэке

This commit is contained in:
ProstoDenya01
2026-03-31 16:44:05 +03:00
parent 73995f86f8
commit 3cdb8614cb
14 changed files with 206 additions and 118 deletions

View File

@@ -6,12 +6,14 @@ import com.magistr.app.model.EducationForm;
import com.magistr.app.model.StudentGroup; import com.magistr.app.model.StudentGroup;
import com.magistr.app.repository.EducationFormRepository; import com.magistr.app.repository.EducationFormRepository;
import com.magistr.app.repository.GroupRepository; import com.magistr.app.repository.GroupRepository;
import com.magistr.app.utils.CourseAndSemesterCalculator;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.time.Year;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
@@ -39,16 +41,21 @@ public class GroupController {
List<StudentGroup> groups = groupRepository.findAll(); List<StudentGroup> groups = groupRepository.findAll();
List<GroupResponse> response = groups.stream() List<GroupResponse> response = groups.stream()
.map(g -> new GroupResponse( .map(g -> {
int course = CourseAndSemesterCalculator.getActualCourse(g.getYearStartStudy());
int semester = CourseAndSemesterCalculator.getActualSemester(g.getYearStartStudy());
return new GroupResponse(
g.getId(), g.getId(),
g.getName(), g.getName(),
g.getGroupSize(), g.getGroupSize(),
g.getEducationForm().getId(), g.getEducationForm().getId(),
g.getEducationForm().getName(), g.getEducationForm().getName(),
g.getDepartmentId(), g.getDepartmentId(),
g.getCourse(), course,
semester,
g.getSpecialityCode() g.getSpecialityCode()
)) );
})
.toList(); .toList();
logger.info("Получено {} групп", response.size()); logger.info("Получено {} групп", response.size());
return response; return response;
@@ -70,9 +77,27 @@ public class GroupController {
.body("Группы для указанной кафедры не найдены"); .body("Группы для указанной кафедры не найдены");
} }
logger.info("Найдено {} групп для кафедры с ID - {}", groups.size(), departmentId); List<GroupResponse> response = groups.stream()
.map(g -> {
int course = CourseAndSemesterCalculator.getActualCourse(g.getYearStartStudy());
int semester = CourseAndSemesterCalculator.getActualSemester(g.getYearStartStudy());
return new GroupResponse(
g.getId(),
g.getName(),
g.getGroupSize(),
g.getEducationForm().getId(),
g.getEducationForm().getName(),
g.getDepartmentId(),
course,
semester,
g.getSpecialityCode()
);
})
.toList();
return ResponseEntity.ok(groups); logger.info("Найдено {} групп для кафедры с ID - {}", response.size(), departmentId);
return ResponseEntity.ok(response);
} catch (Exception e) { } catch (Exception e) {
logger.error("Получена ошибка при получении списка групп для кафедры с ID - {}: {}", departmentId, e.getMessage()); logger.error("Получена ошибка при получении списка групп для кафедры с ID - {}: {}", departmentId, e.getMessage());
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
@@ -82,8 +107,8 @@ public class GroupController {
@PostMapping @PostMapping
public ResponseEntity<?> createGroup(@RequestBody CreateGroupRequest request) { public ResponseEntity<?> createGroup(@RequestBody CreateGroupRequest request) {
logger.info("Получен запрос на создание новой группы: name = {}, groupSize = {}, educationFormId = {}, departmentId = {}, course = {}", logger.info("Получен запрос на создание новой группы: name = {}, groupSize = {}, educationFormId = {}, departmentId = {}, yearStartStudy = {}",
request.getName(), request.getGroupSize(), request.getEducationFormId(), request.getDepartmentId(), request.getCourse()); request.getName(), request.getGroupSize(), request.getEducationFormId(), request.getDepartmentId(), request.getYearStartStudy());
try { try {
if (request.getName() == null || request.getName().isBlank()) { if (request.getName() == null || request.getName().isBlank()) {
String errorMessage = "Название группы обязательно"; String errorMessage = "Название группы обязательно";
@@ -110,8 +135,13 @@ public class GroupController {
logger.error("Ошибка валидации: {}", errorMessage); logger.error("Ошибка валидации: {}", errorMessage);
return ResponseEntity.badRequest().body(Map.of("message", errorMessage)); return ResponseEntity.badRequest().body(Map.of("message", errorMessage));
} }
if (request.getCourse() == null || request.getCourse() == 0) { // if (request.getCourse() == null || request.getCourse() == 0) {
String errorMessage = "Курс обязателен"; // String errorMessage = "Курс обязателен";
// logger.error("Ошибка валидации: {}", errorMessage);
// return ResponseEntity.badRequest().body(Map.of("message", errorMessage));
// }
if (request.getYearStartStudy() == null || request.getYearStartStudy() == 0) {
String errorMessage = "Год начала обучения обязателен";
logger.error("Ошибка валидации: {}", errorMessage); logger.error("Ошибка валидации: {}", errorMessage);
return ResponseEntity.badRequest().body(Map.of("message", errorMessage)); return ResponseEntity.badRequest().body(Map.of("message", errorMessage));
} }
@@ -131,7 +161,7 @@ public class GroupController {
group.setGroupSize(request.getGroupSize()); group.setGroupSize(request.getGroupSize());
group.setEducationForm(efOpt.get()); group.setEducationForm(efOpt.get());
group.setDepartmentId(request.getDepartmentId()); group.setDepartmentId(request.getDepartmentId());
group.setCourse(request.getCourse()); group.setYearStartStudy(request.getYearStartStudy());
group.setSpecialityCode(request.getSpecialityCode()); group.setSpecialityCode(request.getSpecialityCode());
groupRepository.save(group); groupRepository.save(group);
@@ -144,7 +174,7 @@ public class GroupController {
group.getEducationForm().getId(), group.getEducationForm().getId(),
group.getEducationForm().getName(), group.getEducationForm().getName(),
group.getDepartmentId(), group.getDepartmentId(),
group.getCourse(), group.getYearStartStudy(),
group.getSpecialityCode())); group.getSpecialityCode()));
} catch (Exception e ) { } catch (Exception e ) {
logger.error("Ошибка при создании группы: {}", e.getMessage(), e); logger.error("Ошибка при создании группы: {}", e.getMessage(), e);

View File

@@ -4,6 +4,7 @@ import com.magistr.app.dto.CreateScheduleDataRequest;
import com.magistr.app.dto.ScheduleResponse; import com.magistr.app.dto.ScheduleResponse;
import com.magistr.app.model.*; import com.magistr.app.model.*;
import com.magistr.app.repository.*; import com.magistr.app.repository.*;
import com.magistr.app.utils.CourseAndSemesterCalculator;
import com.magistr.app.utils.SemesterTypeValidator; import com.magistr.app.utils.SemesterTypeValidator;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@@ -47,7 +48,6 @@ public class ScheduleDataController {
.map(s -> new ScheduleData( .map(s -> new ScheduleData(
s.getId(), s.getId(),
s.getDepartmentId(), s.getDepartmentId(),
s.getSemester(),
s.getGroupId(), s.getGroupId(),
s.getSubjectsId(), s.getSubjectsId(),
s.getLessonTypeId(), s.getLessonTypeId(),
@@ -90,12 +90,20 @@ public class ScheduleDataController {
.map(StudentGroup::getName) .map(StudentGroup::getName)
.orElse("Неизвестно"); .orElse("Неизвестно");
Integer groupCourse = groupRepository.findById(s.getGroupId()) int groupSemester = 0;
.map(StudentGroup::getCourse) int groupCourse = 0;
.orElse(null);
String specialityCode = "Неизвестно"; String specialityCode = "Неизвестно";
StudentGroup group = groupRepository.findById(s.getGroupId()).orElse(null); StudentGroup group = groupRepository.findById(s.getGroupId()).orElse(null);
if (group != null) {
groupCourse = CourseAndSemesterCalculator.getFutureCourse(group.getYearStartStudy(), period);
}
if (group != null) {
groupSemester = CourseAndSemesterCalculator.getFutureSemester(group.getYearStartStudy(), period, semesterType);
}
if (group != null) { if (group != null) {
Long specialityId = group.getSpecialityCode(); Long specialityId = group.getSpecialityCode();
specialityCode = specialtiesRepository.findById(specialityId). specialityCode = specialtiesRepository.findById(specialityId).
@@ -123,9 +131,9 @@ public class ScheduleDataController {
s.getId(), s.getId(),
s.getDepartmentId(), s.getDepartmentId(),
specialityCode, specialityCode,
s.getSemester(),
groupName, groupName,
groupCourse, groupCourse,
groupSemester,
subjectName, subjectName,
lessonType, lessonType,
s.getNumberOfHours(), s.getNumberOfHours(),
@@ -148,8 +156,8 @@ public class ScheduleDataController {
// Доделать проверки получаемых полей!!! // Доделать проверки получаемых полей!!!
@PostMapping("/create") @PostMapping("/create")
public ResponseEntity<?> createScheduleData(@RequestBody CreateScheduleDataRequest request) { public ResponseEntity<?> createScheduleData(@RequestBody CreateScheduleDataRequest request) {
logger.info("Получен запрос на создание записи данных для расписаний: departmentId={}, semester={}, groupId={}, subjectsId={}, lessonTypeId={}, numberOfHours={}, division={}, teacherId={}, semesterType={}, period={}", logger.info("Получен запрос на создание записи данных для расписаний: departmentId={}, groupId={}, subjectsId={}, lessonTypeId={}, numberOfHours={}, division={}, teacherId={}, semesterType={}, period={}",
request.getDepartmentId(), request.getSemester(), request.getGroupId(), request.getSubjectsId(), request.getLessonTypeId(), request.getNumberOfHours(), request.getDivision(), request.getTeacherId(), request.getSemesterType(), request.getPeriod()); request.getDepartmentId(), request.getGroupId(), request.getSubjectsId(), request.getLessonTypeId(), request.getNumberOfHours(), request.getDivision(), request.getTeacherId(), request.getSemesterType(), request.getPeriod());
try { try {
if (request.getDepartmentId() == null || request.getDepartmentId() == 0) { if (request.getDepartmentId() == null || request.getDepartmentId() == 0) {
String errorMessage = "ID кафедры обязателен"; String errorMessage = "ID кафедры обязателен";
@@ -161,16 +169,6 @@ public class ScheduleDataController {
return ResponseEntity.badRequest().body(Map.of("message", errorMessage)); return ResponseEntity.badRequest().body(Map.of("message", errorMessage));
} }
if (request.getSemester() == null || request.getSemester() == 0) {
String errorMessage = "Семестр обязателен";
logger.info("Ошибка валидации: {}", errorMessage);
return ResponseEntity.badRequest().body(Map.of("message", errorMessage));
} else if(request.getSemester() > 12) {
String errorMessage = "Семестр должен быть меньше или равен 12";
logger.info("Семестр должен быть меньше или равен 12");
return ResponseEntity.badRequest().body(Map.of("message", errorMessage));
}
if (request.getGroupId() == null || request.getGroupId() == 0) { if (request.getGroupId() == null || request.getGroupId() == 0) {
String errorMessage = "ID группы обязателен"; String errorMessage = "ID группы обязателен";
logger.info("Ошибка валидации: {}", errorMessage); logger.info("Ошибка валидации: {}", errorMessage);
@@ -215,9 +213,8 @@ public class ScheduleDataController {
return ResponseEntity.badRequest().body(Map.of("message", errorMessage)); return ResponseEntity.badRequest().body(Map.of("message", errorMessage));
} }
boolean existsRecord = scheduleDataRepository.existsByDepartmentIdAndSemesterAndGroupIdAndSubjectsIdAndLessonTypeIdAndNumberOfHoursAndDivisionAndTeacherIdAndSemesterTypeAndPeriod( boolean existsRecord = scheduleDataRepository.existsByDepartmentIdAndGroupIdAndSubjectsIdAndLessonTypeIdAndNumberOfHoursAndDivisionAndTeacherIdAndSemesterTypeAndPeriod(
request.getDepartmentId(), request.getDepartmentId(),
request.getSemester(),
request.getGroupId(), request.getGroupId(),
request.getSubjectsId(), request.getSubjectsId(),
request.getLessonTypeId(), request.getLessonTypeId(),
@@ -235,7 +232,6 @@ public class ScheduleDataController {
ScheduleData scheduleData = new ScheduleData(); ScheduleData scheduleData = new ScheduleData();
scheduleData.setDepartmentId(request.getDepartmentId()); scheduleData.setDepartmentId(request.getDepartmentId());
scheduleData.setSemester(request.getSemester());
scheduleData.setGroupId(request.getGroupId()); scheduleData.setGroupId(request.getGroupId());
scheduleData.setSubjectsId(request.getSubjectsId()); scheduleData.setSubjectsId(request.getSubjectsId());
scheduleData.setLessonTypeId(request.getLessonTypeId()); scheduleData.setLessonTypeId(request.getLessonTypeId());
@@ -250,7 +246,6 @@ public class ScheduleDataController {
Map<String, Object> response = new LinkedHashMap<>(); Map<String, Object> response = new LinkedHashMap<>();
response.put("id", savedSchedule.getId()); response.put("id", savedSchedule.getId());
response.put("departmentId", savedSchedule.getDepartmentId()); response.put("departmentId", savedSchedule.getDepartmentId());
response.put("semester", savedSchedule.getSemester());
response.put("groupId", savedSchedule.getGroupId()); response.put("groupId", savedSchedule.getGroupId());
response.put("subjectId", savedSchedule.getSubjectsId()); response.put("subjectId", savedSchedule.getSubjectsId());
response.put("lessonTypeId", savedSchedule.getLessonTypeId()); response.put("lessonTypeId", savedSchedule.getLessonTypeId());

View File

@@ -6,7 +6,7 @@ public class CreateGroupRequest {
private Long groupSize; private Long groupSize;
private Long educationFormId; private Long educationFormId;
private Long departmentId; private Long departmentId;
private Integer course; private Integer yearStartStudy;
private Long specialityCode; private Long specialityCode;
public String getName() { public String getName() {
@@ -41,12 +41,12 @@ public class CreateGroupRequest {
this.departmentId = departmentId; this.departmentId = departmentId;
} }
public Integer getCourse() { public Integer getYearStartStudy() {
return course; return yearStartStudy;
} }
public void setCourse(Integer course) { public void setYearStartStudy(Integer yearStartStudy) {
this.course = course; this.yearStartStudy = yearStartStudy;
} }
public Long getSpecialityCode() { public Long getSpecialityCode() {

View File

@@ -5,7 +5,6 @@ import com.magistr.app.model.SemesterType;
public class CreateScheduleDataRequest { public class CreateScheduleDataRequest {
private Long id; private Long id;
private Long departmentId; private Long departmentId;
private Long semester;
private Long groupId; private Long groupId;
private Long subjectsId; private Long subjectsId;
private Long lessonTypeId; private Long lessonTypeId;
@@ -31,14 +30,6 @@ public class CreateScheduleDataRequest {
this.departmentId = departmentId; this.departmentId = departmentId;
} }
public Long getSemester() {
return semester;
}
public void setSemester(Long semester) {
this.semester = semester;
}
public Long getGroupId() { public Long getGroupId() {
return groupId; return groupId;
} }

View File

@@ -1,5 +1,8 @@
package com.magistr.app.dto; package com.magistr.app.dto;
import com.fasterxml.jackson.annotation.JsonInclude;
@JsonInclude(JsonInclude.Include.NON_NULL)
public class GroupResponse { public class GroupResponse {
private Long id; private Long id;
@@ -8,10 +11,12 @@ public class GroupResponse {
private Long educationFormId; private Long educationFormId;
private String educationFormName; private String educationFormName;
private Long departmentId; private Long departmentId;
private Integer yearStartStudy;
private Integer course; private Integer course;
private Integer semester;
private Long specialityCode; private Long specialityCode;
public GroupResponse(Long id, String name, Long groupSize, Long educationFormId, String educationFormName, Long departmentId, Integer course, Long specialityCode) { public GroupResponse(Long id, String name, Long groupSize, Long educationFormId, String educationFormName, Long departmentId, Integer course, Integer semester, Long specialityCode) {
this.id = id; this.id = id;
this.name = name; this.name = name;
this.groupSize = groupSize; this.groupSize = groupSize;
@@ -19,6 +24,18 @@ public class GroupResponse {
this.educationFormName = educationFormName; this.educationFormName = educationFormName;
this.departmentId = departmentId; this.departmentId = departmentId;
this.course = course; this.course = course;
this.semester = semester;
this.specialityCode = specialityCode;
}
public GroupResponse(Long id, String name, Long groupSize, Long educationFormId, String educationFormName, Long departmentId, Integer yearStartStudy, Long specialityCode) {
this.id = id;
this.name = name;
this.groupSize = groupSize;
this.educationFormId = educationFormId;
this.educationFormName = educationFormName;
this.departmentId = departmentId;
this.yearStartStudy = yearStartStudy;
this.specialityCode = specialityCode; this.specialityCode = specialityCode;
} }
@@ -50,6 +67,14 @@ public class GroupResponse {
return course; return course;
} }
public Integer getSemester() {
return semester;
}
public Integer getYearStartStudy() {
return yearStartStudy;
}
public Long getSpecialityCode() { public Long getSpecialityCode() {
return specialityCode; return specialityCode;
} }

View File

@@ -8,10 +8,10 @@ public class ScheduleResponse {
private Long id; private Long id;
private String specialityCode; private String specialityCode;
private Long departmentId; private Long departmentId;
private Long semester;
private Long groupId; private Long groupId;
private String groupName; private String groupName;
private Integer groupCourse; private Integer groupCourse;
private Integer groupSemester;
private Long subjectsId; private Long subjectsId;
private String subjectName; private String subjectName;
private Long lessonTypeId; private Long lessonTypeId;
@@ -24,10 +24,9 @@ public class ScheduleResponse {
private SemesterType semesterType; private SemesterType semesterType;
private String period; private String period;
public ScheduleResponse(Long id, Long departmentId, Long semester, Long groupId, Long subjectsId, Long lessonTypeId, String lessonType, Long numberOfHours, Boolean division, Long teacherId, SemesterType semesterType, String period) { public ScheduleResponse(Long id, Long departmentId, Long groupId, Long subjectsId, Long lessonTypeId, String lessonType, Long numberOfHours, Boolean division, Long teacherId, SemesterType semesterType, String period) {
this.id = id; this.id = id;
this.departmentId = departmentId; this.departmentId = departmentId;
this.semester = semester;
this.groupId = groupId; this.groupId = groupId;
this.subjectsId = subjectsId; this.subjectsId = subjectsId;
this.lessonTypeId = lessonTypeId; this.lessonTypeId = lessonTypeId;
@@ -38,13 +37,13 @@ public class ScheduleResponse {
this.period = period; this.period = period;
} }
public ScheduleResponse(Long id, Long departmentId, String specialityCode, Long semester, String groupName, Integer groupCourse, String subjectName, String lessonType, Long numberOfHours, Boolean division, String teacherName, String teacherJobTitle, SemesterType semesterType, String period) { public ScheduleResponse(Long id, Long departmentId, String specialityCode, String groupName, Integer groupCourse, Integer groupSemester, String subjectName, String lessonType, Long numberOfHours, Boolean division, String teacherName, String teacherJobTitle, SemesterType semesterType, String period) {
this.id = id; this.id = id;
this.departmentId = departmentId; this.departmentId = departmentId;
this.specialityCode = specialityCode; this.specialityCode = specialityCode;
this.semester = semester;
this.groupName = groupName; this.groupName = groupName;
this.groupCourse = groupCourse; this.groupCourse = groupCourse;
this.groupSemester = groupSemester;
this.subjectName = subjectName; this.subjectName = subjectName;
this.lessonType = lessonType; this.lessonType = lessonType;
this.numberOfHours = numberOfHours; this.numberOfHours = numberOfHours;
@@ -67,10 +66,6 @@ public class ScheduleResponse {
return departmentId; return departmentId;
} }
public Long getSemester() {
return semester;
}
public Long getGroupId() { public Long getGroupId() {
return groupId; return groupId;
} }
@@ -83,6 +78,10 @@ public class ScheduleResponse {
return groupCourse; return groupCourse;
} }
public Integer getGroupSemester() {
return groupSemester;
}
public Long getSubjectsId() { public Long getSubjectsId() {
return subjectsId; return subjectsId;
} }

View File

@@ -13,9 +13,6 @@ public class ScheduleData {
@Column(name="department_id", nullable = false) @Column(name="department_id", nullable = false)
private Long departmentId; private Long departmentId;
@Column(name="semester", nullable = false)
private Long semester;
@Column(name="group_id", nullable = false) @Column(name="group_id", nullable = false)
private Long groupId; private Long groupId;
@@ -43,10 +40,9 @@ public class ScheduleData {
public ScheduleData() {} public ScheduleData() {}
public ScheduleData(Long id, Long departmentId, Long semester, Long groupId, Long subjectsId, Long lessonTypeId, Long numberOfHours, Boolean division, Long teacherId, SemesterType semesterType, String period) { public ScheduleData(Long id, Long departmentId, Long groupId, Long subjectsId, Long lessonTypeId, Long numberOfHours, Boolean division, Long teacherId, SemesterType semesterType, String period) {
this.id = id; this.id = id;
this.departmentId = departmentId; this.departmentId = departmentId;
this.semester = semester;
this.groupId = groupId; this.groupId = groupId;
this.subjectsId = subjectsId; this.subjectsId = subjectsId;
this.lessonTypeId = lessonTypeId; this.lessonTypeId = lessonTypeId;
@@ -73,14 +69,6 @@ public class ScheduleData {
this.departmentId = departmentId; this.departmentId = departmentId;
} }
public Long getSemester() {
return semester;
}
public void setSemester(Long semester) {
this.semester = semester;
}
public Long getGroupId() { public Long getGroupId() {
return groupId; return groupId;
} }

View File

@@ -23,12 +23,12 @@ public class StudentGroup {
@Column(name = "department_id", nullable = false) @Column(name = "department_id", nullable = false)
private Long departmentId; private Long departmentId;
@Column(name = "course", nullable = false)
private Integer course;
@Column(name="specialty_code", nullable = false) @Column(name="specialty_code", nullable = false)
private Long specialityCode; private Long specialityCode;
@Column(name="year_start_study", nullable = false)
private Integer yearStartStudy;
public StudentGroup() { public StudentGroup() {
} }
@@ -72,14 +72,6 @@ public class StudentGroup {
this.departmentId = departmentId; this.departmentId = departmentId;
} }
public Integer getCourse() {
return course;
}
public void setCourse(Integer course) {
this.course = course;
}
public Long getSpecialityCode() { public Long getSpecialityCode() {
return specialityCode; return specialityCode;
} }
@@ -87,4 +79,12 @@ public class StudentGroup {
public void setSpecialityCode(Long specialityCode) { public void setSpecialityCode(Long specialityCode) {
this.specialityCode = specialityCode; this.specialityCode = specialityCode;
} }
public Integer getYearStartStudy() {
return yearStartStudy;
}
public void setYearStartStudy(Integer yearStartStudy) {
this.yearStartStudy = yearStartStudy;
}
} }

View File

@@ -10,9 +10,8 @@ public interface ScheduleDataRepository extends JpaRepository<ScheduleData, Long
List<ScheduleData> findByDepartmentIdAndSemesterTypeAndPeriod(Long departmentId, SemesterType semesterType, String period); List<ScheduleData> findByDepartmentIdAndSemesterTypeAndPeriod(Long departmentId, SemesterType semesterType, String period);
boolean existsByDepartmentIdAndSemesterAndGroupIdAndSubjectsIdAndLessonTypeIdAndNumberOfHoursAndDivisionAndTeacherIdAndSemesterTypeAndPeriod( boolean existsByDepartmentIdAndGroupIdAndSubjectsIdAndLessonTypeIdAndNumberOfHoursAndDivisionAndTeacherIdAndSemesterTypeAndPeriod(
Long departmentId, Long departmentId,
Long semester,
Long groupId, Long groupId,
Long subjectsId, Long subjectsId,
Long lessonTypeId, Long lessonTypeId,

View File

@@ -0,0 +1,49 @@
package com.magistr.app.utils;
import com.magistr.app.model.SemesterType;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
@Service
public class CourseAndSemesterCalculator {
public static int getActualCourse(Integer yearStartStudy) {
LocalDate now = LocalDate.now();
int currentYear = now.getYear();
int currentMonth = now.getMonthValue();
if (currentMonth >= 9) {
return currentYear - yearStartStudy + 1;
} else {
return currentYear - yearStartStudy;
}
}
public static int getActualSemester(Integer yearStartStudy) {
int course = getActualCourse(yearStartStudy);
int currentMonth = LocalDate.now().getMonthValue();
if ( currentMonth <= 1 || currentMonth >= 9) {
return course * 2 - 1;
} else {
return course * 2;
}
}
public static int getFutureCourse(Integer yearStartStudy, String periodYears) {
int recordYear = Integer.parseInt(periodYears.substring(0, 4));
return recordYear - yearStartStudy + 1;
}
public static int getFutureSemester(Integer yearStartStudy, String periodYears, SemesterType semesterType) {
int course = getFutureCourse(yearStartStudy, periodYears);
if (semesterType == SemesterType.autumn) {
return course * 2 - 1;
} else if (semesterType == SemesterType.spring) {
return course * 2;
}
throw new IllegalArgumentException("Неизвестный semesterType: " + semesterType);
}
}

View File

@@ -3,27 +3,39 @@
-- ========================================== -- ==========================================
ALTER TABLE student_groups ALTER TABLE student_groups
ADD COLUMN IF NOT EXISTS specialty_code INT REFERENCES specialties(id); ADD COLUMN IF NOT EXISTS specialty_code INT REFERENCES specialties(id),
ADD COLUMN IF NOT EXISTS year_start_study INT,
DROP COLUMN IF EXISTS course;
UPDATE student_groups UPDATE student_groups
SET specialty_code = 1 SET specialty_code = 1
WHERE specialty_code IS NULL; WHERE specialty_code IS NULL;
UPDATE student_groups
SET year_start_study = 2023
WHERE year_start_study IS NULL;
ALTER TABLE student_groups ALTER TABLE student_groups
ALTER COLUMN specialty_code SET NOT NULL; ALTER COLUMN specialty_code SET NOT NULL;
ALTER TABLE student_groups
ALTER COLUMN year_start_study SET NOT NULL;
-- ========================================== -- ==========================================
-- Редактирование данных для расписания -- Редактирование кафедрального файла
-- ========================================== -- ==========================================
INSERT INTO schedule_data (department_id, semester, group_id, subjects_id, lesson_type_id, number_of_hours, is_division, teacher_id, semester_type, period) ALTER TABLE schedule_data
VALUES (1, 1, 1, 1, 3, 2, true, 1, 'autumn', '2024-2025'), DROP COLUMN IF EXISTS semester;
(2, 4, 2, 3, 2, 1, false, 2, 'spring', '2025-2026'),
(3, 5, 1, 2, 1, 3, true, 1, 'autumn', '2023-2024'), INSERT INTO schedule_data (department_id, group_id, subjects_id, lesson_type_id, number_of_hours, is_division, teacher_id, semester_type, period)
(2, 4, 2, 3, 2, 1, false, 2, 'spring', '2025-2026'), VALUES (1, 1, 1, 3, 2, true, 1, 'autumn', '2024-2025'),
(2, 4, 2, 3, 2, 1, false, 2, 'spring', '2025-2026'), (2, 2, 3, 2, 1, false, 2, 'spring', '2025-2026'),
(2, 4, 2, 3, 2, 1, false, 2, 'spring', '2025-2026'), (3, 1, 2, 1, 3, true, 1, 'autumn', '2023-2024'),
(1, 1, 1, 1, 1, 2, true, 2, 'autumn', '2024-2025'), (2, 2, 3, 2, 1, false, 2, 'spring', '2025-2026'),
(1, 2, 2, 2, 3, 4, false, 2, 'autumn', '2024-2025'), (2, 2, 3, 2, 1, false, 2, 'spring', '2025-2026'),
(1, 3, 1, 4, 2, 1, false, 1, 'autumn', '2024-2025'), (2, 2, 3, 2, 1, false, 2, 'spring', '2025-2026'),
(1, 4, 2, 5, 1, 7, true, 1, 'autumn', '2024-2025'); (1, 1, 1, 1, 2, true, 2, 'autumn', '2024-2025'),
(1, 2, 2, 3, 4, false, 2, 'autumn', '2024-2025'),
(1, 1, 4, 2, 1, false, 1, 'autumn', '2024-2025'),
(1, 2, 5, 1, 7, true, 1, 'autumn', '2024-2025');

View File

@@ -46,7 +46,7 @@ export async function initDepartment() {
} }
}); });
function renderScheduleBlock(deptName, semester, period, schedule) { function renderScheduleBlock(deptName, groupSemester, period, schedule) {
const details = document.createElement('details'); const details = document.createElement('details');
details.className = 'table-item'; details.className = 'table-item';
details.open = true; details.open = true;
@@ -61,7 +61,7 @@ export async function initDepartment() {
<div class="title title-multiline"> <div class="title title-multiline">
<span class="title-main">Данные к составлению расписания</span> <span class="title-main">Данные к составлению расписания</span>
<span class="title-sub">Кафедра: <b>${escapeHtml(deptName)}</b></span> <span class="title-sub">Кафедра: <b>${escapeHtml(deptName)}</b></span>
<span class="title-sub">Семестр: <b>${escapeHtml(semester)}</b></span> <span class="title-sub">Семестр: <b>${escapeHtml(groupSemester)}</b></span>
<span class="title-sub">Уч. год: <b>${escapeHtml(period)}</b></span> <span class="title-sub">Уч. год: <b>${escapeHtml(period)}</b></span>
</div> </div>
<div class="meta">${schedule ? schedule.length : 0} записей</div> <div class="meta">${schedule ? schedule.length : 0} записей</div>
@@ -98,9 +98,9 @@ export async function initDepartment() {
<td>${escapeHtml(r.specialityCode || '-')}</td> <td>${escapeHtml(r.specialityCode || '-')}</td>
<td>${(() => { <td>${(() => {
const course = r.groupCourse || '-'; const course = r.groupCourse || '-';
const semester = r.semester || '-'; const groupSemester = r.groupSemester || '-';
if (course === '-' && semester === '-') return '-'; if (course === '-' && groupSemester === '-') return '-';
return `${course} | ${semester}`; return `${course} | ${groupSemester}`;
})()}</td> })()}</td>
<td>${escapeHtml(r.groupName || '-')}</td> <td>${escapeHtml(r.groupName || '-')}</td>
<td>${escapeHtml(r.subjectName || '-')}</td> <td>${escapeHtml(r.subjectName || '-')}</td>
@@ -237,7 +237,7 @@ export async function initDepartment() {
<tr${rowStyle}> <tr${rowStyle}>
<td>${escapeHtml(periodDisplay)}</td> <td>${escapeHtml(periodDisplay)}</td>
<td>${escapeHtml(semLabel)}</td> <td>${escapeHtml(semLabel)}</td>
<td>${s.semester}</td> <td>${s.groupSemester}</td>
<td>${escapeHtml(String(groupName))}</td> <td>${escapeHtml(String(groupName))}</td>
<td>${escapeHtml(String(subjectName))}</td> <td>${escapeHtml(String(subjectName))}</td>
<td>${escapeHtml(lessonTypeName)}</td> <td>${escapeHtml(lessonTypeName)}</td>
@@ -283,7 +283,7 @@ export async function initDepartment() {
const depId = csDepartmentIdInput.value; const depId = csDepartmentIdInput.value;
const period = document.getElementById('cs-period').value; const period = document.getElementById('cs-period').value;
const semesterType = document.querySelector('input[name="csSemesterType"]:checked')?.value; const semesterType = document.querySelector('input[name="csSemesterType"]:checked')?.value;
const semester = document.getElementById('cs-semester').value; const groupSemester = document.getElementById('cs-semester').value;
const groupId = csGroupSelect.value; const groupId = csGroupSelect.value;
const subjectId = csSubjectSelect.value; const subjectId = csSubjectSelect.value;
const lessonTypeId = document.getElementById('cs-lesson-type').value; const lessonTypeId = document.getElementById('cs-lesson-type').value;
@@ -291,14 +291,14 @@ export async function initDepartment() {
const division = document.getElementById('cs-division').checked; const division = document.getElementById('cs-division').checked;
const teacherId = csTeacherSelect.value; const teacherId = csTeacherSelect.value;
if (!period || !semesterType || !semester || !groupId || !subjectId || !lessonTypeId || !hours || !teacherId) { if (!period || !semesterType || !groupId || !subjectId || !lessonTypeId || !hours || !teacherId) {
showAlert('create-schedule-alert', 'Заполните все обязательные поля', 'error'); showAlert('create-schedule-alert', 'Заполните все обязательные поля', 'error');
return; return;
} }
const newRecord = { const newRecord = {
departmentId: Number(depId), departmentId: Number(depId),
semester: Number(semester), groupSemester: Number(groupSemester),
groupId: Number(groupId), groupId: Number(groupId),
subjectsId: Number(subjectId), subjectsId: Number(subjectId),
lessonTypeId: Number(lessonTypeId), lessonTypeId: Number(lessonTypeId),
@@ -313,7 +313,7 @@ export async function initDepartment() {
const isDuplicate = preparedSchedules.some(s => const isDuplicate = preparedSchedules.some(s =>
s.period === newRecord.period && s.period === newRecord.period &&
s.semesterType === newRecord.semesterType && s.semesterType === newRecord.semesterType &&
s.semester === newRecord.semester && s.groupSemester === newRecord.groupSemester &&
s.groupId === newRecord.groupId && s.groupId === newRecord.groupId &&
s.subjectsId === newRecord.subjectsId && s.subjectsId === newRecord.subjectsId &&
s.lessonTypeId === newRecord.lessonTypeId && s.lessonTypeId === newRecord.lessonTypeId &&

View File

@@ -83,13 +83,13 @@ export async function initGroups() {
const groupSize = document.getElementById('new-group-size').value; const groupSize = document.getElementById('new-group-size').value;
const educationFormId = newGroupEfSelect.value; const educationFormId = newGroupEfSelect.value;
const departmentId = document.getElementById('new-group-department').value; const departmentId = document.getElementById('new-group-department').value;
const course = document.getElementById('new-group-course').value; const yearStartStudy = document.getElementById('new-group-yearStartStudy').value;
if (!name) { showAlert('create-group-alert', 'Введите название группы', 'error'); return; } if (!name) { showAlert('create-group-alert', 'Введите название группы', 'error'); return; }
if (!groupSize) { showAlert('create-group-alert', 'Введите размер группы', 'error'); return; } if (!groupSize) { showAlert('create-group-alert', 'Введите размер группы', 'error'); return; }
if (!educationFormId) { showAlert('create-group-alert', 'Выберите форму обучения', 'error'); return; } if (!educationFormId) { showAlert('create-group-alert', 'Выберите форму обучения', 'error'); return; }
if (!departmentId) { showAlert('create-group-alert', 'Введите ID кафедры', 'error'); return; } if (!departmentId) { showAlert('create-group-alert', 'Введите ID кафедры', 'error'); return; }
if (!course) { showAlert('create-group-alert', 'Введите курс', 'error'); return; } if (!yearStartStudy) { showAlert('create-group-alert', 'Введите курс', 'error'); return; }
try { try {
const data = await api.post('/api/groups', { const data = await api.post('/api/groups', {
@@ -97,7 +97,7 @@ export async function initGroups() {
groupSize: Number(groupSize), groupSize: Number(groupSize),
educationFormId: Number(educationFormId), educationFormId: Number(educationFormId),
departmentId: Number(departmentId), departmentId: Number(departmentId),
course: Number(course) yearStartStudy: Number(yearStartStudy)
}); });
showAlert('create-group-alert', `Группа "${escapeHtml(data.name || name)}" создана`, 'success'); showAlert('create-group-alert', `Группа "${escapeHtml(data.name || name)}" создана`, 'success');
createGroupForm.reset(); createGroupForm.reset();

View File

@@ -22,8 +22,8 @@
<input type="number" id="new-group-department" placeholder="ID" required> <input type="number" id="new-group-department" placeholder="ID" required>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="new-group-course">Курс</label> <label for="new-group-yearStartStudy">Год начала обучения</label>
<input type="number" id="new-group-course" placeholder="1-6" min="1" max="6" required> <input type="number" id="new-group-yearStartStudy" required pattern="^20\d{2}$" maxlength="3" placeholder="2026">
</div> </div>
<button type="submit" class="btn-primary">Создать</button> <button type="submit" class="btn-primary">Создать</button>
</div> </div>