This commit is contained in:
parent
f26826bb4e
commit
c6767821aa
2 changed files with 39 additions and 13 deletions
|
|
@ -4,6 +4,7 @@ import java.time.Instant;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
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.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
@ -42,6 +43,8 @@ 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;
|
||||||
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.ImdgPredicateBuilder;
|
||||||
import ru.spcex.platform.imdg.validation.Stored;
|
import ru.spcex.platform.imdg.validation.Stored;
|
||||||
import ru.spcex.platform.utils.enumeration.EnumMessage;
|
import ru.spcex.platform.utils.enumeration.EnumMessage;
|
||||||
import ru.spcex.platform.utils.enumeration.IMessageResolver;
|
import ru.spcex.platform.utils.enumeration.IMessageResolver;
|
||||||
|
|
@ -145,9 +148,29 @@ public class AccountService extends QueueConsumer implements InitializingBean {
|
||||||
account.setCompanyId(req.getCompanyId());
|
account.setCompanyId(req.getCompanyId());
|
||||||
account.setAccount(req.getAccount());
|
account.setAccount(req.getAccount());
|
||||||
if (AccountType.Info.equalsByKey(req.getAccountType())) {
|
if (AccountType.Info.equalsByKey(req.getAccountType())) {
|
||||||
Long infoSequenceId = informationAccountService.accountNextId(currencyCode, currencyCodeId);
|
Account anltAccount;
|
||||||
|
{
|
||||||
|
ImdgPredicateBuilder pb = accountMap.predicateBuilder();
|
||||||
|
ImdgPredicate andPredicate = pb.and(
|
||||||
|
pb.equals("accountType", AccountType.Anlt.getKey()),
|
||||||
|
pb.equals("currency", currency)
|
||||||
|
);
|
||||||
|
Collection<Account> accountsAnlt = accountMap.getCollectionObjectsByPredicate(andPredicate);
|
||||||
|
if (accountsAnlt.isEmpty()) {
|
||||||
|
log.warn("Account with {} not exist.", andPredicate);
|
||||||
|
} else if (accountsAnlt.size() > 1) {
|
||||||
|
log.warn("Account for companyId 1 and accountType=ANLT contains multiply elements, use first");
|
||||||
|
}
|
||||||
|
anltAccount = accountsAnlt.iterator().next();
|
||||||
|
}
|
||||||
|
|
||||||
String accountValue = informationAccountService.generateInfoAccount(currencyCodeId, infoSequenceId);
|
String specialAnltAccId = "7000";
|
||||||
|
if (anltAccount != null && StringUtils.isNotEmpty(anltAccount.getAccount()) && anltAccount.getAccount().length() >= 4) {
|
||||||
|
specialAnltAccId = anltAccount.getAccount().substring(anltAccount.getAccount().length() - 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
Long infoSequenceId = informationAccountService.accountNextId(currencyCode, currencyCodeId);
|
||||||
|
String accountValue = informationAccountService.generateInfoAccount(currencyCodeId, infoSequenceId, specialAnltAccId);
|
||||||
log.trace("New info-account SequenceId={} account={}", infoSequenceId, accountValue);
|
log.trace("New info-account SequenceId={} account={}", infoSequenceId, accountValue);
|
||||||
account.setAccount(accountValue);
|
account.setAccount(accountValue);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -119,9 +119,6 @@ public class InformationAccountService extends QueueConsumer implements Initiali
|
||||||
String currency = req.getCurrency() == null ? CurrencyCode.RUB.getKey() : req.getCurrency(); //userRequest.getRequestPayload().getCurrency();
|
String currency = req.getCurrency() == null ? CurrencyCode.RUB.getKey() : req.getCurrency(); //userRequest.getRequestPayload().getCurrency();
|
||||||
|
|
||||||
Long newId = informationAccountImdg.nextIDSequenceFor();
|
Long newId = informationAccountImdg.nextIDSequenceFor();
|
||||||
Long infoSequenceId = accountNextId(currency, 810L);
|
|
||||||
String accountValue = generateInfoAccount(810L, infoSequenceId);
|
|
||||||
log.trace("New info-account id={}, sequenceId={}, account={}", newId, infoSequenceId, accountValue);
|
|
||||||
|
|
||||||
ImdgPredicateBuilder accountPredicateBuilder = accountImdg.predicateBuilder();
|
ImdgPredicateBuilder accountPredicateBuilder = accountImdg.predicateBuilder();
|
||||||
ImdgPredicate companyIdPredicate = accountPredicateBuilder.equals("companyId", 1L);
|
ImdgPredicate companyIdPredicate = accountPredicateBuilder.equals("companyId", 1L);
|
||||||
|
|
@ -215,15 +212,11 @@ public class InformationAccountService extends QueueConsumer implements Initiali
|
||||||
String currency = userRequest.getRequestPayload().getCurrency();
|
String currency = userRequest.getRequestPayload().getCurrency();
|
||||||
if (currency == null)
|
if (currency == null)
|
||||||
currency = CurrencyCode.RUB.getKey();
|
currency = CurrencyCode.RUB.getKey();
|
||||||
Long newId = informationAccountImdg.nextIDSequenceFor();
|
|
||||||
Long infoSequenceId = accountNextId(currency, 810L); // требуется последовательность n+1
|
|
||||||
String accountValue = generateInfoAccount(810L, infoSequenceId);
|
|
||||||
log.trace("New info-account id={}, sequenceId={}, account={}", newId, infoSequenceId, accountValue);
|
|
||||||
|
|
||||||
Long anltAccountId = null;
|
Long anltAccountId = null;
|
||||||
|
Account anltAccount;
|
||||||
{
|
{
|
||||||
ImdgPredicate andPredicate = pb.and(
|
ImdgPredicate andPredicate = pb.and(
|
||||||
pb.equals("companyId", 1L),
|
|
||||||
pb.equals("accountType", AccountType.Anlt.getKey()),
|
pb.equals("accountType", AccountType.Anlt.getKey()),
|
||||||
pb.equals("currency", currency)
|
pb.equals("currency", currency)
|
||||||
);
|
);
|
||||||
|
|
@ -234,10 +227,20 @@ public class InformationAccountService extends QueueConsumer implements Initiali
|
||||||
} else if (accountsAnlt.size() > 1) {
|
} else if (accountsAnlt.size() > 1) {
|
||||||
log.warn("Account for companyId 1 and accountType=ANLT contains multiply elements, use first");
|
log.warn("Account for companyId 1 and accountType=ANLT contains multiply elements, use first");
|
||||||
}
|
}
|
||||||
Account anltAccount = accountsAnlt.iterator().next();
|
anltAccount = accountsAnlt.iterator().next();
|
||||||
anltAccountId = anltAccount.getId();
|
anltAccountId = anltAccount.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
String specialAnltAccId = "7000";
|
||||||
|
if (anltAccount != null && StringUtils.isNotEmpty(anltAccount.getAccount()) && anltAccount.getAccount().length() >= 4) {
|
||||||
|
specialAnltAccId = anltAccount.getAccount().substring(anltAccount.getAccount().length() - 4);
|
||||||
|
}
|
||||||
|
Long newId = informationAccountImdg.nextIDSequenceFor();
|
||||||
|
Long infoSequenceId = accountNextId(currency, 810L); // требуется последовательность n+1
|
||||||
|
String accountValue = generateInfoAccount(810L, infoSequenceId, specialAnltAccId);
|
||||||
|
log.trace("New info-account id={}, sequenceId={}, account={}", newId, infoSequenceId, accountValue);
|
||||||
|
|
||||||
Instant now = Instant.now();
|
Instant now = Instant.now();
|
||||||
Account account = new Account();
|
Account account = new Account();
|
||||||
account.setAccount(accountValue);
|
account.setAccount(accountValue);
|
||||||
|
|
@ -301,8 +304,8 @@ public class InformationAccountService extends QueueConsumer implements Initiali
|
||||||
kafkaSender.sendRequestToQueue(Consts.CREATE_NOTIFICATION_NCMP, request);
|
kafkaSender.sendRequestToQueue(Consts.CREATE_NOTIFICATION_NCMP, request);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String generateInfoAccount(Long currencyCodeId, Long id) {
|
public String generateInfoAccount(Long currencyCodeId, Long id, String specialAnltAccId) {
|
||||||
return "%d%03d%08d%d".formatted(39911, currencyCodeId, id, 7000);
|
return "%d%03d%08d%s".formatted(39911, currencyCodeId, id, specialAnltAccId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized Long accountNextId(String currency) {
|
public synchronized Long accountNextId(String currency) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue