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