This commit is contained in:
parent
903fed53b3
commit
bd8af7fc16
6 changed files with 70 additions and 27 deletions
|
|
@ -152,7 +152,7 @@ public class BankAccountValidationConfig {
|
||||||
);
|
);
|
||||||
Account account = accountImdg.getSingleObjectByID(accountId);
|
Account account = accountImdg.getSingleObjectByID(accountId);
|
||||||
if (account == null) return AccountError.AccountNotFound;
|
if (account == null) return AccountError.AccountNotFound;
|
||||||
if (!AccountStatus.ACTIVE.equalsByKey(account.getStatus())) return AccountError.AccountNotActive;
|
if (AccountStatus.BLOCKED.equalsByKey(account.getStatus())) return AccountError.AccountNotActive;
|
||||||
return null;
|
return null;
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ public enum AccountError implements IErrorEnumId {
|
||||||
DepoAccountNotFound(5017L),
|
DepoAccountNotFound(5017L),
|
||||||
MoneyAccountNotFound(5018L),
|
MoneyAccountNotFound(5018L),
|
||||||
ClearingCategoryNotFound(5019L),
|
ClearingCategoryNotFound(5019L),
|
||||||
TradingClearingRegistryNotFound(5022L),
|
TradingClearingRegistryNotFound(3022L),
|
||||||
;
|
;
|
||||||
|
|
||||||
private final Long id;
|
private final Long id;
|
||||||
|
|
|
||||||
|
|
@ -157,9 +157,10 @@ public class ClientCodeService extends QueueConsumer implements InitializingBean
|
||||||
boolean doCreateTCR = checkNeedCreateTCR(req.getCompanyId(), req.getMoneyAccountId(), req.getDepoAccountId());
|
boolean doCreateTCR = checkNeedCreateTCR(req.getCompanyId(), req.getMoneyAccountId(), req.getDepoAccountId());
|
||||||
if (doCreateTCR) {
|
if (doCreateTCR) {
|
||||||
try {
|
try {
|
||||||
createAndWaitTCR(userRequest.getId(), null,
|
requestInfoUpdate = createAndWaitTCR(userRequest.getId(), null,
|
||||||
req.getCompanyId(), req.getMoneyAccountId(), req.getDepoAccountId());
|
req.getCompanyId(), req.getMoneyAccountId(), req.getDepoAccountId());
|
||||||
} catch (ClearingBaseException e) {
|
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||||
|
} catch (Exception e) {
|
||||||
log.error("Can not wait creation of TCR. request id={};CompanyId={}, MoneyAccountId={}, DepoAccountId={}; {}",
|
log.error("Can not wait creation of TCR. request id={};CompanyId={}, MoneyAccountId={}, DepoAccountId={}; {}",
|
||||||
userRequest.getId(), req.getCompanyId(), req.getMoneyAccountId(), req.getDepoAccountId(),
|
userRequest.getId(), req.getCompanyId(), req.getMoneyAccountId(), req.getDepoAccountId(),
|
||||||
e.toString());
|
e.toString());
|
||||||
|
|
@ -176,7 +177,7 @@ public class ClientCodeService extends QueueConsumer implements InitializingBean
|
||||||
|
|
||||||
|
|
||||||
protected RequestInfoUpdate clientCodeNewFromApiUmCompany(BaseRequest<ClientCodeNewRequest> userRequest) {
|
protected RequestInfoUpdate clientCodeNewFromApiUmCompany(BaseRequest<ClientCodeNewRequest> userRequest) {
|
||||||
log.debug("ClientCodeNewRequest received {}", userRequest.getId());
|
log.debug("ClientCodeNewRequest (UM_COMPANY) received {}", userRequest.getId());
|
||||||
|
|
||||||
RequestInfoUpdate requestInfoUpdate = userRoleVerification.validateRoleAndGetResult(userRequest);
|
RequestInfoUpdate requestInfoUpdate = userRoleVerification.validateRoleAndGetResult(userRequest);
|
||||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||||
|
|
@ -193,9 +194,10 @@ public class ClientCodeService extends QueueConsumer implements InitializingBean
|
||||||
boolean doCreateTCR = checkNeedCreateTCR(req.getCompanyId(), req.getMoneyAccountId(), req.getDepoAccountId());
|
boolean doCreateTCR = checkNeedCreateTCR(req.getCompanyId(), req.getMoneyAccountId(), req.getDepoAccountId());
|
||||||
if (doCreateTCR) {
|
if (doCreateTCR) {
|
||||||
try {
|
try {
|
||||||
createAndWaitTCR(userRequest.getId(), null,
|
requestInfoUpdate = createAndWaitTCR(userRequest.getId(), null,
|
||||||
req.getCompanyId(), req.getMoneyAccountId(), req.getDepoAccountId());
|
req.getCompanyId(), req.getMoneyAccountId(), req.getDepoAccountId());
|
||||||
} catch (ClearingBaseException e) {
|
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||||
|
} catch (Exception e) {
|
||||||
log.error("Can not wait creation of TCR. request id={};CompanyId={}, MoneyAccountId={}, DepoAccountId={}; {}",
|
log.error("Can not wait creation of TCR. request id={};CompanyId={}, MoneyAccountId={}, DepoAccountId={}; {}",
|
||||||
userRequest.getId(), req.getCompanyId(), req.getMoneyAccountId(), req.getDepoAccountId(),
|
userRequest.getId(), req.getCompanyId(), req.getMoneyAccountId(), req.getDepoAccountId(),
|
||||||
e.toString());
|
e.toString());
|
||||||
|
|
@ -219,6 +221,9 @@ public class ClientCodeService extends QueueConsumer implements InitializingBean
|
||||||
|
|
||||||
requestInfoUpdate = validationHelper.validateTillFirstError(userRequest, clientCodeUpdateRequestValidator);
|
requestInfoUpdate = validationHelper.validateTillFirstError(userRequest, clientCodeUpdateRequestValidator);
|
||||||
if (requestInfoUpdate != null) return requestInfoUpdate;
|
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||||
|
// дополнительная проверка
|
||||||
|
requestInfoUpdate = crossValidate(userRequest, req.getMoneyAccountId(), req.getDepoAccountId(), req.getCompanyId());
|
||||||
|
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||||
|
|
||||||
|
|
||||||
log.debug("ClientCodeUpdateRequest received, id={}", req.getId());
|
log.debug("ClientCodeUpdateRequest received, id={}", req.getId());
|
||||||
|
|
@ -230,9 +235,10 @@ public class ClientCodeService extends QueueConsumer implements InitializingBean
|
||||||
boolean doCreateTCR = checkNeedCreateTCR(req.getCompanyId(), req.getMoneyAccountId(), req.getDepoAccountId());
|
boolean doCreateTCR = checkNeedCreateTCR(req.getCompanyId(), req.getMoneyAccountId(), req.getDepoAccountId());
|
||||||
if (doCreateTCR) {
|
if (doCreateTCR) {
|
||||||
try {
|
try {
|
||||||
createAndWaitTCR(userRequest.getId(), clientCode.getId(),
|
requestInfoUpdate = createAndWaitTCR(userRequest.getId(), clientCode.getId(),
|
||||||
req.getCompanyId(), req.getMoneyAccountId(), req.getDepoAccountId());
|
req.getCompanyId(), req.getMoneyAccountId(), req.getDepoAccountId());
|
||||||
} catch (ClearingBaseException e) {
|
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||||
|
} catch (Exception e) {
|
||||||
log.error("Can not wait creation of TCR. request id={};CompanyId={}, MoneyAccountId={}, DepoAccountId={}; {}",
|
log.error("Can not wait creation of TCR. request id={};CompanyId={}, MoneyAccountId={}, DepoAccountId={}; {}",
|
||||||
userRequest.getId(), req.getCompanyId(), req.getMoneyAccountId(), req.getDepoAccountId(),
|
userRequest.getId(), req.getCompanyId(), req.getMoneyAccountId(), req.getDepoAccountId(),
|
||||||
e.toString());
|
e.toString());
|
||||||
|
|
@ -300,8 +306,8 @@ public class ClientCodeService extends QueueConsumer implements InitializingBean
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void createAndWaitTCR(Long reqId, Long clientCode,
|
protected RequestInfoUpdate createAndWaitTCR(Long reqId, Long clientCode,
|
||||||
Long companyId, Long moneyAccountId, Long depoAccountId) throws ClearingBaseException {
|
Long companyId, Long moneyAccountId, Long depoAccountId) {
|
||||||
log.debug("For request {}, clientCode={} need create TCR: companyId={}, moneyAccountId={}, depoAccountId={}",
|
log.debug("For request {}, clientCode={} need create TCR: companyId={}, moneyAccountId={}, depoAccountId={}",
|
||||||
reqId, clientCode == null ? "new" : clientCode,
|
reqId, clientCode == null ? "new" : clientCode,
|
||||||
companyId, moneyAccountId, depoAccountId);
|
companyId, moneyAccountId, depoAccountId);
|
||||||
|
|
@ -315,17 +321,13 @@ public class ClientCodeService extends QueueConsumer implements InitializingBean
|
||||||
// requestPayload.setStatus(WorkflowStatus.Active.getKey());
|
// requestPayload.setStatus(WorkflowStatus.Active.getKey());
|
||||||
requestPayload.setTradingClearingRegistryType(TradingClearingRegistryType.Client_B.getKey());
|
requestPayload.setTradingClearingRegistryType(TradingClearingRegistryType.Client_B.getKey());
|
||||||
request.setRequestPayload(requestPayload);
|
request.setRequestPayload(requestPayload);
|
||||||
try {
|
|
||||||
// Следующий вызываемый метод обязательно должен быть synchronized.
|
// Следующий вызываемый метод обязательно должен быть synchronized.
|
||||||
RequestInfoUpdate reply = tradingClearingRegistryService.tradingClearingRegistryNew(request);
|
RequestInfoUpdate reply = tradingClearingRegistryService.tradingClearingRegistryNew(request);
|
||||||
if (reply != null && Status.Error.equals(reply.getStatus())) {
|
if (reply != null && Status.Error.equals(reply.getStatus())) {
|
||||||
throw new ClearingBaseException(AccountError.GeneralError, "tradingClearingRegistryService return error: " + reply.getMessage());
|
log.warn("tradingClearingRegistryService return error: " + reply.getMessage());
|
||||||
}
|
|
||||||
} catch (ClearingBaseException expected) {
|
|
||||||
throw expected;
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new ClearingBaseException(AccountError.GeneralError, "Waiting account-service timeout");
|
|
||||||
}
|
}
|
||||||
|
return reply;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void sendBlockTCR(Long tradingClearingRegistryId, Long moneyAccountId) {
|
protected void sendBlockTCR(Long tradingClearingRegistryId, Long moneyAccountId) {
|
||||||
|
|
|
||||||
|
|
@ -226,7 +226,7 @@ public class InformationAccountService extends QueueConsumer implements Initiali
|
||||||
account.setCompanyId(forCompanyId);
|
account.setCompanyId(forCompanyId);
|
||||||
account.setCreated(now);
|
account.setCreated(now);
|
||||||
account.setUpdated(now);
|
account.setUpdated(now);
|
||||||
requestInfoUpdate = accountService.fillAccountFromRelation(account, userRequest.getId(), true);
|
requestInfoUpdate = accountService.fillAccountFromRelation(account, userRequest.getId(), false);
|
||||||
if (requestInfoUpdate != null) {
|
if (requestInfoUpdate != null) {
|
||||||
log.debug("Stop make new account, cause error: {}", requestInfoUpdate.getMessage());
|
log.debug("Stop make new account, cause error: {}", requestInfoUpdate.getMessage());
|
||||||
return requestInfoUpdate;
|
return requestInfoUpdate;
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,6 @@ package ru.spcex.clearing.account.service;
|
||||||
|
|
||||||
import org.apache.kafka.clients.consumer.Consumer;
|
import org.apache.kafka.clients.consumer.Consumer;
|
||||||
import org.apache.kafka.clients.producer.Producer;
|
import org.apache.kafka.clients.producer.Producer;
|
||||||
import org.apache.kafka.clients.producer.ProducerRecord;
|
|
||||||
import org.apache.kafka.clients.producer.RecordMetadata;
|
|
||||||
import org.apache.kafka.common.header.Header;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
|
|
@ -25,8 +22,10 @@ import ru.spcex.clearing.platform.messaging.domain.Consts;
|
||||||
import ru.spcex.clearing.platform.messaging.domain.cud.common.CommonIdRequest;
|
import ru.spcex.clearing.platform.messaging.domain.cud.common.CommonIdRequest;
|
||||||
import ru.spcex.clearing.platform.messaging.domain.cud.registry.TradingClearingRegistryNewRequest;
|
import ru.spcex.clearing.platform.messaging.domain.cud.registry.TradingClearingRegistryNewRequest;
|
||||||
import ru.spcex.clearing.platform.messaging.domain.cud.registry.TradingClearingRegistryUpdateRequest;
|
import ru.spcex.clearing.platform.messaging.domain.cud.registry.TradingClearingRegistryUpdateRequest;
|
||||||
|
import ru.spcex.clearing.platform.messaging.serialization.LogFormatter;
|
||||||
import ru.spcex.clearing.platform.messaging.service.QueueConsumer;
|
import ru.spcex.clearing.platform.messaging.service.QueueConsumer;
|
||||||
import ru.spcex.clearing.platform.messaging.service.RequestInfoUpdate;
|
import ru.spcex.clearing.platform.messaging.service.RequestInfoUpdate;
|
||||||
|
import ru.spcex.clearing.platform.messaging.service.sender.KafkaSender;
|
||||||
import ru.spcex.clearing.util.security.UserRoleVerification;
|
import ru.spcex.clearing.util.security.UserRoleVerification;
|
||||||
import ru.spcex.clearing.util.services.RequestHelper;
|
import ru.spcex.clearing.util.services.RequestHelper;
|
||||||
import ru.spcex.clearing.validation.common.ValidationHelper;
|
import ru.spcex.clearing.validation.common.ValidationHelper;
|
||||||
|
|
@ -70,9 +69,11 @@ public class TradingClearingRegistryService extends QueueConsumer implements Ini
|
||||||
|
|
||||||
private final IMessageResolver messageResolver;
|
private final IMessageResolver messageResolver;
|
||||||
private final Producer<String, Object> kafkaProducer;
|
private final Producer<String, Object> kafkaProducer;
|
||||||
|
private final KafkaSender kafkaSender;
|
||||||
|
|
||||||
public TradingClearingRegistryService(Consumer<String, Object> kafkaQueue,
|
public TradingClearingRegistryService(Consumer<String, Object> kafkaQueue,
|
||||||
Producer<String, Object> kafkaProducer,
|
Producer<String, Object> kafkaProducer,
|
||||||
|
KafkaSender kafkaSender,
|
||||||
ImdgProvider imdgProvider,
|
ImdgProvider imdgProvider,
|
||||||
ValidationHelper validationHelper,
|
ValidationHelper validationHelper,
|
||||||
UserRoleVerification userRoleVerification,
|
UserRoleVerification userRoleVerification,
|
||||||
|
|
@ -86,6 +87,7 @@ public class TradingClearingRegistryService extends QueueConsumer implements Ini
|
||||||
Function<CommonIdRequest, IValidator> tradingClearingRegistryBlockRequestValidator) {
|
Function<CommonIdRequest, IValidator> tradingClearingRegistryBlockRequestValidator) {
|
||||||
super(kafkaQueue, kafkaProducer);
|
super(kafkaQueue, kafkaProducer);
|
||||||
this.kafkaProducer = kafkaProducer;
|
this.kafkaProducer = kafkaProducer;
|
||||||
|
this.kafkaSender = kafkaSender;
|
||||||
this.validationHelper = validationHelper;
|
this.validationHelper = validationHelper;
|
||||||
this.userRoleVerification = userRoleVerification;
|
this.userRoleVerification = userRoleVerification;
|
||||||
this.requestHelper = requestHelper;
|
this.requestHelper = requestHelper;
|
||||||
|
|
@ -339,6 +341,11 @@ public class TradingClearingRegistryService extends QueueConsumer implements Ini
|
||||||
tradingClearingRegistry.setUpdated(now);
|
tradingClearingRegistry.setUpdated(now);
|
||||||
|
|
||||||
tradingClearingRegistryImdg.insert(tradingClearingRegistry);
|
tradingClearingRegistryImdg.insert(tradingClearingRegistry);
|
||||||
|
log.info("New TCR.id={} was created.", tradingClearingRegistry.getId());
|
||||||
|
|
||||||
|
sendNotificationToCompanySvc(tradingClearingRegistry);
|
||||||
|
sendNotificationToClearingSvc(tradingClearingRegistry);
|
||||||
|
sendNotificationToReportSvc(tradingClearingRegistry);
|
||||||
|
|
||||||
log.debug("successfully processed, id {}", id);
|
log.debug("successfully processed, id {}", id);
|
||||||
return null;
|
return null;
|
||||||
|
|
@ -394,4 +401,38 @@ public class TradingClearingRegistryService extends QueueConsumer implements Ini
|
||||||
log.debug("successfully processed, id {}", tradingClearingRegistry.getId());
|
log.debug("successfully processed, id {}", tradingClearingRegistry.getId());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* company-service сообщение об успешном добавлении ТКР клиента с параметром tradingClearingRegistry.code
|
||||||
|
*/
|
||||||
|
protected void sendNotificationToCompanySvc(TradingClearingRegistry tradingClearingRegistry) {
|
||||||
|
// TradingClearingRegistryNewRequest request = new TradingClearingRegistryNewRequest();
|
||||||
|
// request.setMoneyAccountId(tradingClearingRegistry.getId());
|
||||||
|
// request.setCompanyId(tradingClearingRegistry.getCompanyId());
|
||||||
|
// request.setCode(tradingClearingRegistry.getCode());
|
||||||
|
// log.debug("Send message to kafka \"{}\": {}", Consts.DESTINATION_, LogFormatter.toStringWrapper(request));
|
||||||
|
// kafkaSender.sendRequestToQueue(Consts.DESTINATION_, request);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* clearing-service сообщение на открытие клиринговых регистров;
|
||||||
|
*/
|
||||||
|
protected void sendNotificationToClearingSvc(TradingClearingRegistry tradingClearingRegistry) {
|
||||||
|
// TradingClearingRegistryNewRequest request = new TradingClearingRegistryNewRequest();
|
||||||
|
// request.setMoneyAccountId(tradingClearingRegistry.getId());
|
||||||
|
// request.setCompanyId(tradingClearingRegistry.getCompanyId());
|
||||||
|
// request.setCode(tradingClearingRegistry.getCode());
|
||||||
|
// log.debug("Send message to kafka \"{}\": {}", Consts.DESTINATION_, LogFormatter.toStringWrapper(request));
|
||||||
|
// kafkaSender.sendRequestToQueue(Consts.DESTINATION_, request);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* report-service сообщение на формирование уведомления о создании нового ТКР
|
||||||
|
*/
|
||||||
|
protected void sendNotificationToReportSvc(TradingClearingRegistry tradingClearingRegistry) {
|
||||||
|
// TradingClearingRegistryNewRequest request = new TradingClearingRegistryNewRequest();
|
||||||
|
// request.setMoneyAccountId(tradingClearingRegistry.getId());
|
||||||
|
// log.debug("Send message to kafka \"{}\": {}", Consts.DESTINATION_, LogFormatter.toStringWrapper(request));
|
||||||
|
// kafkaSender.sendRequestToQueue(Consts.DESTINATION_, request);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -94,12 +94,12 @@ public record IdPresentRule<R, V extends SpcexObjectBase>(
|
||||||
Imdg<V> imdg = context.obtainMap(mapName, mapClass);
|
Imdg<V> imdg = context.obtainMap(mapName, mapClass);
|
||||||
V fromMap = imdg.getSingleObjectByID(id);
|
V fromMap = imdg.getSingleObjectByID(id);
|
||||||
if (fromMap == null) {
|
if (fromMap == null) {
|
||||||
return of(errorIdNotPresent, fieldName);
|
return of(errorIdNotPresent, id, fieldName);
|
||||||
}
|
}
|
||||||
for (Function<V, IErrorEnumId> additionalCheck : additionalChecks) {
|
for (Function<V, IErrorEnumId> additionalCheck : additionalChecks) {
|
||||||
IErrorEnumId validationError = additionalCheck.apply(fromMap);
|
IErrorEnumId validationError = additionalCheck.apply(fromMap);
|
||||||
if (validationError != null)
|
if (validationError != null)
|
||||||
return of(validationError, fieldName);
|
return of(validationError, id, fieldName);
|
||||||
}
|
}
|
||||||
return empty();
|
return empty();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue