Рефакторинг

This commit is contained in:
Mark Struchkov 2019-05-17 18:59:51 +03:00
parent a4601316ca
commit a584af0e92
4 changed files with 1 additions and 83 deletions

View File

@ -47,9 +47,6 @@
<version>${bot.core.ver}</version>
</dependency>
</dependencies>
<developers>

View File

@ -9,7 +9,7 @@ import org.apache.log4j.Logger;
import org.sadtech.bot.core.domain.Mail;
import org.sadtech.bot.core.domain.attachment.Attachment;
import org.sadtech.bot.core.domain.attachment.AudioMessage;
import org.sadtech.vkbot.core.service.distribution.MailService;
import org.sadtech.bot.core.service.MailService;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

View File

@ -1,8 +0,0 @@
package org.sadtech.vkbot.core.service.distribution;
import org.sadtech.bot.core.domain.Mail;
import org.sadtech.bot.core.service.EventService;
public interface MailService extends EventService<Mail> {
}

View File

@ -1,71 +0,0 @@
package org.sadtech.vkbot.core.service.distribution.impl;
import org.apache.log4j.Logger;
import org.sadtech.bot.core.domain.Mail;
import org.sadtech.bot.core.repository.MailRepository;
import org.sadtech.bot.core.repository.impl.MailRepositoryList;
import org.sadtech.vkbot.core.service.distribution.MailService;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class MailServiceImpl implements MailService {
private static final Logger log = Logger.getLogger(MailServiceImpl.class);
private final MailRepository mailRepository;
public MailServiceImpl() {
this.mailRepository = new MailRepositoryList();
}
public MailServiceImpl(MailRepository mailRepository) {
this.mailRepository = mailRepository;
}
@Override
public void add(Mail mail) {
mailRepository.add(mail);
log.info("Сообщение добавлено в репозиторий");
log.info(mail);
}
@Override
public List<Mail> getFirstEventByTime(LocalDateTime timeFrom, LocalDateTime timeTo) {
log.info("Запрошены сообщения " + timeFrom + " - " + timeTo);
List<Mail> mails = mailRepository.getMailByTime(timeFrom, timeTo);
Set<Integer> people = new HashSet<>();
List<Mail> returnMails = new ArrayList<>();
for (int i = mails.size() - 1; i >= 0; i--) {
if (!people.contains(mails.get(i).getPersonId())) {
returnMails.add(mails.get(i));
people.add(mails.get(i).getPersonId());
}
}
return returnMails;
}
@Override
public List<Mail> getLastEventByTime(LocalDateTime timeFrom, LocalDateTime timeTo) {
List<Mail> mails = mailRepository.getMailByTime(timeFrom, timeTo);
Set<Integer> people = new HashSet<>();
List<Mail> returnMails = new ArrayList<>();
for (Mail mail : mails) {
if (!people.contains(mail.getPersonId())) {
returnMails.add(mail);
people.add(mail.getPersonId());
}
}
return returnMails;
}
@Override
public List<Mail> getEvent(LocalDateTime timeFrom, LocalDateTime timeTo) {
log.info("Запрос на получение сообщений в интервале от " + timeFrom + " до " + timeTo);
return mailRepository.getMailByTime(timeFrom, timeTo);
}
}