From 4d5f3ad542868fcc700f2c26ab0e8863f206c34a Mon Sep 17 00:00:00 2001 From: Struchkov Mark Date: Mon, 25 Apr 2022 21:48:04 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=B4=D0=B0=D0=BB=D0=B8=D0=BB=20=D1=8E?= =?UTF-8?q?=D0=BD=D0=B8=D1=82=20=D0=BE=D1=82=D0=B2=D0=B5=D1=87=D0=B0=D1=8E?= =?UTF-8?q?=D1=89=D0=B8=D0=B9=20=D0=B7=D0=B0=20=D0=BE=D0=BF=D0=BB=D0=B0?= =?UTF-8?q?=D1=82=D1=83=20=D0=B8=20=D0=B2=D1=81=D0=B5=20=D1=87=D1=82=D0=BE?= =?UTF-8?q?=20=D1=81=20=D0=BD=D0=B8=D0=BC=20=D1=81=D0=B2=D1=8F=D0=B7=D0=B0?= =?UTF-8?q?=D0=BD=D0=BE,=20=D1=82=D0=B0=D0=BA=20=D0=B6=D0=B5=20=D0=BE?= =?UTF-8?q?=D0=B1=D0=BD=D0=BE=D0=B2=D0=B8=D0=BB=20=D0=B0=D1=80=D1=85=D0=B8?= =?UTF-8?q?=D1=82=D0=B5=D0=BA=D1=82=D1=83=D1=80=D1=83=20=D0=BA=D0=BB=D0=B0?= =?UTF-8?q?=D0=B2=D0=B8=D0=B0=D1=82=D1=83=D1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../godfather/context/domain/BoxAnswer.java | 11 +-- .../context/domain/keyboard/ButtonColor.java | 15 ---- .../context/domain/keyboard/ButtonType.java | 13 --- .../context/domain/keyboard/KeyBoard.java | 29 +----- .../domain/keyboard/KeyBoardButton.java | 27 +----- .../context/domain/keyboard/KeyBoardLine.java | 24 +---- .../button/KeyBoardButtonAccount.java | 43 --------- .../keyboard/button/KeyBoardButtonText.java | 37 -------- .../domain/keyboard/button/SimpleButton.java | 50 +++++++++++ .../keyboard/simple/SimpleKeyBoard.java | 50 +++++++++++ .../keyboard/simple/SimpleKeyBoardLine.java | 41 +++++++++ .../context/domain/money/Account.java | 68 -------------- .../context/domain/money/AccountStatus.java | 15 ---- .../context/repository/AccountRepository.java | 21 ----- .../impl/local/AccountRepositoryMap.java | 35 -------- .../context/service/AccountService.java | 33 ------- .../service/impl/AccountServiceImpl.java | 61 ------------- .../godfather/context/utils/KeyBoards.java | 88 +++++++++---------- bot-core/pom.xml | 2 +- .../godfather/core/GeneralAutoResponder.java | 6 -- .../core/domain/AccountAutoCheck.java | 40 --------- .../core/domain/unit/AnswerAccount.java | 65 -------------- .../service/action/AnswerAccountAction.java | 81 ----------------- pom.xml | 7 ++ 24 files changed, 201 insertions(+), 661 deletions(-) delete mode 100644 bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/ButtonColor.java delete mode 100644 bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/ButtonType.java delete mode 100644 bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/button/KeyBoardButtonAccount.java delete mode 100644 bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/button/KeyBoardButtonText.java create mode 100644 bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/button/SimpleButton.java create mode 100644 bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/simple/SimpleKeyBoard.java create mode 100644 bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/simple/SimpleKeyBoardLine.java delete mode 100644 bot-context/src/main/java/dev/struchkov/godfather/context/domain/money/Account.java delete mode 100644 bot-context/src/main/java/dev/struchkov/godfather/context/domain/money/AccountStatus.java delete mode 100644 bot-context/src/main/java/dev/struchkov/godfather/context/repository/AccountRepository.java delete mode 100644 bot-context/src/main/java/dev/struchkov/godfather/context/repository/impl/local/AccountRepositoryMap.java delete mode 100644 bot-context/src/main/java/dev/struchkov/godfather/context/service/AccountService.java delete mode 100644 bot-context/src/main/java/dev/struchkov/godfather/context/service/impl/AccountServiceImpl.java delete mode 100644 bot-core/src/main/java/dev/struchkov/godfather/core/domain/AccountAutoCheck.java delete mode 100644 bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/AnswerAccount.java delete mode 100644 bot-core/src/main/java/dev/struchkov/godfather/core/service/action/AnswerAccountAction.java diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/BoxAnswer.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/BoxAnswer.java index 3f1a683..6bcf9b3 100644 --- a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/BoxAnswer.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/BoxAnswer.java @@ -1,7 +1,6 @@ package dev.struchkov.godfather.context.domain; import dev.struchkov.godfather.context.domain.content.Message; -import dev.struchkov.godfather.context.domain.content.attachment.GeoCoordinate; import dev.struchkov.godfather.context.domain.keyboard.KeyBoard; import dev.struchkov.godfather.context.service.usercode.ProcessingData; import lombok.Builder; @@ -32,15 +31,7 @@ public class BoxAnswer { */ private KeyBoard keyBoard; - /** - * Географические координаты. - */ - private GeoCoordinate coordinates; - - /** - * Идентификатор стикера. - */ - private Integer stickerId; + private boolean replace; public static BoxAnswer of(String message) { return BoxAnswer.builder().message(message).build(); diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/ButtonColor.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/ButtonColor.java deleted file mode 100644 index 8b91c78..0000000 --- a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/ButtonColor.java +++ /dev/null @@ -1,15 +0,0 @@ -package dev.struchkov.godfather.context.domain.keyboard; - -/** - * Цвета кнопок на клавиатуре {@link KeyBoard}. - * - * @author upagge [08/07/2019] - */ -public enum ButtonColor { - - PRIMARY, - DEFAULT, - NEGATIVE, - POSITIVE - -} diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/ButtonType.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/ButtonType.java deleted file mode 100644 index 1cd0846..0000000 --- a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/ButtonType.java +++ /dev/null @@ -1,13 +0,0 @@ -package dev.struchkov.godfather.context.domain.keyboard; - -/** - * Тип кнопки на клавиатуре {@link KeyBoard}. - * - * @author upagge [08/07/2019] - */ -public enum ButtonType { - - TEXT, - ACCOUNT - -} diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/KeyBoard.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/KeyBoard.java index 6467dab..12c6413 100644 --- a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/KeyBoard.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/KeyBoard.java @@ -1,34 +1,11 @@ package dev.struchkov.godfather.context.domain.keyboard; -import lombok.Builder; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Singular; -import lombok.ToString; - -import java.util.ArrayList; import java.util.List; -/** - * Сущность клавиатуры, для создания меню с вариантами выбора. - * - * @author upagge [08/07/2019] - */ -@Builder -@Getter -@EqualsAndHashCode -@ToString -public class KeyBoard { +public interface KeyBoard { - /** - * Строки меню. - */ - @Singular(value = "lineKeyBoard") - private List keyBoardLines = new ArrayList<>(); + List getLines(); - /** - * Скрыть меню после ответа или нет. - */ - private boolean oneTime = true; + String getType(); } diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/KeyBoardButton.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/KeyBoardButton.java index 179092c..4d6e5c7 100644 --- a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/KeyBoardButton.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/KeyBoardButton.java @@ -1,30 +1,7 @@ package dev.struchkov.godfather.context.domain.keyboard; -import lombok.AccessLevel; -import lombok.AllArgsConstructor; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.ToString; +public interface KeyBoardButton { -/** - * Абстрактная сущность кнопки для клавиатуры. - * - * @author upagge [08/07/2019] - */ -@Getter -@EqualsAndHashCode -@ToString -@AllArgsConstructor(access = AccessLevel.PROTECTED) -public abstract class KeyBoardButton { - - /** - * Скрытое сообщение, отправляемое по нажатию. - */ - protected String payload; - - /** - * Тип кнопки. - */ - protected ButtonType type; + String getType(); } diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/KeyBoardLine.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/KeyBoardLine.java index a7e60eb..e5c79d5 100644 --- a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/KeyBoardLine.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/KeyBoardLine.java @@ -1,29 +1,9 @@ package dev.struchkov.godfather.context.domain.keyboard; -import lombok.Builder; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Singular; -import lombok.ToString; - -import java.util.ArrayList; import java.util.List; -/** - * Строка в меню клавиатуры {@link KeyBoard}. - * - * @author upagge [08/07/2019] - */ -@Getter -@Builder -@ToString -@EqualsAndHashCode -public class KeyBoardLine { +public interface KeyBoardLine { - /** - * Кнопки в строке. - */ - @Singular(value = "buttonKeyBoard") - private List keyBoardButtons = new ArrayList<>(); + List getButtons(); } diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/button/KeyBoardButtonAccount.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/button/KeyBoardButtonAccount.java deleted file mode 100644 index ceef5e3..0000000 --- a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/button/KeyBoardButtonAccount.java +++ /dev/null @@ -1,43 +0,0 @@ -package dev.struchkov.godfather.context.domain.keyboard.button; - -import dev.struchkov.godfather.context.domain.keyboard.ButtonType; -import dev.struchkov.godfather.context.domain.keyboard.KeyBoardButton; -import lombok.Builder; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.ToString; - -/** - * Кнопка клавиатуры для оплаты счета. - * - * @author upagge [08/07/2019] - */ -@Getter -@ToString -@EqualsAndHashCode(callSuper = true) -public class KeyBoardButtonAccount extends KeyBoardButton { - - /** - * Сумма к оплате. - */ - private Integer amount; - - /** - * Идентификатор счета. - */ - private Integer accountId; - - /** - * Описание. - */ - private String description; - - @Builder - private KeyBoardButtonAccount(String payload, Integer amount, Integer accountId, String description) { - super(payload, ButtonType.ACCOUNT); - this.amount = amount; - this.accountId = accountId; - this.description = description; - } - -} diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/button/KeyBoardButtonText.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/button/KeyBoardButtonText.java deleted file mode 100644 index 7b2cd22..0000000 --- a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/button/KeyBoardButtonText.java +++ /dev/null @@ -1,37 +0,0 @@ -package dev.struchkov.godfather.context.domain.keyboard.button; - -import dev.struchkov.godfather.context.domain.keyboard.ButtonColor; -import dev.struchkov.godfather.context.domain.keyboard.ButtonType; -import dev.struchkov.godfather.context.domain.keyboard.KeyBoardButton; -import lombok.Builder; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.ToString; - -@Getter -@ToString -@EqualsAndHashCode(callSuper = true) -public class KeyBoardButtonText extends KeyBoardButton { - - /** - * Надпись на кнопке - */ - private String label; - - /** - * Цвет кнопки. - */ - private ButtonColor color; - - @Builder - private KeyBoardButtonText(String payload, String label, ButtonColor color) { - super(payload, ButtonType.TEXT); - this.label = label; - this.color = (color != null) ? color : ButtonColor.DEFAULT; - } - - public static KeyBoardButtonText of(String label) { - return KeyBoardButtonText.builder().label(label).build(); - } - -} diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/button/SimpleButton.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/button/SimpleButton.java new file mode 100644 index 0000000..5ffd775 --- /dev/null +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/button/SimpleButton.java @@ -0,0 +1,50 @@ +package dev.struchkov.godfather.context.domain.keyboard.button; + +import dev.struchkov.godfather.context.domain.keyboard.KeyBoardButton; +import lombok.Builder; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NonNull; +import lombok.ToString; + +/** + * Абстрактная сущность кнопки для клавиатуры. + * + * @author upagge [08/07/2019] + */ +@Getter +@ToString +@EqualsAndHashCode +public class SimpleButton implements KeyBoardButton { + + public static final String TYPE = "SIMPLE"; + + /** + * Надпись на кнопке. + */ + protected String label; + /** + * Данные, которые возвращаются при нажатии. + */ + protected String callbackData; + + @Builder(builderMethodName = "simpleBuilder", buildMethodName = "simpleBuild") + protected SimpleButton(String label, String callbackData) { + this.label = label; + this.callbackData = callbackData; + } + + public static SimpleButton of(@NonNull String label, @NonNull String callbackData) { + return new SimpleButton(label, callbackData); + } + + public static SimpleButton of(@NonNull String label) { + return new SimpleButton(label, label); + } + + @Override + public String getType() { + return TYPE; + } + +} diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/simple/SimpleKeyBoard.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/simple/SimpleKeyBoard.java new file mode 100644 index 0000000..6634f18 --- /dev/null +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/simple/SimpleKeyBoard.java @@ -0,0 +1,50 @@ +package dev.struchkov.godfather.context.domain.keyboard.simple; + +import dev.struchkov.godfather.context.domain.keyboard.KeyBoard; +import dev.struchkov.godfather.context.domain.keyboard.KeyBoardButton; +import dev.struchkov.godfather.context.domain.keyboard.KeyBoardLine; +import lombok.Builder; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.Singular; +import lombok.ToString; + +import java.util.ArrayList; +import java.util.List; + +/** + * Сущность клавиатуры, для создания меню с вариантами выбора. + * + * @author upagge [08/07/2019] + */ +@Getter +@ToString +@EqualsAndHashCode +public class SimpleKeyBoard implements KeyBoard { + + public static final String TYPE = "SIMPLE"; + + /** + * Строки меню. + */ + protected List lines = new ArrayList<>(); + + @Builder(builderMethodName = "simpleBuilder", buildMethodName = "simpleBuild") + public SimpleKeyBoard(@Singular("line") List lines) { + this.lines = lines; + } + + public static SimpleKeyBoard single(KeyBoardLine line) { + return new SimpleKeyBoard(List.of(line)); + } + + public SimpleKeyBoard single(KeyBoardButton keyBoardButton) { + return single(SimpleKeyBoardLine.single(keyBoardButton)); + } + + @Override + public String getType() { + return TYPE; + } + +} diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/simple/SimpleKeyBoardLine.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/simple/SimpleKeyBoardLine.java new file mode 100644 index 0000000..07893cf --- /dev/null +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/simple/SimpleKeyBoardLine.java @@ -0,0 +1,41 @@ +package dev.struchkov.godfather.context.domain.keyboard.simple; + +import dev.struchkov.godfather.context.domain.keyboard.KeyBoardButton; +import dev.struchkov.godfather.context.domain.keyboard.KeyBoardLine; +import lombok.Builder; +import lombok.EqualsAndHashCode; +import lombok.Singular; +import lombok.ToString; + +import java.util.ArrayList; +import java.util.List; + +/** + * Строка в меню клавиатуры {@link SimpleKeyBoard}. + * + * @author upagge [08/07/2019] + */ +@ToString +@EqualsAndHashCode +public class SimpleKeyBoardLine implements KeyBoardLine { + + /** + * Кнопки в строке. + */ + protected List buttons = new ArrayList<>(); + + @Builder(builderMethodName = "simpleBuilder", buildMethodName = "simpleBuild") + public SimpleKeyBoardLine(@Singular(value = "button") List buttons) { + this.buttons = buttons; + } + + public static SimpleKeyBoardLine single(KeyBoardButton keyBoardButton) { + return new SimpleKeyBoardLine(List.of(keyBoardButton)); + } + + @Override + public List getButtons() { + return buttons; + } + +} diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/money/Account.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/money/Account.java deleted file mode 100644 index 0a7d99b..0000000 --- a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/money/Account.java +++ /dev/null @@ -1,68 +0,0 @@ -package dev.struchkov.godfather.context.domain.money; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.Table; -import javax.validation.constraints.NotNull; - -/** - * Сущность, которая отвечает за выставленный пользователю счет. - * - * @author upagge [08/07/2019] - */ -@Entity -@Builder -@Getter -@Setter -@NoArgsConstructor -@AllArgsConstructor -@Table(name = "account") -public class Account { - - @Id - @GeneratedValue - private Integer id; - - /** - * Сумма к оплате. - */ - @NotNull - @Column(name = "totalSum") - private Integer totalSum; - - /** - * Идентификатор пользователя, которому выставлен счет. - */ - @Column(name = "belongs_person_id") - private Long belongsPersonId; - - /** - * Идентификатор пользователя, который оплатил счет. - */ - @Column(name = "extinguished_person_id") - private Integer extinguishedPersonId; - - /** - * Описание платежа. - */ - @Column(name = "description") - private String description; - - /** - * Статус оплаты счета. - */ - @Enumerated(EnumType.STRING) - @Column(name = "status") - private AccountStatus accountStatus; - -} diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/money/AccountStatus.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/money/AccountStatus.java deleted file mode 100644 index 1f654f3..0000000 --- a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/money/AccountStatus.java +++ /dev/null @@ -1,15 +0,0 @@ -package dev.struchkov.godfather.context.domain.money; - -/** - * Состояние счета. - * - * @author upagge [08/07/2019] - */ -public enum AccountStatus { - - EXPOSED, - CLOSED, - CANCELLED, - EXCEPTION - -} diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/repository/AccountRepository.java b/bot-context/src/main/java/dev/struchkov/godfather/context/repository/AccountRepository.java deleted file mode 100644 index 72306c6..0000000 --- a/bot-context/src/main/java/dev/struchkov/godfather/context/repository/AccountRepository.java +++ /dev/null @@ -1,21 +0,0 @@ -package dev.struchkov.godfather.context.repository; - -import lombok.NonNull; -import dev.struchkov.godfather.context.domain.money.Account; - -import java.util.Optional; - -/** - * Репозиторий для взаимодействия с хранилищем счетов {@link Account}. - * - * @author upagge [08/07/2019] - */ -public interface AccountRepository { - - Account save(@NonNull Account account); - - Optional findById(@NonNull Integer accountId); - - boolean existsById(Integer id); - -} diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/repository/impl/local/AccountRepositoryMap.java b/bot-context/src/main/java/dev/struchkov/godfather/context/repository/impl/local/AccountRepositoryMap.java deleted file mode 100644 index 1c1c41f..0000000 --- a/bot-context/src/main/java/dev/struchkov/godfather/context/repository/impl/local/AccountRepositoryMap.java +++ /dev/null @@ -1,35 +0,0 @@ -package dev.struchkov.godfather.context.repository.impl.local; - -import dev.struchkov.godfather.context.repository.AccountRepository; -import lombok.NonNull; -import dev.struchkov.godfather.context.domain.money.Account; - -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; - -public class AccountRepositoryMap implements AccountRepository { - - private final Map saveMap = new HashMap<>(); - private int id = 1; - - @Override - public Account save(@NonNull Account account) { - if (existsById(account.getId())) { - account.setId(id); - return saveMap.put(id++, account); - } else { - return saveMap.put(id, account); - } - } - - @Override - public Optional findById(@NonNull Integer accountId) { - return Optional.ofNullable(saveMap.get(accountId)); - } - - public boolean existsById(Integer id) { - return !saveMap.containsKey(id); - } - -} diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/service/AccountService.java b/bot-context/src/main/java/dev/struchkov/godfather/context/service/AccountService.java deleted file mode 100644 index a9f5367..0000000 --- a/bot-context/src/main/java/dev/struchkov/godfather/context/service/AccountService.java +++ /dev/null @@ -1,33 +0,0 @@ -package dev.struchkov.godfather.context.service; - -import lombok.NonNull; -import dev.struchkov.godfather.context.domain.money.Account; - -/** - * Интерфейс сервиса по работе с оплатой. - * - * @author upagge [08/07/2019] - */ -public interface AccountService { - - Account add(@NonNull Account account); - - /** - * Метод для оплаты счета - * - * @param accountId Идентификатор счета - * @param extinguishedPersonId Идентификатор пользователя, который внес оплату - * @param sum Сумма оплаты - * @return true - в случае успешной оплаты - */ - boolean pay(@NonNull Integer accountId, @NonNull Integer extinguishedPersonId, @NonNull Integer sum); - - /** - * Проверка оплаты счета - * - * @param accountId Идентификатор счета - * @return true - если счет оплачен - */ - boolean paymentVerification(@NonNull Integer accountId); - -} diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/service/impl/AccountServiceImpl.java b/bot-context/src/main/java/dev/struchkov/godfather/context/service/impl/AccountServiceImpl.java deleted file mode 100644 index 2082653..0000000 --- a/bot-context/src/main/java/dev/struchkov/godfather/context/service/impl/AccountServiceImpl.java +++ /dev/null @@ -1,61 +0,0 @@ -package dev.struchkov.godfather.context.service.impl; - -import dev.struchkov.godfather.context.exception.AccessException; -import dev.struchkov.godfather.context.exception.NotFoundException; -import dev.struchkov.godfather.context.repository.AccountRepository; -import dev.struchkov.godfather.context.service.AccountService; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; -import dev.struchkov.godfather.context.domain.money.Account; -import dev.struchkov.godfather.context.domain.money.AccountStatus; -import dev.struchkov.godfather.context.exception.PaymentException; - -@RequiredArgsConstructor -public class AccountServiceImpl implements AccountService { - - private final AccountRepository accountRepository; - - @Override - public Account add(@NonNull Account account) { - if (accountRepository.existsById(account.getId())) { - account.setAccountStatus(AccountStatus.EXPOSED); - return accountRepository.save(account); - } else { - throw new AccessException("Счет " + account.getId() + " уже присутствует в базе"); - } - } - - @Override - public boolean pay(@NonNull Integer accountId, @NonNull Integer extinguishedPersonId, @NonNull Integer sum) { - Account account = accountRepository.findById(accountId) - .orElseThrow(() -> new NotFoundException("Счет " + accountId + " не найден")); - if (validStatus(account.getAccountStatus())) { - if (account.getTotalSum().equals(sum)) { - account.setAccountStatus(AccountStatus.CLOSED); - account.setExtinguishedPersonId(extinguishedPersonId); - accountRepository.save(account); - } else { - account.setAccountStatus(AccountStatus.EXCEPTION); - accountRepository.save(account); - throw new PaymentException("Неверная сумма"); - } - } else { - throw new PaymentException("Счет уже оплачен"); - } - return true; - } - - private boolean validStatus(@NonNull AccountStatus accountStatus) { - return AccountStatus.EXCEPTION.equals(accountStatus) || AccountStatus.EXPOSED.equals(accountStatus); - } - - @Override - public boolean paymentVerification(@NonNull Integer accountId) { - return AccountStatus.CLOSED.equals( - accountRepository.findById(accountId) - .orElseThrow(() -> new NotFoundException("Счет " + accountId + " не найден")) - .getAccountStatus() - ); - } - -} diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/utils/KeyBoards.java b/bot-context/src/main/java/dev/struchkov/godfather/context/utils/KeyBoards.java index f083de0..d0844fe 100644 --- a/bot-context/src/main/java/dev/struchkov/godfather/context/utils/KeyBoards.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/utils/KeyBoards.java @@ -1,21 +1,22 @@ package dev.struchkov.godfather.context.utils; -import dev.struchkov.godfather.context.domain.keyboard.ButtonColor; -import dev.struchkov.godfather.context.domain.keyboard.KeyBoard; -import dev.struchkov.godfather.context.domain.keyboard.KeyBoardButton; -import dev.struchkov.godfather.context.domain.keyboard.KeyBoardLine; -import dev.struchkov.godfather.context.domain.keyboard.button.KeyBoardButtonText; +import dev.struchkov.godfather.context.domain.keyboard.button.SimpleButton; +import dev.struchkov.godfather.context.domain.keyboard.simple.SimpleKeyBoard; +import dev.struchkov.godfather.context.domain.keyboard.simple.SimpleKeyBoardLine; import java.util.Arrays; import java.util.List; /** - * Используется для быстрого создания клавиаутр {@link KeyBoard}. + * Используется для быстрого создания клавиаутр {@link SimpleKeyBoard}. * * @author upagge [08/07/2019] */ public class KeyBoards { + public static final SimpleButton YES_BUTTON = SimpleButton.of("Да", "{\"button\": \"yes\"}"); + public static final SimpleButton NO_BUTTON = SimpleButton.of("Нет", "{\"button\": \"no\"}"); + private KeyBoards() { throw new IllegalStateException(); } @@ -23,37 +24,36 @@ public class KeyBoards { /** * Возвращает клавиатуру формата 1х2, с кнопками "Да | Нет" * - * @return {@link KeyBoard} + * @return {@link SimpleKeyBoard} */ - public static KeyBoard keyBoardYesNo() { - 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(); + public static SimpleKeyBoard keyBoardYesNo() { + return SimpleKeyBoard.simpleBuilder().line( + SimpleKeyBoardLine.simpleBuilder().button(YES_BUTTON).button(NO_BUTTON).simpleBuild() + ).simpleBuild(); } /** * Возвращает клавиатуру формата 1хN, где N - это количество элементов в переданном списке * * @param labelButtons Список названий для кнопок - * @return {@link KeyBoard} + * @return {@link SimpleKeyBoard} */ - public static KeyBoard verticalMenuString(List labelButtons) { - KeyBoard.KeyBoardBuilder keyBoard = KeyBoard.builder().oneTime(true); + public static SimpleKeyBoard verticalMenuString(List labelButtons) { + final SimpleKeyBoard.SimpleKeyBoardBuilder keyBoard = SimpleKeyBoard.simpleBuilder(); for (String labelButton : labelButtons) { - KeyBoardButton keyBoardButton = KeyBoardButtonText.builder().label(labelButton).payload("{\"button\": \"" + labelButton + "\"}").build(); - keyBoard.lineKeyBoard(KeyBoardLine.builder().buttonKeyBoard(keyBoardButton).build()); + final SimpleButton simpleButton = SimpleButton.of(labelButton, "{\"button\": \"" + labelButton + "\"}"); + keyBoard.line(SimpleKeyBoardLine.simpleBuilder().button(simpleButton).simpleBuild()); } - return keyBoard.build(); + return keyBoard.simpleBuild(); } /** * Возвращает клавиатуру формата 1хN, где N - это количество элементов в переданном списке * * @param labelButton Список названий для кнопок - * @return {@link KeyBoard} + * @return {@link SimpleKeyBoard} */ - public static KeyBoard verticalMenuString(String... labelButton) { + public static SimpleKeyBoard verticalMenuString(String... labelButton) { return verticalMenuString(Arrays.asList(labelButton)); } @@ -61,9 +61,9 @@ public class KeyBoards { * Возвращает клавиатуру формата 2х(N/2), где N - это количество элементов в переданном списке * * @param labelButton Список названий для кнопок - * @return {@link KeyBoard} + * @return {@link SimpleKeyBoard} */ - public static KeyBoard verticalDuoMenuString(String... labelButton) { + public static SimpleKeyBoard verticalDuoMenuString(String... labelButton) { return verticalDuoMenuString(Arrays.asList(labelButton)); } @@ -71,53 +71,53 @@ public class KeyBoards { * Возвращает клавиатуру формата 2х(N/2), где N - это количество элементов в переданном списке * * @param labelButton Список названий для кнопок - * @return {@link KeyBoard} + * @return {@link SimpleKeyBoard} */ - public static KeyBoard verticalDuoMenuString(List labelButton) { - KeyBoard.KeyBoardBuilder keyBoard = KeyBoard.builder().oneTime(true); + public static SimpleKeyBoard verticalDuoMenuString(List labelButton) { + final SimpleKeyBoard.SimpleKeyBoardBuilder keyBoard = SimpleKeyBoard.simpleBuilder(); boolean flag = true; - KeyBoardLine.KeyBoardLineBuilder keyBoardLine = KeyBoardLine.builder(); + SimpleKeyBoardLine.SimpleKeyBoardLineBuilder keyBoardLine = SimpleKeyBoardLine.simpleBuilder(); for (int i = 0; i <= labelButton.size() - 1; i++) { String label = labelButton.get(i); + keyBoardLine.button(SimpleButton.of(label)); if (flag) { - keyBoardLine.buttonKeyBoard(KeyBoardButtonText.of(label)); if (i == labelButton.size() - 1) { - keyBoard.lineKeyBoard(keyBoardLine.build()); + keyBoard.line(keyBoardLine.simpleBuild()); } else { flag = false; } } else { - keyBoardLine.buttonKeyBoard(KeyBoardButtonText.of(label)); - keyBoard.lineKeyBoard(keyBoardLine.build()); - keyBoardLine = KeyBoardLine.builder(); + keyBoard.line(keyBoardLine.simpleBuild()); + keyBoardLine = SimpleKeyBoardLine.simpleBuilder(); flag = true; } } - return keyBoard.build(); + return keyBoard.simpleBuild(); } /** * Возвращает клавиатуру формата 1xN сформированную из списка кнопок, где N - количество кнопок в списке * - * @param keyBoardButtons Список кнопок - * @return {@link KeyBoard} + * @param simpleButtons Список кнопок + * @return {@link SimpleKeyBoard} */ - public static KeyBoard verticalMenuButton(List keyBoardButtons) { - KeyBoard.KeyBoardBuilder keyBoard = KeyBoard.builder().oneTime(true); - for (KeyBoardButton keyBoardButton : keyBoardButtons) { - keyBoard.lineKeyBoard(KeyBoardLine.builder().buttonKeyBoard(keyBoardButton).build()); + public static SimpleKeyBoard verticalMenuButton(List simpleButtons) { + final SimpleKeyBoard.SimpleKeyBoardBuilder keyBoard = SimpleKeyBoard.simpleBuilder(); + for (SimpleButton simpleButton : simpleButtons) { + keyBoard.line(SimpleKeyBoardLine.simpleBuilder().button(simpleButton).simpleBuild()); } - return keyBoard.build(); + return keyBoard.simpleBuild(); } /** * Возвращает клавиатуру из одной кнопки * - * @param keyBoardButton Кнопка - * @return {@link KeyBoard} + * @param simpleButton Кнопка + * @return {@link SimpleKeyBoard} */ - public static KeyBoard singelton(KeyBoardButton keyBoardButton) { - KeyBoardLine line = KeyBoardLine.builder().buttonKeyBoard(keyBoardButton).build(); - return KeyBoard.builder().lineKeyBoard(line).build(); + public static SimpleKeyBoard singleton(SimpleButton simpleButton) { + final SimpleKeyBoardLine line = SimpleKeyBoardLine.simpleBuilder().button(simpleButton).simpleBuild(); + return SimpleKeyBoard.simpleBuilder().line(line).simpleBuild(); } + } diff --git a/bot-core/pom.xml b/bot-core/pom.xml index 60a8d57..15d83d7 100644 --- a/bot-core/pom.xml +++ b/bot-core/pom.xml @@ -6,7 +6,7 @@ dev.struchkov.godfather godfather-bot - 0.0.3 + 0.0.4-SNAPSHOT bot-core diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/GeneralAutoResponder.java b/bot-core/src/main/java/dev/struchkov/godfather/core/GeneralAutoResponder.java index d629839..f566cdc 100644 --- a/bot-core/src/main/java/dev/struchkov/godfather/core/GeneralAutoResponder.java +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/GeneralAutoResponder.java @@ -3,14 +3,12 @@ package dev.struchkov.godfather.core; import dev.struchkov.godfather.context.domain.content.Message; import dev.struchkov.godfather.context.exception.ConfigAppException; import dev.struchkov.godfather.context.exception.NotFoundException; -import dev.struchkov.godfather.context.service.AccountService; import dev.struchkov.godfather.context.service.MessageService; import dev.struchkov.godfather.context.service.Modifiable; import dev.struchkov.godfather.context.service.sender.Sending; import dev.struchkov.godfather.core.domain.unit.MainUnit; import dev.struchkov.godfather.core.domain.unit.UnitActiveType; import dev.struchkov.godfather.core.service.action.ActionUnit; -import dev.struchkov.godfather.core.service.action.AnswerAccountAction; import dev.struchkov.godfather.core.service.action.AnswerCheckAction; import dev.struchkov.godfather.core.service.action.AnswerProcessingAction; import dev.struchkov.godfather.core.service.action.AnswerSaveAction; @@ -83,10 +81,6 @@ public class GeneralAutoResponder extends TimerTask { actionUnitMap.put(TypeUnit.TIMER, new AnswerTimerAction(timerService, this)); } - public void initAccountAction(AccountService accountService, TimerService timerService) { - actionUnitMap.put(TypeUnit.ACCOUNT, new AnswerAccountAction(accountService, timerService)); - } - public void setDefaultUnit(MainUnit mainUnit) { autoResponder.setDefaultUnit(mainUnit); } diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/domain/AccountAutoCheck.java b/bot-core/src/main/java/dev/struchkov/godfather/core/domain/AccountAutoCheck.java deleted file mode 100644 index db141f5..0000000 --- a/bot-core/src/main/java/dev/struchkov/godfather/core/domain/AccountAutoCheck.java +++ /dev/null @@ -1,40 +0,0 @@ -package dev.struchkov.godfather.core.domain; - -import dev.struchkov.godfather.context.domain.money.Account; -import dev.struchkov.godfather.core.domain.unit.MainUnit; -import lombok.Builder; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.ToString; - -/** - * Объект, для автоматической проверки оплаты счета {@link Account}. - * - * @author upagge [11/07/2019] - */ -@Getter -@Builder -@ToString -@EqualsAndHashCode -public class AccountAutoCheck { - - /** - * Unut, который обрабатывается при успешной оплате. - */ - private MainUnit successfulPayment; - - /** - * Unit, который обрабатывается при не успешной оплате. - */ - private MainUnit failedPayment; - - /** - * Период проверки. - */ - private Integer periodSec; - - /** - * Время жизни счета. - */ - private Integer lifeTimeHours; -} diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/AnswerAccount.java b/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/AnswerAccount.java deleted file mode 100644 index 83162e4..0000000 --- a/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/AnswerAccount.java +++ /dev/null @@ -1,65 +0,0 @@ -package dev.struchkov.godfather.core.domain.unit; - -import dev.struchkov.godfather.core.domain.AccountAutoCheck; -import dev.struchkov.godfather.core.utils.TypeUnit; -import lombok.Builder; -import lombok.EqualsAndHashCode; -import lombok.Getter; -import lombok.Singular; - -import java.util.Set; -import java.util.regex.Pattern; - -/** - * Юнит для обработки платежей. - * - * @author upagge [08/07/2019] - */ -@Getter -@EqualsAndHashCode(callSuper = true) -public class AnswerAccount extends MainUnit { - - /** - * Сумма к оплате. - */ - private final Integer totalSum; - - /** - * Время жизни счета. - */ - private final Integer timeHours; - - /** - * Настройки для автоматической проверки оплаты. - */ - private final AccountAutoCheck autoCheck; - - @Builder - private AnswerAccount( - @Singular Set keyWords, - String phrase, - Pattern pattern, - Integer matchThreshold, - Integer priority, - @Singular Set nextUnits, - UnitActiveType activeType, - Integer totalSum, - Integer timeHours, - AccountAutoCheck autoCheck - ) { - super( - keyWords, - phrase, - pattern, - matchThreshold, - priority, - nextUnits, - (activeType == null) ? UnitActiveType.AFTER : activeType, - TypeUnit.ACCOUNT - ); - this.totalSum = totalSum; - this.timeHours = timeHours; - this.autoCheck = autoCheck; - } - -} diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/service/action/AnswerAccountAction.java b/bot-core/src/main/java/dev/struchkov/godfather/core/service/action/AnswerAccountAction.java deleted file mode 100644 index 19bccc2..0000000 --- a/bot-core/src/main/java/dev/struchkov/godfather/core/service/action/AnswerAccountAction.java +++ /dev/null @@ -1,81 +0,0 @@ -package dev.struchkov.godfather.core.service.action; - -import dev.struchkov.godfather.context.domain.BoxAnswer; -import dev.struchkov.godfather.context.domain.content.Mail; -import dev.struchkov.godfather.context.domain.keyboard.button.KeyBoardButtonAccount; -import dev.struchkov.godfather.context.domain.money.Account; -import dev.struchkov.godfather.context.service.AccountService; -import dev.struchkov.godfather.context.utils.KeyBoards; -import dev.struchkov.godfather.core.domain.AccountAutoCheck; -import dev.struchkov.godfather.core.domain.Timer; -import dev.struchkov.godfather.core.domain.unit.AnswerAccount; -import dev.struchkov.godfather.core.domain.unit.AnswerText; -import dev.struchkov.godfather.core.domain.unit.MainUnit; -import dev.struchkov.godfather.core.service.timer.TimerService; - -import java.time.Clock; -import java.time.LocalDateTime; -import java.time.ZoneId; - -/** - * Обработчик Unit-а {@link AnswerAccount}. - * - * @author upagge [11/07/2019] - */ -public class AnswerAccountAction implements ActionUnit { - - private final AccountService accountService; - private TimerService timerService; - - public AnswerAccountAction(AccountService accountService, TimerService timerService) { - this.accountService = accountService; - this.timerService = timerService; - } - - public AnswerAccountAction(AccountService accountService) { - this.accountService = accountService; - } - - @Override - public MainUnit action(AnswerAccount answerAccount, Mail mail) { - final Account account = new Account(); - account.setBelongsPersonId(mail.getPersonId()); - account.setTotalSum(answerAccount.getTotalSum()); - - final Integer accountId = accountService.add(account).getId(); - - settingCheckTimer(answerAccount, mail, accountId); - - KeyBoardButtonAccount buttonAccount = KeyBoardButtonAccount.builder() - .accountId(accountId) - .amount(answerAccount.getTotalSum()).build(); - - BoxAnswer boxAnswer = BoxAnswer.builder() - .message("Для оплаты укажите номер счета " + accountId + "\nСумма к оплате: " - + answerAccount.getTotalSum()) - .keyBoard(KeyBoards.singelton(buttonAccount)) - .build(); - - return AnswerText.builder().boxAnswer(message -> boxAnswer).build(); - } - - private void settingCheckTimer(AnswerAccount answerAccount, Mail mail, Integer accountId) { - AccountAutoCheck autoCheck = answerAccount.getAutoCheck(); - if (autoCheck != null && timerService != null) { - Timer timer = Timer.builder() - .personId(mail.getPersonId()) - .unitAnswer(autoCheck.getSuccessfulPayment()) - .unitDeath(autoCheck.getFailedPayment()) - .checkLoop(content1 -> accountService.paymentVerification(accountId)) - .periodSec(autoCheck.getPeriodSec()) - .timeActive(LocalDateTime - .now(Clock.tickSeconds(ZoneId.systemDefault())) - .plusSeconds(autoCheck.getPeriodSec())) - .timeDeath(LocalDateTime - .now(Clock.tickSeconds(ZoneId.systemDefault())) - .plusHours(autoCheck.getLifeTimeHours())) - .build(); - timerService.add(timer); - } - } -} diff --git a/pom.xml b/pom.xml index e55da47..7eb8e5f 100644 --- a/pom.xml +++ b/pom.xml @@ -118,6 +118,13 @@ ${java.version} ${java.version} + + + org.projectlombok + lombok + ${lombok.ver} + +