Resolve "Список периодических событий" #129

Merged
romanov73 merged 57 commits from 4-show-time-line into master 2018-10-30 23:32:01 +04:00
Showing only changes of commit 40c668905f - Show all commits

View File

@ -7,6 +7,8 @@ import ru.ulstu.paper.model.Paper;
import ru.ulstu.paper.model.PaperDto; import ru.ulstu.paper.model.PaperDto;
import ru.ulstu.paper.model.PaperStatusDto; import ru.ulstu.paper.model.PaperStatusDto;
import ru.ulstu.paper.repository.PaperRepository; import ru.ulstu.paper.repository.PaperRepository;
import ru.ulstu.user.model.UserDto;
import ru.ulstu.user.service.MailService;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
@ -20,11 +22,14 @@ public class PaperService {
private final PaperRepository paperRepository; private final PaperRepository paperRepository;
private final FileService fileService; private final FileService fileService;
public final MailService mailService;
public PaperService(PaperRepository paperRepository, public PaperService(PaperRepository paperRepository,
FileService fileService) { FileService fileService, MailService mailService) {
this.paperRepository = paperRepository; this.paperRepository = paperRepository;
this.fileService = fileService; this.fileService = fileService;
this.mailService = mailService;
} }
public List<PaperDto> findAll() { public List<PaperDto> findAll() {
@ -62,6 +67,9 @@ public class PaperService {
@Transactional @Transactional
public Integer update(PaperDto paperDto) throws IOException { public Integer update(PaperDto paperDto) throws IOException {
Paper paper = paperRepository.findOne(paperDto.getId()); Paper paper = paperRepository.findOne(paperDto.getId());
if(paper != null && paper.getStatus() != paperDto.getStatus()){
sendMessageAboutStatusChange(paper.getStatus(),paperDto);
}
if (paperDto.getTmpFileName() != null && paper.getFileData() != null) { if (paperDto.getTmpFileName() != null && paper.getFileData() != null) {
fileService.deleteFile(paper.getFileData()); fileService.deleteFile(paper.getFileData());
} }
@ -80,4 +88,12 @@ public class PaperService {
public List<PaperStatusDto> getPaperStatuses() { public List<PaperStatusDto> getPaperStatuses() {
return convert(Arrays.asList(Paper.PaperStatus.values()), status ->new PaperStatusDto(status)); return convert(Arrays.asList(Paper.PaperStatus.values()), status ->new PaperStatusDto(status));
} }
private void sendMessageAboutStatusChange(Paper.PaperStatus oldStatus, PaperDto paper){
for (UserDto user: paper.getAuthors()) {
mailService.sendEmail(user.getEmail(), "Обновление статуса статьи",
"Статус статьи " + paper.getTitle() + " сменился с " + oldStatus.getName()
+ " на " + paper.getStatus().getName());
}
}
} }