Изменил логику в группах, вместо семестра теперь пишется год начала обучения, чтобы курс и семестр считались на бэке
This commit is contained in:
@@ -6,12 +6,14 @@ import com.magistr.app.model.EducationForm;
|
||||
import com.magistr.app.model.StudentGroup;
|
||||
import com.magistr.app.repository.EducationFormRepository;
|
||||
import com.magistr.app.repository.GroupRepository;
|
||||
import com.magistr.app.utils.CourseAndSemesterCalculator;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.time.Year;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
@@ -39,16 +41,21 @@ public class GroupController {
|
||||
List<StudentGroup> groups = groupRepository.findAll();
|
||||
|
||||
List<GroupResponse> response = groups.stream()
|
||||
.map(g -> new GroupResponse(
|
||||
g.getId(),
|
||||
g.getName(),
|
||||
g.getGroupSize(),
|
||||
g.getEducationForm().getId(),
|
||||
g.getEducationForm().getName(),
|
||||
g.getDepartmentId(),
|
||||
g.getCourse(),
|
||||
g.getSpecialityCode()
|
||||
))
|
||||
.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();
|
||||
logger.info("Получено {} групп", response.size());
|
||||
return response;
|
||||
@@ -70,9 +77,27 @@ public class GroupController {
|
||||
.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) {
|
||||
logger.error("Получена ошибка при получении списка групп для кафедры с ID - {}: {}", departmentId, e.getMessage());
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
@@ -82,8 +107,8 @@ public class GroupController {
|
||||
|
||||
@PostMapping
|
||||
public ResponseEntity<?> createGroup(@RequestBody CreateGroupRequest request) {
|
||||
logger.info("Получен запрос на создание новой группы: name = {}, groupSize = {}, educationFormId = {}, departmentId = {}, course = {}",
|
||||
request.getName(), request.getGroupSize(), request.getEducationFormId(), request.getDepartmentId(), request.getCourse());
|
||||
logger.info("Получен запрос на создание новой группы: name = {}, groupSize = {}, educationFormId = {}, departmentId = {}, yearStartStudy = {}",
|
||||
request.getName(), request.getGroupSize(), request.getEducationFormId(), request.getDepartmentId(), request.getYearStartStudy());
|
||||
try {
|
||||
if (request.getName() == null || request.getName().isBlank()) {
|
||||
String errorMessage = "Название группы обязательно";
|
||||
@@ -110,8 +135,13 @@ public class GroupController {
|
||||
logger.error("Ошибка валидации: {}", errorMessage);
|
||||
return ResponseEntity.badRequest().body(Map.of("message", errorMessage));
|
||||
}
|
||||
if (request.getCourse() == null || request.getCourse() == 0) {
|
||||
String errorMessage = "Курс обязателен";
|
||||
// if (request.getCourse() == null || request.getCourse() == 0) {
|
||||
// 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);
|
||||
return ResponseEntity.badRequest().body(Map.of("message", errorMessage));
|
||||
}
|
||||
@@ -131,7 +161,7 @@ public class GroupController {
|
||||
group.setGroupSize(request.getGroupSize());
|
||||
group.setEducationForm(efOpt.get());
|
||||
group.setDepartmentId(request.getDepartmentId());
|
||||
group.setCourse(request.getCourse());
|
||||
group.setYearStartStudy(request.getYearStartStudy());
|
||||
group.setSpecialityCode(request.getSpecialityCode());
|
||||
groupRepository.save(group);
|
||||
|
||||
@@ -144,7 +174,7 @@ public class GroupController {
|
||||
group.getEducationForm().getId(),
|
||||
group.getEducationForm().getName(),
|
||||
group.getDepartmentId(),
|
||||
group.getCourse(),
|
||||
group.getYearStartStudy(),
|
||||
group.getSpecialityCode()));
|
||||
} catch (Exception e ) {
|
||||
logger.error("Ошибка при создании группы: {}", e.getMessage(), e);
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.magistr.app.dto.CreateScheduleDataRequest;
|
||||
import com.magistr.app.dto.ScheduleResponse;
|
||||
import com.magistr.app.model.*;
|
||||
import com.magistr.app.repository.*;
|
||||
import com.magistr.app.utils.CourseAndSemesterCalculator;
|
||||
import com.magistr.app.utils.SemesterTypeValidator;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -47,7 +48,6 @@ public class ScheduleDataController {
|
||||
.map(s -> new ScheduleData(
|
||||
s.getId(),
|
||||
s.getDepartmentId(),
|
||||
s.getSemester(),
|
||||
s.getGroupId(),
|
||||
s.getSubjectsId(),
|
||||
s.getLessonTypeId(),
|
||||
@@ -90,12 +90,20 @@ public class ScheduleDataController {
|
||||
.map(StudentGroup::getName)
|
||||
.orElse("Неизвестно");
|
||||
|
||||
Integer groupCourse = groupRepository.findById(s.getGroupId())
|
||||
.map(StudentGroup::getCourse)
|
||||
.orElse(null);
|
||||
|
||||
int groupSemester = 0;
|
||||
int groupCourse = 0;
|
||||
String specialityCode = "Неизвестно";
|
||||
|
||||
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) {
|
||||
Long specialityId = group.getSpecialityCode();
|
||||
specialityCode = specialtiesRepository.findById(specialityId).
|
||||
@@ -123,9 +131,9 @@ public class ScheduleDataController {
|
||||
s.getId(),
|
||||
s.getDepartmentId(),
|
||||
specialityCode,
|
||||
s.getSemester(),
|
||||
groupName,
|
||||
groupCourse,
|
||||
groupSemester,
|
||||
subjectName,
|
||||
lessonType,
|
||||
s.getNumberOfHours(),
|
||||
@@ -148,8 +156,8 @@ public class ScheduleDataController {
|
||||
// Доделать проверки получаемых полей!!!
|
||||
@PostMapping("/create")
|
||||
public ResponseEntity<?> createScheduleData(@RequestBody CreateScheduleDataRequest request) {
|
||||
logger.info("Получен запрос на создание записи данных для расписаний: departmentId={}, semester={}, 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());
|
||||
logger.info("Получен запрос на создание записи данных для расписаний: departmentId={}, groupId={}, subjectsId={}, lessonTypeId={}, numberOfHours={}, division={}, teacherId={}, semesterType={}, period={}",
|
||||
request.getDepartmentId(), request.getGroupId(), request.getSubjectsId(), request.getLessonTypeId(), request.getNumberOfHours(), request.getDivision(), request.getTeacherId(), request.getSemesterType(), request.getPeriod());
|
||||
try {
|
||||
if (request.getDepartmentId() == null || request.getDepartmentId() == 0) {
|
||||
String errorMessage = "ID кафедры обязателен";
|
||||
@@ -161,16 +169,6 @@ public class ScheduleDataController {
|
||||
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) {
|
||||
String errorMessage = "ID группы обязателен";
|
||||
logger.info("Ошибка валидации: {}", errorMessage);
|
||||
@@ -215,9 +213,8 @@ public class ScheduleDataController {
|
||||
return ResponseEntity.badRequest().body(Map.of("message", errorMessage));
|
||||
}
|
||||
|
||||
boolean existsRecord = scheduleDataRepository.existsByDepartmentIdAndSemesterAndGroupIdAndSubjectsIdAndLessonTypeIdAndNumberOfHoursAndDivisionAndTeacherIdAndSemesterTypeAndPeriod(
|
||||
boolean existsRecord = scheduleDataRepository.existsByDepartmentIdAndGroupIdAndSubjectsIdAndLessonTypeIdAndNumberOfHoursAndDivisionAndTeacherIdAndSemesterTypeAndPeriod(
|
||||
request.getDepartmentId(),
|
||||
request.getSemester(),
|
||||
request.getGroupId(),
|
||||
request.getSubjectsId(),
|
||||
request.getLessonTypeId(),
|
||||
@@ -235,7 +232,6 @@ public class ScheduleDataController {
|
||||
|
||||
ScheduleData scheduleData = new ScheduleData();
|
||||
scheduleData.setDepartmentId(request.getDepartmentId());
|
||||
scheduleData.setSemester(request.getSemester());
|
||||
scheduleData.setGroupId(request.getGroupId());
|
||||
scheduleData.setSubjectsId(request.getSubjectsId());
|
||||
scheduleData.setLessonTypeId(request.getLessonTypeId());
|
||||
@@ -250,7 +246,6 @@ public class ScheduleDataController {
|
||||
Map<String, Object> response = new LinkedHashMap<>();
|
||||
response.put("id", savedSchedule.getId());
|
||||
response.put("departmentId", savedSchedule.getDepartmentId());
|
||||
response.put("semester", savedSchedule.getSemester());
|
||||
response.put("groupId", savedSchedule.getGroupId());
|
||||
response.put("subjectId", savedSchedule.getSubjectsId());
|
||||
response.put("lessonTypeId", savedSchedule.getLessonTypeId());
|
||||
|
||||
@@ -6,7 +6,7 @@ public class CreateGroupRequest {
|
||||
private Long groupSize;
|
||||
private Long educationFormId;
|
||||
private Long departmentId;
|
||||
private Integer course;
|
||||
private Integer yearStartStudy;
|
||||
private Long specialityCode;
|
||||
|
||||
public String getName() {
|
||||
@@ -41,12 +41,12 @@ public class CreateGroupRequest {
|
||||
this.departmentId = departmentId;
|
||||
}
|
||||
|
||||
public Integer getCourse() {
|
||||
return course;
|
||||
public Integer getYearStartStudy() {
|
||||
return yearStartStudy;
|
||||
}
|
||||
|
||||
public void setCourse(Integer course) {
|
||||
this.course = course;
|
||||
public void setYearStartStudy(Integer yearStartStudy) {
|
||||
this.yearStartStudy = yearStartStudy;
|
||||
}
|
||||
|
||||
public Long getSpecialityCode() {
|
||||
|
||||
@@ -5,7 +5,6 @@ import com.magistr.app.model.SemesterType;
|
||||
public class CreateScheduleDataRequest {
|
||||
private Long id;
|
||||
private Long departmentId;
|
||||
private Long semester;
|
||||
private Long groupId;
|
||||
private Long subjectsId;
|
||||
private Long lessonTypeId;
|
||||
@@ -31,14 +30,6 @@ public class CreateScheduleDataRequest {
|
||||
this.departmentId = departmentId;
|
||||
}
|
||||
|
||||
public Long getSemester() {
|
||||
return semester;
|
||||
}
|
||||
|
||||
public void setSemester(Long semester) {
|
||||
this.semester = semester;
|
||||
}
|
||||
|
||||
public Long getGroupId() {
|
||||
return groupId;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package com.magistr.app.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public class GroupResponse {
|
||||
|
||||
private Long id;
|
||||
@@ -8,10 +11,12 @@ public class GroupResponse {
|
||||
private Long educationFormId;
|
||||
private String educationFormName;
|
||||
private Long departmentId;
|
||||
private Integer yearStartStudy;
|
||||
private Integer course;
|
||||
private Integer semester;
|
||||
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.name = name;
|
||||
this.groupSize = groupSize;
|
||||
@@ -19,6 +24,18 @@ public class GroupResponse {
|
||||
this.educationFormName = educationFormName;
|
||||
this.departmentId = departmentId;
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -50,6 +67,14 @@ public class GroupResponse {
|
||||
return course;
|
||||
}
|
||||
|
||||
public Integer getSemester() {
|
||||
return semester;
|
||||
}
|
||||
|
||||
public Integer getYearStartStudy() {
|
||||
return yearStartStudy;
|
||||
}
|
||||
|
||||
public Long getSpecialityCode() {
|
||||
return specialityCode;
|
||||
}
|
||||
|
||||
@@ -8,10 +8,10 @@ public class ScheduleResponse {
|
||||
private Long id;
|
||||
private String specialityCode;
|
||||
private Long departmentId;
|
||||
private Long semester;
|
||||
private Long groupId;
|
||||
private String groupName;
|
||||
private Integer groupCourse;
|
||||
private Integer groupSemester;
|
||||
private Long subjectsId;
|
||||
private String subjectName;
|
||||
private Long lessonTypeId;
|
||||
@@ -24,10 +24,9 @@ public class ScheduleResponse {
|
||||
private SemesterType semesterType;
|
||||
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.departmentId = departmentId;
|
||||
this.semester = semester;
|
||||
this.groupId = groupId;
|
||||
this.subjectsId = subjectsId;
|
||||
this.lessonTypeId = lessonTypeId;
|
||||
@@ -38,13 +37,13 @@ public class ScheduleResponse {
|
||||
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.departmentId = departmentId;
|
||||
this.specialityCode = specialityCode;
|
||||
this.semester = semester;
|
||||
this.groupName = groupName;
|
||||
this.groupCourse = groupCourse;
|
||||
this.groupSemester = groupSemester;
|
||||
this.subjectName = subjectName;
|
||||
this.lessonType = lessonType;
|
||||
this.numberOfHours = numberOfHours;
|
||||
@@ -67,10 +66,6 @@ public class ScheduleResponse {
|
||||
return departmentId;
|
||||
}
|
||||
|
||||
public Long getSemester() {
|
||||
return semester;
|
||||
}
|
||||
|
||||
public Long getGroupId() {
|
||||
return groupId;
|
||||
}
|
||||
@@ -83,6 +78,10 @@ public class ScheduleResponse {
|
||||
return groupCourse;
|
||||
}
|
||||
|
||||
public Integer getGroupSemester() {
|
||||
return groupSemester;
|
||||
}
|
||||
|
||||
public Long getSubjectsId() {
|
||||
return subjectsId;
|
||||
}
|
||||
|
||||
@@ -13,9 +13,6 @@ public class ScheduleData {
|
||||
@Column(name="department_id", nullable = false)
|
||||
private Long departmentId;
|
||||
|
||||
@Column(name="semester", nullable = false)
|
||||
private Long semester;
|
||||
|
||||
@Column(name="group_id", nullable = false)
|
||||
private Long groupId;
|
||||
|
||||
@@ -43,10 +40,9 @@ public class 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.departmentId = departmentId;
|
||||
this.semester = semester;
|
||||
this.groupId = groupId;
|
||||
this.subjectsId = subjectsId;
|
||||
this.lessonTypeId = lessonTypeId;
|
||||
@@ -73,14 +69,6 @@ public class ScheduleData {
|
||||
this.departmentId = departmentId;
|
||||
}
|
||||
|
||||
public Long getSemester() {
|
||||
return semester;
|
||||
}
|
||||
|
||||
public void setSemester(Long semester) {
|
||||
this.semester = semester;
|
||||
}
|
||||
|
||||
public Long getGroupId() {
|
||||
return groupId;
|
||||
}
|
||||
|
||||
@@ -23,12 +23,12 @@ public class StudentGroup {
|
||||
@Column(name = "department_id", nullable = false)
|
||||
private Long departmentId;
|
||||
|
||||
@Column(name = "course", nullable = false)
|
||||
private Integer course;
|
||||
|
||||
@Column(name="specialty_code", nullable = false)
|
||||
private Long specialityCode;
|
||||
|
||||
@Column(name="year_start_study", nullable = false)
|
||||
private Integer yearStartStudy;
|
||||
|
||||
public StudentGroup() {
|
||||
}
|
||||
|
||||
@@ -72,14 +72,6 @@ public class StudentGroup {
|
||||
this.departmentId = departmentId;
|
||||
}
|
||||
|
||||
public Integer getCourse() {
|
||||
return course;
|
||||
}
|
||||
|
||||
public void setCourse(Integer course) {
|
||||
this.course = course;
|
||||
}
|
||||
|
||||
public Long getSpecialityCode() {
|
||||
return specialityCode;
|
||||
}
|
||||
@@ -87,4 +79,12 @@ public class StudentGroup {
|
||||
public void setSpecialityCode(Long specialityCode) {
|
||||
this.specialityCode = specialityCode;
|
||||
}
|
||||
|
||||
public Integer getYearStartStudy() {
|
||||
return yearStartStudy;
|
||||
}
|
||||
|
||||
public void setYearStartStudy(Integer yearStartStudy) {
|
||||
this.yearStartStudy = yearStartStudy;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,9 +10,8 @@ public interface ScheduleDataRepository extends JpaRepository<ScheduleData, Long
|
||||
|
||||
List<ScheduleData> findByDepartmentIdAndSemesterTypeAndPeriod(Long departmentId, SemesterType semesterType, String period);
|
||||
|
||||
boolean existsByDepartmentIdAndSemesterAndGroupIdAndSubjectsIdAndLessonTypeIdAndNumberOfHoursAndDivisionAndTeacherIdAndSemesterTypeAndPeriod(
|
||||
boolean existsByDepartmentIdAndGroupIdAndSubjectsIdAndLessonTypeIdAndNumberOfHoursAndDivisionAndTeacherIdAndSemesterTypeAndPeriod(
|
||||
Long departmentId,
|
||||
Long semester,
|
||||
Long groupId,
|
||||
Long subjectsId,
|
||||
Long lessonTypeId,
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -3,27 +3,39 @@
|
||||
-- ==========================================
|
||||
|
||||
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
|
||||
SET specialty_code = 1
|
||||
WHERE specialty_code IS NULL;
|
||||
|
||||
UPDATE student_groups
|
||||
SET year_start_study = 2023
|
||||
WHERE year_start_study IS NULL;
|
||||
|
||||
ALTER TABLE student_groups
|
||||
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)
|
||||
VALUES (1, 1, 1, 1, 3, 2, true, 1, 'autumn', '2024-2025'),
|
||||
(2, 4, 2, 3, 2, 1, false, 2, 'spring', '2025-2026'),
|
||||
(3, 5, 1, 2, 1, 3, true, 1, 'autumn', '2023-2024'),
|
||||
(2, 4, 2, 3, 2, 1, false, 2, 'spring', '2025-2026'),
|
||||
(2, 4, 2, 3, 2, 1, false, 2, 'spring', '2025-2026'),
|
||||
(2, 4, 2, 3, 2, 1, false, 2, 'spring', '2025-2026'),
|
||||
(1, 1, 1, 1, 1, 2, true, 2, 'autumn', '2024-2025'),
|
||||
(1, 2, 2, 2, 3, 4, false, 2, 'autumn', '2024-2025'),
|
||||
(1, 3, 1, 4, 2, 1, false, 1, 'autumn', '2024-2025'),
|
||||
(1, 4, 2, 5, 1, 7, true, 1, 'autumn', '2024-2025');
|
||||
ALTER TABLE schedule_data
|
||||
DROP COLUMN IF EXISTS semester;
|
||||
|
||||
INSERT INTO schedule_data (department_id, group_id, subjects_id, lesson_type_id, number_of_hours, is_division, teacher_id, semester_type, period)
|
||||
VALUES (1, 1, 1, 3, 2, true, 1, 'autumn', '2024-2025'),
|
||||
(2, 2, 3, 2, 1, false, 2, 'spring', '2025-2026'),
|
||||
(3, 1, 2, 1, 3, true, 1, 'autumn', '2023-2024'),
|
||||
(2, 2, 3, 2, 1, false, 2, 'spring', '2025-2026'),
|
||||
(2, 2, 3, 2, 1, false, 2, 'spring', '2025-2026'),
|
||||
(2, 2, 3, 2, 1, false, 2, 'spring', '2025-2026'),
|
||||
(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');
|
||||
@@ -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');
|
||||
details.className = 'table-item';
|
||||
details.open = true;
|
||||
@@ -61,7 +61,7 @@ export async function initDepartment() {
|
||||
<div class="title title-multiline">
|
||||
<span class="title-main">Данные к составлению расписания</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>
|
||||
</div>
|
||||
<div class="meta">${schedule ? schedule.length : 0} записей</div>
|
||||
@@ -98,9 +98,9 @@ export async function initDepartment() {
|
||||
<td>${escapeHtml(r.specialityCode || '-')}</td>
|
||||
<td>${(() => {
|
||||
const course = r.groupCourse || '-';
|
||||
const semester = r.semester || '-';
|
||||
if (course === '-' && semester === '-') return '-';
|
||||
return `${course} | ${semester}`;
|
||||
const groupSemester = r.groupSemester || '-';
|
||||
if (course === '-' && groupSemester === '-') return '-';
|
||||
return `${course} | ${groupSemester}`;
|
||||
})()}</td>
|
||||
<td>${escapeHtml(r.groupName || '-')}</td>
|
||||
<td>${escapeHtml(r.subjectName || '-')}</td>
|
||||
@@ -237,7 +237,7 @@ export async function initDepartment() {
|
||||
<tr${rowStyle}>
|
||||
<td>${escapeHtml(periodDisplay)}</td>
|
||||
<td>${escapeHtml(semLabel)}</td>
|
||||
<td>${s.semester}</td>
|
||||
<td>${s.groupSemester}</td>
|
||||
<td>${escapeHtml(String(groupName))}</td>
|
||||
<td>${escapeHtml(String(subjectName))}</td>
|
||||
<td>${escapeHtml(lessonTypeName)}</td>
|
||||
@@ -283,7 +283,7 @@ export async function initDepartment() {
|
||||
const depId = csDepartmentIdInput.value;
|
||||
const period = document.getElementById('cs-period').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 subjectId = csSubjectSelect.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 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');
|
||||
return;
|
||||
}
|
||||
|
||||
const newRecord = {
|
||||
departmentId: Number(depId),
|
||||
semester: Number(semester),
|
||||
groupSemester: Number(groupSemester),
|
||||
groupId: Number(groupId),
|
||||
subjectsId: Number(subjectId),
|
||||
lessonTypeId: Number(lessonTypeId),
|
||||
@@ -313,7 +313,7 @@ export async function initDepartment() {
|
||||
const isDuplicate = preparedSchedules.some(s =>
|
||||
s.period === newRecord.period &&
|
||||
s.semesterType === newRecord.semesterType &&
|
||||
s.semester === newRecord.semester &&
|
||||
s.groupSemester === newRecord.groupSemester &&
|
||||
s.groupId === newRecord.groupId &&
|
||||
s.subjectsId === newRecord.subjectsId &&
|
||||
s.lessonTypeId === newRecord.lessonTypeId &&
|
||||
|
||||
@@ -83,13 +83,13 @@ export async function initGroups() {
|
||||
const groupSize = document.getElementById('new-group-size').value;
|
||||
const educationFormId = newGroupEfSelect.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 (!groupSize) { showAlert('create-group-alert', 'Введите размер группы', 'error'); return; }
|
||||
if (!educationFormId) { showAlert('create-group-alert', 'Выберите форму обучения', '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 {
|
||||
const data = await api.post('/api/groups', {
|
||||
@@ -97,7 +97,7 @@ export async function initGroups() {
|
||||
groupSize: Number(groupSize),
|
||||
educationFormId: Number(educationFormId),
|
||||
departmentId: Number(departmentId),
|
||||
course: Number(course)
|
||||
yearStartStudy: Number(yearStartStudy)
|
||||
});
|
||||
showAlert('create-group-alert', `Группа "${escapeHtml(data.name || name)}" создана`, 'success');
|
||||
createGroupForm.reset();
|
||||
|
||||
@@ -22,8 +22,8 @@
|
||||
<input type="number" id="new-group-department" placeholder="ID" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="new-group-course">Курс</label>
|
||||
<input type="number" id="new-group-course" placeholder="1-6" min="1" max="6" required>
|
||||
<label for="new-group-yearStartStudy">Год начала обучения</label>
|
||||
<input type="number" id="new-group-yearStartStudy" required pattern="^20\d{2}$" maxlength="3" placeholder="2026">
|
||||
</div>
|
||||
<button type="submit" class="btn-primary">Создать</button>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user