Merge branch 'release/release-0.6.2'
This commit is contained in:
commit
89050be9a3
3
pom.xml
3
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>org.sadtech.bot</groupId>
|
||||
<artifactId>bot-core</artifactId>
|
||||
<version>0.6.1-RELEASE</version>
|
||||
<version>0.6.2-RELEASE</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<build>
|
||||
@ -57,6 +57,7 @@
|
||||
<developers>
|
||||
<developer>
|
||||
<id>uPagge</id>
|
||||
<organization>SADTECH</organization>
|
||||
<name>Struchkov Mark</name>
|
||||
<email>upagge@mail.ru</email>
|
||||
</developer>
|
||||
|
@ -38,10 +38,6 @@ public class BoxAnswer {
|
||||
return keyboard;
|
||||
}
|
||||
|
||||
public void setKeyboard(KeyBoard keyboard) {
|
||||
this.keyboard = keyboard;
|
||||
}
|
||||
|
||||
public GeoCoordinate getCoordinates() {
|
||||
return coordinates;
|
||||
}
|
||||
@ -50,10 +46,6 @@ public class BoxAnswer {
|
||||
return stickerId;
|
||||
}
|
||||
|
||||
public void setStickerId(Integer stickerId) {
|
||||
this.stickerId = stickerId;
|
||||
}
|
||||
|
||||
public BoxAnswer prototype() {
|
||||
return new BoxAnswer(this);
|
||||
}
|
||||
|
@ -0,0 +1,9 @@
|
||||
package org.sadtech.bot.core.domain.content;
|
||||
|
||||
public class BoardComment extends Comment {
|
||||
|
||||
public BoardComment() {
|
||||
type = ContentType.BOARD_COMMENT;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package org.sadtech.bot.core.domain.content;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public abstract class Comment extends Message {
|
||||
|
||||
private Integer contentId;
|
||||
|
||||
public Integer getContentId() {
|
||||
return contentId;
|
||||
}
|
||||
|
||||
public void setContentId(Integer contentId) {
|
||||
this.contentId = contentId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof Comment)) return false;
|
||||
if (!super.equals(o)) return false;
|
||||
Comment that = (Comment) o;
|
||||
return Objects.equals(contentId, that.contentId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(super.hashCode(), contentId);
|
||||
}
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
package org.sadtech.bot.core.domain.content;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public abstract class Content {
|
||||
|
||||
private Integer personId;
|
||||
private String message;
|
||||
|
||||
public Content() {
|
||||
|
||||
}
|
||||
|
||||
public Content(Content source) {
|
||||
this.personId = source.getPersonId();
|
||||
this.message = source.getMessage();
|
||||
}
|
||||
|
||||
public Integer getPersonId() {
|
||||
return personId;
|
||||
}
|
||||
|
||||
public void setPersonId(Integer personId) {
|
||||
this.personId = personId;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof Content)) return false;
|
||||
Content content = (Content) o;
|
||||
return Objects.equals(personId, content.personId) &&
|
||||
Objects.equals(message, content.message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(personId, message);
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package org.sadtech.bot.core.domain.content;
|
||||
|
||||
public enum ContentType {
|
||||
|
||||
MAIL, BOARD_COMMENT, EMPTY
|
||||
|
||||
}
|
@ -2,7 +2,11 @@ package org.sadtech.bot.core.domain.content;
|
||||
|
||||
import org.sadtech.bot.core.exception.AppBotException;
|
||||
|
||||
public class EmptyContent extends Content {
|
||||
public class EmptyMessage extends Message {
|
||||
|
||||
public EmptyMessage() {
|
||||
type = ContentType.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
@ -11,6 +15,6 @@ public class EmptyContent extends Content {
|
||||
|
||||
@Override
|
||||
public void setMessage(String message) {
|
||||
throw new AppBotException(0, "EmptyContent no setMessage");
|
||||
throw new AppBotException(0, "EmptyMessage no setMessage");
|
||||
}
|
||||
}
|
@ -2,40 +2,20 @@ package org.sadtech.bot.core.domain.content;
|
||||
|
||||
import org.sadtech.bot.core.domain.content.attachment.Attachment;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class Mail extends Content {
|
||||
public class Mail extends Message {
|
||||
|
||||
private Integer id;
|
||||
private LocalDateTime date;
|
||||
private List<Attachment> attachments;
|
||||
|
||||
public Mail() {
|
||||
|
||||
type = ContentType.MAIL;
|
||||
}
|
||||
|
||||
public Mail(Mail source) {
|
||||
super(source);
|
||||
this.id = source.getId();
|
||||
this.date = source.getDate();
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public LocalDateTime getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public void setDate(LocalDateTime date) {
|
||||
this.date = date;
|
||||
this.attachments = source.getAttachments();
|
||||
}
|
||||
|
||||
|
||||
@ -51,28 +31,26 @@ public class Mail extends Content {
|
||||
this.attachments = attachments;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof Mail)) return false;
|
||||
if (!super.equals(o)) return false;
|
||||
Mail mail = (Mail) o;
|
||||
return Objects.equals(id, mail.id) &&
|
||||
Objects.equals(date, mail.date) &&
|
||||
Objects.equals(attachments, mail.attachments);
|
||||
return Objects.equals(attachments, mail.attachments);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(super.hashCode(), id, date, attachments);
|
||||
return Objects.hash(super.hashCode(), attachments);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Mail{" +
|
||||
"id=" + id +
|
||||
", date=" + date +
|
||||
", attachments=" + attachments +
|
||||
"attachments=" + attachments +
|
||||
", type=" + type +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,93 @@
|
||||
package org.sadtech.bot.core.domain.content;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Objects;
|
||||
|
||||
public abstract class Message {
|
||||
|
||||
private Integer id;
|
||||
protected ContentType type;
|
||||
private LocalDateTime createDate;
|
||||
private Integer personId;
|
||||
private String message;
|
||||
|
||||
public Message() {
|
||||
|
||||
}
|
||||
|
||||
public Message(Message source) {
|
||||
this.personId = source.getPersonId();
|
||||
this.message = source.getMessage();
|
||||
this.createDate = source.getCreateDate();
|
||||
this.id = source.getPersonId();
|
||||
this.type = source.getType();
|
||||
}
|
||||
|
||||
public Integer getPersonId() {
|
||||
return personId;
|
||||
}
|
||||
|
||||
public void setPersonId(Integer personId) {
|
||||
this.personId = personId;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public LocalDateTime getCreateDate() {
|
||||
return createDate;
|
||||
}
|
||||
|
||||
public void setCreateDate(LocalDateTime createDate) {
|
||||
this.createDate = createDate;
|
||||
}
|
||||
|
||||
public ContentType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(ContentType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof Message)) return false;
|
||||
Message message = (Message) o;
|
||||
return Objects.equals(id, message.id) &&
|
||||
type == message.type &&
|
||||
Objects.equals(createDate, message.createDate) &&
|
||||
Objects.equals(personId, message.personId) &&
|
||||
Objects.equals(this.message, message.message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id, type, createDate, personId, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Message{" +
|
||||
"id=" + id +
|
||||
", type=" + type +
|
||||
", createDate=" + createDate +
|
||||
", personId=" + personId +
|
||||
", message='" + message + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package org.sadtech.bot.core.domain.keyboard;
|
||||
|
||||
public enum ButtonType {
|
||||
|
||||
TEXT, ACCOUNT
|
||||
|
||||
}
|
@ -2,80 +2,38 @@ package org.sadtech.bot.core.domain.keyboard;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class KeyBoardButton {
|
||||
public abstract class KeyBoardButton {
|
||||
|
||||
private String payload;
|
||||
private String label;
|
||||
private ButtonColor color = ButtonColor.DEFAULT;
|
||||
|
||||
private KeyBoardButton() {
|
||||
|
||||
}
|
||||
protected String payload;
|
||||
protected ButtonType type = ButtonType.TEXT;
|
||||
|
||||
public String getPayload() {
|
||||
return payload;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
public void setPayload(String payload) {
|
||||
this.payload = payload;
|
||||
}
|
||||
|
||||
public ButtonColor getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new KeyBoardButton().new Builder();
|
||||
}
|
||||
|
||||
public class Builder {
|
||||
|
||||
private Builder() {
|
||||
|
||||
}
|
||||
|
||||
public Builder color(ButtonColor color) {
|
||||
KeyBoardButton.this.color = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder label(String label) {
|
||||
KeyBoardButton.this.label = label;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder payload(String payload) {
|
||||
KeyBoardButton.this.payload = payload;
|
||||
return this;
|
||||
}
|
||||
|
||||
public KeyBoardButton build() {
|
||||
return KeyBoardButton.this;
|
||||
public ButtonType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(ButtonType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof KeyBoardButton)) return false;
|
||||
KeyBoardButton button = (KeyBoardButton) o;
|
||||
return Objects.equals(payload, button.payload) &&
|
||||
Objects.equals(label, button.label) &&
|
||||
color == button.color;
|
||||
KeyBoardButton that = (KeyBoardButton) o;
|
||||
return Objects.equals(payload, that.payload) &&
|
||||
type == that.type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(payload, label, color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "KeyBoardButton{" +
|
||||
"payload='" + payload + '\'' +
|
||||
", label='" + label + '\'' +
|
||||
", color=" + color +
|
||||
'}';
|
||||
return Objects.hash(payload, type);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,75 @@
|
||||
package org.sadtech.bot.core.domain.keyboard.button;
|
||||
|
||||
import org.sadtech.bot.core.domain.keyboard.ButtonType;
|
||||
import org.sadtech.bot.core.domain.keyboard.KeyBoardButton;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class KeyBoardButtonAccount extends KeyBoardButton {
|
||||
|
||||
private Integer amount;
|
||||
private Integer accountId;
|
||||
private String description;
|
||||
|
||||
private KeyBoardButtonAccount() {
|
||||
type = ButtonType.ACCOUNT;
|
||||
}
|
||||
|
||||
public Integer getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public Integer getAccountId() {
|
||||
return accountId;
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new KeyBoardButtonAccount().new Builder();
|
||||
}
|
||||
|
||||
public class Builder {
|
||||
private Builder() {
|
||||
|
||||
}
|
||||
|
||||
public Builder amount(Integer amount) {
|
||||
KeyBoardButtonAccount.this.amount = amount;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder description(String description) {
|
||||
KeyBoardButtonAccount.this.description = description;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder accountId(Integer accountId) {
|
||||
KeyBoardButtonAccount.this.accountId = accountId;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public KeyBoardButtonAccount build() {
|
||||
return KeyBoardButtonAccount.this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof KeyBoardButtonAccount)) return false;
|
||||
if (!super.equals(o)) return false;
|
||||
KeyBoardButtonAccount that = (KeyBoardButtonAccount) o;
|
||||
return Objects.equals(amount, that.amount) &&
|
||||
Objects.equals(description, that.description);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(super.hashCode(), amount, description);
|
||||
}
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
package org.sadtech.bot.core.domain.keyboard.button;
|
||||
|
||||
import org.sadtech.bot.core.domain.keyboard.ButtonColor;
|
||||
import org.sadtech.bot.core.domain.keyboard.ButtonType;
|
||||
import org.sadtech.bot.core.domain.keyboard.KeyBoardButton;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class KeyBoardButtonText extends KeyBoardButton {
|
||||
|
||||
private String label;
|
||||
private ButtonColor color = ButtonColor.DEFAULT;
|
||||
|
||||
public KeyBoardButtonText() {
|
||||
type = ButtonType.TEXT;
|
||||
}
|
||||
|
||||
public ButtonColor getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new KeyBoardButtonText().new Builder();
|
||||
}
|
||||
|
||||
public class Builder {
|
||||
private Builder() {
|
||||
|
||||
}
|
||||
|
||||
public Builder label(String label) {
|
||||
KeyBoardButtonText.this.label = label;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder color(ButtonColor color) {
|
||||
KeyBoardButtonText.this.color = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder payload(String payload) {
|
||||
KeyBoardButtonText.this.payload = payload;
|
||||
return this;
|
||||
}
|
||||
|
||||
public KeyBoardButtonText build() {
|
||||
return KeyBoardButtonText.this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof KeyBoardButtonText)) return false;
|
||||
if (!super.equals(o)) return false;
|
||||
KeyBoardButtonText that = (KeyBoardButtonText) o;
|
||||
return Objects.equals(label, that.label) &&
|
||||
color == that.color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(super.hashCode(), label, color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "KeyBoardButtonText{" +
|
||||
"label='" + label + '\'' +
|
||||
", color=" + color +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -5,7 +5,7 @@ import java.util.Objects;
|
||||
public class Account {
|
||||
|
||||
private Integer id;
|
||||
private Double totalSum;
|
||||
private Integer totalSum;
|
||||
private Integer belongsPersonId;
|
||||
private Integer extinguishedPersonId;
|
||||
private String description;
|
||||
@ -19,11 +19,11 @@ public class Account {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Double getTotalSum() {
|
||||
public Integer getTotalSum() {
|
||||
return totalSum;
|
||||
}
|
||||
|
||||
public void setTotalSum(Double totalSum) {
|
||||
public void setTotalSum(Integer totalSum) {
|
||||
this.totalSum = totalSum;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,9 @@
|
||||
package org.sadtech.bot.core.exception;
|
||||
|
||||
public class TimerSettingExceprion extends AppBotException {
|
||||
|
||||
public TimerSettingExceprion(String message) {
|
||||
super(54, message);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package org.sadtech.bot.core.repository;
|
||||
|
||||
import org.sadtech.bot.core.domain.content.Message;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
public interface ContentRepository<T extends Message> {
|
||||
|
||||
Integer add(T content);
|
||||
|
||||
List<T> findByTime(LocalDateTime timeFrom, LocalDateTime timeTo);
|
||||
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
package org.sadtech.bot.core.repository;
|
||||
|
||||
import org.sadtech.bot.core.domain.content.Mail;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
public interface MailRepository {
|
||||
|
||||
void add(Mail mail);
|
||||
|
||||
List<Mail> getMailByTime(LocalDateTime timeFrom, LocalDateTime timeTo);
|
||||
|
||||
}
|
@ -43,6 +43,6 @@ public class AccountRepositoryMap implements AccountRepository {
|
||||
}
|
||||
|
||||
private boolean check(Integer id) {
|
||||
return saveMap.containsKey(id);
|
||||
return !saveMap.containsKey(id);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,36 @@
|
||||
package org.sadtech.bot.core.repository.impl;
|
||||
|
||||
import org.sadtech.bot.core.domain.content.BoardComment;
|
||||
import org.sadtech.bot.core.repository.ContentRepository;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class BoardCommentRepositoryMap implements ContentRepository<BoardComment> {
|
||||
|
||||
private final Map<Integer, BoardComment> saveMap = new HashMap<>();
|
||||
private Integer count = 0;
|
||||
|
||||
@Override
|
||||
public Integer add(BoardComment comment) {
|
||||
comment.setId(count);
|
||||
saveMap.put(count, comment);
|
||||
return count++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BoardComment> findByTime(LocalDateTime timeFrom, LocalDateTime timeTo) {
|
||||
ArrayList<BoardComment> rezultMails = new ArrayList<>();
|
||||
for (int i = saveMap.size() - 1; i >= 0; i--) {
|
||||
if (!(saveMap.get(i).getCreateDate().isBefore(timeFrom) || saveMap.get(i).getCreateDate().isAfter(timeTo)) && saveMap.get(i).getCreateDate().equals(timeFrom)) {
|
||||
rezultMails.add(this.saveMap.get(i));
|
||||
} else if (saveMap.get(i).getCreateDate().isBefore(timeFrom)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return rezultMails;
|
||||
}
|
||||
}
|
@ -1,40 +1,30 @@
|
||||
package org.sadtech.bot.core.repository.impl;
|
||||
|
||||
import org.sadtech.bot.core.domain.content.Mail;
|
||||
import org.sadtech.bot.core.repository.EventRepository;
|
||||
import org.sadtech.bot.core.repository.MailRepository;
|
||||
import org.sadtech.bot.core.repository.ContentRepository;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
public class MailRepositoryList implements EventRepository<Mail>, MailRepository {
|
||||
public class MailRepositoryList implements ContentRepository<Mail> {
|
||||
|
||||
private final List<Mail> mails = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void add(Mail mail) {
|
||||
public Integer add(Mail mail) {
|
||||
mails.add(mail);
|
||||
return mails.size() - 1;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void cleanAll() {
|
||||
mails.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Queue<Mail> getEventQueue() {
|
||||
return new ConcurrentLinkedQueue<>(mails);
|
||||
}
|
||||
|
||||
public List<Mail> getMailByTime(LocalDateTime timeFrom, LocalDateTime timeTo) {
|
||||
public List<Mail> findByTime(LocalDateTime timeFrom, LocalDateTime timeTo) {
|
||||
ArrayList<Mail> rezultMails = new ArrayList<>();
|
||||
for (int i = mails.size() - 1; i >= 0; i--) {
|
||||
if (!(mails.get(i).getDate().isBefore(timeFrom) || mails.get(i).getDate().isAfter(timeTo)) && mails.get(i).getDate().equals(timeFrom)) {
|
||||
if (!(mails.get(i).getCreateDate().isBefore(timeFrom) || mails.get(i).getCreateDate().isAfter(timeTo)) && mails.get(i).getCreateDate().equals(timeFrom)) {
|
||||
rezultMails.add(this.mails.get(i));
|
||||
} else if (mails.get(i).getDate().isBefore(timeFrom)) {
|
||||
} else if (mails.get(i).getCreateDate().isBefore(timeFrom)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ public interface AccountService {
|
||||
|
||||
Integer add(Account account);
|
||||
|
||||
Boolean pay(Integer accountId, Integer extinguishedPersonId, Double sum);
|
||||
Boolean pay(Integer accountId, Integer extinguishedPersonId, Integer sum);
|
||||
|
||||
Boolean paymentVerification(Integer accountId);
|
||||
|
||||
|
@ -0,0 +1,6 @@
|
||||
package org.sadtech.bot.core.service;
|
||||
|
||||
import org.sadtech.bot.core.domain.content.BoardComment;
|
||||
|
||||
public interface BoardCommentService extends ContentService<BoardComment> {
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package org.sadtech.bot.core.service;
|
||||
|
||||
import org.sadtech.bot.core.domain.content.Message;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
public interface ContentService<T extends Message> {
|
||||
|
||||
void add(T event);
|
||||
|
||||
List<T> getByTime(LocalDateTime timeFrom, LocalDateTime timeTo);
|
||||
|
||||
List<T> getLastEventByTime(LocalDateTime timeFrom, LocalDateTime timeTo);
|
||||
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
package org.sadtech.bot.core.service;
|
||||
|
||||
import org.sadtech.bot.core.domain.content.Content;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
public interface EventService<T extends Content> {
|
||||
|
||||
void add(T event);
|
||||
|
||||
List<T> getEvent(LocalDateTime timeFrom, LocalDateTime timeTo);
|
||||
|
||||
List<T> getFirstEventByTime(LocalDateTime timeFrom, LocalDateTime timeTo);
|
||||
|
||||
List<T> getLastEventByTime(LocalDateTime timeFrom, LocalDateTime timeTo);
|
||||
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
package org.sadtech.bot.core.service;
|
||||
|
||||
import org.sadtech.bot.core.domain.content.Content;
|
||||
import org.sadtech.bot.core.domain.content.Message;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Filter<T extends Content> {
|
||||
public interface Filter<T extends Message> {
|
||||
|
||||
void processing(T content);
|
||||
|
||||
|
@ -2,6 +2,6 @@ package org.sadtech.bot.core.service;
|
||||
|
||||
import org.sadtech.bot.core.domain.content.Mail;
|
||||
|
||||
public interface MailService extends EventService<Mail> {
|
||||
public interface MailService extends ContentService<Mail> {
|
||||
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ public class AccountServiceImpl implements AccountService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean pay(Integer accountId, Integer extinguishedPersonId, Double sum) {
|
||||
public Boolean pay(Integer accountId, Integer extinguishedPersonId, Integer sum) {
|
||||
Account account = accountRepository.findById(accountId);
|
||||
if (validStatus(account.getAccountStatus())) {
|
||||
if (account.getTotalSum().equals(sum)) {
|
||||
|
@ -0,0 +1,49 @@
|
||||
package org.sadtech.bot.core.service.impl;
|
||||
|
||||
import org.sadtech.bot.core.domain.content.BoardComment;
|
||||
import org.sadtech.bot.core.repository.ContentRepository;
|
||||
import org.sadtech.bot.core.service.BoardCommentService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class BoardCommentServiceImpl implements BoardCommentService {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(BoardCommentServiceImpl.class);
|
||||
|
||||
private final ContentRepository<BoardComment> commentRepository;
|
||||
|
||||
public BoardCommentServiceImpl(ContentRepository<BoardComment> commentRepository) {
|
||||
this.commentRepository = commentRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(BoardComment event) {
|
||||
commentRepository.add(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BoardComment> getByTime(LocalDateTime timeFrom, LocalDateTime timeTo) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BoardComment> getLastEventByTime(LocalDateTime timeFrom, LocalDateTime timeTo) {
|
||||
log.info("Запрошены последние комментарии к обсуждению {} - {} ", timeFrom, timeTo);
|
||||
List<BoardComment> mails = commentRepository.findByTime(timeFrom, timeTo);
|
||||
Set<Integer> people = new HashSet<>();
|
||||
List<BoardComment> returnMails = new ArrayList<>();
|
||||
for (int i = mails.size() - 1; i >= 0; i--) {
|
||||
if (!people.contains(mails.get(i).getPersonId())) {
|
||||
returnMails.add(mails.get(i));
|
||||
people.add(mails.get(i).getPersonId());
|
||||
}
|
||||
}
|
||||
return returnMails;
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package org.sadtech.bot.core.service.impl;
|
||||
|
||||
import org.sadtech.bot.core.domain.content.Mail;
|
||||
import org.sadtech.bot.core.repository.MailRepository;
|
||||
import org.sadtech.bot.core.repository.ContentRepository;
|
||||
import org.sadtech.bot.core.service.MailService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -16,9 +16,9 @@ public class MailServiceImpl implements MailService {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(MailServiceImpl.class);
|
||||
|
||||
private final MailRepository mailRepository;
|
||||
private final ContentRepository<Mail> mailRepository;
|
||||
|
||||
public MailServiceImpl(MailRepository mailRepository) {
|
||||
public MailServiceImpl(ContentRepository<Mail> mailRepository) {
|
||||
this.mailRepository = mailRepository;
|
||||
}
|
||||
|
||||
@ -29,9 +29,9 @@ public class MailServiceImpl implements MailService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Mail> getFirstEventByTime(LocalDateTime timeFrom, LocalDateTime timeTo) {
|
||||
log.info("Запрошены сообщения {} - {} ", timeFrom, timeTo);
|
||||
List<Mail> mails = mailRepository.getMailByTime(timeFrom, timeTo);
|
||||
public List<Mail> getLastEventByTime(LocalDateTime timeFrom, LocalDateTime timeTo) {
|
||||
log.info("Запрошены последние сообщения {} - {} ", timeFrom, timeTo);
|
||||
List<Mail> mails = mailRepository.findByTime(timeFrom, timeTo);
|
||||
Set<Integer> people = new HashSet<>();
|
||||
List<Mail> returnMails = new ArrayList<>();
|
||||
for (int i = mails.size() - 1; i >= 0; i--) {
|
||||
@ -44,23 +44,9 @@ public class MailServiceImpl implements MailService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Mail> getLastEventByTime(LocalDateTime timeFrom, LocalDateTime timeTo) {
|
||||
List<Mail> mails = mailRepository.getMailByTime(timeFrom, timeTo);
|
||||
Set<Integer> people = new HashSet<>();
|
||||
List<Mail> returnMails = new ArrayList<>();
|
||||
for (Mail mail : mails) {
|
||||
if (!people.contains(mail.getPersonId())) {
|
||||
returnMails.add(mail);
|
||||
people.add(mail.getPersonId());
|
||||
}
|
||||
}
|
||||
return returnMails;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Mail> getEvent(LocalDateTime timeFrom, LocalDateTime timeTo) {
|
||||
log.info("Запрошены сообщения {} - {} ", timeFrom, timeTo);
|
||||
return mailRepository.getMailByTime(timeFrom, timeTo);
|
||||
public List<Mail> getByTime(LocalDateTime timeFrom, LocalDateTime timeTo) {
|
||||
log.info("Запрошены все сообщения {} - {} ", timeFrom, timeTo);
|
||||
return mailRepository.findByTime(timeFrom, timeTo);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,26 @@
|
||||
package org.sadtech.bot.core.service.sender;
|
||||
|
||||
import org.sadtech.bot.core.domain.BoxAnswer;
|
||||
import org.sadtech.bot.core.domain.content.Comment;
|
||||
import org.sadtech.bot.core.domain.content.Message;
|
||||
|
||||
public class SendBox {
|
||||
|
||||
private SendBox() {
|
||||
|
||||
}
|
||||
|
||||
public static void sent(Message message, BoxAnswer boxAnswer, Sent sent) {
|
||||
switch (message.getType()) {
|
||||
case BOARD_COMMENT:
|
||||
sent.send(((Comment) message).getContentId(), message.getPersonId(), boxAnswer);
|
||||
break;
|
||||
case MAIL:
|
||||
sent.send(message.getPersonId(), boxAnswer);
|
||||
break;
|
||||
default:
|
||||
sent.send(message.getPersonId(), boxAnswer);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -4,8 +4,8 @@ import org.sadtech.bot.core.domain.BoxAnswer;
|
||||
|
||||
public interface Sent {
|
||||
|
||||
void send(Integer personId, String message);
|
||||
|
||||
void send(Integer personId, BoxAnswer boxAnswer);
|
||||
|
||||
void send(Integer contentId, Integer personId, BoxAnswer boxAnswer);
|
||||
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ public class EmailSent implements Sent {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(Integer personId, String htmlText) {
|
||||
public void send(Integer personId, BoxAnswer boxAnswer) {
|
||||
Session session = Session.getDefaultInstance(emailConfig.getProps(), new Authenticator() {
|
||||
@Override
|
||||
protected PasswordAuthentication getPasswordAuthentication() {
|
||||
@ -33,7 +33,7 @@ public class EmailSent implements Sent {
|
||||
Message message = new MimeMessage(session);
|
||||
message.setFrom(new InternetAddress(emailConfig.getUsername()));
|
||||
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(emailConfig.getUsername()));
|
||||
message.setContent(htmlText, "text/html; charset=utf-8");
|
||||
message.setContent(boxAnswer.getMessage(), "text/html; charset=utf-8");
|
||||
Transport.send(message);
|
||||
} catch (MessagingException e) {
|
||||
log.error(e.getMessage());
|
||||
@ -42,7 +42,7 @@ public class EmailSent implements Sent {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(Integer personId, BoxAnswer boxAnswer) {
|
||||
public void send(Integer contentId, Integer personId, BoxAnswer boxAnswer) {
|
||||
throw new MailSendException();
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package org.sadtech.bot.core.utils;
|
||||
|
||||
import org.sadtech.bot.core.domain.content.EmptyContent;
|
||||
import org.sadtech.bot.core.domain.content.EmptyMessage;
|
||||
|
||||
public class Contents {
|
||||
|
||||
@ -8,7 +8,7 @@ public class Contents {
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
public static final EmptyContent EMPTY_CONTENT = new EmptyContent();
|
||||
public static final EmptyMessage EMPTY_CONTENT = new EmptyMessage();
|
||||
|
||||
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import org.sadtech.bot.core.domain.keyboard.ButtonColor;
|
||||
import org.sadtech.bot.core.domain.keyboard.KeyBoard;
|
||||
import org.sadtech.bot.core.domain.keyboard.KeyBoardButton;
|
||||
import org.sadtech.bot.core.domain.keyboard.KeyBoardLine;
|
||||
import org.sadtech.bot.core.domain.keyboard.button.KeyBoardButtonText;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -14,8 +15,8 @@ public class KeyBoards {
|
||||
}
|
||||
|
||||
public static KeyBoard keyBoardYesNo() {
|
||||
KeyBoardButton yesButton = KeyBoardButton.builder().color(ButtonColor.POSITIVE).label("Да").payload("{\"button\": \"yes\"}").build();
|
||||
KeyBoardButton noButton = KeyBoardButton.builder().color(ButtonColor.NEGATIVE).label("Нет").payload("{\"button\": \"no\"}").build();
|
||||
KeyBoardButton yesButton = KeyBoardButtonText.builder().color(ButtonColor.POSITIVE).label("Да").payload("{\"button\": \"yes\"}").build();
|
||||
KeyBoardButton noButton = KeyBoardButtonText.builder().color(ButtonColor.NEGATIVE).label("Нет").payload("{\"button\": \"no\"}").build();
|
||||
KeyBoardLine keyBoardLine = KeyBoardLine.builder().buttonKeyBoard(yesButton).buttonKeyBoard(noButton).build();
|
||||
return KeyBoard.builder().lineKeyBoard(keyBoardLine).oneTime(true).build();
|
||||
}
|
||||
@ -23,12 +24,39 @@ public class KeyBoards {
|
||||
public static KeyBoard verticalMenuString(List<String> labelButtons) {
|
||||
KeyBoard.Builder keyBoard = KeyBoard.builder().oneTime(true);
|
||||
for (String labelButton : labelButtons) {
|
||||
KeyBoardButton keyBoardButton = KeyBoardButton.builder().label(labelButton).payload("{\"button\": \"" + labelButton + "\"}").build();
|
||||
KeyBoardButton keyBoardButton = KeyBoardButtonText.builder().label(labelButton).payload("{\"button\": \"" + labelButton + "\"}").build();
|
||||
keyBoard.lineKeyBoard(KeyBoardLine.builder().buttonKeyBoard(keyBoardButton).build());
|
||||
}
|
||||
return keyBoard.build();
|
||||
}
|
||||
|
||||
public static KeyBoard verticalMenuString(String... labelButton) {
|
||||
KeyBoard.Builder keyBoard = KeyBoard.builder().oneTime(true);
|
||||
for (String label : labelButton) {
|
||||
KeyBoardButton keyBoardButton = KeyBoardButtonText.builder().label(label).payload("{\"button\": \"" + label + "\"}").build();
|
||||
keyBoard.lineKeyBoard(KeyBoardLine.builder().buttonKeyBoard(keyBoardButton).build());
|
||||
}
|
||||
return keyBoard.build();
|
||||
}
|
||||
|
||||
public static KeyBoard verticalDuoMenuString(String... labelButton) {
|
||||
KeyBoard.Builder keyBoard = KeyBoard.builder().oneTime(true);
|
||||
boolean flag = true;
|
||||
KeyBoardLine.Builder keyBoardLine = KeyBoardLine.builder();
|
||||
for (String label : labelButton) {
|
||||
if (flag) {
|
||||
keyBoardLine.buttonKeyBoard(KeyBoardButtonText.builder().label(label).build());
|
||||
flag = false;
|
||||
} else {
|
||||
keyBoardLine.buttonKeyBoard(KeyBoardButtonText.builder().label(label).build());
|
||||
keyBoard.lineKeyBoard(keyBoardLine.build());
|
||||
keyBoardLine = KeyBoardLine.builder();
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
return keyBoard.build();
|
||||
}
|
||||
|
||||
public static KeyBoard verticalMenuButton(List<KeyBoardButton> keyBoardButtons) {
|
||||
KeyBoard.Builder keyBoard = KeyBoard.builder().oneTime(true);
|
||||
for (KeyBoardButton keyBoardButton : keyBoardButtons) {
|
||||
@ -36,4 +64,9 @@ public class KeyBoards {
|
||||
}
|
||||
return keyBoard.build();
|
||||
}
|
||||
|
||||
public static KeyBoard singelton(KeyBoardButton keyBoardButton) {
|
||||
KeyBoardLine line = KeyBoardLine.builder().buttonKeyBoard(keyBoardButton).build();
|
||||
return KeyBoard.builder().lineKeyBoard(line).build();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user