This commit is contained in:
parent
5d2e4610f3
commit
4b44df76ca
9 changed files with 367 additions and 15 deletions
|
|
@ -182,4 +182,27 @@ public class ClientCodeValidationConfig {
|
|||
};
|
||||
}
|
||||
|
||||
@Bean("tkrEksAccountsGatewayValidator")
|
||||
public Function<TkrAccount, IValidator> newTkrEksAccountsGatewayValidator(Map<String, Imdg<? extends SpcexObjectBase>> imdgForValidation) {
|
||||
return tkrGatewayRequest -> {
|
||||
ImdgValidationContext<TkrAccount> context = new ImdgValidationContext<>();
|
||||
context.setValidatedObject(tkrGatewayRequest);
|
||||
Consumer<String> addImdg = (s) -> context.addImdg(s, imdgForValidation.get(s));
|
||||
addImdg.accept(IMDGDistributedNames.Map_Company);
|
||||
addImdg.accept(IMDGDistributedNames.Map_CompanySymbols);
|
||||
addImdg.accept(IMDGDistributedNames.Map_Account);
|
||||
addImdg.accept(IMDGDistributedNames.Map_TradingClearingRegistry);
|
||||
addImdg.accept(IMDGDistributedNames.Map_AccountSymbols);
|
||||
addImdg.accept(IMDGDistributedNames.Map_DepoAccount);
|
||||
return new ValidatorImpl<>(context,
|
||||
FieldRequiredRule.instance("client_code", TkrAccount::getClientCode, AccountError.RequiredFieldEmpty),
|
||||
GatewayClientCodeValidationRule.CompanyPresent,
|
||||
// GatewayClientCodeValidationRule.AllAccountsPresent,
|
||||
GatewayClientCodeValidationRule.DepoAccountsPresent
|
||||
// GatewayClientCodeValidationRule.TcrIsNotPresent,
|
||||
// GatewayClientCodeValidationRule.TcrListIsNotPresent
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,125 @@
|
|||
package ru.spcex.clearing.account.service.v2.facade;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.clearing.classes.statics.data.account.Account;
|
||||
import ru.clearing.classes.statics.data.account.InformationAccount;
|
||||
import ru.clearing.classes.statics.data.company.Company;
|
||||
import ru.clearing.classes.statics.data.misc.Currency;
|
||||
import ru.spcex.clearing.account.service.AccountHelper;
|
||||
import ru.spcex.clearing.account.service.InformationAccountService;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.account.TkrAccount;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.gateway.MoneyAccountMsgRequest;
|
||||
import ru.spcex.platform.classes.base.interfaces.IClearingFacade;
|
||||
import ru.spcex.platform.enumeration.AccountType;
|
||||
import ru.spcex.platform.enumeration.CurrencyCode;
|
||||
import ru.spcex.platform.enumeration.Sender;
|
||||
import ru.spcex.platform.enumeration.WorkflowStatus;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
import ru.spcex.platform.imdg.api.ImdgId;
|
||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicate;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicateBuilder;
|
||||
|
||||
@Service
|
||||
public class AccountFacade implements IClearingFacade {
|
||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||
private final ImdgId idGenerator;
|
||||
private final ImdgProvider imdgProvider;
|
||||
private final Imdg<Account> accountImdg;
|
||||
private final Imdg<InformationAccount> informationAccountImdg;
|
||||
private final Imdg<Currency> currencyImdg;
|
||||
private final InformationAccountService informationAccountService;
|
||||
private final AccountHelper accountHelper;
|
||||
private final TradingClearingRegistryFacade tradingClearingRegistryFacade;
|
||||
private final TradingClearingRegistryListFacade tradingClearingRegistryListFacade;
|
||||
|
||||
public AccountFacade(ImdgProvider imdgProvider,
|
||||
InformationAccountService informationAccountService,
|
||||
AccountHelper accountHelper,
|
||||
TradingClearingRegistryFacade tradingClearingRegistryFacade,
|
||||
TradingClearingRegistryListFacade tradingClearingRegistryListFacade) {
|
||||
this.idGenerator = imdgProvider.getImdgIdGenerator();
|
||||
this.imdgProvider = imdgProvider;
|
||||
this.accountImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Account, Account.class);
|
||||
this.informationAccountImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_InformationAccount, InformationAccount.class);
|
||||
this.currencyImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Currency, Currency.class);
|
||||
this.informationAccountService = informationAccountService;
|
||||
this.accountHelper = accountHelper;
|
||||
this.tradingClearingRegistryFacade = tradingClearingRegistryFacade;
|
||||
this.tradingClearingRegistryListFacade = tradingClearingRegistryListFacade;
|
||||
}
|
||||
|
||||
public void createInfoAccount(TkrAccount account, Company company) {
|
||||
for (MoneyAccountMsgRequest moneyAccountMsgRequest : account.getMoneyAccounts()) {
|
||||
String currencyCode = moneyAccountMsgRequest.getCurrCode() == null ? CurrencyCode.RUB.getKey() : moneyAccountMsgRequest.getCurrCode();
|
||||
ImdgPredicateBuilder predicateBuilder = currencyImdg.predicateBuilder();
|
||||
Currency currency = currencyImdg.getFirstObjectByPredicate(
|
||||
predicateBuilder.equals("currencyCode", currencyCode)
|
||||
);
|
||||
|
||||
Long currencyCodeId = CurrencyCode.RUB.getKey().equals(currencyCode) ? 810 : currency.getId();
|
||||
Instant now = Instant.now();
|
||||
Account infoAccount = new Account();
|
||||
infoAccount.setCompanyId(company.getId());
|
||||
infoAccount.setAccount(moneyAccountMsgRequest.getEks_account());
|
||||
|
||||
ImdgPredicateBuilder pb = accountImdg.predicateBuilder();
|
||||
ImdgPredicate andPredicate = pb.and(
|
||||
pb.equals("accountType", AccountType.Anlt.getKey()),
|
||||
pb.equals("currency", currency.getCurrencyCode())
|
||||
);
|
||||
Collection<Account> accountsAnlt = accountImdg.getCollectionObjectsByPredicate(andPredicate);
|
||||
if (accountsAnlt.isEmpty()) {
|
||||
log.warn("Account with {} not exist.", andPredicate);
|
||||
} else if (accountsAnlt.size() > 1) {
|
||||
log.warn("Account for companyId 1 and accountType=ANLT contains multiply elements, use first");
|
||||
}
|
||||
Account anltAccount = accountsAnlt.iterator().next();
|
||||
String specialAnltAccId = anltAccount.getAccount().substring(anltAccount.getAccount().length() - 4);
|
||||
Long infoSequenceId = informationAccountService.accountNextId(currencyCode, currencyCodeId);
|
||||
String accountValue = informationAccountService.generateInfoAccount(currencyCodeId, infoSequenceId, specialAnltAccId);
|
||||
log.trace("New info-account SequenceId={} account={}", infoSequenceId, accountValue);
|
||||
infoAccount.setAccount(accountValue);
|
||||
infoAccount.setAccountType(AccountType.Info.getKey());
|
||||
infoAccount.setCurrency(currencyCode);
|
||||
infoAccount.setStatus(WorkflowStatus.Active.getKey());
|
||||
infoAccount.setCreated(now);
|
||||
infoAccount.setUpdated(now);
|
||||
accountHelper.fillAccountFromRelation(infoAccount, null, false);
|
||||
|
||||
InformationAccount infoAcc = new InformationAccount();
|
||||
infoAcc.setAccountId(infoAccount.getId());
|
||||
Account firstAccountAntl = accountImdg.getFirstObjectByFieldValues(Map.of(
|
||||
"companyId", Sender.One.getId(),
|
||||
"accountType", AccountType.Anlt.getKey(),
|
||||
"currency", infoAccount.getCurrency()
|
||||
));
|
||||
if (firstAccountAntl == null) {
|
||||
log.warn("Can not find 1 ANTL {} account for fill information ClearingAccountId.", infoAccount.getCurrency());
|
||||
} else {
|
||||
infoAcc.setClearingAccountId(firstAccountAntl.getId());
|
||||
}
|
||||
infoAcc.setCompanyId(infoAccount.getCompanyId());
|
||||
accountImdg.insert(infoAccount);
|
||||
Long infoId = informationAccountImdg.insert(infoAcc);
|
||||
log.debug("For account id={} make InformationAccount id={}", infoAccount.getId(), infoId);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void lock() {
|
||||
// tradingClearingRegistryFacade.lock()
|
||||
// tradingClearingRegistryListFacade.lock()
|
||||
}
|
||||
|
||||
public void unlock() {
|
||||
// tradingClearingRegistryFacade.lock()
|
||||
// tradingClearingRegistryListFacade.lock()
|
||||
}
|
||||
}
|
||||
|
|
@ -67,8 +67,8 @@ public class ClientCodeFacade implements IClearingFacade {
|
|||
|
||||
clientCode.setCompanyId(request.getCompanyId());
|
||||
clientCode.setCode(request.getCode());
|
||||
clientCode.setMoneyAccountId(request.getMoneyAccountId());
|
||||
clientCode.setDepoAccountId(request.getDepoAccountId());
|
||||
// clientCode.setMoneyAccountId(request.getMoneyAccountId());
|
||||
// clientCode.setDepoAccountId(request.getDepoAccountId());
|
||||
clientCode.setStatus(request.getStatus());
|
||||
clientCodeImdg.insert(clientCode);
|
||||
log.debug("successfully processed, new clientCode id {}", clientCode.getId());
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import org.apache.kafka.clients.consumer.Consumer;
|
||||
import org.apache.kafka.clients.producer.Producer;
|
||||
import org.slf4j.Logger;
|
||||
|
|
@ -15,6 +16,7 @@ import ru.clearing.classes.statics.data.company.Company;
|
|||
import ru.clearing.classes.statics.data.registry.TradingClearingRegistry;
|
||||
import ru.spcex.clearing.account.model.ValidationResult;
|
||||
import ru.spcex.clearing.account.service.v2.GatewayRequestCreator;
|
||||
import ru.spcex.clearing.account.service.v2.facade.AccountFacade;
|
||||
import ru.spcex.clearing.account.service.v2.facade.ClientCodeFacade;
|
||||
import ru.spcex.clearing.account.service.v2.validators.ClientCodeValidator;
|
||||
import ru.spcex.clearing.account.validation.ClientCodeStoreObjects;
|
||||
|
|
@ -46,6 +48,7 @@ public class ClientCodeMessageListener extends QueueConsumer implements Initiali
|
|||
private final ClientCodeValidator clientCodeValidator;
|
||||
private final GatewayRequestCreator gatewayRequestCreator;
|
||||
private final UserRoleVerification userRoleVerification;
|
||||
private final AccountFacade accountFacade;
|
||||
|
||||
public ClientCodeMessageListener(Consumer<String, Object> kafkaQueue,
|
||||
Producer<String, Object> kafkaProducer,
|
||||
|
|
@ -54,7 +57,8 @@ public class ClientCodeMessageListener extends QueueConsumer implements Initiali
|
|||
ClientCodeFacade clientCodeFacade,
|
||||
ClientCodeValidator clientCodeValidator,
|
||||
GatewayRequestCreator gatewayRequestCreator,
|
||||
UserRoleVerification userRoleVerification) {
|
||||
UserRoleVerification userRoleVerification,
|
||||
AccountFacade accountFacade) {
|
||||
super(kafkaQueue, kafkaProducer);
|
||||
this.kafkaSender = kafkaSender;
|
||||
this.imdgProvider = imdgProvider;
|
||||
|
|
@ -62,6 +66,7 @@ public class ClientCodeMessageListener extends QueueConsumer implements Initiali
|
|||
this.clientCodeValidator = clientCodeValidator;
|
||||
this.gatewayRequestCreator = gatewayRequestCreator;
|
||||
this.userRoleVerification = userRoleVerification;
|
||||
this.accountFacade = accountFacade;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -90,17 +95,39 @@ public class ClientCodeMessageListener extends QueueConsumer implements Initiali
|
|||
SendTkrRequest sendTkrRequest = new SendTkrRequest();
|
||||
sendTkrRequest.setRequestId(gatewayRequest.getRequestId());
|
||||
|
||||
boolean isAnyoneInvalid = false;
|
||||
AtomicBoolean isAnyoneInvalid = new AtomicBoolean(false);
|
||||
Map<TkrAccount, ValidationResult> eksAccountsAfterValidation = new HashMap<>();
|
||||
Map<TkrAccount, ValidationResult> accountsAfterValidation = new HashMap<>();
|
||||
for (TkrAccount tkrAccount : gatewayRequest.getAccounts()) {
|
||||
List<TkrAccount> withAccount = gatewayRequest.getAccounts().stream()
|
||||
.filter(tkrAccount -> tkrAccount.getMoneyAccounts() != null &&
|
||||
tkrAccount.getMoneyAccounts().stream()
|
||||
.anyMatch(moneyAccountMsgRequest -> moneyAccountMsgRequest.getAccount() != null))
|
||||
.toList();
|
||||
List<TkrAccount> withEksAccount = gatewayRequest.getAccounts().stream()
|
||||
.filter(tkrAccount -> tkrAccount.getMoneyAccounts() != null &&
|
||||
tkrAccount.getMoneyAccounts().stream()
|
||||
.anyMatch(moneyAccountMsgRequest -> moneyAccountMsgRequest.getEks_account() != null))
|
||||
.toList();
|
||||
|
||||
withAccount.forEach(tkrAccount -> {
|
||||
ValidationResult validationResult = clientCodeValidator.checkGatewayRequest(tkrAccount);
|
||||
if (!validationResult.isValid()) {
|
||||
log.debug("Validation failed for tkr.client_code {}", tkrAccount.getClientCode());
|
||||
isAnyoneInvalid = true;
|
||||
isAnyoneInvalid.set(true);
|
||||
}
|
||||
accountsAfterValidation.put(tkrAccount, validationResult);
|
||||
}
|
||||
if (isAnyoneInvalid) {
|
||||
});
|
||||
|
||||
withEksAccount.forEach(tkrAccount -> {
|
||||
ValidationResult validationResult = clientCodeValidator.checkGatewayRequestWithEksAcc(tkrAccount);
|
||||
if (!validationResult.isValid()) {
|
||||
log.debug("Validation failed for tkr.client_code {}", tkrAccount.getClientCode());
|
||||
isAnyoneInvalid.set(true);
|
||||
}
|
||||
eksAccountsAfterValidation.put(tkrAccount, validationResult);
|
||||
});
|
||||
|
||||
if (isAnyoneInvalid.get()) {
|
||||
log.debug("Create error request to gateway service");
|
||||
|
||||
List<Tkr> tkrs = accountsAfterValidation.entrySet()
|
||||
|
|
@ -111,12 +138,30 @@ public class ClientCodeMessageListener extends QueueConsumer implements Initiali
|
|||
tkrAccountValidationResultEntry.getValue().errorMsg()
|
||||
))
|
||||
.toList();
|
||||
sendTkrRequest.setTkrs(tkrs);
|
||||
List<Tkr> eksTkrs = eksAccountsAfterValidation.entrySet()
|
||||
.stream()
|
||||
.map(tkrAccountValidationResultEntry ->
|
||||
gatewayRequestCreator.crateErrorTkrToGateway(
|
||||
tkrAccountValidationResultEntry.getKey(),
|
||||
tkrAccountValidationResultEntry.getValue().errorMsg()
|
||||
))
|
||||
.toList();
|
||||
sendTkrRequest.getTkrs().addAll(tkrs);
|
||||
sendTkrRequest.getTkrs().addAll(eksTkrs);
|
||||
kafkaSender.sendRequestToQueue(Consts.ACCOUNTS_TO_GATEWAY, sendTkrRequest);
|
||||
return null;
|
||||
}
|
||||
|
||||
//unwrap запроса
|
||||
processAccount(accountsAfterValidation, gatewayRequest);
|
||||
processEksAccount(eksAccountsAfterValidation, gatewayRequest);
|
||||
kafkaSender.sendRequestToQueue(Consts.ACCOUNTS_TO_GATEWAY, sendTkrRequest);
|
||||
return null;
|
||||
}
|
||||
|
||||
private void processAccount(Map<TkrAccount, ValidationResult> accountsAfterValidation, TkrAccountsGatewayRequest gatewayRequest) {
|
||||
SendTkrRequest sendTkrRequest = new SendTkrRequest();
|
||||
sendTkrRequest.setRequestId(gatewayRequest.getRequestId());
|
||||
|
||||
for (Map.Entry<TkrAccount, ValidationResult> entry : accountsAfterValidation.entrySet()) {
|
||||
ClientCodeNewRequest clientCodeNewRequest = new ClientCodeNewRequest();
|
||||
TkrAccount tkrAccount = entry.getKey();
|
||||
|
|
@ -148,8 +193,45 @@ public class ClientCodeMessageListener extends QueueConsumer implements Initiali
|
|||
sendTkrRequest.getTkrs().add(gatewayRequestCreator.createTkrGatewayReq(tradingClearingRegistry));
|
||||
log.debug("Success created new clientCode by tkr account: {}", tkrAccount.getClientCode());
|
||||
}
|
||||
kafkaSender.sendRequestToQueue(Consts.ACCOUNTS_TO_GATEWAY, sendTkrRequest);
|
||||
return null;
|
||||
}
|
||||
|
||||
private void processEksAccount(Map<TkrAccount, ValidationResult> accountsAfterValidation, TkrAccountsGatewayRequest gatewayRequest) {
|
||||
SendTkrRequest sendTkrRequest = new SendTkrRequest();
|
||||
sendTkrRequest.setRequestId(gatewayRequest.getRequestId());
|
||||
|
||||
for (Map.Entry<TkrAccount, ValidationResult> entry : accountsAfterValidation.entrySet()) {
|
||||
TkrAccount tkrAccount = entry.getKey();
|
||||
ValidationResult validationResult = entry.getValue();
|
||||
IValidator validator = validationResult.validator();
|
||||
Company company = validator.getStored(ClientCodeStoreObjects.COMPANY);
|
||||
accountFacade.createInfoAccount(tkrAccount, company);
|
||||
|
||||
ClientCodeNewRequest clientCodeNewRequest = new ClientCodeNewRequest();
|
||||
log.debug("Creating new clientCode by tkr account: {}", tkrAccount.getClientCode());
|
||||
|
||||
Optional<Account> depoAccount = validator.getStored(ClientCodeStoreObjects.DEPO_ACCOUNT);
|
||||
Long depoAccountId = depoAccount.map(Account::getId).orElse(null);
|
||||
// Map<String, Account> accountByCurrency = validator.getStored(ClientCodeStoreObjects.MAPPED_TO_CURRENCY_ACCOUNTS);
|
||||
//
|
||||
// clientCodeNewRequest.setCompanyId(company.getId());
|
||||
// clientCodeNewRequest.setCode(tkrAccount.getClientCode());
|
||||
// clientCodeNewRequest.setDepoAccountId(depoAccountId);
|
||||
// Account moneyAccount = accountByCurrency.get(CurrencyCode.RUB.getKey());
|
||||
// clientCodeNewRequest.setMoneyAccountId(moneyAccount.getId());
|
||||
//
|
||||
// List<Long> foreignCurrencyList = accountByCurrency.entrySet()
|
||||
// .stream()
|
||||
// .filter(currencyCodeAccountEntry -> !CurrencyCode.RUB.equalsByKey(currencyCodeAccountEntry.getKey()))
|
||||
// .map(currencyCodeAccountEntry -> currencyCodeAccountEntry.getValue().getId())
|
||||
// .toList();
|
||||
// clientCodeNewRequest.setCurrencyAccountList(foreignCurrencyList);
|
||||
// clientCodeFacade.createClientCode(clientCodeNewRequest, validator);
|
||||
//
|
||||
// TradingClearingRegistry tradingClearingRegistry = selectTradingClearingRegistry(company.getId(),
|
||||
// moneyAccount.getId(), depoAccountId);
|
||||
// sendTkrRequest.getTkrs().add(gatewayRequestCreator.createTkrGatewayReq(tradingClearingRegistry));
|
||||
// log.debug("Success created new clientCode by tkr account: {}", tkrAccount.getClientCode());
|
||||
}
|
||||
}
|
||||
|
||||
private RequestInfoUpdate clientCodeNewFromBackend(BaseRequest<ClientCodeNewRequest> clientCodeNewRequest) {
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ public class ClientCodeValidator {
|
|||
private final Function<ClientCodeUpdateRequest, IValidator> clientCodeUpdateRequestValidator;
|
||||
private final Function<CommonDeleteRequest, IValidator> clientCodeDeleteRequestValidator;
|
||||
private final Function<TkrAccount, IValidator> tkrAccountsGatewayValidator;
|
||||
private final Function<TkrAccount, IValidator> tkrEksAccountsGatewayValidator;
|
||||
private final IMessageResolver messageResolver;
|
||||
|
||||
public ClientCodeValidator(UserRoleVerification userRoleVerification,
|
||||
|
|
@ -31,12 +32,14 @@ public class ClientCodeValidator {
|
|||
Function<ClientCodeUpdateRequest, IValidator> clientCodeUpdateRequestValidator,
|
||||
Function<CommonDeleteRequest, IValidator> clientCodeDeleteRequestValidator,
|
||||
Function<TkrAccount, IValidator> tkrAccountsGatewayValidator,
|
||||
Function<TkrAccount, IValidator> tkrEksAccountsGatewayValidator,
|
||||
IMessageResolver messageResolver) {
|
||||
this.userRoleVerification = userRoleVerification;
|
||||
this.clientCodeNewRequestValidator = clientCodeNewRequestValidator;
|
||||
this.clientCodeUpdateRequestValidator = clientCodeUpdateRequestValidator;
|
||||
this.clientCodeDeleteRequestValidator = clientCodeDeleteRequestValidator;
|
||||
this.tkrAccountsGatewayValidator = tkrAccountsGatewayValidator;
|
||||
this.tkrEksAccountsGatewayValidator = tkrEksAccountsGatewayValidator;
|
||||
this.messageResolver = messageResolver;
|
||||
}
|
||||
|
||||
|
|
@ -44,6 +47,10 @@ public class ClientCodeValidator {
|
|||
return standardValidation(tkrAccountsGatewayValidator, gatewayAccountRequest);
|
||||
}
|
||||
|
||||
public ValidationResult checkGatewayRequestWithEksAcc(TkrAccount gatewayAccountRequest) {
|
||||
return standardValidation(tkrEksAccountsGatewayValidator, gatewayAccountRequest);
|
||||
}
|
||||
|
||||
public ValidationResult checkBackendNewRequest(ClientCodeNewRequest clientCodeNewRequest) {
|
||||
return standardValidation(clientCodeNewRequestValidator, clientCodeNewRequest);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ import java.util.Map;
|
|||
import java.util.Optional;
|
||||
import org.springframework.util.StringUtils;
|
||||
import ru.clearing.classes.statics.data.account.Account;
|
||||
import ru.clearing.classes.statics.data.account.AccountSymbols;
|
||||
import ru.clearing.classes.statics.data.account.DepoAccount;
|
||||
import ru.clearing.classes.statics.data.company.Company;
|
||||
import ru.clearing.classes.statics.data.registry.TradingClearingRegistry;
|
||||
import ru.clearing.classes.statics.data.registry.TradingClearingRegistryList;
|
||||
|
|
@ -96,9 +98,18 @@ public enum GatewayClientCodeValidationRule implements IValidationRule<ImdgValid
|
|||
return empty();
|
||||
}
|
||||
|
||||
Imdg<Account> imdg = context.obtainMap(IMDGDistributedNames.Map_Account, Account.class);
|
||||
Account depoAccount = imdg.getFirstObjectByFieldValues(
|
||||
Map.of("account", depoAccountVal)
|
||||
Imdg<AccountSymbols> accountSymbolsImdg = context.obtainMap(IMDGDistributedNames.Map_AccountSymbols, AccountSymbols.class);
|
||||
ImdgPredicateBuilder predicateBuilder = accountSymbolsImdg.predicateBuilder();
|
||||
AccountSymbols accountSymbols = accountSymbolsImdg.getSingleObjectByPredicate(
|
||||
predicateBuilder.equals("accountSymbolValue", depoAccountVal)
|
||||
);
|
||||
|
||||
if (accountSymbols == null) {
|
||||
return of(AccountError.DepoAccountNotFound, "depo_account");
|
||||
}
|
||||
Imdg<DepoAccount> imdg = context.obtainMap(IMDGDistributedNames.Map_DepoAccount, DepoAccount.class);
|
||||
DepoAccount depoAccount = imdg.getFirstObjectByPredicate(
|
||||
predicateBuilder.equals("accountId", accountSymbols.getAccountId())
|
||||
);
|
||||
if (depoAccount == null) {
|
||||
context.storeObject(ClientCodeStoreObjects.DEPO_ACCOUNT, Optional.empty());
|
||||
|
|
|
|||
|
|
@ -0,0 +1,93 @@
|
|||
package ru.spcex.clearing.account.validation;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.util.StringUtils;
|
||||
import ru.clearing.classes.statics.data.account.Account;
|
||||
import ru.clearing.classes.statics.data.company.Company;
|
||||
import ru.spcex.clearing.account.errors.AccountError;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.account.TkrAccount;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.gateway.MoneyAccountMsgRequest;
|
||||
import ru.spcex.platform.enumeration.CurrencyCode;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
import ru.spcex.platform.imdg.validation.ImdgValidationContext;
|
||||
import ru.spcex.platform.utils.enumeration.EnumMessage;
|
||||
import ru.spcex.platform.utils.validation.IValidationRule;
|
||||
|
||||
public enum GatewayEksClientCodeValidationRule implements IValidationRule<ImdgValidationContext<TkrAccount>> {
|
||||
CompanyPresent() {
|
||||
@Override
|
||||
public Optional<EnumMessage> validate(ImdgValidationContext<TkrAccount> context) {
|
||||
TkrAccount validatedObject = context.getValidatedObject();
|
||||
Long tradingCode = validatedObject.getTradingCode();
|
||||
if (tradingCode == null) {
|
||||
return of(AccountError.RequiredFieldEmpty, "trading_code");
|
||||
}
|
||||
|
||||
Imdg<Company> companyImdg = context.obtainMap(IMDGDistributedNames.Map_Company, Company.class);
|
||||
Company company = companyImdg.getFirstObjectByFieldValues(
|
||||
Map.of("tradingCode", String.valueOf(tradingCode))
|
||||
);
|
||||
if (company == null) {
|
||||
return of(AccountError.COMPANY_NOT_FOUND_GTW, "trading_code");
|
||||
}
|
||||
|
||||
context.storeObject(ClientCodeStoreObjects.COMPANY, company);
|
||||
return Optional.empty();
|
||||
}
|
||||
},
|
||||
AllAccountsPresent() {
|
||||
@Override
|
||||
public Optional<EnumMessage> validate(ImdgValidationContext<TkrAccount> context) {
|
||||
TkrAccount validatedObject = context.getValidatedObject();
|
||||
List<MoneyAccountMsgRequest> accountList = validatedObject.getMoneyAccounts();
|
||||
if (accountList == null || accountList.isEmpty()) {
|
||||
return of(AccountError.RequiredFieldEmpty, "money_account");
|
||||
}
|
||||
List<String> currencies = accountList.stream().map(MoneyAccountMsgRequest::getCurrCode).toList();
|
||||
if (!currencies.contains(CurrencyCode.RUB.getKey())) {
|
||||
return of(AccountError.RequiredFieldEmpty, "money_account");
|
||||
}
|
||||
Imdg<Account> imdg = context.obtainMap(IMDGDistributedNames.Map_Account, Account.class);
|
||||
Map<String, Account> accountByCurrency = new HashMap<>();
|
||||
for (MoneyAccountMsgRequest moneyAccountMsg : accountList) {
|
||||
//если в списке есть eksAccount то проверим, что его нет в системе
|
||||
if (!StringUtils.hasText(moneyAccountMsg.getEks_account())) {
|
||||
return of(AccountError.RequiredFieldEmpty, "eks_account");
|
||||
}
|
||||
}
|
||||
context.storeObject(ClientCodeStoreObjects.MAPPED_TO_CURRENCY_ACCOUNTS, accountByCurrency);
|
||||
return Optional.empty();
|
||||
}
|
||||
},
|
||||
DepoAccountsPresent() {
|
||||
@Override
|
||||
public Optional<EnumMessage> validate(ImdgValidationContext<TkrAccount> context) {
|
||||
TkrAccount validatedObject = context.getValidatedObject();
|
||||
String depoAccountVal = validatedObject.getDepoAccount();
|
||||
if (!StringUtils.hasText(depoAccountVal)) {
|
||||
context.storeObject(ClientCodeStoreObjects.DEPO_ACCOUNT, Optional.empty());
|
||||
return empty();
|
||||
}
|
||||
|
||||
Imdg<Account> imdg = context.obtainMap(IMDGDistributedNames.Map_Account, Account.class);
|
||||
Account depoAccount = imdg.getFirstObjectByFieldValues(
|
||||
Map.of("account", depoAccountVal)
|
||||
);
|
||||
if (depoAccount == null) {
|
||||
context.storeObject(ClientCodeStoreObjects.DEPO_ACCOUNT, Optional.empty());
|
||||
return of(AccountError.DepoAccountNotFound, "depo_account");
|
||||
}
|
||||
|
||||
context.storeObject(ClientCodeStoreObjects.DEPO_ACCOUNT, depoAccount);
|
||||
return Optional.empty();
|
||||
}
|
||||
};
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(GatewayEksClientCodeValidationRule.class);
|
||||
}
|
||||
|
|
@ -54,6 +54,7 @@ public class TkrAdapter {
|
|||
MoneyAccountMsgRequest moneyAccountMsg = new MoneyAccountMsgRequest();
|
||||
moneyAccountMsg.setAccount(moneyAccount.getAccount());
|
||||
moneyAccountMsg.setCurrCode(moneyAccount.getCurrCode());
|
||||
moneyAccountMsg.setEks_account(moneyAccount.getEksAccount());
|
||||
return moneyAccountMsg;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ public class MoneyAccountMsgRequest {
|
|||
private String currCode;
|
||||
@JsonProperty("account")
|
||||
private String account;
|
||||
@JsonProperty("eks_account")
|
||||
private String eks_account;
|
||||
@JsonProperty("status")
|
||||
private String status;
|
||||
|
||||
|
|
@ -25,4 +27,12 @@ public class MoneyAccountMsgRequest {
|
|||
public void setAccount(String account) {
|
||||
this.account = account;
|
||||
}
|
||||
|
||||
public String getEks_account() {
|
||||
return eks_account;
|
||||
}
|
||||
|
||||
public void setEks_account(String eks_account) {
|
||||
this.eks_account = eks_account;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue