From 1cf0b4dce6bae67e401b4a1d794da26f7b5ed0b0 Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Fri, 11 Jan 2019 03:21:58 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=BE=D0=B2=D0=B0=D1=8F=20=D0=B0=D1=80?= =?UTF-8?q?=D1=85=D0=B8=D1=82=D0=B5=D0=BA=D1=82=D1=83=D1=80=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 23 +++----- .../sadtech/autoresponder/Autoresponder.java | 17 ++++++ .../sadtech/autoresponder/MessageSender.java | 7 --- .../autoresponder/database/entity/Mail.java | 23 -------- .../database/entity/NextUnit.java | 16 ------ .../autoresponder/database/entity/Person.java | 36 ------------- .../database/entity/SaveUnit.java | 19 ------- .../autoresponder/database/entity/Unit.java | 17 ------ .../database/repository/MailRepository.java | 15 ------ .../repository/NextUnitRepository.java | 9 ---- .../database/repository/PersonRepository.java | 13 ----- .../repository/SaveUnitRepositoriy.java | 7 --- .../database/repository/UnitRepositoriy.java | 7 --- .../database/service/MailService.java | 12 ----- .../database/service/NextUnitService.java | 4 -- .../database/service/PersonService.java | 18 ------- .../database/service/SaveUnitService.java | 4 -- .../database/service/UnitService.java | 11 ---- .../service/impl/MailServiceImpl.java | 25 --------- .../service/impl/NextUnitServiceImpl.java | 14 ----- .../service/impl/PersonServiceImpl.java | 41 -------------- .../service/impl/SaveUnitServiceImpl.java | 14 ----- .../service/impl/UnitServiceImpl.java | 22 -------- .../sadtech/autoresponder/entity/Unit.java | 17 ++++++ .../processing/MessageHandler.java | 54 ------------------- .../processing/MessageLogicService.java | 25 --------- .../processing/PersonLogicService.java | 52 ------------------ .../repository/UnitRepository.java | 16 ++++++ .../repository/impl/UnitRepositoryImpl.java | 33 ++++++++++++ .../autoresponder/service/UnitService.java | 10 ++++ .../service/impl/UnitServiceImpl.java | 42 +++++++++++++++ .../submodule/parser/Parser.java | 26 +++++++++ 32 files changed, 168 insertions(+), 481 deletions(-) create mode 100644 src/main/java/org/sadtech/autoresponder/Autoresponder.java delete mode 100644 src/main/java/org/sadtech/autoresponder/MessageSender.java delete mode 100644 src/main/java/org/sadtech/autoresponder/database/entity/Mail.java delete mode 100644 src/main/java/org/sadtech/autoresponder/database/entity/NextUnit.java delete mode 100644 src/main/java/org/sadtech/autoresponder/database/entity/Person.java delete mode 100644 src/main/java/org/sadtech/autoresponder/database/entity/SaveUnit.java delete mode 100644 src/main/java/org/sadtech/autoresponder/database/entity/Unit.java delete mode 100644 src/main/java/org/sadtech/autoresponder/database/repository/MailRepository.java delete mode 100644 src/main/java/org/sadtech/autoresponder/database/repository/NextUnitRepository.java delete mode 100644 src/main/java/org/sadtech/autoresponder/database/repository/PersonRepository.java delete mode 100644 src/main/java/org/sadtech/autoresponder/database/repository/SaveUnitRepositoriy.java delete mode 100644 src/main/java/org/sadtech/autoresponder/database/repository/UnitRepositoriy.java delete mode 100644 src/main/java/org/sadtech/autoresponder/database/service/MailService.java delete mode 100644 src/main/java/org/sadtech/autoresponder/database/service/NextUnitService.java delete mode 100644 src/main/java/org/sadtech/autoresponder/database/service/PersonService.java delete mode 100644 src/main/java/org/sadtech/autoresponder/database/service/SaveUnitService.java delete mode 100644 src/main/java/org/sadtech/autoresponder/database/service/UnitService.java delete mode 100644 src/main/java/org/sadtech/autoresponder/database/service/impl/MailServiceImpl.java delete mode 100644 src/main/java/org/sadtech/autoresponder/database/service/impl/NextUnitServiceImpl.java delete mode 100644 src/main/java/org/sadtech/autoresponder/database/service/impl/PersonServiceImpl.java delete mode 100644 src/main/java/org/sadtech/autoresponder/database/service/impl/SaveUnitServiceImpl.java delete mode 100644 src/main/java/org/sadtech/autoresponder/database/service/impl/UnitServiceImpl.java create mode 100644 src/main/java/org/sadtech/autoresponder/entity/Unit.java delete mode 100644 src/main/java/org/sadtech/autoresponder/processing/MessageHandler.java delete mode 100644 src/main/java/org/sadtech/autoresponder/processing/MessageLogicService.java delete mode 100644 src/main/java/org/sadtech/autoresponder/processing/PersonLogicService.java create mode 100644 src/main/java/org/sadtech/autoresponder/repository/UnitRepository.java create mode 100644 src/main/java/org/sadtech/autoresponder/repository/impl/UnitRepositoryImpl.java create mode 100644 src/main/java/org/sadtech/autoresponder/service/UnitService.java create mode 100644 src/main/java/org/sadtech/autoresponder/service/impl/UnitServiceImpl.java create mode 100644 src/main/java/org/sadtech/autoresponder/submodule/parser/Parser.java diff --git a/pom.xml b/pom.xml index bd99519..dd014f0 100644 --- a/pom.xml +++ b/pom.xml @@ -21,19 +21,12 @@ - 1.0.2 1.18.4 1.2.17 - - 2.1.3.RELEASE + 4.12 - - javax.persistence - persistence-api - ${persistence.ver} - org.projectlombok @@ -47,16 +40,14 @@ ${log4j} + - org.springframework.data - spring-data-jpa - ${spring.data} - - - javax.persistence - javax.persistence-api - 2.2 + junit + junit + ${junit.ver} + test + \ No newline at end of file diff --git a/src/main/java/org/sadtech/autoresponder/Autoresponder.java b/src/main/java/org/sadtech/autoresponder/Autoresponder.java new file mode 100644 index 0000000..254c6e8 --- /dev/null +++ b/src/main/java/org/sadtech/autoresponder/Autoresponder.java @@ -0,0 +1,17 @@ +package org.sadtech.autoresponder; + +import lombok.AllArgsConstructor; +import org.sadtech.autoresponder.entity.Unit; +import org.sadtech.autoresponder.service.UnitService; + +@AllArgsConstructor +public class Autoresponder { + + private UnitService unitService; + + public Unit nextUnit(Integer idUnit, String message) { + Unit unit = unitService.getUnitById(idUnit); + return unitService.nextUnit(unit, message); + } + +} diff --git a/src/main/java/org/sadtech/autoresponder/MessageSender.java b/src/main/java/org/sadtech/autoresponder/MessageSender.java deleted file mode 100644 index ad72975..0000000 --- a/src/main/java/org/sadtech/autoresponder/MessageSender.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.sadtech.autoresponder; - -public interface MessageSender { - - void send(Integer idNetSoc, String text); - -} diff --git a/src/main/java/org/sadtech/autoresponder/database/entity/Mail.java b/src/main/java/org/sadtech/autoresponder/database/entity/Mail.java deleted file mode 100644 index 266d64b..0000000 --- a/src/main/java/org/sadtech/autoresponder/database/entity/Mail.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.sadtech.autoresponder.database.entity; - -import lombok.Data; - -import javax.persistence.*; - -@Data -@Entity -public class Mail { - - @Id - @GeneratedValue - private Long idMess; - private String text; - private Long date; - private String sourceMessage; - - @ManyToOne - @JoinColumn(name = "idPerson", nullable = false) - private Person person; - - -} diff --git a/src/main/java/org/sadtech/autoresponder/database/entity/NextUnit.java b/src/main/java/org/sadtech/autoresponder/database/entity/NextUnit.java deleted file mode 100644 index 82b8ff4..0000000 --- a/src/main/java/org/sadtech/autoresponder/database/entity/NextUnit.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.sadtech.autoresponder.database.entity; - -import lombok.Data; - -import javax.persistence.Entity; -import javax.persistence.Id; - -@Entity -@Data -public class NextUnit { - - @Id - private Long id; - private Long idNext; - -} diff --git a/src/main/java/org/sadtech/autoresponder/database/entity/Person.java b/src/main/java/org/sadtech/autoresponder/database/entity/Person.java deleted file mode 100644 index bfe26a6..0000000 --- a/src/main/java/org/sadtech/autoresponder/database/entity/Person.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.sadtech.autoresponder.database.entity; - -import lombok.Data; - -import javax.persistence.*; -import java.util.HashMap; -import java.util.Map; - -@Entity -@Data -public class Person { - - @Id - @GeneratedValue - private Long id; - - @Column(length = 20) - private String name; - - @Column(length = 20) - private String lastName; - - @Column(length = 20) - private String city; - - private String token; - private String email; - - @ElementCollection - @CollectionTable(name = "PersonSocialNetworks") - @MapKeyColumn(name = "KeysSocialNetworks", length = 20) - private Map socialNetworks = new HashMap<>(); - - - -} diff --git a/src/main/java/org/sadtech/autoresponder/database/entity/SaveUnit.java b/src/main/java/org/sadtech/autoresponder/database/entity/SaveUnit.java deleted file mode 100644 index 8aebffd..0000000 --- a/src/main/java/org/sadtech/autoresponder/database/entity/SaveUnit.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.sadtech.autoresponder.database.entity; - -import lombok.Data; - -import javax.persistence.*; - -@Entity -@Data -public class SaveUnit { - - @Id - private Long id; - private Long idStage; - - @OneToOne - @JoinColumn(name = "idPerson", nullable = false) - private Person user; - -} diff --git a/src/main/java/org/sadtech/autoresponder/database/entity/Unit.java b/src/main/java/org/sadtech/autoresponder/database/entity/Unit.java deleted file mode 100644 index e26b54e..0000000 --- a/src/main/java/org/sadtech/autoresponder/database/entity/Unit.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.sadtech.autoresponder.database.entity; - -import lombok.Data; - -import javax.persistence.Entity; -import javax.persistence.Id; - -@Entity -@Data -public class Unit { - - @Id - private Long id; - private String text; - private String wordKeys; - -} diff --git a/src/main/java/org/sadtech/autoresponder/database/repository/MailRepository.java b/src/main/java/org/sadtech/autoresponder/database/repository/MailRepository.java deleted file mode 100644 index ebb2354..0000000 --- a/src/main/java/org/sadtech/autoresponder/database/repository/MailRepository.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.sadtech.autoresponder.database.repository; - -import org.sadtech.autoresponder.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 MailRepository extends JpaRepository { - - @Query("SELECT u FROM Mail u WHERE u.date > :date") - Collection getMessagesByRange(@Param("date") Long date); - -} diff --git a/src/main/java/org/sadtech/autoresponder/database/repository/NextUnitRepository.java b/src/main/java/org/sadtech/autoresponder/database/repository/NextUnitRepository.java deleted file mode 100644 index 4241f6e..0000000 --- a/src/main/java/org/sadtech/autoresponder/database/repository/NextUnitRepository.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.sadtech.autoresponder.database.repository; - -import org.sadtech.autoresponder.database.entity.NextUnit; -import org.springframework.data.jpa.repository.JpaRepository; - -public interface NextUnitRepository extends JpaRepository { - - -} diff --git a/src/main/java/org/sadtech/autoresponder/database/repository/PersonRepository.java b/src/main/java/org/sadtech/autoresponder/database/repository/PersonRepository.java deleted file mode 100644 index c810301..0000000 --- a/src/main/java/org/sadtech/autoresponder/database/repository/PersonRepository.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.sadtech.autoresponder.database.repository; - -import org.sadtech.autoresponder.database.entity.Person; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; - -public interface PersonRepository extends JpaRepository { - - @Query("SELECT u FROM Person u INNER JOIN u.socialNetworks p WHERE KEY(p) = :type2 AND VALUE(p) = :socialId") - Person getUserBySocialNetworksId(@Param("type2") String type, @Param("socialId") Integer socialNetworksId); - -} diff --git a/src/main/java/org/sadtech/autoresponder/database/repository/SaveUnitRepositoriy.java b/src/main/java/org/sadtech/autoresponder/database/repository/SaveUnitRepositoriy.java deleted file mode 100644 index 29b9f61..0000000 --- a/src/main/java/org/sadtech/autoresponder/database/repository/SaveUnitRepositoriy.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.sadtech.autoresponder.database.repository; - -import org.sadtech.autoresponder.database.entity.SaveUnit; -import org.springframework.data.jpa.repository.JpaRepository; - -public interface SaveUnitRepositoriy extends JpaRepository { -} diff --git a/src/main/java/org/sadtech/autoresponder/database/repository/UnitRepositoriy.java b/src/main/java/org/sadtech/autoresponder/database/repository/UnitRepositoriy.java deleted file mode 100644 index 183a913..0000000 --- a/src/main/java/org/sadtech/autoresponder/database/repository/UnitRepositoriy.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.sadtech.autoresponder.database.repository; - -import org.sadtech.autoresponder.database.entity.Unit; -import org.springframework.data.jpa.repository.JpaRepository; - -public interface UnitRepositoriy extends JpaRepository { -} diff --git a/src/main/java/org/sadtech/autoresponder/database/service/MailService.java b/src/main/java/org/sadtech/autoresponder/database/service/MailService.java deleted file mode 100644 index c5481e1..0000000 --- a/src/main/java/org/sadtech/autoresponder/database/service/MailService.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.sadtech.autoresponder.database.service; - -import org.sadtech.autoresponder.database.entity.Mail; - -import java.util.List; - -public interface MailService { - - void addMessage(Mail message); - - List getMessageRange(Long date); -} diff --git a/src/main/java/org/sadtech/autoresponder/database/service/NextUnitService.java b/src/main/java/org/sadtech/autoresponder/database/service/NextUnitService.java deleted file mode 100644 index 48ed22f..0000000 --- a/src/main/java/org/sadtech/autoresponder/database/service/NextUnitService.java +++ /dev/null @@ -1,4 +0,0 @@ -package org.sadtech.autoresponder.database.service; - -public interface NextUnitService { -} diff --git a/src/main/java/org/sadtech/autoresponder/database/service/PersonService.java b/src/main/java/org/sadtech/autoresponder/database/service/PersonService.java deleted file mode 100644 index d044d62..0000000 --- a/src/main/java/org/sadtech/autoresponder/database/service/PersonService.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.sadtech.autoresponder.database.service; - -import org.sadtech.autoresponder.database.entity.Person; - -import java.util.Map; - -public interface PersonService { - - void addUser(Person user); - - void removeUser(Long id); - - Person getUserByID(Long id); - - Map getSocialNetwork(Long id); - - Person getUserBySocialNetworksId(String type, Integer socialNetworksId); -} diff --git a/src/main/java/org/sadtech/autoresponder/database/service/SaveUnitService.java b/src/main/java/org/sadtech/autoresponder/database/service/SaveUnitService.java deleted file mode 100644 index 23b0273..0000000 --- a/src/main/java/org/sadtech/autoresponder/database/service/SaveUnitService.java +++ /dev/null @@ -1,4 +0,0 @@ -package org.sadtech.autoresponder.database.service; - -public interface SaveUnitService { -} diff --git a/src/main/java/org/sadtech/autoresponder/database/service/UnitService.java b/src/main/java/org/sadtech/autoresponder/database/service/UnitService.java deleted file mode 100644 index 7fb8e88..0000000 --- a/src/main/java/org/sadtech/autoresponder/database/service/UnitService.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.sadtech.autoresponder.database.service; - -import org.sadtech.autoresponder.database.entity.Unit; - -public interface UnitService { - - void addUnit(Unit unit); - - void removeUnit(Long id); - -} diff --git a/src/main/java/org/sadtech/autoresponder/database/service/impl/MailServiceImpl.java b/src/main/java/org/sadtech/autoresponder/database/service/impl/MailServiceImpl.java deleted file mode 100644 index 3bfada3..0000000 --- a/src/main/java/org/sadtech/autoresponder/database/service/impl/MailServiceImpl.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.sadtech.autoresponder.database.service.impl; - -import org.sadtech.autoresponder.database.entity.Mail; -import org.sadtech.autoresponder.database.repository.MailRepository; -import org.sadtech.autoresponder.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 getMessageRange(Long date) { - return (List) repository.getMessagesByRange(date); - } -} diff --git a/src/main/java/org/sadtech/autoresponder/database/service/impl/NextUnitServiceImpl.java b/src/main/java/org/sadtech/autoresponder/database/service/impl/NextUnitServiceImpl.java deleted file mode 100644 index 6f52c91..0000000 --- a/src/main/java/org/sadtech/autoresponder/database/service/impl/NextUnitServiceImpl.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.sadtech.autoresponder.database.service.impl; - -import org.sadtech.autoresponder.database.repository.NextUnitRepository; -import org.sadtech.autoresponder.database.service.NextUnitService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -@Service -public class NextUnitServiceImpl implements NextUnitService { - - @Autowired - private NextUnitRepository repository; - -} diff --git a/src/main/java/org/sadtech/autoresponder/database/service/impl/PersonServiceImpl.java b/src/main/java/org/sadtech/autoresponder/database/service/impl/PersonServiceImpl.java deleted file mode 100644 index 7be8a66..0000000 --- a/src/main/java/org/sadtech/autoresponder/database/service/impl/PersonServiceImpl.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.sadtech.autoresponder.database.service.impl; - -import org.sadtech.autoresponder.database.repository.PersonRepository; -import org.sadtech.autoresponder.database.entity.Person; -import org.sadtech.autoresponder.database.service.PersonService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import java.util.Map; - -@Service -public class PersonServiceImpl implements PersonService { - - @Autowired - private PersonRepository repositoriy; - - @Override - public void addUser(Person user) { - repositoriy.saveAndFlush(user); - } - - @Override - public void removeUser(Long id) { - repositoriy.deleteById(id); - } - - @Override - public Person getUserByID(Long id) { - return repositoriy.getOne(id); - } - - @Override - public Map getSocialNetwork(Long id) { - return repositoriy.getOne(id).getSocialNetworks(); - } - - @Override - public Person getUserBySocialNetworksId(String type, Integer socialNetworksId) { - return repositoriy.getUserBySocialNetworksId(type, socialNetworksId); - } -} diff --git a/src/main/java/org/sadtech/autoresponder/database/service/impl/SaveUnitServiceImpl.java b/src/main/java/org/sadtech/autoresponder/database/service/impl/SaveUnitServiceImpl.java deleted file mode 100644 index 603a89c..0000000 --- a/src/main/java/org/sadtech/autoresponder/database/service/impl/SaveUnitServiceImpl.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.sadtech.autoresponder.database.service.impl; - -import org.sadtech.autoresponder.database.repository.SaveUnitRepositoriy; -import org.sadtech.autoresponder.database.service.SaveUnitService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -@Service -public class SaveUnitServiceImpl implements SaveUnitService { - - @Autowired - private SaveUnitRepositoriy repositoriy; - -} diff --git a/src/main/java/org/sadtech/autoresponder/database/service/impl/UnitServiceImpl.java b/src/main/java/org/sadtech/autoresponder/database/service/impl/UnitServiceImpl.java deleted file mode 100644 index 2cdddf2..0000000 --- a/src/main/java/org/sadtech/autoresponder/database/service/impl/UnitServiceImpl.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.sadtech.autoresponder.database.service.impl; - -import org.sadtech.autoresponder.database.repository.UnitRepositoriy; -import org.sadtech.autoresponder.database.entity.Unit; -import org.sadtech.autoresponder.database.service.UnitService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -@Service -public class UnitServiceImpl implements UnitService { - - @Autowired - private UnitRepositoriy repositoriy; - - public void addUnit(Unit unit) { - repositoriy.saveAndFlush(unit); - } - - public void removeUnit(Long id) { - - } -} diff --git a/src/main/java/org/sadtech/autoresponder/entity/Unit.java b/src/main/java/org/sadtech/autoresponder/entity/Unit.java new file mode 100644 index 0000000..bf3a536 --- /dev/null +++ b/src/main/java/org/sadtech/autoresponder/entity/Unit.java @@ -0,0 +1,17 @@ +package org.sadtech.autoresponder.entity; + +import lombok.Data; + +import java.util.List; +import java.util.Set; + +@Data +public class Unit { + + private Integer idUnit; + private List nextUnits; + private String answer; + private Integer priority; + private Set keyWords; + +} diff --git a/src/main/java/org/sadtech/autoresponder/processing/MessageHandler.java b/src/main/java/org/sadtech/autoresponder/processing/MessageHandler.java deleted file mode 100644 index ae1fab8..0000000 --- a/src/main/java/org/sadtech/autoresponder/processing/MessageHandler.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.sadtech.autoresponder.processing; - -import lombok.extern.log4j.Log4j; -import org.sadtech.autoresponder.database.entity.Mail; -import org.sadtech.autoresponder.MessageSender; -import org.sadtech.autoresponder.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 -public class MessageHandler { - - private MessageLogicService messageLogicService; - private PersonLogicService userLogicService; - private Map senderHashMap = new HashMap<>(); - private long data; - - public MessageHandler(MessageLogicService messageLogicService, PersonLogicService userLogicService) { - this.messageLogicService = messageLogicService; - this.userLogicService = userLogicService; - 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 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(); - } - } - } - } - -} diff --git a/src/main/java/org/sadtech/autoresponder/processing/MessageLogicService.java b/src/main/java/org/sadtech/autoresponder/processing/MessageLogicService.java deleted file mode 100644 index 6301456..0000000 --- a/src/main/java/org/sadtech/autoresponder/processing/MessageLogicService.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.sadtech.autoresponder.processing; - -import org.sadtech.autoresponder.database.entity.Mail; -import org.sadtech.autoresponder.database.service.MailService; -import org.springframework.stereotype.Component; - -import java.util.List; - -@Component -public class MessageLogicService { - - private MailService messageService; - - public MessageLogicService(MailService messageService) { - this.messageService = messageService; - } - - public void addMessage(Mail message) { - messageService.addMessage(message); - } - - public List getMessageRange(long data) { - return messageService.getMessageRange(data); - } -} diff --git a/src/main/java/org/sadtech/autoresponder/processing/PersonLogicService.java b/src/main/java/org/sadtech/autoresponder/processing/PersonLogicService.java deleted file mode 100644 index 211dda8..0000000 --- a/src/main/java/org/sadtech/autoresponder/processing/PersonLogicService.java +++ /dev/null @@ -1,52 +0,0 @@ -package org.sadtech.autoresponder.processing; - -import lombok.extern.log4j.Log4j; -import org.sadtech.autoresponder.database.entity.Person; -import org.sadtech.autoresponder.database.service.PersonService; -import org.springframework.stereotype.Component; - -@Log4j -@Component -public class PersonLogicService { - - private PersonService personService; - - public PersonLogicService(PersonService userService) { - this.personService = userService; - } - - public void addUser(Person user) { - personService.addUser(user); - log.info("Пользователь добавлен в бд"); - } - - public boolean checkPersonBySocialNetworksId(String socType, Integer socId) { - Person checkPerson = personService.getUserBySocialNetworksId(socType, socId); - if (checkPerson != null) { - log.info("Пользователь уже есть в бд"); - return true; - } - log.info("Пользователя нет в бд"); - return false; - } - - public Person getPersonBySocialNetworksId(Person person) { - for (String key : person.getSocialNetworks().keySet()) { - Person getPerson = personService.getUserBySocialNetworksId(key, person.getSocialNetworks().get(key)); - if (getPerson != null) { - log.info("Пользователь уже есть в бд"); - return getPerson; - } - } - return null; - } - - public Person getUserById(Long id) { - return personService.getUserByID(id); - } - - public Person getUserBySocialId(String type, Integer id) { - return personService.getUserBySocialNetworksId(type, id); - } - -} diff --git a/src/main/java/org/sadtech/autoresponder/repository/UnitRepository.java b/src/main/java/org/sadtech/autoresponder/repository/UnitRepository.java new file mode 100644 index 0000000..1d918ac --- /dev/null +++ b/src/main/java/org/sadtech/autoresponder/repository/UnitRepository.java @@ -0,0 +1,16 @@ +package org.sadtech.autoresponder.repository; + +import org.sadtech.autoresponder.entity.Unit; + +import java.util.Collection; + +public interface UnitRepository { + + Unit getUnitById(Integer idUnit); + + void addUnit(Unit unit); + + void addUnits(Collection units); + + void removeUnit(Integer idUnit); +} diff --git a/src/main/java/org/sadtech/autoresponder/repository/impl/UnitRepositoryImpl.java b/src/main/java/org/sadtech/autoresponder/repository/impl/UnitRepositoryImpl.java new file mode 100644 index 0000000..f837ed4 --- /dev/null +++ b/src/main/java/org/sadtech/autoresponder/repository/impl/UnitRepositoryImpl.java @@ -0,0 +1,33 @@ +package org.sadtech.autoresponder.repository.impl; + +import org.sadtech.autoresponder.entity.Unit; +import org.sadtech.autoresponder.repository.UnitRepository; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +public class UnitRepositoryImpl implements UnitRepository { + + private Map units = new HashMap<>(); + + @Override + public Unit getUnitById(Integer idUnit) { + return units.get(idUnit); + } + + @Override + public void addUnit(Unit unit) { + units.put(unit.getIdUnit(), unit); + } + + @Override + public void addUnits(Collection units) { + units.addAll(units); + } + + @Override + public void removeUnit(Integer idUnit) { + units.remove(idUnit); + } +} diff --git a/src/main/java/org/sadtech/autoresponder/service/UnitService.java b/src/main/java/org/sadtech/autoresponder/service/UnitService.java new file mode 100644 index 0000000..3cf507c --- /dev/null +++ b/src/main/java/org/sadtech/autoresponder/service/UnitService.java @@ -0,0 +1,10 @@ +package org.sadtech.autoresponder.service; + +import lombok.NonNull; +import org.sadtech.autoresponder.entity.Unit; + +public interface UnitService { + Unit nextUnit(Unit unit, String message); + + Unit getUnitById(Integer idUnit); +} diff --git a/src/main/java/org/sadtech/autoresponder/service/impl/UnitServiceImpl.java b/src/main/java/org/sadtech/autoresponder/service/impl/UnitServiceImpl.java new file mode 100644 index 0000000..6563755 --- /dev/null +++ b/src/main/java/org/sadtech/autoresponder/service/impl/UnitServiceImpl.java @@ -0,0 +1,42 @@ +package org.sadtech.autoresponder.service.impl; + +import com.sun.istack.internal.NotNull; +import lombok.AllArgsConstructor; +import lombok.NonNull; +import lombok.Setter; +import org.sadtech.autoresponder.entity.Unit; +import org.sadtech.autoresponder.repository.UnitRepository; +import org.sadtech.autoresponder.submodule.parser.Parser; +import org.sadtech.autoresponder.service.UnitService; + +import java.util.ArrayList; + +@AllArgsConstructor +public class UnitServiceImpl implements UnitService { + + private UnitRepository unitRepository; + + public Unit nextUnit(@NotNull Unit unit, @NotNull String message) { + ArrayList nextUnits = (ArrayList) unit.getNextUnits(); + Unit unitReturn = new Unit(); + if (nextUnits.size() > 0) { + Parser parser = new Parser(); + parser.setText(message); + parser.parse(); + for (Unit nextUnit : nextUnits) { + if (nextUnit.getKeyWords().retainAll(parser.getWords()) && (nextUnit.getPriority()>unitReturn.getPriority())) { + unitReturn = nextUnit; + } + } + return unitReturn; + } else { + return null; + } + } + + @Override + public Unit getUnitById(@NotNull Integer idUnit) { + return unitRepository.getUnitById(idUnit); + } +} + diff --git a/src/main/java/org/sadtech/autoresponder/submodule/parser/Parser.java b/src/main/java/org/sadtech/autoresponder/submodule/parser/Parser.java new file mode 100644 index 0000000..3e64e4b --- /dev/null +++ b/src/main/java/org/sadtech/autoresponder/submodule/parser/Parser.java @@ -0,0 +1,26 @@ +package org.sadtech.autoresponder.submodule.parser; + +import lombok.Getter; +import lombok.Setter; + +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class Parser { + + @Getter + private Set words; + + @Setter + private String text; + + public void parse() { + Pattern p = Pattern.compile("[а-яА-Я0-9]+"); + Matcher m = p.matcher(text); + while (m.find()) { + words.add(m.group()); + } + } + +}