diff --git a/pom.xml b/pom.xml index 76dd72e..f48b5bd 100644 --- a/pom.xml +++ b/pom.xml @@ -71,6 +71,11 @@ validation-api ${validation.api.ver} + + org.springframework.boot + spring-boot-autoconfigure + 2.1.3.RELEASE + diff --git a/src/main/java/org/sadtech/social/core/config/SocialJpaSpringConfig.java b/src/main/java/org/sadtech/social/core/config/SocialJpaSpringConfig.java new file mode 100644 index 0000000..ebf6709 --- /dev/null +++ b/src/main/java/org/sadtech/social/core/config/SocialJpaSpringConfig.java @@ -0,0 +1,15 @@ +package org.sadtech.social.core.config; + +import org.springframework.boot.autoconfigure.domain.EntityScan; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; + +/** + * Конфигуратор для использования в {@link org.springframework.context.annotation.Import}. + * + * @author upagge [28/07/2019] + */ +@EnableJpaRepositories(basePackages = "org.sadtech.social.core.repository.jpa") +@EntityScan(basePackages = "org.sadtech.social.core.domain") +public class SocialJpaSpringConfig { + +} diff --git a/src/main/java/org/sadtech/social/core/domain/content/Mail.java b/src/main/java/org/sadtech/social/core/domain/content/Mail.java index 3ac675f..64dd705 100644 --- a/src/main/java/org/sadtech/social/core/domain/content/Mail.java +++ b/src/main/java/org/sadtech/social/core/domain/content/Mail.java @@ -30,18 +30,13 @@ public class Mail extends Message { @Description("Вложения к сообщению") private List attachments; + @OneToMany + @Column(name = "forward_mail") + @Description("Пересланные сообщения") + private List forwardMail; + public Mail() { type = ContentType.MAIL; } - public Mail(Mail source) { - super(source); - this.attachments = source.getAttachments(); - } - - - public Mail prototype() { - return new Mail(this); - } - } diff --git a/src/main/java/org/sadtech/social/core/domain/content/Message.java b/src/main/java/org/sadtech/social/core/domain/content/Message.java index a1dc7fb..37e030c 100644 --- a/src/main/java/org/sadtech/social/core/domain/content/Message.java +++ b/src/main/java/org/sadtech/social/core/domain/content/Message.java @@ -33,6 +33,10 @@ public abstract class Message extends BasicEntity { @Description("Дата создания") private LocalDateTime createDate; + @Column(name = "add_date") + @Description("Дата добавления в базу") + private LocalDateTime addDate; + @NotNull @Column(name = "person_id") @Description("Идентификатор пользователя, отправившего сообщение") diff --git a/src/main/java/org/sadtech/social/core/domain/jpa/JsonObjectId.java b/src/main/java/org/sadtech/social/core/domain/jpa/JsonObjectId.java deleted file mode 100644 index d76186f..0000000 --- a/src/main/java/org/sadtech/social/core/domain/jpa/JsonObjectId.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.sadtech.social.core.domain.jpa; - -import com.google.gson.JsonObject; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; -import org.sadtech.social.core.domain.BasicEntity; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Table; - -/** - * TODO: Добавить описание класса. - * - * @author upagge [28/07/2019] - */ -@Data -@RequiredArgsConstructor -@EqualsAndHashCode(callSuper = true) -@Entity -@Table(name = "event") -public class JsonObjectId extends BasicEntity { - - @Column(name = "json") - @NonNull - private JsonObject jsonObject; - -} diff --git a/src/main/java/org/sadtech/social/core/repository/ContentRepository.java b/src/main/java/org/sadtech/social/core/repository/ContentRepository.java index 179d89b..73952ef 100644 --- a/src/main/java/org/sadtech/social/core/repository/ContentRepository.java +++ b/src/main/java/org/sadtech/social/core/repository/ContentRepository.java @@ -27,6 +27,8 @@ public interface ContentRepository { * @param timeTo Конец диапазона * @return Список сообщений */ - List betweenByTime(LocalDateTime timeFrom, LocalDateTime timeTo); + List betweenByCreateDateTime(LocalDateTime timeFrom, LocalDateTime timeTo); + + List betweenByAddDateTime(LocalDateTime from, LocalDateTime to); } diff --git a/src/main/java/org/sadtech/social/core/repository/impl/jpa/MailRepositoryJpaImpl.java b/src/main/java/org/sadtech/social/core/repository/impl/jpa/MailRepositoryJpaImpl.java index 3d96ca2..138bc42 100644 --- a/src/main/java/org/sadtech/social/core/repository/impl/jpa/MailRepositoryJpaImpl.java +++ b/src/main/java/org/sadtech/social/core/repository/impl/jpa/MailRepositoryJpaImpl.java @@ -24,7 +24,13 @@ public class MailRepositoryJpaImpl implements ContentRepository { } @Override - public List betweenByTime(LocalDateTime timeFrom, LocalDateTime timeTo) { + public List betweenByCreateDateTime(LocalDateTime timeFrom, LocalDateTime timeTo) { return mailRepositoryJpa.findByCreateDateBetween(timeFrom, timeTo); } + + @Override + public List betweenByAddDateTime(LocalDateTime from, LocalDateTime to) { + return mailRepositoryJpa.findByAddDateBetween(from, to); + } + } diff --git a/src/main/java/org/sadtech/social/core/repository/impl/local/BoardCommentRepositoryMap.java b/src/main/java/org/sadtech/social/core/repository/impl/local/BoardCommentRepositoryMap.java index faaa6c6..fbd8fc6 100644 --- a/src/main/java/org/sadtech/social/core/repository/impl/local/BoardCommentRepositoryMap.java +++ b/src/main/java/org/sadtech/social/core/repository/impl/local/BoardCommentRepositoryMap.java @@ -22,7 +22,7 @@ public class BoardCommentRepositoryMap implements ContentRepository betweenByTime(LocalDateTime timeFrom, LocalDateTime timeTo) { + public List betweenByCreateDateTime(LocalDateTime timeFrom, LocalDateTime timeTo) { ArrayList rezultMails = new ArrayList<>(); for (int i = saveMap.size() - 1; i >= 0; i--) { if (!(saveMap.get(i).getCreateDate().isBefore(timeFrom) || saveMap.get(i).getCreateDate().isAfter(timeTo)) && saveMap.get(i).getCreateDate().equals(timeFrom)) { @@ -33,4 +33,18 @@ public class BoardCommentRepositoryMap implements ContentRepository betweenByAddDateTime(LocalDateTime from, LocalDateTime to) { + ArrayList rezultMails = new ArrayList<>(); + for (int i = saveMap.size() - 1; i >= 0; i--) { + if (!(saveMap.get(i).getAddDate().isBefore(from) || saveMap.get(i).getAddDate().isAfter(to)) && saveMap.get(i).getAddDate().equals(from)) { + rezultMails.add(this.saveMap.get(i)); + } else if (saveMap.get(i).getCreateDate().isBefore(to)) { + break; + } + } + return rezultMails; + } + } diff --git a/src/main/java/org/sadtech/social/core/repository/impl/local/MailRepositoryList.java b/src/main/java/org/sadtech/social/core/repository/impl/local/MailRepositoryList.java index c5afdf3..512d0bc 100644 --- a/src/main/java/org/sadtech/social/core/repository/impl/local/MailRepositoryList.java +++ b/src/main/java/org/sadtech/social/core/repository/impl/local/MailRepositoryList.java @@ -1,5 +1,6 @@ package org.sadtech.social.core.repository.impl.local; +import lombok.extern.slf4j.Slf4j; import org.sadtech.social.core.domain.content.Mail; import org.sadtech.social.core.repository.ContentRepository; @@ -12,29 +13,51 @@ import java.util.List; * * @author upagge [27/07/2019] */ +@Slf4j public class MailRepositoryList implements ContentRepository { private final List mails = new ArrayList<>(); @Override public Integer add(Mail mail) { + int id = mails.size(); + mail.setId(id); mails.add(mail); - return mails.size() - 1; + return id; } - @Override - public List betweenByTime(LocalDateTime timeFrom, LocalDateTime timeTo) { + public List betweenByCreateDateTime(LocalDateTime from, LocalDateTime to) { ArrayList rezultMails = new ArrayList<>(); for (int i = mails.size() - 1; i >= 0; i--) { - if (!(mails.get(i).getCreateDate().isBefore(timeFrom) || mails.get(i).getCreateDate().isAfter(timeTo))) { - rezultMails.add(this.mails.get(i)); - } else if (mails.get(i).getCreateDate().isBefore(timeFrom)) { + Mail mail = mails.get(i); + if (isTimePeriod(from, to, mail.getAddDate())) { + rezultMails.add(mail); + } else if (mail.getCreateDate().isBefore(from)) { break; } } return rezultMails; } + @Override + public List betweenByAddDateTime(LocalDateTime from, LocalDateTime to) { + ArrayList rezultMails = new ArrayList<>(); + for (int i = mails.size() - 1; i >= 0; i--) { + Mail mail = mails.get(i); + LocalDateTime addDate = mail.getAddDate(); + if (isTimePeriod(from, to, addDate)) { + rezultMails.add(mail); + } else if (addDate.isBefore(from)) { + break; + } + } + return rezultMails; + } + + private boolean isTimePeriod(LocalDateTime from, LocalDateTime to, LocalDateTime dateTime) { + return from.isBefore(dateTime) && to.isAfter(dateTime); + } + } diff --git a/src/main/java/org/sadtech/social/core/repository/jpa/MailRepositoryJpa.java b/src/main/java/org/sadtech/social/core/repository/jpa/MailRepositoryJpa.java index e953fcb..57b6715 100644 --- a/src/main/java/org/sadtech/social/core/repository/jpa/MailRepositoryJpa.java +++ b/src/main/java/org/sadtech/social/core/repository/jpa/MailRepositoryJpa.java @@ -18,4 +18,6 @@ public interface MailRepositoryJpa extends JpaRepository { List findByCreateDateBetween(LocalDateTime from, LocalDateTime to); + List findByAddDateBetween(LocalDateTime from, LocalDateTime to); + } diff --git a/src/main/java/org/sadtech/social/core/service/MessageService.java b/src/main/java/org/sadtech/social/core/service/MessageService.java index 36e8c85..a5ca63e 100644 --- a/src/main/java/org/sadtech/social/core/service/MessageService.java +++ b/src/main/java/org/sadtech/social/core/service/MessageService.java @@ -20,7 +20,7 @@ public interface MessageService { * @param timeTo Конец интервала * @return Список сообщений */ - List getByTime(LocalDateTime timeFrom, LocalDateTime timeTo); + List getByAddDateTime(LocalDateTime timeFrom, LocalDateTime timeTo); /** * Получить список ПОСЛЕДНИХ сообщений для каждого пользователя за заданных временной интервал @@ -28,6 +28,8 @@ public interface MessageService { * @param timeTo Конец интервала * @return Список сообщений */ - List getLastEventByTime(LocalDateTime timeFrom, LocalDateTime timeTo); + List getLastEventByCreateDateTime(LocalDateTime timeFrom, LocalDateTime timeTo); + + List getLastEventByAddDateTime(LocalDateTime timeFrom, LocalDateTime timeTo); } diff --git a/src/main/java/org/sadtech/social/core/service/impl/BoardCommentServiceImpl.java b/src/main/java/org/sadtech/social/core/service/impl/BoardCommentServiceImpl.java index 196d0b9..b004d96 100644 --- a/src/main/java/org/sadtech/social/core/service/impl/BoardCommentServiceImpl.java +++ b/src/main/java/org/sadtech/social/core/service/impl/BoardCommentServiceImpl.java @@ -24,14 +24,25 @@ public class BoardCommentServiceImpl implements BoardCommentService { } @Override - public List getByTime(LocalDateTime timeFrom, LocalDateTime timeTo) { + public List getByAddDateTime(LocalDateTime timeFrom, LocalDateTime timeTo) { return null; } @Override - public List getLastEventByTime(LocalDateTime timeFrom, LocalDateTime timeTo) { + public List getLastEventByCreateDateTime(LocalDateTime timeFrom, LocalDateTime timeTo) { log.info("Запрошены последние комментарии к обсуждению {} - {} ", timeFrom, timeTo); - List mails = commentRepository.betweenByTime(timeFrom, timeTo); + List mails = commentRepository.betweenByCreateDateTime(timeFrom, timeTo); + return getBoardComments(mails); + } + + @Override + public List getLastEventByAddDateTime(LocalDateTime timeFrom, LocalDateTime timeTo) { + log.info("Запрошены последние комментарии к обсуждению {} - {} ", timeFrom, timeTo); + List mails = commentRepository.betweenByAddDateTime(timeFrom, timeTo); + return getBoardComments(mails); + } + + private List getBoardComments(List mails) { Set people = new HashSet<>(); List returnMails = new ArrayList<>(); for (int i = mails.size() - 1; i >= 0; i--) { @@ -42,4 +53,5 @@ public class BoardCommentServiceImpl implements BoardCommentService { } return returnMails; } + } diff --git a/src/main/java/org/sadtech/social/core/service/impl/MailServiceImpl.java b/src/main/java/org/sadtech/social/core/service/impl/MailServiceImpl.java index a390189..561d6fd 100644 --- a/src/main/java/org/sadtech/social/core/service/impl/MailServiceImpl.java +++ b/src/main/java/org/sadtech/social/core/service/impl/MailServiceImpl.java @@ -8,6 +8,7 @@ import org.sadtech.social.core.service.MailService; import java.time.LocalDateTime; import java.util.ArrayList; +import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -25,9 +26,34 @@ public class MailServiceImpl implements MailService { } @Override - public List getLastEventByTime(LocalDateTime timeFrom, LocalDateTime timeTo) { - log.info("Запрошены последние сообщения {} - {} ", timeFrom, timeTo); - List mails = mailRepository.betweenByTime(timeFrom, timeTo); + public List getByAddDateTime(LocalDateTime timeFrom, LocalDateTime timeTo) { + log.debug("Запрошены все сообщения {} - {} ", timeFrom, timeTo); + return mailRepository.betweenByAddDateTime(timeFrom, timeTo); + } + + @Override + public List getLastEventByCreateDateTime(LocalDateTime timeFrom, LocalDateTime timeTo) { + log.debug("Запрошены последние сообщения {} - {} ", timeFrom, timeTo); + List mails = mailRepository.betweenByCreateDateTime(timeFrom, timeTo); + if (mails != null && !mails.isEmpty()) { + return getReturnMails(mails); + } else { + return Collections.emptyList(); + } + } + + @Override + public List getLastEventByAddDateTime(LocalDateTime timeFrom, LocalDateTime timeTo) { + log.debug("Запрошены последние сообщения {} - {} ", timeFrom, timeTo); + List mails = mailRepository.betweenByAddDateTime(timeFrom, timeTo); + if (mails != null && !mails.isEmpty()) { + return getReturnMails(mails); + } else { + return Collections.emptyList(); + } + } + + private List getReturnMails(List mails) { Set people = new HashSet<>(); List returnMails = new ArrayList<>(); for (int i = mails.size() - 1; i >= 0; i--) { @@ -36,13 +62,11 @@ public class MailServiceImpl implements MailService { people.add(mails.get(i).getPersonId()); } } - return returnMails; - } - - @Override - public List getByTime(LocalDateTime timeFrom, LocalDateTime timeTo) { - log.info("Запрошены все сообщения {} - {} ", timeFrom, timeTo); - return mailRepository.betweenByTime(timeFrom, timeTo); + if (!returnMails.isEmpty()) { + return returnMails; + } else { + return Collections.emptyList(); + } } }