Compare commits

..

No commits in common. "3791f10b8e978159272a4a405bb3101a87c87ec9" and "faa081f8286e7e4e3eedbddfb75716f4397b67c1" have entirely different histories.

6 changed files with 89 additions and 66 deletions

View File

@ -0,0 +1,52 @@
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,7 +3,6 @@ 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;
@ -41,7 +40,6 @@ 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";
}
@ -52,28 +50,16 @@ 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(reportListForm.getReportPeriod()));
model.addAttribute("canCreate", !periods.isEmpty() && reportService.canCreateReport(periods.getFirst()));
return "report/reportList";
}
@GetMapping("new-report/{reportPeriodId}")
public String createReport(@PathVariable("reportPeriodId") Integer reportPeriodId,
@GetMapping("editReport/{reportId}/{reportPeriodId}")
public String createReport(@PathVariable("reportId") Integer reportId,
@PathVariable("reportPeriodId") Integer reportPeriodId,
Model model) {
List<Indicator> indicators = aspirantService.getCurrentAspirantIndicators();
model.addAttribute("report", new ReportDto(reportPeriodId, indicators));
model.addAttribute("report", new ReportDto(reportId, 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,8 +1,6 @@
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;
@ -11,25 +9,15 @@ 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() {
}
public ReportDto(Integer reportPeriodId, List<Indicator> indicators) {
public ReportDto(Integer id, Integer reportPeriodId, List<Indicator> indicators) {
this.id = id;
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,7 +5,6 @@ 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;
@ -16,15 +15,13 @@ 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, ReportPeriodService reportPeriodService) {
AspirantService aspirantService) {
this.reportRepository = reportRepository;
this.userService = userService;
this.aspirantService = aspirantService;
this.reportPeriodService = reportPeriodService;
}
public List<Report> getReports(ReportPeriod reportPeriod) {
@ -35,26 +32,4 @@ 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,18 +3,22 @@
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/save-report}"
<form action="#" th:action="@{/report/saveReport}"
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}">
<a th:href="${'/edit-indicator/' + rv.indicator.id}"
th:text="${rv.indicator.name}"></a>
<hr/>
<h5 th:text="${rv.indicator.name}"></h5>
<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>
@ -36,13 +40,31 @@
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/new-report/'+ ${reportListForm.reportPeriod.id}}" class="btn btn-outline-dark"
<a th:href="@{'/report/editReport/0/'+ ${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/edit-report/' + ${r.id}}" class="btn btn-sm btn-primary">
<a th:href="@{'/report/editReport/' + ${r.id}}" class="btn btn-sm btn-primary">
<i class="fa fa-edit" aria-hidden="true"></i> Редактировать
</a>
</td>