SDF03 создание подмена на ANLT номер счета для Info счетов

SDF04 обработка снятие блокировок для счетов при пришедшем ANLT счете
This commit is contained in:
ialbert 2023-07-09 13:52:22 +03:00
parent 7d30f24525
commit 667ca04eeb
5 changed files with 159 additions and 207 deletions

View file

@ -0,0 +1,112 @@
package ru.spcex.clearing.service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import ru.clearing.classes.statics.data.account.Account;
import ru.clearing.classes.statics.data.company.Company;
import ru.clearing.classes.statics.data.payment.PaymentInstruction;
import ru.clearing.classes.statics.data.registry.TradingClearingRegistry;
import ru.clearing.classes.statics.data.sdf.SDf03;
import ru.spcex.clearing.imdg.IMDGDistributedNames;
import ru.spcex.platform.enumeration.AccountType;
import ru.spcex.platform.enumeration.Status;
import ru.spcex.platform.imdg.api.Imdg;
import ru.spcex.platform.imdg.api.ImdgId;
import ru.spcex.platform.imdg.api.ImdgProvider;
import ru.spcex.platform.utils.enumeration.IEnumKey;
import ru.spcex.platform.utils.number.BigDecimalUtil;
import ru.spcex.platform.utils.time.TimeUtil;
import java.time.Instant;
import java.time.format.DateTimeFormatter;
@Component
public class Sdf03Creator {
private Logger log = LoggerFactory.getLogger(getClass());
private final Imdg<TradingClearingRegistry> tradingClearingRegistryImdg;
private final Imdg<Company> companyImdg;
private final Imdg<Account> accountImdg;
private final ImdgId idGenerator;
private static DateTimeFormatter payDateFormatter = DateTimeFormatter.ofPattern("dd.MM.yy");
public Sdf03Creator(ImdgProvider imdgProvider) {
this.tradingClearingRegistryImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_TradingClearingRegistry, TradingClearingRegistry.class);
this.companyImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Company, Company.class);
this.accountImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Account, Account.class);
this.idGenerator = imdgProvider.getImdgIdGenerator();
}
public SDf03 create(PaymentInstruction paymentInstruction) {
Account account = accountImdg.getSingleObjectByID(paymentInstruction.getCreditLeg_accountId());
AccountType accType = IEnumKey.getEnumByKey(AccountType.class, account.getAccountType());
String c_acc_deb;
if (AccountType.Info.equals(accType)) {
Account anltAcc = accountImdg.getSingleObjectBySQL("accountType = '%s' and status = '%s'"
.formatted(AccountType.Anlt, Status.Active.getKey()));
if (anltAcc == null) {
throw new IllegalStateException("SDF03 creation error: paymentInstruction.creditLeg_accountId="
+ paymentInstruction.getCreditLeg_accountId() + " accountType 'Info' but no 'ANLT' account found");
}
c_acc_deb = anltAcc.getAccount();
} else {
c_acc_deb = paymentInstruction.getCreditLeg_account();
}
SDf03 sDf03 = new SDf03();
sDf03.setId(idGenerator.nextId());
sDf03.setSeg_type("S");
sDf03.setDoc_type("002");
String strId = paymentInstruction.getId().toString();
String strIdCut = strId.length() > 16 ? strId.substring(strId.length() - 16) : strId;
sDf03.setDocnm_ref(strIdCut);
sDf03.setC_acc_deb(c_acc_deb);
String senderSbankName = "";
if (paymentInstruction.getSenderId().equals(1L)) {
senderSbankName = paymentInstruction.getPayeeBankName();
} else {
Company company = companyImdg.getSingleObjectByID(paymentInstruction.getSenderId());
if (company != null) {
senderSbankName = company.getShortName();
}
}
SpecifUtil.fillSegmentsBy35Symbols(senderSbankName,
sDf03::setSbanknam1,
sDf03::setSbanknam2,
sDf03::setSbanknam3,
sDf03::setSbanknam4,
sDf03::setSbanknam5);
sDf03.setC_acc_cred(paymentInstruction.getDebitLeg_account());
String addresseeSbankName = "";
if (paymentInstruction.getAddresseeId().equals(1L)) {
addresseeSbankName = paymentInstruction.getAddresseeBankName();
} else {
Company company = companyImdg.getSingleObjectByID(paymentInstruction.getAddresseeId());
if (company != null) {
addresseeSbankName = company.getShortName();
}
}
SpecifUtil.fillSegmentsBy35Symbols(addresseeSbankName,
sDf03::setRbanknam1,
sDf03::setRbanknam2,
sDf03::setRbanknam3,
sDf03::setRbanknam4,
sDf03::setRbanknam5);
sDf03.setPay_date(payDateFormatter.format(TimeUtil.toLocalDate(paymentInstruction.getPaymentDate())));
sDf03.setPay_val("RUR");
String sumDeb = paymentInstruction.getDebitLeg_amount() != null ? paymentInstruction.getDebitLeg_amount().toString() : "";
sDf03.setSum_deb(BigDecimalUtil.limitDecimalPlaces(sumDeb, 2));
sDf03.setSpecif_1(paymentInstruction.getPaymentPurpose());
sDf03.setGenerationTime(Instant.now());
sDf03.setPaymentInstructionId(paymentInstruction.getId());
log.debug("paymentInstruction.id={}, sdf03.id {}", paymentInstruction.getId(), sDf03.getId());
return sDf03;
}
}

View file

@ -3,12 +3,15 @@ package ru.spcex.clearing.service.executors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import ru.clearing.classes.statics.data.account.Account;
import ru.clearing.classes.statics.data.registry.Registry;
import ru.clearing.classes.statics.data.sdf.SDf04;
import ru.spcex.clearing.imdg.IMDGDistributedNames;
import ru.spcex.clearing.platform.messaging.domain.cud.balance.StatementRequest;
import ru.spcex.clearing.platform.messaging.service.sender.KafkaSender;
import ru.spcex.clearing.service.AnltSearcher;
import ru.spcex.clearing.service.model.Result;
import ru.spcex.platform.enumeration.AccountType;
import ru.spcex.platform.enumeration.RegistryDesignation;
import ru.spcex.platform.enumeration.RegistryInstrumentType;
import ru.spcex.platform.enumeration.RegistryUnit;
@ -16,11 +19,13 @@ import ru.spcex.platform.imdg.api.Imdg;
import ru.spcex.platform.imdg.api.ImdgProvider;
import ru.spcex.platform.imdg.api.predicate.ImdgPredicate;
import ru.spcex.platform.imdg.api.predicate.ImdgPredicateBuilder;
import ru.spcex.platform.utils.enumeration.IMessageResolver;
import ru.spcex.platform.utils.log.ExceptionUtils;
import java.math.BigDecimal;
import java.time.Instant;
import java.util.Collection;
import java.util.Collections;
@Service
public class Sdf04Executor extends AbstractExecutor<SDf04> {
@ -28,10 +33,16 @@ public class Sdf04Executor extends AbstractExecutor<SDf04> {
private final ImdgProvider imdgProvider;
private final Imdg<Registry> registryImdg;
private final Imdg<Account> accountImdg;
private final AnltSearcher anltSearcher;
private final IMessageResolver msgRslv;
public Sdf04Executor(ImdgProvider imdgProvider) {
public Sdf04Executor(ImdgProvider imdgProvider, AnltSearcher anltSearcher, IMessageResolver msgRslv) {
this.imdgProvider = imdgProvider;
this.registryImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Registry, Registry.class);
this.accountImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Account, Account.class);
this.anltSearcher = anltSearcher;
this.msgRslv = msgRslv;
}
@Override
@ -55,7 +66,22 @@ public class Sdf04Executor extends AbstractExecutor<SDf04> {
for (SDf04 sdf04 : sdf) {
//обычно мы ищем по группу sdf04, здесь как будто всегда только одна запись, todo нужно прочекать этот момент
log.debug("Process sdf04 record; sdf04.id: {}", sdf04.getId());
Collection<Registry> registries = selectRegistryForSDF04(sdf04.getC_acc_deb());
Collection<Registry> registries;
Account anltAcc = accountImdg.getSingleObjectBySQL("account = '%s' and accountType = '%s'"
.formatted(sdf04.getC_acc_deb(), AccountType.Anlt.getKey()));
//если сдф04 не по аналитическому счету, выбираем по тому c_acc_deb что пришло
if (anltAcc == null) {
registries = selectRegistryForSDF04(sdf04.getC_acc_deb());
} else {
//в сдф04 указан ANLT счет, ищем по контракту
AnltSearcher.AnltSearch anltSearch = anltSearcher.loadByAnlt(sdf04.getSpecif_1());
if (!anltSearch.isFound()) {
log.error("sdf04.id={} search by specif1 failed {}", sdf04.getId(), msgRslv.resolve(anltSearch.getError()));
registries = Collections.emptyList();
} else {
registries = selectRegistryForSDF04(anltSearch.getAccount().getAccount());
}
}
registries.forEach(registry -> unlockRegistry(registry, parseString(sdf04.getSum_deb())));
}
return result;

View file

@ -18,7 +18,7 @@ import ru.spcex.clearing.platform.messaging.domain.Consts;
import ru.spcex.clearing.platform.messaging.domain.cud.balance.ExportToFileRequest;
import ru.spcex.clearing.platform.messaging.domain.cud.importexport.SwtExporterRequest;
import ru.spcex.clearing.platform.messaging.service.sender.KafkaSender;
import ru.spcex.clearing.service.SpecifUtil;
import ru.spcex.clearing.service.Sdf03Creator;
import ru.spcex.clearing.service.builder.PaymentInstructionBuilder;
import ru.spcex.clearing.session.stage.ISessionStage;
import ru.spcex.clearing.session.stage.StageResult;
@ -35,7 +35,6 @@ import ru.spcex.platform.utils.enumeration.IEnumKey;
import ru.spcex.platform.utils.enumeration.IMessageResolver;
import ru.spcex.platform.utils.enumeration.SimpleMessageResolver;
import ru.spcex.platform.utils.number.BigDecimalUtil;
import ru.spcex.platform.utils.time.TimeUtil;
import java.math.BigDecimal;
import java.time.Instant;
@ -58,11 +57,12 @@ public class FormingPaymentInstruction implements ISessionStage {
private Imdg<SDf03> sDf03Imdg;
private Imdg<SDf12> sDf12Imdg;
private KafkaSender kafkaSender;
private final Sdf03Creator sdf03Creator;
private final IMessageResolver msgResolver = new SimpleMessageResolver();
@Autowired
public FormingPaymentInstruction(ImdgProvider imdgProvider,
KafkaSender kafkaSender) {
KafkaSender kafkaSender, Sdf03Creator sdf03Creator) {
this.kafkaSender = kafkaSender;
this.imdgProvider = imdgProvider;
this.idGenerator = imdgProvider.getImdgIdGenerator();
@ -73,6 +73,7 @@ public class FormingPaymentInstruction implements ISessionStage {
this.sDf03Imdg = imdgProvider.getImdg(IMDGDistributedNames.Map_SDf03, SDf03.class);
this.sDf12Imdg = imdgProvider.getImdg(IMDGDistributedNames.Map_SDf12, SDf12.class);
this.paymentInstructionImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_PaymentInstruction, PaymentInstruction.class);
this.sdf03Creator = sdf03Creator;
}
@Override
@ -284,8 +285,8 @@ public class FormingPaymentInstruction implements ISessionStage {
Security security = securityImdg.getSingleObjectByID(paymentInstruction.getCreditLeg_securityId());
Account account = accountImdg.getSingleObjectByID(paymentInstruction.getCreditLeg_accountId());
if (InstrumentType.CRNC.equalsByKey(security.getInstrumentType()) &&
List.of(AccountType.Corr, AccountType.Clrn).contains(IEnumKey.getEnumByKey(AccountType.class, account.getAccountType()))) {
sDf03Created.add(newSDf03(paymentInstruction));
List.of(AccountType.Corr, AccountType.Clrn, AccountType.Info).contains(IEnumKey.getEnumByKey(AccountType.class, account.getAccountType()))) {
sDf03Created.add(sdf03Creator.create(paymentInstruction));
} else if (!InstrumentType.CRNC.equalsByKey(security.getInstrumentType()) &&
AccountType.Depo.equalsByKey(account.getAccountType())) {
sDf12Created.add(newSDf12(paymentInstruction));
@ -338,62 +339,6 @@ public class FormingPaymentInstruction implements ISessionStage {
return paymentInstructionBuilder.build();
}
private SDf03 newSDf03(PaymentInstruction paymentInstruction) {
log.debug("creating sdf03");
SDf03 sDf03 = new SDf03();
sDf03.setId(idGenerator.nextId());
sDf03.setSeg_type("S");
sDf03.setDoc_type("002");
String strId = paymentInstruction.getId().toString();
String strIdCut = strId.length() > 16 ? strId.substring(strId.length() - 16) : strId;
sDf03.setDocnm_ref(strIdCut);
sDf03.setC_acc_deb(paymentInstruction.getCreditLeg_account());
String senderSbankName = "";
if (paymentInstruction.getSenderId().equals(1L)) {
senderSbankName = paymentInstruction.getPayeeBankName();
} else {
Company company = companyImdg.getSingleObjectByID(paymentInstruction.getSenderId());
if (company != null) {
senderSbankName = company.getShortName();
}
}
SpecifUtil.fillSegmentsBy35Symbols(senderSbankName,
sDf03::setSbanknam1,
sDf03::setSbanknam2,
sDf03::setSbanknam3,
sDf03::setSbanknam4,
sDf03::setSbanknam5);
sDf03.setC_acc_cred(paymentInstruction.getDebitLeg_account());
String addresseeSbankName = "";
if (paymentInstruction.getAddresseeId().equals(1L)) {
addresseeSbankName = paymentInstruction.getAddresseeBankName();
} else {
Company company = companyImdg.getSingleObjectByID(paymentInstruction.getAddresseeId());
if (company != null) {
addresseeSbankName = company.getShortName();
}
}
SpecifUtil.fillSegmentsBy35Symbols(addresseeSbankName,
sDf03::setRbanknam1,
sDf03::setRbanknam2,
sDf03::setRbanknam3,
sDf03::setRbanknam4,
sDf03::setRbanknam5);
sDf03.setPay_date(payDateFormatter.format(TimeUtil.toLocalDate(paymentInstruction.getPaymentDate())));
sDf03.setPay_val("RUR");
String sumDeb = paymentInstruction.getDebitLeg_amount() != null ? paymentInstruction.getDebitLeg_amount().toString() : "";
sDf03.setSum_deb(BigDecimalUtil.limitDecimalPlaces(sumDeb, 2));
sDf03.setSpecif_1(paymentInstruction.getPaymentPurpose());
sDf03.setGenerationTime(Instant.now());
sDf03.setPaymentInstructionId(paymentInstruction.getId());
log.debug("successfully processed, new id {}", sDf03.getId());
return sDf03;
}
private SDf12 newSDf12(PaymentInstruction paymentInstruction) {
log.debug("creating sdf12");
SDf12 sDf12 = new SDf12();

View file

@ -18,7 +18,7 @@ import ru.spcex.clearing.imdg.IMDGDistributedNames;
import ru.spcex.clearing.platform.messaging.domain.Consts;
import ru.spcex.clearing.platform.messaging.domain.cud.balance.ExportToFileRequest;
import ru.spcex.clearing.platform.messaging.service.sender.KafkaSender;
import ru.spcex.clearing.service.SpecifUtil;
import ru.spcex.clearing.service.Sdf03Creator;
import ru.spcex.clearing.service.builder.PaymentInstructionBuilderFinalMkrDeals;
import ru.spcex.clearing.session.stage.ISessionStage;
import ru.spcex.clearing.session.stage.StageResult;
@ -37,7 +37,6 @@ import ru.spcex.platform.utils.enumeration.IEnumKey;
import ru.spcex.platform.utils.enumeration.IMessageResolver;
import ru.spcex.platform.utils.enumeration.SimpleMessageResolver;
import ru.spcex.platform.utils.number.BigDecimalUtil;
import ru.spcex.platform.utils.time.TimeUtil;
import java.time.Instant;
import java.time.LocalDate;
@ -64,12 +63,14 @@ public class FormingPaymentInstructionDealsFinalMkr implements ISessionStage {
private Imdg<Company> companyImdg;
private Imdg<SDf03> sDf03Imdg;
private Imdg<SDf12> sDf12Imdg;
private final Sdf03Creator sdf03Creator;
private KafkaSender kafkaSender;
private final IMessageResolver msgResolver = new SimpleMessageResolver();
@Autowired
public FormingPaymentInstructionDealsFinalMkr(ImdgProvider imdgProvider,
KafkaSender kafkaSender) {
Sdf03Creator sdf03Creator, KafkaSender kafkaSender) {
this.sdf03Creator = sdf03Creator;
this.kafkaSender = kafkaSender;
this.imdgProvider = imdgProvider;
this.idGenerator = imdgProvider.getImdgIdGenerator();
@ -235,9 +236,10 @@ public class FormingPaymentInstructionDealsFinalMkr implements ISessionStage {
List<SDf03> sDf03Created = new ArrayList<>();
for (PaymentInstruction paymentInstruction : formedPaymentInstructions) {
Account account = accountImdg.getSingleObjectByID(paymentInstruction.getCreditLeg_accountId());
if (List.of(AccountType.Corr, AccountType.Clrn, AccountType.Tran, AccountType.Anlt)
if (List.of(AccountType.Corr, AccountType.Clrn, AccountType.Tran, AccountType.Anlt, AccountType.Info)
.contains(IEnumKey.getEnumByKey(AccountType.class, account.getAccountType()))) {
sDf03Created.add(newSDf03(paymentInstruction));
//если info подставить anlt (единственный счет в системе)
sDf03Created.add(sdf03Creator.create(paymentInstruction));
}
}
@ -255,73 +257,6 @@ public class FormingPaymentInstructionDealsFinalMkr implements ISessionStage {
}
}
private SDf03 newSDf03(PaymentInstruction paymentInstruction) {
log.debug("creating sdf03");
SDf03 sDf03 = new SDf03();
sDf03.setId(idGenerator.nextId());
sDf03.setSeg_type("S");
sDf03.setDoc_type("002");
String strId = paymentInstruction.getId().toString();
String strIdCut = strId.length() > 16 ? strId.substring(strId.length() - 16) : strId;
sDf03.setDocnm_ref(strIdCut);
sDf03.setC_acc_deb(paymentInstruction.getCreditLeg_account());
String senderSbankName = "";
if (paymentInstruction.getSenderId().equals(1L)) {
senderSbankName = paymentInstruction.getPayeeBankName();
} else {
Company company = companyImdg.getSingleObjectByID(paymentInstruction.getSenderId());
if (company != null) {
senderSbankName = company.getShortName();
}
}
String[] bnkNmeParts = SpecifUtil.split5SegmentsBy35Symbols(senderSbankName);
for (int i = 0; i < bnkNmeParts.length; i++) {
if (i == 0) {
sDf03.setSbanknam1(bnkNmeParts[i]);
}
if (i == 1) {
sDf03.setSbanknam2(bnkNmeParts[i]);
}
if (i == 2) {
sDf03.setSbanknam3(bnkNmeParts[i]);
}
if (i == 3) {
sDf03.setSbanknam4(bnkNmeParts[i]);
}
if (i == 4) {
sDf03.setSbanknam5(bnkNmeParts[i]);
}
}
sDf03.setC_acc_cred(paymentInstruction.getDebitLeg_account());
String addresseeSbankName = "";
if (paymentInstruction.getAddresseeId().equals(1L)) {
addresseeSbankName = paymentInstruction.getAddresseeBankName();
} else {
Company company = companyImdg.getSingleObjectByID(paymentInstruction.getAddresseeId());
if (company != null) {
addresseeSbankName = company.getShortName();
}
}
sDf03.setRbanknam1(addresseeSbankName);
sDf03.setRbanknam2(addresseeSbankName);
sDf03.setRbanknam3(addresseeSbankName);
sDf03.setRbanknam4(addresseeSbankName);
sDf03.setRbanknam5(addresseeSbankName);
sDf03.setPay_date(payDateFormatter.format(TimeUtil.toLocalDate(paymentInstruction.getPaymentDate())));
sDf03.setPay_val("RUR");
String sumDeb = paymentInstruction.getDebitLeg_amount() != null ? paymentInstruction.getDebitLeg_amount().toString() : "";
sDf03.setSum_deb(BigDecimalUtil.limitDecimalPlaces(sumDeb, 2));
sDf03.setSpecif_1(paymentInstruction.getPaymentPurpose());
sDf03.setGenerationTime(Instant.now());
sDf03.setPaymentInstructionId(paymentInstruction.getId());
log.debug("successfully processed, new id {}", sDf03.getId());
return sDf03;
}
private SDf12 newSDf12(PaymentInstruction paymentInstruction) {
log.debug("creating sdf12");
SDf12 sDf12 = new SDf12();

View file

@ -18,7 +18,7 @@ import ru.spcex.clearing.imdg.IMDGDistributedNames;
import ru.spcex.clearing.platform.messaging.domain.Consts;
import ru.spcex.clearing.platform.messaging.domain.cud.balance.ExportToFileRequest;
import ru.spcex.clearing.platform.messaging.service.sender.KafkaSender;
import ru.spcex.clearing.service.SpecifUtil;
import ru.spcex.clearing.service.Sdf03Creator;
import ru.spcex.clearing.service.builder.PaymentInstructionBuilderFinalMkrDeals;
import ru.spcex.clearing.session.stage.ISessionStage;
import ru.spcex.clearing.session.stage.StageResult;
@ -37,7 +37,6 @@ import ru.spcex.platform.utils.enumeration.IEnumKey;
import ru.spcex.platform.utils.enumeration.IMessageResolver;
import ru.spcex.platform.utils.enumeration.SimpleMessageResolver;
import ru.spcex.platform.utils.number.BigDecimalUtil;
import ru.spcex.platform.utils.time.TimeUtil;
import java.time.Instant;
import java.time.LocalDate;
@ -65,11 +64,12 @@ public class FormingPaymentInstructionSecondaryT0 implements ISessionStage {
private Imdg<SDf03> sDf03Imdg;
private Imdg<SDf12> sDf12Imdg;
private KafkaSender kafkaSender;
private final Sdf03Creator sdf03Creator;
private final IMessageResolver msgResolver = new SimpleMessageResolver();
@Autowired
public FormingPaymentInstructionSecondaryT0(ImdgProvider imdgProvider,
KafkaSender kafkaSender) {
KafkaSender kafkaSender, Sdf03Creator sdf03Creator) {
this.kafkaSender = kafkaSender;
this.imdgProvider = imdgProvider;
this.idGenerator = imdgProvider.getImdgIdGenerator();
@ -80,6 +80,7 @@ public class FormingPaymentInstructionSecondaryT0 implements ISessionStage {
this.sDf03Imdg = imdgProvider.getImdg(IMDGDistributedNames.Map_SDf03, SDf03.class);
this.sDf12Imdg = imdgProvider.getImdg(IMDGDistributedNames.Map_SDf12, SDf12.class);
this.paymentInstructionImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_PaymentInstruction, PaymentInstruction.class);
this.sdf03Creator = sdf03Creator;
}
@Override
@ -235,9 +236,9 @@ public class FormingPaymentInstructionSecondaryT0 implements ISessionStage {
List<SDf03> sDf03Created = new ArrayList<>();
for (PaymentInstruction paymentInstruction : formedPaymentInstructions) {
Account account = accountImdg.getSingleObjectByID(paymentInstruction.getCreditLeg_accountId());
if (List.of(AccountType.Corr, AccountType.Clrn, AccountType.Tran, AccountType.Anlt)
if (List.of(AccountType.Corr, AccountType.Clrn, AccountType.Tran, AccountType.Anlt, AccountType.Info)
.contains(IEnumKey.getEnumByKey(AccountType.class, account.getAccountType()))) {
sDf03Created.add(newSDf03(paymentInstruction));
sDf03Created.add(sdf03Creator.create(paymentInstruction));
}
}
@ -255,73 +256,6 @@ public class FormingPaymentInstructionSecondaryT0 implements ISessionStage {
}
}
private SDf03 newSDf03(PaymentInstruction paymentInstruction) {
log.debug("creating sdf03");
SDf03 sDf03 = new SDf03();
sDf03.setId(idGenerator.nextId());
sDf03.setSeg_type("S");
sDf03.setDoc_type("002");
String strId = paymentInstruction.getId().toString();
String strIdCut = strId.length() > 16 ? strId.substring(strId.length() - 16) : strId;
sDf03.setDocnm_ref(strIdCut);
sDf03.setC_acc_deb(paymentInstruction.getCreditLeg_account());
String senderSbankName = "";
if (paymentInstruction.getSenderId().equals(1L)) {
senderSbankName = paymentInstruction.getPayeeBankName();
} else {
Company company = companyImdg.getSingleObjectByID(paymentInstruction.getSenderId());
if (company != null) {
senderSbankName = company.getShortName();
}
}
String[] bnkNmeParts = SpecifUtil.split5SegmentsBy35Symbols(senderSbankName);
for (int i = 0; i < bnkNmeParts.length; i++) {
if (i == 0) {
sDf03.setSbanknam1(bnkNmeParts[i]);
}
if (i == 1) {
sDf03.setSbanknam2(bnkNmeParts[i]);
}
if (i == 2) {
sDf03.setSbanknam3(bnkNmeParts[i]);
}
if (i == 3) {
sDf03.setSbanknam4(bnkNmeParts[i]);
}
if (i == 4) {
sDf03.setSbanknam5(bnkNmeParts[i]);
}
}
sDf03.setC_acc_cred(paymentInstruction.getDebitLeg_account());
String addresseeSbankName = "";
if (paymentInstruction.getAddresseeId().equals(1L)) {
addresseeSbankName = paymentInstruction.getAddresseeBankName();
} else {
Company company = companyImdg.getSingleObjectByID(paymentInstruction.getAddresseeId());
if (company != null) {
addresseeSbankName = company.getShortName();
}
}
sDf03.setRbanknam1(addresseeSbankName);
sDf03.setRbanknam2(addresseeSbankName);
sDf03.setRbanknam3(addresseeSbankName);
sDf03.setRbanknam4(addresseeSbankName);
sDf03.setRbanknam5(addresseeSbankName);
sDf03.setPay_date(payDateFormatter.format(TimeUtil.toLocalDate(paymentInstruction.getPaymentDate())));
sDf03.setPay_val("RUR");
String sumDeb = paymentInstruction.getDebitLeg_amount() != null ? paymentInstruction.getDebitLeg_amount().toString() : "";
sDf03.setSum_deb(BigDecimalUtil.limitDecimalPlaces(sumDeb, 2));
sDf03.setSpecif_1(paymentInstruction.getPaymentPurpose());
sDf03.setGenerationTime(Instant.now());
sDf03.setPaymentInstructionId(paymentInstruction.getId());
log.debug("successfully processed, new id {}", sDf03.getId());
return sDf03;
}
private SDf12 newSDf12(PaymentInstruction paymentInstruction) {
log.debug("creating sdf12");
SDf12 sDf12 = new SDf12();