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.ClientCode;
|
||||
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.platform.dictionary.ServiceStatusDictionary;
|
||||
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.IdPresentRule;
|
||||
import ru.spcex.platform.classes.base.SpcexObjectBase;
|
||||
import ru.spcex.platform.enumeration.CompanySymbol;
|
||||
import ru.spcex.platform.enumeration.CurrencyCode;
|
||||
import ru.spcex.platform.enumeration.Status;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
|
|
@ -180,23 +178,24 @@ public class ClientCodeValidationConfig {
|
|||
}
|
||||
|
||||
@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 -> {
|
||||
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);
|
||||
return new ValidatorImpl<>(context,
|
||||
new ExistCompanyByUuid<>("companySymbolValue",
|
||||
TkrAccount::getCompanyId),
|
||||
new ExistAccountByValue<>("account",
|
||||
FieldRequiredRule.instance("client_code", TkrAccount::getClientCode, AccountError.RequiredFieldEmpty),
|
||||
new ExistCompanyByTradingCode<>("trading_code",
|
||||
TkrAccount::getTradingCode),
|
||||
new ExistAccountByValue<>("money_account",
|
||||
TkrAccount::getMoneyAccounts),
|
||||
new ExistDepoAccountByValue<>("depo_account",
|
||||
TkrAccount::getDepoAccount),
|
||||
new ExistTcrByCode<>("tcr_code",
|
||||
TkrAccount::getTkrCode)
|
||||
new ExistTcrByCode<>("tcr_code")
|
||||
);
|
||||
};
|
||||
}
|
||||
|
|
@ -238,26 +237,24 @@ public class ClientCodeValidationConfig {
|
|||
|
||||
public static class ExistTcrByCode<R> implements IValidationRule<ImdgValidationContext<R>> {
|
||||
String fieldName;
|
||||
Function<R, String> codeGetter;
|
||||
|
||||
public ExistTcrByCode(String fieldName, Function<R, String> codeGetter) {
|
||||
public ExistTcrByCode(String fieldName) {
|
||||
this.fieldName = fieldName;
|
||||
this.codeGetter = codeGetter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<EnumMessage> validate(ImdgValidationContext<R> context) {
|
||||
R validatedObject = context.getValidatedObject();
|
||||
String tcrCode = codeGetter.apply(validatedObject);
|
||||
if (!StringUtils.hasText(tcrCode)) {
|
||||
return of(AccountError.RequiredFieldEmpty, fieldName);
|
||||
Map<String, Account> accountByCurrency = context.getStoredObject(ClientCodeStoreObjects.MAPPED_TO_CURRENCY_ACCOUNTS);
|
||||
Account moneyAccount = accountByCurrency.get(CurrencyCode.RUB.getKey());
|
||||
if (moneyAccount == null) {
|
||||
return of(AccountError.AccountNotFound, fieldName);
|
||||
}
|
||||
Imdg<TradingClearingRegistry> imdg = context.obtainMap(IMDGDistributedNames.Map_TradingClearingRegistry,
|
||||
TradingClearingRegistry.class);
|
||||
|
||||
TradingClearingRegistry tcr = imdg.getFirstObjectByFieldValues(
|
||||
Map.of(
|
||||
"code", tcrCode,
|
||||
"moneyAccountId", moneyAccount.getId(),
|
||||
"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;
|
||||
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.symbolCodeGetter = symbolCodeGetter;
|
||||
this.tradingCodeGetter = tradingCodeGetter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<EnumMessage> validate(ImdgValidationContext<R> context) {
|
||||
R validatedObject = context.getValidatedObject();
|
||||
String symbolCodeValue = symbolCodeGetter.apply(validatedObject);
|
||||
if (!StringUtils.hasText(symbolCodeValue)) {
|
||||
Long tradingCode = tradingCodeGetter.apply(validatedObject);
|
||||
if (tradingCode == null) {
|
||||
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);
|
||||
Company company = companyImdg.getSingleObjectByID(companySymbols.getCompanyId());
|
||||
Company company = companyImdg.getFirstObjectByFieldValues(
|
||||
Map.of("trading_code", String.valueOf(tradingCode))
|
||||
);
|
||||
if (company == null) {
|
||||
return of(AccountError.COMPANY_NOT_FOUND_GTW, fieldName);
|
||||
}
|
||||
|
|
@ -372,7 +361,7 @@ public class ClientCodeValidationConfig {
|
|||
String fieldName;
|
||||
Function<R, String> depoAccountGetter;
|
||||
|
||||
public ExistDepoAccountByValue(String fieldName, Function<R, String> accountsListValueGetter) {
|
||||
public ExistDepoAccountByValue(String fieldName, Function<R, String> depoAccountGetter) {
|
||||
this.fieldName = fieldName;
|
||||
this.depoAccountGetter = depoAccountGetter;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import org.slf4j.LoggerFactory;
|
|||
import org.springframework.stereotype.Service;
|
||||
import ru.clearing.classes.statics.data.account.ClientCode;
|
||||
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.platform.messaging.domain.cud.account.ClientCodeNewRequest;
|
||||
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) {
|
||||
log.trace("Start process creating new client code");
|
||||
TradingClearingRegistry tradingClearingRegistry = validator.getStored(ClientCodeStoreObjects.TRADING_CLEARING_REGISTRY);
|
||||
if (tradingClearingRegistry == null) {
|
||||
log.debug("Trading Clearing Registry is not exist, creating...");
|
||||
TradingClearingRegistry tradingClearingRegistry;
|
||||
{
|
||||
log.debug("Trading Clearing Registry is not exist, creating...");
|
||||
TradingClearingRegistryNewRequest creationTcrRequest = new TradingClearingRegistryNewRequest();
|
||||
creationTcrRequest.setCompanyId(request.getCompanyId());
|
||||
creationTcrRequest.setMoneyAccountId(request.getMoneyAccountId());
|
||||
|
|
@ -53,7 +51,6 @@ public class ClientCodeFacade implements IClearingFacade {
|
|||
creationTcrRequest.setTradingClearingRegistryType(TradingClearingRegistryType.Client_B.getKey());
|
||||
tradingClearingRegistry = tradingClearingRegistryFacade.createTradingClearingRegistry(creationTcrRequest, null);
|
||||
}
|
||||
}
|
||||
{
|
||||
if (request.getCurrencyAccountList() != null && !request.getCurrencyAccountList().isEmpty()) {
|
||||
TradingClearingRegistryListNewRequest tcrListNew = new TradingClearingRegistryListNewRequest();
|
||||
|
|
|
|||
|
|
@ -35,6 +35,12 @@ public class TkrService {
|
|||
.filter(Objects::nonNull)
|
||||
.toList();
|
||||
|
||||
List<TkrAccount> tkrAccountsForUpdate = tkrRequest.getInfoAccount()
|
||||
.stream().filter(infoAccount -> TypeOperations.UPDATE.equalsByKey(infoAccount.getTypeOperationClient()))
|
||||
.map(tkrAdapter::toTkrResponse)
|
||||
.filter(Objects::nonNull)
|
||||
.toList();
|
||||
|
||||
if (!tkrAccountsForCheck.isEmpty()) {
|
||||
TkrAccountsGatewayRequest tkrAccountsRequest = new TkrAccountsGatewayRequest();
|
||||
tkrAccountsRequest.setRequestId(tkrRequest.getId());
|
||||
|
|
@ -48,5 +54,12 @@ public class TkrService {
|
|||
tkrAccountsRequest.setAccounts(tkrAccountsForNew);
|
||||
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.MoneyAccount;
|
||||
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.gateway.MoneyAccountMsgRequest;
|
||||
|
||||
@Service
|
||||
public class TkrAdapter {
|
||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||
|
||||
public TkrAccount toTkrResponse(InfoAccount infoAccount) {
|
||||
TkrAccount tkrResponse = new TkrAccount();
|
||||
tkrResponse.setCompanyId(infoAccount.getCompanyId());
|
||||
|
|
@ -22,12 +23,20 @@ public class TkrAdapter {
|
|||
tkrResponse.setEnabled(infoAccount.getEnabled());
|
||||
if (TypeOperations.CHECK.equalsByKey(infoAccount.getTypeOperationClient()) &&
|
||||
!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;
|
||||
}
|
||||
if (TypeOperations.ADD.equalsByKey(infoAccount.getTypeOperationClient()) &&
|
||||
!StringUtils.hasText(infoAccount.getClientCode())){
|
||||
log.warn("For check action client_code is required, skip this account.tkr_code: {}", infoAccount.getTkrCode());
|
||||
!StringUtils.hasText(infoAccount.getClientCode()) && StringUtils.hasText(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;
|
||||
}
|
||||
tkrResponse.setTkrCode(infoAccount.getTkrCode());
|
||||
|
|
|
|||
|
|
@ -102,6 +102,7 @@ public interface Consts {
|
|||
|
||||
String DESTINATION_CLIENT_CODE_NEW = "client-code-new";
|
||||
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_UPDATE = "client-code-update";
|
||||
String DESTINATION_CLIENT_CODE_DELETE = "client-code-delete";
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue