fix filer
This commit is contained in:
parent
ec1e3ff052
commit
468f440d9d
@ -12,11 +12,14 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||
import ru.ulstu.deadline.model.DeadlineDto;
|
||||
import ru.ulstu.paper.model.Paper;
|
||||
import ru.ulstu.paper.model.PaperDto;
|
||||
import ru.ulstu.paper.model.PaperFilterDto;
|
||||
import ru.ulstu.paper.service.PaperService;
|
||||
import ru.ulstu.user.model.User;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -34,7 +37,14 @@ public class PaperController {
|
||||
|
||||
@GetMapping("/papers")
|
||||
public void getPapers(ModelMap modelMap) {
|
||||
modelMap.put("papers", paperService.findAllDto());
|
||||
modelMap.put("filteredPapers", new PaperFilterDto(paperService.findAllDto(), null, null));
|
||||
}
|
||||
|
||||
@PostMapping("/papers")
|
||||
public void filterPapers(@Valid PaperFilterDto paperFilterDto, ModelMap modelMap) {
|
||||
modelMap.put("filteredPapers", new PaperFilterDto(paperService.filter(paperFilterDto),
|
||||
paperFilterDto.getFilterAuthorId(),
|
||||
paperFilterDto.getYear()));
|
||||
}
|
||||
|
||||
@GetMapping("/dashboard")
|
||||
@ -90,6 +100,15 @@ public class PaperController {
|
||||
return paperService.getPaperAuthors();
|
||||
}
|
||||
|
||||
@ModelAttribute("allYears")
|
||||
public List<Integer> getAllYears() {
|
||||
List<Integer> years = new ArrayList<>();
|
||||
for (int i = Calendar.getInstance().get(Calendar.YEAR); i > 2010; i-- ) {
|
||||
years.add(i);
|
||||
}
|
||||
return years;
|
||||
}
|
||||
|
||||
private void filterEmptyDeadlines(PaperDto paperDto) {
|
||||
paperDto.setDeadlines(paperDto.getDeadlines().stream()
|
||||
.filter(dto -> dto.getDate() != null || !isEmpty(dto.getDescription()))
|
||||
|
@ -63,7 +63,7 @@ public class Paper extends BaseEntity implements UserContainer {
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date updateDate = new Date();
|
||||
|
||||
@OneToMany(cascade = CascadeType.ALL)
|
||||
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "paper_id")
|
||||
private List<Deadline> deadlines = new ArrayList<>();
|
||||
|
||||
|
@ -33,6 +33,7 @@ public class PaperDto {
|
||||
private Date fileCreateDate;
|
||||
private Set<Integer> authorIds;
|
||||
private Set<UserDto> authors;
|
||||
private Integer filterAuthorId;
|
||||
|
||||
public PaperDto() {
|
||||
deadlines.add(new DeadlineDto());
|
||||
@ -200,4 +201,12 @@ public class PaperDto {
|
||||
.map(author -> author.getLastName())
|
||||
.collect(Collectors.joining(", "));
|
||||
}
|
||||
|
||||
public Integer getFilterAuthorId() {
|
||||
return filterAuthorId;
|
||||
}
|
||||
|
||||
public void setFilterAuthorId(Integer filterAuthorId) {
|
||||
this.filterAuthorId = filterAuthorId;
|
||||
}
|
||||
}
|
||||
|
@ -1,24 +1,42 @@
|
||||
package ru.ulstu.paper.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import java.util.List;
|
||||
|
||||
public class PaperFilterDto {
|
||||
private final Integer authorId;
|
||||
private final Integer year;
|
||||
private List<PaperDto> papers;
|
||||
private Integer filterAuthorId;
|
||||
private Integer year;
|
||||
|
||||
@JsonCreator
|
||||
public PaperFilterDto(@JsonProperty("authorId") Integer authorId,
|
||||
@JsonProperty("year") Integer year) {
|
||||
this.authorId = authorId;
|
||||
public PaperFilterDto() {
|
||||
}
|
||||
|
||||
public PaperFilterDto(List<PaperDto> paperDtos, Integer filterAuthorId, Integer year) {
|
||||
this.papers = paperDtos;
|
||||
this.filterAuthorId = filterAuthorId;
|
||||
this.year = year;
|
||||
}
|
||||
|
||||
public Integer getAuthorId() {
|
||||
return authorId;
|
||||
public List<PaperDto> getPapers() {
|
||||
return papers;
|
||||
}
|
||||
|
||||
public void setPapers(List<PaperDto> papers) {
|
||||
this.papers = papers;
|
||||
}
|
||||
|
||||
public Integer getFilterAuthorId() {
|
||||
return filterAuthorId;
|
||||
}
|
||||
|
||||
public void setFilterAuthorId(Integer filterAuthorId) {
|
||||
this.filterAuthorId = filterAuthorId;
|
||||
}
|
||||
|
||||
public Integer getYear() {
|
||||
return year;
|
||||
}
|
||||
|
||||
public void setYear(Integer year) {
|
||||
this.year = year;
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,6 @@ import java.util.List;
|
||||
|
||||
public interface PaperRepository extends JpaRepository<Paper, Integer> {
|
||||
|
||||
@Query("SELECT p FROM Paper p WHERE (:author IS NULL OR :author MEMBER OF p.authors) AND YEAR(p.createDate) = :year OR :year IS NULL")
|
||||
@Query("SELECT p FROM Paper p WHERE (:author IS NULL OR :author MEMBER OF p.authors) AND (YEAR(p.createDate) = :year OR :year IS NULL)")
|
||||
List<Paper> filter(@Param("author") User author, @Param("year") Integer year);
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class PaperScheduler {
|
||||
private final static boolean IS_DEADLINE_NOTIFICATION_BEFORE_WEEK = true;
|
||||
private final static boolean IS_DEADLINE_NOTIFICATION_AFTER_WEEK = true;
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(PaperScheduler.class);
|
||||
|
||||
@ -24,14 +24,14 @@ public class PaperScheduler {
|
||||
@Scheduled(cron = "0 0 8 * 1 ?")
|
||||
public void checkDeadlineBeforeWeek() {
|
||||
log.debug("PaperScheduler.checkDeadlineBeforeWeek started");
|
||||
paperNotificationService.sendDeadlineNotifications(paperService.findAll(), !IS_DEADLINE_NOTIFICATION_BEFORE_WEEK);
|
||||
paperNotificationService.sendDeadlineNotifications(paperService.findAll(), !IS_DEADLINE_NOTIFICATION_AFTER_WEEK);
|
||||
log.debug("PaperScheduler.checkDeadlineBeforeWeek finished");
|
||||
}
|
||||
|
||||
@Scheduled(cron = "0 0 8 * * ?")
|
||||
public void checkDeadlineAfterWeek() {
|
||||
log.debug("PaperScheduler.checkDeadlineAfterWeek started");
|
||||
paperNotificationService.sendDeadlineNotifications(paperService.findAll(), IS_DEADLINE_NOTIFICATION_BEFORE_WEEK);
|
||||
paperNotificationService.sendDeadlineNotifications(paperService.findAll(), IS_DEADLINE_NOTIFICATION_AFTER_WEEK);
|
||||
log.debug("PaperScheduler.checkDeadlineAfterWeek finished");
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,9 @@ import ru.ulstu.user.service.UserService;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.springframework.util.ObjectUtils.isEmpty;
|
||||
@ -83,10 +85,9 @@ public class PaperService {
|
||||
if (paperDto.getTmpFileName() != null) {
|
||||
paper.setFileData(fileService.createFileFromTmp(paperDto.getTmpFileName()));
|
||||
}
|
||||
paper.getAuthors().clear();
|
||||
if (paperDto.getAuthorIds() != null && !paperDto.getAuthorIds().isEmpty()) {
|
||||
paperDto.getAuthorIds().forEach(authorIds -> paper.getAuthors().add(userService.findById(authorIds)));
|
||||
} else {
|
||||
paper.getAuthors().clear();
|
||||
}
|
||||
return paper;
|
||||
}
|
||||
@ -95,11 +96,18 @@ public class PaperService {
|
||||
public Integer update(PaperDto paperDto) throws IOException {
|
||||
Paper paper = paperRepository.findOne(paperDto.getId());
|
||||
Paper.PaperStatus oldStatus = paper.getStatus();
|
||||
Set<User> oldAuthors = new HashSet<>(paper.getAuthors());
|
||||
if (paperDto.getTmpFileName() != null && paper.getFileData() != null) {
|
||||
fileService.deleteFile(paper.getFileData());
|
||||
}
|
||||
paperRepository.save(copyFromDto(paper, paperDto));
|
||||
|
||||
paper.getAuthors().forEach(author -> {
|
||||
if (!oldAuthors.contains(author)) {
|
||||
paperNotificationService.sendCreateNotification(paper);
|
||||
}
|
||||
});
|
||||
|
||||
if (paper.getStatus() != oldStatus) {
|
||||
paperNotificationService.statusChangeNotification(paper, oldStatus);
|
||||
}
|
||||
@ -137,10 +145,12 @@ public class PaperService {
|
||||
}
|
||||
|
||||
public List<PaperDto> filter(PaperFilterDto filterDto) {
|
||||
return convert(paperRepository.filter(userService.findById(filterDto.getAuthorId()), filterDto.getYear()), PaperDto::new);
|
||||
return convert(paperRepository.filter(
|
||||
filterDto.getFilterAuthorId() == null ? null : userService.findById(filterDto.getFilterAuthorId()),
|
||||
filterDto.getYear()), PaperDto::new);
|
||||
}
|
||||
|
||||
public PaperDto findPaper(int id){
|
||||
public PaperDto findPaper(int id) {
|
||||
return new PaperDto(paperRepository.getOne(id));
|
||||
}
|
||||
|
||||
|
@ -7,39 +7,42 @@
|
||||
<body>
|
||||
|
||||
<div class="container" layout:fragment="content">
|
||||
<form id="papers-form" method="get" th:action="@{'/papers/papers'}">
|
||||
<form id="papers-form" method="post" th:action="@{'/papers/papers'}">
|
||||
<input th:type="hidden" name="paperDeleteId" id="paperDeleteId"/>
|
||||
<section id="papers">
|
||||
<div class="container">
|
||||
<div class="row" id="paper-list">
|
||||
<div class="col-lg-12 text-center">
|
||||
<h2 class="section-heading text-uppercase">Статьи</h2>
|
||||
|
||||
<div th:replace="papers/fragments/paperNavigationFragment"/>
|
||||
<div class="filter">
|
||||
<h5>Фильтровать по:</h5>
|
||||
<select id="author">
|
||||
<option value="1">Алёна</option>
|
||||
<option value="2">Маша</option>
|
||||
<option value="3">Петя</option>
|
||||
</select>
|
||||
<select id="index score">
|
||||
<option>РИНЦ</option>
|
||||
<option>Scopus</option>
|
||||
<option>Web of science</option>
|
||||
</select>
|
||||
<select id="year">
|
||||
<option>2018</option>
|
||||
<option>2017</option>
|
||||
<option>2016</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<th:block th:each="paper : ${papers}">
|
||||
<div class="row">
|
||||
<div class="col-md-9 col-sm-12">
|
||||
<th:block th:each="paper : ${filteredPapers.papers}">
|
||||
<div th:replace="papers/fragments/paperLineFragment :: titleLine(paper=${paper})"/>
|
||||
</th:block>
|
||||
</div>
|
||||
<div class="col-md-3 col-sm-12">
|
||||
<div class="filter">
|
||||
<h5>Фильтр:</h5>
|
||||
<select class="form-control" th:field="${filteredPapers.filterAuthorId}" id="author"
|
||||
onchange="this.form.submit();">
|
||||
<option value="">Все авторы </option>
|
||||
<option th:each="author: ${allAuthors}" th:value="${author.id}"
|
||||
th:text="${author.lastName}">lastName
|
||||
</option>
|
||||
</select>
|
||||
<select class="form-control" id="year" th:field="${filteredPapers.year}" onchange="this.form.submit();">
|
||||
<option value="">Все годы</option>
|
||||
<option th:each="year: ${allYears}" th:value="${year}"
|
||||
th:text="${year}">year
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<div id="modalDelete"/>
|
||||
|
Loading…
Reference in New Issue
Block a user