Исправления в проверке новых сообщений от пользователя

Исправления мапинга для бд
Переименование метода findByTime в betweenByTime
This commit is contained in:
Mark Struchkov 2019-07-28 08:51:31 +03:00
parent 18fbf8127f
commit 198bb8599b
13 changed files with 29 additions and 25 deletions

View File

@ -62,6 +62,11 @@
<artifactId>javax.persistence-api</artifactId> <artifactId>javax.persistence-api</artifactId>
<version>2.2</version> <version>2.2</version>
</dependency> </dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>
</dependencies> </dependencies>
<developers> <developers>

View File

@ -7,6 +7,7 @@ import org.sadtech.social.core.utils.Description;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import javax.persistence.Table; import javax.persistence.Table;
import java.util.List; import java.util.List;
@ -22,7 +23,7 @@ import java.util.List;
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
public class Mail extends Message { public class Mail extends Message {
@OneToMany @OneToMany(fetch = FetchType.EAGER)
@Column(name = "attachment") @Column(name = "attachment")
@Description("Вложения к сообщению") @Description("Вложения к сообщению")
private List<Attachment> attachments; private List<Attachment> attachments;

View File

@ -1,15 +1,15 @@
package org.sadtech.social.core.domain.content; package org.sadtech.social.core.domain.content;
import com.sun.istack.internal.NotNull;
import lombok.Data; import lombok.Data;
import org.sadtech.social.core.utils.Description; import org.sadtech.social.core.utils.Description;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType; import javax.persistence.EnumType;
import javax.persistence.Enumerated; import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.validation.constraints.NotNull;
import java.time.LocalDateTime; import java.time.LocalDateTime;
/** /**
@ -18,7 +18,7 @@ import java.time.LocalDateTime;
* @author upagge [08/07/2019] * @author upagge [08/07/2019]
*/ */
@Data @Data
@Entity @MappedSuperclass
public abstract class Message { public abstract class Message {
@Id @Id

View File

@ -1,13 +1,9 @@
package org.sadtech.social.core.domain.money; package org.sadtech.social.core.domain.money;
import com.sun.istack.internal.NotNull;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
import lombok.EqualsAndHashCode; import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.sadtech.social.core.utils.Description; import org.sadtech.social.core.utils.Description;
import javax.persistence.Column; import javax.persistence.Column;
@ -17,6 +13,7 @@ import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.Table; import javax.persistence.Table;
import javax.validation.constraints.NotNull;
/** /**
* Сущность, которая отвечает за выставленный пользователю счет. * Сущность, которая отвечает за выставленный пользователю счет.
@ -24,10 +21,7 @@ import javax.persistence.Table;
* @author upagge [08/07/2019] * @author upagge [08/07/2019]
*/ */
@Builder @Builder
@Getter @Data
@Setter
@EqualsAndHashCode
@ToString
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@Entity @Entity

View File

@ -27,6 +27,6 @@ public interface ContentRepository<T extends Message> {
* @param timeTo Конец диапазона * @param timeTo Конец диапазона
* @return Список сообщений * @return Список сообщений
*/ */
List<T> findByTime(LocalDateTime timeFrom, LocalDateTime timeTo); List<T> betweenByTime(LocalDateTime timeFrom, LocalDateTime timeTo);
} }

View File

@ -3,18 +3,18 @@ package org.sadtech.social.core.repository.impl.jpa;
import org.sadtech.social.core.domain.money.Account; import org.sadtech.social.core.domain.money.Account;
import org.sadtech.social.core.repository.AccountRepository; import org.sadtech.social.core.repository.AccountRepository;
import org.sadtech.social.core.repository.jpa.AccountRepositoryJpa; import org.sadtech.social.core.repository.jpa.AccountRepositoryJpa;
import org.springframework.stereotype.Repository; import org.springframework.beans.factory.annotation.Autowired;
/** /**
* TODO: Добавить описание класса. * TODO: Добавить описание класса.
* *
* @author upagge [27/07/2019] * @author upagge [27/07/2019]
*/ */
@Repository
public class AccountRepositoryJpaImpl implements AccountRepository { public class AccountRepositoryJpaImpl implements AccountRepository {
private final AccountRepositoryJpa accountRepositoryJpa; private final AccountRepositoryJpa accountRepositoryJpa;
@Autowired
public AccountRepositoryJpaImpl(AccountRepositoryJpa accountRepositoryJpa) { public AccountRepositoryJpaImpl(AccountRepositoryJpa accountRepositoryJpa) {
this.accountRepositoryJpa = accountRepositoryJpa; this.accountRepositoryJpa = accountRepositoryJpa;
} }

View File

@ -3,7 +3,7 @@ package org.sadtech.social.core.repository.impl.jpa;
import org.sadtech.social.core.domain.content.Mail; import org.sadtech.social.core.domain.content.Mail;
import org.sadtech.social.core.repository.ContentRepository; import org.sadtech.social.core.repository.ContentRepository;
import org.sadtech.social.core.repository.jpa.MailRepositoryJpa; import org.sadtech.social.core.repository.jpa.MailRepositoryJpa;
import org.springframework.stereotype.Repository; import org.springframework.beans.factory.annotation.Autowired;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List; import java.util.List;
@ -13,11 +13,11 @@ import java.util.List;
* *
* @author upagge [25/07/2019] * @author upagge [25/07/2019]
*/ */
@Repository
public class MailRepositoryJpaImpl implements ContentRepository<Mail> { public class MailRepositoryJpaImpl implements ContentRepository<Mail> {
private final MailRepositoryJpa mailRepositoryJpa; private final MailRepositoryJpa mailRepositoryJpa;
@Autowired
public MailRepositoryJpaImpl(MailRepositoryJpa mailRepositoryJpa) { public MailRepositoryJpaImpl(MailRepositoryJpa mailRepositoryJpa) {
this.mailRepositoryJpa = mailRepositoryJpa; this.mailRepositoryJpa = mailRepositoryJpa;
} }
@ -28,7 +28,7 @@ public class MailRepositoryJpaImpl implements ContentRepository<Mail> {
} }
@Override @Override
public List<Mail> findByTime(LocalDateTime timeFrom, LocalDateTime timeTo) { public List<Mail> betweenByTime(LocalDateTime timeFrom, LocalDateTime timeTo) {
return mailRepositoryJpa.findByCreateDateBetween(timeFrom, timeTo); return mailRepositoryJpa.findByCreateDateBetween(timeFrom, timeTo);
} }
} }

View File

@ -22,7 +22,7 @@ public class BoardCommentRepositoryMap implements ContentRepository<BoardComment
} }
@Override @Override
public List<BoardComment> findByTime(LocalDateTime timeFrom, LocalDateTime timeTo) { public List<BoardComment> betweenByTime(LocalDateTime timeFrom, LocalDateTime timeTo) {
ArrayList<BoardComment> rezultMails = new ArrayList<>(); ArrayList<BoardComment> rezultMails = new ArrayList<>();
for (int i = saveMap.size() - 1; i >= 0; i--) { 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)) { if (!(saveMap.get(i).getCreateDate().isBefore(timeFrom) || saveMap.get(i).getCreateDate().isAfter(timeTo)) && saveMap.get(i).getCreateDate().equals(timeFrom)) {

View File

@ -24,10 +24,10 @@ public class MailRepositoryList implements ContentRepository<Mail> {
@Override @Override
public List<Mail> findByTime(LocalDateTime timeFrom, LocalDateTime timeTo) { public List<Mail> betweenByTime(LocalDateTime timeFrom, LocalDateTime timeTo) {
ArrayList<Mail> rezultMails = new ArrayList<>(); ArrayList<Mail> rezultMails = new ArrayList<>();
for (int i = mails.size() - 1; i >= 0; i--) { for (int i = mails.size() - 1; i >= 0; i--) {
if (!(mails.get(i).getCreateDate().isBefore(timeFrom) || mails.get(i).getCreateDate().isAfter(timeTo)) && mails.get(i).getCreateDate().equals(timeFrom)) { if (!(mails.get(i).getCreateDate().isBefore(timeFrom) || mails.get(i).getCreateDate().isAfter(timeTo))) {
rezultMails.add(this.mails.get(i)); rezultMails.add(this.mails.get(i));
} else if (mails.get(i).getCreateDate().isBefore(timeFrom)) { } else if (mails.get(i).getCreateDate().isBefore(timeFrom)) {
break; break;

View File

@ -2,12 +2,14 @@ package org.sadtech.social.core.repository.jpa;
import org.sadtech.social.core.domain.money.Account; import org.sadtech.social.core.domain.money.Account;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
/** /**
* TODO: Добавить описание интерфейса. * TODO: Добавить описание интерфейса.
* *
* @author upagge [27/07/2019] * @author upagge [27/07/2019]
*/ */
@Repository
public interface AccountRepositoryJpa extends JpaRepository<Account, Integer> { public interface AccountRepositoryJpa extends JpaRepository<Account, Integer> {
} }

View File

@ -2,6 +2,7 @@ package org.sadtech.social.core.repository.jpa;
import org.sadtech.social.core.domain.content.Mail; import org.sadtech.social.core.domain.content.Mail;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List; import java.util.List;
@ -12,6 +13,7 @@ import java.util.List;
* *
* @author upagge [27/07/2019] * @author upagge [27/07/2019]
*/ */
@Repository
public interface MailRepositoryJpa extends JpaRepository<Mail, Integer> { public interface MailRepositoryJpa extends JpaRepository<Mail, Integer> {
List<Mail> findByCreateDateBetween(LocalDateTime from, LocalDateTime to); List<Mail> findByCreateDateBetween(LocalDateTime from, LocalDateTime to);

View File

@ -35,7 +35,7 @@ public class BoardCommentServiceImpl implements BoardCommentService {
@Override @Override
public List<BoardComment> getLastEventByTime(LocalDateTime timeFrom, LocalDateTime timeTo) { public List<BoardComment> getLastEventByTime(LocalDateTime timeFrom, LocalDateTime timeTo) {
log.info("Запрошены последние комментарии к обсуждению {} - {} ", timeFrom, timeTo); log.info("Запрошены последние комментарии к обсуждению {} - {} ", timeFrom, timeTo);
List<BoardComment> mails = commentRepository.findByTime(timeFrom, timeTo); List<BoardComment> mails = commentRepository.betweenByTime(timeFrom, timeTo);
Set<Integer> people = new HashSet<>(); Set<Integer> people = new HashSet<>();
List<BoardComment> returnMails = new ArrayList<>(); List<BoardComment> returnMails = new ArrayList<>();
for (int i = mails.size() - 1; i >= 0; i--) { for (int i = mails.size() - 1; i >= 0; i--) {

View File

@ -31,7 +31,7 @@ public class MailServiceImpl implements MailService {
@Override @Override
public List<Mail> getLastEventByTime(LocalDateTime timeFrom, LocalDateTime timeTo) { public List<Mail> getLastEventByTime(LocalDateTime timeFrom, LocalDateTime timeTo) {
log.info("Запрошены последние сообщения {} - {} ", timeFrom, timeTo); log.info("Запрошены последние сообщения {} - {} ", timeFrom, timeTo);
List<Mail> mails = mailRepository.findByTime(timeFrom, timeTo); List<Mail> mails = mailRepository.betweenByTime(timeFrom, timeTo);
Set<Integer> people = new HashSet<>(); Set<Integer> people = new HashSet<>();
List<Mail> returnMails = new ArrayList<>(); List<Mail> returnMails = new ArrayList<>();
for (int i = mails.size() - 1; i >= 0; i--) { for (int i = mails.size() - 1; i >= 0; i--) {
@ -46,7 +46,7 @@ public class MailServiceImpl implements MailService {
@Override @Override
public List<Mail> getByTime(LocalDateTime timeFrom, LocalDateTime timeTo) { public List<Mail> getByTime(LocalDateTime timeFrom, LocalDateTime timeTo) {
log.info("Запрошены все сообщения {} - {} ", timeFrom, timeTo); log.info("Запрошены все сообщения {} - {} ", timeFrom, timeTo);
return mailRepository.findByTime(timeFrom, timeTo); return mailRepository.betweenByTime(timeFrom, timeTo);
} }
} }