diff --git a/pom.xml b/pom.xml index dfd0910..3a0ef96 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ org.sadtech.autoresponder autoresponder - 1.3.0-RELEASE + 1.3.1-RELEASE jar diff --git a/src/main/java/org/sadtech/autoresponder/Autoresponder.java b/src/main/java/org/sadtech/autoresponder/Autoresponder.java index 05d54a2..180567d 100644 --- a/src/main/java/org/sadtech/autoresponder/Autoresponder.java +++ b/src/main/java/org/sadtech/autoresponder/Autoresponder.java @@ -8,10 +8,7 @@ import org.sadtech.autoresponder.service.PersonService; import org.sadtech.autoresponder.service.UnitService; import org.sadtech.autoresponder.submodule.parser.Parser; -import java.util.HashSet; -import java.util.List; -import java.util.Optional; -import java.util.Set; +import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -22,6 +19,14 @@ public class Autoresponder { private UnitService unitService; private PersonService personService; + public PersonService getPersonService() { + return personService; + } + + public void setPersonService(PersonService personService) { + this.personService = personService; + } + public Autoresponder(UnitService unitService, PersonService personService) { this.unitService = unitService; this.personService = personService; @@ -56,7 +61,7 @@ public class Autoresponder { return person; } - private Unit nextUnit(List nextUnits, String message) { + private Unit nextUnit(Set nextUnits, String message) { if (nextUnits.size() > 0) { UnitPriorityComparator unitPriorityComparator = new UnitPriorityComparator(); Optional patternUnits = nextUnits.stream().filter(nextUnit -> nextUnit.getPattern() != null).filter(nextUnit -> patternReg(nextUnit, message)).max(unitPriorityComparator); @@ -91,6 +96,7 @@ public class Autoresponder { if (unit.getKeyWords() != null) { Set temp = new HashSet<>(unit.getKeyWords()); temp.retainAll(words); + log.info("Юнит: " + unit.getClass().getSimpleName()); log.info("Ключевые слова юнита: " + unit.getKeyWords() + " (" + unit.getKeyWords().size() + ")"); log.info("Ключевые слова от пользователя: " + words); log.info("Пересечение: " + temp + " (" + temp.size() + ")"); diff --git a/src/main/java/org/sadtech/autoresponder/entity/Person.java b/src/main/java/org/sadtech/autoresponder/entity/Person.java index 86fb8d1..92f5a4e 100644 --- a/src/main/java/org/sadtech/autoresponder/entity/Person.java +++ b/src/main/java/org/sadtech/autoresponder/entity/Person.java @@ -6,10 +6,12 @@ public class Person { private Integer id; private Unit unit; + private Boolean replyStatus; public Person(Integer id, Unit unit) { this.id = id; this.unit = unit; + replyStatus = true; } public Person(Integer id) { @@ -32,6 +34,14 @@ public class Person { this.unit = unit; } + public Boolean getReplyStatus() { + return replyStatus; + } + + public void setReplyStatus(Boolean replyStatus) { + this.replyStatus = replyStatus; + } + @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/src/main/java/org/sadtech/autoresponder/entity/Unit.java b/src/main/java/org/sadtech/autoresponder/entity/Unit.java index e4df06c..690e008 100644 --- a/src/main/java/org/sadtech/autoresponder/entity/Unit.java +++ b/src/main/java/org/sadtech/autoresponder/entity/Unit.java @@ -9,14 +9,14 @@ public abstract class Unit { private Pattern pattern; private Integer matchThreshold; private Integer priority; - private List nextUnits; + private Set nextUnits; public Unit() { priority = 10; matchThreshold = 10; } - public Unit(Set keyWords, Pattern pattern, Integer matchThreshold, Integer priority, List nextUnits) { + public Unit(Set keyWords, Pattern pattern, Integer matchThreshold, Integer priority, Set nextUnits) { this.keyWords = keyWords; this.pattern = pattern; this.matchThreshold = matchThreshold; @@ -33,7 +33,7 @@ public abstract class Unit { public void setNextUnit(Unit unit) { if (nextUnits == null) { - nextUnits = new ArrayList<>(); + nextUnits = new HashSet<>(); } nextUnits.add(unit); } @@ -62,11 +62,11 @@ public abstract class Unit { this.priority = priority; } - public List getNextUnits() { + public Set getNextUnits() { return nextUnits; } - public void setNextUnits(List nextUnits) { + public void setNextUnits(Set nextUnits) { this.nextUnits = nextUnits; } diff --git a/src/main/java/org/sadtech/autoresponder/repository/UnitRepository.java b/src/main/java/org/sadtech/autoresponder/repository/UnitRepository.java index 74d8040..380bd34 100644 --- a/src/main/java/org/sadtech/autoresponder/repository/UnitRepository.java +++ b/src/main/java/org/sadtech/autoresponder/repository/UnitRepository.java @@ -3,6 +3,7 @@ package org.sadtech.autoresponder.repository; import org.sadtech.autoresponder.entity.Unit; import java.util.List; +import java.util.Set; public interface UnitRepository { @@ -10,6 +11,6 @@ public interface UnitRepository { void addUnits(List units); - List menuUnits(); + Set menuUnits(); } diff --git a/src/main/java/org/sadtech/autoresponder/service/UnitService.java b/src/main/java/org/sadtech/autoresponder/service/UnitService.java index 0b44574..903fe99 100644 --- a/src/main/java/org/sadtech/autoresponder/service/UnitService.java +++ b/src/main/java/org/sadtech/autoresponder/service/UnitService.java @@ -1,13 +1,12 @@ package org.sadtech.autoresponder.service; import org.sadtech.autoresponder.entity.Unit; -import org.sadtech.autoresponder.repository.UnitRepository; -import java.util.List; +import java.util.Set; public interface UnitService { - List menuUnit(); + Set menuUnit(); void addUnit(Unit unit); diff --git a/src/main/java/org/sadtech/autoresponder/service/impl/PersonServiceImpl.java b/src/main/java/org/sadtech/autoresponder/service/impl/PersonServiceImpl.java index 4162ec7..53d1ad3 100644 --- a/src/main/java/org/sadtech/autoresponder/service/impl/PersonServiceImpl.java +++ b/src/main/java/org/sadtech/autoresponder/service/impl/PersonServiceImpl.java @@ -2,6 +2,7 @@ package org.sadtech.autoresponder.service.impl; import org.sadtech.autoresponder.entity.Person; import org.sadtech.autoresponder.repository.PersonRepository; +import org.sadtech.autoresponder.repository.impl.PersonRepositoryMap; import org.sadtech.autoresponder.service.PersonService; import org.apache.log4j.Logger; @@ -12,6 +13,10 @@ public class PersonServiceImpl implements PersonService { private PersonRepository personRepository; + public PersonServiceImpl() { + this.personRepository = new PersonRepositoryMap(); + } + public PersonServiceImpl(PersonRepository personRepository) { this.personRepository = personRepository; } diff --git a/src/main/java/org/sadtech/autoresponder/service/impl/UnitServiceImpl.java b/src/main/java/org/sadtech/autoresponder/service/impl/UnitServiceImpl.java index d3bd53e..499e5db 100644 --- a/src/main/java/org/sadtech/autoresponder/service/impl/UnitServiceImpl.java +++ b/src/main/java/org/sadtech/autoresponder/service/impl/UnitServiceImpl.java @@ -5,8 +5,7 @@ import org.sadtech.autoresponder.entity.Unit; import org.sadtech.autoresponder.repository.UnitRepository; import org.sadtech.autoresponder.service.UnitService; -import java.util.ArrayList; -import java.util.List; +import java.util.Set; public class UnitServiceImpl implements UnitService { @@ -19,7 +18,7 @@ public class UnitServiceImpl implements UnitService { } @Override - public List menuUnit() { + public Set menuUnit() { return unitRepository.menuUnits(); }