|
|
|
@ -1,22 +1,29 @@
@@ -1,22 +1,29 @@
|
|
|
|
|
package ru.mlokoin.gates.controller.v1; |
|
|
|
|
|
|
|
|
|
import java.time.Duration; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.http.MediaType; |
|
|
|
|
import org.springframework.stereotype.Controller; |
|
|
|
|
import org.springframework.ui.Model; |
|
|
|
|
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 reactor.core.publisher.Mono; |
|
|
|
|
import ru.mlokoin.gates.model.building.Building; |
|
|
|
|
import ru.mlokoin.gates.model.course.Course; |
|
|
|
|
import ru.mlokoin.gates.model.course.CourseWraper; |
|
|
|
|
import ru.mlokoin.gates.model.education.EducationEntryWraper; |
|
|
|
|
import ru.mlokoin.gates.model.education.EducatonEntry; |
|
|
|
|
import ru.mlokoin.gates.model.fs.xlsx.XlsxDocument; |
|
|
|
|
import ru.mlokoin.gates.model.fs.xlsx.XlsxDocumentReestr; |
|
|
|
|
import ru.mlokoin.gates.model.monitoring.EducationsReview; |
|
|
|
|
import ru.mlokoin.gates.model.organization.Organization; |
|
|
|
|
import ru.mlokoin.gates.model.program.Program; |
|
|
|
|
import ru.mlokoin.gates.model.student.Student; |
|
|
|
@ -24,7 +31,7 @@ import ru.mlokoin.gates.model.teacher.Teacher;
@@ -24,7 +31,7 @@ import ru.mlokoin.gates.model.teacher.Teacher;
|
|
|
|
|
import ru.mlokoin.gates.repository.Storage; |
|
|
|
|
|
|
|
|
|
@Controller |
|
|
|
|
@RequestMapping(path = "/") |
|
|
|
|
@RequestMapping(path = "/document/educations") |
|
|
|
|
public class EducationsController { |
|
|
|
|
@Autowired |
|
|
|
|
private WebClient client; |
|
|
|
@ -42,7 +49,7 @@ public class EducationsController {
@@ -42,7 +49,7 @@ public class EducationsController {
|
|
|
|
|
* @param xlsxEducations TODO |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
@GetMapping("/document/view-as-educations/{id}") |
|
|
|
|
@GetMapping("/view/{id}") |
|
|
|
|
public String viewAsEducations(Model model, @PathVariable String id) { |
|
|
|
|
|
|
|
|
|
// создание списка ошибок
|
|
|
|
@ -151,8 +158,35 @@ public class EducationsController {
@@ -151,8 +158,35 @@ public class EducationsController {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//фильтрация записей уже присутствующих в базе
|
|
|
|
|
List<EducatonEntry> filtered = new ArrayList<>(xlsx_educations); |
|
|
|
|
List<EducatonEntry> filtered = new ArrayList<>(); |
|
|
|
|
for (EducatonEntry xlsx_entry : xlsx_educations) { |
|
|
|
|
if (xlsx_entry != null) { |
|
|
|
|
if (xlsx_entry.getStudent() != null |
|
|
|
|
|| xlsx_entry.getCourse() != null) { |
|
|
|
|
if (!filtered.contains(xlsx_entry)) { |
|
|
|
|
boolean exists = false; |
|
|
|
|
for (EducatonEntry base_entry : base_educations) { |
|
|
|
|
if (base_entry.getSertificate_number().equals(xlsx_entry.getSertificate_number()) |
|
|
|
|
&& base_entry.getCourse().getProtocol_number().equals(xlsx_entry.getCourse().getProtocol_number()) |
|
|
|
|
&& base_entry.getCourse().getPlace().equals(xlsx_entry.getCourse().getPlace()) |
|
|
|
|
&& base_entry.getCourse().getStart_date().equals(xlsx_entry.getCourse().getStart_date()) |
|
|
|
|
&& base_entry.getCourse().getTeacher().getFullName().equals(xlsx_entry.getCourse().getTeacher().getFullName()) |
|
|
|
|
&& base_entry.getCourse().getBuilding().getName_short().equals(xlsx_entry.getCourse().getBuilding().getName_short()) |
|
|
|
|
&& base_entry.getCourse().getProgram().getName().equals(xlsx_entry.getCourse().getProgram().getName())) { |
|
|
|
|
|
|
|
|
|
exists = true; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (!exists) { |
|
|
|
|
filtered.add(xlsx_entry); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//ограничение количества выводимых пользователю записей
|
|
|
|
|
if (filtered.size() > 0) { |
|
|
|
|
if (filtered.size() > 200) { |
|
|
|
|
filtered = filtered.subList(0, 200); |
|
|
|
@ -163,6 +197,7 @@ public class EducationsController {
@@ -163,6 +197,7 @@ public class EducationsController {
|
|
|
|
|
wraper.setStudents(base_students); |
|
|
|
|
|
|
|
|
|
//передача данных в модель
|
|
|
|
|
model.addAttribute("review", new EducationsReview()); |
|
|
|
|
model.addAttribute("wrapEducations", wraper); |
|
|
|
|
model.addAttribute("errors", errors); |
|
|
|
|
model.addAttribute("filename", xlsxEducations.getDocument().getName()); |
|
|
|
@ -171,4 +206,31 @@ public class EducationsController {
@@ -171,4 +206,31 @@ public class EducationsController {
|
|
|
|
|
// model.addAttribute("headers", xlsx.getHeaders());
|
|
|
|
|
return "view-as-educations"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@PostMapping( |
|
|
|
|
path="/save/{id}", |
|
|
|
|
consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, |
|
|
|
|
produces = MediaType.APPLICATION_JSON_VALUE |
|
|
|
|
) |
|
|
|
|
public String saveEducations(Model model, @ModelAttribute("wrapEducations") EducationEntryWraper wraper, @PathVariable String id) { |
|
|
|
|
List<EducatonEntry> educations = wraper.getEducations(); |
|
|
|
|
if (educations.size() > 0) { |
|
|
|
|
for (EducatonEntry education : educations) { |
|
|
|
|
try { |
|
|
|
|
client.post() |
|
|
|
|
.uri("http://resource-service-api:8181/education/create") |
|
|
|
|
.body(Mono.just(education), EducatonEntry.class) |
|
|
|
|
.retrieve() |
|
|
|
|
.toBodilessEntity() |
|
|
|
|
.timeout(Duration.ofSeconds(2)) |
|
|
|
|
.block(); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
System.out.println("Не удалось добавить запись об обучении в базу: " + e.getMessage()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return "redirect:/document/educations/view/" + id; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|