diff --git a/client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/controllers/CourseController.java b/client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/controllers/CourseController.java new file mode 100644 index 0000000..922952b --- /dev/null +++ b/client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/controllers/CourseController.java @@ -0,0 +1,201 @@ +package ru.molokoin.clientserviceteachers.controllers; + +import java.time.Duration; +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.HttpMethod; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.reactive.function.client.WebClient; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; + +import reactor.core.publisher.Mono; +import ru.molokoin.clientserviceteachers.entities.Building; +import ru.molokoin.clientserviceteachers.entities.Course; +import ru.molokoin.clientserviceteachers.entities.Program; +import ru.molokoin.clientserviceteachers.entities.ProgramCretarea; +import ru.molokoin.clientserviceteachers.entities.Teacher; + +@Controller +@RequestMapping(path = "/") +public class CourseController { + @Autowired + private WebClient client; + + @GetMapping("/courses") + public String courseList(Model model) throws JsonMappingException, JsonProcessingException{ + List courses = client.method(HttpMethod.GET) + .uri("/course/list") + .retrieve() + .bodyToMono(new ParameterizedTypeReference >(){}) + .block(); + + model.addAttribute("courses", courses); + model.addAttribute("cs", new Course()); + System.out.println("COURCES:" + courses.toString()); + return "courses"; + } + + @GetMapping("/course-edit/{id}") + public String courseById(Model model, @PathVariable Long id) { + /** + * получение списка преподавателей (Class.Teacher) из ресурсов + * - для select поля формы + */ + List teachers = client.get() + .uri("/teacher/list") + .retrieve() + .bodyToMono(new ParameterizedTypeReference >(){}) + .timeout(Duration.ofSeconds(1)) + .block(); + model.addAttribute("teachers", teachers); + + /** + * получение списка программ обучения (Class.Program) из ресурсов + * - для select поля формы + */ + List programs = client.get() + .uri("/program/list") + .retrieve() + .bodyToMono(new ParameterizedTypeReference >(){}) + .timeout(Duration.ofSeconds(1)) + .block(); + model.addAttribute("programs", programs); + + /** + * получение списка объектов строительства (Class.Building) из ресурсов + * - для select поля формы + */ + List buildings = client.get() + .uri("/building/list") + .retrieve() + .bodyToMono(new ParameterizedTypeReference >(){}) + .timeout(Duration.ofSeconds(1)) + .block(); + model.addAttribute("buildings", buildings); + + /** + * Получение сведений о курсе (Class.Course) из ресурсов + * - для отображения на редактирование в форме course-edit + */ + Course course = client.get() + .uri("/course/" + id) + .retrieve() + .bodyToMono(Course.class) + .timeout(Duration.ofSeconds(1)) + .block(); + model.addAttribute("course", course); + return "course-edit"; + } + + /** + * Отправка данных заполненной формы курса на сервер + * @param model + * @param course + * @return + * @throws JsonMappingException + * @throws JsonProcessingException + */ + @PostMapping( + path = "/course/add", + consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, + produces = { + MediaType.APPLICATION_JSON_VALUE + }) + public String addCourse(Model model, @ModelAttribute("course") @Validated Course course) throws JsonMappingException, JsonProcessingException{ + client.post() + .uri("/course/create") + .body(Mono.just(course), Course.class) + .retrieve() + .toBodilessEntity() + .timeout(Duration.ofSeconds(1)) + .block(); + return "redirect:/courses"; + } + + @GetMapping(path = "/course/add") + public String addCourseFrame(Model model){ + /** + * получение списка преподавателей (Class.Teacher) из ресурсов + * - для select поля формы + */ + List teachers = client.get() + .uri("/teacher/list") + .retrieve() + .bodyToMono(new ParameterizedTypeReference >(){}) + .timeout(Duration.ofSeconds(1)) + .block(); + model.addAttribute("teachers", teachers); + + /** + * получение списка программ обучения (Class.Program) из ресурсов + * - для select поля формы + */ + List programs = client.get() + .uri("/program/list") + .retrieve() + .bodyToMono(new ParameterizedTypeReference >(){}) + .timeout(Duration.ofSeconds(1)) + .block(); + model.addAttribute("programs", programs); + + /** + * получение списка объектов строительства (Class.Building) из ресурсов + * - для select поля формы + */ + List buildings = client.get() + .uri("/building/list") + .retrieve() + .bodyToMono(new ParameterizedTypeReference >(){}) + .timeout(Duration.ofSeconds(1)) + .block(); + model.addAttribute("buildings", buildings); + + Course course = new Course(); + model.addAttribute("newCourse", course); + return "course-add"; + } + + @GetMapping(path = "/course/delete/{id}") + public String deleteCourse(@PathVariable Long id) throws JsonMappingException, JsonProcessingException{ + client.delete() + .uri("/course/delete/" + id) + .retrieve() + .bodyToMono(String.class) + .timeout(Duration.ofSeconds(1)) + .block(); + return "redirect:/courses"; + } + + @PostMapping( + path = "/course/update/{id}", + consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, + produces = { + MediaType.APPLICATION_JSON_VALUE + }) + public String updateCourse(@PathVariable Long id + , @ModelAttribute("cs") @Validated Course course) throws JsonMappingException, JsonProcessingException{ + client.post() + .uri("/course/update/" + course.getId()) + .body(Mono.just(course), Course.class) + .retrieve() + .toBodilessEntity() + .timeout(Duration.ofSeconds(1)) + .block(); + return "redirect:/courses"; + } + + + +} diff --git a/client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/controllers/ProgramController.java b/client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/controllers/ProgramController.java index fd574ad..20130ab 100644 --- a/client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/controllers/ProgramController.java +++ b/client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/controllers/ProgramController.java @@ -32,7 +32,7 @@ public class ProgramController { private WebClient client; @GetMapping("/programs") - public String teacherList(Model model) throws JsonMappingException, JsonProcessingException{ + public String programList(Model model) throws JsonMappingException, JsonProcessingException{ List programs = client.method(HttpMethod.GET) .uri("/program/list") .retrieve() @@ -46,9 +46,10 @@ public class ProgramController { } @GetMapping("/program-edit/{id}") - public String teacherById(Model model, @PathVariable Long id) { + public String programById(Model model, @PathVariable Long id) { /** - * получение критериев из ресурсов + * получение списка критериев из ресурсов + * - для select поля формы */ List pcl = client.get() .uri("/cretarea/list") @@ -102,7 +103,7 @@ public class ProgramController { } @GetMapping(path = "/program/add") - public String addTeacherFrame(Model model){ + public String addProgramFrame(Model model){ /** * получение критериев из ресурсов */ @@ -120,7 +121,7 @@ public class ProgramController { } @GetMapping(path = "/program/delete/{id}") - public String deleteTeacher(@PathVariable Long id) throws JsonMappingException, JsonProcessingException{ + public String deleteProgram(@PathVariable Long id) throws JsonMappingException, JsonProcessingException{ client.delete() .uri("/program/delete/" + id) .retrieve() @@ -136,7 +137,7 @@ public class ProgramController { produces = { MediaType.APPLICATION_JSON_VALUE }) - public String updateTeacher(@PathVariable Long id + public String updateProgram(@PathVariable Long id , @ModelAttribute("p") @Validated Program program) throws JsonMappingException, JsonProcessingException{ client.post() .uri("/teacher/update/" + program.getId()) @@ -147,7 +148,4 @@ public class ProgramController { .block(); return "redirect:/programs"; } - - - } diff --git a/client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/entities/Course.java b/client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/entities/Course.java new file mode 100644 index 0000000..f170cef --- /dev/null +++ b/client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/entities/Course.java @@ -0,0 +1,45 @@ +package ru.molokoin.clientserviceteachers.entities; + +import java.util.Date; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@NoArgsConstructor +@AllArgsConstructor +@Data +public class Course { + private long id;//уникальный идентификатор курса + private String place;//место проведения занятий + private Date start_date;//дата начала курса + private Date protocol_date;//дата протокола + private String protocol_number;//номер протоколаssss + private String report_period;//отчетный период (наименование месяца) + private Teacher teacher;//сведения о преподаватле + private Program program;//сведения о программе обучения + private Building building;//сведения об объекте строительства + + /** + * Конструктор без id + * @param place + * @param start_date + * @param protocol_date + * @param protocol_number + * @param report_period + * @param teacher + * @param program + * @param building + */ + public Course(String place, Date start_date, Date protocol_date, String protocol_number, String report_period, + Teacher teacher, Program program, Building building) { + this.place = place; + this.start_date = start_date; + this.protocol_date = protocol_date; + this.protocol_number = protocol_number; + this.report_period = report_period; + this.teacher = teacher; + this.program = program; + this.building = building; + } +} diff --git a/client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/entities/Program.java b/client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/entities/Program.java index ede41e6..b0c4f85 100644 --- a/client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/entities/Program.java +++ b/client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/entities/Program.java @@ -1,6 +1,5 @@ package ru.molokoin.clientserviceteachers.entities; -import jakarta.annotation.Nullable; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; diff --git a/client-service-teachers/src/main/resources/application.yaml b/client-service-teachers/src/main/resources/application.yaml index 0abd80a..624696b 100644 --- a/client-service-teachers/src/main/resources/application.yaml +++ b/client-service-teachers/src/main/resources/application.yaml @@ -13,5 +13,9 @@ spring: hiddenmethod: filter: enabled: true + format: + date: yyyy-MM-dd + date-time: yyyy-MM-dd HH:mm:ss + time: HH:mm:ss diff --git a/client-service-teachers/src/main/resources/templates/course-add.html b/client-service-teachers/src/main/resources/templates/course-add.html new file mode 100644 index 0000000..2944c38 --- /dev/null +++ b/client-service-teachers/src/main/resources/templates/course-add.html @@ -0,0 +1,70 @@ + + + + + Course-add + + + + +
+ add : course +
+
+

Добавление нового курса:

+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+
+ +
+
+ \ No newline at end of file diff --git a/client-service-teachers/src/main/resources/templates/course-edit.html b/client-service-teachers/src/main/resources/templates/course-edit.html new file mode 100644 index 0000000..e69de29 diff --git a/client-service-teachers/src/main/resources/templates/courses.html b/client-service-teachers/src/main/resources/templates/courses.html new file mode 100644 index 0000000..2621e99 --- /dev/null +++ b/client-service-teachers/src/main/resources/templates/courses.html @@ -0,0 +1,85 @@ + + + + + Courses + + + + + +
+

COURSES

+ menu : auth : courses +
+
+
+
+

Перечень курсов:

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
idplacestart_dateprotocol_dateprotocol_numberreport_periodteacherprogrambuilding + +
+ +
+
+ + + + + + + + + + + + + + + + + + +
+ +
+
+ +
+
+ +
+
+ + \ No newline at end of file diff --git a/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/controllers/OrganizationController.java b/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/controllers/OrganizationController.java new file mode 100644 index 0000000..dd56969 --- /dev/null +++ b/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/controllers/OrganizationController.java @@ -0,0 +1,89 @@ +package ru.molokoin.resourceserviceapi.controllers; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import ru.molokoin.resourceserviceapi.entities.Organization; +import ru.molokoin.resourceserviceapi.repositories.OrganizationFace; + +@RestController +@RequestMapping(path = "/", consumes = {"*/*"}) +public class OrganizationController { + @Autowired + private OrganizationFace repo; + + /** + * Получение списа организаций + * @return + */ + @GetMapping("/organization/list") + public ResponseEntity> getOrganizations(){ + return new ResponseEntity<>(repo.findAll(), HttpStatus.OK); + } + + /** + * Получение сведений об организации по id + * @param id + * @return + */ + @GetMapping("/organization/{id}") + public ResponseEntity getOrganizationByID(@PathVariable Integer id){ + return new ResponseEntity<>(repo.findOrganizationById(id), HttpStatus.OK); + } + + /** + * Создание записи об организации + * @param organization + * @return + */ + @PostMapping(path = "/organization/create", + consumes = MediaType.APPLICATION_JSON_VALUE, + produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity saveOrganization(@RequestBody Organization organization) { + repo.save(organization); + return new ResponseEntity<>(organization, HttpStatus.CREATED); + } + + /** + * Обновление вседений об организации + * @param id + * @param organization + * @return + */ + @PostMapping(path = "/organization/update/{id}", + consumes = MediaType.APPLICATION_JSON_VALUE, + produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity updateOrganization(@PathVariable Integer id, @RequestBody Organization organization) { + Organization org = repo.findOrganizationById(id); + org.setOwnership(organization.getOwnership()); + org.setName_short(organization.getName_short()); + org.setName_full(organization.getName_full()); + org.setType(organization.getType()); + org.setInn(organization.getInn()); + repo.save(org); + return new ResponseEntity<>(repo.findOrganizationById(id), HttpStatus.CREATED); + } + + /** + * Удаление записи об организации + * @param id + * @return + */ + @DeleteMapping("/organization/delete/{id}") + public ResponseEntity deleteOrganization(@PathVariable Long id){ + Organization org = repo.findOrganizationById(id); + repo.delete(org); + return new ResponseEntity<>("Запись id#" + id + " удалена ... ", HttpStatus.OK); + } +} diff --git a/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/entities/Organization.java b/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/entities/Organization.java new file mode 100644 index 0000000..e3447f3 --- /dev/null +++ b/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/entities/Organization.java @@ -0,0 +1,44 @@ +package ru.molokoin.resourceserviceapi.entities; + +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * Сущность для хранения сведений об организации - контрагенте + * - ПСК + */ +@NoArgsConstructor +@AllArgsConstructor +@Entity +@Data +public class Organization { + @Id + @GeneratedValue(strategy=GenerationType.AUTO) + private long id; + private String ownership; + private String name_short;//Сокращенное наименование + private String name_full;//Полное наименование + private String type; + private String inn; + + /** + * подготовить конструкторы на все варианты внесения информации о преподавателях + * @param ownership + * @param name_short + * @param name_full + * @param type + * @param inn + */ + 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.type = type; + this.inn = inn; + } +} diff --git a/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/entities/Teacher.java b/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/entities/Teacher.java index 98fc1ef..b5360dd 100644 --- a/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/entities/Teacher.java +++ b/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/entities/Teacher.java @@ -1,7 +1,5 @@ package ru.molokoin.resourceserviceapi.entities; -import org.hibernate.engine.jdbc.SerializableBlobProxy; - import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; diff --git a/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/repositories/OrganizationFace.java b/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/repositories/OrganizationFace.java new file mode 100644 index 0000000..a020b71 --- /dev/null +++ b/resource-service-api/src/main/java/ru/molokoin/resourceserviceapi/repositories/OrganizationFace.java @@ -0,0 +1,15 @@ +package ru.molokoin.resourceserviceapi.repositories; + +import java.util.List; + +import org.springframework.data.repository.ListCrudRepository; +import org.springframework.stereotype.Repository; + + +import ru.molokoin.resourceserviceapi.entities.Organization; + +@Repository +public interface OrganizationFace extends ListCrudRepository{ + List findAll(); + Organization findOrganizationById(long id); +}