etreschenkov 2026-05-26 16:25:45 +03:00
parent 578f6a708b
commit 1982731a0e
6 changed files with 66 additions and 43 deletions

View file

@ -152,13 +152,13 @@ public class ClientCodeValidationConfig {
addImdg.accept(IMDGDistributedNames.Map_DepoAccount);
return new ValidatorImpl<>(context,
FieldRequiredRule.instance("client_code", TkrAccount::getClientCode, AccountError.RequiredFieldEmpty),
GatewayEksClientCodeValidationRule.RequiredAndCorrectsFields,
GatewayEksClientCodeValidationRule.RubAccountPresent,
GatewayEksClientCodeValidationRule.CompanyPresent,
GatewayEksClientCodeValidationRule.DepoAccountsPresent,
GatewayEksClientCodeValidationRule.ClsAccountsPresent,
GatewayEksClientCodeValidationRule.AnltAccountPresent,
GatewayEksClientCodeValidationRule.TcrIsNotPresent
// GatewayClientCodeValidationRule.TcrIsNotPresent,
// GatewayClientCodeValidationRule.TcrListIsNotPresent
);
};
}

View file

@ -136,43 +136,6 @@ public class ClientCodeMessageListener extends QueueConsumer implements Initiali
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();
ValidationResult validationResult = entry.getValue();
log.debug("Creating new clientCode by tkr account: {}", tkrAccount.getClientCode());
IValidator validator = validationResult.validator();
Company company = validator.getStored(ClientCodeStoreObjects.COMPANY);
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.createClientCodeWithTkr(clientCodeNewRequest, validator, true);
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 void processEksAccount(Map<TkrAccount, ValidationResult> accountsAfterValidation, TkrAccountsGatewayRequest gatewayRequest) {
SendTkrRequest sendTkrRequest = new SendTkrRequest();
sendTkrRequest.setRequestId(gatewayRequest.getRequestId());

View file

@ -5,6 +5,7 @@ public enum ClientCodeStoreObjects {
MONEY_ACCOUNT,
DEPO_ACCOUNT,
CLRN_ACCS,
ANLT_ACCS,
MAPPED_TO_CURRENCY_ACCOUNTS,
TRADING_CLEARING_REGISTRY
}

View file

@ -28,6 +28,29 @@ import ru.spcex.platform.utils.enumeration.EnumMessage;
import ru.spcex.platform.utils.validation.IValidationRule;
public enum GatewayEksClientCodeValidationRule implements IValidationRule<ImdgValidationContext<TkrAccount>> {
RequiredAndCorrectsFields() {
@Override
public Optional<EnumMessage> validate(ImdgValidationContext<TkrAccount> context) {
TkrAccount validatedObject = context.getValidatedObject();
Collection<MoneyAccountMsgRequest> msgs = validatedObject.getMoneyAccounts().stream()
.filter(acc -> !StringUtils.hasText(acc.getAccount()) && StringUtils.hasText(acc.getEks_account()))
.toList();
for (MoneyAccountMsgRequest msg : validatedObject.getMoneyAccounts()) {
if (!StringUtils.hasText(msg.getAccount()) && StringUtils.hasText(msg.getEks_account())) {
return of(AccountError.RequiredFieldEmpty, "account+eks_account");
}
if (!msg.getStatus().equals("NEW")) {
return of(AccountError.WrongFieldValue, "status");
}
}
if (!msgs.isEmpty()) {
return of(AccountError.RequiredFieldEmpty, "account+eks_account");
}
return empty();
}
},
CompanyPresent() {
@Override
public Optional<EnumMessage> validate(ImdgValidationContext<TkrAccount> context) {
@ -121,6 +144,28 @@ public enum GatewayEksClientCodeValidationRule implements IValidationRule<ImdgVa
return Optional.empty();
}
},
AnltAccountPresent() {
@Override
public Optional<EnumMessage> validate(ImdgValidationContext<TkrAccount> context) {
TkrAccount validatedObject = context.getValidatedObject();
List<MoneyAccountMsgRequest> moneyAccounts = validatedObject.getMoneyAccounts().stream()
.filter(account -> StringUtils.hasText(account.getEks_account()))
.toList();
Imdg<Account> accountImdg = context.obtainMap(IMDGDistributedNames.Map_Account, Account.class);
for (MoneyAccountMsgRequest moneyAccount : moneyAccounts) {
ImdgPredicateBuilder predicateBuilder = accountImdg.predicateBuilder();
Account anltAcc = accountImdg.getFirstObjectByPredicate(
predicateBuilder.and(
predicateBuilder.equals("accountType", AccountType.Anlt.getKey()),
predicateBuilder.equals("currency", moneyAccount.getCurrCode())
));
if (anltAcc == null) {
return of(AccountError.AccountNotFound, moneyAccount.getAccount());
}
}
return Optional.empty();
}
},
TcrIsNotPresent() {
@Override
@ -131,7 +176,7 @@ public enum GatewayEksClientCodeValidationRule implements IValidationRule<ImdgVa
.filter(ruAcc -> CurrencyCode.RUB.equalsByKey(ruAcc.getCurrency()))
.findFirst();
if (ruClrnAcc.isEmpty()) {
if (ruClrnAcc.isEmpty() && depoAccountOpt.isEmpty()) {
return empty();
}
Imdg<TradingClearingRegistry> imdg = context.obtainMap(IMDGDistributedNames.Map_TradingClearingRegistry,
@ -140,9 +185,13 @@ public enum GatewayEksClientCodeValidationRule implements IValidationRule<ImdgVa
Account.class);
ImdgPredicateBuilder pb = imdg.predicateBuilder();
ImdgPredicate query = pb.equals("moneyAccountId", ruClrnAcc.get().getId());
ImdgPredicate query = null;
if (ruClrnAcc.isPresent()) {
query = pb.equals("moneyAccountId", ruClrnAcc.get().getId());
}
if (depoAccountOpt.isPresent()) {
query = pb.or(query, pb.equals("depoAccountId", depoAccountOpt.get().getAccountId()));
ImdgPredicate depoCondition = pb.equals("depoAccountId", depoAccountOpt.get().getAccountId());
query = query == null ? depoCondition : pb.or(query, depoCondition);
}
Collection<TradingClearingRegistry> tcr = imdg.getCollectionObjectsByPredicate(query);
@ -151,7 +200,8 @@ public enum GatewayEksClientCodeValidationRule implements IValidationRule<ImdgVa
} else {
Account dubAcc = null;
for (TradingClearingRegistry duplicate : tcr) {
if (Objects.equals(duplicate.getMoneyAccountId(), ruClrnAcc.get().getId())) {
if (ruClrnAcc.isPresent() &&
Objects.equals(duplicate.getMoneyAccountId(), ruClrnAcc.get().getId())) {
dubAcc = ruClrnAcc.get();
}
if (depoAccountOpt.isPresent() &&

View file

@ -55,6 +55,7 @@ public class TkrAdapter {
moneyAccountMsg.setAccount(moneyAccount.getAccount());
moneyAccountMsg.setCurrCode(moneyAccount.getCurrCode());
moneyAccountMsg.setEks_account(moneyAccount.getEksAccount());
moneyAccountMsg.setStatus(moneyAccount.getStatus());
return moneyAccountMsg;
}
}

View file

@ -35,4 +35,12 @@ public class MoneyAccountMsgRequest {
public void setEks_account(String eks_account) {
this.eks_account = eks_account;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
}