This commit is contained in:
parent
743f721df5
commit
c9c5fc9297
3 changed files with 57 additions and 32 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
package ru.spcex.clearing.account.config.validation;
|
package ru.spcex.clearing.account.config.validation;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
@ -57,7 +58,7 @@ public class TradingClearingRegistryListValidationConfig {
|
||||||
AccountError.TradingClearingRegistryNotFound,
|
AccountError.TradingClearingRegistryNotFound,
|
||||||
false),
|
false),
|
||||||
new ExistAllAccountId<>("accountId",
|
new ExistAllAccountId<>("accountId",
|
||||||
TradingClearingRegistryListNewRequest::getAccountId,
|
TradingClearingRegistryListNewRequest::getCurrencyAccountList,
|
||||||
false,
|
false,
|
||||||
null),
|
null),
|
||||||
DictionaryPresentRule.instance("stauts",
|
DictionaryPresentRule.instance("stauts",
|
||||||
|
|
@ -153,11 +154,11 @@ public class TradingClearingRegistryListValidationConfig {
|
||||||
|
|
||||||
public static class ExistAllAccountId<R> implements IValidationRule<ImdgValidationContext<R>> {
|
public static class ExistAllAccountId<R> implements IValidationRule<ImdgValidationContext<R>> {
|
||||||
String fieldName;
|
String fieldName;
|
||||||
Function<R, Long> accountIdGetter;
|
Function<R, List<Long>> accountIdGetter;
|
||||||
boolean required;
|
boolean required;
|
||||||
Function<R, Long> idGetter;
|
Function<R, Long> idGetter;
|
||||||
|
|
||||||
public ExistAllAccountId(String fieldName, Function<R, Long> accountIdGetter, boolean required, Function<R, Long> idGetter) {
|
public ExistAllAccountId(String fieldName, Function<R, List<Long>> accountIdGetter, boolean required, Function<R, Long> idGetter) {
|
||||||
this.fieldName = fieldName;
|
this.fieldName = fieldName;
|
||||||
this.accountIdGetter = accountIdGetter;
|
this.accountIdGetter = accountIdGetter;
|
||||||
this.required = required;
|
this.required = required;
|
||||||
|
|
@ -167,8 +168,8 @@ public class TradingClearingRegistryListValidationConfig {
|
||||||
@Override
|
@Override
|
||||||
public Optional<EnumMessage> validate(ImdgValidationContext<R> context) {
|
public Optional<EnumMessage> validate(ImdgValidationContext<R> context) {
|
||||||
R validatedObject = context.getValidatedObject();
|
R validatedObject = context.getValidatedObject();
|
||||||
Long accountId = accountIdGetter.apply(validatedObject);
|
List<Long> accounts = accountIdGetter.apply(validatedObject);
|
||||||
if (accountId == null) {
|
if (accounts == null || accounts.isEmpty()) {
|
||||||
if (required)
|
if (required)
|
||||||
return of(AccountError.RequiredFieldEmpty, fieldName); // обязательное поле
|
return of(AccountError.RequiredFieldEmpty, fieldName); // обязательное поле
|
||||||
else
|
else
|
||||||
|
|
@ -177,36 +178,40 @@ public class TradingClearingRegistryListValidationConfig {
|
||||||
Imdg<Account> accountImdg = context.obtainMap(IMDGDistributedNames.Map_Account, Account.class);
|
Imdg<Account> accountImdg = context.obtainMap(IMDGDistributedNames.Map_Account, Account.class);
|
||||||
// Проверить существование счетов
|
// Проверить существование счетов
|
||||||
{
|
{
|
||||||
Account byIdObject = accountImdg.getSingleObjectByID(accountId);
|
for (Long accountId : accounts) {
|
||||||
if (byIdObject == null)
|
Account byIdObject = accountImdg.getSingleObjectByID(accountId);
|
||||||
return of(AccountError.AccountNotFound, accountId, fieldName);
|
if (byIdObject == null)
|
||||||
if (!IEnumKey.contains(byIdObject.getAccountType(), AccountType.Clrn, AccountType.Info)) {
|
return of(AccountError.AccountNotFound, accountId, fieldName);
|
||||||
return of(AccountError.AccountIsNotACurrency, accountId,
|
if (!IEnumKey.contains(byIdObject.getAccountType(), AccountType.Clrn, AccountType.Info)) {
|
||||||
|
return of(AccountError.AccountIsNotACurrency, accountId,
|
||||||
fieldName, "expected: CLRN/INFO but is " + byIdObject.getAccountType()); // Счет %S не
|
fieldName, "expected: CLRN/INFO but is " + byIdObject.getAccountType()); // Счет %S не
|
||||||
}
|
}
|
||||||
if (CurrencyCode.isRub(byIdObject.getCurrency()) || StringUtils.isEmpty(byIdObject.getCurrency())) {
|
if (CurrencyCode.isRub(byIdObject.getCurrency()) || StringUtils.isEmpty(byIdObject.getCurrency())) {
|
||||||
return of(AccountError.AccountIsNotACurrency, accountId, fieldName); // Счет %S не валютный
|
return of(AccountError.AccountIsNotACurrency, accountId, fieldName); // Счет %S не валютный
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Проверка отсутствия других TradingClearingRegistryList с этими счетами
|
// Проверка отсутствия других TradingClearingRegistryList с этими счетами
|
||||||
Imdg<TradingClearingRegistryList> tradingClearingRegistryListImdg = context.obtainMap(IMDGDistributedNames.Map_TradingClearingRegistryList, TradingClearingRegistryList.class);
|
Imdg<TradingClearingRegistryList> tradingClearingRegistryListImdg = context.obtainMap(IMDGDistributedNames.Map_TradingClearingRegistryList, TradingClearingRegistryList.class);
|
||||||
ImdgPredicateBuilder pb = tradingClearingRegistryListImdg.predicateBuilder();
|
ImdgPredicateBuilder pb = tradingClearingRegistryListImdg.predicateBuilder();
|
||||||
ImdgPredicate query = pb.and(pb.equals("status", WorkflowStatus.Active.getKey()),
|
for (Long accountId : accounts) {
|
||||||
|
ImdgPredicate query = pb.and(pb.equals("status", WorkflowStatus.Active.getKey()),
|
||||||
pb.equals("accountId", accountId));
|
pb.equals("accountId", accountId));
|
||||||
if (idGetter != null) {
|
if (idGetter != null) {
|
||||||
Long id = idGetter.apply(validatedObject);
|
Long id = idGetter.apply(validatedObject);
|
||||||
if (id == null) // never
|
if (id == null) // never
|
||||||
return of(AccountError.RequiredFieldEmpty, "id");
|
return of(AccountError.RequiredFieldEmpty, "id");
|
||||||
query = pb.and(query, pb.not(pb.equals("id", id)));
|
query = pb.and(query, pb.not(pb.equals("id", id)));
|
||||||
}
|
}
|
||||||
Collection<TradingClearingRegistryList> inOtherLists = tradingClearingRegistryListImdg.getCollectionObjectsByPredicate(query);
|
Collection<TradingClearingRegistryList> inOtherLists = tradingClearingRegistryListImdg.getCollectionObjectsByPredicate(query);
|
||||||
if (!inOtherLists.isEmpty()) {
|
if (!inOtherLists.isEmpty()) {
|
||||||
Collection<Long> duplicateAccounts = inOtherLists.stream()
|
Collection<Long> duplicateAccounts = inOtherLists.stream()
|
||||||
.map(TradingClearingRegistryList::getAccountId)
|
.map(TradingClearingRegistryList::getAccountId)
|
||||||
.filter(accountId::equals)
|
.filter(accountId::equals)
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
return of(AccountError.AccountForTradingClearingRegistryAlreadyUsed, duplicateAccounts, fieldName); // (5023) «Счет %s уже используется»
|
return of(AccountError.AccountForTradingClearingRegistryAlreadyUsed, duplicateAccounts, fieldName); // (5023) «Счет %s уже используется»
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return empty();
|
return empty();
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,8 @@ import ru.spcex.platform.enumeration.WorkflowStatus;
|
||||||
import ru.spcex.platform.imdg.api.Imdg;
|
import ru.spcex.platform.imdg.api.Imdg;
|
||||||
import ru.spcex.platform.imdg.api.ImdgId;
|
import ru.spcex.platform.imdg.api.ImdgId;
|
||||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||||
|
import ru.spcex.platform.imdg.api.predicate.ImdgPredicate;
|
||||||
|
import ru.spcex.platform.imdg.api.predicate.ImdgPredicateBuilder;
|
||||||
import ru.spcex.platform.utils.enumeration.EnumMessage;
|
import ru.spcex.platform.utils.enumeration.EnumMessage;
|
||||||
import ru.spcex.platform.utils.enumeration.IMessageResolver;
|
import ru.spcex.platform.utils.enumeration.IMessageResolver;
|
||||||
import ru.spcex.platform.utils.log.ExceptionUtils;
|
import ru.spcex.platform.utils.log.ExceptionUtils;
|
||||||
|
|
@ -197,17 +199,35 @@ public class ClientCodeService extends QueueConsumer implements InitializingBean
|
||||||
clientCodeNewRequest.setDepoAccountId(account.getId());
|
clientCodeNewRequest.setDepoAccountId(account.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
List<Long> currencyIds = new ArrayList<>();
|
||||||
for (MoneyAccountMsgRequest moneyAccountMsg : tkrAccount.getMoneyAccounts()) {
|
for (MoneyAccountMsgRequest moneyAccountMsg : tkrAccount.getMoneyAccounts()) {
|
||||||
|
ImdgPredicateBuilder predicateBuilder = accountImdg.predicateBuilder();
|
||||||
|
ImdgPredicate currencyPredicate;
|
||||||
|
ImdgPredicate accountPredicate = predicateBuilder.equals("account", moneyAccountMsg.getAccount());
|
||||||
if (moneyAccountMsg.getCurrCode().equals(CurrencyCode.RUB.getKey())) {
|
if (moneyAccountMsg.getCurrCode().equals(CurrencyCode.RUB.getKey())) {
|
||||||
Account account = accountImdg.getFirstObjectByFieldValues(
|
currencyPredicate = predicateBuilder.or(
|
||||||
Map.of(
|
predicateBuilder.equals("currency", CurrencyCode.RUB.getKey()),
|
||||||
"account", moneyAccountMsg.getAccount()
|
predicateBuilder.isNull("currency")
|
||||||
)
|
|
||||||
);
|
);
|
||||||
if (account != null) {
|
} else {
|
||||||
clientCodeNewRequest.setMoneyAccountId(account.getId());
|
currencyPredicate = predicateBuilder.equals("currency", moneyAccountMsg.getCurrCode());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Account account = accountImdg.getFirstObjectByPredicate(
|
||||||
|
predicateBuilder.and(accountPredicate, currencyPredicate)
|
||||||
|
);
|
||||||
|
if (account == null) {
|
||||||
|
log.warn("Account not found: currency: {}; account: {}", moneyAccountMsg.getCurrCode(),
|
||||||
|
moneyAccountMsg.getAccount());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!StringUtils.hasText(account.getCurrency()) || CurrencyCode.RUB.equalsByKey(account.getCurrency())) {
|
||||||
|
clientCodeNewRequest.setMoneyAccountId(account.getId());
|
||||||
|
} else {
|
||||||
|
currencyIds.add(account.getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!currencyIds.isEmpty()) {
|
||||||
|
clientCodeNewRequest.setCurrencyAccountList(currencyIds);
|
||||||
}
|
}
|
||||||
BaseRequest<ClientCodeNewRequest> request = new BaseRequest<>();
|
BaseRequest<ClientCodeNewRequest> request = new BaseRequest<>();
|
||||||
request.setRequestPayload(clientCodeNewRequest);
|
request.setRequestPayload(clientCodeNewRequest);
|
||||||
|
|
|
||||||
|
|
@ -141,7 +141,6 @@ public class TradingClearingRegistryListService extends QueueConsumer implements
|
||||||
|
|
||||||
|
|
||||||
TradingClearingRegistryListNewRequest req = userRequest.getRequestPayload();
|
TradingClearingRegistryListNewRequest req = userRequest.getRequestPayload();
|
||||||
Account account = accountImdg.getSingleObjectByID(req.getAccountId());
|
|
||||||
Instant now = Instant.now();
|
Instant now = Instant.now();
|
||||||
|
|
||||||
List<Long> newIds=new ArrayList<>();
|
List<Long> newIds=new ArrayList<>();
|
||||||
|
|
@ -153,6 +152,7 @@ public class TradingClearingRegistryListService extends QueueConsumer implements
|
||||||
tradingClearingRegistryList.setUpdated(now);
|
tradingClearingRegistryList.setUpdated(now);
|
||||||
tradingClearingRegistryList.setTradingClearingRegistryId(req.getTradingClearingRegistryId());
|
tradingClearingRegistryList.setTradingClearingRegistryId(req.getTradingClearingRegistryId());
|
||||||
tradingClearingRegistryList.setAccountId(currAccId);
|
tradingClearingRegistryList.setAccountId(currAccId);
|
||||||
|
Account account = accountImdg.getSingleObjectByID(currAccId);
|
||||||
tradingClearingRegistryList.setCurrency(account.getCurrency());
|
tradingClearingRegistryList.setCurrency(account.getCurrency());
|
||||||
if (req.getStatus() == null) {
|
if (req.getStatus() == null) {
|
||||||
tradingClearingRegistryList.setStatus(ServiceStatus.Active.getKey());
|
tradingClearingRegistryList.setStatus(ServiceStatus.Active.getKey());
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue