#21 -- Save values and fix front for files upload
This commit is contained in:
parent
dab6c030e5
commit
f5c89b0897
@ -2,6 +2,7 @@ package ru.ulstu.file.model;
|
|||||||
|
|
||||||
import jakarta.persistence.Column;
|
import jakarta.persistence.Column;
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.Lob;
|
||||||
import jakarta.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
import ru.ulstu.model.BaseEntity;
|
import ru.ulstu.model.BaseEntity;
|
||||||
|
|
||||||
@ -17,11 +18,9 @@ public class FileData extends BaseEntity {
|
|||||||
@Column(name = "create_date")
|
@Column(name = "create_date")
|
||||||
private Date createDate;
|
private Date createDate;
|
||||||
|
|
||||||
|
@Lob
|
||||||
private byte[] data;
|
private byte[] data;
|
||||||
|
|
||||||
@Column(name = "is_latex_attach")
|
|
||||||
private Boolean isLatexAttach;
|
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
@ -53,12 +52,4 @@ public class FileData extends BaseEntity {
|
|||||||
public void setData(byte[] data) {
|
public void setData(byte[] data) {
|
||||||
this.data = data;
|
this.data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean isLatexAttach() {
|
|
||||||
return isLatexAttach;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLatexAttach(Boolean latexAttach) {
|
|
||||||
isLatexAttach = latexAttach;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,39 +1,37 @@
|
|||||||
package ru.ulstu.report.controller;
|
package ru.ulstu.report.controller;
|
||||||
|
|
||||||
|
import jakarta.validation.Valid;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
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.bind.annotation.RequestMapping;
|
||||||
import ru.ulstu.aspirant.service.AspirantService;
|
|
||||||
import ru.ulstu.indicator.service.IndicatorService;
|
|
||||||
import ru.ulstu.report.model.dto.ReportValueDto;
|
import ru.ulstu.report.model.dto.ReportValueDto;
|
||||||
import ru.ulstu.report.service.ReportPeriodService;
|
import ru.ulstu.report.service.ReportValueService;
|
||||||
import ru.ulstu.report.service.ReportService;
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
@RequestMapping("report-value")
|
@RequestMapping("report-value")
|
||||||
public class ReportValueController {
|
public class ReportValueController {
|
||||||
private final IndicatorService indicatorService;
|
private final ReportValueService reportValueService;
|
||||||
private final AspirantService aspirantService;
|
|
||||||
private final ReportService reportService;
|
|
||||||
private final ReportPeriodService reportPeriodService;
|
|
||||||
|
|
||||||
public ReportValueController(IndicatorService indicatorService,
|
public ReportValueController(ReportValueService reportValueService) {
|
||||||
AspirantService aspirantService,
|
this.reportValueService = reportValueService;
|
||||||
ReportService reportService,
|
|
||||||
ReportPeriodService reportPeriodService) {
|
|
||||||
this.indicatorService = indicatorService;
|
|
||||||
this.aspirantService = aspirantService;
|
|
||||||
this.reportService = reportService;
|
|
||||||
this.reportPeriodService = reportPeriodService;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("edit-report-value/{reportId}/{indicatorId}")
|
@GetMapping("edit-report-value/{reportId}/{indicatorId}")
|
||||||
public String getReportPeriods(@PathVariable("reportId") Integer reportId,
|
public String getReportValue(@PathVariable("reportId") Integer reportId,
|
||||||
@PathVariable("indicatorId") Integer indicatorId,
|
@PathVariable("indicatorId") Integer indicatorId,
|
||||||
Model model) {
|
Model model) {
|
||||||
model.addAttribute("reportValue", new ReportValueDto(reportId, indicatorService.getIndicatorById(indicatorId)));
|
model.addAttribute("reportValue", reportValueService.getByIndicatorId(reportId, indicatorId));
|
||||||
return "report/editReportValue";
|
return "report/editReportValue";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("save-report-value")
|
||||||
|
public String saveReportValue(@Valid ReportValueDto reportValueDto, Model model) throws IOException {
|
||||||
|
reportValueService.saveReportValue(reportValueDto);
|
||||||
|
return "redirect:/report/edit-report/" + reportValueDto.getReportId();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,11 @@ package ru.ulstu.report.model.dto;
|
|||||||
|
|
||||||
import ru.ulstu.file.model.FileDataDto;
|
import ru.ulstu.file.model.FileDataDto;
|
||||||
import ru.ulstu.indicator.model.Indicator;
|
import ru.ulstu.indicator.model.Indicator;
|
||||||
|
import ru.ulstu.report.model.ReportValue;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class ReportValueDto {
|
public class ReportValueDto {
|
||||||
private Integer id = 0;
|
private Integer id = 0;
|
||||||
@ -25,6 +27,14 @@ public class ReportValueDto {
|
|||||||
this.indicator = indicator;
|
this.indicator = indicator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ReportValueDto(ReportValue reportValue, Integer reportId) {
|
||||||
|
this.id = reportValue.getId();
|
||||||
|
this.reportId = reportId;
|
||||||
|
this.indicator = reportValue.getIndicator();
|
||||||
|
this.files = reportValue.getFiles().stream().map(FileDataDto::new).collect(Collectors.toList());
|
||||||
|
this.indicatorValue = reportValue.getIndicatorValue();
|
||||||
|
}
|
||||||
|
|
||||||
public Indicator getIndicator() {
|
public Indicator getIndicator() {
|
||||||
return indicator;
|
return indicator;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,11 @@
|
|||||||
|
package ru.ulstu.report.repository;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
import org.springframework.data.repository.query.Param;
|
||||||
|
import ru.ulstu.report.model.ReportValue;
|
||||||
|
|
||||||
|
public interface ReportValueRepository extends JpaRepository<ReportValue, Integer> {
|
||||||
|
@Query("SELECT rv FROM Report r JOIN r.values rv WHERE r.id = :reportId AND rv.indicator.id = :indicatorId")
|
||||||
|
ReportValue findByReportIdAndIndicatorId(@Param("reportId") Integer reportId, @Param("indicatorId") Integer indicatorId);
|
||||||
|
}
|
@ -5,6 +5,7 @@ import ru.ulstu.aspirant.model.Aspirant;
|
|||||||
import ru.ulstu.aspirant.service.AspirantService;
|
import ru.ulstu.aspirant.service.AspirantService;
|
||||||
import ru.ulstu.report.model.Report;
|
import ru.ulstu.report.model.Report;
|
||||||
import ru.ulstu.report.model.ReportPeriod;
|
import ru.ulstu.report.model.ReportPeriod;
|
||||||
|
import ru.ulstu.report.model.ReportValue;
|
||||||
import ru.ulstu.report.model.dto.ReportDto;
|
import ru.ulstu.report.model.dto.ReportDto;
|
||||||
import ru.ulstu.report.repository.ReportRepository;
|
import ru.ulstu.report.repository.ReportRepository;
|
||||||
import ru.ulstu.user.UserService;
|
import ru.ulstu.user.UserService;
|
||||||
@ -61,4 +62,10 @@ public class ReportService {
|
|||||||
public void deleteReport(Integer id) {
|
public void deleteReport(Integer id) {
|
||||||
reportRepository.deleteById(id);
|
reportRepository.deleteById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addReportValue(Integer reportId, ReportValue reportValue) {
|
||||||
|
Report report = getReportById(reportId);
|
||||||
|
report.getValues().add(reportValue);
|
||||||
|
reportRepository.save(report);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,64 @@
|
|||||||
|
package ru.ulstu.report.service;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import ru.ulstu.file.service.FileService;
|
||||||
|
import ru.ulstu.indicator.service.IndicatorService;
|
||||||
|
import ru.ulstu.report.model.ReportValue;
|
||||||
|
import ru.ulstu.report.model.dto.ReportValueDto;
|
||||||
|
import ru.ulstu.report.repository.ReportValueRepository;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class ReportValueService {
|
||||||
|
private final ReportValueRepository reportValueRepository;
|
||||||
|
private final IndicatorService indicatorService;
|
||||||
|
private final FileService fileService;
|
||||||
|
private final ReportService reportService;
|
||||||
|
|
||||||
|
public ReportValueService(ReportValueRepository reportValueRepository,
|
||||||
|
IndicatorService indicatorService,
|
||||||
|
FileService fileService,
|
||||||
|
ReportService reportService) {
|
||||||
|
this.reportValueRepository = reportValueRepository;
|
||||||
|
this.indicatorService = indicatorService;
|
||||||
|
this.fileService = fileService;
|
||||||
|
this.reportService = reportService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReportValue saveReportValue(ReportValueDto reportValueDto) throws IOException {
|
||||||
|
ReportValue reportValue;
|
||||||
|
if (reportValueDto.getId() == null || reportValueDto.getId() == 0) {
|
||||||
|
reportValue = new ReportValue();
|
||||||
|
} else {
|
||||||
|
reportValue = getReportValueById(reportValueDto.getId());
|
||||||
|
}
|
||||||
|
reportValue.setIndicatorValue(reportValueDto.getIndicatorValue());
|
||||||
|
reportValue.setIndicator(indicatorService.getIndicatorById(reportValueDto.getIndicator().getId()));
|
||||||
|
reportValue.setFiles(fileService.saveOrCreate(reportValueDto.getFiles().stream()
|
||||||
|
.filter(f -> !f.isDeleted())
|
||||||
|
.toList()));
|
||||||
|
reportValue = reportValueRepository.save(reportValue);
|
||||||
|
reportService.addReportValue(reportValueDto.getReportId(), reportValue);
|
||||||
|
|
||||||
|
return reportValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReportValue getReportValueById(Integer reportValueId) {
|
||||||
|
return reportValueRepository
|
||||||
|
.findById(reportValueId)
|
||||||
|
.orElseThrow(() -> new RuntimeException("Report value not found by id"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteReportValue(Integer id) {
|
||||||
|
reportValueRepository.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReportValueDto getByIndicatorId(Integer reportId, Integer indicatorId) {
|
||||||
|
ReportValue reportValue = reportValueRepository.findByReportIdAndIndicatorId(reportId, indicatorId);
|
||||||
|
if (reportValue == null) {
|
||||||
|
return new ReportValueDto(reportId, indicatorService.getIndicatorById(indicatorId));
|
||||||
|
}
|
||||||
|
return new ReportValueDto(reportValue, reportId);
|
||||||
|
}
|
||||||
|
}
|
@ -2,21 +2,15 @@
|
|||||||
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:th="http://www.w3.org/1999/xhtml"
|
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout" xmlns:th="http://www.w3.org/1999/xhtml"
|
||||||
layout:decorate="~{default}">
|
layout:decorate="~{default}">
|
||||||
<div class="container" layout:fragment="content">
|
<div class="container" layout:fragment="content">
|
||||||
<h3 th:text="${'Редактирование показателя '+ reportValue.indicator.name}"></h3>
|
<h3>Редактирование показателя</h3>
|
||||||
<form action="#" th:action="@{/report/save-report-value}"
|
<h3 th:text="${reportValue.indicator.name}"></h3>
|
||||||
th:object="${reportValue}"
|
|
||||||
method="post">
|
<form action="#" th:action="@{/report-value/save-report-value}"
|
||||||
|
th:object="${reportValue}" method="post">
|
||||||
<input type="hidden" th:field="*{id}">
|
<input type="hidden" th:field="*{id}">
|
||||||
|
<input type="hidden" th:field="*{reportId}">
|
||||||
<input type="hidden" th:field="*{indicator.id}">
|
<input type="hidden" th:field="*{indicator.id}">
|
||||||
|
|
||||||
<button name="save" type="submit" class="btn btn-outline-dark">Сохранить</button>
|
|
||||||
<button name="delete"
|
|
||||||
type="submit"
|
|
||||||
class="btn btn-outline-dark"
|
|
||||||
onclick="return confirm('Удалить запись?')">
|
|
||||||
Удалить
|
|
||||||
</button>
|
|
||||||
<a href="${'/report/edit-report/'+ reportValue.reportId}" class="btn btn-outline-dark">Отмена</a>
|
|
||||||
<div class="form-group files-list" id="files-list">
|
<div class="form-group files-list" id="files-list">
|
||||||
<label class="form-label">Загрузка подтверждающих документов</label>
|
<label class="form-label">Загрузка подтверждающих документов</label>
|
||||||
<div th:each="file, rowStat : ${reportValue.files}">
|
<div th:each="file, rowStat : ${reportValue.files}">
|
||||||
@ -37,8 +31,13 @@
|
|||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-10">
|
<div class="col-10">
|
||||||
<a th:onclick="${file.id==null} ? 'downloadFile('+${file.tmpFileName}+',null,\''+${file.name}+'\')':
|
<a th:if="${file.id != null}"
|
||||||
'downloadFile(null,'+${file.id}+',\''+${file.name}+'\')' "
|
th:onclick="downloadFile(null, [[${file.id}]], [[${file.name}]])"
|
||||||
|
href="javascript:void(0)"
|
||||||
|
th:text="*{files[__${rowStat.index}__].name}">
|
||||||
|
</a>
|
||||||
|
<a th:if="${file.id == null}"
|
||||||
|
th:onclick="downloadFile([[${file.tmpFileName}]],null,[[${file.name}]])"
|
||||||
href="javascript:void(0)"
|
href="javascript:void(0)"
|
||||||
th:text="*{files[__${rowStat.index}__].name}">
|
th:text="*{files[__${rowStat.index}__].name}">
|
||||||
</a>
|
</a>
|
||||||
@ -52,7 +51,18 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<button name="save" type="submit" class="btn btn-outline-dark">Сохранить</button>
|
||||||
|
<button name="delete"
|
||||||
|
type="submit"
|
||||||
|
class="btn btn-outline-dark"
|
||||||
|
onclick="return confirm('Удалить запись?')">
|
||||||
|
Удалить
|
||||||
|
</button>
|
||||||
|
<a href="${'/report/edit-report/' + reportValue.reportId}" class="btn btn-outline-dark">Отмена</a>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
|
||||||
<script type="text/javascript" src="/js/file-loader.js"></script>
|
<script type="text/javascript" src="/js/file-loader.js"></script>
|
||||||
<script>
|
<script>
|
||||||
/*<![CDATA[*/
|
/*<![CDATA[*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user