This commit is contained in:
parent
578f6a708b
commit
1982731a0e
6 changed files with 66 additions and 43 deletions
|
|
@ -152,13 +152,13 @@ public class ClientCodeValidationConfig {
|
||||||
addImdg.accept(IMDGDistributedNames.Map_DepoAccount);
|
addImdg.accept(IMDGDistributedNames.Map_DepoAccount);
|
||||||
return new ValidatorImpl<>(context,
|
return new ValidatorImpl<>(context,
|
||||||
FieldRequiredRule.instance("client_code", TkrAccount::getClientCode, AccountError.RequiredFieldEmpty),
|
FieldRequiredRule.instance("client_code", TkrAccount::getClientCode, AccountError.RequiredFieldEmpty),
|
||||||
|
GatewayEksClientCodeValidationRule.RequiredAndCorrectsFields,
|
||||||
GatewayEksClientCodeValidationRule.RubAccountPresent,
|
GatewayEksClientCodeValidationRule.RubAccountPresent,
|
||||||
GatewayEksClientCodeValidationRule.CompanyPresent,
|
GatewayEksClientCodeValidationRule.CompanyPresent,
|
||||||
GatewayEksClientCodeValidationRule.DepoAccountsPresent,
|
GatewayEksClientCodeValidationRule.DepoAccountsPresent,
|
||||||
GatewayEksClientCodeValidationRule.ClsAccountsPresent,
|
GatewayEksClientCodeValidationRule.ClsAccountsPresent,
|
||||||
|
GatewayEksClientCodeValidationRule.AnltAccountPresent,
|
||||||
GatewayEksClientCodeValidationRule.TcrIsNotPresent
|
GatewayEksClientCodeValidationRule.TcrIsNotPresent
|
||||||
// GatewayClientCodeValidationRule.TcrIsNotPresent,
|
|
||||||
// GatewayClientCodeValidationRule.TcrListIsNotPresent
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -136,43 +136,6 @@ public class ClientCodeMessageListener extends QueueConsumer implements Initiali
|
||||||
return null;
|
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) {
|
private void processEksAccount(Map<TkrAccount, ValidationResult> accountsAfterValidation, TkrAccountsGatewayRequest gatewayRequest) {
|
||||||
SendTkrRequest sendTkrRequest = new SendTkrRequest();
|
SendTkrRequest sendTkrRequest = new SendTkrRequest();
|
||||||
sendTkrRequest.setRequestId(gatewayRequest.getRequestId());
|
sendTkrRequest.setRequestId(gatewayRequest.getRequestId());
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ public enum ClientCodeStoreObjects {
|
||||||
MONEY_ACCOUNT,
|
MONEY_ACCOUNT,
|
||||||
DEPO_ACCOUNT,
|
DEPO_ACCOUNT,
|
||||||
CLRN_ACCS,
|
CLRN_ACCS,
|
||||||
|
ANLT_ACCS,
|
||||||
MAPPED_TO_CURRENCY_ACCOUNTS,
|
MAPPED_TO_CURRENCY_ACCOUNTS,
|
||||||
TRADING_CLEARING_REGISTRY
|
TRADING_CLEARING_REGISTRY
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,29 @@ import ru.spcex.platform.utils.enumeration.EnumMessage;
|
||||||
import ru.spcex.platform.utils.validation.IValidationRule;
|
import ru.spcex.platform.utils.validation.IValidationRule;
|
||||||
|
|
||||||
public enum GatewayEksClientCodeValidationRule implements IValidationRule<ImdgValidationContext<TkrAccount>> {
|
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() {
|
CompanyPresent() {
|
||||||
@Override
|
@Override
|
||||||
public Optional<EnumMessage> validate(ImdgValidationContext<TkrAccount> context) {
|
public Optional<EnumMessage> validate(ImdgValidationContext<TkrAccount> context) {
|
||||||
|
|
@ -121,6 +144,28 @@ public enum GatewayEksClientCodeValidationRule implements IValidationRule<ImdgVa
|
||||||
return Optional.empty();
|
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() {
|
TcrIsNotPresent() {
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -131,7 +176,7 @@ public enum GatewayEksClientCodeValidationRule implements IValidationRule<ImdgVa
|
||||||
.filter(ruAcc -> CurrencyCode.RUB.equalsByKey(ruAcc.getCurrency()))
|
.filter(ruAcc -> CurrencyCode.RUB.equalsByKey(ruAcc.getCurrency()))
|
||||||
.findFirst();
|
.findFirst();
|
||||||
|
|
||||||
if (ruClrnAcc.isEmpty()) {
|
if (ruClrnAcc.isEmpty() && depoAccountOpt.isEmpty()) {
|
||||||
return empty();
|
return empty();
|
||||||
}
|
}
|
||||||
Imdg<TradingClearingRegistry> imdg = context.obtainMap(IMDGDistributedNames.Map_TradingClearingRegistry,
|
Imdg<TradingClearingRegistry> imdg = context.obtainMap(IMDGDistributedNames.Map_TradingClearingRegistry,
|
||||||
|
|
@ -140,9 +185,13 @@ public enum GatewayEksClientCodeValidationRule implements IValidationRule<ImdgVa
|
||||||
Account.class);
|
Account.class);
|
||||||
|
|
||||||
ImdgPredicateBuilder pb = imdg.predicateBuilder();
|
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()) {
|
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);
|
Collection<TradingClearingRegistry> tcr = imdg.getCollectionObjectsByPredicate(query);
|
||||||
|
|
||||||
|
|
@ -151,7 +200,8 @@ public enum GatewayEksClientCodeValidationRule implements IValidationRule<ImdgVa
|
||||||
} else {
|
} else {
|
||||||
Account dubAcc = null;
|
Account dubAcc = null;
|
||||||
for (TradingClearingRegistry duplicate : tcr) {
|
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();
|
dubAcc = ruClrnAcc.get();
|
||||||
}
|
}
|
||||||
if (depoAccountOpt.isPresent() &&
|
if (depoAccountOpt.isPresent() &&
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,7 @@ public class TkrAdapter {
|
||||||
moneyAccountMsg.setAccount(moneyAccount.getAccount());
|
moneyAccountMsg.setAccount(moneyAccount.getAccount());
|
||||||
moneyAccountMsg.setCurrCode(moneyAccount.getCurrCode());
|
moneyAccountMsg.setCurrCode(moneyAccount.getCurrCode());
|
||||||
moneyAccountMsg.setEks_account(moneyAccount.getEksAccount());
|
moneyAccountMsg.setEks_account(moneyAccount.getEksAccount());
|
||||||
|
moneyAccountMsg.setStatus(moneyAccount.getStatus());
|
||||||
return moneyAccountMsg;
|
return moneyAccountMsg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,4 +35,12 @@ public class MoneyAccountMsgRequest {
|
||||||
public void setEks_account(String eks_account) {
|
public void setEks_account(String eks_account) {
|
||||||
this.eks_account = eks_account;
|
this.eks_account = eks_account;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(String status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue