From eed10a1eecde33dce7979299144a51ece8e19f05 Mon Sep 17 00:00:00 2001 From: AKurakin Date: Mon, 3 Jun 2024 17:39:20 +0300 Subject: [PATCH] =?UTF-8?q?account-service=20=D1=80=D0=B0=D0=B7=D1=80?= =?UTF-8?q?=D0=B5=D1=88=D0=B8=D0=BB=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20TCR.DepoAccountId=20=D1=81=20null?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...adingClearingRegistryValidationConfig.java | 57 ++++++++++++++++--- .../TradingClearingRegistryService.java | 10 ++-- 2 files changed, 55 insertions(+), 12 deletions(-) diff --git a/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/config/validation/TradingClearingRegistryValidationConfig.java b/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/config/validation/TradingClearingRegistryValidationConfig.java index 2a9d7a877..fe1e099db 100644 --- a/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/config/validation/TradingClearingRegistryValidationConfig.java +++ b/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/config/validation/TradingClearingRegistryValidationConfig.java @@ -31,6 +31,7 @@ import ru.spcex.platform.utils.validation.ValidatorImpl; import java.util.Collection; import java.util.Map; +import java.util.Objects; import java.util.Optional; import java.util.function.Consumer; import java.util.function.Function; @@ -140,11 +141,6 @@ public class TradingClearingRegistryValidationConfig { if (validatedObject.getMoneyAccountId() == null) { return of(AccountError.RequiredFieldEmpty, "MoneyAccountId"); } - //Map> query = new HashMap<>(); -// query.put("moneyAccountId", validatedObject.getMoneyAccountId()); -// if (validatedObject.getDepoAccountId() != null) { -// query.put("depoAccountId", validatedObject.getDepoAccountId()); -// } ImdgPredicateBuilder pb = tcrMap.predicateBuilder(); ImdgPredicate query = pb.equals("moneyAccountId", validatedObject.getMoneyAccountId()); if (validatedObject.getDepoAccountId() != null) { @@ -160,8 +156,49 @@ public class TradingClearingRegistryValidationConfig { Account account = accountImdg.getSingleObjectByID(validatedObject.getMoneyAccountId()); if (account == null && validatedObject.getDepoAccountId() != null) account = accountImdg.getSingleObjectByID(validatedObject.getDepoAccountId()); return of(AccountError.AccountForTradingClearingRegistryAlreadyUsed, account.getAccount()); -// String tcrIds = existTCR.stream().map(tcr -> String.valueOf(tcr.getId())).collect(Collectors.joining(";")); -// return of(AccountError.AccountForTradingClearingRegistryAlreadyUsed, tcrIds); + } + } + } + + static class updateTCRDepoCheck implements IValidationRule> { + @Override + public Optional validate(ImdgValidationContext context) { + TradingClearingRegistryUpdateRequest validatedObject = context.getValidatedObject(); + Long depoAccountId = validatedObject.getDepoAccountId(); + if (depoAccountId == null) // необязательное поле + return empty(); + + // Проверка типа счёта ДЕПО, что существует + Imdg depoAccountImdg = context.obtainMap(IMDGDistributedNames.Map_DepoAccount, DepoAccount.class); + DepoAccount depoAccount = depoAccountImdg.getFirstObjectByFieldValues( + Map.of("accountId", depoAccountId) + ); + if (depoAccount == null) + return of(AccountError.AccountNotFound, depoAccountId); + + // Проверка компании ТКР и счёта + Imdg tcrMap = context.obtainMap(IMDGDistributedNames.Map_TradingClearingRegistry, TradingClearingRegistry.class); + Imdg accountImdg = context.obtainMap(IMDGDistributedNames.Map_Account, Account.class); + Account account = accountImdg.getSingleObjectByID(validatedObject.getMoneyAccountId()); + if (account == null) { // never + return of(AccountError.AccountNotFound, depoAccountId); + } + TradingClearingRegistry updateObject = tcrMap.getSingleObjectByID(validatedObject.getId()); + if (!Objects.equals(account.getCompanyId(), updateObject.getCompanyId())) { + return of(AccountError.AccountNotFound, depoAccountId); // или UserVerifyDenial + } + + // Проверка использования счёта в других ТКР + ImdgPredicateBuilder pb = tcrMap.predicateBuilder(); + ImdgPredicate query = pb.and(pb.equals("depoAccountId", validatedObject.getDepoAccountId()), + pb.not(pb.equals("id", validatedObject.getId())) + ); + Collection existTCR = tcrMap.getCollectionObjectsByPredicate(query); + if (existTCR.isEmpty()) { + return empty(); + } else { + if (account == null && validatedObject.getDepoAccountId() != null) account = accountImdg.getSingleObjectByID(validatedObject.getDepoAccountId()); + return of(AccountError.AccountForTradingClearingRegistryAlreadyUsed, account.getAccount()); } } } @@ -177,6 +214,8 @@ public class TradingClearingRegistryValidationConfig { Consumer addImdg = (s) -> context.addImdg(s, imdgForValidation.get(s)); addImdg.accept(IMDGDistributedNames.Map_ServiceStatusDictionary); addImdg.accept(IMDGDistributedNames.Map_TradingClearingRegistry); + addImdg.accept(IMDGDistributedNames.Map_Account); + addImdg.accept(IMDGDistributedNames.Map_DepoAccount); return new ValidatorImpl<>(context, IdPresentRule.instance("id", TradingClearingRegistryUpdateRequest::getId, @@ -190,7 +229,9 @@ public class TradingClearingRegistryValidationConfig { ServiceStatusDictionary.class, AccountError.RequiredFieldEmpty, AccountError.DictionaryNotFound, - false) + false), + + new updateTCRDepoCheck() ); }; } diff --git a/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/service/TradingClearingRegistryService.java b/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/service/TradingClearingRegistryService.java index c35ff2848..f89374ba9 100644 --- a/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/service/TradingClearingRegistryService.java +++ b/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/service/TradingClearingRegistryService.java @@ -459,17 +459,19 @@ public class TradingClearingRegistryService extends QueueConsumer implements Ini if (req.getMoneyAccountId() != null && !req.getMoneyAccountId().equals(tradingClearingRegistry.getMoneyAccountId())) { return requestHelper.makeErrorResponse(userRequest, AccountError.WrongFieldValue, "MoneyAccountId", req.getMoneyAccountId()); } - if (req.getDepoAccountId() != null && !req.getDepoAccountId().equals(tradingClearingRegistry.getDepoAccountId())) { + if (tradingClearingRegistry.getDepoAccountId() != null && // но можно с null заменить + req.getDepoAccountId() != null && !req.getDepoAccountId().equals(tradingClearingRegistry.getDepoAccountId())) { return requestHelper.makeErrorResponse(userRequest, AccountError.WrongFieldValue, "DepoAccountId", req.getDepoAccountId()); } // tradingClearingRegistry.setMoneyAccountId(req.getMoneyAccountId()); -// tradingClearingRegistry.setDepoAccountId(req.getDepoAccountId()); - - if (req.getStatus() != null && !Objects.equals(req.getStatus(), tradingClearingRegistry.getStatus())) { + if (req.getStatus() != null && !Objects.equals(req.getStatus(), tradingClearingRegistry.getStatus()) + || req.getDepoAccountId() != null && !req.getDepoAccountId().equals(tradingClearingRegistry.getDepoAccountId()) + ) { Instant now = Instant.now(); tradingClearingRegistry.setUpdated(now); tradingClearingRegistry.setStatus(req.getStatus()); + tradingClearingRegistry.setDepoAccountId(req.getDepoAccountId()); tradingClearingRegistryImdg.update(tradingClearingRegistry); Optional tkr = createRequestToGateway(tradingClearingRegistry); if (tkr.isPresent()) {