Compare commits

..

2 Commits

Author SHA1 Message Date
3791f10b8e #21 -- Fix save report 2025-04-05 23:48:36 +04:00
7d63899fb2 #21 -- Add save report mapping 2025-04-04 14:19:24 +04:00
6 changed files with 66 additions and 89 deletions

View File

@ -1,52 +0,0 @@
package ru.ulstu.admin.controller;
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.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import ru.ulstu.admin.model.ReportForm;
import ru.ulstu.admin.service.AdminReportService;
import java.util.List;
@Controller
@RequestMapping("/admin")
public class AdminReportController {
private final AdminReportService adminReportService;
public AdminReportController(AdminReportService adminReportService) {
this.adminReportService = adminReportService;
}
@GetMapping("/report")
public String getReportForm(Model model) {
ReportForm reportForm = new ReportForm();
//todo get current user aspirant id
//reportForm.setAspirantId(aspirantId); // Устанавливаем ID аспиранта
model.addAttribute("report", reportForm);
return "admin/aspirantReport"; // Возвращает шаблон report.html
}
@PostMapping("/saveReport")
public String saveReport(@ModelAttribute ReportForm reportForm,
@RequestParam("file") List<MultipartFile> files) {
// Сохраняем отчет
adminReportService.saveReport(reportForm);
// Обработка загруженных файлов
if (!files.isEmpty()) {
for (MultipartFile file : files) {
System.out.println("Файл: " + file.getOriginalFilename());
// Здесь можно добавить логику сохранения файла на сервере
}
}
return "redirect:/admin/aspirants"; // Перенаправление на список аспирантов
}
}

View File

@ -3,6 +3,7 @@ package ru.ulstu.report.controller;
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;
@ -40,6 +41,7 @@ public class ReportController {
List<ReportPeriod> periods = reportPeriodService.getReportPeriods();
model.addAttribute("reportPeriods", periods);
model.addAttribute("reportListForm", new ReportListForm(periods.isEmpty() ? null : periods.getFirst()));
model.addAttribute("reports", reportService.getReports(periods.isEmpty() ? null : periods.getFirst()));
model.addAttribute("canCreate", !periods.isEmpty() && reportService.canCreateReport(periods.getFirst()));
return "report/reportList";
}
@ -50,16 +52,28 @@ public class ReportController {
model.addAttribute("reports", reportService.getReports(reportListForm.getReportPeriod()));
List<ReportPeriod> periods = reportPeriodService.getReportPeriods();
model.addAttribute("reportPeriods", periods);
model.addAttribute("canCreate", !periods.isEmpty() && reportService.canCreateReport(periods.getFirst()));
model.addAttribute("canCreate", !periods.isEmpty() && reportService.canCreateReport(reportListForm.getReportPeriod()));
return "report/reportList";
}
@GetMapping("editReport/{reportId}/{reportPeriodId}")
public String createReport(@PathVariable("reportId") Integer reportId,
@PathVariable("reportPeriodId") Integer reportPeriodId,
@GetMapping("new-report/{reportPeriodId}")
public String createReport(@PathVariable("reportPeriodId") Integer reportPeriodId,
Model model) {
List<Indicator> indicators = aspirantService.getCurrentAspirantIndicators();
model.addAttribute("report", new ReportDto(reportId, reportPeriodId, indicators));
model.addAttribute("report", new ReportDto(reportPeriodId, indicators));
return "report/editReport";
}
@GetMapping("edit-report/{reportId}")
public String editReportWithoutReportPeriod(@PathVariable("reportId") Integer reportId, Model model) {
List<Indicator> indicators = aspirantService.getCurrentAspirantIndicators();
model.addAttribute("report", new ReportDto(reportService.getReportById(reportId), indicators));
return "report/editReport";
}
@PostMapping("save-report")
public String saveReport(@ModelAttribute("report") ReportDto reportDto, Model model) {
reportService.saveReport(reportDto);
return "redirect:/report/reportList";
}
}

View File

@ -1,6 +1,8 @@
package ru.ulstu.report.model.dto;
import org.springframework.format.annotation.DateTimeFormat;
import ru.ulstu.indicator.model.Indicator;
import ru.ulstu.report.model.Report;
import java.util.ArrayList;
import java.util.Date;
@ -9,15 +11,25 @@ import java.util.List;
public class ReportDto {
private Integer id;
private Integer reportPeriodId;
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
private Date createDate = new Date();
private List<ReportValueDto> reportValues = new ArrayList<>();
public ReportDto(Integer id, Integer reportPeriodId, List<Indicator> indicators) {
this.id = id;
public ReportDto() {
}
public ReportDto(Integer reportPeriodId, List<Indicator> indicators) {
this.reportPeriodId = reportPeriodId;
this.reportValues = indicators.stream().map(ReportValueDto::new).toList();
}
public ReportDto(Report report, List<Indicator> indicators) {
this.id = report.getId();
this.reportPeriodId = report.getReportPeriod().getId();
this.createDate = report.getCreateDate();
this.reportValues = indicators.stream().map(ReportValueDto::new).toList();
}
public List<ReportValueDto> getReportValues() {
return reportValues;
}

View File

@ -5,6 +5,7 @@ import ru.ulstu.aspirant.model.Aspirant;
import ru.ulstu.aspirant.service.AspirantService;
import ru.ulstu.report.model.Report;
import ru.ulstu.report.model.ReportPeriod;
import ru.ulstu.report.model.dto.ReportDto;
import ru.ulstu.report.repository.ReportRepository;
import ru.ulstu.user.UserService;
@ -15,13 +16,15 @@ public class ReportService {
private final ReportRepository reportRepository;
private final UserService userService;
private final AspirantService aspirantService;
private final ReportPeriodService reportPeriodService;
public ReportService(ReportRepository reportRepository,
UserService userService,
AspirantService aspirantService) {
AspirantService aspirantService, ReportPeriodService reportPeriodService) {
this.reportRepository = reportRepository;
this.userService = userService;
this.aspirantService = aspirantService;
this.reportPeriodService = reportPeriodService;
}
public List<Report> getReports(ReportPeriod reportPeriod) {
@ -32,4 +35,26 @@ public class ReportService {
Aspirant currentAspirant = aspirantService.getAspirantByUser(userService.getCurrentUser());
return reportRepository.findByReportPeriodAndAspirant(reportPeriod, currentAspirant) == null;
}
public Report saveReport(ReportDto reportDto) {
Report report;
if (reportDto.getId() == null || reportDto.getId() == 0) {
report = new Report();
} else {
report = getReportById(reportDto.getId());
}
if (reportDto.getReportPeriodId() != null) {
report.setReportPeriod(reportPeriodService.getById(reportDto.getReportPeriodId()));
}
report.setAspirant(aspirantService.getAspirantByUser(userService.getCurrentUser()));
report.setCreateDate(reportDto.getCreateDate());
//TODO: add status
return reportRepository.save(report);
}
public Report getReportById(Integer reportId) {
return reportRepository
.findById(reportId)
.orElseThrow(() -> new RuntimeException("Report not found by id"));
}
}

View File

@ -3,22 +3,18 @@
layout:decorate="~{default}">
<div class="container" layout:fragment="content">
<h3 th:text="${'Редактирование отчета аспиранта от '} +${#calendars.format(report.createDate, 'dd.MM.yyyy HH:mm')}"></h3>
<form action="#" th:action="@{/report/saveReport}"
<form action="#" th:action="@{/report/save-report}"
th:object="${report}"
method="post">
<input type="hidden" th:field="*{id}">
<input type="hidden" th:field="*{reportPeriodId}">
<input type="hidden" th:field="*{createDate}">
<div class="form-group" th:each="rv, ind : *{reportValues}">
<hr/>
<h5 th:text="${rv.indicator.name}"></h5>
<a th:href="${'/edit-indicator/' + rv.indicator.id}"
th:text="${rv.indicator.name}"></a>
<p th:text="${rv.indicator.proofDocuments}"></p>
<p th:text="'Максимальное количество баллов за показатель: '+ ${rv.indicator.max}"></p>
<div class="form-group files-list" id="files-list">
<label class="form-label">Загрузка подтверждающих документов</label>
<div th:replace="/report/reportFilesListFragment"></div>
</div>
</div>
<button name="save" type="submit" class="btn btn-outline-dark">Сохранить</button>
@ -40,31 +36,13 @@
maxSize: -1,
extensions: [],
callback: function (response) {
showFeedbackMessage("Файл успешно загружен");
console.debug(response);
addNewFile(response, $("#files-list"));
}
});
$('.selectpicker').selectpicker();
});
function sendPing() {
id = document.getElementById("projectId").value
$.ajax({
url: "/projects/ping?projectId=" + id,
contentType: "application/json; charset=utf-8",
method: "POST",
success: function () {
showFeedbackMessage("Ping был отправлен", MessageTypesEnum.SUCCESS)
},
error: function (errorData) {
showFeedbackMessage(errorData.responseJSON.error.message, MessageTypesEnum.WARNING)
}
})
}
/*]]>*/
function addNewFile(fileDto, listElement) {
var fileNumber = $('.files-list div.row').length;

View File

@ -29,7 +29,7 @@
</div>
</form>
<a th:href="@{'/report/editReport/0/'+ ${reportListForm.reportPeriod.id}}" class="btn btn-outline-dark"
<a th:href="@{'/report/new-report/'+ ${reportListForm.reportPeriod.id}}" class="btn btn-outline-dark"
th:if="${canCreate}">
<i class="fa fa-plus-square" aria-hidden="true"> Добавить отчет</i>
</a>
@ -49,10 +49,10 @@
<td th:text="${#calendars.format(r.reportPeriod.startDate, 'dd.MM.yyyy') + ' - ' + #calendars.format(r.reportPeriod.endDate, 'dd.MM.yyyy')}"></td>
<td th:text="${r.aspirant.surname + ' '+ r.aspirant.name + ' '+ r.aspirant.patronymic }"></td>
<td th:text="${#calendars.format(r.createDate, 'dd.MM.yyyy HH:mm')}"></td>
<td th:text="${r.status}"></td>
<!-- <td th:text="${r.status}"></td>-->
<td>
<!-- Ссылка на редактирование -->
<a th:href="@{'/report/editReport/' + ${r.id}}" class="btn btn-sm btn-primary">
<a th:href="@{'/report/edit-report/' + ${r.id}}" class="btn btn-sm btn-primary">
<i class="fa fa-edit" aria-hidden="true"></i> Редактировать
</a>
</td>