esoe 2 months ago
parent
commit
99bea206f9
  1. 12
      gates/src/main/java/ru/mlokoin/gates/controller/v1/OrganizationController.java
  2. 2
      gates/src/main/java/ru/mlokoin/gates/controller/v1/ProgramController.java
  3. 2
      gates/src/main/java/ru/mlokoin/gates/model/fs/xlsx/XlsxDocumentReestr.java
  4. 12
      gates/src/main/java/ru/mlokoin/gates/model/organization/Organization.java
  5. 6
      gates/src/main/java/ru/mlokoin/gates/model/program/Program.java
  6. 2
      gates/src/main/java/ru/mlokoin/gates/model/student/Student.java
  7. 4
      gates/src/main/java/ru/mlokoin/gates/repository/Storage.java
  8. 213
      resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/controllers/api/CourseController.java
  9. 4
      resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/enums/Base.java
  10. 34
      resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/enums/Courses.java
  11. 43
      resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/repositories/CourseRepository.java
  12. 12
      resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/repositories/CourseRepositoryFace.java
  13. 1
      resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/repositories/ProgramCretareaRepository.java
  14. 173
      resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/services/CourseService.java
  15. BIN
      Описание.docx

12
gates/src/main/java/ru/mlokoin/gates/controller/v1/OrganizationController.java

@ -63,7 +63,7 @@ public class OrganizationController {
} }
Organization organization = new Organization(); Organization organization = new Organization();
organization.setName_full(string); organization.setNameFull(string);
xlsx_orgs.add(organization); xlsx_orgs.add(organization);
} }
xlsx_orgs.remove(0);//Удалили из списка заголовок xlsx_orgs.remove(0);//Удалили из списка заголовок
@ -73,7 +73,7 @@ public class OrganizationController {
System.out.println("###############################"); System.out.println("###############################");
System.out.println(">> Организации из файла: " + xlsx_orgSet.size()); System.out.println(">> Организации из файла: " + xlsx_orgSet.size());
for (Organization organization : xlsx_orgSet) { 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<String> base_organizations_str = new HashSet<>(); Set<String> base_organizations_str = new HashSet<>();
for (Organization o : xlsx_orgSet) { for (Organization o : xlsx_orgSet) {
String s = o.getName_full(); String s = o.getNameFull();
xlsx_organizations_str.add(s); xlsx_organizations_str.add(s);
} }
System.out.println("Организации в базе:"); System.out.println("Организации в базе:");
for (Organization o : base_organizations) { for (Organization o : base_organizations) {
String s = o.getName_full(); String s = o.getNameFull();
System.out.println("base_organizations : " + s); System.out.println("base_organizations : " + s);
base_organizations_str.add(s); base_organizations_str.add(s);
} }
@ -114,7 +114,7 @@ public class OrganizationController {
ArrayList<Organization> list = new ArrayList<>(); ArrayList<Organization> list = new ArrayList<>();
for (String string : xlsx_organizations_str) { for (String string : xlsx_organizations_str) {
Organization o = new Organization(); Organization o = new Organization();
o.setName_full(string); o.setNameFull(string);
list.add(o); list.add(o);
} }
@ -138,7 +138,7 @@ public class OrganizationController {
for (Organization organization : wraper.getList()) { for (Organization organization : wraper.getList()) {
//Проверка наличия флага для добавления в базу //Проверка наличия флага для добавления в базу
//по полю табельного номера //по полю табельного номера
if (organization.getName_full() != ""){ if (organization.getNameFull() != ""){
client.post() client.post()
.uri("http://resource-service-api:8181/organization/create") .uri("http://resource-service-api:8181/organization/create")
.body(Mono.just(organization), Organization.class) .body(Mono.just(organization), Organization.class)

2
gates/src/main/java/ru/mlokoin/gates/controller/v1/ProgramController.java

@ -127,7 +127,7 @@ public class ProgramController {
//проверка наличия длительности программы //проверка наличия длительности программы
if (program.getLenght() != null) { if (program.getLenght() != null) {
//проверка наличия направления обучения //проверка наличия направления обучения
if (!program.getStudy_direction().equals("")){ if (!program.getStudyDirection().equals("")){
//проверка наличия критерия //проверка наличия критерия
if (program.getCretarea() != null){ if (program.getCretarea() != null){
client.post() client.post()

2
gates/src/main/java/ru/mlokoin/gates/model/fs/xlsx/XlsxDocumentReestr.java

@ -179,7 +179,7 @@ public class XlsxDocumentReestr extends XlsxDocument {
List<Organization> organizations = getOrganizationsAsIs(); List<Organization> organizations = getOrganizationsAsIs();
List<Organization> unique = new ArrayList<>(); List<Organization> unique = new ArrayList<>();
for (Organization organization : organizations) { for (Organization organization : organizations) {
if (!unique.contains(organization) && organization.getName_full() != "") { if (!unique.contains(organization) && organization.getNameFull() != "") {
unique.add(organization); unique.add(organization);
} }
} }

12
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{ public class Organization implements Serializable{
private long id; private long id;
private String ownership;//Форма собственности ПСК private String ownership;//Форма собственности ПСК
private String name_short;//Сокращенное наименование private String nameShort;//Сокращенное наименование
private String name_full;//Полное наименование private String nameFull;//Полное наименование
private String type;//вид ПСК - производственная/сервисная private String type;//вид ПСК - производственная/сервисная
private String inn;//ИНН организации 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) { public Organization(String ownership, String name_short, String name_full, String type, String inn) {
this.ownership = ownership; this.ownership = ownership;
this.name_short = name_short; this.nameShort = name_short;
this.name_full = name_full; this.nameFull = name_full;
this.type = type; this.type = type;
this.inn = inn; this.inn = inn;
} }
public Organization(Entry<Integer, List<XlsxCell>> entry) { public Organization(Entry<Integer, List<XlsxCell>> 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) { public boolean isSimilar(Organization organization) {
return this.getName_full().equals(organization.getName_full()); return this.getNameFull().equals(organization.getNameFull());
} }
} }

6
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 Integer price;//рублей
private ProgramCretarea cretarea; private ProgramCretarea cretarea;
@ -42,7 +42,7 @@ public class Program {
public Program(String name, Integer lenght, String study_direction, Integer price, ProgramCretarea cretarea) { public Program(String name, Integer lenght, String study_direction, Integer price, ProgramCretarea cretarea) {
this.name = name; this.name = name;
this.lenght = lenght; this.lenght = lenght;
this.study_direction = study_direction; this.studyDirection = study_direction;
this.price = price; this.price = price;
this.cretarea = cretarea; 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 { try {

2
gates/src/main/java/ru/mlokoin/gates/model/student/Student.java

@ -86,7 +86,7 @@ public class Student implements Serializable{
if (base_organizations != null) { if (base_organizations != null) {
this.organization = base_organizations this.organization = base_organizations
.stream() .stream()
.filter(org -> org.getName_full().equals(organization)) .filter(org -> org.getNameFull().equals(organization))
.findFirst() .findFirst()
.orElse(null); .orElse(null);
} else { } else {

4
gates/src/main/java/ru/mlokoin/gates/repository/Storage.java

@ -571,7 +571,7 @@ public class Storage {
for (Organization xlsxOrganization : xlsxList) { for (Organization xlsxOrganization : xlsxList) {
for (Organization baseOrganization : baseList) { for (Organization baseOrganization : baseList) {
if (xlsxOrganization.getName_full().equals(baseOrganization.getName_full())) { if (xlsxOrganization.getNameFull().equals(baseOrganization.getNameFull())) {
result.remove(xlsxOrganization); result.remove(xlsxOrganization);
break; break;
} }
@ -616,7 +616,7 @@ public class Storage {
&& xlsxStudent.getProfession().equals(baseStudent.getProfession()) && xlsxStudent.getProfession().equals(baseStudent.getProfession())
&& xlsxStudent.getDirection().equals(baseStudent.getDirection()) && xlsxStudent.getDirection().equals(baseStudent.getDirection())
&& xlsxStudent.getProfession().equals(baseStudent.getProfession()) && xlsxStudent.getProfession().equals(baseStudent.getProfession())
&& xlsxStudent.getOrganization().getName_full().equals(baseStudent.getOrganization().getName_full())) { && xlsxStudent.getOrganization().getNameFull().equals(baseStudent.getOrganization().getNameFull())) {
result.remove(xlsxStudent); result.remove(xlsxStudent);
break; break;
} }

213
resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/controllers/api/CourseController.java

@ -1,8 +1,14 @@
package ru.molokoin.resourceserviceapi.controllers.api; package ru.molokoin.resourceserviceapi.controllers.api;
import java.util.ArrayList;
import java.util.Date;
import java.util.List; import java.util.List;
import org.springframework.beans.factory.annotation.Autowired; 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.HttpStatus;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; 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.PutMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import ru.molokoin.resourceserviceapi.entities.Course; 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 @RestController
@RequestMapping(path = "/", consumes = {"*/*"}) @RequestMapping(path = "/api/course", consumes = {"*/*"})
public class CourseController { public class CourseController {
@Autowired @Autowired
private CourseRepositoryFace repo; private CourseService repo;
@GetMapping("/course/list") public CourseController(CourseService repo) {
public ResponseEntity<List<Course>> getCourses(){ this.repo = repo;
return new ResponseEntity<>(repo.findAll(), HttpStatus.OK);
} }
@GetMapping("/course/{id}") @GetMapping("/pages")
public ResponseEntity<?> getCourseByID(@PathVariable Integer id){ public Page<Course> courses(@RequestParam(name="page", defaultValue = "0") int pageNo,
return new ResponseEntity<>(repo.findById(id), HttpStatus.OK); @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<Long> 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> 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, consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE) produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> saveCourse(@RequestBody Course course) { public ResponseEntity<?> saveCourse(@RequestBody Course course) {
@ -42,7 +221,7 @@ public class CourseController {
return new ResponseEntity<>(course, HttpStatus.CREATED); return new ResponseEntity<>(course, HttpStatus.CREATED);
} }
@PutMapping(path = "/course/update/{id}", @PutMapping(path = "/update/{id}",
consumes = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE) produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> updateCourse(@PathVariable Integer id, @RequestBody Course course) { public ResponseEntity<?> updateCourse(@PathVariable Integer id, @RequestBody Course course) {
@ -59,11 +238,21 @@ public class CourseController {
return new ResponseEntity<>(repo.findById(id), HttpStatus.CREATED); return new ResponseEntity<>(repo.findById(id), HttpStatus.CREATED);
} }
@DeleteMapping("/course/delete/{id}") @DeleteMapping("/delete/{id}")
public ResponseEntity<String> deleteCourse(@PathVariable Long id){ public ResponseEntity<String> deleteCourse(@PathVariable Long id){
Course c = repo.findById(id).get(); Course c = repo.findById(id).get();
System.out.println(c.toString()); System.out.println(c.toString());
repo.delete(c); repo.delete(c);
return new ResponseEntity<>("Запись id#" + id + " удалена ... ", HttpStatus.OK); return new ResponseEntity<>("Запись id#" + id + " удалена ... ", HttpStatus.OK);
} }
// @GetMapping("/list")
// public ResponseEntity<List<Course>> getCourses(){
// return new ResponseEntity<>(repo.findAll(), HttpStatus.OK);
// }
// @GetMapping("/{id}")
// public ResponseEntity<?> getCourseByID(@PathVariable Integer id){
// return new ResponseEntity<>(repo.findById(id), HttpStatus.OK);
// }
} }

4
resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/enums/Base.java

@ -10,8 +10,8 @@ public enum Base {
ORGANIZATIONS (Organizations.getTitles()), ORGANIZATIONS (Organizations.getTitles()),
// EDUCATIONS (Educations.getTitles()), // EDUCATIONS (Educations.getTitles()),
BUILDINGS (Buildings.getTitles()), BUILDINGS (Buildings.getTitles()),
CRETAREAS (Cretareas.getTitles()); CRETAREAS (Cretareas.getTitles()),
// COURSES (Courses.getTitles()), COURSES (Courses.getTitles());
// POSTS (Posts.getTitles()), // POSTS (Posts.getTitles()),
// STORES (Stores.getTitles()); // STORES (Stores.getTitles());

34
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<String> getTitles() {
return Arrays.stream(Courses.values())
.map(Courses::column)
.collect(Collectors.toList());
}
}

43
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<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);
}

12
resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/repositories/CourseRepositoryFace.java

@ -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);
}

1
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.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import ru.molokoin.resourceserviceapi.entities.Program;
import ru.molokoin.resourceserviceapi.entities.ProgramCretarea; import ru.molokoin.resourceserviceapi.entities.ProgramCretarea;
@Repository @Repository

173
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<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);
// }
}

BIN
Описание.docx

Binary file not shown.
Loading…
Cancel
Save