Архитектурное разбиение на независимые проекты
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
|
@Data
|
||||||
@Entity
|
@Entity
|
||||||
public class Message {
|
public class Mail {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
@ -14,11 +14,10 @@ public class Message {
|
|||||||
private String text;
|
private String text;
|
||||||
private Long date;
|
private Long date;
|
||||||
private String sourceMessage;
|
private String sourceMessage;
|
||||||
private String sex;
|
|
||||||
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(name = "idUser", nullable = false)
|
@JoinColumn(name = "idPerson", nullable = false)
|
||||||
private Person user;
|
private Person person;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -24,10 +24,13 @@ public class Person {
|
|||||||
private String city;
|
private String city;
|
||||||
|
|
||||||
private String token;
|
private String token;
|
||||||
|
private String email;
|
||||||
|
|
||||||
@ElementCollection
|
@ElementCollection
|
||||||
@CollectionTable(name = "PersonSocialNetworks")
|
@CollectionTable(name = "PersonSocialNetworks")
|
||||||
@MapKeyColumn(name = "KeysSocialNetworks", length = 20)
|
@MapKeyColumn(name = "KeysSocialNetworks", length = 20)
|
||||||
private Map<String, Integer> socialNetworks = new HashMap<>();
|
private Map<String, Integer> socialNetworks = new HashMap<>();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,7 @@ package org.sadtech.consultant.database.entity;
|
|||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.*;
|
||||||
import javax.persistence.Id;
|
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Data
|
@Data
|
||||||
@ -13,4 +12,8 @@ public class SaveUnit {
|
|||||||
private Long id;
|
private Long id;
|
||||||
private Long idStage;
|
private Long idStage;
|
||||||
|
|
||||||
|
@OneToOne
|
||||||
|
@JoinColumn(name = "idPerson", nullable = false)
|
||||||
|
private Person user;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
package org.sadtech.consultant.database.repository;
|
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.JpaRepository;
|
||||||
import org.springframework.data.jpa.repository.Query;
|
import org.springframework.data.jpa.repository.Query;
|
||||||
import org.springframework.data.repository.query.Param;
|
import org.springframework.data.repository.query.Param;
|
||||||
|
|
||||||
import java.util.Collection;
|
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")
|
@Query("SELECT u FROM Mail u WHERE u.date > :date")
|
||||||
Collection<Message> getMessagesByRange(@Param("date") Long 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;
|
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.repository.PersonRepository;
|
||||||
|
import org.sadtech.consultant.database.entity.Person;
|
||||||
import org.sadtech.consultant.database.service.PersonService;
|
import org.sadtech.consultant.database.service.PersonService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package org.sadtech.consultant.database.service.impl;
|
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.repository.UnitRepositoriy;
|
||||||
|
import org.sadtech.consultant.database.entity.Unit;
|
||||||
import org.sadtech.consultant.database.service.UnitService;
|
import org.sadtech.consultant.database.service.UnitService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
@ -1,12 +1,17 @@
|
|||||||
package org.sadtech.consultant.processing;
|
package org.sadtech.consultant.processing;
|
||||||
|
|
||||||
import lombok.extern.log4j.Log4j;
|
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.scheduling.annotation.Async;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@Log4j
|
@Log4j
|
||||||
@Component
|
@Component
|
||||||
@ -14,6 +19,7 @@ public class MessageHandler {
|
|||||||
|
|
||||||
private MessageLogicService messageLogicService;
|
private MessageLogicService messageLogicService;
|
||||||
private PersonLogicService userLogicService;
|
private PersonLogicService userLogicService;
|
||||||
|
private Map<String, MessageSender> senderHashMap = new HashMap<>();
|
||||||
private long data;
|
private long data;
|
||||||
|
|
||||||
public MessageHandler(MessageLogicService messageLogicService, PersonLogicService userLogicService) {
|
public MessageHandler(MessageLogicService messageLogicService, PersonLogicService userLogicService) {
|
||||||
@ -22,13 +28,25 @@ public class MessageHandler {
|
|||||||
data = new Date().getTime() / 1000;
|
data = new Date().getTime() / 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addMessageSendler(String type, MessageSender messageSender) {
|
||||||
|
senderHashMap.put(type, messageSender);
|
||||||
|
}
|
||||||
|
|
||||||
@Async
|
@Async
|
||||||
|
@Transactional
|
||||||
public void processing() {
|
public void processing() {
|
||||||
|
log.info("process");
|
||||||
while (true) {
|
while (true) {
|
||||||
List<Message> messages = messageLogicService.getMessageRange(data);
|
List<Mail> messages = messageLogicService.getMessageRange(data);
|
||||||
for (Message message : messages) {
|
if (messages.size()>0) {
|
||||||
log.info(message);
|
for (Mail message : messages) {
|
||||||
data = message.getDate();
|
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;
|
package org.sadtech.consultant.processing;
|
||||||
|
|
||||||
import org.sadtech.consultant.database.entity.Message;
|
import org.sadtech.consultant.database.entity.Mail;
|
||||||
import org.sadtech.consultant.database.service.MessageService;
|
import org.sadtech.consultant.database.service.MailService;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -9,17 +9,17 @@ import java.util.List;
|
|||||||
@Component
|
@Component
|
||||||
public class MessageLogicService {
|
public class MessageLogicService {
|
||||||
|
|
||||||
private MessageService messageService;
|
private MailService messageService;
|
||||||
|
|
||||||
public MessageLogicService(MessageService messageService) {
|
public MessageLogicService(MailService messageService) {
|
||||||
this.messageService = messageService;
|
this.messageService = messageService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addMessage(Message message) {
|
public void addMessage(Mail message) {
|
||||||
messageService.addMessage(message);
|
messageService.addMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Message> getMessageRange(long data) {
|
public List<Mail> getMessageRange(long data) {
|
||||||
return messageService.getMessageRange(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 lombok.extern.log4j.Log4j;
|
||||||
import org.sadtech.consultant.processing.MessageHandler;
|
import org.sadtech.consultant.processing.MessageHandler;
|
||||||
import org.sadtech.vkbot.config.SpringConfigVk;
|
import org.sadtech.vkbot.core.handlers.Handled;
|
||||||
import org.sadtech.vkbot.listener.EventListenable;
|
import org.sadtech.vkbot.core.listener.EventListenable;
|
||||||
import org.sadtech.vkbot.handlers.Handled;
|
|
||||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
|
import ru.fitelit.consultant.config.SpringConfigVk;
|
||||||
|
|
||||||
@Log4j
|
@Log4j
|
||||||
public class Main {
|
public class Main {
|
||||||
@ -19,9 +19,9 @@ public class Main {
|
|||||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SpringConfigVk.class);
|
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SpringConfigVk.class);
|
||||||
EventListenable eventListener = context.getBean(EventListenable.class);
|
EventListenable eventListener = context.getBean(EventListenable.class);
|
||||||
eventListener.listen();
|
eventListener.listen();
|
||||||
Handled dispetcherHandler = context.getBean(Handled.class);
|
Handled dispatcherHandler = context.getBean(Handled.class);
|
||||||
dispetcherHandler.sortAndSend();
|
dispatcherHandler.sortAndSend();
|
||||||
// MessageHandler messageHandler = context.getBean(MessageHandler.class);
|
MessageHandler messageHandler = context.getBean(MessageHandler.class);
|
||||||
// messageHandler.processing();
|
messageHandler.processing();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package org.sadtech.vkbot.config;
|
package ru.fitelit.consultant.config;
|
||||||
|
|
||||||
import org.hibernate.jpa.HibernatePersistenceProvider;
|
import org.hibernate.jpa.HibernatePersistenceProvider;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
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.TransportClient;
|
||||||
import com.vk.api.sdk.client.VkApiClient;
|
import com.vk.api.sdk.client.VkApiClient;
|
||||||
@ -21,7 +21,7 @@ import java.util.concurrent.Executors;
|
|||||||
@EnableAsync
|
@EnableAsync
|
||||||
@PropertySource("classpath:config.properties")
|
@PropertySource("classpath:config.properties")
|
||||||
@Import({DataConfig.class})
|
@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 {
|
public class SpringConfigVk {
|
||||||
|
|
@ -2,9 +2,9 @@
|
|||||||
//
|
//
|
||||||
//import com.vk.api.sdk.exceptions.ApiException;
|
//import com.vk.api.sdk.exceptions.ApiException;
|
||||||
//import com.vk.api.sdk.exceptions.ClientException;
|
//import com.vk.api.sdk.exceptions.ClientException;
|
||||||
//import org.sadtech.vkbot.listener.EventListenable;
|
//import EventListenable;
|
||||||
//import org.sadtech.vkbot.listener.Observable;
|
//import Observable;
|
||||||
//import org.sadtech.vkbot.listener.impl.EventListenerVk;
|
//import EventListenerVk;
|
||||||
//import org.springframework.context.annotation.ComponentScan;
|
//import org.springframework.context.annotation.ComponentScan;
|
||||||
//import org.springframework.context.annotation.Configuration;
|
//import org.springframework.context.annotation.Configuration;
|
||||||
//import org.springframework.web.WebApplicationInitializer;
|
//import org.springframework.web.WebApplicationInitializer;
|
2
pom.xml
2
pom.xml
@ -11,7 +11,7 @@
|
|||||||
<modules>
|
<modules>
|
||||||
<module>vk-bot</module>
|
<module>vk-bot</module>
|
||||||
<module>core</module>
|
<module>core</module>
|
||||||
<module>facebook-bot</module>
|
<module>fit-elit-consultant</module>
|
||||||
</modules>
|
</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"
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
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">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<artifactId>time-table</artifactId>
|
<artifactId>consultant</artifactId>
|
||||||
<groupId>org.sadtech</groupId>
|
<groupId>org.sadtech</groupId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>org.sadtech</groupId>
|
||||||
<artifactId>vk-bot</artifactId>
|
<artifactId>vk-bot</artifactId>
|
||||||
<version>0.1-SNAPSHOT</version>
|
<version>0.2-SNAPSHOT</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
@ -170,6 +171,12 @@
|
|||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jetbrains</groupId>
|
||||||
|
<artifactId>annotations-java5</artifactId>
|
||||||
|
<version>16.0.2</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package org.sadtech.vkbot;
|
package org.sadtech.vkbot.core;
|
||||||
|
|
||||||
public enum SourceMessage {
|
public enum SourceMessage {
|
||||||
VK("VK"),
|
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.VkApiClient;
|
||||||
import com.vk.api.sdk.client.actors.GroupActor;
|
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;
|
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 com.google.gson.JsonObject;
|
||||||
import org.sadtech.vkbot.listener.data.ResponsibleData;
|
import org.sadtech.vkbot.core.data.ResponsibleData;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.util.Queue;
|
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 com.google.gson.JsonObject;
|
||||||
import lombok.extern.log4j.Log4j;
|
import lombok.extern.log4j.Log4j;
|
||||||
import org.sadtech.vkbot.handlers.Handled;
|
import org.sadtech.vkbot.core.handlers.Handled;
|
||||||
import org.sadtech.vkbot.listener.Observable;
|
import org.sadtech.vkbot.core.listener.Observable;
|
||||||
import org.sadtech.vkbot.listener.Observer;
|
import org.sadtech.vkbot.core.data.ResponsibleData;
|
||||||
import org.sadtech.vkbot.listener.data.ResponsibleData;
|
import org.sadtech.vkbot.core.listener.Observer;
|
||||||
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.scheduling.annotation.Async;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@ -13,14 +13,14 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Log4j
|
@Log4j
|
||||||
@Component
|
@Component("dispatcherHandler")
|
||||||
public class DispetcherHandlerVk implements Observable, Handled {
|
public class DispatcherHandlerVk implements Observable, Handled {
|
||||||
|
|
||||||
private ResponsibleData date;
|
private ResponsibleData date;
|
||||||
private List<Observer> observers = new ArrayList<Observer>();
|
private List<Observer> observers = new ArrayList<>();
|
||||||
private JsonObject event;
|
private JsonObject event;
|
||||||
|
|
||||||
public DispetcherHandlerVk(ResponsibleData date) {
|
public DispatcherHandlerVk(ResponsibleData date) {
|
||||||
this.date = 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.Gson;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
import com.vk.api.sdk.objects.messages.Message;
|
||||||
import com.vk.api.sdk.objects.users.UserXtrCounters;
|
import com.vk.api.sdk.objects.users.UserXtrCounters;
|
||||||
import lombok.extern.log4j.Log4j;
|
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.database.entity.Person;
|
||||||
import org.sadtech.consultant.processing.MessageLogicService;
|
import org.sadtech.consultant.processing.MessageLogicService;
|
||||||
import org.sadtech.consultant.processing.PersonLogicService;
|
import org.sadtech.consultant.processing.PersonLogicService;
|
||||||
import org.sadtech.vkbot.SourceMessage;
|
import org.sadtech.vkbot.core.SourceMessage;
|
||||||
import org.sadtech.vkbot.VkApi;
|
import org.sadtech.vkbot.core.VkApi;
|
||||||
import org.sadtech.vkbot.listener.Observable;
|
import org.sadtech.vkbot.core.handlers.Handled;
|
||||||
import org.sadtech.vkbot.listener.Observer;
|
import org.sadtech.vkbot.core.listener.Observer;
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@Log4j
|
@Log4j
|
||||||
@ -20,41 +22,40 @@ public class MessageHandlerVk implements Observer {
|
|||||||
|
|
||||||
private MessageLogicService messageLogicService;
|
private MessageLogicService messageLogicService;
|
||||||
private PersonLogicService personLogicService;
|
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.messageLogicService = messageLogicService;
|
||||||
this.personLogicService = personLogicService;
|
this.personLogicService = personLogicService;
|
||||||
dispetcherHandler.registerObserver(this);
|
dispatcherHandler.registerObserver(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(JsonObject object) {
|
public void update(JsonObject object) {
|
||||||
if (object.get("type").toString().equals("\"message_new\"")) {
|
if (object.get("type").toString().equals("\"message_new\"")) {
|
||||||
Gson gson = new Gson();
|
Gson gson = new Gson();
|
||||||
log.info(object.getAsJsonObject("object"));
|
userMessage = gson.fromJson(object.getAsJsonObject("object"), com.vk.api.sdk.objects.messages.Message.class);
|
||||||
com.vk.api.sdk.objects.messages.Message message = gson.fromJson(object.getAsJsonObject("object"), com.vk.api.sdk.objects.messages.Message.class);
|
sortAndSend();
|
||||||
sendProcessing(message);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendProcessing(com.vk.api.sdk.objects.messages.Message userMessage) {
|
public void sortAndSend() {
|
||||||
Person user;
|
Person user;
|
||||||
Integer userVkId = userMessage.getUserId();
|
Integer userVkId = userMessage.getUserId();
|
||||||
log.info(VkApi.getUserVk(userVkId));
|
|
||||||
if (personLogicService.checkPersonBySocialNetworksId(SourceMessage.VK.name(), userVkId)) {
|
if (personLogicService.checkPersonBySocialNetworksId(SourceMessage.VK.name(), userVkId)) {
|
||||||
user = personLogicService.getUserBySocialId(SourceMessage.VK.name(), userMessage.getUserId());
|
user = personLogicService.getUserBySocialId(SourceMessage.VK.name(), userMessage.getUserId());
|
||||||
} else {
|
} else {
|
||||||
user = new Person();
|
user = new Person();
|
||||||
UserXtrCounters userXtrCounters = VkApi.getUserVk(userVkId);
|
UserXtrCounters userXtrCounters = VkApi.getUserVk(userVkId);
|
||||||
user.setCity("ыыыы");
|
user.setCity("city");
|
||||||
user.setName(userXtrCounters.getFirstName());
|
user.setName(userXtrCounters.getFirstName());
|
||||||
user.setLastName(userXtrCounters.getLastName());
|
user.setLastName(userXtrCounters.getLastName());
|
||||||
user.getSocialNetworks().put(String.valueOf(SourceMessage.VK), userMessage.getUserId());
|
user.getSocialNetworks().put(String.valueOf(SourceMessage.VK), userMessage.getUserId());
|
||||||
personLogicService.addUser(user);
|
personLogicService.addUser(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
Message message = new Message();
|
Mail message = new Mail();
|
||||||
message.setUser(user);
|
message.setPerson(user);
|
||||||
message.setText(userMessage.getBody());
|
message.setText(userMessage.getBody());
|
||||||
message.setDate(Long.valueOf(userMessage.getDate()));
|
message.setDate(Long.valueOf(userMessage.getDate()));
|
||||||
message.setSourceMessage(SourceMessage.VK.name());
|
message.setSourceMessage(SourceMessage.VK.name());
|
@ -1,4 +1,4 @@
|
|||||||
package org.sadtech.vkbot.listener;
|
package org.sadtech.vkbot.core.listener;
|
||||||
|
|
||||||
public interface EventListenable {
|
public interface EventListenable {
|
||||||
void listen() throws Exception;
|
void listen() throws Exception;
|
@ -1,7 +1,6 @@
|
|||||||
package org.sadtech.vkbot.listener;
|
package org.sadtech.vkbot.core.listener;
|
||||||
|
|
||||||
public interface Observable {
|
public interface Observable {
|
||||||
void registerObserver(Observer o);
|
|
||||||
|
|
||||||
// void removeObserver(Observer o);
|
// void removeObserver(Observer o);
|
||||||
void notifyObservers();
|
void notifyObservers();
|
@ -1,4 +1,4 @@
|
|||||||
package org.sadtech.vkbot.listener;
|
package org.sadtech.vkbot.core.listener;
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
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.actions.LongPoll;
|
||||||
import com.vk.api.sdk.callback.longpoll.queries.GetLongPollEventsQuery;
|
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.exceptions.ClientException;
|
||||||
import com.vk.api.sdk.objects.groups.responses.GetLongPollServerResponse;
|
import com.vk.api.sdk.objects.groups.responses.GetLongPollServerResponse;
|
||||||
import lombok.extern.log4j.Log4j;
|
import lombok.extern.log4j.Log4j;
|
||||||
import org.sadtech.vkbot.listener.EventListenable;
|
import org.sadtech.vkbot.core.listener.EventListenable;
|
||||||
import org.sadtech.vkbot.listener.data.ResponsibleData;
|
import org.sadtech.vkbot.core.data.ResponsibleData;
|
||||||
import org.springframework.scheduling.annotation.Async;
|
import org.springframework.scheduling.annotation.Async;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
@ -51,7 +51,7 @@ public class EventListenerVk implements EventListenable {
|
|||||||
if (eventsResponse.getUpdates().toArray().length != 0) {
|
if (eventsResponse.getUpdates().toArray().length != 0) {
|
||||||
responseData.add(eventsResponse.getUpdates().get(0));
|
responseData.add(eventsResponse.getUpdates().get(0));
|
||||||
log.info(eventsResponse.getUpdates());
|
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);
|
longPollEventsQuery = longPoll.getEvents(server.getServer(), server.getKey(), eventsResponse.getTs()).waitTime(20);
|
||||||
} while (true);
|
} 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