* Добавлен ENUM для определения источника события
* Добавлен кастомный SQL метод возвращающий сообщения из БД новее запрошеной даты * Добавлен глобальный обработчик сообщений * Исрпавлены конфигурации spring, которые приводили к ошибкам в создании бинов * Добавлен статический класс с методами вк апи
This commit is contained in:
parent
1a19f1f88d
commit
d6b902f2b9
17
pom.xml
17
pom.xml
@ -10,6 +10,18 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<artifactId>consultant-core</artifactId>
|
<artifactId>consultant-core</artifactId>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<source>8</source>
|
||||||
|
<target>8</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<persistence.ver>1.0.2</persistence.ver>
|
<persistence.ver>1.0.2</persistence.ver>
|
||||||
@ -43,6 +55,11 @@
|
|||||||
<artifactId>spring-data-jpa</artifactId>
|
<artifactId>spring-data-jpa</artifactId>
|
||||||
<version>${spring.data}</version>
|
<version>${spring.data}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.persistence</groupId>
|
||||||
|
<artifactId>javax.persistence-api</artifactId>
|
||||||
|
<version>2.2</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
@ -2,20 +2,20 @@ package org.sadtech.consultant.database.entity;
|
|||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.*;
|
||||||
import javax.persistence.GeneratedValue;
|
|
||||||
import javax.persistence.Id;
|
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@Entity
|
@Entity
|
||||||
public class Message {
|
public class Messages {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
private Long idMess;
|
private Long idMess;
|
||||||
private Long idUser;
|
private Long idUser;
|
||||||
private String text;
|
private String text;
|
||||||
private String date;
|
private Long date;
|
||||||
|
@Enumerated(EnumType.STRING)
|
||||||
|
private SourceMessage source;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -1,17 +0,0 @@
|
|||||||
package org.sadtech.consultant.database.entity;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
|
||||||
import javax.persistence.Id;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@Entity
|
|
||||||
public class SocialNetworks {
|
|
||||||
|
|
||||||
@Id
|
|
||||||
private Long id;
|
|
||||||
private Long idVk;
|
|
||||||
private Long idFacebook;
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,5 @@
|
|||||||
|
package org.sadtech.consultant.database.entity;
|
||||||
|
|
||||||
|
public enum SourceMessage {
|
||||||
|
VK, FACEBOOK;
|
||||||
|
}
|
@ -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;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@ -16,7 +15,10 @@ public class User {
|
|||||||
private String token;
|
private String token;
|
||||||
private String lastName;
|
private String lastName;
|
||||||
private String city;
|
private String city;
|
||||||
// private List<SocialNetworks> socialNetworks;
|
|
||||||
|
@ElementCollection
|
||||||
|
@CollectionTable(name="SocialNetworks", joinColumns=@JoinColumn(name="id"))
|
||||||
|
private List<String> socialNetworks;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,16 @@
|
|||||||
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.Messages;
|
||||||
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.repository.query.Param;
|
||||||
|
|
||||||
public interface MessageRepository extends JpaRepository<Message, Long> {
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface MessageRepository extends JpaRepository<Messages, Long> {
|
||||||
|
|
||||||
|
@Query("SELECT u FROM Messages u WHERE u.date > :date")
|
||||||
|
Collection<Messages> getMessagesByRange(@Param("date") Long date);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,7 @@ package org.sadtech.consultant.database.repository;
|
|||||||
import org.sadtech.consultant.database.entity.NextUnit;
|
import org.sadtech.consultant.database.entity.NextUnit;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
public interface NextUnitRepositoriy extends JpaRepository<NextUnit, Long> {
|
public interface NextUnitRepository extends JpaRepository<NextUnit, Long> {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -1,7 +0,0 @@
|
|||||||
package org.sadtech.consultant.database.repository;
|
|
||||||
|
|
||||||
import org.sadtech.consultant.database.entity.SocialNetworks;
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
|
||||||
|
|
||||||
public interface SocialNetworksRepositoriy extends JpaRepository<SocialNetworks, Long> {
|
|
||||||
}
|
|
@ -1,8 +1,12 @@
|
|||||||
package org.sadtech.consultant.database.service;
|
package org.sadtech.consultant.database.service;
|
||||||
|
|
||||||
import org.sadtech.consultant.database.entity.Message;
|
import org.sadtech.consultant.database.entity.Messages;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public interface MessageService {
|
public interface MessageService {
|
||||||
|
|
||||||
void addMessage(Message message);
|
void addMessage(Messages message);
|
||||||
|
|
||||||
|
List<Messages> getMessageRange(Long date);
|
||||||
}
|
}
|
||||||
|
@ -1,4 +0,0 @@
|
|||||||
package org.sadtech.consultant.database.service;
|
|
||||||
|
|
||||||
public interface SocialNetworksService {
|
|
||||||
}
|
|
@ -1,18 +1,25 @@
|
|||||||
package org.sadtech.consultant.database.service.impl;
|
package org.sadtech.consultant.database.service.impl;
|
||||||
|
|
||||||
import org.sadtech.consultant.database.entity.Message;
|
import org.sadtech.consultant.database.entity.Messages;
|
||||||
import org.sadtech.consultant.database.repository.MessageRepository;
|
import org.sadtech.consultant.database.repository.MessageRepository;
|
||||||
import org.sadtech.consultant.database.service.MessageService;
|
import org.sadtech.consultant.database.service.MessageService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class MessageServiceImpl implements MessageService {
|
public class MessageServiceImpl implements MessageService {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private MessageRepository repository;
|
private MessageRepository repository;
|
||||||
|
|
||||||
public void addMessage(Message message) {
|
public void addMessage(Messages message) {
|
||||||
repository.saveAndFlush(message);
|
repository.saveAndFlush(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Messages> getMessageRange(Long date) {
|
||||||
|
return (List<Messages>) repository.getMessagesByRange(date);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package org.sadtech.consultant.database.service.impl;
|
package org.sadtech.consultant.database.service.impl;
|
||||||
|
|
||||||
import org.sadtech.consultant.database.repository.NextUnitRepositoriy;
|
import org.sadtech.consultant.database.repository.NextUnitRepository;
|
||||||
import org.sadtech.consultant.database.service.NextUnitService;
|
import org.sadtech.consultant.database.service.NextUnitService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@ -9,6 +9,6 @@ import org.springframework.stereotype.Service;
|
|||||||
public class NextUnitServiceImpl implements NextUnitService {
|
public class NextUnitServiceImpl implements NextUnitService {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private NextUnitRepositoriy repositoriy;
|
private NextUnitRepository repository;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
package org.sadtech.consultant.database.service.impl;
|
|
||||||
|
|
||||||
import org.sadtech.consultant.database.repository.SocialNetworksRepositoriy;
|
|
||||||
import org.sadtech.consultant.database.service.SocialNetworksService;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class SocialNetworksServiceImpl implements SocialNetworksService {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private SocialNetworksRepositoriy repositoriy;
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,40 @@
|
|||||||
|
package org.sadtech.consultant.processing;
|
||||||
|
|
||||||
|
import lombok.extern.log4j.Log4j;
|
||||||
|
import org.sadtech.consultant.database.entity.Messages;
|
||||||
|
import org.sadtech.consultant.database.service.MessageService;
|
||||||
|
import org.springframework.scheduling.annotation.Async;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Log4j
|
||||||
|
@Component
|
||||||
|
public class MessageHandler {
|
||||||
|
|
||||||
|
private MessageService service;
|
||||||
|
private long data;
|
||||||
|
|
||||||
|
public MessageHandler(MessageService service) {
|
||||||
|
this.service = service;
|
||||||
|
data = new Date().getTime() / 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Async
|
||||||
|
public void processing() {
|
||||||
|
while (true) {
|
||||||
|
List<Messages> messages = service.getMessageRange(data);
|
||||||
|
for (Messages message : messages) {
|
||||||
|
System.out.println(message);
|
||||||
|
data = message.getDate();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Thread.sleep(10000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user