создание PaymentInstruction при обработке сделок для итоговой сессии МКР SDF03 Sbanknam

This commit is contained in:
ialbert 2023-06-08 16:33:26 +03:00
parent 5d4005a087
commit fb77fb7603
4 changed files with 33 additions and 19 deletions

View file

@ -1,15 +1,15 @@
package ru.spcex.clearing.service;
public class SpecifUtil {
public static String[] splitPaymentPurpose(String paymentPurpose) {
if (paymentPurpose == null || paymentPurpose.length() < 1) return new String[0];
int specifSize = divisionRoundUp(paymentPurpose.length(), 35);
specifSize = Math.min(specifSize, 6);
String[] res = new String[specifSize];
public static String[] split5SegmentsBy35Symbols(String str) {
if (str == null || str.length() < 1) return new String[0];
int size = divisionRoundUp(str.length(), 35);
size = Math.min(size, 6);
String[] res = new String[size];
for (int i = 0; i < res.length; i++) {
int startIndex = i * 35;
int endIndex = Math.min(35 * (i + 1), paymentPurpose.length());
res[i] = paymentPurpose.substring(startIndex, endIndex);
int endIndex = Math.min(35 * (i + 1), str.length());
res[i] = str.substring(startIndex, endIndex);
}
return res;
}

View file

@ -77,7 +77,7 @@ public class Sdf03Builder {
sDf03.setPay_val("RUR");
sDf03.setSum_deb(paymentInstruction.getDebitLeg_amount() != null ? paymentInstruction.getDebitLeg_amount().toString() : null);
//37 sp_code varchar(2) Код назначения платежа
String[] splitPaymentPurpose = SpecifUtil.splitPaymentPurpose(paymentInstruction.getPaymentPurpose());
String[] splitPaymentPurpose = SpecifUtil.split5SegmentsBy35Symbols(paymentInstruction.getPaymentPurpose());
for (int i = 0; i < splitPaymentPurpose.length; i++) {
String specif = splitPaymentPurpose[i];
if (i == 0) {

View file

@ -18,6 +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.builder.PaymentInstructionBuilderFinalMkrDeals;
import ru.spcex.clearing.session.stage.ISessionStage;
import ru.spcex.clearing.session.stage.StageResult;
@ -216,11 +217,24 @@ public class FormingPaymentInstructionDealsFinalMkr implements ISessionStage {
senderSbankName = company.getShortName();
}
}
sDf03.setSbanknam1(senderSbankName);
sDf03.setSbanknam2(senderSbankName);
sDf03.setSbanknam3(senderSbankName);
sDf03.setSbanknam4(senderSbankName);
sDf03.setSbanknam5(senderSbankName);
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());

View file

@ -15,7 +15,7 @@ class SpecifUtilTest {
public void testSplit() {
{
//40 symbols
String[] splitted = SpecifUtil.splitPaymentPurpose("0123456789012345678901234567890123456789");
String[] splitted = SpecifUtil.split5SegmentsBy35Symbols("0123456789012345678901234567890123456789");
Assertions.assertEquals(2, splitted.length);
Assertions.assertEquals("01234567890123456789012345678901234", splitted[0]);
Assertions.assertEquals("56789", splitted[1]);
@ -23,27 +23,27 @@ class SpecifUtilTest {
{
//40 symbols
String[] splitted = SpecifUtil.splitPaymentPurpose("01234567890123456789012345678901234");
String[] splitted = SpecifUtil.split5SegmentsBy35Symbols("01234567890123456789012345678901234");
Assertions.assertEquals(1, splitted.length);
Assertions.assertEquals("01234567890123456789012345678901234", splitted[0]);
}
{
//10 symbols
String[] splitted = SpecifUtil.splitPaymentPurpose("0123456789");
String[] splitted = SpecifUtil.split5SegmentsBy35Symbols("0123456789");
Assertions.assertEquals(1, splitted.length);
Assertions.assertEquals("0123456789", splitted[0]);
}
{
//0 symbols
String[] splitted = SpecifUtil.splitPaymentPurpose("");
String[] splitted = SpecifUtil.split5SegmentsBy35Symbols("");
Assertions.assertEquals(0, splitted.length);
}
{
//80 symbols
String[] splitted = SpecifUtil.splitPaymentPurpose("0123456789012345678901234567890123456789" +
String[] splitted = SpecifUtil.split5SegmentsBy35Symbols("0123456789012345678901234567890123456789" +
"0123456789012345678901234567890123456789");
Assertions.assertEquals(3, splitted.length);
Assertions.assertEquals("01234567890123456789012345678901234", splitted[0]);
@ -53,7 +53,7 @@ class SpecifUtilTest {
{
//maximum symbols
String[] splitted = SpecifUtil.splitPaymentPurpose("01234567890123456789012345678912345" +
String[] splitted = SpecifUtil.split5SegmentsBy35Symbols("01234567890123456789012345678912345" +
"01234567890123456789012345678912345" +
"01234567890123456789012345678912345" +
"01234567890123456789012345678912345" +