This commit is contained in:
akulikov 2023-05-05 18:28:32 +03:00
parent 654943ec36
commit 65c235c01c
5 changed files with 39 additions and 4 deletions

View file

@ -16,9 +16,11 @@ import ru.spcex.clearing.platform.messaging.domain.BaseRequest;
import ru.spcex.clearing.platform.messaging.domain.Consts; import ru.spcex.clearing.platform.messaging.domain.Consts;
import ru.spcex.clearing.platform.messaging.domain.cud.account.ClearingAccountNewRequest; import ru.spcex.clearing.platform.messaging.domain.cud.account.ClearingAccountNewRequest;
import ru.spcex.clearing.platform.messaging.domain.cud.account.ClearingAccountUpdateRequest; import ru.spcex.clearing.platform.messaging.domain.cud.account.ClearingAccountUpdateRequest;
import ru.spcex.clearing.platform.messaging.domain.cud.registry.TradingClearingRegistryNewRequest;
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.Status; import ru.spcex.clearing.platform.messaging.service.Status;
import ru.spcex.clearing.platform.messaging.service.sender.KafkaSender;
import ru.spcex.clearing.validation.common.ValidationHelper; import ru.spcex.clearing.validation.common.ValidationHelper;
import ru.spcex.platform.enumeration.AccountType; import ru.spcex.platform.enumeration.AccountType;
import ru.spcex.platform.enumeration.ServiceStatus; import ru.spcex.platform.enumeration.ServiceStatus;
@ -38,6 +40,7 @@ import java.util.function.Function;
@Service @Service
public class ClearingAccountService extends QueueConsumer implements InitializingBean { public class ClearingAccountService extends QueueConsumer implements InitializingBean {
private final Logger log = LoggerFactory.getLogger(getClass()); private final Logger log = LoggerFactory.getLogger(getClass());
private final KafkaSender kafkaSender;
private final AccountService accountService; private final AccountService accountService;
private final ValidationHelper validationHelper; private final ValidationHelper validationHelper;
private final ImdgProvider imdgProvider; private final ImdgProvider imdgProvider;
@ -50,6 +53,7 @@ public class ClearingAccountService extends QueueConsumer implements Initializin
@Autowired @Autowired
public ClearingAccountService(Consumer<String, Object> kafkaQueue, public ClearingAccountService(Consumer<String, Object> kafkaQueue,
Producer<String, Object> kafkaResponseQueue, Producer<String, Object> kafkaResponseQueue,
KafkaSender kafkaSender,
AccountService accountService, AccountService accountService,
ValidationHelper validationHelper, ValidationHelper validationHelper,
ImdgProvider imdgProvider, ImdgProvider imdgProvider,
@ -59,6 +63,7 @@ public class ClearingAccountService extends QueueConsumer implements Initializin
@Qualifier("clearingAccountUpdateRequestValidator") @Qualifier("clearingAccountUpdateRequestValidator")
Function<ClearingAccountUpdateRequest, IValidator> clearingAccountUpdateRequestValidator) { Function<ClearingAccountUpdateRequest, IValidator> clearingAccountUpdateRequestValidator) {
super(kafkaQueue, kafkaResponseQueue); super(kafkaQueue, kafkaResponseQueue);
this.kafkaSender = kafkaSender;
this.accountService = accountService; this.accountService = accountService;
this.validationHelper = validationHelper; this.validationHelper = validationHelper;
this.imdgProvider = imdgProvider; this.imdgProvider = imdgProvider;
@ -104,10 +109,11 @@ public class ClearingAccountService extends QueueConsumer implements Initializin
ImdgTransaction imdgTransaction = imdgProvider.newTransaction(); ImdgTransaction imdgTransaction = imdgProvider.newTransaction();
boolean txOk = false; boolean txOk = false;
imdgTransaction.beginTransaction(); imdgTransaction.beginTransaction();
ClearingAccount clearingAccount = null;
try { try {
accountId = accountImdg.insert(account); accountId = accountImdg.insert(account);
ClearingAccount clearingAccount = new ClearingAccount(); clearingAccount = new ClearingAccount();
clearingAccount.setCompanyId(req.getCompanyId()); clearingAccount.setCompanyId(req.getCompanyId());
clearingAccount.setAccountId(accountId); clearingAccount.setAccountId(accountId);
clearingAccount.setClearingAccountType(req.getClearingAccountType()); clearingAccount.setClearingAccountType(req.getClearingAccountType());
@ -116,6 +122,10 @@ public class ClearingAccountService extends QueueConsumer implements Initializin
} finally { } finally {
if (txOk) { if (txOk) {
imdgTransaction.commitTransaction(); imdgTransaction.commitTransaction();
TradingClearingRegistryNewRequest request = new TradingClearingRegistryNewRequest();
request.setMoneyAccountId(accountId);
request.setCompanyId(clearingAccount.getCompanyId());
kafkaSender.sendRequestToQueue(Consts.DESTINATION_TRADING_CLEARING_REGISTRY_AUTO_NEW, request);
log.debug("successfully processed, new clearing account id {}, account id {}", clearingAccountId, accountId); log.debug("successfully processed, new clearing account id {}, account id {}", clearingAccountId, accountId);
} else { } else {
// todo выяснить, что возвращать из метода в этой ситуации // todo выяснить, что возвращать из метода в этой ситуации

View file

@ -13,8 +13,10 @@ import ru.spcex.clearing.imdg.IMDGDistributedNames;
import ru.spcex.clearing.platform.messaging.domain.BaseRequest; import ru.spcex.clearing.platform.messaging.domain.BaseRequest;
import ru.spcex.clearing.platform.messaging.domain.Consts; import ru.spcex.clearing.platform.messaging.domain.Consts;
import ru.spcex.clearing.platform.messaging.domain.cud.account.DepoAccountNewRequest; import ru.spcex.clearing.platform.messaging.domain.cud.account.DepoAccountNewRequest;
import ru.spcex.clearing.platform.messaging.domain.cud.registry.TradingClearingRegistryNewRequest;
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.validation.common.ValidationHelper; import ru.spcex.clearing.validation.common.ValidationHelper;
import ru.spcex.platform.enumeration.AccountType; import ru.spcex.platform.enumeration.AccountType;
import ru.spcex.platform.enumeration.ServiceStatus; import ru.spcex.platform.enumeration.ServiceStatus;
@ -30,6 +32,7 @@ import java.util.function.Function;
public class DepoAccountService extends QueueConsumer implements InitializingBean { public class DepoAccountService extends QueueConsumer implements InitializingBean {
private final Logger log = LoggerFactory.getLogger(getClass()); private final Logger log = LoggerFactory.getLogger(getClass());
private final KafkaSender kafkaSender;
private final ValidationHelper validationHelper; private final ValidationHelper validationHelper;
private final ImdgProvider imdgProvider; private final ImdgProvider imdgProvider;
private final AccountService accountService; private final AccountService accountService;
@ -39,12 +42,14 @@ public class DepoAccountService extends QueueConsumer implements InitializingBea
public DepoAccountService(Consumer<String, Object> kafkaQueue, public DepoAccountService(Consumer<String, Object> kafkaQueue,
Producer<String, Object> kafkaProducer, Producer<String, Object> kafkaProducer,
KafkaSender kafkaSender,
ValidationHelper validationHelper, ValidationHelper validationHelper,
ImdgProvider imdgProvider, ImdgProvider imdgProvider,
AccountService accountService, AccountService accountService,
@Qualifier("depoAccountNewRequestValidator") @Qualifier("depoAccountNewRequestValidator")
Function<DepoAccountNewRequest, IValidator> depoAccountNewRequestValidator) { Function<DepoAccountNewRequest, IValidator> depoAccountNewRequestValidator) {
super(kafkaQueue, kafkaProducer); super(kafkaQueue, kafkaProducer);
this.kafkaSender = kafkaSender;
this.validationHelper = validationHelper; this.validationHelper = validationHelper;
this.imdgProvider = imdgProvider; this.imdgProvider = imdgProvider;
this.accountService = accountService; this.accountService = accountService;
@ -86,10 +91,11 @@ public class DepoAccountService extends QueueConsumer implements InitializingBea
ImdgTransaction imdgTransaction = imdgProvider.newTransaction(); ImdgTransaction imdgTransaction = imdgProvider.newTransaction();
boolean txOk = false; boolean txOk = false;
imdgTransaction.beginTransaction(); imdgTransaction.beginTransaction();
DepoAccount depoAccount = null;
try { try {
accountId = accountImdg.insert(account); accountId = accountImdg.insert(account);
DepoAccount depoAccount = new DepoAccount(); depoAccount = new DepoAccount();
depoAccount.setCompanyId(req.getCompanyId()); depoAccount.setCompanyId(req.getCompanyId());
depoAccount.setAccountId(accountId); depoAccount.setAccountId(accountId);
depoAccount.setDepoAccountType(req.getDepoAccountType()); depoAccount.setDepoAccountType(req.getDepoAccountType());
@ -98,6 +104,10 @@ public class DepoAccountService extends QueueConsumer implements InitializingBea
} finally { } finally {
if (txOk) { if (txOk) {
imdgTransaction.commitTransaction(); imdgTransaction.commitTransaction();
TradingClearingRegistryNewRequest request = new TradingClearingRegistryNewRequest();
request.setDepoAccountId(accountId);
request.setCompanyId(depoAccount.getCompanyId());
kafkaSender.sendRequestToQueue(Consts.DESTINATION_TRADING_CLEARING_REGISTRY_AUTO_NEW, request);
log.debug("successfully processed, new depo account id {}, account id {}", depoAccountId, accountId); log.debug("successfully processed, new depo account id {}, account id {}", depoAccountId, accountId);
} else { } else {
// todo выяснить, что возвращать из метода в этой ситуации // todo выяснить, что возвращать из метода в этой ситуации

View file

@ -15,9 +15,11 @@ import ru.spcex.clearing.imdg.IMDGDistributedNames;
import ru.spcex.clearing.platform.messaging.domain.BaseRequest; import ru.spcex.clearing.platform.messaging.domain.BaseRequest;
import ru.spcex.clearing.platform.messaging.domain.Consts; import ru.spcex.clearing.platform.messaging.domain.Consts;
import ru.spcex.clearing.platform.messaging.domain.cud.account.InformationAccountNewRequest; import ru.spcex.clearing.platform.messaging.domain.cud.account.InformationAccountNewRequest;
import ru.spcex.clearing.platform.messaging.domain.cud.registry.TradingClearingRegistryNewRequest;
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.Status; import ru.spcex.clearing.platform.messaging.service.Status;
import ru.spcex.clearing.platform.messaging.service.sender.KafkaSender;
import ru.spcex.clearing.validation.common.ValidationHelper; import ru.spcex.clearing.validation.common.ValidationHelper;
import ru.spcex.platform.enumeration.AccountType; import ru.spcex.platform.enumeration.AccountType;
import ru.spcex.platform.enumeration.ServiceStatus; import ru.spcex.platform.enumeration.ServiceStatus;
@ -37,6 +39,7 @@ import java.util.function.Function;
@Service @Service
public class InformationAccountService extends QueueConsumer implements InitializingBean { public class InformationAccountService extends QueueConsumer implements InitializingBean {
private final Logger log = LoggerFactory.getLogger(getClass()); private final Logger log = LoggerFactory.getLogger(getClass());
private final KafkaSender kafkaSender;
private final IMessageResolver messageResolver; private final IMessageResolver messageResolver;
private final ImdgProvider imdgProvider; private final ImdgProvider imdgProvider;
private final ValidationHelper validationHelper; private final ValidationHelper validationHelper;
@ -48,6 +51,7 @@ public class InformationAccountService extends QueueConsumer implements Initiali
@Autowired @Autowired
public InformationAccountService(Consumer<String, Object> kafkaQueue, public InformationAccountService(Consumer<String, Object> kafkaQueue,
Producer<String, Object> kafkaResponseQueue, Producer<String, Object> kafkaResponseQueue,
KafkaSender kafkaSender,
IMessageResolver messageResolver, IMessageResolver messageResolver,
ImdgProvider imdgProvider, ImdgProvider imdgProvider,
ValidationHelper validationHelper, ValidationHelper validationHelper,
@ -55,6 +59,7 @@ public class InformationAccountService extends QueueConsumer implements Initiali
@Qualifier("informationAccountNewRequestValidator") @Qualifier("informationAccountNewRequestValidator")
Function<InformationAccountNewRequest, IValidator> infoAccountNewRequestValidator) { Function<InformationAccountNewRequest, IValidator> infoAccountNewRequestValidator) {
super(kafkaQueue, kafkaResponseQueue); super(kafkaQueue, kafkaResponseQueue);
this.kafkaSender = kafkaSender;
this.messageResolver = messageResolver; this.messageResolver = messageResolver;
this.imdgProvider = imdgProvider; this.imdgProvider = imdgProvider;
this.validationHelper = validationHelper; this.validationHelper = validationHelper;
@ -117,10 +122,11 @@ public class InformationAccountService extends QueueConsumer implements Initiali
boolean txOk = false; boolean txOk = false;
Long informationAccountId = -1L; Long informationAccountId = -1L;
Long accountId = -1L; Long accountId = -1L;
InformationAccount informationAccount = null;
try { try {
accountId = accountImdg.insert(account); accountId = accountImdg.insert(account);
InformationAccount informationAccount = new InformationAccount(); informationAccount = new InformationAccount();
informationAccount.setId(newId); informationAccount.setId(newId);
informationAccount.setAccountId(accountId); informationAccount.setAccountId(accountId);
informationAccount.setClearingAccountId(anltAccount.getId()); informationAccount.setClearingAccountId(anltAccount.getId());
@ -130,6 +136,10 @@ public class InformationAccountService extends QueueConsumer implements Initiali
} finally { } finally {
if (txOk) { if (txOk) {
imdgTransaction.commitTransaction(); imdgTransaction.commitTransaction();
TradingClearingRegistryNewRequest request = new TradingClearingRegistryNewRequest();
request.setMoneyAccountId(informationAccountId);
request.setCompanyId(informationAccount.getCompanyId());
kafkaSender.sendRequestToQueue(Consts.DESTINATION_TRADING_CLEARING_REGISTRY_AUTO_NEW, request);
log.debug("successfully processed, new information account id {}, new account id {}", log.debug("successfully processed, new information account id {}, new account id {}",
informationAccountId, informationAccountId,
accountId); accountId);

View file

@ -99,6 +99,9 @@ public class TradingClearingRegistryService extends QueueConsumer implements Ini
@Override @Override
public void afterPropertiesSet() throws Exception { public void afterPropertiesSet() throws Exception {
init(); init();
callback(TradingClearingRegistryNewRequest.class)
.setConsumer(this::tradingClearingRegistryAutoNew)
.forDestination(Consts.DESTINATION_TRADING_CLEARING_REGISTRY_AUTO_NEW, callbacks::put);
callback(TradingClearingRegistryNewRequest.class) callback(TradingClearingRegistryNewRequest.class)
.setConsumer(this::tradingClearingRegistryNew) .setConsumer(this::tradingClearingRegistryNew)
.forDestination(Consts.DESTINATION_TRADING_CLEARING_REGISTRY_NEW, callbacks::put); .forDestination(Consts.DESTINATION_TRADING_CLEARING_REGISTRY_NEW, callbacks::put);
@ -140,7 +143,8 @@ public class TradingClearingRegistryService extends QueueConsumer implements Ini
// TODO: WELCOME TO HELL // TODO: WELCOME TO HELL
// Проверка выглядит очень сложно и запутанно, потому что репортеры сами не до конца понимают, какая она должна быть. // Проверка выглядит очень сложно и запутанно, потому что репортеры сами не до конца понимают, какая она должна быть.
// Пока что она соответствует ТЗ, но возможно будет правиться, поэтому расписана без выноса кода в методы и // Пока что она соответствует ТЗ, но возможно будет правиться, поэтому расписана без выноса кода в методы и
// прочих методов сокращения кода // прочих методов сокращения кода. В дальнейшем, после тестирования и окончательного выяснения вида проверки,
// её стоит вынести на этап валидации запроса.
Relation relation = relationImdg.getSingleObjectByFieldValues(Map.of("consumerId", req.getCompanyId())); Relation relation = relationImdg.getSingleObjectByFieldValues(Map.of("consumerId", req.getCompanyId()));
if (ru.spcex.platform.enumeration.Service.MKR.equalsByKey(relation.getService())) { if (ru.spcex.platform.enumeration.Service.MKR.equalsByKey(relation.getService())) {
TradingClearingRegistry registry = tradingClearingRegistryImdg.getSingleObjectByFieldValues(Map.of("companyId", req.getCompanyId())); TradingClearingRegistry registry = tradingClearingRegistryImdg.getSingleObjectByFieldValues(Map.of("companyId", req.getCompanyId()));

View file

@ -82,6 +82,7 @@ public interface Consts {
String DESTINATION_CLIENT_CODE_DELETE = "client-code-delete"; String DESTINATION_CLIENT_CODE_DELETE = "client-code-delete";
String DESTINATION_TRADING_CLEARING_REGISTRY_NEW = "trading-clearing-registry-new"; String DESTINATION_TRADING_CLEARING_REGISTRY_NEW = "trading-clearing-registry-new";
String DESTINATION_TRADING_CLEARING_REGISTRY_AUTO_NEW = "trading-clearing-registry-auto-new";
String DESTINATION_TRADING_CLEARING_REGISTRY_UPDATE = "trading-clearing-registry-update"; String DESTINATION_TRADING_CLEARING_REGISTRY_UPDATE = "trading-clearing-registry-update";
String DESTINATION_TRADING_CLEARING_REGISTRY_BLOCK = "trading-clearing-registry-block"; String DESTINATION_TRADING_CLEARING_REGISTRY_BLOCK = "trading-clearing-registry-block";