Добавлена оплата
Рефакторинг
This commit is contained in:
parent
0dfddc7f2d
commit
fd8c8402d1
78
src/main/java/org/sadtech/bot/core/domain/money/Account.java
Normal file
78
src/main/java/org/sadtech/bot/core/domain/money/Account.java
Normal file
@ -0,0 +1,78 @@
|
||||
package org.sadtech.bot.core.domain.money;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class Account {
|
||||
|
||||
private Integer id;
|
||||
private Double totalSum;
|
||||
private Integer belongsPersonId;
|
||||
private Integer extinguishedPersonId;
|
||||
private String description;
|
||||
private AccountStatus accountStatus;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Double getTotalSum() {
|
||||
return totalSum;
|
||||
}
|
||||
|
||||
public void setTotalSum(Double totalSum) {
|
||||
this.totalSum = totalSum;
|
||||
}
|
||||
|
||||
public Integer getBelongsPersonId() {
|
||||
return belongsPersonId;
|
||||
}
|
||||
|
||||
public void setBelongsPersonId(Integer belongsPersonId) {
|
||||
this.belongsPersonId = belongsPersonId;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public AccountStatus getAccountStatus() {
|
||||
return accountStatus;
|
||||
}
|
||||
|
||||
public void setAccountStatus(AccountStatus accountStatus) {
|
||||
this.accountStatus = accountStatus;
|
||||
}
|
||||
|
||||
public Integer getExtinguishedPersonId() {
|
||||
return extinguishedPersonId;
|
||||
}
|
||||
|
||||
public void setExtinguishedPersonId(Integer extinguishedPersonId) {
|
||||
this.extinguishedPersonId = extinguishedPersonId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof Account)) return false;
|
||||
Account account = (Account) o;
|
||||
return Objects.equals(id, account.id) &&
|
||||
Objects.equals(totalSum, account.totalSum) &&
|
||||
Objects.equals(belongsPersonId, account.belongsPersonId) &&
|
||||
Objects.equals(description, account.description) &&
|
||||
accountStatus == account.accountStatus;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id, totalSum, belongsPersonId, description, accountStatus);
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package org.sadtech.bot.core.domain.money;
|
||||
|
||||
public enum AccountStatus {
|
||||
|
||||
EXPOSED, CLOSED, CANCELLED, EXCEPTION;
|
||||
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package org.sadtech.bot.core.exception;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
public class AppBotException extends RuntimeException {
|
||||
|
||||
private final String type = "ERROR";
|
||||
private final LocalDateTime timeError = LocalDateTime.now();
|
||||
protected Integer code;
|
||||
protected String description;
|
||||
|
||||
public AppBotException(String message, Integer code) {
|
||||
super(message);
|
||||
this.description = message;
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public AppBotException(Integer code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public LocalDateTime getTimeError() {
|
||||
return timeError;
|
||||
}
|
||||
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
}
|
@ -1,5 +1,10 @@
|
||||
package org.sadtech.bot.core.exception;
|
||||
|
||||
public class MailSendException extends RuntimeException {
|
||||
public class MailSendException extends AppBotException {
|
||||
|
||||
public final static Integer CODE = 1;
|
||||
|
||||
public MailSendException() {
|
||||
super(CODE);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,13 @@
|
||||
package org.sadtech.bot.core.exception;
|
||||
|
||||
public class PaymentException extends AppBotException {
|
||||
|
||||
public PaymentException(String message, Integer code) {
|
||||
super(message, code);
|
||||
}
|
||||
|
||||
public PaymentException(Integer code) {
|
||||
super(code);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package org.sadtech.bot.core.repository;
|
||||
|
||||
import org.sadtech.bot.core.domain.money.Account;
|
||||
|
||||
public interface AccountRepository {
|
||||
|
||||
Integer add(Account account);
|
||||
|
||||
void edit(Integer accountId, Account account);
|
||||
|
||||
Account findById(Integer accountId);
|
||||
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package org.sadtech.bot.core.repository.impl;
|
||||
|
||||
import org.sadtech.bot.core.domain.money.Account;
|
||||
import org.sadtech.bot.core.repository.AccountRepository;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class AccountRepositoryImpl implements AccountRepository {
|
||||
|
||||
private final Map<Integer, Account> saveMap = new HashMap<>();
|
||||
private Integer id = 0;
|
||||
|
||||
@Override
|
||||
public Integer add(Account account) {
|
||||
account.setId(id);
|
||||
saveMap.put(id, account);
|
||||
return id++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void edit(Integer accountId, Account account) {
|
||||
account.setId(accountId);
|
||||
saveMap.put(accountId, account);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Account findById(Integer accountId) {
|
||||
return saveMap.get(accountId);
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
package org.sadtech.bot.core.repository.impl;
|
||||
|
||||
import org.sadtech.bot.core.domain.Mail;
|
||||
import org.sadtech.bot.core.repository.EventRepository;
|
||||
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
public class TerminalComandRepositoryQueue implements EventRepository<Mail> {
|
||||
|
||||
private final Queue<Mail> mailQueue = new ConcurrentLinkedQueue<>();
|
||||
|
||||
@Override
|
||||
public void add(Mail dataObject) {
|
||||
mailQueue.offer(dataObject);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanAll() {
|
||||
mailQueue.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Queue<Mail> getEventQueue() {
|
||||
return mailQueue;
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package org.sadtech.bot.core.service;
|
||||
|
||||
import org.sadtech.bot.core.domain.money.Account;
|
||||
|
||||
public interface AccountService {
|
||||
|
||||
Integer add(Account account);
|
||||
|
||||
Boolean pay(Integer accountId, Integer extinguishedPersonId, Double sum);
|
||||
|
||||
Boolean paymentVerification(Integer accountId);
|
||||
|
||||
}
|
@ -8,7 +8,7 @@ public interface PersonService {
|
||||
|
||||
Person get(Integer id);
|
||||
|
||||
boolean checkPerson(Integer idPerson);
|
||||
boolean checkPerson(Integer personId);
|
||||
|
||||
Person createPerson(Integer userId);
|
||||
|
||||
|
@ -0,0 +1,42 @@
|
||||
package org.sadtech.bot.core.service.impl;
|
||||
|
||||
import org.sadtech.bot.core.domain.money.Account;
|
||||
import org.sadtech.bot.core.domain.money.AccountStatus;
|
||||
import org.sadtech.bot.core.exception.PaymentException;
|
||||
import org.sadtech.bot.core.repository.AccountRepository;
|
||||
import org.sadtech.bot.core.service.AccountService;
|
||||
|
||||
public class AccountServiceImpl implements AccountService {
|
||||
|
||||
private final AccountRepository accountRepository;
|
||||
|
||||
public AccountServiceImpl(AccountRepository accountRepository) {
|
||||
this.accountRepository = accountRepository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer add(Account account) {
|
||||
account.setAccountStatus(AccountStatus.EXPOSED);
|
||||
return accountRepository.add(account);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean pay(Integer accountId, Integer extinguishedPersonId, Double sum) {
|
||||
Account account = accountRepository.findById(accountId);
|
||||
if (account.getTotalSum().equals(sum)) {
|
||||
account.setAccountStatus(AccountStatus.CLOSED);
|
||||
account.setExtinguishedPersonId(extinguishedPersonId);
|
||||
accountRepository.edit(accountId, account);
|
||||
} else {
|
||||
account.setAccountStatus(AccountStatus.EXCEPTION);
|
||||
accountRepository.edit(accountId, account);
|
||||
throw new PaymentException("Неверная сумма", 2);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean paymentVerification(Integer accountId) {
|
||||
return AccountStatus.CLOSED.equals(accountRepository.findById(accountId).getAccountStatus());
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package org.sadtech.bot.core.sender;
|
||||
package org.sadtech.bot.core.service.sender;
|
||||
|
||||
import org.sadtech.bot.core.domain.BoxAnswer;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package org.sadtech.bot.core.sender.email;
|
||||
package org.sadtech.bot.core.service.sender.email;
|
||||
|
||||
import java.util.Properties;
|
||||
|
@ -1,8 +1,8 @@
|
||||
package org.sadtech.bot.core.sender.email;
|
||||
package org.sadtech.bot.core.service.sender.email;
|
||||
|
||||
import org.sadtech.bot.core.domain.BoxAnswer;
|
||||
import org.sadtech.bot.core.exception.MailSendException;
|
||||
import org.sadtech.bot.core.sender.Sent;
|
||||
import org.sadtech.bot.core.service.sender.Sent;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -1,4 +1,4 @@
|
||||
package org.sadtech.bot.core.insert;
|
||||
package org.sadtech.bot.core.utils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
@ -1,4 +1,4 @@
|
||||
package org.sadtech.bot.core.service;
|
||||
package org.sadtech.bot.core.utils;
|
||||
|
||||
import org.sadtech.bot.core.domain.keyboard.ButtonColor;
|
||||
import org.sadtech.bot.core.domain.keyboard.KeyBoard;
|
Loading…
Reference in New Issue
Block a user