account-service разрешил изменение TCR.DepoAccountId с null
This commit is contained in:
parent
585f7cf6e7
commit
eed10a1eec
2 changed files with 55 additions and 12 deletions
|
|
@ -31,6 +31,7 @@ import ru.spcex.platform.utils.validation.ValidatorImpl;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
@ -140,11 +141,6 @@ public class TradingClearingRegistryValidationConfig {
|
||||||
if (validatedObject.getMoneyAccountId() == null) {
|
if (validatedObject.getMoneyAccountId() == null) {
|
||||||
return of(AccountError.RequiredFieldEmpty, "MoneyAccountId");
|
return of(AccountError.RequiredFieldEmpty, "MoneyAccountId");
|
||||||
}
|
}
|
||||||
//Map<String, Comparable<?>> query = new HashMap<>();
|
|
||||||
// query.put("moneyAccountId", validatedObject.getMoneyAccountId());
|
|
||||||
// if (validatedObject.getDepoAccountId() != null) {
|
|
||||||
// query.put("depoAccountId", validatedObject.getDepoAccountId());
|
|
||||||
// }
|
|
||||||
ImdgPredicateBuilder pb = tcrMap.predicateBuilder();
|
ImdgPredicateBuilder pb = tcrMap.predicateBuilder();
|
||||||
ImdgPredicate query = pb.equals("moneyAccountId", validatedObject.getMoneyAccountId());
|
ImdgPredicate query = pb.equals("moneyAccountId", validatedObject.getMoneyAccountId());
|
||||||
if (validatedObject.getDepoAccountId() != null) {
|
if (validatedObject.getDepoAccountId() != null) {
|
||||||
|
|
@ -160,8 +156,49 @@ public class TradingClearingRegistryValidationConfig {
|
||||||
Account account = accountImdg.getSingleObjectByID(validatedObject.getMoneyAccountId());
|
Account account = accountImdg.getSingleObjectByID(validatedObject.getMoneyAccountId());
|
||||||
if (account == null && validatedObject.getDepoAccountId() != null) account = accountImdg.getSingleObjectByID(validatedObject.getDepoAccountId());
|
if (account == null && validatedObject.getDepoAccountId() != null) account = accountImdg.getSingleObjectByID(validatedObject.getDepoAccountId());
|
||||||
return of(AccountError.AccountForTradingClearingRegistryAlreadyUsed, account.getAccount());
|
return of(AccountError.AccountForTradingClearingRegistryAlreadyUsed, account.getAccount());
|
||||||
// String tcrIds = existTCR.stream().map(tcr -> String.valueOf(tcr.getId())).collect(Collectors.joining(";"));
|
}
|
||||||
// return of(AccountError.AccountForTradingClearingRegistryAlreadyUsed, tcrIds);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static class updateTCRDepoCheck implements IValidationRule<ImdgValidationContext<TradingClearingRegistryUpdateRequest>> {
|
||||||
|
@Override
|
||||||
|
public Optional<EnumMessage> validate(ImdgValidationContext<TradingClearingRegistryUpdateRequest> context) {
|
||||||
|
TradingClearingRegistryUpdateRequest validatedObject = context.getValidatedObject();
|
||||||
|
Long depoAccountId = validatedObject.getDepoAccountId();
|
||||||
|
if (depoAccountId == null) // необязательное поле
|
||||||
|
return empty();
|
||||||
|
|
||||||
|
// Проверка типа счёта ДЕПО, что существует
|
||||||
|
Imdg<DepoAccount> depoAccountImdg = context.obtainMap(IMDGDistributedNames.Map_DepoAccount, DepoAccount.class);
|
||||||
|
DepoAccount depoAccount = depoAccountImdg.getFirstObjectByFieldValues(
|
||||||
|
Map.of("accountId", depoAccountId)
|
||||||
|
);
|
||||||
|
if (depoAccount == null)
|
||||||
|
return of(AccountError.AccountNotFound, depoAccountId);
|
||||||
|
|
||||||
|
// Проверка компании ТКР и счёта
|
||||||
|
Imdg<TradingClearingRegistry> tcrMap = context.obtainMap(IMDGDistributedNames.Map_TradingClearingRegistry, TradingClearingRegistry.class);
|
||||||
|
Imdg<Account> accountImdg = context.obtainMap(IMDGDistributedNames.Map_Account, Account.class);
|
||||||
|
Account account = accountImdg.getSingleObjectByID(validatedObject.getMoneyAccountId());
|
||||||
|
if (account == null) { // never
|
||||||
|
return of(AccountError.AccountNotFound, depoAccountId);
|
||||||
|
}
|
||||||
|
TradingClearingRegistry updateObject = tcrMap.getSingleObjectByID(validatedObject.getId());
|
||||||
|
if (!Objects.equals(account.getCompanyId(), updateObject.getCompanyId())) {
|
||||||
|
return of(AccountError.AccountNotFound, depoAccountId); // или UserVerifyDenial
|
||||||
|
}
|
||||||
|
|
||||||
|
// Проверка использования счёта в других ТКР
|
||||||
|
ImdgPredicateBuilder pb = tcrMap.predicateBuilder();
|
||||||
|
ImdgPredicate query = pb.and(pb.equals("depoAccountId", validatedObject.getDepoAccountId()),
|
||||||
|
pb.not(pb.equals("id", validatedObject.getId()))
|
||||||
|
);
|
||||||
|
Collection<TradingClearingRegistry> existTCR = tcrMap.getCollectionObjectsByPredicate(query);
|
||||||
|
if (existTCR.isEmpty()) {
|
||||||
|
return empty();
|
||||||
|
} else {
|
||||||
|
if (account == null && validatedObject.getDepoAccountId() != null) account = accountImdg.getSingleObjectByID(validatedObject.getDepoAccountId());
|
||||||
|
return of(AccountError.AccountForTradingClearingRegistryAlreadyUsed, account.getAccount());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -177,6 +214,8 @@ public class TradingClearingRegistryValidationConfig {
|
||||||
Consumer<String> addImdg = (s) -> context.addImdg(s, imdgForValidation.get(s));
|
Consumer<String> addImdg = (s) -> context.addImdg(s, imdgForValidation.get(s));
|
||||||
addImdg.accept(IMDGDistributedNames.Map_ServiceStatusDictionary);
|
addImdg.accept(IMDGDistributedNames.Map_ServiceStatusDictionary);
|
||||||
addImdg.accept(IMDGDistributedNames.Map_TradingClearingRegistry);
|
addImdg.accept(IMDGDistributedNames.Map_TradingClearingRegistry);
|
||||||
|
addImdg.accept(IMDGDistributedNames.Map_Account);
|
||||||
|
addImdg.accept(IMDGDistributedNames.Map_DepoAccount);
|
||||||
return new ValidatorImpl<>(context,
|
return new ValidatorImpl<>(context,
|
||||||
IdPresentRule.instance("id",
|
IdPresentRule.instance("id",
|
||||||
TradingClearingRegistryUpdateRequest::getId,
|
TradingClearingRegistryUpdateRequest::getId,
|
||||||
|
|
@ -190,7 +229,9 @@ public class TradingClearingRegistryValidationConfig {
|
||||||
ServiceStatusDictionary.class,
|
ServiceStatusDictionary.class,
|
||||||
AccountError.RequiredFieldEmpty,
|
AccountError.RequiredFieldEmpty,
|
||||||
AccountError.DictionaryNotFound,
|
AccountError.DictionaryNotFound,
|
||||||
false)
|
false),
|
||||||
|
|
||||||
|
new updateTCRDepoCheck()
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -459,17 +459,19 @@ public class TradingClearingRegistryService extends QueueConsumer implements Ini
|
||||||
if (req.getMoneyAccountId() != null && !req.getMoneyAccountId().equals(tradingClearingRegistry.getMoneyAccountId())) {
|
if (req.getMoneyAccountId() != null && !req.getMoneyAccountId().equals(tradingClearingRegistry.getMoneyAccountId())) {
|
||||||
return requestHelper.makeErrorResponse(userRequest, AccountError.WrongFieldValue, "MoneyAccountId", req.getMoneyAccountId());
|
return requestHelper.makeErrorResponse(userRequest, AccountError.WrongFieldValue, "MoneyAccountId", req.getMoneyAccountId());
|
||||||
}
|
}
|
||||||
if (req.getDepoAccountId() != null && !req.getDepoAccountId().equals(tradingClearingRegistry.getDepoAccountId())) {
|
if (tradingClearingRegistry.getDepoAccountId() != null && // но можно с null заменить
|
||||||
|
req.getDepoAccountId() != null && !req.getDepoAccountId().equals(tradingClearingRegistry.getDepoAccountId())) {
|
||||||
return requestHelper.makeErrorResponse(userRequest, AccountError.WrongFieldValue, "DepoAccountId", req.getDepoAccountId());
|
return requestHelper.makeErrorResponse(userRequest, AccountError.WrongFieldValue, "DepoAccountId", req.getDepoAccountId());
|
||||||
}
|
}
|
||||||
// tradingClearingRegistry.setMoneyAccountId(req.getMoneyAccountId());
|
// tradingClearingRegistry.setMoneyAccountId(req.getMoneyAccountId());
|
||||||
// tradingClearingRegistry.setDepoAccountId(req.getDepoAccountId());
|
|
||||||
|
|
||||||
|
if (req.getStatus() != null && !Objects.equals(req.getStatus(), tradingClearingRegistry.getStatus())
|
||||||
if (req.getStatus() != null && !Objects.equals(req.getStatus(), tradingClearingRegistry.getStatus())) {
|
|| req.getDepoAccountId() != null && !req.getDepoAccountId().equals(tradingClearingRegistry.getDepoAccountId())
|
||||||
|
) {
|
||||||
Instant now = Instant.now();
|
Instant now = Instant.now();
|
||||||
tradingClearingRegistry.setUpdated(now);
|
tradingClearingRegistry.setUpdated(now);
|
||||||
tradingClearingRegistry.setStatus(req.getStatus());
|
tradingClearingRegistry.setStatus(req.getStatus());
|
||||||
|
tradingClearingRegistry.setDepoAccountId(req.getDepoAccountId());
|
||||||
tradingClearingRegistryImdg.update(tradingClearingRegistry);
|
tradingClearingRegistryImdg.update(tradingClearingRegistry);
|
||||||
Optional<Tkr> tkr = createRequestToGateway(tradingClearingRegistry);
|
Optional<Tkr> tkr = createRequestToGateway(tradingClearingRegistry);
|
||||||
if (tkr.isPresent()) {
|
if (tkr.isPresent()) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue