diff --git a/client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/controllers/BuildingController.java b/client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/controllers/BuildingController.java index 3759065..082db9d 100644 --- a/client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/controllers/BuildingController.java +++ b/client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/controllers/BuildingController.java @@ -22,7 +22,6 @@ import com.fasterxml.jackson.databind.JsonMappingException; import reactor.core.publisher.Mono; import ru.molokoin.clientserviceteachers.entities.Building; -import ru.molokoin.clientserviceteachers.entities.Teacher; @Controller @RequestMapping(path = "/") @@ -99,7 +98,7 @@ public class BuildingController { produces = { MediaType.APPLICATION_JSON_VALUE }) - public String updateTeacher(@PathVariable Long id + public String updateBuilding(@PathVariable Long id , @ModelAttribute("b") @Validated Building building) throws JsonMappingException, JsonProcessingException{ System.out.println(">>>>>>>>>>>>>> ####################### <<<<<<<<<<<<<<<<<<<<"); System.out.println(">>>>>>>>>>>>>> ####################### <<<<<<<<<<<<<<<<<<<<"); diff --git a/client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/controllers/OrganizationController.java b/client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/controllers/OrganizationController.java new file mode 100644 index 0000000..45c06a7 --- /dev/null +++ b/client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/controllers/OrganizationController.java @@ -0,0 +1,124 @@ +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.Organization; + +@Controller +@RequestMapping(path = "/") +public class OrganizationController { + @Autowired + private WebClient client; + + /** + * Получение страницы списка организаций + * @param model + * @return + * @throws JsonMappingException + * @throws JsonProcessingException + */ + @GetMapping("/organizations") + public String organizationList(Model model) throws JsonMappingException, JsonProcessingException{ + List organizations = client.method(HttpMethod.GET) + .uri("/organization/list") + .retrieve() + .bodyToMono(new ParameterizedTypeReference >(){}) + .block(); + + model.addAttribute("organization_list", organizations); + model.addAttribute("org", new Organization()); + System.out.println("ORGANIZATIONS:" + organizations.toString()); + return "organizations"; + } + + @GetMapping("/organization-edit/{id}") + public String organizationById(Model model, @PathVariable Long id) { + Organization org = client.get() + .uri("/organization/" + id) + .retrieve() + .bodyToMono(Organization.class) + .timeout(Duration.ofSeconds(1)) + .block(); + model.addAttribute("organization", org); + return "organization-edit"; + } + + @PostMapping( + path = "/organization/add", + consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, + produces = { + MediaType.APPLICATION_JSON_VALUE + }) + public String addOrganization(@ModelAttribute("org") @Validated Organization organization) throws JsonMappingException, JsonProcessingException{ + client.post() + .uri("/organization/create") + .body(Mono.just(organization), Organization.class) + .retrieve() + .toBodilessEntity() + .timeout(Duration.ofSeconds(1)) + .block(); + return "redirect:/organizations"; + } + + @GetMapping(path = "/organization/add") + public String addOrganizationFrame(Model model){ + Organization organization = new Organization(); + model.addAttribute("newOrganization", organization); + return "organization-add"; + } + + @GetMapping(path = "/organization/delete/{id}") + public String deleteOrganization(@PathVariable Long id) throws JsonMappingException, JsonProcessingException{ + client.delete() + .uri("/organization/delete/" + id) + .retrieve() + .bodyToMono(String.class) + .timeout(Duration.ofSeconds(1)) + .block(); + return "redirect:/organizations"; + } + + @PostMapping( + path = "/organization/update/{id}", + consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, + produces = { + MediaType.APPLICATION_JSON_VALUE + }) + public String updateOrganization(@PathVariable Long id + , @ModelAttribute("org") @Validated Organization organization) throws JsonMappingException, JsonProcessingException{ + System.out.println(">>>>>>>>>>>>>> ####################### <<<<<<<<<<<<<<<<<<<<"); + System.out.println(">>>>>>>>>>>>>> ####################### <<<<<<<<<<<<<<<<<<<<"); + System.out.println(">>>>>>>>>>>>>>" + organization.toString()); + client.post() + .uri("/organization/update/" + organization.getId()) + .body(Mono.just(organization), Organization.class) + .retrieve() + .toBodilessEntity() + .timeout(Duration.ofSeconds(1)) + .block(); + return "redirect:/organizations"; + } + + + +} diff --git a/client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/entities/Building.java b/client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/entities/Building.java index d1deeb3..02e70b2 100644 --- a/client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/entities/Building.java +++ b/client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/entities/Building.java @@ -26,5 +26,4 @@ public class Building implements Serializable{ this.code_short = code_short; this.code_full = code_full; } - } diff --git a/client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/entities/Organization.java b/client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/entities/Organization.java new file mode 100644 index 0000000..cc8f0b5 --- /dev/null +++ b/client-service-teachers/src/main/java/ru/molokoin/clientserviceteachers/entities/Organization.java @@ -0,0 +1,38 @@ +package ru.molokoin.clientserviceteachers.entities; + +import java.io.Serializable; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * Сущность организации + */ +@NoArgsConstructor +@AllArgsConstructor +@Data +public class Organization implements Serializable{ + private long id; + private String ownership;//Форма собственности ПСК + private String name_short;//Сокращенное наименование + private String name_full;//Полное наименование + private String type;//вид ПСК - производственная/сервисная + private String inn;//ИНН организации + + /** + * Конструктор без id + * @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/client-service-teachers/src/main/resources/templates/organization-add.html b/client-service-teachers/src/main/resources/templates/organization-add.html new file mode 100644 index 0000000..62d87d6 --- /dev/null +++ b/client-service-teachers/src/main/resources/templates/organization-add.html @@ -0,0 +1,50 @@ + + + + + Organization + + + + +
+ edit : Organization +
+
+

Добавление записи о новой организации:

+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+ +
+
+
+ +
+
+ \ No newline at end of file diff --git a/client-service-teachers/src/main/resources/templates/organization-edit.html b/client-service-teachers/src/main/resources/templates/organization-edit.html new file mode 100644 index 0000000..2a095ba --- /dev/null +++ b/client-service-teachers/src/main/resources/templates/organization-edit.html @@ -0,0 +1,49 @@ + + + + + Organizations + + + + +
+ edit : Organization +
+
+

Редактирование сведений об организации:

+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+
+ +
+
+ \ No newline at end of file diff --git a/client-service-teachers/src/main/resources/templates/organizations.html b/client-service-teachers/src/main/resources/templates/organizations.html new file mode 100644 index 0000000..5587848 --- /dev/null +++ b/client-service-teachers/src/main/resources/templates/organizations.html @@ -0,0 +1,71 @@ + + + + + Organizations + + + + +
+

ORGANIZATIONS

+ menu : auth : Organizations +
+
+
+
+

Перечень объектов строительства:

+
+ + + + + + + + + + + + + + + + + + + + + + + +
idownershipname_shortname_fulltypeinn +
+ +
+
+ + + + + + + + + + + + +
+ +
+
+ +
+
+ +
+
+ + 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 index e3447f3..126e0ee 100644 --- 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 @@ -20,11 +20,11 @@ public class Organization { @Id @GeneratedValue(strategy=GenerationType.AUTO) private long id; - private String ownership; + private String ownership;//Форма собственности ПСК private String name_short;//Сокращенное наименование private String name_full;//Полное наименование - private String type; - private String inn; + private String type;//вид ПСК - производственная/сервисная + private String inn;//ИНН организации /** * подготовить конструкторы на все варианты внесения информации о преподавателях