company-service account-srvice http://jira.mfd.msk:8088/browse/CLS-265 http://jira.mfd.msk:8088/browse/CLS-333 system new Info-account
This commit is contained in:
parent
c922351170
commit
75968bba76
4 changed files with 111 additions and 1 deletions
|
|
@ -29,11 +29,13 @@ import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||||
import ru.spcex.platform.imdg.api.ImdgTransaction;
|
import ru.spcex.platform.imdg.api.ImdgTransaction;
|
||||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicate;
|
import ru.spcex.platform.imdg.api.predicate.ImdgPredicate;
|
||||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicateBuilder;
|
import ru.spcex.platform.imdg.api.predicate.ImdgPredicateBuilder;
|
||||||
|
import ru.spcex.platform.utils.enumeration.EnumMessage;
|
||||||
import ru.spcex.platform.utils.enumeration.IMessageResolver;
|
import ru.spcex.platform.utils.enumeration.IMessageResolver;
|
||||||
import ru.spcex.platform.utils.validation.IValidator;
|
import ru.spcex.platform.utils.validation.IValidator;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
|
@ -81,6 +83,9 @@ public class InformationAccountService extends QueueConsumer implements Initiali
|
||||||
callback(InformationAccountNewRequest.class)
|
callback(InformationAccountNewRequest.class)
|
||||||
.setFunction(this::informationAccountNew)
|
.setFunction(this::informationAccountNew)
|
||||||
.forDestination(Consts.DESTINATION_INFORMATION_ACCOUNT_NEW, callbacks::put);
|
.forDestination(Consts.DESTINATION_INFORMATION_ACCOUNT_NEW, callbacks::put);
|
||||||
|
callback(InformationAccountNewRequest.class)
|
||||||
|
.setFunction(this::informationAccountSystemNew)
|
||||||
|
.forDestination(Consts.INFORMATION_ACCOUNT_SYSTEM_NEW, callbacks::put);
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -94,7 +99,7 @@ public class InformationAccountService extends QueueConsumer implements Initiali
|
||||||
String accountValue = generateInfoAccount(newId);
|
String accountValue = generateInfoAccount(newId);
|
||||||
|
|
||||||
ImdgPredicateBuilder accountPredicateBuilder = accountImdg.predicateBuilder();
|
ImdgPredicateBuilder accountPredicateBuilder = accountImdg.predicateBuilder();
|
||||||
ImdgPredicate companyIdPredicate = accountPredicateBuilder.equals("companyId", 1);
|
ImdgPredicate companyIdPredicate = accountPredicateBuilder.equals("companyId", 1L);
|
||||||
ImdgPredicate accountTypePredicate = accountPredicateBuilder.equals("accountType", AccountType.Anlt.getKey());
|
ImdgPredicate accountTypePredicate = accountPredicateBuilder.equals("accountType", AccountType.Anlt.getKey());
|
||||||
ImdgPredicate andPredicate = accountPredicateBuilder.and(companyIdPredicate, accountTypePredicate);
|
ImdgPredicate andPredicate = accountPredicateBuilder.and(companyIdPredicate, accountTypePredicate);
|
||||||
Collection<Account> accountsAnlt = accountImdg.getCollectionObjectsByPredicate(andPredicate);
|
Collection<Account> accountsAnlt = accountImdg.getCollectionObjectsByPredicate(andPredicate);
|
||||||
|
|
@ -154,6 +159,94 @@ public class InformationAccountService extends QueueConsumer implements Initiali
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public RequestInfoUpdate informationAccountSystemNew(BaseRequest<InformationAccountNewRequest> userRequest) {
|
||||||
|
log.debug("InformationAccountNewRequest received (system)");
|
||||||
|
|
||||||
|
RequestInfoUpdate requestInfoUpdate;
|
||||||
|
// RequestInfoUpdate requestInfoUpdate = validationHelper.validateTillFirstError(userRequest, infoAccountNewRequestValidator);
|
||||||
|
// if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||||
|
final Long forCompanyId = userRequest.getRequestPayload().getCompanyId();
|
||||||
|
|
||||||
|
ImdgPredicateBuilder pb = accountImdg.predicateBuilder();
|
||||||
|
{ // Проверка существования счёта
|
||||||
|
Collection<Account> accountsAnlt = accountImdg.getCollectionObjectsByFieldValues(Map.of(
|
||||||
|
"companyId", forCompanyId,
|
||||||
|
"accountType", AccountType.Info.getKey()
|
||||||
|
));
|
||||||
|
if (!accountsAnlt.isEmpty()) {
|
||||||
|
String trueMessage = messageResolver.resolve(new EnumMessage(AccountError.InfoAccountAlreadyExist, forCompanyId));
|
||||||
|
log.warn("{}", trueMessage);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// todo требуется последовательность n+1
|
||||||
|
Long newId = informationAccountImdg.nextIDSequenceFor();
|
||||||
|
String accountValue = generateInfoAccount(newId);
|
||||||
|
|
||||||
|
ImdgPredicate andPredicate = pb.and(
|
||||||
|
pb.equals("companyId", 1L),
|
||||||
|
pb.equals("accountType", AccountType.Anlt.getKey())
|
||||||
|
);
|
||||||
|
Collection<Account> accountsAnlt = accountImdg.getCollectionObjectsByPredicate(andPredicate);
|
||||||
|
if (accountsAnlt.isEmpty()) {
|
||||||
|
return requestHelper.makeErrorResponse(userRequest, AccountError.WrongFieldValue, "clearingAccountId");
|
||||||
|
} else if (accountsAnlt.size() > 1) {
|
||||||
|
log.warn("Account for companyId 1 and accountType=ANLT contains multiply elements, use first");
|
||||||
|
}
|
||||||
|
Account anltAccount = accountsAnlt.iterator().next();
|
||||||
|
|
||||||
|
Instant now = Instant.now();
|
||||||
|
Account account = new Account();
|
||||||
|
account.setAccount(accountValue);
|
||||||
|
account.setAccountType(AccountType.Info.getKey());
|
||||||
|
account.setStatus(ServiceStatus.Active.getKey());
|
||||||
|
account.setCompanyId(forCompanyId);
|
||||||
|
account.setCreated(now);
|
||||||
|
account.setUpdated(now);
|
||||||
|
requestInfoUpdate = accountService.fillAccountFromRelation(account, userRequest.getId());
|
||||||
|
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||||
|
|
||||||
|
ImdgTransaction imdgTransaction = imdgProvider.newTransaction();
|
||||||
|
imdgTransaction.beginTransaction();
|
||||||
|
boolean txOk = false;
|
||||||
|
Long informationAccountId = -1L;
|
||||||
|
Long accountId = -1L;
|
||||||
|
InformationAccount informationAccount = null;
|
||||||
|
try {
|
||||||
|
accountId = accountImdg.insert(account);
|
||||||
|
|
||||||
|
informationAccount = new InformationAccount();
|
||||||
|
informationAccount.setId(newId);
|
||||||
|
informationAccount.setAccountId(accountId);
|
||||||
|
informationAccount.setClearingAccountId(anltAccount.getId());
|
||||||
|
informationAccount.setCompanyId(userRequest.getRequestPayload().getCompanyId());
|
||||||
|
informationAccountId = informationAccountImdg.insert(informationAccount);
|
||||||
|
txOk = true;
|
||||||
|
} finally {
|
||||||
|
if (txOk) {
|
||||||
|
imdgTransaction.commitTransaction();
|
||||||
|
TradingClearingRegistryNewRequest request = new TradingClearingRegistryNewRequest();
|
||||||
|
request.setMoneyAccountId(informationAccountId);
|
||||||
|
request.setCompanyId(informationAccount.getCompanyId());
|
||||||
|
log.debug("Send message to kafka \"{}\": {}", Consts.DESTINATION_TRADING_CLEARING_REGISTRY_AUTO_NEW, LogFormatter.toStringWrapper(request));
|
||||||
|
kafkaSender.sendRequestToQueue(Consts.DESTINATION_TRADING_CLEARING_REGISTRY_AUTO_NEW, request);
|
||||||
|
log.debug("successfully processed, new information account id {}, new account id {}",
|
||||||
|
informationAccountId,
|
||||||
|
accountId);
|
||||||
|
} else {
|
||||||
|
log.debug("failed insert, new information account id {}, new account id {} (if id = -1 then insert is failed)",
|
||||||
|
informationAccountId,
|
||||||
|
accountId);
|
||||||
|
imdgTransaction.rollbackTransaction();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public String generateInfoAccount(Long id) {
|
public String generateInfoAccount(Long id) {
|
||||||
return "%d%d%08d%d".formatted(39911, 810, id, 7000);
|
return "%d%d%08d%d".formatted(39911, 810, id, 7000);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,12 @@ import ru.clearing.classes.statics.data.liabilities.LiabilitiesClaimsAssets;
|
||||||
import ru.spcex.clearing.company.error.CompanyErrors;
|
import ru.spcex.clearing.company.error.CompanyErrors;
|
||||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||||
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.AccountNewRequest;
|
||||||
|
import ru.spcex.clearing.platform.messaging.domain.cud.account.InformationAccountNewRequest;
|
||||||
import ru.spcex.clearing.platform.messaging.domain.cud.account.sdf01.AccountTerminationRequest;
|
import ru.spcex.clearing.platform.messaging.domain.cud.account.sdf01.AccountTerminationRequest;
|
||||||
import ru.spcex.clearing.platform.messaging.service.sender.KafkaSender;
|
import ru.spcex.clearing.platform.messaging.service.sender.KafkaSender;
|
||||||
|
import ru.spcex.platform.enumeration.AccountType;
|
||||||
|
import ru.spcex.platform.enumeration.WorkflowStatus;
|
||||||
import ru.spcex.platform.imdg.api.Imdg;
|
import ru.spcex.platform.imdg.api.Imdg;
|
||||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||||
|
|
||||||
|
|
@ -82,4 +86,15 @@ public class AccountNotificationHelper {
|
||||||
// ответ должен послаться в DESTINATION_COMPANY_BLOCK = "company-block";
|
// ответ должен послаться в DESTINATION_COMPANY_BLOCK = "company-block";
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void makeInfoAccount(Long companyId) {
|
||||||
|
InformationAccountNewRequest r = new InformationAccountNewRequest();
|
||||||
|
r.setCompanyId(companyId);
|
||||||
|
// формат "39911"+ "810" +"000001"(счётчик)+"7000"; пример: "39911810000000017000"
|
||||||
|
|
||||||
|
log.debug("Sending messages to account-service {} for company {}",
|
||||||
|
Consts.INFORMATION_ACCOUNT_SYSTEM_NEW, companyId);
|
||||||
|
Long reqId = kafkaSender.sendRequestToQueue(Consts.INFORMATION_ACCOUNT_SYSTEM_NEW, r);
|
||||||
|
log.debug("Send request id={}", reqId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -152,6 +152,7 @@ public class CompanyService extends QueueConsumer implements InitializingBean {
|
||||||
else
|
else
|
||||||
transaction.rollbackTransaction();
|
transaction.rollbackTransaction();
|
||||||
}
|
}
|
||||||
|
accountNotification.makeInfoAccount(company.getId());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -66,6 +66,7 @@ public interface Consts {
|
||||||
String DESTINATION_CLEARING_ACCOUNT_UPDATE = "clearing-account-update";
|
String DESTINATION_CLEARING_ACCOUNT_UPDATE = "clearing-account-update";
|
||||||
|
|
||||||
String DESTINATION_INFORMATION_ACCOUNT_NEW = "information-account-new";
|
String DESTINATION_INFORMATION_ACCOUNT_NEW = "information-account-new";
|
||||||
|
String INFORMATION_ACCOUNT_SYSTEM_NEW = "information-account-system-new";
|
||||||
|
|
||||||
String DESTINATION_CORRESPONDENT_ACCOUNT_NEW = "correspondent-account-new";
|
String DESTINATION_CORRESPONDENT_ACCOUNT_NEW = "correspondent-account-new";
|
||||||
String DESTINATION_CORRESPONDENT_ACCOUNT_UPDATE = "correspondent-account-update";
|
String DESTINATION_CORRESPONDENT_ACCOUNT_UPDATE = "correspondent-account-update";
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue