This commit is contained in:
parent
a129db1c98
commit
2bd57dc4b6
5 changed files with 23 additions and 152 deletions
|
|
@ -48,29 +48,7 @@ public class ClientCodeValidationConfig {
|
|||
Company.class,
|
||||
AccountError.RequiredFieldEmpty,
|
||||
AccountError.CompanyNotFound),
|
||||
//
|
||||
// IdPresentRule.instance("moneyAccountId",
|
||||
// ClientCodeNewRequest::getMoneyAccountId,
|
||||
// IMDGDistributedNames.Map_Account,
|
||||
// Account.class,
|
||||
// AccountError.RequiredFieldEmpty,
|
||||
// AccountError.AccountNotFound,
|
||||
// false,
|
||||
// acc -> Objects.equals(context.getValidatedObject().getCompanyId(), acc.getCompanyId())
|
||||
// ? null : AccountError.AccountNotFound
|
||||
// ),
|
||||
// IdPresentRule.instance("depoAccountId",
|
||||
// ClientCodeNewRequest::getDepoAccountId,
|
||||
// IMDGDistributedNames.Map_Account,
|
||||
// Account.class,
|
||||
// AccountError.RequiredFieldEmpty,
|
||||
// AccountError.AccountNotFound,
|
||||
// false,
|
||||
// acc -> Objects.equals(context.getValidatedObject().getCompanyId(), acc.getCompanyId())
|
||||
// ? null : AccountError.AccountNotFound
|
||||
// ),
|
||||
// BackendClientCodeValidationRule.AllAccountsPresent,
|
||||
BackendClientCodeValidationRule.TcrIsNotPresentByAccount,
|
||||
BackendClientCodeValidationRule.TcrIsPresentByAccount,
|
||||
DictionaryPresentRule.instance("status",
|
||||
ClientCodeNewRequest::getStatus,
|
||||
IMDGDistributedNames.Map_ServiceStatusDictionary,
|
||||
|
|
@ -101,7 +79,6 @@ public class ClientCodeValidationConfig {
|
|||
AccountError.RequiredFieldEmpty,
|
||||
AccountError.RecordNotFound
|
||||
),
|
||||
|
||||
FieldRequiredRule.instance("companyId", ClientCodeUpdateRequest::getCompanyId, AccountError.RequiredFieldEmpty),
|
||||
IdPresentRule.instance("companyId",
|
||||
ClientCodeUpdateRequest::getCompanyId,
|
||||
|
|
@ -109,29 +86,7 @@ public class ClientCodeValidationConfig {
|
|||
Company.class,
|
||||
AccountError.RequiredFieldEmpty,
|
||||
AccountError.CompanyNotFound),
|
||||
//
|
||||
// IdPresentRule.instance("moneyAccountId",
|
||||
// ClientCodeUpdateRequest::getMoneyAccountId,
|
||||
// IMDGDistributedNames.Map_Account,
|
||||
// Account.class,
|
||||
// AccountError.RequiredFieldEmpty,
|
||||
// AccountError.AccountNotFound,
|
||||
// false,
|
||||
// acc -> Objects.equals(context.getValidatedObject().getCompanyId(), acc.getCompanyId())
|
||||
// ? null : AccountError.AccountNotFound
|
||||
// ),
|
||||
// IdPresentRule.instance("depoAccountId",
|
||||
// ClientCodeUpdateRequest::getDepoAccountId,
|
||||
// IMDGDistributedNames.Map_Account,
|
||||
// Account.class,
|
||||
// AccountError.RequiredFieldEmpty,
|
||||
// AccountError.AccountNotFound,
|
||||
// false,
|
||||
// acc -> Objects.equals(context.getValidatedObject().getCompanyId(), acc.getCompanyId())
|
||||
// ? null : AccountError.AccountNotFound
|
||||
// ),
|
||||
// BackendClientCodeValidationRule.AllAccountsPresent,
|
||||
DictionaryPresentRule.instance("stauts",
|
||||
DictionaryPresentRule.instance("status",
|
||||
ClientCodeUpdateRequest::getStatus,
|
||||
IMDGDistributedNames.Map_ServiceStatusDictionary,
|
||||
ServiceStatusDictionary.class,
|
||||
|
|
|
|||
|
|
@ -344,23 +344,7 @@ public class ClientCodeService extends QueueConsumer implements InitializingBean
|
|||
return makeErrorResponse(userRequest, AccountError.RecordNotFound, req.getId());
|
||||
}
|
||||
|
||||
boolean doCreateTCR = checkNeedCreateTCR(req.getCompanyId(), req.getMoneyAccountId(), req.getDepoAccountId());
|
||||
if (doCreateTCR) {
|
||||
try {
|
||||
requestInfoUpdate = createAndWaitTCR(userRequest.getId(), clientCode.getId(),
|
||||
req.getCompanyId(), req.getMoneyAccountId(), req.getDepoAccountId());
|
||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||
} catch (Exception e) {
|
||||
log.error("Can not wait creation of TCR. request id={};CompanyId={}, MoneyAccountId={}, DepoAccountId={}; {}",
|
||||
userRequest.getId(), req.getCompanyId(), req.getMoneyAccountId(), req.getDepoAccountId(),
|
||||
e.toString());
|
||||
return makeErrorResponse(userRequest, AccountError.GeneralError, "Can not create TCR: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
updateClientCode(clientCode, req);
|
||||
//fixme спросить, у нас при апдейте передаётся clientCode.id которого надо изменять. А тут список currencyAccountList приходит - в нём что будет - только 1 счёт для него и его же менять?
|
||||
|
||||
clientCodeMap.update(clientCode);
|
||||
log.debug("successfully processed update, id {}", clientCode.getId());
|
||||
return null;
|
||||
|
|
@ -525,25 +509,10 @@ public class ClientCodeService extends QueueConsumer implements InitializingBean
|
|||
|
||||
private void updateClientCode(ClientCode clientCode, ClientCodeUpdateRequest req) {
|
||||
assert clientCode.getId() != null && clientCode.getId().equals(req.getId());
|
||||
|
||||
clientCode.setCompanyId(req.getCompanyId());
|
||||
clientCode.setCode(req.getCode());
|
||||
|
||||
if (req.getMoneyAccountId() != null) {
|
||||
TradingClearingRegistry tradingClearingRegistry = selectTradingClearingRegistry(req.getCompanyId(), req.getMoneyAccountId(), req.getDepoAccountId());
|
||||
if (tradingClearingRegistry == null) {
|
||||
log.warn("TCR not found: CompanyId {}, MoneyAccountId {}, DepoAccountId {}",
|
||||
req.getCompanyId(), req.getMoneyAccountId(), req.getDepoAccountId());
|
||||
} else {
|
||||
clientCode.setTradingClearingRegistryId(tradingClearingRegistry.getId());
|
||||
}
|
||||
}
|
||||
|
||||
clientCode.setTradingClearingRegistryId(req.getTradingClearingRegistryId());
|
||||
clientCode.setMoneyAccountId(req.getMoneyAccountId());
|
||||
clientCode.setDepoAccountId(req.getDepoAccountId());
|
||||
clientCode.setStatus(req.getStatus());
|
||||
|
||||
clientCode.setUpdated(Instant.now());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ public class ClientCodeFacade implements IClearingFacade {
|
|||
/**
|
||||
* Создает clientCode, TCR и опционально TCRList, если указаны валюты.
|
||||
*/
|
||||
public void createClientCode(ClientCodeNewRequest request, IValidator validator, boolean isClearingAcc) {
|
||||
public void createClientCodeWithTkr(ClientCodeNewRequest request, IValidator validator, boolean isClearingAcc) {
|
||||
log.trace("Start process creating new client code");
|
||||
TradingClearingRegistry tradingClearingRegistry;
|
||||
{
|
||||
|
|
@ -78,8 +78,6 @@ public class ClientCodeFacade implements IClearingFacade {
|
|||
clientCode.setCompanyId(request.getCompanyId());
|
||||
clientCode.setCode(request.getCode());
|
||||
clientCode.setTradingClearingRegistryId(tradingClearingRegistry.getId());
|
||||
// clientCode.setMoneyAccountId(request.getMoneyAccountId());
|
||||
// clientCode.setDepoAccountId(request.getDepoAccountId());
|
||||
clientCode.setStatus(request.getStatus());
|
||||
clientCodeImdg.insert(clientCode);
|
||||
log.debug("successfully processed, new clientCode id {}", clientCode.getId());
|
||||
|
|
@ -87,41 +85,19 @@ public class ClientCodeFacade implements IClearingFacade {
|
|||
}
|
||||
}
|
||||
|
||||
// public void createClientCode(ClientCodeBusiness businessRequest) {
|
||||
// log.trace("Start process creating new client code");
|
||||
// TradingClearingRegistry tradingClearingRegistry;
|
||||
// {
|
||||
// log.debug("Trading Clearing Registry is not exist, creating...");
|
||||
// TradingClearingRegistryBusiness creationTcrRequest = new TradingClearingRegistryBusiness();
|
||||
// creationTcrRequest.setCompanyId(request.getCompanyId());
|
||||
// creationTcrRequest.setMoneyAccountId(request.getMoneyAccountId());
|
||||
// creationTcrRequest.setDepoAccountId(request.getDepoAccountId());
|
||||
// creationTcrRequest.setTradingClearingRegistryType(TradingClearingRegistryType.Client_B.getKey());
|
||||
// tradingClearingRegistry = tradingClearingRegistryFacade.createTradingClearingRegistry(creationTcrRequest, null);
|
||||
// }
|
||||
// {
|
||||
// if (request.getCurrencyAccountList() != null && !request.getCurrencyAccountList().isEmpty()) {
|
||||
// TradingClearingRegistryListNewRequest tcrListNew = new TradingClearingRegistryListNewRequest();
|
||||
// tcrListNew.setTradingClearingRegistryId(tradingClearingRegistry.getId());
|
||||
// tcrListNew.setCurrencyAccountList(request.getCurrencyAccountList());
|
||||
// List<Long> tkrListIds = tradingClearingRegistryListFacade.createTradingClearingRegistryList(tcrListNew, null);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// {
|
||||
// ClientCode clientCode = new ClientCode();
|
||||
// clientCode.setCreated(Instant.now());
|
||||
// clientCode.setUpdated(clientCode.getCreated());
|
||||
//
|
||||
// clientCode.setCompanyId(request.getCompanyId());
|
||||
// clientCode.setCode(request.getCode());
|
||||
// clientCode.setMoneyAccountId(request.getMoneyAccountId());
|
||||
// clientCode.setDepoAccountId(request.getDepoAccountId());
|
||||
// clientCode.setStatus(request.getStatus());
|
||||
// clientCodeImdg.insert(clientCode);
|
||||
// log.debug("successfully processed, new clientCode id {}", clientCode.getId());
|
||||
// }
|
||||
// }
|
||||
public void createClientCode(ClientCodeNewRequest request) {
|
||||
log.trace("Start process creating new client code");
|
||||
ClientCode clientCode = new ClientCode();
|
||||
clientCode.setCreated(Instant.now());
|
||||
clientCode.setUpdated(clientCode.getCreated());
|
||||
clientCode.setCompanyId(request.getCompanyId());
|
||||
clientCode.setCode(request.getCode());
|
||||
clientCode.setTradingClearingRegistryId(request.getTradingClearingRegistryId());
|
||||
clientCode.setStatus(request.getStatus());
|
||||
clientCodeImdg.insert(clientCode);
|
||||
log.debug("successfully processed, new clientCode id {}", clientCode.getId());
|
||||
}
|
||||
|
||||
public void lock() {
|
||||
// tradingClearingRegistryFacade.lock()
|
||||
// tradingClearingRegistryListFacade.lock()
|
||||
|
|
|
|||
|
|
@ -163,7 +163,7 @@ public class ClientCodeMessageListener extends QueueConsumer implements Initiali
|
|||
.map(currencyCodeAccountEntry -> currencyCodeAccountEntry.getValue().getId())
|
||||
.toList();
|
||||
clientCodeNewRequest.setCurrencyAccountList(foreignCurrencyList);
|
||||
clientCodeFacade.createClientCode(clientCodeNewRequest, validator, true);
|
||||
clientCodeFacade.createClientCodeWithTkr(clientCodeNewRequest, validator, true);
|
||||
|
||||
TradingClearingRegistry tradingClearingRegistry = selectTradingClearingRegistry(company.getId(),
|
||||
moneyAccount.getId(), depoAccountId);
|
||||
|
|
@ -209,7 +209,7 @@ public class ClientCodeMessageListener extends QueueConsumer implements Initiali
|
|||
clientCodeNewRequest.setMoneyAccountId(rubMoneyAcc.get());
|
||||
clientCodeNewRequest.setDepoAccountId(depoAccountId);
|
||||
clientCodeNewRequest.setCurrencyAccountList(accIds);
|
||||
clientCodeFacade.createClientCode(clientCodeNewRequest, validator, false);
|
||||
clientCodeFacade.createClientCodeWithTkr(clientCodeNewRequest, validator, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -222,7 +222,7 @@ public class ClientCodeMessageListener extends QueueConsumer implements Initiali
|
|||
return makeErrorResponse(clientCodeNewRequest, validationResult);
|
||||
}
|
||||
|
||||
clientCodeFacade.createClientCode(request, validationResult.validator(), true);
|
||||
clientCodeFacade.createClientCode(request);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,15 +1,12 @@
|
|||
package ru.spcex.clearing.account.validation;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import ru.clearing.classes.statics.data.account.Account;
|
||||
import ru.clearing.classes.statics.data.registry.TradingClearingRegistry;
|
||||
import ru.clearing.classes.statics.data.registry.TradingClearingRegistryList;
|
||||
import ru.spcex.clearing.account.errors.AccountError;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.account.ClientCodeNewRequest;
|
||||
import ru.spcex.platform.enumeration.Status;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
import ru.spcex.platform.imdg.validation.ImdgValidationContext;
|
||||
import ru.spcex.platform.utils.enumeration.EnumMessage;
|
||||
|
|
@ -37,43 +34,17 @@ public enum BackendClientCodeValidationRule implements IValidationRule<ImdgValid
|
|||
return empty();
|
||||
}
|
||||
},
|
||||
TcrIsNotPresentByAccount() {
|
||||
TcrIsPresentByAccount() {
|
||||
@Override
|
||||
public Optional<EnumMessage> validate(ImdgValidationContext<ClientCodeNewRequest> context) {
|
||||
ClientCodeNewRequest validatedObject = context.getValidatedObject();
|
||||
List<Long> currencyIds = validatedObject.getCurrencyAccountList();
|
||||
Long moneyAccountId = validatedObject.getMoneyAccountId();
|
||||
if (moneyAccountId == null) {
|
||||
return empty();
|
||||
}
|
||||
Imdg<TradingClearingRegistry> tradingClearingRegistryImdg =
|
||||
context.obtainMap(IMDGDistributedNames.Map_TradingClearingRegistry, TradingClearingRegistry.class);
|
||||
Imdg<TradingClearingRegistryList> tradingClearingRegistryListImdg =
|
||||
context.obtainMap(IMDGDistributedNames.Map_TradingClearingRegistryList, TradingClearingRegistryList.class);
|
||||
|
||||
TradingClearingRegistry tcrByMoneyAccount = tradingClearingRegistryImdg.getFirstObjectByFieldValues(
|
||||
Map.of(
|
||||
"moneyAccountId", moneyAccountId,
|
||||
"status", Status.Active.getKey()
|
||||
));
|
||||
if (tcrByMoneyAccount != null) {
|
||||
return of(AccountError.TradingClearingRegistryAlreadyExist);
|
||||
TradingClearingRegistry tcrByMoneyAccount = tradingClearingRegistryImdg.getSingleObjectByID(validatedObject.getTradingClearingRegistryId());
|
||||
if (tcrByMoneyAccount == null) {
|
||||
return of(AccountError.TradingClearingRegistryNotFound);
|
||||
}
|
||||
|
||||
if (currencyIds == null || currencyIds.isEmpty()) {
|
||||
return empty();
|
||||
}
|
||||
for (Long id : currencyIds) {
|
||||
TradingClearingRegistryList tcrList = tradingClearingRegistryListImdg.getFirstObjectByFieldValues(
|
||||
Map.of(
|
||||
"accountId", id,
|
||||
"status", Status.Active.getKey()
|
||||
));
|
||||
if (tcrList != null) {
|
||||
return of(AccountError.AccountForTradingClearingRegistryAlreadyUsed);
|
||||
}
|
||||
}
|
||||
|
||||
return empty();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue