Небольшие доработки обработки сообщений

This commit is contained in:
Mark Struchkov 2019-01-09 11:02:38 +03:00
parent 0090ab9034
commit d42ae014e0
6 changed files with 33 additions and 7 deletions

View File

@ -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)

View File

@ -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<String, Integer> socialNetworks = new HashMap<>();
// @OneToMany(fetch=FetchType.LAZY, cascade = CascadeType.ALL, mappedBy="idMess")
// private List<Message> messages;
}

View File

@ -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;

View File

@ -27,9 +27,7 @@ public class MessageHandler {
while (true) {
List<Message> messages = messageLogicService.getMessageRange(data);
for (Message message : messages) {
System.out.println(message);
log.info(message);
data = message.getDate();
}
}

View File

@ -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;

View File

@ -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) {