etreschenkov 2026-05-22 17:02:28 +03:00
parent 0cada83af9
commit f6ba9ee06d
8 changed files with 170 additions and 152 deletions

View file

@ -1,12 +1,10 @@
package ru.spcex.clearing.account.config.validation; package ru.spcex.clearing.account.config.validation;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.Function; import java.util.function.Function;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import ru.clearing.classes.statics.data.account.Account;
import ru.clearing.classes.statics.data.account.ClientCode; import ru.clearing.classes.statics.data.account.ClientCode;
import ru.clearing.classes.statics.data.company.Company; import ru.clearing.classes.statics.data.company.Company;
import ru.clearing.platform.dictionary.ServiceStatusDictionary; import ru.clearing.platform.dictionary.ServiceStatusDictionary;
@ -50,28 +48,28 @@ public class ClientCodeValidationConfig {
Company.class, Company.class,
AccountError.RequiredFieldEmpty, AccountError.RequiredFieldEmpty,
AccountError.CompanyNotFound), AccountError.CompanyNotFound),
//
IdPresentRule.instance("moneyAccountId", // IdPresentRule.instance("moneyAccountId",
ClientCodeNewRequest::getMoneyAccountId, // ClientCodeNewRequest::getMoneyAccountId,
IMDGDistributedNames.Map_Account, // IMDGDistributedNames.Map_Account,
Account.class, // Account.class,
AccountError.RequiredFieldEmpty, // AccountError.RequiredFieldEmpty,
AccountError.AccountNotFound, // AccountError.AccountNotFound,
false, // false,
acc -> Objects.equals(context.getValidatedObject().getCompanyId(), acc.getCompanyId()) // acc -> Objects.equals(context.getValidatedObject().getCompanyId(), acc.getCompanyId())
? null : AccountError.AccountNotFound // ? null : AccountError.AccountNotFound
), // ),
IdPresentRule.instance("depoAccountId", // IdPresentRule.instance("depoAccountId",
ClientCodeNewRequest::getDepoAccountId, // ClientCodeNewRequest::getDepoAccountId,
IMDGDistributedNames.Map_Account, // IMDGDistributedNames.Map_Account,
Account.class, // Account.class,
AccountError.RequiredFieldEmpty, // AccountError.RequiredFieldEmpty,
AccountError.AccountNotFound, // AccountError.AccountNotFound,
false, // false,
acc -> Objects.equals(context.getValidatedObject().getCompanyId(), acc.getCompanyId()) // acc -> Objects.equals(context.getValidatedObject().getCompanyId(), acc.getCompanyId())
? null : AccountError.AccountNotFound // ? null : AccountError.AccountNotFound
), // ),
BackendClientCodeValidationRule.AllAccountsPresent, // BackendClientCodeValidationRule.AllAccountsPresent,
BackendClientCodeValidationRule.TcrIsNotPresentByAccount, BackendClientCodeValidationRule.TcrIsNotPresentByAccount,
DictionaryPresentRule.instance("status", DictionaryPresentRule.instance("status",
ClientCodeNewRequest::getStatus, ClientCodeNewRequest::getStatus,
@ -111,28 +109,28 @@ public class ClientCodeValidationConfig {
Company.class, Company.class,
AccountError.RequiredFieldEmpty, AccountError.RequiredFieldEmpty,
AccountError.CompanyNotFound), AccountError.CompanyNotFound),
//
IdPresentRule.instance("moneyAccountId", // IdPresentRule.instance("moneyAccountId",
ClientCodeUpdateRequest::getMoneyAccountId, // ClientCodeUpdateRequest::getMoneyAccountId,
IMDGDistributedNames.Map_Account, // IMDGDistributedNames.Map_Account,
Account.class, // Account.class,
AccountError.RequiredFieldEmpty, // AccountError.RequiredFieldEmpty,
AccountError.AccountNotFound, // AccountError.AccountNotFound,
false, // false,
acc -> Objects.equals(context.getValidatedObject().getCompanyId(), acc.getCompanyId()) // acc -> Objects.equals(context.getValidatedObject().getCompanyId(), acc.getCompanyId())
? null : AccountError.AccountNotFound // ? null : AccountError.AccountNotFound
), // ),
IdPresentRule.instance("depoAccountId", // IdPresentRule.instance("depoAccountId",
ClientCodeUpdateRequest::getDepoAccountId, // ClientCodeUpdateRequest::getDepoAccountId,
IMDGDistributedNames.Map_Account, // IMDGDistributedNames.Map_Account,
Account.class, // Account.class,
AccountError.RequiredFieldEmpty, // AccountError.RequiredFieldEmpty,
AccountError.AccountNotFound, // AccountError.AccountNotFound,
false, // false,
acc -> Objects.equals(context.getValidatedObject().getCompanyId(), acc.getCompanyId()) // acc -> Objects.equals(context.getValidatedObject().getCompanyId(), acc.getCompanyId())
? null : AccountError.AccountNotFound // ? null : AccountError.AccountNotFound
), // ),
BackendClientCodeValidationRule.AllAccountsPresent, // BackendClientCodeValidationRule.AllAccountsPresent,
DictionaryPresentRule.instance("stauts", DictionaryPresentRule.instance("stauts",
ClientCodeUpdateRequest::getStatus, ClientCodeUpdateRequest::getStatus,
IMDGDistributedNames.Map_ServiceStatusDictionary, IMDGDistributedNames.Map_ServiceStatusDictionary,
@ -172,6 +170,8 @@ public class ClientCodeValidationConfig {
addImdg.accept(IMDGDistributedNames.Map_CompanySymbols); addImdg.accept(IMDGDistributedNames.Map_CompanySymbols);
addImdg.accept(IMDGDistributedNames.Map_Account); addImdg.accept(IMDGDistributedNames.Map_Account);
addImdg.accept(IMDGDistributedNames.Map_TradingClearingRegistry); addImdg.accept(IMDGDistributedNames.Map_TradingClearingRegistry);
addImdg.accept(IMDGDistributedNames.Map_AccountSymbols);
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),
GatewayClientCodeValidationRule.CompanyPresent, GatewayClientCodeValidationRule.CompanyPresent,

View file

@ -436,7 +436,7 @@ public class ClientCodeService extends QueueConsumer implements InitializingBean
request.setRequestPayload(requestPayload); request.setRequestPayload(requestPayload);
// Следующий вызываемый метод обязательно должен быть synchronized. // Следующий вызываемый метод обязательно должен быть synchronized.
RequestInfoUpdate reply = tradingClearingRegistryService.tradingClearingRegistryNew(request); RequestInfoUpdate reply = tradingClearingRegistryService.tradingClearingRegistryNew(request, true);
if (reply != null && Status.Error.equals(reply.getStatus())) { if (reply != null && Status.Error.equals(reply.getStatus())) {
log.warn("tradingClearingRegistryService return error: " + reply.getMessage()); log.warn("tradingClearingRegistryService return error: " + reply.getMessage());
} }

View file

@ -143,7 +143,7 @@ public class TradingClearingRegistryService extends QueueConsumer implements Ini
.setFunction(this::tradingClearingRegistryAutoNew) .setFunction(this::tradingClearingRegistryAutoNew)
.forDestination(Consts.DESTINATION_TRADING_CLEARING_REGISTRY_AUTO_NEW, callbacks::put); .forDestination(Consts.DESTINATION_TRADING_CLEARING_REGISTRY_AUTO_NEW, callbacks::put);
callback(TradingClearingRegistryNewRequest.class) callback(TradingClearingRegistryNewRequest.class)
.setFunction(this::tradingClearingRegistryNew) .setFunction(tkrReq -> tradingClearingRegistryNew(tkrReq, true))
.forDestination(Consts.DESTINATION_TRADING_CLEARING_REGISTRY_NEW, callbacks::put); .forDestination(Consts.DESTINATION_TRADING_CLEARING_REGISTRY_NEW, callbacks::put);
callback(TradingClearingRegistryUpdateRequest.class) callback(TradingClearingRegistryUpdateRequest.class)
.setFunction(this::tradingClearingRegistryUpdate) .setFunction(this::tradingClearingRegistryUpdate)
@ -318,7 +318,8 @@ public class TradingClearingRegistryService extends QueueConsumer implements Ini
return null; return null;
} }
public synchronized RequestInfoUpdate tradingClearingRegistryNew(BaseRequest<TradingClearingRegistryNewRequest> userRequest) { public synchronized RequestInfoUpdate tradingClearingRegistryNew(BaseRequest<TradingClearingRegistryNewRequest> userRequest,
boolean sentToGateway) {
log.debug("TradingClearingRegistryNewRequest received"); log.debug("TradingClearingRegistryNewRequest received");
RequestInfoUpdate requestInfoUpdate = userRoleVerification.validateRoleAndGetResult(userRequest); RequestInfoUpdate requestInfoUpdate = userRoleVerification.validateRoleAndGetResult(userRequest);
if (requestInfoUpdate != null) { if (requestInfoUpdate != null) {
@ -341,6 +342,25 @@ public class TradingClearingRegistryService extends QueueConsumer implements Ini
} }
} }
TradingClearingRegistry tradingClearingRegistry = createTkr(req);
if (sentToGateway) {
Optional<Tkr> tkr = createRequestToGateway(tradingClearingRegistry);
if (tkr.isPresent()) {
SendTkrRequest sendTkrRequest = new SendTkrRequest();
sendTkrRequest.getTkrs().add(tkr.get());
kafkaSender.sendRequestToQueue(Consts.ACCOUNTS_TO_GATEWAY, sendTkrRequest);
}
sendNotificationToReportSvc(tradingClearingRegistry);
sendNotificationToClearingSvc(tradingClearingRegistry);
}
log.debug("successfully processed, id {}", tradingClearingRegistry.getId());
return null;
}
public TradingClearingRegistry createTkr(TradingClearingRegistryNewRequest req) {
// Дополнительная проверка
Long id = tradingClearingRegistryImdg.nextIDSequenceFor(); Long id = tradingClearingRegistryImdg.nextIDSequenceFor();
TradingClearingRegistry tradingClearingRegistry = new TradingClearingRegistry(); TradingClearingRegistry tradingClearingRegistry = new TradingClearingRegistry();
tradingClearingRegistry.setId(id); tradingClearingRegistry.setId(id);
@ -386,20 +406,8 @@ public class TradingClearingRegistryService extends QueueConsumer implements Ini
tradingClearingRegistryImdg.insert(tradingClearingRegistry); tradingClearingRegistryImdg.insert(tradingClearingRegistry);
log.info("New TCR.id={} was created.", tradingClearingRegistry.getId()); log.info("New TCR.id={} was created.", tradingClearingRegistry.getId());
Optional<Tkr> tkr = createRequestToGateway(tradingClearingRegistry); return tradingClearingRegistry;
if (tkr.isPresent()) {
SendTkrRequest sendTkrRequest = new SendTkrRequest();
sendTkrRequest.getTkrs().add(tkr.get());
kafkaSender.sendRequestToQueue(Consts.ACCOUNTS_TO_GATEWAY, sendTkrRequest);
}
sendNotificationToReportSvc(tradingClearingRegistry);
sendNotificationToClearingSvc(tradingClearingRegistry);
log.debug("successfully processed, id {}", id);
return null;
} }
protected Long companySequenceNextId(Long companyId, TradingClearingRegistryPurpose registryPurpose, String tradingRegistryType) { protected Long companySequenceNextId(Long companyId, TradingClearingRegistryPurpose registryPurpose, String tradingRegistryType) {
ImdgPredicateBuilder pb = tradingClearingRegistryImdg.predicateBuilder(); ImdgPredicateBuilder pb = tradingClearingRegistryImdg.predicateBuilder();
Collection<TradingClearingRegistry> existTCR = tradingClearingRegistryImdg.getCollectionObjectsByPredicate( Collection<TradingClearingRegistry> existTCR = tradingClearingRegistryImdg.getCollectionObjectsByPredicate(

View file

@ -3,6 +3,7 @@ package ru.spcex.clearing.account.service.v2.facade;
import java.time.Instant; import java.time.Instant;
import java.util.Collection; import java.util.Collection;
import java.util.Map; import java.util.Map;
import java.util.Optional;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -13,7 +14,6 @@ import ru.clearing.classes.statics.data.misc.Currency;
import ru.spcex.clearing.account.service.AccountHelper; import ru.spcex.clearing.account.service.AccountHelper;
import ru.spcex.clearing.account.service.InformationAccountService; import ru.spcex.clearing.account.service.InformationAccountService;
import ru.spcex.clearing.imdg.IMDGDistributedNames; 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.clearing.platform.messaging.domain.cud.gateway.MoneyAccountMsgRequest;
import ru.spcex.platform.classes.base.interfaces.IClearingFacade; import ru.spcex.platform.classes.base.interfaces.IClearingFacade;
import ru.spcex.platform.enumeration.AccountType; import ru.spcex.platform.enumeration.AccountType;
@ -55,62 +55,60 @@ public class AccountFacade implements IClearingFacade {
this.tradingClearingRegistryListFacade = tradingClearingRegistryListFacade; this.tradingClearingRegistryListFacade = tradingClearingRegistryListFacade;
} }
public void createInfoAccount(TkrAccount account, Company company) { public Optional<InformationAccount> createInfoAccount(MoneyAccountMsgRequest moneyAccountMsgRequest, Company company) {
for (MoneyAccountMsgRequest moneyAccountMsgRequest : account.getMoneyAccounts()) { String currencyCode = moneyAccountMsgRequest.getCurrCode() == null ? CurrencyCode.RUB.getKey() : moneyAccountMsgRequest.getCurrCode();
String currencyCode = moneyAccountMsgRequest.getCurrCode() == null ? CurrencyCode.RUB.getKey() : moneyAccountMsgRequest.getCurrCode(); ImdgPredicateBuilder predicateBuilder = currencyImdg.predicateBuilder();
ImdgPredicateBuilder predicateBuilder = currencyImdg.predicateBuilder(); Currency currency = currencyImdg.getFirstObjectByPredicate(
Currency currency = currencyImdg.getFirstObjectByPredicate( predicateBuilder.equals("currencyCode", currencyCode)
predicateBuilder.equals("currencyCode", currencyCode) );
);
Long currencyCodeId = CurrencyCode.RUB.getKey().equals(currencyCode) ? 810 : currency.getId(); Long currencyCodeId = CurrencyCode.RUB.getKey().equals(currencyCode) ? 810 : currency.getId();
Instant now = Instant.now(); Instant now = Instant.now();
Account infoAccount = new Account(); Account infoAccount = new Account();
infoAccount.setCompanyId(company.getId()); infoAccount.setCompanyId(company.getId());
infoAccount.setAccount(moneyAccountMsgRequest.getEks_account()); 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);
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);
accountImdg.insert(infoAccount);
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());
Long infoId = informationAccountImdg.insert(infoAcc);
log.debug("For account id={} make InformationAccount id={}", infoAccount.getId(), infoId);
return Optional.of(infoAcc);
} }
public void lock() { public void lock() {

View file

@ -39,7 +39,7 @@ public class ClientCodeFacade implements IClearingFacade {
/** /**
* Создает clientCode, TCR и опционально TCRList, если указаны валюты. * Создает clientCode, TCR и опционально TCRList, если указаны валюты.
*/ */
public void createClientCode(ClientCodeNewRequest request, IValidator validator) { public void createClientCode(ClientCodeNewRequest request, IValidator validator, boolean isClearingAcc) {
log.trace("Start process creating new client code"); log.trace("Start process creating new client code");
TradingClearingRegistry tradingClearingRegistry; TradingClearingRegistry tradingClearingRegistry;
{ {
@ -49,7 +49,7 @@ public class ClientCodeFacade implements IClearingFacade {
creationTcrRequest.setMoneyAccountId(request.getMoneyAccountId()); creationTcrRequest.setMoneyAccountId(request.getMoneyAccountId());
creationTcrRequest.setDepoAccountId(request.getDepoAccountId()); creationTcrRequest.setDepoAccountId(request.getDepoAccountId());
creationTcrRequest.setTradingClearingRegistryType(TradingClearingRegistryType.Client_B.getKey()); creationTcrRequest.setTradingClearingRegistryType(TradingClearingRegistryType.Client_B.getKey());
tradingClearingRegistry = tradingClearingRegistryFacade.createTradingClearingRegistry(creationTcrRequest, null); tradingClearingRegistry = tradingClearingRegistryFacade.createTradingClearingRegistry(creationTcrRequest, null, isClearingAcc);
} }
{ {
if (request.getCurrencyAccountList() != null && !request.getCurrencyAccountList().isEmpty()) { if (request.getCurrencyAccountList() != null && !request.getCurrencyAccountList().isEmpty()) {

View file

@ -8,6 +8,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import ru.clearing.classes.statics.data.account.ClearingAccount; import ru.clearing.classes.statics.data.account.ClearingAccount;
import ru.clearing.classes.statics.data.account.DepoAccount; import ru.clearing.classes.statics.data.account.DepoAccount;
import ru.clearing.classes.statics.data.account.InformationAccount;
import ru.clearing.classes.statics.data.company.Company; import ru.clearing.classes.statics.data.company.Company;
import ru.clearing.classes.statics.data.registry.TradingClearingRegistry; import ru.clearing.classes.statics.data.registry.TradingClearingRegistry;
import ru.spcex.clearing.account.model.TradingClearingRegistryBusiness; import ru.spcex.clearing.account.model.TradingClearingRegistryBusiness;
@ -34,6 +35,7 @@ public class TradingClearingRegistryFacade {
private final Imdg<TradingClearingRegistry> tradingClearingRegistryImdg; private final Imdg<TradingClearingRegistry> tradingClearingRegistryImdg;
private final Imdg<DepoAccount> depoAccountImdg; private final Imdg<DepoAccount> depoAccountImdg;
private final Imdg<ClearingAccount> clearingAccountImdg; private final Imdg<ClearingAccount> clearingAccountImdg;
private final Imdg<InformationAccount> informationAccountImdg;
private final Imdg<Company> companyImdg; private final Imdg<Company> companyImdg;
public TradingClearingRegistryFacade(ImdgProvider imdgProvider, public TradingClearingRegistryFacade(ImdgProvider imdgProvider,
@ -43,12 +45,14 @@ public class TradingClearingRegistryFacade {
TradingClearingRegistry.class); TradingClearingRegistry.class);
this.depoAccountImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_DepoAccount, DepoAccount.class); this.depoAccountImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_DepoAccount, DepoAccount.class);
this.clearingAccountImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_ClearingAccount, ClearingAccount.class); this.clearingAccountImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_ClearingAccount, ClearingAccount.class);
this.informationAccountImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_InformationAccount, InformationAccount.class);
this.companyImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Company, Company.class); this.companyImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Company, Company.class);
this.kafkaSender = kafkaSender; this.kafkaSender = kafkaSender;
} }
public TradingClearingRegistry createTradingClearingRegistry(TradingClearingRegistryNewRequest request, public TradingClearingRegistry createTradingClearingRegistry(TradingClearingRegistryNewRequest request,
IValidator validator) { IValidator validator,
boolean isClearingAcc) {
Long id = tradingClearingRegistryImdg.nextIDSequenceFor(); Long id = tradingClearingRegistryImdg.nextIDSequenceFor();
TradingClearingRegistry tradingClearingRegistry = new TradingClearingRegistry(); TradingClearingRegistry tradingClearingRegistry = new TradingClearingRegistry();
tradingClearingRegistry.setId(id); tradingClearingRegistry.setId(id);
@ -58,8 +62,15 @@ public class TradingClearingRegistryFacade {
DepoAccount depoAccount = request.getDepoAccountId() != null ? DepoAccount depoAccount = request.getDepoAccountId() != null ?
depoAccountImdg.getFirstObjectByFieldValues(Map.of("accountId", request.getDepoAccountId())) : null; depoAccountImdg.getFirstObjectByFieldValues(Map.of("accountId", request.getDepoAccountId())) : null;
ClearingAccount clearingAccount = request.getMoneyAccountId() != null ?
clearingAccountImdg.getFirstObjectByFieldValues(Map.of("accountId", request.getMoneyAccountId())) : null; String tradingRegistryType = TradingClearingRegistryType.Owner_A.getKey();
if (isClearingAcc) {
ClearingAccount clearingAccount = request.getMoneyAccountId() != null ?
clearingAccountImdg.getFirstObjectByFieldValues(Map.of("accountId", request.getMoneyAccountId())) : null;
if (clearingAccount != null) {
tradingRegistryType = clearingAccount.getClearingAccountType();
}
}
if (request.getStatus() == null) { if (request.getStatus() == null) {
tradingClearingRegistry.setStatus(ServiceStatus.Active.getKey()); tradingClearingRegistry.setStatus(ServiceStatus.Active.getKey());
@ -69,14 +80,10 @@ public class TradingClearingRegistryFacade {
log.trace("TCR status in request set: {}", tradingClearingRegistry.getStatus()); log.trace("TCR status in request set: {}", tradingClearingRegistry.getStatus());
} }
String tradingRegistryType;
if (request.getTradingClearingRegistryType() != null) { if (request.getTradingClearingRegistryType() != null) {
tradingRegistryType = request.getTradingClearingRegistryType(); tradingRegistryType = request.getTradingClearingRegistryType();
} else if (depoAccount != null) { } else if (depoAccount != null) {
tradingRegistryType = depoAccount.getDepoAccountType(); tradingRegistryType = depoAccount.getDepoAccountType();
} else {
if (clearingAccount != null) tradingRegistryType = clearingAccount.getClearingAccountType();
else tradingRegistryType = TradingClearingRegistryType.Owner_A.getKey();
} }
tradingClearingRegistry.setTradingClearingRegistryType(tradingRegistryType); tradingClearingRegistry.setTradingClearingRegistryType(tradingRegistryType);

View file

@ -1,5 +1,6 @@
package ru.spcex.clearing.account.service.v2.listeners; package ru.spcex.clearing.account.service.v2.listeners;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -12,9 +13,12 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import ru.clearing.classes.statics.data.account.Account; import ru.clearing.classes.statics.data.account.Account;
import ru.clearing.classes.statics.data.account.DepoAccount;
import ru.clearing.classes.statics.data.account.InformationAccount;
import ru.clearing.classes.statics.data.company.Company; import ru.clearing.classes.statics.data.company.Company;
import ru.clearing.classes.statics.data.registry.TradingClearingRegistry; import ru.clearing.classes.statics.data.registry.TradingClearingRegistry;
import ru.spcex.clearing.account.model.ValidationResult; import ru.spcex.clearing.account.model.ValidationResult;
import ru.spcex.clearing.account.service.TradingClearingRegistryService;
import ru.spcex.clearing.account.service.v2.GatewayRequestCreator; 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.AccountFacade;
import ru.spcex.clearing.account.service.v2.facade.ClientCodeFacade; import ru.spcex.clearing.account.service.v2.facade.ClientCodeFacade;
@ -26,6 +30,7 @@ import ru.spcex.clearing.platform.messaging.domain.Consts;
import ru.spcex.clearing.platform.messaging.domain.cud.account.ClientCodeNewRequest; import ru.spcex.clearing.platform.messaging.domain.cud.account.ClientCodeNewRequest;
import ru.spcex.clearing.platform.messaging.domain.cud.account.TkrAccount; import ru.spcex.clearing.platform.messaging.domain.cud.account.TkrAccount;
import ru.spcex.clearing.platform.messaging.domain.cud.account.TkrAccountsGatewayRequest; import ru.spcex.clearing.platform.messaging.domain.cud.account.TkrAccountsGatewayRequest;
import ru.spcex.clearing.platform.messaging.domain.cud.gateway.MoneyAccountMsgRequest;
import ru.spcex.clearing.platform.messaging.domain.cud.gateway.SendTkrRequest; import ru.spcex.clearing.platform.messaging.domain.cud.gateway.SendTkrRequest;
import ru.spcex.clearing.platform.messaging.domain.cud.gateway.Tkr; import ru.spcex.clearing.platform.messaging.domain.cud.gateway.Tkr;
import ru.spcex.clearing.platform.messaging.service.QueueConsumer; import ru.spcex.clearing.platform.messaging.service.QueueConsumer;
@ -49,6 +54,7 @@ public class ClientCodeMessageListener extends QueueConsumer implements Initiali
private final GatewayRequestCreator gatewayRequestCreator; private final GatewayRequestCreator gatewayRequestCreator;
private final UserRoleVerification userRoleVerification; private final UserRoleVerification userRoleVerification;
private final AccountFacade accountFacade; private final AccountFacade accountFacade;
private final TradingClearingRegistryService tradingClearingRegistryService;
public ClientCodeMessageListener(Consumer<String, Object> kafkaQueue, public ClientCodeMessageListener(Consumer<String, Object> kafkaQueue,
Producer<String, Object> kafkaProducer, Producer<String, Object> kafkaProducer,
@ -58,7 +64,8 @@ public class ClientCodeMessageListener extends QueueConsumer implements Initiali
ClientCodeValidator clientCodeValidator, ClientCodeValidator clientCodeValidator,
GatewayRequestCreator gatewayRequestCreator, GatewayRequestCreator gatewayRequestCreator,
UserRoleVerification userRoleVerification, UserRoleVerification userRoleVerification,
AccountFacade accountFacade) { AccountFacade accountFacade,
TradingClearingRegistryService tradingClearingRegistryService) {
super(kafkaQueue, kafkaProducer); super(kafkaQueue, kafkaProducer);
this.kafkaSender = kafkaSender; this.kafkaSender = kafkaSender;
this.imdgProvider = imdgProvider; this.imdgProvider = imdgProvider;
@ -67,6 +74,7 @@ public class ClientCodeMessageListener extends QueueConsumer implements Initiali
this.gatewayRequestCreator = gatewayRequestCreator; this.gatewayRequestCreator = gatewayRequestCreator;
this.userRoleVerification = userRoleVerification; this.userRoleVerification = userRoleVerification;
this.accountFacade = accountFacade; this.accountFacade = accountFacade;
this.tradingClearingRegistryService = tradingClearingRegistryService;
} }
@Override @Override
@ -186,7 +194,7 @@ public class ClientCodeMessageListener extends QueueConsumer implements Initiali
.map(currencyCodeAccountEntry -> currencyCodeAccountEntry.getValue().getId()) .map(currencyCodeAccountEntry -> currencyCodeAccountEntry.getValue().getId())
.toList(); .toList();
clientCodeNewRequest.setCurrencyAccountList(foreignCurrencyList); clientCodeNewRequest.setCurrencyAccountList(foreignCurrencyList);
clientCodeFacade.createClientCode(clientCodeNewRequest, validator); clientCodeFacade.createClientCode(clientCodeNewRequest, validator, true);
TradingClearingRegistry tradingClearingRegistry = selectTradingClearingRegistry(company.getId(), TradingClearingRegistry tradingClearingRegistry = selectTradingClearingRegistry(company.getId(),
moneyAccount.getId(), depoAccountId); moneyAccount.getId(), depoAccountId);
@ -204,33 +212,30 @@ public class ClientCodeMessageListener extends QueueConsumer implements Initiali
ValidationResult validationResult = entry.getValue(); ValidationResult validationResult = entry.getValue();
IValidator validator = validationResult.validator(); IValidator validator = validationResult.validator();
Company company = validator.getStored(ClientCodeStoreObjects.COMPANY); Company company = validator.getStored(ClientCodeStoreObjects.COMPANY);
accountFacade.createInfoAccount(tkrAccount, company); Optional<DepoAccount> depoAccount = validator.getStored(ClientCodeStoreObjects.DEPO_ACCOUNT);
Long depoAccountId = depoAccount.map(DepoAccount::getId).orElse(null);
List<Long> accountIds = new ArrayList<>();
List<Long> infoAccsId = new ArrayList<>();
for (MoneyAccountMsgRequest account : tkrAccount.getMoneyAccounts()) {
Optional<InformationAccount> infoAccId = accountFacade.createInfoAccount(account, company);
if (infoAccId.isPresent()) {
accountIds.add(infoAccId.get().getAccountId());
infoAccsId.add(infoAccId.get().getId());
} else {
log.error("Can't create info account for account: {}", tkrAccount.getClientCode());
}
}
ClientCodeNewRequest clientCodeNewRequest = new ClientCodeNewRequest(); ClientCodeNewRequest clientCodeNewRequest = new ClientCodeNewRequest();
log.debug("Creating new clientCode by tkr account: {}", tkrAccount.getClientCode()); log.debug("Creating new clientCode by tkr account: {}", tkrAccount.getClientCode());
Optional<Account> depoAccount = validator.getStored(ClientCodeStoreObjects.DEPO_ACCOUNT); clientCodeNewRequest.setCompanyId(company.getId());
Long depoAccountId = depoAccount.map(Account::getId).orElse(null); clientCodeNewRequest.setCode(tkrAccount.getClientCode());
// Map<String, Account> accountByCurrency = validator.getStored(ClientCodeStoreObjects.MAPPED_TO_CURRENCY_ACCOUNTS); clientCodeNewRequest.setMoneyAccountId(accountIds.get(0));
// clientCodeNewRequest.setDepoAccountId(depoAccountId);
// clientCodeNewRequest.setCompanyId(company.getId()); clientCodeNewRequest.setCurrencyAccountList(accountIds);
// clientCodeNewRequest.setCode(tkrAccount.getClientCode()); clientCodeFacade.createClientCode(clientCodeNewRequest, validator, false);
// 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());
} }
} }
@ -243,7 +248,7 @@ public class ClientCodeMessageListener extends QueueConsumer implements Initiali
return makeErrorResponse(clientCodeNewRequest, validationResult); return makeErrorResponse(clientCodeNewRequest, validationResult);
} }
clientCodeFacade.createClientCode(request, validationResult.validator()); clientCodeFacade.createClientCode(request, validationResult.validator(), true);
return null; return null;
} }

View file

@ -96,7 +96,7 @@ public enum GatewayEksClientCodeValidationRule implements IValidationRule<ImdgVa
return of(AccountError.DepoAccountNotFound, "depo_account"); return of(AccountError.DepoAccountNotFound, "depo_account");
} }
context.storeObject(ClientCodeStoreObjects.DEPO_ACCOUNT, depoAccount); context.storeObject(ClientCodeStoreObjects.DEPO_ACCOUNT, Optional.of(depoAccount));
return Optional.empty(); return Optional.empty();
} }
}; };