diff --git a/gates/src/main/java/ru/mlokoin/gates/controller/v1/OrganizationController.java b/gates/src/main/java/ru/mlokoin/gates/controller/v1/OrganizationController.java index a39b17a..c56414f 100644 --- a/gates/src/main/java/ru/mlokoin/gates/controller/v1/OrganizationController.java +++ b/gates/src/main/java/ru/mlokoin/gates/controller/v1/OrganizationController.java @@ -63,7 +63,7 @@ public class OrganizationController { } Organization organization = new Organization(); - organization.setName_full(string); + organization.setNameFull(string); xlsx_orgs.add(organization); } xlsx_orgs.remove(0);//Удалили из списка заголовок @@ -73,7 +73,7 @@ public class OrganizationController { System.out.println("###############################"); System.out.println(">> Организации из файла: " + xlsx_orgSet.size()); for (Organization organization : xlsx_orgSet) { - System.out.println("Объект строительства (xlsx): " + organization.getName_full()); + System.out.println("Объект строительства (xlsx): " + organization.getNameFull()); } //Ошибки в консоль @@ -94,13 +94,13 @@ public class OrganizationController { Set base_organizations_str = new HashSet<>(); for (Organization o : xlsx_orgSet) { - String s = o.getName_full(); + String s = o.getNameFull(); xlsx_organizations_str.add(s); } System.out.println("Организации в базе:"); for (Organization o : base_organizations) { - String s = o.getName_full(); + String s = o.getNameFull(); System.out.println("base_organizations : " + s); base_organizations_str.add(s); } @@ -114,7 +114,7 @@ public class OrganizationController { ArrayList list = new ArrayList<>(); for (String string : xlsx_organizations_str) { Organization o = new Organization(); - o.setName_full(string); + o.setNameFull(string); list.add(o); } @@ -138,7 +138,7 @@ public class OrganizationController { for (Organization organization : wraper.getList()) { //Проверка наличия флага для добавления в базу //по полю табельного номера - if (organization.getName_full() != ""){ + if (organization.getNameFull() != ""){ client.post() .uri("http://resource-service-api:8181/organization/create") .body(Mono.just(organization), Organization.class) diff --git a/gates/src/main/java/ru/mlokoin/gates/controller/v1/ProgramController.java b/gates/src/main/java/ru/mlokoin/gates/controller/v1/ProgramController.java index 91d591b..77291a9 100644 --- a/gates/src/main/java/ru/mlokoin/gates/controller/v1/ProgramController.java +++ b/gates/src/main/java/ru/mlokoin/gates/controller/v1/ProgramController.java @@ -127,7 +127,7 @@ public class ProgramController { //проверка наличия длительности программы if (program.getLenght() != null) { //проверка наличия направления обучения - if (!program.getStudy_direction().equals("")){ + if (!program.getStudyDirection().equals("")){ //проверка наличия критерия if (program.getCretarea() != null){ client.post() diff --git a/gates/src/main/java/ru/mlokoin/gates/model/fs/xlsx/XlsxDocumentReestr.java b/gates/src/main/java/ru/mlokoin/gates/model/fs/xlsx/XlsxDocumentReestr.java index 68b0c7d..1dac1d6 100644 --- a/gates/src/main/java/ru/mlokoin/gates/model/fs/xlsx/XlsxDocumentReestr.java +++ b/gates/src/main/java/ru/mlokoin/gates/model/fs/xlsx/XlsxDocumentReestr.java @@ -179,7 +179,7 @@ public class XlsxDocumentReestr extends XlsxDocument { List organizations = getOrganizationsAsIs(); List unique = new ArrayList<>(); for (Organization organization : organizations) { - if (!unique.contains(organization) && organization.getName_full() != "") { + if (!unique.contains(organization) && organization.getNameFull() != "") { unique.add(organization); } } diff --git a/gates/src/main/java/ru/mlokoin/gates/model/organization/Organization.java b/gates/src/main/java/ru/mlokoin/gates/model/organization/Organization.java index 9ab1fa4..e0d4d7a 100644 --- a/gates/src/main/java/ru/mlokoin/gates/model/organization/Organization.java +++ b/gates/src/main/java/ru/mlokoin/gates/model/organization/Organization.java @@ -19,8 +19,8 @@ import ru.mlokoin.gates.teh.strings.Stringer; public class Organization implements Serializable{ private long id; private String ownership;//Форма собственности ПСК - private String name_short;//Сокращенное наименование - private String name_full;//Полное наименование + private String nameShort;//Сокращенное наименование + private String nameFull;//Полное наименование private String type;//вид ПСК - производственная/сервисная private String inn;//ИНН организации @@ -34,17 +34,17 @@ public class Organization implements Serializable{ */ public Organization(String ownership, String name_short, String name_full, String type, String inn) { this.ownership = ownership; - this.name_short = name_short; - this.name_full = name_full; + this.nameShort = name_short; + this.nameFull = name_full; this.type = type; this.inn = inn; } public Organization(Entry> entry) { - this.setName_full(Stringer.clear(entry.getValue().get(1).getContent())); + this.setNameFull(Stringer.clear(entry.getValue().get(1).getContent())); } public boolean isSimilar(Organization organization) { - return this.getName_full().equals(organization.getName_full()); + return this.getNameFull().equals(organization.getNameFull()); } } diff --git a/gates/src/main/java/ru/mlokoin/gates/model/program/Program.java b/gates/src/main/java/ru/mlokoin/gates/model/program/Program.java index dd3340c..ba31008 100644 --- a/gates/src/main/java/ru/mlokoin/gates/model/program/Program.java +++ b/gates/src/main/java/ru/mlokoin/gates/model/program/Program.java @@ -26,7 +26,7 @@ public class Program { * - Обучение вновь внедряемым процедурам * - Обучение водителей */ - private String study_direction; + private String studyDirection; private Integer price;//рублей private ProgramCretarea cretarea; @@ -42,7 +42,7 @@ public class Program { public Program(String name, Integer lenght, String study_direction, Integer price, ProgramCretarea cretarea) { this.name = name; this.lenght = lenght; - this.study_direction = study_direction; + this.studyDirection = study_direction; this.price = price; this.cretarea = cretarea; } @@ -67,7 +67,7 @@ public class Program { } - this.setStudy_direction(Stringer.clear(entry.getValue().get(Headers.PROGRAMM_STADY_DIRECTION.column()).getContent())); + this.setStudyDirection(Stringer.clear(entry.getValue().get(Headers.PROGRAMM_STADY_DIRECTION.column()).getContent())); //устанавливаем стоимость обучения try { diff --git a/gates/src/main/java/ru/mlokoin/gates/model/student/Student.java b/gates/src/main/java/ru/mlokoin/gates/model/student/Student.java index 4a0266e..9ecc10c 100644 --- a/gates/src/main/java/ru/mlokoin/gates/model/student/Student.java +++ b/gates/src/main/java/ru/mlokoin/gates/model/student/Student.java @@ -86,7 +86,7 @@ public class Student implements Serializable{ if (base_organizations != null) { this.organization = base_organizations .stream() - .filter(org -> org.getName_full().equals(organization)) + .filter(org -> org.getNameFull().equals(organization)) .findFirst() .orElse(null); } else { diff --git a/gates/src/main/java/ru/mlokoin/gates/repository/Storage.java b/gates/src/main/java/ru/mlokoin/gates/repository/Storage.java index 4c70bcb..8c85913 100644 --- a/gates/src/main/java/ru/mlokoin/gates/repository/Storage.java +++ b/gates/src/main/java/ru/mlokoin/gates/repository/Storage.java @@ -571,7 +571,7 @@ public class Storage { for (Organization xlsxOrganization : xlsxList) { for (Organization baseOrganization : baseList) { - if (xlsxOrganization.getName_full().equals(baseOrganization.getName_full())) { + if (xlsxOrganization.getNameFull().equals(baseOrganization.getNameFull())) { result.remove(xlsxOrganization); break; } @@ -616,7 +616,7 @@ public class Storage { && xlsxStudent.getProfession().equals(baseStudent.getProfession()) && xlsxStudent.getDirection().equals(baseStudent.getDirection()) && xlsxStudent.getProfession().equals(baseStudent.getProfession()) - && xlsxStudent.getOrganization().getName_full().equals(baseStudent.getOrganization().getName_full())) { + && xlsxStudent.getOrganization().getNameFull().equals(baseStudent.getOrganization().getNameFull())) { result.remove(xlsxStudent); break; } diff --git a/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/controllers/api/CourseController.java b/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/controllers/api/CourseController.java index 80e8b25..7429ba6 100644 --- a/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/controllers/api/CourseController.java +++ b/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/controllers/api/CourseController.java @@ -1,8 +1,14 @@ package ru.molokoin.resourceserviceapi.controllers.api; +import java.util.ArrayList; +import java.util.Date; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageImpl; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Sort; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; @@ -13,28 +19,201 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import ru.molokoin.resourceserviceapi.entities.Course; -import ru.molokoin.resourceserviceapi.repositories.CourseRepositoryFace; +import ru.molokoin.resourceserviceapi.enums.Base; +import ru.molokoin.resourceserviceapi.services.CourseService; @RestController -@RequestMapping(path = "/", consumes = {"*/*"}) +@RequestMapping(path = "/api/course", consumes = {"*/*"}) public class CourseController { @Autowired - private CourseRepositoryFace repo; + private CourseService repo; - @GetMapping("/course/list") - public ResponseEntity> getCourses(){ - return new ResponseEntity<>(repo.findAll(), HttpStatus.OK); + public CourseController(CourseService repo) { + this.repo = repo; } - @GetMapping("/course/{id}") - public ResponseEntity getCourseByID(@PathVariable Integer id){ - return new ResponseEntity<>(repo.findById(id), HttpStatus.OK); + @GetMapping("/pages") + public Page courses(@RequestParam(name="page", defaultValue = "0") int pageNo, + @RequestParam(name = "size", defaultValue = "10") int pageSize, + @RequestParam(name="sortBy", defaultValue = "id") String sortBy) { + if (!Base.COURSES.contains(sortBy)) sortBy = "id"; + return repo.findAll(PageRequest.of(pageNo, pageSize, Sort.by(sortBy))); } - @PostMapping(path = "/course/create", + @GetMapping("/count") + public ResponseEntity count(){ + return new ResponseEntity<>(repo.count(), HttpStatus.OK); + } + + /** + * Возвращает страницы по одному наиболее приоритетному параметру + * @param id + * @param place + * @param startDate + * @param protocolDate + * @param protocolNumber + * @param reportPeriod + * @param teacherId + * @param teacherSecondName + * @param teacherFirstName + * @param teacherLastName + * @param teacherFio + * @param employeeId + * @param snils + * @param programId + * @param programName + * @param programLenght + * @param programStudyDirection + * @param programPrice + * @param programCretareaId + * @param programCretareaName + * @param programNameShort + * @param buildingId + * @param buildingNameShort + * @param buildingNameFull + * @param buildingCodeShort + * @param buildingCodeFull + * @param pageNo + * @param pageSize + * @param sortBy + * @return + */ + @GetMapping("") + public Page course( + @RequestParam(name="id", defaultValue = "0") Long id, + @RequestParam(name="place", defaultValue = "") String place, + @RequestParam(name="startDate", defaultValue = "") Date startDate, + @RequestParam(name="protocolDate", defaultValue = "") Date protocolDate, + @RequestParam(name="protocolNumber", defaultValue = "") String protocolNumber, + @RequestParam(name="reportPeriod", defaultValue = "") String reportPeriod, + //Параметры вложенного объекта teacher + @RequestParam(name="teacherId", defaultValue = "") Long teacherId, + @RequestParam(name="teacherSecondName", defaultValue = "") String teacherSecondName, + @RequestParam(name="teacherFirstName", defaultValue = "") String teacherFirstName, + @RequestParam(name="teacherLastName", defaultValue = "") String teacherLastName, + @RequestParam(name="teacherFio", defaultValue = "") String teacherFio, + @RequestParam(name="teacherEmployeeId", defaultValue = "") String employeeId, + @RequestParam(name="teacherSnils", defaultValue = "") String snils, + //Параметры вложенного объекта program + @RequestParam(name="programId", defaultValue = "") Long programId, + @RequestParam(name="programName", defaultValue = "") String programName, + @RequestParam(name="programLenght", defaultValue = "") String programLenght, + @RequestParam(name="programStudyDirection", defaultValue = "") String programStudyDirection, + @RequestParam(name="programPrice", defaultValue = "") String programPrice, + @RequestParam(name="programCretareaId", defaultValue = "") String programCretareaId, + @RequestParam(name="programCretareaName", defaultValue = "") String programCretareaName, + @RequestParam(name="programCretareaNameShort", defaultValue = "") String programNameShort, + //Параметры вложенного объекта building + @RequestParam(name="buildingId", defaultValue = "") Long buildingId, + @RequestParam(name="buildingNameShort", defaultValue = "") String buildingNameShort, + @RequestParam(name="buildingNameFull", defaultValue = "") String buildingNameFull, + @RequestParam(name="buildingCodeShort", defaultValue = "") String buildingCodeShort, + @RequestParam(name="buildingCodeFull", defaultValue = "") String buildingCodeFull, + //параметры возвращаемой страницы + @RequestParam(name="page", defaultValue = "0") int pageNo, + @RequestParam(name = "size", defaultValue = "10") int pageSize, + @RequestParam(name="sortBy", defaultValue = "id") String sortBy + ) { + if (!Base.COURSES.contains(sortBy)) sortBy = "id"; + + if (id > 0) { + return repo.findById(PageRequest.of(pageNo, pageSize, Sort.by(sortBy)), id); + } + + if (!place.isEmpty()) { + return repo.findByPlace(PageRequest.of(pageNo, pageSize, Sort.by(sortBy)), place); + } + + if (startDate != null) { + return repo.findByStartDate(PageRequest.of(pageNo, pageSize, Sort.by(sortBy)), startDate); + } + + if (protocolDate != null) { + return repo.findByProtocolDate(PageRequest.of(pageNo, pageSize, Sort.by(sortBy)), protocolDate); + } + + if (!protocolNumber.isEmpty()) { + return repo.findByProtocolNumber(PageRequest.of(pageNo, pageSize, Sort.by(sortBy)), protocolNumber); + } + + if (!reportPeriod.isEmpty()) { + return repo.findByReportPeriod(PageRequest.of(pageNo, pageSize, Sort.by(sortBy)), reportPeriod); + } + + if (teacherId > 0) { + return repo.findByTeacherId(PageRequest.of(pageNo, pageSize, Sort.by(sortBy)), teacherId); + } + + if (!teacherFio.isEmpty()) { + return repo.findByTeacherFio(PageRequest.of(pageNo, pageSize, Sort.by(sortBy)), teacherFio); + } + + // if (!teacherSecondName.isEmpty()) { + // return repo.findByTeacherSecondName(PageRequest.of(pageNo, pageSize, Sort.by(sortBy)), teacherSecondName); + // } + + // if (!teacherFirstName.isEmpty()) { + // return repo.findByTeacherFirstName(PageRequest.of(pageNo, pageSize, Sort.by(sortBy)), teacherFirstName); + // } + + // if (!teacherLastName.isEmpty()) { + // return repo.findByTeacherLastName(PageRequest.of(pageNo, pageSize, Sort.by(sortBy)), teacherLastName); + // } + + // if (!employeeId.isEmpty()) { + // return repo.findByTeacherEmployeeId(PageRequest.of(pageNo, pageSize, Sort.by(sortBy)), employeeId); + // } + + // if (!snils.isEmpty()) { + // return repo.findByTeacherSnils(PageRequest.of(pageNo, pageSize, Sort.by(sortBy)), snils); + // } + + // if (programId > 0) { + // return repo.findByProgramId(PageRequest.of(pageNo, pageSize, Sort.by(sortBy)), programId); + // } + + // if (!programName.isEmpty()) { + // return repo.findByProgramName(PageRequest.of(pageNo, pageSize, Sort.by(sortBy)), programName); + // } + + // if (!programLenght.isEmpty()) { + // return repo.findByProgramLenght(PageRequest.of(pageNo, pageSize, Sort.by(sortBy)), programLenght); + // } + + // if (!programStudyDirection.isEmpty()) { + // return repo.findByProgramStudyDirection(PageRequest.of(pageNo, pageSize, Sort.by(sortBy)), programStudyDirection); + // } + + // if (!programPrice.isEmpty()) { + // return repo.findByProgramPrice(PageRequest.of(pageNo, pageSize, Sort.by(sortBy)), programPrice); + // } + + // if (!buildingNameShort.isEmpty()) { + // return repo.findByBuildingNameShort(PageRequest.of(pageNo, pageSize, Sort.by(sortBy)), buildingNameShort); + // } + + // if (!buildingCodeShort.isEmpty()) { + // return repo.findByBuildingCodeShort(PageRequest.of(pageNo, pageSize, Sort.by(sortBy)), buildingCodeShort); + // } + + // if (!buildingNameFull.isEmpty()) { + // return repo.findByBuildingNameFull(PageRequest.of(pageNo, pageSize, Sort.by(sortBy)), buildingNameFull); + // } + + // if (!buildingCodeFull.isEmpty()) { + // return repo.findByBuildingCodeFull(PageRequest.of(pageNo, pageSize, Sort.by(sortBy)), buildingCodeFull); + // } + return new PageImpl<>(new ArrayList<>(), PageRequest.of(pageNo, pageSize, Sort.by(sortBy)), 0); + } + + + + + @PostMapping(path = "/create", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity saveCourse(@RequestBody Course course) { @@ -42,7 +221,7 @@ public class CourseController { return new ResponseEntity<>(course, HttpStatus.CREATED); } - @PutMapping(path = "/course/update/{id}", + @PutMapping(path = "/update/{id}", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity updateCourse(@PathVariable Integer id, @RequestBody Course course) { @@ -59,11 +238,21 @@ public class CourseController { return new ResponseEntity<>(repo.findById(id), HttpStatus.CREATED); } - @DeleteMapping("/course/delete/{id}") + @DeleteMapping("/delete/{id}") public ResponseEntity deleteCourse(@PathVariable Long id){ Course c = repo.findById(id).get(); System.out.println(c.toString()); repo.delete(c); return new ResponseEntity<>("Запись id#" + id + " удалена ... ", HttpStatus.OK); } + + // @GetMapping("/list") + // public ResponseEntity> getCourses(){ + // return new ResponseEntity<>(repo.findAll(), HttpStatus.OK); + // } + + // @GetMapping("/{id}") + // public ResponseEntity getCourseByID(@PathVariable Integer id){ + // return new ResponseEntity<>(repo.findById(id), HttpStatus.OK); + // } } diff --git a/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/enums/Base.java b/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/enums/Base.java index 51a7f15..1de3439 100644 --- a/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/enums/Base.java +++ b/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/enums/Base.java @@ -10,8 +10,8 @@ public enum Base { ORGANIZATIONS (Organizations.getTitles()), // EDUCATIONS (Educations.getTitles()), BUILDINGS (Buildings.getTitles()), - CRETAREAS (Cretareas.getTitles()); - // COURSES (Courses.getTitles()), + CRETAREAS (Cretareas.getTitles()), + COURSES (Courses.getTitles()); // POSTS (Posts.getTitles()), // STORES (Stores.getTitles()); diff --git a/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/enums/Courses.java b/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/enums/Courses.java new file mode 100644 index 0000000..d2c89c7 --- /dev/null +++ b/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/enums/Courses.java @@ -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 getTitles() { + return Arrays.stream(Courses.values()) + .map(Courses::column) + .collect(Collectors.toList()); + } + +} diff --git a/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/repositories/CourseRepository.java b/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/repositories/CourseRepository.java new file mode 100644 index 0000000..991b420 --- /dev/null +++ b/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/repositories/CourseRepository.java @@ -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{ + List findAll(); + Course findById(long id); + Page findById(PageRequest of, Long id); + Page findByPlace(PageRequest of, String place); + Page findByStartDate(PageRequest of, Date startDate); + Page findByProtocolNumber(PageRequest of, String protocolNumber); + Page findByProtocolDate(PageRequest of, Date protocolDate); + Page findByReportPeriod(PageRequest of, String reportPeriod); + // Page findByTeacherId(PageRequest of, Long teacherId); + // Page findByTeacherFio(PageRequest of, String teacherFio); + // Page findByTeacherSecondName(PageRequest of, String teacherSecondName); + // Page findByTeacherFirstName(PageRequest of, String teacherFirstName); + // Page findByTeacherLastName(PageRequest of, String teacherLastName); + // Page findByTeacherEmployeeId(PageRequest of, String employeeId); + // Page findByTeacherSnils(PageRequest of, String snils); + // Page findByProgramId(PageRequest of, Long programId); + // Page findByProgramName(PageRequest of, String programName); + // Page findByProgramLenght(PageRequest of, String programLenght); + // Page findByProgramStudyDirection(PageRequest of, String programStudyDirection); + // Page findByProgramPrice(PageRequest of, String programPrice); + // Page findByBuildingId(PageRequest of, String buildingNameShort); + // Page findByBuildingCodeShort(PageRequest of, String buildingCodeShort); + // Page findByBuildingNameShort(PageRequest of, String buildingNameShort); + // Page findByBuildingNameFull(PageRequest of, String buildingNameFull); + // Page findByBuildingCodeFull(PageRequest of, String buildingCodeFull); + Page findByTeacher(PageRequest of, Teacher teacher); + boolean existsByTeacher(Teacher teacher); +} diff --git a/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/repositories/CourseRepositoryFace.java b/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/repositories/CourseRepositoryFace.java deleted file mode 100644 index 9120014..0000000 --- a/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/repositories/CourseRepositoryFace.java +++ /dev/null @@ -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{ - List findAll(); - Course findById(long id); -} diff --git a/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/repositories/ProgramCretareaRepository.java b/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/repositories/ProgramCretareaRepository.java index 22fcf1b..c4b23c2 100644 --- a/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/repositories/ProgramCretareaRepository.java +++ b/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/repositories/ProgramCretareaRepository.java @@ -5,7 +5,6 @@ import org.springframework.data.domain.PageRequest; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; -import ru.molokoin.resourceserviceapi.entities.Program; import ru.molokoin.resourceserviceapi.entities.ProgramCretarea; @Repository diff --git a/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/services/CourseService.java b/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/services/CourseService.java new file mode 100644 index 0000000..8ba4946 --- /dev/null +++ b/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/services/CourseService.java @@ -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 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 findById(Long id) { + return repo.findById(id); + + } + public void delete(Course c) { + repo.delete(c); + } + public List findAll() { + return repo.findAll(); + } + public Long count() { + return repo.count(); + } + public Page findById(PageRequest of, Long id) { + return repo.findById(PageRequest.of(of.getPageNumber(), of.getPageSize()), id); + } + public Page findByPlace(PageRequest of, String place) { + return repo.findByPlace(PageRequest.of(of.getPageNumber(), of.getPageSize()), place); + } + public Page findByStartDate(PageRequest of, Date startDate) { + return repo.findByStartDate(PageRequest.of(of.getPageNumber(), of.getPageSize()), startDate); + } + public Page findByProtocolNumber(PageRequest of, String protocolNumber) { + return repo.findByProtocolNumber(PageRequest.of(of.getPageNumber(), of.getPageSize()), protocolNumber); + } + public Page findByProtocolDate(PageRequest of, Date protocolDate) { + return repo.findByProtocolDate(PageRequest.of(of.getPageNumber(), of.getPageSize()), protocolDate); + } + public Page findByReportPeriod(PageRequest of, String reportPeriod) { + return repo.findByReportPeriod(PageRequest.of(of.getPageNumber(), of.getPageSize()), reportPeriod); + } + + /** + * Поиск курсов по идентификатору преподавателя + * @param of + * @param teacherId + * @return + */ + public Page 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(), of, 0); + } + public Page findByTeacherFio(PageRequest of, String teacherFio) { + //извлекаем из базы список преподавателей по ФИО + List teachers = new ArrayList<>(); + if (teacherFio != null && !teacherFio.isEmpty() && teacherService.existsByFIO(teacherFio)) { + teachers = teacherService.findByFIO(teacherFio); + } + + if (teachers.size() > 0) { + //курсы каждого подходящего преподавателя добавляем к страничкам ответа + Page courses = new PageImpl<>(new ArrayList(), 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(), of, 0); + } + + // public Page findByTeacherSecondName(PageRequest of, String teacherSecondName) { + // return repo.findByTeacherSecondName(PageRequest.of(of.getPageNumber(), of.getPageSize()), teacherSecondName); + // } + // public Page findByTeacherFirstName(PageRequest of, String teacherFirstName) { + // return repo.findByTeacherFirstName(PageRequest.of(of.getPageNumber(), of.getPageSize()), teacherFirstName); + // } + // public Page findByTeacherLastName(PageRequest of, String teacherLastName) { + // return repo.findByTeacherLastName(PageRequest.of(of.getPageNumber(), of.getPageSize()), teacherLastName); + // } + // public Page findByProgramName(PageRequest of, String programName) { + // return repo.findByProgramName(PageRequest.of(of.getPageNumber(), of.getPageSize()), programName); + // } + // public Page findByBuildingId(PageRequest of, String buildingNameShort) { + // return repo.findByBuildingId(PageRequest.of(of.getPageNumber(), of.getPageSize()), buildingNameShort); + // } + // public Page findByBuildingCodeShort(PageRequest of, String buildingCodeShort) { + // return repo.findByBuildingCodeShort(PageRequest.of(of.getPageNumber(), of.getPageSize()), buildingCodeShort); + // } + // public Page findByBuildingNameShort(PageRequest of, String buildingNameShort) { + // return repo.findByBuildingNameShort(PageRequest.of(of.getPageNumber(), of.getPageSize()), buildingNameShort); + // } + // public Page findByProgramId(PageRequest of, Long programId) { + // return repo.findByProgramId(PageRequest.of(of.getPageNumber(), of.getPageSize()), programId); + // } + // public Page findByProgramLenght(PageRequest of, String programLenght) { + // return repo.findByProgramLenght(PageRequest.of(of.getPageNumber(), of.getPageSize()), programLenght); + // } + // public Page findByTeacherEmployeeId(PageRequest of, String employeeId) { + // return repo.findByTeacherEmployeeId(PageRequest.of(of.getPageNumber(), of.getPageSize()), employeeId); + // } + // public Page findByTeacherSnils(PageRequest of, String snils) { + // return repo.findByTeacherSnils(PageRequest.of(of.getPageNumber(), of.getPageSize()), snils); + // } + // public Page findByProgramStudyDirection(PageRequest of, String programStudyDirection) { + // return repo.findByProgramStudyDirection(PageRequest.of(of.getPageNumber(), of.getPageSize()), programStudyDirection); + // } + // public Page findByProgramPrice(PageRequest of, String programPrice) { + // return repo.findByProgramPrice(PageRequest.of(of.getPageNumber(), of.getPageSize()), programPrice); + // } + // public Page findByBuildingNameFull(PageRequest of, String buildingNameFull) { + // return repo.findByBuildingNameFull(PageRequest.of(of.getPageNumber(), of.getPageSize()), buildingNameFull); + // } + // public Page findByBuildingCodeFull(PageRequest of, String buildingCodeFull) { + // return repo.findByBuildingCodeFull(PageRequest.of(of.getPageNumber(), of.getPageSize()), buildingCodeFull); + // } + +} diff --git a/Описание.docx b/Описание.docx new file mode 100644 index 0000000..0eb336f Binary files /dev/null and b/Описание.docx differ