Удалил юнит отвечающий за оплату и все что с ним связано, так же обновил архитектуру клавиатур
This commit is contained in:
parent
b3fdcbbccb
commit
4d5f3ad542
@ -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();
|
||||
|
@ -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
|
||||
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
package dev.struchkov.godfather.context.domain.keyboard;
|
||||
|
||||
/**
|
||||
* Тип кнопки на клавиатуре {@link KeyBoard}.
|
||||
*
|
||||
* @author upagge [08/07/2019]
|
||||
*/
|
||||
public enum ButtonType {
|
||||
|
||||
TEXT,
|
||||
ACCOUNT
|
||||
|
||||
}
|
@ -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<KeyBoardLine> keyBoardLines = new ArrayList<>();
|
||||
List<KeyBoardLine> getLines();
|
||||
|
||||
/**
|
||||
* Скрыть меню после ответа или нет.
|
||||
*/
|
||||
private boolean oneTime = true;
|
||||
String getType();
|
||||
|
||||
}
|
||||
|
@ -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();
|
||||
|
||||
}
|
||||
|
@ -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<KeyBoardButton> keyBoardButtons = new ArrayList<>();
|
||||
List<? extends KeyBoardButton> getButtons();
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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<KeyBoardLine> lines = new ArrayList<>();
|
||||
|
||||
@Builder(builderMethodName = "simpleBuilder", buildMethodName = "simpleBuild")
|
||||
public SimpleKeyBoard(@Singular("line") List<KeyBoardLine> 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;
|
||||
}
|
||||
|
||||
}
|
@ -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<KeyBoardButton> buttons = new ArrayList<>();
|
||||
|
||||
@Builder(builderMethodName = "simpleBuilder", buildMethodName = "simpleBuild")
|
||||
public SimpleKeyBoardLine(@Singular(value = "button") List<KeyBoardButton> buttons) {
|
||||
this.buttons = buttons;
|
||||
}
|
||||
|
||||
public static SimpleKeyBoardLine single(KeyBoardButton keyBoardButton) {
|
||||
return new SimpleKeyBoardLine(List.of(keyBoardButton));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<KeyBoardButton> getButtons() {
|
||||
return buttons;
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
package dev.struchkov.godfather.context.domain.money;
|
||||
|
||||
/**
|
||||
* Состояние счета.
|
||||
*
|
||||
* @author upagge [08/07/2019]
|
||||
*/
|
||||
public enum AccountStatus {
|
||||
|
||||
EXPOSED,
|
||||
CLOSED,
|
||||
CANCELLED,
|
||||
EXCEPTION
|
||||
|
||||
}
|
@ -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<Account> findById(@NonNull Integer accountId);
|
||||
|
||||
boolean existsById(Integer id);
|
||||
|
||||
}
|
@ -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<Integer, Account> 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<Account> findById(@NonNull Integer accountId) {
|
||||
return Optional.ofNullable(saveMap.get(accountId));
|
||||
}
|
||||
|
||||
public boolean existsById(Integer id) {
|
||||
return !saveMap.containsKey(id);
|
||||
}
|
||||
|
||||
}
|
@ -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);
|
||||
|
||||
}
|
@ -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()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -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<String> labelButtons) {
|
||||
KeyBoard.KeyBoardBuilder keyBoard = KeyBoard.builder().oneTime(true);
|
||||
public static SimpleKeyBoard verticalMenuString(List<String> 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<String> labelButton) {
|
||||
KeyBoard.KeyBoardBuilder keyBoard = KeyBoard.builder().oneTime(true);
|
||||
public static SimpleKeyBoard verticalDuoMenuString(List<String> 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<KeyBoardButton> keyBoardButtons) {
|
||||
KeyBoard.KeyBoardBuilder keyBoard = KeyBoard.builder().oneTime(true);
|
||||
for (KeyBoardButton keyBoardButton : keyBoardButtons) {
|
||||
keyBoard.lineKeyBoard(KeyBoardLine.builder().buttonKeyBoard(keyBoardButton).build());
|
||||
public static SimpleKeyBoard verticalMenuButton(List<SimpleButton> 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();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>dev.struchkov.godfather</groupId>
|
||||
<artifactId>godfather-bot</artifactId>
|
||||
<version>0.0.3</version>
|
||||
<version>0.0.4-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>bot-core</artifactId>
|
||||
|
@ -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<T extends Message> 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);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
@ -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<String> keyWords,
|
||||
String phrase,
|
||||
Pattern pattern,
|
||||
Integer matchThreshold,
|
||||
Integer priority,
|
||||
@Singular Set<MainUnit> 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;
|
||||
}
|
||||
|
||||
}
|
@ -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<AnswerAccount, Mail> {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
7
pom.xml
7
pom.xml
@ -118,6 +118,13 @@
|
||||
<configuration>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
<annotationProcessorPaths>
|
||||
<path>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.ver}</version>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
Loading…
Reference in New Issue
Block a user