This commit is contained in:
parent
e2bcf7d117
commit
568f29a62a
5 changed files with 61 additions and 52 deletions
|
|
@ -13,7 +13,6 @@ import org.springframework.util.StringUtils;
|
||||||
import ru.clearing.classes.statics.data.account.Account;
|
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.classes.statics.data.company.CompanySymbols;
|
|
||||||
import ru.clearing.classes.statics.data.registry.TradingClearingRegistry;
|
import ru.clearing.classes.statics.data.registry.TradingClearingRegistry;
|
||||||
import ru.clearing.platform.dictionary.ServiceStatusDictionary;
|
import ru.clearing.platform.dictionary.ServiceStatusDictionary;
|
||||||
import ru.spcex.clearing.account.errors.AccountError;
|
import ru.spcex.clearing.account.errors.AccountError;
|
||||||
|
|
@ -28,7 +27,6 @@ import ru.spcex.clearing.validation.common.rules.DictionaryPresentRule;
|
||||||
import ru.spcex.clearing.validation.common.rules.FieldRequiredRule;
|
import ru.spcex.clearing.validation.common.rules.FieldRequiredRule;
|
||||||
import ru.spcex.clearing.validation.common.rules.IdPresentRule;
|
import ru.spcex.clearing.validation.common.rules.IdPresentRule;
|
||||||
import ru.spcex.platform.classes.base.SpcexObjectBase;
|
import ru.spcex.platform.classes.base.SpcexObjectBase;
|
||||||
import ru.spcex.platform.enumeration.CompanySymbol;
|
|
||||||
import ru.spcex.platform.enumeration.CurrencyCode;
|
import ru.spcex.platform.enumeration.CurrencyCode;
|
||||||
import ru.spcex.platform.enumeration.Status;
|
import ru.spcex.platform.enumeration.Status;
|
||||||
import ru.spcex.platform.imdg.api.Imdg;
|
import ru.spcex.platform.imdg.api.Imdg;
|
||||||
|
|
@ -180,23 +178,24 @@ public class ClientCodeValidationConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean("tkrAccountsGatewayValidator")
|
@Bean("tkrAccountsGatewayValidator")
|
||||||
public Function<TkrAccount, IValidator> tkrAccountsGatewayValidator(Map<String, Imdg<? extends SpcexObjectBase>> imdgForValidation) {
|
public Function<TkrAccount, IValidator> newTkrAccountsGatewayValidator(Map<String, Imdg<? extends SpcexObjectBase>> imdgForValidation) {
|
||||||
return tkrGatewayRequest -> {
|
return tkrGatewayRequest -> {
|
||||||
ImdgValidationContext<TkrAccount> context = new ImdgValidationContext<>();
|
ImdgValidationContext<TkrAccount> context = new ImdgValidationContext<>();
|
||||||
context.setValidatedObject(tkrGatewayRequest);
|
context.setValidatedObject(tkrGatewayRequest);
|
||||||
Consumer<String> addImdg = (s) -> context.addImdg(s, imdgForValidation.get(s));
|
Consumer<String> addImdg = (s) -> context.addImdg(s, imdgForValidation.get(s));
|
||||||
|
addImdg.accept(IMDGDistributedNames.Map_Company);
|
||||||
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);
|
||||||
return new ValidatorImpl<>(context,
|
return new ValidatorImpl<>(context,
|
||||||
new ExistCompanyByUuid<>("companySymbolValue",
|
FieldRequiredRule.instance("client_code", TkrAccount::getClientCode, AccountError.RequiredFieldEmpty),
|
||||||
TkrAccount::getCompanyId),
|
new ExistCompanyByTradingCode<>("trading_code",
|
||||||
new ExistAccountByValue<>("account",
|
TkrAccount::getTradingCode),
|
||||||
|
new ExistAccountByValue<>("money_account",
|
||||||
TkrAccount::getMoneyAccounts),
|
TkrAccount::getMoneyAccounts),
|
||||||
new ExistDepoAccountByValue<>("depo_account",
|
new ExistDepoAccountByValue<>("depo_account",
|
||||||
TkrAccount::getDepoAccount),
|
TkrAccount::getDepoAccount),
|
||||||
new ExistTcrByCode<>("tcr_code",
|
new ExistTcrByCode<>("tcr_code")
|
||||||
TkrAccount::getTkrCode)
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -238,26 +237,24 @@ public class ClientCodeValidationConfig {
|
||||||
|
|
||||||
public static class ExistTcrByCode<R> implements IValidationRule<ImdgValidationContext<R>> {
|
public static class ExistTcrByCode<R> implements IValidationRule<ImdgValidationContext<R>> {
|
||||||
String fieldName;
|
String fieldName;
|
||||||
Function<R, String> codeGetter;
|
|
||||||
|
|
||||||
public ExistTcrByCode(String fieldName, Function<R, String> codeGetter) {
|
public ExistTcrByCode(String fieldName) {
|
||||||
this.fieldName = fieldName;
|
this.fieldName = fieldName;
|
||||||
this.codeGetter = codeGetter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<EnumMessage> validate(ImdgValidationContext<R> context) {
|
public Optional<EnumMessage> validate(ImdgValidationContext<R> context) {
|
||||||
R validatedObject = context.getValidatedObject();
|
Map<String, Account> accountByCurrency = context.getStoredObject(ClientCodeStoreObjects.MAPPED_TO_CURRENCY_ACCOUNTS);
|
||||||
String tcrCode = codeGetter.apply(validatedObject);
|
Account moneyAccount = accountByCurrency.get(CurrencyCode.RUB.getKey());
|
||||||
if (!StringUtils.hasText(tcrCode)) {
|
if (moneyAccount == null) {
|
||||||
return of(AccountError.RequiredFieldEmpty, fieldName);
|
return of(AccountError.AccountNotFound, fieldName);
|
||||||
}
|
}
|
||||||
Imdg<TradingClearingRegistry> imdg = context.obtainMap(IMDGDistributedNames.Map_TradingClearingRegistry,
|
Imdg<TradingClearingRegistry> imdg = context.obtainMap(IMDGDistributedNames.Map_TradingClearingRegistry,
|
||||||
TradingClearingRegistry.class);
|
TradingClearingRegistry.class);
|
||||||
|
|
||||||
TradingClearingRegistry tcr = imdg.getFirstObjectByFieldValues(
|
TradingClearingRegistry tcr = imdg.getFirstObjectByFieldValues(
|
||||||
Map.of(
|
Map.of(
|
||||||
"code", tcrCode,
|
"moneyAccountId", moneyAccount.getId(),
|
||||||
"status", Status.Active.getKey()
|
"status", Status.Active.getKey()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
@ -273,35 +270,27 @@ public class ClientCodeValidationConfig {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ExistCompanyByUuid<R> implements IValidationRule<ImdgValidationContext<R>> {
|
public static class ExistCompanyByTradingCode<R> implements IValidationRule<ImdgValidationContext<R>> {
|
||||||
String fieldName;
|
String fieldName;
|
||||||
Function<R, String> symbolCodeGetter;
|
Function<R, Long> tradingCodeGetter;
|
||||||
|
|
||||||
public ExistCompanyByUuid(String fieldName, Function<R, String> symbolCodeGetter) {
|
public ExistCompanyByTradingCode(String fieldName, Function<R, Long> tradingCodeGetter) {
|
||||||
this.fieldName = fieldName;
|
this.fieldName = fieldName;
|
||||||
this.symbolCodeGetter = symbolCodeGetter;
|
this.tradingCodeGetter = tradingCodeGetter;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<EnumMessage> validate(ImdgValidationContext<R> context) {
|
public Optional<EnumMessage> validate(ImdgValidationContext<R> context) {
|
||||||
R validatedObject = context.getValidatedObject();
|
R validatedObject = context.getValidatedObject();
|
||||||
String symbolCodeValue = symbolCodeGetter.apply(validatedObject);
|
Long tradingCode = tradingCodeGetter.apply(validatedObject);
|
||||||
if (!StringUtils.hasText(symbolCodeValue)) {
|
if (tradingCode == null) {
|
||||||
return of(AccountError.RequiredFieldEmpty, fieldName);
|
return of(AccountError.RequiredFieldEmpty, fieldName);
|
||||||
}
|
}
|
||||||
Imdg<CompanySymbols> imdg = context.obtainMap(IMDGDistributedNames.Map_CompanySymbols, CompanySymbols.class);
|
|
||||||
CompanySymbols companySymbols = imdg.getFirstObjectByFieldValues(
|
|
||||||
Map.of(
|
|
||||||
"companySymbol", CompanySymbol.UUID.getKey(),
|
|
||||||
"companySymbolValue", symbolCodeValue
|
|
||||||
)
|
|
||||||
);
|
|
||||||
if (companySymbols == null) {
|
|
||||||
return of(AccountError.COMPANY_NOT_FOUND_GTW, fieldName);
|
|
||||||
}
|
|
||||||
|
|
||||||
Imdg<Company> companyImdg = context.obtainMap(IMDGDistributedNames.Map_Company, Company.class);
|
Imdg<Company> companyImdg = context.obtainMap(IMDGDistributedNames.Map_Company, Company.class);
|
||||||
Company company = companyImdg.getSingleObjectByID(companySymbols.getCompanyId());
|
Company company = companyImdg.getFirstObjectByFieldValues(
|
||||||
|
Map.of("trading_code", String.valueOf(tradingCode))
|
||||||
|
);
|
||||||
if (company == null) {
|
if (company == null) {
|
||||||
return of(AccountError.COMPANY_NOT_FOUND_GTW, fieldName);
|
return of(AccountError.COMPANY_NOT_FOUND_GTW, fieldName);
|
||||||
}
|
}
|
||||||
|
|
@ -372,7 +361,7 @@ public class ClientCodeValidationConfig {
|
||||||
String fieldName;
|
String fieldName;
|
||||||
Function<R, String> depoAccountGetter;
|
Function<R, String> depoAccountGetter;
|
||||||
|
|
||||||
public ExistDepoAccountByValue(String fieldName, Function<R, String> accountsListValueGetter) {
|
public ExistDepoAccountByValue(String fieldName, Function<R, String> depoAccountGetter) {
|
||||||
this.fieldName = fieldName;
|
this.fieldName = fieldName;
|
||||||
this.depoAccountGetter = depoAccountGetter;
|
this.depoAccountGetter = depoAccountGetter;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import ru.clearing.classes.statics.data.account.ClientCode;
|
import ru.clearing.classes.statics.data.account.ClientCode;
|
||||||
import ru.clearing.classes.statics.data.registry.TradingClearingRegistry;
|
import ru.clearing.classes.statics.data.registry.TradingClearingRegistry;
|
||||||
import ru.spcex.clearing.account.validation.ClientCodeStoreObjects;
|
|
||||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||||
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.registry.TradingClearingRegistryListNewRequest;
|
import ru.spcex.clearing.platform.messaging.domain.cud.registry.TradingClearingRegistryListNewRequest;
|
||||||
|
|
@ -42,10 +41,9 @@ public class ClientCodeFacade implements IClearingFacade {
|
||||||
*/
|
*/
|
||||||
public void createClientCode(ClientCodeNewRequest request, IValidator validator) {
|
public void createClientCode(ClientCodeNewRequest request, IValidator validator) {
|
||||||
log.trace("Start process creating new client code");
|
log.trace("Start process creating new client code");
|
||||||
TradingClearingRegistry tradingClearingRegistry = validator.getStored(ClientCodeStoreObjects.TRADING_CLEARING_REGISTRY);
|
TradingClearingRegistry tradingClearingRegistry;
|
||||||
if (tradingClearingRegistry == null) {
|
|
||||||
log.debug("Trading Clearing Registry is not exist, creating...");
|
|
||||||
{
|
{
|
||||||
|
log.debug("Trading Clearing Registry is not exist, creating...");
|
||||||
TradingClearingRegistryNewRequest creationTcrRequest = new TradingClearingRegistryNewRequest();
|
TradingClearingRegistryNewRequest creationTcrRequest = new TradingClearingRegistryNewRequest();
|
||||||
creationTcrRequest.setCompanyId(request.getCompanyId());
|
creationTcrRequest.setCompanyId(request.getCompanyId());
|
||||||
creationTcrRequest.setMoneyAccountId(request.getMoneyAccountId());
|
creationTcrRequest.setMoneyAccountId(request.getMoneyAccountId());
|
||||||
|
|
@ -53,7 +51,6 @@ public class ClientCodeFacade implements IClearingFacade {
|
||||||
creationTcrRequest.setTradingClearingRegistryType(TradingClearingRegistryType.Client_B.getKey());
|
creationTcrRequest.setTradingClearingRegistryType(TradingClearingRegistryType.Client_B.getKey());
|
||||||
tradingClearingRegistry = tradingClearingRegistryFacade.createTradingClearingRegistry(creationTcrRequest, null);
|
tradingClearingRegistry = tradingClearingRegistryFacade.createTradingClearingRegistry(creationTcrRequest, null);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
{
|
{
|
||||||
if (request.getCurrencyAccountList() != null && !request.getCurrencyAccountList().isEmpty()) {
|
if (request.getCurrencyAccountList() != null && !request.getCurrencyAccountList().isEmpty()) {
|
||||||
TradingClearingRegistryListNewRequest tcrListNew = new TradingClearingRegistryListNewRequest();
|
TradingClearingRegistryListNewRequest tcrListNew = new TradingClearingRegistryListNewRequest();
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,12 @@ public class TkrService {
|
||||||
.filter(Objects::nonNull)
|
.filter(Objects::nonNull)
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
|
List<TkrAccount> tkrAccountsForUpdate = tkrRequest.getInfoAccount()
|
||||||
|
.stream().filter(infoAccount -> TypeOperations.UPDATE.equalsByKey(infoAccount.getTypeOperationClient()))
|
||||||
|
.map(tkrAdapter::toTkrResponse)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.toList();
|
||||||
|
|
||||||
if (!tkrAccountsForCheck.isEmpty()) {
|
if (!tkrAccountsForCheck.isEmpty()) {
|
||||||
TkrAccountsGatewayRequest tkrAccountsRequest = new TkrAccountsGatewayRequest();
|
TkrAccountsGatewayRequest tkrAccountsRequest = new TkrAccountsGatewayRequest();
|
||||||
tkrAccountsRequest.setRequestId(tkrRequest.getId());
|
tkrAccountsRequest.setRequestId(tkrRequest.getId());
|
||||||
|
|
@ -48,5 +54,12 @@ public class TkrService {
|
||||||
tkrAccountsRequest.setAccounts(tkrAccountsForNew);
|
tkrAccountsRequest.setAccounts(tkrAccountsForNew);
|
||||||
kafkaSender.sendRequestToQueue(Consts.DESTINATION_CLIENT_CODE_NEW_FROM_GATEWAY, tkrAccountsRequest);
|
kafkaSender.sendRequestToQueue(Consts.DESTINATION_CLIENT_CODE_NEW_FROM_GATEWAY, tkrAccountsRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!tkrAccountsForUpdate.isEmpty()) {
|
||||||
|
TkrAccountsGatewayRequest tkrAccountsRequest = new TkrAccountsGatewayRequest();
|
||||||
|
tkrAccountsRequest.setRequestId(tkrRequest.getId());
|
||||||
|
tkrAccountsRequest.setAccounts(tkrAccountsForUpdate);
|
||||||
|
kafkaSender.sendRequestToQueue(Consts.DESTINATION_CLIENT_CODE_UPDATE_FROM_GATEWAY, tkrAccountsRequest);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,12 +8,13 @@ import org.springframework.util.StringUtils;
|
||||||
import ru.spcex.clearing.gatewayapi.controller.inbound.request.tkr.request.InfoAccount;
|
import ru.spcex.clearing.gatewayapi.controller.inbound.request.tkr.request.InfoAccount;
|
||||||
import ru.spcex.clearing.gatewayapi.controller.inbound.request.tkr.request.MoneyAccount;
|
import ru.spcex.clearing.gatewayapi.controller.inbound.request.tkr.request.MoneyAccount;
|
||||||
import ru.spcex.clearing.gatewayapi.enums.TypeOperations;
|
import ru.spcex.clearing.gatewayapi.enums.TypeOperations;
|
||||||
import ru.spcex.clearing.platform.messaging.domain.cud.gateway.MoneyAccountMsgRequest;
|
|
||||||
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.gateway.MoneyAccountMsgRequest;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class TkrAdapter {
|
public class TkrAdapter {
|
||||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||||
|
|
||||||
public TkrAccount toTkrResponse(InfoAccount infoAccount) {
|
public TkrAccount toTkrResponse(InfoAccount infoAccount) {
|
||||||
TkrAccount tkrResponse = new TkrAccount();
|
TkrAccount tkrResponse = new TkrAccount();
|
||||||
tkrResponse.setCompanyId(infoAccount.getCompanyId());
|
tkrResponse.setCompanyId(infoAccount.getCompanyId());
|
||||||
|
|
@ -22,12 +23,20 @@ public class TkrAdapter {
|
||||||
tkrResponse.setEnabled(infoAccount.getEnabled());
|
tkrResponse.setEnabled(infoAccount.getEnabled());
|
||||||
if (TypeOperations.CHECK.equalsByKey(infoAccount.getTypeOperationClient()) &&
|
if (TypeOperations.CHECK.equalsByKey(infoAccount.getTypeOperationClient()) &&
|
||||||
!StringUtils.hasText(infoAccount.getTkrCode())) {
|
!StringUtils.hasText(infoAccount.getTkrCode())) {
|
||||||
log.warn("For check action trk_code is required, skip this account.client_code: {}", infoAccount.getClientCode());
|
log.warn("For check action trk_code is required, skip this account.client_code: {}",
|
||||||
|
infoAccount.getClientCode());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (TypeOperations.ADD.equalsByKey(infoAccount.getTypeOperationClient()) &&
|
if (TypeOperations.ADD.equalsByKey(infoAccount.getTypeOperationClient()) &&
|
||||||
!StringUtils.hasText(infoAccount.getClientCode())){
|
!StringUtils.hasText(infoAccount.getClientCode()) && StringUtils.hasText(infoAccount.getTkrCode())) {
|
||||||
log.warn("For check action client_code is required, skip this account.tkr_code: {}", infoAccount.getTkrCode());
|
log.warn("For add action client_code is required and tkr_code should be empty, skip this account.company_id: {}",
|
||||||
|
infoAccount.getCompanyId());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (TypeOperations.UPDATE.equalsByKey(infoAccount.getTypeOperationClient()) &&
|
||||||
|
!StringUtils.hasText(infoAccount.getClientCode()) && !StringUtils.hasText(infoAccount.getTkrCode())) {
|
||||||
|
log.warn("For update action client_code and tkr_code is required, skip this account.company_id: {}",
|
||||||
|
infoAccount.getCompanyId());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
tkrResponse.setTkrCode(infoAccount.getTkrCode());
|
tkrResponse.setTkrCode(infoAccount.getTkrCode());
|
||||||
|
|
|
||||||
|
|
@ -102,6 +102,7 @@ public interface Consts {
|
||||||
|
|
||||||
String DESTINATION_CLIENT_CODE_NEW = "client-code-new";
|
String DESTINATION_CLIENT_CODE_NEW = "client-code-new";
|
||||||
String DESTINATION_CLIENT_CODE_NEW_FROM_GATEWAY = "client-code-new-from-gateway";
|
String DESTINATION_CLIENT_CODE_NEW_FROM_GATEWAY = "client-code-new-from-gateway";
|
||||||
|
String DESTINATION_CLIENT_CODE_UPDATE_FROM_GATEWAY = "client-code-update-from-gateway";
|
||||||
String DESTINATION_CLIENT_CODE_NEW_UM_COMPANY = "client-code-new-from-api-um-company";
|
String DESTINATION_CLIENT_CODE_NEW_UM_COMPANY = "client-code-new-from-api-um-company";
|
||||||
String DESTINATION_CLIENT_CODE_UPDATE = "client-code-update";
|
String DESTINATION_CLIENT_CODE_UPDATE = "client-code-update";
|
||||||
String DESTINATION_CLIENT_CODE_DELETE = "client-code-delete";
|
String DESTINATION_CLIENT_CODE_DELETE = "client-code-delete";
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue