AKurakin 2023-06-01 18:46:24 +03:00
parent 903fed53b3
commit bd8af7fc16
6 changed files with 70 additions and 27 deletions

View file

@ -152,7 +152,7 @@ public class BankAccountValidationConfig {
);
Account account = accountImdg.getSingleObjectByID(accountId);
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;
})
);

View file

@ -19,7 +19,7 @@ public enum AccountError implements IErrorEnumId {
DepoAccountNotFound(5017L),
MoneyAccountNotFound(5018L),
ClearingCategoryNotFound(5019L),
TradingClearingRegistryNotFound(5022L),
TradingClearingRegistryNotFound(3022L),
;
private final Long id;

View file

@ -157,9 +157,10 @@ public class ClientCodeService extends QueueConsumer implements InitializingBean
boolean doCreateTCR = checkNeedCreateTCR(req.getCompanyId(), req.getMoneyAccountId(), req.getDepoAccountId());
if (doCreateTCR) {
try {
createAndWaitTCR(userRequest.getId(), null,
requestInfoUpdate = createAndWaitTCR(userRequest.getId(), null,
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={}; {}",
userRequest.getId(), req.getCompanyId(), req.getMoneyAccountId(), req.getDepoAccountId(),
e.toString());
@ -176,7 +177,7 @@ public class ClientCodeService extends QueueConsumer implements InitializingBean
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);
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());
if (doCreateTCR) {
try {
createAndWaitTCR(userRequest.getId(), null,
requestInfoUpdate = createAndWaitTCR(userRequest.getId(), null,
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={}; {}",
userRequest.getId(), req.getCompanyId(), req.getMoneyAccountId(), req.getDepoAccountId(),
e.toString());
@ -219,6 +221,9 @@ public class ClientCodeService extends QueueConsumer implements InitializingBean
requestInfoUpdate = validationHelper.validateTillFirstError(userRequest, clientCodeUpdateRequestValidator);
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());
@ -230,9 +235,10 @@ public class ClientCodeService extends QueueConsumer implements InitializingBean
boolean doCreateTCR = checkNeedCreateTCR(req.getCompanyId(), req.getMoneyAccountId(), req.getDepoAccountId());
if (doCreateTCR) {
try {
createAndWaitTCR(userRequest.getId(), clientCode.getId(),
requestInfoUpdate = createAndWaitTCR(userRequest.getId(), clientCode.getId(),
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={}; {}",
userRequest.getId(), req.getCompanyId(), req.getMoneyAccountId(), req.getDepoAccountId(),
e.toString());
@ -300,8 +306,8 @@ public class ClientCodeService extends QueueConsumer implements InitializingBean
}
}
protected void createAndWaitTCR(Long reqId, Long clientCode,
Long companyId, Long moneyAccountId, Long depoAccountId) throws ClearingBaseException {
protected RequestInfoUpdate createAndWaitTCR(Long reqId, Long clientCode,
Long companyId, Long moneyAccountId, Long depoAccountId) {
log.debug("For request {}, clientCode={} need create TCR: companyId={}, moneyAccountId={}, depoAccountId={}",
reqId, clientCode == null ? "new" : clientCode,
companyId, moneyAccountId, depoAccountId);
@ -315,17 +321,13 @@ public class ClientCodeService extends QueueConsumer implements InitializingBean
// requestPayload.setStatus(WorkflowStatus.Active.getKey());
requestPayload.setTradingClearingRegistryType(TradingClearingRegistryType.Client_B.getKey());
request.setRequestPayload(requestPayload);
try {
// Следующий вызываемый метод обязательно должен быть synchronized.
RequestInfoUpdate reply = tradingClearingRegistryService.tradingClearingRegistryNew(request);
if (reply != null && Status.Error.equals(reply.getStatus())) {
throw new ClearingBaseException(AccountError.GeneralError, "tradingClearingRegistryService return error: " + reply.getMessage());
}
} catch (ClearingBaseException expected) {
throw expected;
} catch (Exception e) {
throw new ClearingBaseException(AccountError.GeneralError, "Waiting account-service timeout");
// Следующий вызываемый метод обязательно должен быть synchronized.
RequestInfoUpdate reply = tradingClearingRegistryService.tradingClearingRegistryNew(request);
if (reply != null && Status.Error.equals(reply.getStatus())) {
log.warn("tradingClearingRegistryService return error: " + reply.getMessage());
}
return reply;
}
protected void sendBlockTCR(Long tradingClearingRegistryId, Long moneyAccountId) {

View file

@ -226,7 +226,7 @@ public class InformationAccountService extends QueueConsumer implements Initiali
account.setCompanyId(forCompanyId);
account.setCreated(now);
account.setUpdated(now);
requestInfoUpdate = accountService.fillAccountFromRelation(account, userRequest.getId(), true);
requestInfoUpdate = accountService.fillAccountFromRelation(account, userRequest.getId(), false);
if (requestInfoUpdate != null) {
log.debug("Stop make new account, cause error: {}", requestInfoUpdate.getMessage());
return requestInfoUpdate;

View file

@ -2,9 +2,6 @@ package ru.spcex.clearing.account.service;
import org.apache.kafka.clients.consumer.Consumer;
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.LoggerFactory;
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.registry.TradingClearingRegistryNewRequest;
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.RequestInfoUpdate;
import ru.spcex.clearing.platform.messaging.service.sender.KafkaSender;
import ru.spcex.clearing.util.security.UserRoleVerification;
import ru.spcex.clearing.util.services.RequestHelper;
import ru.spcex.clearing.validation.common.ValidationHelper;
@ -70,9 +69,11 @@ public class TradingClearingRegistryService extends QueueConsumer implements Ini
private final IMessageResolver messageResolver;
private final Producer<String, Object> kafkaProducer;
private final KafkaSender kafkaSender;
public TradingClearingRegistryService(Consumer<String, Object> kafkaQueue,
Producer<String, Object> kafkaProducer,
KafkaSender kafkaSender,
ImdgProvider imdgProvider,
ValidationHelper validationHelper,
UserRoleVerification userRoleVerification,
@ -86,6 +87,7 @@ public class TradingClearingRegistryService extends QueueConsumer implements Ini
Function<CommonIdRequest, IValidator> tradingClearingRegistryBlockRequestValidator) {
super(kafkaQueue, kafkaProducer);
this.kafkaProducer = kafkaProducer;
this.kafkaSender = kafkaSender;
this.validationHelper = validationHelper;
this.userRoleVerification = userRoleVerification;
this.requestHelper = requestHelper;
@ -339,6 +341,11 @@ public class TradingClearingRegistryService extends QueueConsumer implements Ini
tradingClearingRegistry.setUpdated(now);
tradingClearingRegistryImdg.insert(tradingClearingRegistry);
log.info("New TCR.id={} was created.", tradingClearingRegistry.getId());
sendNotificationToCompanySvc(tradingClearingRegistry);
sendNotificationToClearingSvc(tradingClearingRegistry);
sendNotificationToReportSvc(tradingClearingRegistry);
log.debug("successfully processed, id {}", id);
return null;
@ -394,4 +401,38 @@ public class TradingClearingRegistryService extends QueueConsumer implements Ini
log.debug("successfully processed, id {}", tradingClearingRegistry.getId());
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);
}
}

View file

@ -94,12 +94,12 @@ public record IdPresentRule<R, V extends SpcexObjectBase>(
Imdg<V> imdg = context.obtainMap(mapName, mapClass);
V fromMap = imdg.getSingleObjectByID(id);
if (fromMap == null) {
return of(errorIdNotPresent, fieldName);
return of(errorIdNotPresent, id, fieldName);
}
for (Function<V, IErrorEnumId> additionalCheck : additionalChecks) {
IErrorEnumId validationError = additionalCheck.apply(fromMap);
if (validationError != null)
return of(validationError, fieldName);
return of(validationError, id, fieldName);
}
return empty();
}