diff --git a/src/main/java/org/sadtech/consultant/database/entity/Message.java b/src/main/java/org/sadtech/consultant/database/entity/Message.java index b1d0ff3..69afff2 100644 --- a/src/main/java/org/sadtech/consultant/database/entity/Message.java +++ b/src/main/java/org/sadtech/consultant/database/entity/Message.java @@ -14,6 +14,7 @@ public class Message { private String text; private Long date; private String sourceMessage; + private String sex; @ManyToOne @JoinColumn(name = "idUser", nullable = false) diff --git a/src/main/java/org/sadtech/consultant/database/entity/Person.java b/src/main/java/org/sadtech/consultant/database/entity/Person.java index 5a3e580..7ab5275 100644 --- a/src/main/java/org/sadtech/consultant/database/entity/Person.java +++ b/src/main/java/org/sadtech/consultant/database/entity/Person.java @@ -3,8 +3,7 @@ package org.sadtech.consultant.database.entity; import lombok.Data; import javax.persistence.*; -import java.util.HashMap; -import java.util.Map; +import java.util.*; @Entity @Data @@ -30,4 +29,7 @@ public class Person { @MapKeyColumn(name="KeysSocialNetworks", length = 20) private Map socialNetworks = new HashMap<>(); +// @OneToMany(fetch=FetchType.LAZY, cascade = CascadeType.ALL, mappedBy="idMess") +// private List messages; + } diff --git a/src/main/java/org/sadtech/consultant/database/service/impl/MessageServiceImpl.java b/src/main/java/org/sadtech/consultant/database/service/impl/MessageServiceImpl.java index f5d967b..284a997 100644 --- a/src/main/java/org/sadtech/consultant/database/service/impl/MessageServiceImpl.java +++ b/src/main/java/org/sadtech/consultant/database/service/impl/MessageServiceImpl.java @@ -5,6 +5,7 @@ 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 org.springframework.transaction.annotation.Transactional; import java.util.List; diff --git a/src/main/java/org/sadtech/consultant/processing/MessageHandler.java b/src/main/java/org/sadtech/consultant/processing/MessageHandler.java index 232b33e..e486947 100644 --- a/src/main/java/org/sadtech/consultant/processing/MessageHandler.java +++ b/src/main/java/org/sadtech/consultant/processing/MessageHandler.java @@ -27,9 +27,7 @@ public class MessageHandler { while (true) { List messages = messageLogicService.getMessageRange(data); for (Message message : messages) { - System.out.println(message); - - + log.info(message); data = message.getDate(); } } diff --git a/src/main/java/org/sadtech/consultant/processing/MessageLogicService.java b/src/main/java/org/sadtech/consultant/processing/MessageLogicService.java index 1ed910a..7b37ba7 100644 --- a/src/main/java/org/sadtech/consultant/processing/MessageLogicService.java +++ b/src/main/java/org/sadtech/consultant/processing/MessageLogicService.java @@ -1,6 +1,7 @@ package org.sadtech.consultant.processing; import org.sadtech.consultant.database.entity.Message; +import org.sadtech.consultant.database.entity.Person; import org.sadtech.consultant.database.service.MessageService; import org.springframework.stereotype.Component; diff --git a/src/main/java/org/sadtech/consultant/processing/PersonLogicService.java b/src/main/java/org/sadtech/consultant/processing/PersonLogicService.java index 28c672c..4da66f7 100644 --- a/src/main/java/org/sadtech/consultant/processing/PersonLogicService.java +++ b/src/main/java/org/sadtech/consultant/processing/PersonLogicService.java @@ -1,9 +1,11 @@ package org.sadtech.consultant.processing; +import lombok.extern.log4j.Log4j; import org.sadtech.consultant.database.entity.Person; import org.sadtech.consultant.database.service.PersonService; import org.springframework.stereotype.Component; +@Log4j @Component public class PersonLogicService { @@ -13,9 +15,30 @@ public class PersonLogicService { this.personService = userService; } - public boolean addUser(Person user) { + public void addUser(Person user) { personService.addUser(user); - return true; + 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) {