diff --git a/pom.xml b/pom.xml
index b0b0bd0..9b8e494 100644
--- a/pom.xml
+++ b/pom.xml
@@ -24,7 +24,8 @@
0.6.1-SNAPSHOT
- 0.5.13-SNAPSHOT
+
+ 1.0.2
1.2.17
diff --git a/src/main/java/org/sadtech/vkbot/core/distribution/Convert.java b/src/main/java/org/sadtech/vkbot/core/convert/Convert.java
similarity index 50%
rename from src/main/java/org/sadtech/vkbot/core/distribution/Convert.java
rename to src/main/java/org/sadtech/vkbot/core/convert/Convert.java
index 6f2e201..792bd25 100644
--- a/src/main/java/org/sadtech/vkbot/core/distribution/Convert.java
+++ b/src/main/java/org/sadtech/vkbot/core/convert/Convert.java
@@ -1,8 +1,8 @@
-package org.sadtech.vkbot.core.distribution;
+package org.sadtech.vkbot.core.convert;
-@FunctionalInterface
public interface Convert {
C converting(T target);
+
}
diff --git a/src/main/java/org/sadtech/vkbot/core/convert/MessageMailConvert.java b/src/main/java/org/sadtech/vkbot/core/convert/MessageMailConvert.java
new file mode 100644
index 0000000..a09b446
--- /dev/null
+++ b/src/main/java/org/sadtech/vkbot/core/convert/MessageMailConvert.java
@@ -0,0 +1,50 @@
+package org.sadtech.vkbot.core.convert;
+
+import com.vk.api.sdk.objects.messages.Message;
+import com.vk.api.sdk.objects.messages.MessageAttachment;
+import org.sadtech.bot.core.domain.attachment.Attachment;
+import org.sadtech.bot.core.domain.attachment.AudioMessage;
+import org.sadtech.bot.core.domain.attachment.Geo;
+import org.sadtech.bot.core.domain.content.Mail;
+
+import java.time.Instant;
+import java.time.LocalDateTime;
+import java.util.TimeZone;
+import java.util.stream.Collectors;
+
+public class MessageMailConvert implements Convert {
+
+ @Override
+ public Mail converting(Message message) {
+ Mail mail = new Mail();
+ mail.setMessage(message.getText());
+ mail.setDate(LocalDateTime.ofInstant(Instant.ofEpochSecond(message.getDate()), TimeZone.getDefault().toZoneId()));
+ mail.setId(message.getId());
+ mail.setPersonId(message.getPeerId());
+ mail.setAttachments(message.getAttachments()
+ .stream()
+ .map(this::convertAttachment)
+ .collect(Collectors.toList()));
+ mail.getAttachments().add(convertGeo(message.getGeo()));
+ return mail;
+ }
+
+ private Geo convertGeo(com.vk.api.sdk.objects.base.Geo geoVk) {
+ return Geo.builder()
+ .coordinate(geoVk.getCoordinates().getLatitude(),
+ geoVk.getCoordinates().getLongitude())
+ .build();
+ }
+
+ private Attachment convertAttachment(MessageAttachment vkAttachment) {
+ Attachment attachment = null;
+ switch (vkAttachment.getType()) {
+ case AUDIO_MESSAGE:
+ AudioMessage audioMessage = new AudioMessage();
+ audioMessage.setLinkOdd(vkAttachment.getAudioMessage().getLinkOgg());
+ attachment = audioMessage;
+ break;
+ }
+ return attachment;
+ }
+}
diff --git a/src/main/java/org/sadtech/vkbot/core/distribution/AbstractBasketSubscribe.java b/src/main/java/org/sadtech/vkbot/core/distribution/AbstractBasketSubscribe.java
index f136494..7d3affe 100644
--- a/src/main/java/org/sadtech/vkbot/core/distribution/AbstractBasketSubscribe.java
+++ b/src/main/java/org/sadtech/vkbot/core/distribution/AbstractBasketSubscribe.java
@@ -1,5 +1,7 @@
package org.sadtech.vkbot.core.distribution;
+import org.sadtech.vkbot.core.convert.Convert;
+
import java.util.Set;
public abstract class AbstractBasketSubscribe {
diff --git a/src/main/java/org/sadtech/vkbot/core/distribution/AccountSubscribe.java b/src/main/java/org/sadtech/vkbot/core/distribution/AccountSubscribe.java
index aba0a81..d100355 100644
--- a/src/main/java/org/sadtech/vkbot/core/distribution/AccountSubscribe.java
+++ b/src/main/java/org/sadtech/vkbot/core/distribution/AccountSubscribe.java
@@ -1,14 +1,41 @@
package org.sadtech.vkbot.core.distribution;
import com.vk.api.sdk.objects.messages.Message;
+import org.sadtech.bot.core.domain.BoxAnswer;
+import org.sadtech.bot.core.exception.PaymentException;
import org.sadtech.bot.core.service.AccountService;
+import org.sadtech.bot.core.service.sender.Sent;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class AccountSubscribe extends AbstractBasketSubscribe {
- private final AccountService accountService;
+ private static final Logger log = LoggerFactory.getLogger(AccountSubscribe.class);
- public AccountSubscribe(AccountService accountService) {
+ private final AccountService accountService;
+ private final Sent sent;
+ private BoxAnswer answerSuccessfulPayment;
+ private BoxAnswer answerFailPayment;
+
+ public AccountSubscribe(AccountService accountService, Sent sent) {
this.accountService = accountService;
+ this.sent = sent;
+ }
+
+ public BoxAnswer getAnswerSuccessfulPayment() {
+ return answerSuccessfulPayment;
+ }
+
+ public void setAnswerSuccessfulPayment(BoxAnswer answerSuccessfulPayment) {
+ this.answerSuccessfulPayment = answerSuccessfulPayment;
+ }
+
+ public BoxAnswer getAnswerFailPayment() {
+ return answerFailPayment;
+ }
+
+ public void setAnswerFailPayment(BoxAnswer answerFailPayment) {
+ this.answerFailPayment = answerFailPayment;
}
@Override
@@ -17,7 +44,15 @@ public class AccountSubscribe extends AbstractBasketSubscribe
}
@Override
- public void processing(Message object) {
- accountService.pay(0);
+ public void processing(Message message) {
+ if (message.getText() != null) {
+ try {
+ if (accountService.pay(Integer.valueOf(message.getText()), message.getPeerId(), Double.valueOf(message.getAttachments().get(0).getLink().getTitle().split(" ")[0]))) {
+ sent.send(message.getPeerId(), answerSuccessfulPayment);
+ }
+ } catch (PaymentException e) {
+ sent.send(message.getPeerId(), BoxAnswer.builder().message(e.getDescription()).build());
+ }
+ }
}
}
diff --git a/src/main/java/org/sadtech/vkbot/core/distribution/EventDistributor.java b/src/main/java/org/sadtech/vkbot/core/distribution/EventDistributor.java
index f5e250f..731da2e 100644
--- a/src/main/java/org/sadtech/vkbot/core/distribution/EventDistributor.java
+++ b/src/main/java/org/sadtech/vkbot/core/distribution/EventDistributor.java
@@ -20,6 +20,7 @@ public class EventDistributor extends AbstractBasketSubscribe {
- private static final Logger log = Logger.getLogger(MailSubscriber.class);
-
private final MailService mailService;
+ private final Convert mailConvert = new MessageMailConvert();
public MailSubscriber(MailService mailService) {
this.mailService = mailService;
@@ -39,26 +29,7 @@ public class MailSubscriber extends AbstractBasketSubscribe
@Override
public void processing(Message object) {
- mailService.add(createMail(object));
- }
-
- private Mail createMail(Message message) {
- Mail mail = new Mail();
- mail.setMessage(message.getText());
- mail.setDate(LocalDateTime.ofInstant(Instant.ofEpochSecond(message.getDate()), TimeZone.getDefault().toZoneId()));
- mail.setId(message.getId());
- mail.setPersonId(message.getPeerId());
-
- List attachments = new ArrayList<>();
- for (MessageAttachment attachment : message.getAttachments()) {
- if (MessageAttachmentType.AUDIO_MESSAGE.equals(attachment.getType())) {
- AudioMessage audioMessage = new AudioMessage();
- audioMessage.setLinkOdd(attachment.getAudioMessage().getLinkOgg());
- attachments.add(audioMessage);
- }
- }
- mail.setAttachments(attachments);
- return mail;
+ mailService.add(mailConvert.converting(object));
}
}
diff --git a/src/main/java/org/sadtech/vkbot/core/sender/MailSenderVk.java b/src/main/java/org/sadtech/vkbot/core/sender/MailSenderVk.java
index 09bb80b..0af6de0 100644
--- a/src/main/java/org/sadtech/vkbot/core/sender/MailSenderVk.java
+++ b/src/main/java/org/sadtech/vkbot/core/sender/MailSenderVk.java
@@ -54,8 +54,8 @@ public class MailSenderVk implements Sent {
keyboard.setButtons(Collections.EMPTY_LIST);
messages.keyboard(keyboard);
}
- if (boxAnswer.getLat() != null && boxAnswer.getaLong() != null) {
- messages.lat(boxAnswer.getLat()).lng(boxAnswer.getaLong());
+ if (boxAnswer.getCoordinates() != null) {
+ messages.lat(boxAnswer.getCoordinates().getLat()).lng(boxAnswer.getCoordinates().getaLong());
}
if (boxAnswer.getStickerId() != null) {
try {
diff --git a/src/main/java/org/sadtech/vkbot/core/service/PersonServiceImpl.java b/src/main/java/org/sadtech/vkbot/core/service/PersonServiceImpl.java
deleted file mode 100644
index c14abb0..0000000
--- a/src/main/java/org/sadtech/vkbot/core/service/PersonServiceImpl.java
+++ /dev/null
@@ -1,74 +0,0 @@
-package org.sadtech.vkbot.core.service;
-
-import com.vk.api.sdk.objects.users.User;
-import com.vk.api.sdk.objects.users.UserMin;
-import org.apache.log4j.Logger;
-import org.sadtech.bot.core.domain.Person;
-import org.sadtech.bot.core.repository.PersonRepository;
-import org.sadtech.bot.core.repository.impl.PersonRepositoryMap;
-import org.sadtech.bot.core.service.PersonService;
-import org.sadtech.vkbot.core.VkApi;
-import org.sadtech.vkbot.core.VkConnect;
-
-public class PersonServiceImpl implements PersonService {
-
- private static final Logger log = Logger.getLogger(PersonServiceImpl.class);
-
- private final PersonRepository personRepository;
- private final VkApi vkApi;
-
- public PersonServiceImpl(VkConnect vkConnect) {
- this.personRepository = new PersonRepositoryMap();
- vkApi = new VkApi(vkConnect);
- }
-
- public PersonServiceImpl(PersonRepository personRepository, VkConnect vkConnect) {
- this.personRepository = personRepository;
- vkApi = new VkApi(vkConnect);
- }
-
- public void add(User user) {
- Person person = new Person();
- person.setId(user.getId());
- person.setLastName(user.getLastName());
- person.setFirstName(user.getFirstName());
- personRepository.add(person);
- log.info("Пользователь добавлен в репозиторий");
- }
-
- @Override
- public void add(Person person) {
- personRepository.add(person);
- log.info("Пользователь добавлен в репозиторий");
- }
-
- public void add(UserMin userMin) {
- Person person = new Person();
- person.setId(userMin.getId());
- person.setFirstName(userMin.getFirstName());
- person.setLastName(userMin.getLastName());
- personRepository.add(person);
- }
-
- @Override
- public Person get(Integer id) {
- return personRepository.get(id);
- }
-
- @Override
- public boolean checkPerson(Integer idPerson) {
- log.info("Проверка наличия пользователя в репозитории");
- return get(idPerson) != null;
- }
-
- @Override
- public Person createPerson(Integer userId) {
- Person person = new Person();
- UserMin userMin = vkApi.getUserMini(userId);
- person.setId(userMin.getId());
- person.setLastName(userMin.getLastName());
- person.setFirstName(userMin.getFirstName());
- return person;
- }
-
-}