Размышления над архитектурой

* Продолжаю настроивать взаимодействие с юнитами
* Главный класс автоответчика разбил на методы
This commit is contained in:
Mark Struchkov 2019-01-25 15:24:30 +03:00
parent b5a8680f09
commit 04062ba8b1
13 changed files with 40 additions and 120 deletions

12
pom.xml
View File

@ -20,11 +20,20 @@
</plugins>
</build>
<developers>
<developer>
<id>uPagge</id>
<name>Struchkov Mark</name>
<email>upagge@mail.ru</email>
</developer>
</developers>
<properties>
<gson.ver>2.8.5</gson.ver>
<vksdk.ver>0.5.13-SNAPSHOT</vksdk.ver>
<log4j.ver>1.2.17</log4j.ver>
<json.ver>20180813</json.ver>
<autoresponder.ver>1.1.2-SNAPHOT</autoresponder.ver>
</properties>
<dependencies>
@ -51,8 +60,7 @@
<dependency>
<groupId>org.sadtech.autoresponder</groupId>
<artifactId>autoresponder</artifactId>
<version>1.1.2-SNAPHOT</version>
<scope>compile</scope>
<version>${autoresponder.ver}</version>
</dependency>
</dependencies>

View File

@ -1,10 +0,0 @@
package org.sadtech.vkbot.core.entity.unit;
import org.sadtech.vkbot.autoresponder.DataService;
public class SaveAnswer extends TextAnswer {
private SaveAnswer prevSaveAnswer;
private DataService dataService;
}

View File

@ -1,16 +0,0 @@
package org.sadtech.vkbot.core.entity.unit;
import org.sadtech.vkbot.core.keyboard.KeyBoard;
public class TextAndKeyBoardAnswer extends TextAnswer {
KeyBoard keyBoard;
public KeyBoard getKeyBoard() {
return keyBoard;
}
public void setKeyBoard(KeyBoard keyBoard) {
this.keyBoard = keyBoard;
}
}

View File

@ -1,16 +0,0 @@
package org.sadtech.vkbot.core.entity.unit;
import org.sadtech.autoresponder.entity.Unit;
public class TextAnswer extends Unit {
private String answer;
public String getAnswer() {
return answer;
}
public void setAnswer(String answer) {
this.answer = answer;
}
}

View File

@ -0,0 +1,7 @@
package org.sadtech.vkbot.core.keyboard;
public interface ButtonKeyBoardService {
}

View File

@ -0,0 +1,4 @@
package org.sadtech.vkbot.core.keyboard;
public interface LineKeyBoardService {
}

View File

@ -1,6 +1,6 @@
package org.sadtech.vkbot.core.listener;
public interface EventListenable extends Runnable {
public interface EventListener extends Runnable {
void listen() throws Exception;

View File

@ -1,4 +1,4 @@
package org.sadtech.vkbot.core.listener.impl;
package org.sadtech.vkbot.core.listener;
import com.google.gson.JsonObject;
import com.vk.api.sdk.actions.LongPoll;
@ -15,9 +15,8 @@ import org.sadtech.vkbot.core.repository.EventRepository;
import org.sadtech.vkbot.core.repository.impl.EventRepositoryQueue;
import org.sadtech.vkbot.core.service.EventService;
import org.sadtech.vkbot.core.service.impl.EventServiceImpl;
import org.sadtech.vkbot.core.listener.EventListenable;
public class EventListenerVk implements EventListenable, Runnable {
public class EventListenerVk implements EventListener, Runnable {
public static final Logger log = Logger.getLogger(EventListenerVk.class);

View File

@ -1,24 +0,0 @@
package org.sadtech.vkbot.core.repository.unit;
import org.sadtech.vkbot.core.entity.unit.TextAndKeyBoardAnswer;
import org.sadtech.autoresponder.repository.UnitRepository;
import java.util.List;
public class TextAndKeyBoardAnswerRepository implements UnitRepository<TextAndKeyBoardAnswer> {
@Override
public void addUnit(TextAndKeyBoardAnswer unit) {
}
@Override
public void addUnits(List<TextAndKeyBoardAnswer> units) {
}
@Override
public List<TextAndKeyBoardAnswer> menuUnits() {
return null;
}
}

View File

@ -1,35 +0,0 @@
package org.sadtech.vkbot.core.repository.unit;
import org.sadtech.vkbot.core.entity.unit.TextAnswer;
import org.sadtech.autoresponder.repository.UnitRepository;
import java.util.ArrayList;
import java.util.List;
public class TextAnswerRepository implements UnitRepository<TextAnswer> {
private List<TextAnswer> textAnswers;
public TextAnswerRepository() {
textAnswers = new ArrayList<>();
}
public TextAnswerRepository(List<TextAnswer> textAnswers) {
this.textAnswers = textAnswers;
}
@Override
public void addUnit(TextAnswer unit) {
textAnswers.add(unit);
}
@Override
public void addUnits(List<TextAnswer> units) {
textAnswers.addAll(units);
}
@Override
public List<TextAnswer> menuUnits() {
return textAnswers;
}
}

View File

@ -6,9 +6,8 @@ import com.vk.api.sdk.exceptions.ApiException;
import com.vk.api.sdk.exceptions.ClientException;
import org.sadtech.vkbot.core.VkConnect;
import org.sadtech.vkbot.core.entity.Person;
import org.sadtech.vkbot.core.keyboard.KeyBoard;
public class MailSanderVk {
public class MailSanderVk implements MailSandler {
private Person person;
private VkApiClient vkApiClient;
@ -29,20 +28,12 @@ public class MailSanderVk {
this.person = person;
}
public void sendText(String messageText) {
@Override
public void send(String text) {
try {
vkApiClient.messages().send(groupActor).userId(person.getId()).message(messageText).execute();
vkApiClient.messages().send(groupActor).userId(person.getId()).message(text).execute();
} catch (ApiException | ClientException e) {
e.printStackTrace();
}
}
public void sendTextandKeyBoard(String message, KeyBoard keyBoard) {
try {
vkApiClient.messages().send(groupActor).userId(person.getId()).message(message).keyboard(keyBoard.getKeyboard(true).toString()).execute();
} catch (ApiException | ClientException e) {
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,11 @@
package org.sadtech.vkbot.core.sender;
import org.sadtech.vkbot.core.entity.Person;
public interface MailSandler {
void send(String text);
void setPerson(Person person);
}

View File

@ -33,6 +33,7 @@ public class MailServiceImpl implements MailService {
@Override
public List<Mail> getFirstMailByTime(Integer timeFrom, Integer timeTo) {
log.info("Запрошены сообщения от " + timeFrom + " до " + timeTo);
List<Mail> mails = messageRepository.getMailByTime(timeFrom, timeTo);
Set<Person> people = new HashSet<>();
List<Mail> returnMails = new ArrayList<>();