Архитектурное разбиение на независимые проекты
This commit is contained in:
parent
273356cd83
commit
863229f5b6
@ -0,0 +1,7 @@
|
||||
package org.sadtech.consultant;
|
||||
|
||||
public interface MessageSender {
|
||||
|
||||
void send(Integer idNetSoc, String text);
|
||||
|
||||
}
|
@ -6,7 +6,7 @@ import javax.persistence.*;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
public class Message {
|
||||
public class Mail {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@ -14,11 +14,10 @@ public class Message {
|
||||
private String text;
|
||||
private Long date;
|
||||
private String sourceMessage;
|
||||
private String sex;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "idUser", nullable = false)
|
||||
private Person user;
|
||||
@JoinColumn(name = "idPerson", nullable = false)
|
||||
private Person person;
|
||||
|
||||
|
||||
}
|
@ -24,10 +24,13 @@ public class Person {
|
||||
private String city;
|
||||
|
||||
private String token;
|
||||
private String email;
|
||||
|
||||
@ElementCollection
|
||||
@CollectionTable(name = "PersonSocialNetworks")
|
||||
@MapKeyColumn(name = "KeysSocialNetworks", length = 20)
|
||||
private Map<String, Integer> socialNetworks = new HashMap<>();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -2,8 +2,7 @@ package org.sadtech.consultant.database.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Data
|
||||
@ -13,4 +12,8 @@ public class SaveUnit {
|
||||
private Long id;
|
||||
private Long idStage;
|
||||
|
||||
@OneToOne
|
||||
@JoinColumn(name = "idPerson", nullable = false)
|
||||
private Person user;
|
||||
|
||||
}
|
||||
|
@ -1,15 +1,15 @@
|
||||
package org.sadtech.consultant.database.repository;
|
||||
|
||||
import org.sadtech.consultant.database.entity.Message;
|
||||
import org.sadtech.consultant.database.entity.Mail;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public interface MessageRepository extends JpaRepository<Message, Long> {
|
||||
public interface MailRepository extends JpaRepository<Mail, Long> {
|
||||
|
||||
@Query("SELECT u FROM Message u WHERE u.date > :date")
|
||||
Collection<Message> getMessagesByRange(@Param("date") Long date);
|
||||
@Query("SELECT u FROM Mail u WHERE u.date > :date")
|
||||
Collection<Mail> getMessagesByRange(@Param("date") Long date);
|
||||
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package org.sadtech.consultant.database.service;
|
||||
|
||||
import org.sadtech.consultant.database.entity.Mail;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface MailService {
|
||||
|
||||
void addMessage(Mail message);
|
||||
|
||||
List<Mail> getMessageRange(Long date);
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
package org.sadtech.consultant.database.service;
|
||||
|
||||
import org.sadtech.consultant.database.entity.Message;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface MessageService {
|
||||
|
||||
void addMessage(Message message);
|
||||
|
||||
List<Message> getMessageRange(Long date);
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package org.sadtech.consultant.database.service.impl;
|
||||
|
||||
import org.sadtech.consultant.database.entity.Mail;
|
||||
import org.sadtech.consultant.database.repository.MailRepository;
|
||||
import org.sadtech.consultant.database.service.MailService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class MailServiceImpl implements MailService {
|
||||
|
||||
@Autowired
|
||||
private MailRepository repository;
|
||||
|
||||
public void addMessage(Mail message) {
|
||||
repository.saveAndFlush(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Mail> getMessageRange(Long date) {
|
||||
return (List<Mail>) repository.getMessagesByRange(date);
|
||||
}
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package org.sadtech.consultant.database.service.impl;
|
||||
|
||||
import org.sadtech.consultant.database.entity.Message;
|
||||
import org.sadtech.consultant.database.repository.MessageRepository;
|
||||
import org.sadtech.consultant.database.service.MessageService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class MessageServiceImpl implements MessageService {
|
||||
|
||||
@Autowired
|
||||
private MessageRepository repository;
|
||||
|
||||
public void addMessage(Message message) {
|
||||
repository.saveAndFlush(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Message> getMessageRange(Long date) {
|
||||
return (List<Message>) repository.getMessagesByRange(date);
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package org.sadtech.consultant.database.service.impl;
|
||||
|
||||
import org.sadtech.consultant.database.entity.Person;
|
||||
import org.sadtech.consultant.database.repository.PersonRepository;
|
||||
import org.sadtech.consultant.database.entity.Person;
|
||||
import org.sadtech.consultant.database.service.PersonService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -1,7 +1,7 @@
|
||||
package org.sadtech.consultant.database.service.impl;
|
||||
|
||||
import org.sadtech.consultant.database.entity.Unit;
|
||||
import org.sadtech.consultant.database.repository.UnitRepositoriy;
|
||||
import org.sadtech.consultant.database.entity.Unit;
|
||||
import org.sadtech.consultant.database.service.UnitService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -1,12 +1,17 @@
|
||||
package org.sadtech.consultant.processing;
|
||||
|
||||
import lombok.extern.log4j.Log4j;
|
||||
import org.sadtech.consultant.database.entity.Message;
|
||||
import org.sadtech.consultant.database.entity.Mail;
|
||||
import org.sadtech.consultant.MessageSender;
|
||||
import org.sadtech.consultant.database.entity.Person;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Log4j
|
||||
@Component
|
||||
@ -14,6 +19,7 @@ public class MessageHandler {
|
||||
|
||||
private MessageLogicService messageLogicService;
|
||||
private PersonLogicService userLogicService;
|
||||
private Map<String, MessageSender> senderHashMap = new HashMap<>();
|
||||
private long data;
|
||||
|
||||
public MessageHandler(MessageLogicService messageLogicService, PersonLogicService userLogicService) {
|
||||
@ -22,13 +28,25 @@ public class MessageHandler {
|
||||
data = new Date().getTime() / 1000;
|
||||
}
|
||||
|
||||
public void addMessageSendler(String type, MessageSender messageSender) {
|
||||
senderHashMap.put(type, messageSender);
|
||||
}
|
||||
|
||||
@Async
|
||||
@Transactional
|
||||
public void processing() {
|
||||
log.info("process");
|
||||
while (true) {
|
||||
List<Message> messages = messageLogicService.getMessageRange(data);
|
||||
for (Message message : messages) {
|
||||
log.info(message);
|
||||
data = message.getDate();
|
||||
List<Mail> messages = messageLogicService.getMessageRange(data);
|
||||
if (messages.size()>0) {
|
||||
for (Mail message : messages) {
|
||||
log.info(message);
|
||||
Person person = message.getPerson();
|
||||
Integer idNetSoc = person.getSocialNetworks().get(message.getSourceMessage());
|
||||
senderHashMap.get(message.getSourceMessage()).send(idNetSoc, "Тестовое сообщение");
|
||||
|
||||
data = message.getDate();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package org.sadtech.consultant.processing;
|
||||
|
||||
import org.sadtech.consultant.database.entity.Message;
|
||||
import org.sadtech.consultant.database.service.MessageService;
|
||||
import org.sadtech.consultant.database.entity.Mail;
|
||||
import org.sadtech.consultant.database.service.MailService;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
@ -9,17 +9,17 @@ import java.util.List;
|
||||
@Component
|
||||
public class MessageLogicService {
|
||||
|
||||
private MessageService messageService;
|
||||
private MailService messageService;
|
||||
|
||||
public MessageLogicService(MessageService messageService) {
|
||||
public MessageLogicService(MailService messageService) {
|
||||
this.messageService = messageService;
|
||||
}
|
||||
|
||||
public void addMessage(Message message) {
|
||||
public void addMessage(Mail message) {
|
||||
messageService.addMessage(message);
|
||||
}
|
||||
|
||||
public List<Message> getMessageRange(long data) {
|
||||
public List<Mail> getMessageRange(long data) {
|
||||
return messageService.getMessageRange(data);
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>consultant</artifactId>
|
||||
<groupId>org.sadtech</groupId>
|
||||
<version>0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>facebook-bot</artifactId>
|
||||
|
||||
|
||||
</project>
|
181
fit-elit-consultant/pom.xml
Normal file
181
fit-elit-consultant/pom.xml
Normal file
@ -0,0 +1,181 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>consultant</artifactId>
|
||||
<groupId>org.sadtech</groupId>
|
||||
<version>0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>ru.fit-elit</groupId>
|
||||
<artifactId>consultant</artifactId>
|
||||
<version>0.1-SNAPSHOT</version>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>7</source>
|
||||
<target>7</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<vk.api.ver>0.5.13-SNAPSHOT</vk.api.ver>
|
||||
|
||||
<spring.core>5.1.3.RELEASE</spring.core>
|
||||
<spring.context>5.1.3.RELEASE</spring.context>
|
||||
<spring.web>5.1.3.RELEASE</spring.web>
|
||||
<spring.webmvc>5.1.3.RELEASE</spring.webmvc>
|
||||
<spring.context>5.1.3.RELEASE</spring.context>
|
||||
<spring.context>5.1.3.RELEASE</spring.context>
|
||||
<spring.data>2.1.3.RELEASE</spring.data>
|
||||
|
||||
<javax.servlet>3.1.0</javax.servlet>
|
||||
<javax.persistance>2.2</javax.persistance>
|
||||
|
||||
<hibernate.entitymanager>5.4.0.Final</hibernate.entitymanager>
|
||||
<hibernate.core>5.2.10.Final</hibernate.core>
|
||||
|
||||
<mysql.connector>8.0.13</mysql.connector>
|
||||
|
||||
<lombok>1.18.4</lombok>
|
||||
|
||||
<log4j>1.2.17</log4j>
|
||||
|
||||
<json>20180813</json>
|
||||
|
||||
<jetty.util>6.1.25</jetty.util>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.vk.api</groupId>
|
||||
<artifactId>sdk</artifactId>
|
||||
<version>${vk.api.ver}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.sadtech</groupId>
|
||||
<artifactId>vk-bot</artifactId>
|
||||
<version>0.2-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>${log4j}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-core</artifactId>
|
||||
<version>${spring.core}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
<version>${spring.context}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context-support</artifactId>
|
||||
<version>${spring.context}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-web</artifactId>
|
||||
<version>${spring.web}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-webmvc</artifactId>
|
||||
<version>${spring.webmvc}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-jpa</artifactId>
|
||||
<version>${spring.data}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-orm</artifactId>
|
||||
<version>5.1.3.RELEASE</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.8.5</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mortbay.jetty</groupId>
|
||||
<artifactId>jetty-util</artifactId>
|
||||
<version>${jetty.util}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.json</groupId>
|
||||
<artifactId>json</artifactId>
|
||||
<version>${json}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.persistence</groupId>
|
||||
<artifactId>javax.persistence-api</artifactId>
|
||||
<version>${javax.persistance}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>${mysql.connector}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-entitymanager</artifactId>
|
||||
<version>${hibernate.entitymanager}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-core</artifactId>
|
||||
<version>${hibernate.core}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-nop</artifactId>
|
||||
<version>1.7.13</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.sadtech</groupId>
|
||||
<artifactId>consultant-core</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains</groupId>
|
||||
<artifactId>annotations-java5</artifactId>
|
||||
<version>16.0.2</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -1,11 +1,11 @@
|
||||
package org.sadtech.vkbot;
|
||||
package ru.fitelit.consultant;
|
||||
|
||||
import lombok.extern.log4j.Log4j;
|
||||
import org.sadtech.consultant.processing.MessageHandler;
|
||||
import org.sadtech.vkbot.config.SpringConfigVk;
|
||||
import org.sadtech.vkbot.listener.EventListenable;
|
||||
import org.sadtech.vkbot.handlers.Handled;
|
||||
import org.sadtech.vkbot.core.handlers.Handled;
|
||||
import org.sadtech.vkbot.core.listener.EventListenable;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import ru.fitelit.consultant.config.SpringConfigVk;
|
||||
|
||||
@Log4j
|
||||
public class Main {
|
||||
@ -19,9 +19,9 @@ public class Main {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SpringConfigVk.class);
|
||||
EventListenable eventListener = context.getBean(EventListenable.class);
|
||||
eventListener.listen();
|
||||
Handled dispetcherHandler = context.getBean(Handled.class);
|
||||
dispetcherHandler.sortAndSend();
|
||||
// MessageHandler messageHandler = context.getBean(MessageHandler.class);
|
||||
// messageHandler.processing();
|
||||
Handled dispatcherHandler = context.getBean(Handled.class);
|
||||
dispatcherHandler.sortAndSend();
|
||||
MessageHandler messageHandler = context.getBean(MessageHandler.class);
|
||||
messageHandler.processing();
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package org.sadtech.vkbot.config;
|
||||
package ru.fitelit.consultant.config;
|
||||
|
||||
import org.hibernate.jpa.HibernatePersistenceProvider;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
@ -1,4 +1,4 @@
|
||||
package org.sadtech.vkbot.config;
|
||||
package ru.fitelit.consultant.config;
|
||||
|
||||
import com.vk.api.sdk.client.TransportClient;
|
||||
import com.vk.api.sdk.client.VkApiClient;
|
||||
@ -21,7 +21,7 @@ import java.util.concurrent.Executors;
|
||||
@EnableAsync
|
||||
@PropertySource("classpath:config.properties")
|
||||
@Import({DataConfig.class})
|
||||
@ComponentScan({"org.sadtech.vkbot", "org.sadtech.consultant.processing"})
|
||||
@ComponentScan({"ru.fitelit.consultant", "org.sadtech.consultant.processing", "org.sadtech.vkbot.core"})
|
||||
|
||||
public class SpringConfigVk {
|
||||
|
@ -2,9 +2,9 @@
|
||||
//
|
||||
//import com.vk.api.sdk.exceptions.ApiException;
|
||||
//import com.vk.api.sdk.exceptions.ClientException;
|
||||
//import org.sadtech.vkbot.listener.EventListenable;
|
||||
//import org.sadtech.vkbot.listener.Observable;
|
||||
//import org.sadtech.vkbot.listener.impl.EventListenerVk;
|
||||
//import EventListenable;
|
||||
//import Observable;
|
||||
//import EventListenerVk;
|
||||
//import org.springframework.context.annotation.ComponentScan;
|
||||
//import org.springframework.context.annotation.Configuration;
|
||||
//import org.springframework.web.WebApplicationInitializer;
|
2
pom.xml
2
pom.xml
@ -11,7 +11,7 @@
|
||||
<modules>
|
||||
<module>vk-bot</module>
|
||||
<module>core</module>
|
||||
<module>facebook-bot</module>
|
||||
<module>fit-elit-consultant</module>
|
||||
</modules>
|
||||
|
||||
|
||||
|
@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
|
||||
version="4.0">
|
||||
</web-app>
|
@ -2,16 +2,17 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<parent>
|
||||
<artifactId>time-table</artifactId>
|
||||
<artifactId>consultant</artifactId>
|
||||
<groupId>org.sadtech</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.sadtech</groupId>
|
||||
<artifactId>vk-bot</artifactId>
|
||||
<version>0.1-SNAPSHOT</version>
|
||||
<version>0.2-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
@ -170,6 +171,12 @@
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains</groupId>
|
||||
<artifactId>annotations-java5</artifactId>
|
||||
<version>16.0.2</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
@ -1,4 +1,4 @@
|
||||
package org.sadtech.vkbot;
|
||||
package org.sadtech.vkbot.core;
|
||||
|
||||
public enum SourceMessage {
|
||||
VK("VK"),
|
@ -1,4 +1,4 @@
|
||||
package org.sadtech.vkbot;
|
||||
package org.sadtech.vkbot.core;
|
||||
|
||||
import com.vk.api.sdk.client.VkApiClient;
|
||||
import com.vk.api.sdk.client.actors.GroupActor;
|
@ -1,4 +1,4 @@
|
||||
package org.sadtech.vkbot.listener.data;
|
||||
package org.sadtech.vkbot.core.data;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
@ -1,7 +1,7 @@
|
||||
package org.sadtech.vkbot.listener.data.impl;
|
||||
package org.sadtech.vkbot.core.data.impl;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import org.sadtech.vkbot.listener.data.ResponsibleData;
|
||||
import org.sadtech.vkbot.core.data.ResponsibleData;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Queue;
|
@ -0,0 +1,9 @@
|
||||
package org.sadtech.vkbot.core.handlers;
|
||||
|
||||
import org.sadtech.vkbot.core.listener.Observer;
|
||||
|
||||
public interface Handled {
|
||||
|
||||
void sortAndSend() throws Exception;
|
||||
void registerObserver(Observer o);
|
||||
}
|
@ -1,11 +1,11 @@
|
||||
package org.sadtech.vkbot.handlers.impl;
|
||||
package org.sadtech.vkbot.core.handlers.impl;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import lombok.extern.log4j.Log4j;
|
||||
import org.sadtech.vkbot.handlers.Handled;
|
||||
import org.sadtech.vkbot.listener.Observable;
|
||||
import org.sadtech.vkbot.listener.Observer;
|
||||
import org.sadtech.vkbot.listener.data.ResponsibleData;
|
||||
import org.sadtech.vkbot.core.handlers.Handled;
|
||||
import org.sadtech.vkbot.core.listener.Observable;
|
||||
import org.sadtech.vkbot.core.data.ResponsibleData;
|
||||
import org.sadtech.vkbot.core.listener.Observer;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@ -13,14 +13,14 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Log4j
|
||||
@Component
|
||||
public class DispetcherHandlerVk implements Observable, Handled {
|
||||
@Component("dispatcherHandler")
|
||||
public class DispatcherHandlerVk implements Observable, Handled {
|
||||
|
||||
private ResponsibleData date;
|
||||
private List<Observer> observers = new ArrayList<Observer>();
|
||||
private List<Observer> observers = new ArrayList<>();
|
||||
private JsonObject event;
|
||||
|
||||
public DispetcherHandlerVk(ResponsibleData date) {
|
||||
public DispatcherHandlerVk(ResponsibleData date) {
|
||||
this.date = date;
|
||||
}
|
||||
|
@ -1,17 +1,19 @@
|
||||
package org.sadtech.vkbot.handlers.impl;
|
||||
package org.sadtech.vkbot.core.handlers.impl;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.vk.api.sdk.objects.messages.Message;
|
||||
import com.vk.api.sdk.objects.users.UserXtrCounters;
|
||||
import lombok.extern.log4j.Log4j;
|
||||
import org.sadtech.consultant.database.entity.Message;
|
||||
import org.sadtech.consultant.database.entity.Mail;
|
||||
import org.sadtech.consultant.database.entity.Person;
|
||||
import org.sadtech.consultant.processing.MessageLogicService;
|
||||
import org.sadtech.consultant.processing.PersonLogicService;
|
||||
import org.sadtech.vkbot.SourceMessage;
|
||||
import org.sadtech.vkbot.VkApi;
|
||||
import org.sadtech.vkbot.listener.Observable;
|
||||
import org.sadtech.vkbot.listener.Observer;
|
||||
import org.sadtech.vkbot.core.SourceMessage;
|
||||
import org.sadtech.vkbot.core.VkApi;
|
||||
import org.sadtech.vkbot.core.handlers.Handled;
|
||||
import org.sadtech.vkbot.core.listener.Observer;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Log4j
|
||||
@ -20,41 +22,40 @@ public class MessageHandlerVk implements Observer {
|
||||
|
||||
private MessageLogicService messageLogicService;
|
||||
private PersonLogicService personLogicService;
|
||||
private Message userMessage;
|
||||
|
||||
public MessageHandlerVk(Observable dispetcherHandler, PersonLogicService personLogicService, MessageLogicService messageLogicService) {
|
||||
public MessageHandlerVk(@Qualifier("dispatcherHandler") Handled dispatcherHandler, PersonLogicService personLogicService, MessageLogicService messageLogicService) {
|
||||
this.messageLogicService = messageLogicService;
|
||||
this.personLogicService = personLogicService;
|
||||
dispetcherHandler.registerObserver(this);
|
||||
dispatcherHandler.registerObserver(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(JsonObject object) {
|
||||
if (object.get("type").toString().equals("\"message_new\"")) {
|
||||
Gson gson = new Gson();
|
||||
log.info(object.getAsJsonObject("object"));
|
||||
com.vk.api.sdk.objects.messages.Message message = gson.fromJson(object.getAsJsonObject("object"), com.vk.api.sdk.objects.messages.Message.class);
|
||||
sendProcessing(message);
|
||||
userMessage = gson.fromJson(object.getAsJsonObject("object"), com.vk.api.sdk.objects.messages.Message.class);
|
||||
sortAndSend();
|
||||
}
|
||||
}
|
||||
|
||||
private void sendProcessing(com.vk.api.sdk.objects.messages.Message userMessage) {
|
||||
public void sortAndSend() {
|
||||
Person user;
|
||||
Integer userVkId = userMessage.getUserId();
|
||||
log.info(VkApi.getUserVk(userVkId));
|
||||
if (personLogicService.checkPersonBySocialNetworksId(SourceMessage.VK.name(), userVkId)) {
|
||||
user = personLogicService.getUserBySocialId(SourceMessage.VK.name(), userMessage.getUserId());
|
||||
} else {
|
||||
user = new Person();
|
||||
UserXtrCounters userXtrCounters = VkApi.getUserVk(userVkId);
|
||||
user.setCity("ыыыы");
|
||||
user.setCity("city");
|
||||
user.setName(userXtrCounters.getFirstName());
|
||||
user.setLastName(userXtrCounters.getLastName());
|
||||
user.getSocialNetworks().put(String.valueOf(SourceMessage.VK), userMessage.getUserId());
|
||||
personLogicService.addUser(user);
|
||||
}
|
||||
|
||||
Message message = new Message();
|
||||
message.setUser(user);
|
||||
Mail message = new Mail();
|
||||
message.setPerson(user);
|
||||
message.setText(userMessage.getBody());
|
||||
message.setDate(Long.valueOf(userMessage.getDate()));
|
||||
message.setSourceMessage(SourceMessage.VK.name());
|
@ -1,4 +1,4 @@
|
||||
package org.sadtech.vkbot.listener;
|
||||
package org.sadtech.vkbot.core.listener;
|
||||
|
||||
public interface EventListenable {
|
||||
void listen() throws Exception;
|
@ -1,7 +1,6 @@
|
||||
package org.sadtech.vkbot.listener;
|
||||
package org.sadtech.vkbot.core.listener;
|
||||
|
||||
public interface Observable {
|
||||
void registerObserver(Observer o);
|
||||
|
||||
// void removeObserver(Observer o);
|
||||
void notifyObservers();
|
@ -1,4 +1,4 @@
|
||||
package org.sadtech.vkbot.listener;
|
||||
package org.sadtech.vkbot.core.listener;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package org.sadtech.vkbot.listener.impl;
|
||||
package org.sadtech.vkbot.core.listener.impl;
|
||||
|
||||
import com.vk.api.sdk.actions.LongPoll;
|
||||
import com.vk.api.sdk.callback.longpoll.queries.GetLongPollEventsQuery;
|
||||
@ -9,8 +9,8 @@ import com.vk.api.sdk.exceptions.ApiException;
|
||||
import com.vk.api.sdk.exceptions.ClientException;
|
||||
import com.vk.api.sdk.objects.groups.responses.GetLongPollServerResponse;
|
||||
import lombok.extern.log4j.Log4j;
|
||||
import org.sadtech.vkbot.listener.EventListenable;
|
||||
import org.sadtech.vkbot.listener.data.ResponsibleData;
|
||||
import org.sadtech.vkbot.core.listener.EventListenable;
|
||||
import org.sadtech.vkbot.core.data.ResponsibleData;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@ -51,7 +51,7 @@ public class EventListenerVk implements EventListenable {
|
||||
if (eventsResponse.getUpdates().toArray().length != 0) {
|
||||
responseData.add(eventsResponse.getUpdates().get(0));
|
||||
log.info(eventsResponse.getUpdates());
|
||||
String test = "{\"one_time\":false,\"buttons\":[[{\"action\":{\"type\":\"text\",\"payload\":\"{\\\"button\\\": \\\"1\\\"}\",\"label\":\"Red2\"},\"color\":\"negative\"},{\"action\":{\"type\":\"text\",\"payload\":\"{\\\"button\\\": \\\"2\\\"}\",\"label\":\"Green\"},\"color\":\"positive\"}],[{\"action\":{\"type\":\"text\",\"payload\":\"{\\\"button\\\": \\\"3\\\"}\",\"label\":\"White\"},\"color\":\"default\"},{\"action\":{\"type\":\"text\",\"payload\":\"{\\\"button\\\": \\\"4\\\"}\",\"label\":\"Blue\"},\"color\":\"primary\"}]]}";
|
||||
// String test = "{\"one_time\":false,\"buttons\":[[{\"action\":{\"type\":\"text\",\"payload\":\"{\\\"button\\\": \\\"1\\\"}\",\"label\":\"Red2\"},\"color\":\"negative\"},{\"action\":{\"type\":\"text\",\"payload\":\"{\\\"button\\\": \\\"2\\\"}\",\"label\":\"Green\"},\"color\":\"positive\"}],[{\"action\":{\"type\":\"text\",\"payload\":\"{\\\"button\\\": \\\"3\\\"}\",\"label\":\"White\"},\"color\":\"default\"},{\"action\":{\"type\":\"text\",\"payload\":\"{\\\"button\\\": \\\"4\\\"}\",\"label\":\"Blue\"},\"color\":\"primary\"}]]}";
|
||||
}
|
||||
longPollEventsQuery = longPoll.getEvents(server.getServer(), server.getKey(), eventsResponse.getTs()).waitTime(20);
|
||||
} while (true);
|
@ -0,0 +1,20 @@
|
||||
package org.sadtech.vkbot.core.sendler;
|
||||
|
||||
import org.sadtech.consultant.MessageSender;
|
||||
import org.sadtech.consultant.processing.MessageHandler;
|
||||
import org.sadtech.vkbot.core.SourceMessage;
|
||||
import org.sadtech.vkbot.core.VkApi;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class MessageSendVk implements MessageSender {
|
||||
|
||||
public MessageSendVk(MessageHandler messageHandler) {
|
||||
messageHandler.addMessageSendler(SourceMessage.VK.name(), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(Integer idNetSoc, String text) {
|
||||
VkApi.sendMessage(idNetSoc, text);
|
||||
}
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
package org.sadtech.vkbot.handlers;
|
||||
|
||||
public interface Handled {
|
||||
|
||||
void sortAndSend() throws Exception;
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user