From 3184e46d1bcbf07481e92e427e07ba9f4bbb7b13 Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Mon, 27 May 2019 09:57:51 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE?= =?UTF-8?q?=D1=80=D0=B8=D0=BD=D0=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/content/attachment/Attachment.java | 2 +- .../core/service/impl/AccountServiceImpl.java | 22 +++++++++++++------ .../service/impl/RawEventServiceImpl.java | 4 ++-- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/main/java/org/sadtech/bot/core/domain/content/attachment/Attachment.java b/src/main/java/org/sadtech/bot/core/domain/content/attachment/Attachment.java index fef3973..12698de 100644 --- a/src/main/java/org/sadtech/bot/core/domain/content/attachment/Attachment.java +++ b/src/main/java/org/sadtech/bot/core/domain/content/attachment/Attachment.java @@ -2,7 +2,7 @@ package org.sadtech.bot.core.domain.content.attachment; public abstract class Attachment { - AttachmentType type; + protected AttachmentType type; public AttachmentType getType() { return type; diff --git a/src/main/java/org/sadtech/bot/core/service/impl/AccountServiceImpl.java b/src/main/java/org/sadtech/bot/core/service/impl/AccountServiceImpl.java index 2a370e4..e13d53c 100644 --- a/src/main/java/org/sadtech/bot/core/service/impl/AccountServiceImpl.java +++ b/src/main/java/org/sadtech/bot/core/service/impl/AccountServiceImpl.java @@ -23,18 +23,26 @@ public class AccountServiceImpl implements AccountService { @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); + if (validStatus(account.getAccountStatus())) { + 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, "Неверная сумма"); + } } else { - account.setAccountStatus(AccountStatus.EXCEPTION); - accountRepository.edit(accountId, account); - throw new PaymentException(2, "Неверная сумма"); + throw new PaymentException(3, "Счет уже оплачен"); } return true; } + private boolean validStatus(AccountStatus accountStatus) { + return AccountStatus.EXCEPTION.equals(accountStatus) || AccountStatus.EXPOSED.equals(accountStatus); + } + @Override public Boolean paymentVerification(Integer accountId) { return AccountStatus.CLOSED.equals(accountRepository.findById(accountId).getAccountStatus()); diff --git a/src/main/java/org/sadtech/bot/core/service/impl/RawEventServiceImpl.java b/src/main/java/org/sadtech/bot/core/service/impl/RawEventServiceImpl.java index a61880c..16b7ad7 100644 --- a/src/main/java/org/sadtech/bot/core/service/impl/RawEventServiceImpl.java +++ b/src/main/java/org/sadtech/bot/core/service/impl/RawEventServiceImpl.java @@ -12,9 +12,9 @@ public class RawEventServiceImpl implements RawEventService { private static final Logger log = LoggerFactory.getLogger(RawEventServiceImpl.class); - private final EventRepository eventRepository; + private final EventRepository eventRepository; - public RawEventServiceImpl(EventRepository eventRepository) { + public RawEventServiceImpl(EventRepository eventRepository) { this.eventRepository = eventRepository; }