esoe
2 months ago
15 changed files with 473 additions and 47 deletions
@ -0,0 +1,34 @@
@@ -0,0 +1,34 @@
|
||||
package ru.molokoin.resourceserviceapi.enums; |
||||
|
||||
import java.util.Arrays; |
||||
import java.util.List; |
||||
import java.util.stream.Collectors; |
||||
|
||||
public enum Courses { |
||||
ID("id"), |
||||
PLACE("place"), |
||||
START_DATE("startDate"), |
||||
PROTOCOL_DATE("protocolDate"), |
||||
PROTOCOL_NUMBER("protocolNumber"), |
||||
REPORT_PERIOD("reportPeriod"), |
||||
TEACHER("teacher"), |
||||
PROGRAM("program"), |
||||
BUILDING("building"); |
||||
|
||||
private String column; |
||||
|
||||
Courses(String column) { |
||||
this.column = column; |
||||
} |
||||
|
||||
public String column() { |
||||
return column; |
||||
} |
||||
|
||||
public static List<String> getTitles() { |
||||
return Arrays.stream(Courses.values()) |
||||
.map(Courses::column) |
||||
.collect(Collectors.toList()); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,43 @@
@@ -0,0 +1,43 @@
|
||||
package ru.molokoin.resourceserviceapi.repositories; |
||||
|
||||
import java.util.Date; |
||||
import java.util.List; |
||||
|
||||
import org.springframework.data.domain.Page; |
||||
import org.springframework.data.domain.PageRequest; |
||||
import org.springframework.data.jpa.repository.JpaRepository; |
||||
import org.springframework.stereotype.Repository; |
||||
|
||||
import ru.molokoin.resourceserviceapi.entities.Course; |
||||
import ru.molokoin.resourceserviceapi.entities.Teacher; |
||||
|
||||
@Repository |
||||
public interface CourseRepository extends JpaRepository<Course, Long>{ |
||||
List<Course> findAll(); |
||||
Course findById(long id); |
||||
Page<Course> findById(PageRequest of, Long id); |
||||
Page<Course> findByPlace(PageRequest of, String place); |
||||
Page<Course> findByStartDate(PageRequest of, Date startDate); |
||||
Page<Course> findByProtocolNumber(PageRequest of, String protocolNumber); |
||||
Page<Course> findByProtocolDate(PageRequest of, Date protocolDate); |
||||
Page<Course> findByReportPeriod(PageRequest of, String reportPeriod); |
||||
// Page<Course> findByTeacherId(PageRequest of, Long teacherId);
|
||||
// Page<Course> findByTeacherFio(PageRequest of, String teacherFio);
|
||||
// Page<Course> findByTeacherSecondName(PageRequest of, String teacherSecondName);
|
||||
// Page<Course> findByTeacherFirstName(PageRequest of, String teacherFirstName);
|
||||
// Page<Course> findByTeacherLastName(PageRequest of, String teacherLastName);
|
||||
// Page<Course> findByTeacherEmployeeId(PageRequest of, String employeeId);
|
||||
// Page<Course> findByTeacherSnils(PageRequest of, String snils);
|
||||
// Page<Course> findByProgramId(PageRequest of, Long programId);
|
||||
// Page<Course> findByProgramName(PageRequest of, String programName);
|
||||
// Page<Course> findByProgramLenght(PageRequest of, String programLenght);
|
||||
// Page<Course> findByProgramStudyDirection(PageRequest of, String programStudyDirection);
|
||||
// Page<Course> findByProgramPrice(PageRequest of, String programPrice);
|
||||
// Page<Course> findByBuildingId(PageRequest of, String buildingNameShort);
|
||||
// Page<Course> findByBuildingCodeShort(PageRequest of, String buildingCodeShort);
|
||||
// Page<Course> findByBuildingNameShort(PageRequest of, String buildingNameShort);
|
||||
// Page<Course> findByBuildingNameFull(PageRequest of, String buildingNameFull);
|
||||
// Page<Course> findByBuildingCodeFull(PageRequest of, String buildingCodeFull);
|
||||
Page<Course> findByTeacher(PageRequest of, Teacher teacher); |
||||
boolean existsByTeacher(Teacher teacher); |
||||
} |
@ -1,12 +0,0 @@
@@ -1,12 +0,0 @@
|
||||
package ru.molokoin.resourceserviceapi.repositories; |
||||
|
||||
import java.util.List; |
||||
|
||||
import org.springframework.data.repository.ListCrudRepository; |
||||
|
||||
import ru.molokoin.resourceserviceapi.entities.Course; |
||||
|
||||
public interface CourseRepositoryFace extends ListCrudRepository<Course, Long>{ |
||||
List<Course> findAll(); |
||||
Course findById(long id); |
||||
} |
@ -0,0 +1,173 @@
@@ -0,0 +1,173 @@
|
||||
package ru.molokoin.resourceserviceapi.services; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.Date; |
||||
import java.util.List; |
||||
import java.util.Optional; |
||||
|
||||
import org.springframework.data.domain.Page; |
||||
import org.springframework.data.domain.PageImpl; |
||||
import org.springframework.data.domain.PageRequest; |
||||
import org.springframework.data.domain.Sort.Order; |
||||
import org.springframework.data.util.Streamable; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import ru.molokoin.resourceserviceapi.entities.Course; |
||||
import ru.molokoin.resourceserviceapi.entities.Teacher; |
||||
import ru.molokoin.resourceserviceapi.repositories.BuildingRepository; |
||||
import ru.molokoin.resourceserviceapi.repositories.CourseRepository; |
||||
import ru.molokoin.resourceserviceapi.repositories.ProgramCretareaRepository; |
||||
import ru.molokoin.resourceserviceapi.repositories.ProgramRepository; |
||||
import ru.molokoin.resourceserviceapi.repositories.TeacherRepository; |
||||
|
||||
@Service |
||||
public class CourseService { |
||||
//репозиторий курсов
|
||||
private final CourseRepository repo; |
||||
//репозиторий преподавателей
|
||||
private final TeacherService teacherService; |
||||
//репозиторий объектов строительства
|
||||
private final BuildingService buildingService; |
||||
//репозиторий программ обучения
|
||||
private final ProgramService programService; |
||||
//репозиторий критериев
|
||||
private final ProgramCretareaService programCretareaService; |
||||
|
||||
public CourseService(CourseRepository repo, |
||||
TeacherService teacherService, |
||||
BuildingService buildingService, |
||||
ProgramService programService, |
||||
ProgramCretareaService programCretareaService) { |
||||
this.repo = repo; |
||||
this.teacherService = teacherService; |
||||
this.buildingService = buildingService; |
||||
this.programService = programService; |
||||
this.programCretareaService = programCretareaService; |
||||
} |
||||
public Page<Course> findAll(PageRequest of) { |
||||
return repo.findAll(of); |
||||
} |
||||
public void save(Course course) { |
||||
repo.save(course); |
||||
} |
||||
public Course findById(Integer id) { |
||||
return repo.findById(id); |
||||
} |
||||
public Optional<Course> findById(Long id) { |
||||
return repo.findById(id); |
||||
|
||||
} |
||||
public void delete(Course c) { |
||||
repo.delete(c); |
||||
} |
||||
public List<Course> findAll() { |
||||
return repo.findAll(); |
||||
} |
||||
public Long count() { |
||||
return repo.count(); |
||||
} |
||||
public Page<Course> findById(PageRequest of, Long id) { |
||||
return repo.findById(PageRequest.of(of.getPageNumber(), of.getPageSize()), id); |
||||
} |
||||
public Page<Course> findByPlace(PageRequest of, String place) { |
||||
return repo.findByPlace(PageRequest.of(of.getPageNumber(), of.getPageSize()), place); |
||||
} |
||||
public Page<Course> findByStartDate(PageRequest of, Date startDate) { |
||||
return repo.findByStartDate(PageRequest.of(of.getPageNumber(), of.getPageSize()), startDate); |
||||
} |
||||
public Page<Course> findByProtocolNumber(PageRequest of, String protocolNumber) { |
||||
return repo.findByProtocolNumber(PageRequest.of(of.getPageNumber(), of.getPageSize()), protocolNumber); |
||||
} |
||||
public Page<Course> findByProtocolDate(PageRequest of, Date protocolDate) { |
||||
return repo.findByProtocolDate(PageRequest.of(of.getPageNumber(), of.getPageSize()), protocolDate); |
||||
} |
||||
public Page<Course> findByReportPeriod(PageRequest of, String reportPeriod) { |
||||
return repo.findByReportPeriod(PageRequest.of(of.getPageNumber(), of.getPageSize()), reportPeriod); |
||||
} |
||||
|
||||
/** |
||||
* Поиск курсов по идентификатору преподавателя |
||||
* @param of |
||||
* @param teacherId |
||||
* @return |
||||
*/ |
||||
public Page<Course> findByTeacherId(PageRequest of, Long teacherId) { |
||||
Teacher teacher = null; |
||||
if (teacherId > 0 && teacherService.existsById(teacherId)) { |
||||
teacher = teacherService.findById(teacherId); |
||||
} |
||||
|
||||
if (teacher != null && repo.existsByTeacher(teacher)) { |
||||
return repo.findByTeacher(PageRequest.of(of.getPageNumber(), of.getPageSize()), teacher); |
||||
} |
||||
//пустой список курсов
|
||||
return new PageImpl<>(new ArrayList<Course>(), of, 0); |
||||
} |
||||
public Page<Course> findByTeacherFio(PageRequest of, String teacherFio) { |
||||
//извлекаем из базы список преподавателей по ФИО
|
||||
List<Teacher> teachers = new ArrayList<>(); |
||||
if (teacherFio != null && !teacherFio.isEmpty() && teacherService.existsByFIO(teacherFio)) { |
||||
teachers = teacherService.findByFIO(teacherFio); |
||||
} |
||||
|
||||
if (teachers.size() > 0) { |
||||
//курсы каждого подходящего преподавателя добавляем к страничкам ответа
|
||||
Page<Course> courses = new PageImpl<>(new ArrayList<Course>(), of, 0); |
||||
for (Teacher t : teachers) { |
||||
courses.and(repo.findByTeacher(PageRequest.of(of.getPageNumber(), of.getPageSize()), t)); |
||||
} |
||||
if (courses.getTotalElements() > 0) { |
||||
return courses; |
||||
} |
||||
} |
||||
//пустой список курсов
|
||||
return new PageImpl<>(new ArrayList<Course>(), of, 0); |
||||
} |
||||
|
||||
// public Page<Course> findByTeacherSecondName(PageRequest of, String teacherSecondName) {
|
||||
// return repo.findByTeacherSecondName(PageRequest.of(of.getPageNumber(), of.getPageSize()), teacherSecondName);
|
||||
// }
|
||||
// public Page<Course> findByTeacherFirstName(PageRequest of, String teacherFirstName) {
|
||||
// return repo.findByTeacherFirstName(PageRequest.of(of.getPageNumber(), of.getPageSize()), teacherFirstName);
|
||||
// }
|
||||
// public Page<Course> findByTeacherLastName(PageRequest of, String teacherLastName) {
|
||||
// return repo.findByTeacherLastName(PageRequest.of(of.getPageNumber(), of.getPageSize()), teacherLastName);
|
||||
// }
|
||||
// public Page<Course> findByProgramName(PageRequest of, String programName) {
|
||||
// return repo.findByProgramName(PageRequest.of(of.getPageNumber(), of.getPageSize()), programName);
|
||||
// }
|
||||
// public Page<Course> findByBuildingId(PageRequest of, String buildingNameShort) {
|
||||
// return repo.findByBuildingId(PageRequest.of(of.getPageNumber(), of.getPageSize()), buildingNameShort);
|
||||
// }
|
||||
// public Page<Course> findByBuildingCodeShort(PageRequest of, String buildingCodeShort) {
|
||||
// return repo.findByBuildingCodeShort(PageRequest.of(of.getPageNumber(), of.getPageSize()), buildingCodeShort);
|
||||
// }
|
||||
// public Page<Course> findByBuildingNameShort(PageRequest of, String buildingNameShort) {
|
||||
// return repo.findByBuildingNameShort(PageRequest.of(of.getPageNumber(), of.getPageSize()), buildingNameShort);
|
||||
// }
|
||||
// public Page<Course> findByProgramId(PageRequest of, Long programId) {
|
||||
// return repo.findByProgramId(PageRequest.of(of.getPageNumber(), of.getPageSize()), programId);
|
||||
// }
|
||||
// public Page<Course> findByProgramLenght(PageRequest of, String programLenght) {
|
||||
// return repo.findByProgramLenght(PageRequest.of(of.getPageNumber(), of.getPageSize()), programLenght);
|
||||
// }
|
||||
// public Page<Course> findByTeacherEmployeeId(PageRequest of, String employeeId) {
|
||||
// return repo.findByTeacherEmployeeId(PageRequest.of(of.getPageNumber(), of.getPageSize()), employeeId);
|
||||
// }
|
||||
// public Page<Course> findByTeacherSnils(PageRequest of, String snils) {
|
||||
// return repo.findByTeacherSnils(PageRequest.of(of.getPageNumber(), of.getPageSize()), snils);
|
||||
// }
|
||||
// public Page<Course> findByProgramStudyDirection(PageRequest of, String programStudyDirection) {
|
||||
// return repo.findByProgramStudyDirection(PageRequest.of(of.getPageNumber(), of.getPageSize()), programStudyDirection);
|
||||
// }
|
||||
// public Page<Course> findByProgramPrice(PageRequest of, String programPrice) {
|
||||
// return repo.findByProgramPrice(PageRequest.of(of.getPageNumber(), of.getPageSize()), programPrice);
|
||||
// }
|
||||
// public Page<Course> findByBuildingNameFull(PageRequest of, String buildingNameFull) {
|
||||
// return repo.findByBuildingNameFull(PageRequest.of(of.getPageNumber(), of.getPageSize()), buildingNameFull);
|
||||
// }
|
||||
// public Page<Course> findByBuildingCodeFull(PageRequest of, String buildingCodeFull) {
|
||||
// return repo.findByBuildingCodeFull(PageRequest.of(of.getPageNumber(), of.getPageSize()), buildingCodeFull);
|
||||
// }
|
||||
|
||||
} |
Binary file not shown.
Loading…
Reference in new issue