Добавил final переменные
This commit is contained in:
parent
c175c378db
commit
6b168bcd31
@ -7,9 +7,10 @@ import lombok.ToString;
|
|||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@EqualsAndHashCode(callSuper = true)
|
|
||||||
@ToString
|
@ToString
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
public class Link extends Attachment {
|
public class Link extends Attachment {
|
||||||
|
|
||||||
private String url;
|
private String url;
|
||||||
|
|
||||||
public Link() {
|
public Link() {
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
package dev.struchkov.godfather.context.service.impl;
|
package dev.struchkov.godfather.context.service.impl;
|
||||||
|
|
||||||
|
import dev.struchkov.godfather.context.domain.content.Mail;
|
||||||
import dev.struchkov.godfather.context.repository.ContentRepository;
|
import dev.struchkov.godfather.context.repository.ContentRepository;
|
||||||
|
import dev.struchkov.godfather.context.service.MailService;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import dev.struchkov.godfather.context.domain.content.Mail;
|
|
||||||
import dev.struchkov.godfather.context.service.MailService;
|
|
||||||
|
|
||||||
import java.time.Clock;
|
import java.time.Clock;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
@ -24,6 +24,7 @@ public class MailServiceImpl implements MailService {
|
|||||||
private boolean newMessage = false;
|
private boolean newMessage = false;
|
||||||
private LocalDateTime oldDateTime = LocalDateTime.now(Clock.tickSeconds(ZoneId.systemDefault()));
|
private LocalDateTime oldDateTime = LocalDateTime.now(Clock.tickSeconds(ZoneId.systemDefault()));
|
||||||
|
|
||||||
|
//TODO [13.04.2022]: Подобная реализация с newMessage вызовет проблемы с несколькими инстансами.
|
||||||
@Override
|
@Override
|
||||||
public void add(Mail mail) {
|
public void add(Mail mail) {
|
||||||
mailRepository.add(mail);
|
mailRepository.add(mail);
|
||||||
@ -40,9 +41,9 @@ public class MailServiceImpl implements MailService {
|
|||||||
@Override
|
@Override
|
||||||
public List<Mail> getLastEventByCreateDateTime(LocalDateTime timeFrom, LocalDateTime timeTo) {
|
public List<Mail> getLastEventByCreateDateTime(LocalDateTime timeFrom, LocalDateTime timeTo) {
|
||||||
log.trace("Запрошены последние сообщения {} - {} ", timeFrom, timeTo);
|
log.trace("Запрошены последние сообщения {} - {} ", timeFrom, timeTo);
|
||||||
List<Mail> mails = mailRepository.betweenByCreateDateTime(timeFrom, timeTo);
|
final List<Mail> mails = mailRepository.betweenByCreateDateTime(timeFrom, timeTo);
|
||||||
if (mails != null && !mails.isEmpty()) {
|
if (mails != null && !mails.isEmpty()) {
|
||||||
return getReturnMails(mails);
|
return findLastMailEachUser(mails);
|
||||||
} else {
|
} else {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
@ -51,9 +52,9 @@ public class MailServiceImpl implements MailService {
|
|||||||
@Override
|
@Override
|
||||||
public List<Mail> getLastEventByAddDateTime(LocalDateTime timeFrom, LocalDateTime timeTo) {
|
public List<Mail> getLastEventByAddDateTime(LocalDateTime timeFrom, LocalDateTime timeTo) {
|
||||||
log.trace("Запрошены последние сообщения {} - {} ", timeFrom, timeTo);
|
log.trace("Запрошены последние сообщения {} - {} ", timeFrom, timeTo);
|
||||||
List<Mail> mails = mailRepository.betweenByAddDateTime(timeFrom, timeTo);
|
final List<Mail> mails = mailRepository.betweenByAddDateTime(timeFrom, timeTo);
|
||||||
if (mails != null && !mails.isEmpty()) {
|
if (mails != null && !mails.isEmpty()) {
|
||||||
return getReturnMails(mails);
|
return findLastMailEachUser(mails);
|
||||||
} else {
|
} else {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
@ -61,15 +62,15 @@ public class MailServiceImpl implements MailService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Mail> getNewMessage() {
|
public List<Mail> getNewMessage() {
|
||||||
LocalDateTime newData = LocalDateTime.now(Clock.tickSeconds(ZoneId.systemDefault())).plusNanos(999999999);
|
final LocalDateTime newData = LocalDateTime.now(Clock.tickSeconds(ZoneId.systemDefault())).plusNanos(999999999);
|
||||||
List<Mail> lastEventByAddDateTime = Collections.emptyList();
|
|
||||||
if (newMessage) {
|
if (newMessage) {
|
||||||
lastEventByAddDateTime = getLastEventByAddDateTime(oldDateTime, newData);
|
final List<Mail> lastEventByAddDateTime = getLastEventByAddDateTime(oldDateTime, newData);
|
||||||
newMessage = false;
|
newMessage = false;
|
||||||
oldDateTime = newData;
|
oldDateTime = newData;
|
||||||
}
|
|
||||||
return lastEventByAddDateTime;
|
return lastEventByAddDateTime;
|
||||||
}
|
}
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteAllByAddDateBetween(@NonNull LocalDateTime dateFrom, @NonNull LocalDateTime dateTo) {
|
public void deleteAllByAddDateBetween(@NonNull LocalDateTime dateFrom, @NonNull LocalDateTime dateTo) {
|
||||||
@ -86,9 +87,12 @@ public class MailServiceImpl implements MailService {
|
|||||||
mailRepository.deleteAllByAddDateAfter(date);
|
mailRepository.deleteAllByAddDateAfter(date);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Mail> getReturnMails(List<Mail> mails) {
|
/**
|
||||||
Set<Long> people = new HashSet<>();
|
* Возвращает только последнее сообщение каждого пользователя переданного из списка.
|
||||||
List<Mail> returnMails = new ArrayList<>();
|
*/
|
||||||
|
private List<Mail> findLastMailEachUser(List<Mail> mails) {
|
||||||
|
final Set<Long> people = new HashSet<>();
|
||||||
|
final List<Mail> returnMails = new ArrayList<>();
|
||||||
for (int i = mails.size() - 1; i >= 0; i--) {
|
for (int i = mails.size() - 1; i >= 0; i--) {
|
||||||
if (!people.contains(mails.get(i).getPersonId())) {
|
if (!people.contains(mails.get(i).getPersonId())) {
|
||||||
returnMails.add(mails.get(i));
|
returnMails.add(mails.get(i));
|
||||||
|
Loading…
Reference in New Issue
Block a user