|
|
|
@ -14,13 +14,13 @@ import ru.ulstu.project.model.ProjectDto;
|
|
|
|
|
import ru.ulstu.project.service.ProjectService;
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
import static org.springframework.util.ObjectUtils.isEmpty;
|
|
|
|
|
import static ru.ulstu.core.util.StreamApiUtils.convert;
|
|
|
|
|
import static ru.ulstu.grant.model.Grant.GrantStatus.APPLICATION;
|
|
|
|
|
import static ru.ulstu.grant.model.Grant.GrantStatus.IN_WORK;
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
public class GrantService {
|
|
|
|
@ -59,7 +59,6 @@ public class GrantService {
|
|
|
|
|
public Integer create(GrantDto grantDto) throws IOException {
|
|
|
|
|
Grant newGrant = copyFromDto(new Grant(), grantDto);
|
|
|
|
|
newGrant = grantRepository.save(newGrant);
|
|
|
|
|
//paperNotificationService.sendCreateNotification(newGrant);
|
|
|
|
|
return newGrant.getId();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -67,10 +66,9 @@ public class GrantService {
|
|
|
|
|
grant.setComment(grantDto.getComment());
|
|
|
|
|
grant.setStatus(grantDto.getStatus() == null ? APPLICATION : grantDto.getStatus());
|
|
|
|
|
grant.setTitle(grantDto.getTitle());
|
|
|
|
|
if (grantDto.getProject() != null) {
|
|
|
|
|
if (grantDto.getProject() != null && grantDto.getProject().getId() != null) {
|
|
|
|
|
grant.setProject(projectService.findById(grantDto.getProject().getId()));
|
|
|
|
|
}
|
|
|
|
|
//grant. setdeadlineDate(grant.getdeadlineDate() == null ? new Date() : grant.getdeadlineDate());
|
|
|
|
|
grant.setDeadlines(deadlineService.saveOrCreate(grantDto.getDeadlines()));
|
|
|
|
|
if (grantDto.getApplicationFileName() != null) {
|
|
|
|
|
grant.setApplication(fileService.createFileFromTmp(grantDto.getApplicationFileName()));
|
|
|
|
@ -90,9 +88,6 @@ public class GrantService {
|
|
|
|
|
if (grantDto.getApplicationFileName() != null && grant.getApplication() != null) {
|
|
|
|
|
fileService.deleteFile(grant.getApplication());
|
|
|
|
|
}
|
|
|
|
|
// if (paper.getStatus() != oldStatus) { //TODO: доделать потом все уведомления
|
|
|
|
|
// paperNotificationService.statusChangeNotification(paper, oldStatus);
|
|
|
|
|
// }
|
|
|
|
|
grantRepository.save(copyFromDto(grant, grantDto));
|
|
|
|
|
return grant.getId();
|
|
|
|
|
}
|
|
|
|
@ -120,48 +115,9 @@ public class GrantService {
|
|
|
|
|
grant.setStatus(APPLICATION);
|
|
|
|
|
grant.getDeadlines().add(new Deadline(deadlineDate, "первый дедлайн"));
|
|
|
|
|
grant = grantRepository.save(grant);
|
|
|
|
|
// paperNotificationService.sendCreateNotification(paper);
|
|
|
|
|
return grant;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// public List<PaperDto> filter(PaperFilterDto filterDto) {
|
|
|
|
|
// return convert(sortPapers(paperRepository.filter(
|
|
|
|
|
// filterDto.getFilterAuthorId() == null ? null : userService.findById(filterDto.getFilterAuthorId()),
|
|
|
|
|
// filterDto.getYear())), PaperDto::new);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
private List<Grant> sortGrants(List<Grant> grants) {
|
|
|
|
|
return grants.stream().sorted((grant1, grant2) -> {
|
|
|
|
|
int statusCompareResult =
|
|
|
|
|
Integer.valueOf(Arrays.asList(Grant.GrantStatus.values()).indexOf(grant1.getStatus()))
|
|
|
|
|
.compareTo(Arrays.asList(Grant.GrantStatus.values()).indexOf(grant2.getStatus()));
|
|
|
|
|
if (statusCompareResult != 0) {
|
|
|
|
|
return statusCompareResult;
|
|
|
|
|
}
|
|
|
|
|
return grant1.getTitle().compareTo(grant2.getTitle());
|
|
|
|
|
}).collect(Collectors.toList());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public GrantDto findGrant(int id) {
|
|
|
|
|
return new GrantDto(grantRepository.getOne(id));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void closeFailedGrants() {
|
|
|
|
|
List<Grant> grants = grantRepository.findAll()
|
|
|
|
|
.stream()
|
|
|
|
|
.filter(grant -> grant.getNextDeadline().isPresent()
|
|
|
|
|
&& (grant.getStatus() == APPLICATION
|
|
|
|
|
|| grant.getStatus() == IN_WORK)
|
|
|
|
|
&& grant.getNextDeadline().get().getDate().before(new Date()))
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
grants.forEach(grant -> {
|
|
|
|
|
//Grant.GrantStatus oldStatus = grant.getStatus();
|
|
|
|
|
grant.setStatus(Grant.GrantStatus.FAILED);
|
|
|
|
|
grantRepository.save(grant);
|
|
|
|
|
//paperNotificationService.sendFailedNotification(grant, oldStatus);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void save(GrantDto grantDto) throws IOException {
|
|
|
|
|
if (isEmpty(grantDto.getId())) {
|
|
|
|
|
create(grantDto);
|
|
|
|
@ -169,8 +125,4 @@ public class GrantService {
|
|
|
|
|
update(grantDto);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public GrantDto findById(Integer grantId) {
|
|
|
|
|
return new GrantDto(grantRepository.findOne(grantId));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|