Небольшие доработки обработки сообщений
This commit is contained in:
parent
0090ab9034
commit
d42ae014e0
@ -14,6 +14,7 @@ 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 = "idUser", nullable = false)
|
||||||
|
@ -3,8 +3,7 @@ package org.sadtech.consultant.database.entity;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import javax.persistence.*;
|
import javax.persistence.*;
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Data
|
@Data
|
||||||
@ -30,4 +29,7 @@ public class Person {
|
|||||||
@MapKeyColumn(name="KeysSocialNetworks", length = 20)
|
@MapKeyColumn(name="KeysSocialNetworks", length = 20)
|
||||||
private Map<String, Integer> socialNetworks = new HashMap<>();
|
private Map<String, Integer> socialNetworks = new HashMap<>();
|
||||||
|
|
||||||
|
// @OneToMany(fetch=FetchType.LAZY, cascade = CascadeType.ALL, mappedBy="idMess")
|
||||||
|
// private List<Message> messages;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ 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 org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -27,9 +27,7 @@ public class MessageHandler {
|
|||||||
while (true) {
|
while (true) {
|
||||||
List<Message> messages = messageLogicService.getMessageRange(data);
|
List<Message> messages = messageLogicService.getMessageRange(data);
|
||||||
for (Message message : messages) {
|
for (Message message : messages) {
|
||||||
System.out.println(message);
|
log.info(message);
|
||||||
|
|
||||||
|
|
||||||
data = message.getDate();
|
data = message.getDate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +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.Message;
|
||||||
|
import org.sadtech.consultant.database.entity.Person;
|
||||||
import org.sadtech.consultant.database.service.MessageService;
|
import org.sadtech.consultant.database.service.MessageService;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
package org.sadtech.consultant.processing;
|
package org.sadtech.consultant.processing;
|
||||||
|
|
||||||
|
import lombok.extern.log4j.Log4j;
|
||||||
import org.sadtech.consultant.database.entity.Person;
|
import org.sadtech.consultant.database.entity.Person;
|
||||||
import org.sadtech.consultant.database.service.PersonService;
|
import org.sadtech.consultant.database.service.PersonService;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Log4j
|
||||||
@Component
|
@Component
|
||||||
public class PersonLogicService {
|
public class PersonLogicService {
|
||||||
|
|
||||||
@ -13,10 +15,31 @@ public class PersonLogicService {
|
|||||||
this.personService = userService;
|
this.personService = userService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean addUser(Person user) {
|
public void addUser(Person user) {
|
||||||
personService.addUser(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;
|
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) {
|
public Person getUserById(Long id) {
|
||||||
return personService.getUserByID(id);
|
return personService.getUserByID(id);
|
||||||
|
Loading…
Reference in New Issue
Block a user