clearing-service http://jira.mfd.msk:8088/browse/CLS-311 доделки Sdf54

This commit is contained in:
AKurakin 2023-09-06 12:14:43 +03:00
parent 534e1d8cfe
commit de16808e25
2 changed files with 41 additions and 52 deletions

View file

@ -11,10 +11,7 @@ import ru.clearing.classes.statics.data.payment.PaymentInstruction;
import ru.clearing.classes.statics.data.registry.TradingClearingRegistry;
import ru.clearing.classes.statics.data.sdf.SDf54;
import ru.spcex.clearing.imdg.IMDGDistributedNames;
import ru.spcex.platform.enumeration.AccountType;
import ru.spcex.platform.enumeration.CompanySymbol;
import ru.spcex.platform.enumeration.Sender;
import ru.spcex.platform.enumeration.Status;
import ru.spcex.platform.enumeration.*;
import ru.spcex.platform.imdg.api.Imdg;
import ru.spcex.platform.imdg.api.ImdgId;
import ru.spcex.platform.imdg.api.ImdgProvider;
@ -50,24 +47,10 @@ public class Sdf54Creator {
public SDf54 create(PaymentInstruction paymentInstruction) {
Instant now = Instant.now();
AccountType creditAccType = getAccountType(paymentInstruction.getCreditLeg_accountId());
AccountType debAccType = getAccountType(paymentInstruction.getDebitLeg_accountId());
String c_acc_deb = null;
String c_acc_cred = null;
Account anltAcc = accountImdg.getFirstObjectBySQL("accountType = '%s' and status = '%s'"
.formatted(AccountType.Anlt.getKey(), Status.Active.getKey()));
if (AccountType.Info.equals(creditAccType) ^ AccountType.Info.equals(debAccType)) {
if (anltAcc == null) {
throw new IllegalStateException("SDF54 creation error: paymentInstruction.creditLeg_accountId="
+ paymentInstruction.getCreditLeg_accountId() + " accountType 'Info' but no 'ANLT' account found");
}
if (AccountType.Info.equals(creditAccType)) {
c_acc_deb = anltAcc.getAccount();
} else {
c_acc_cred = anltAcc.getAccount();
}
}
c_acc_deb = c_acc_deb == null ? paymentInstruction.getCreditLeg_account() : c_acc_deb;
// c_acc_deb = c_acc_deb == null ? paymentInstruction.getCreditLeg_account() : c_acc_deb;
c_acc_cred = c_acc_cred == null ? paymentInstruction.getDebitLeg_account() : c_acc_cred;
@ -111,50 +94,50 @@ public class Sdf54Creator {
if (anltAcc != null) {
sDf54.setAcc_deb(anltAcc.getAccount());
}
Account accDebAcc = accountImdg.getSingleObjectByID(paymentInstruction.getDebitLeg_accountId());
if (accDebAcc == null || !AccountStatus.ACTIVE.equalsByKey(accDebAcc.getStatus())) {
log.warn("paymentInstruction[{}].DebitLeg_accountId={} account not exist or not active.", paymentInstruction.getId(), paymentInstruction.getDebitLeg_accountId());
}
BankAccount bnkAcc = bankAccountImdg.getFirstObjectBySQL("accountId = %d".formatted(paymentInstruction.getDebitLeg_accountId()));
if (bnkAcc != null) {
sDf54.setInn_cred(bnkAcc.getTaxpayerIdentificationNumber());
sDf54.setKpp_cred(bnkAcc.getTaxRegistrationReasonCode());
c_acc_cred = bnkAcc.getCorrespondentAccount();
} else {
log.warn("Bank account not found for DebitLeg_accountId={}", paymentInstruction.getDebitLeg_accountId());
}
sDf54.setAcc_kr_1(paymentInstruction.getDebitLeg_account());
{
Account prcCorrAcc = accountImdg.getFirstObjectBySQL("companyId=%d and accountType = '%s' and status = '%s'"
.formatted(Sender.Prc.getId(), AccountType.Corr.getKey(), Status.Active.getKey()));
if (prcCorrAcc == null) {
log.warn("Account for PRC CORR not found");
} else {
sDf54.setC_acc_deb(prcCorrAcc.getAccount());
}
}
//**********************
sDf54.setSend_type("срочно");
sDf54.setDoc_type("002");
sDf54.setDocnm_ref(docnmRefFormatter.format(TimeUtil.toDateTime(now)));
sDf54.setC_acc_deb(c_acc_deb);
Account rBnkAccount = accountImdg.getFirstObjectBySQL("companyId=%s and accountType = '%s' and status = '%s'"
.formatted(paymentInstruction.getAddresseeId(), AccountType.Bank.getKey(), Status.Active.getKey()));
BankAccount rBnkAcc = rBnkAccount == null ? null : bankAccountImdg.getFirstObjectBySQL("accountId = %d".formatted(rBnkAccount.getId()));
if (rBnkAcc != null) {
sDf54.setRbankcode(rBnkAcc.getBankIdentificationCode());
if (rBnkAcc.getCorrespondentAccount() != null && !rBnkAcc.getCorrespondentAccount().equals(c_acc_cred)) {
log.warn("By paymentInstruction[{}] found accountId={} with CorrespondentAccount=\"{}\" not same that c_acc_cred=\"{}\"", paymentInstruction.getId(), rBnkAccount.getId(),
rBnkAcc.getCorrespondentAccount(), c_acc_cred);
}
// Account rBnkAccount = accountImdg.getFirstObjectBySQL("companyId=%s and accountType = '%s' and status = '%s'"
// .formatted(paymentInstruction.getAddresseeId(), AccountType.Bank.getKey(), Status.Active.getKey()));
// BankAccount rBnkAcc = rBnkAccount == null ? null : bankAccountImdg.getFirstObjectBySQL("accountId = %d".formatted(rBnkAccount.getId()));
if (bnkAcc != null) {
sDf54.setRbankcode(bnkAcc.getBankIdentificationCode());
SpecifUtil.fillSegmentsBy35Symbols(bnkAcc.getCorrespondentAccountName(),
sDf54::setRbanknam1,
sDf54::setRbanknam2,
sDf54::setRbanknam3,
sDf54::setRbanknam4,
sDf54::setRbanknam5);
}
sDf54.setC_acc_cred(c_acc_cred);
String addresseeSbankName = "";
if (Sender.One.equalsById(paymentInstruction.getAddresseeId())) { // == 1
addresseeSbankName = paymentInstruction.getAddresseeBankName();
} else {
Company company = companyImdg.getSingleObjectByID(paymentInstruction.getAddresseeId());
if (company != null) {
addresseeSbankName = company.getShortName();
}
}
SpecifUtil.fillSegmentsBy35Symbols(addresseeSbankName,
sDf54::setRbanknam1,
sDf54::setRbanknam2,
sDf54::setRbanknam3,
sDf54::setRbanknam4,
sDf54::setRbanknam5);
{
Company company1 = companyImdg.getSingleObjectByID(Sender.One.getId());
if (company1 != null) { // "АО СПВБ" company.shortName[id = 1]
@ -168,9 +151,8 @@ public class Sdf54Creator {
}
}
{
Company company = companyImdg.getSingleObjectByID(paymentInstruction.getAddresseeId());
if (company != null) {
SpecifUtil.fillSegmentsBy35Symbols(company.getShortName(),
if (bnkAcc != null) {
SpecifUtil.fillSegmentsBy35Symbols(bnkAcc.getBankName(),
sDf54::setRclientn1,
sDf54::setRclientn2,
sDf54::setRclientn3,

View file

@ -110,6 +110,13 @@ public class PaymentInstructionOutboundService {
TradingClearingRegistry tcr = tcrImdg.getFirstObjectBySQL("moneyAccountId = '%d' and companyId = %d"
.formatted(accCred.getId(), addressee.getId()));
String purpose = tcr != null ? "Вывод средств по ТКР " + tcr.getCode() + "." : "Вывод средств.";
if (payload.getPaymentPurpose() != null) {
purpose += " " + payload.getPaymentPurpose();
if (!(purpose.endsWith(".") || purpose.endsWith("!") || purpose.endsWith("?") || purpose.endsWith(";"))) {
purpose += ".";
}
}
PaymentInstruction pmt = PaymentInstructionBuilderV2.builder(imdgProvider)
.registry(new Registry())
.sender(addressee.getId())
@ -118,7 +125,7 @@ public class PaymentInstructionOutboundService {
.creditLegAccount(accCred)
.amount(amount)
.sessionId(null)
.purpose(tcr != null ? "Вывод средств по ТКР " + tcr.getCode() : "Вывод средств")
.purpose(purpose)
.build();
BankAccount bnkAcc = bnkAccImdg.getFirstObjectBySQL("accountId = %d".formatted(accDeb.getId()));
if (bnkAcc != null) {