diff --git a/clearing-parent/clearing-service/src/main/java/ru/spcex/clearing/service/SpecifUtil.java b/clearing-parent/clearing-service/src/main/java/ru/spcex/clearing/service/SpecifUtil.java index f40573d5a..cb12a49e2 100644 --- a/clearing-parent/clearing-service/src/main/java/ru/spcex/clearing/service/SpecifUtil.java +++ b/clearing-parent/clearing-service/src/main/java/ru/spcex/clearing/service/SpecifUtil.java @@ -1,10 +1,11 @@ package ru.spcex.clearing.service; +import java.util.function.Consumer; + public class SpecifUtil { 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; @@ -14,6 +15,14 @@ public class SpecifUtil { return res; } + @SafeVarargs + public static void fillSegmentsBy35Symbols(String str, Consumer... setters) { + String[] parts = split5SegmentsBy35Symbols(str); + for (int i = 0; i < setters.length && i < parts.length; i++) { + setters[i].accept(parts[i]); + } + } + public static int divisionRoundUp(int a, int b) { int ostatok = a % b; return a / b + (ostatok > 0 ? 1 : 0); diff --git a/clearing-parent/clearing-service/src/main/java/ru/spcex/clearing/service/builder/Sdf03Builder.java b/clearing-parent/clearing-service/src/main/java/ru/spcex/clearing/service/builder/Sdf03Builder.java index 00ee57f12..ef31d5c3e 100644 --- a/clearing-parent/clearing-service/src/main/java/ru/spcex/clearing/service/builder/Sdf03Builder.java +++ b/clearing-parent/clearing-service/src/main/java/ru/spcex/clearing/service/builder/Sdf03Builder.java @@ -6,6 +6,7 @@ import ru.clearing.classes.statics.data.sdf.SDf03; import ru.spcex.clearing.service.SpecifUtil; import ru.spcex.platform.enumeration.Sender; import ru.spcex.platform.imdg.api.Imdg; +import ru.spcex.platform.utils.number.BigDecimalUtil; import ru.spcex.platform.utils.time.TimeUtil; import java.time.Instant; @@ -75,7 +76,8 @@ public class Sdf03Builder { sDf03.setPay_date(paymtDt.format(PROPERTY_DATE_FORMATTER_YY)); } sDf03.setPay_val("RUR"); - sDf03.setSum_deb(paymentInstruction.getDebitLeg_amount() != null ? paymentInstruction.getDebitLeg_amount().toString() : null); + String sumDeb = paymentInstruction.getDebitLeg_amount() != null ? paymentInstruction.getDebitLeg_amount().toString() : null; + sDf03.setSum_deb(BigDecimalUtil.limitDecimalPlaces(sumDeb, 2)); //37 sp_code varchar(2) Код назначения платежа String[] splitPaymentPurpose = SpecifUtil.split5SegmentsBy35Symbols(paymentInstruction.getPaymentPurpose()); for (int i = 0; i < splitPaymentPurpose.length; i++) { diff --git a/clearing-parent/clearing-service/src/main/java/ru/spcex/clearing/session/stage/impl/FormingPaymentInstruction.java b/clearing-parent/clearing-service/src/main/java/ru/spcex/clearing/session/stage/impl/FormingPaymentInstruction.java index 836f0fc7b..5023ef200 100644 --- a/clearing-parent/clearing-service/src/main/java/ru/spcex/clearing/session/stage/impl/FormingPaymentInstruction.java +++ b/clearing-parent/clearing-service/src/main/java/ru/spcex/clearing/session/stage/impl/FormingPaymentInstruction.java @@ -18,6 +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.builder.PaymentInstructionBuilder; import ru.spcex.clearing.session.stage.ISessionStage; import ru.spcex.clearing.session.stage.StageResult; @@ -33,6 +34,7 @@ import ru.spcex.platform.imdg.api.predicate.specific.RegistryCodeSqlBuilder; 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; @@ -356,11 +358,12 @@ public class FormingPaymentInstruction implements ISessionStage { senderSbankName = company.getShortName(); } } - sDf03.setSbanknam1(senderSbankName); - sDf03.setSbanknam2(senderSbankName); - sDf03.setSbanknam3(senderSbankName); - sDf03.setSbanknam4(senderSbankName); - sDf03.setSbanknam5(senderSbankName); + SpecifUtil.fillSegmentsBy35Symbols(senderSbankName, + sDf03::setSbanknam1, + sDf03::setSbanknam2, + sDf03::setSbanknam3, + sDf03::setSbanknam4, + sDf03::setSbanknam5); sDf03.setC_acc_cred(paymentInstruction.getDebitLeg_account()); @@ -373,15 +376,17 @@ public class FormingPaymentInstruction implements ISessionStage { addresseeSbankName = company.getShortName(); } } - sDf03.setRbanknam1(addresseeSbankName); - sDf03.setRbanknam2(addresseeSbankName); - sDf03.setRbanknam3(addresseeSbankName); - sDf03.setRbanknam4(addresseeSbankName); - sDf03.setRbanknam5(addresseeSbankName); + 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"); - sDf03.setSum_deb(paymentInstruction.getDebitLeg_amount() != null ? paymentInstruction.getDebitLeg_amount().toString() : ""); + 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()); @@ -395,7 +400,7 @@ public class FormingPaymentInstruction implements ISessionStage { sDf12.setId(idGenerator.nextId()); sDf12.setOutDocument(sDf12.getId().toString()); sDf12.setDirection("DELFREE"); - sDf12.setQuantity(paymentInstruction.getCreditLeg_amount().toString()); + sDf12.setQuantity(BigDecimalUtil.limitDecimalPlaces(paymentInstruction.getCreditLeg_amount().toString(), 2)); sDf12.setSecurityCode(paymentInstruction.getCreditLeg_securityId().toString()); sDf12.setDepoCodeSender(paymentInstruction.getCreditLeg_account()); sDf12.setDepoCodeAdressee(paymentInstruction.getDebitLeg_account()); diff --git a/clearing-parent/clearing-service/src/main/java/ru/spcex/clearing/session/stage/impl/FormingPaymentInstructionDealsFinalMkr.java b/clearing-parent/clearing-service/src/main/java/ru/spcex/clearing/session/stage/impl/FormingPaymentInstructionDealsFinalMkr.java index 3a07e1021..a151693df 100644 --- a/clearing-parent/clearing-service/src/main/java/ru/spcex/clearing/session/stage/impl/FormingPaymentInstructionDealsFinalMkr.java +++ b/clearing-parent/clearing-service/src/main/java/ru/spcex/clearing/session/stage/impl/FormingPaymentInstructionDealsFinalMkr.java @@ -36,6 +36,7 @@ import ru.spcex.platform.utils.enumeration.EnumMessage; 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; @@ -308,7 +309,8 @@ public class FormingPaymentInstructionDealsFinalMkr implements ISessionStage { sDf03.setPay_date(payDateFormatter.format(TimeUtil.toLocalDate(paymentInstruction.getPaymentDate()))); sDf03.setPay_val("RUR"); - sDf03.setSum_deb(paymentInstruction.getDebitLeg_amount() != null ? paymentInstruction.getDebitLeg_amount().toString() : ""); + 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()); @@ -322,7 +324,7 @@ public class FormingPaymentInstructionDealsFinalMkr implements ISessionStage { sDf12.setId(idGenerator.nextId()); sDf12.setOutDocument(sDf12.getId().toString()); sDf12.setDirection("DELFREE"); - sDf12.setQuantity(paymentInstruction.getCreditLeg_amount().toString()); + sDf12.setQuantity(BigDecimalUtil.limitDecimalPlaces(paymentInstruction.getCreditLeg_amount().toString(), 2)); sDf12.setSecurityCode(paymentInstruction.getCreditLeg_securityId().toString()); sDf12.setDepoCodeSender(paymentInstruction.getCreditLeg_account()); sDf12.setDepoCodeAdressee(paymentInstruction.getDebitLeg_account()); diff --git a/clearing-parent/clearing-service/src/main/java/ru/spcex/clearing/session/stage/impl/FormingPaymentInstructionDepositReturn.java b/clearing-parent/clearing-service/src/main/java/ru/spcex/clearing/session/stage/impl/FormingPaymentInstructionDepositReturn.java index f05762570..497efbd73 100644 --- a/clearing-parent/clearing-service/src/main/java/ru/spcex/clearing/session/stage/impl/FormingPaymentInstructionDepositReturn.java +++ b/clearing-parent/clearing-service/src/main/java/ru/spcex/clearing/session/stage/impl/FormingPaymentInstructionDepositReturn.java @@ -17,6 +17,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.PaymentInstructionBuilder; import ru.spcex.clearing.session.stage.ISessionStage; import ru.spcex.clearing.session.stage.StageResult; @@ -30,6 +31,7 @@ import ru.spcex.platform.imdg.api.predicate.ImdgPredicate; import ru.spcex.platform.imdg.api.predicate.ImdgPredicateBuilder; import ru.spcex.platform.imdg.api.predicate.specific.RegistryCodeSqlBuilder; import ru.spcex.platform.utils.enumeration.IEnumKey; +import ru.spcex.platform.utils.number.BigDecimalUtil; import java.math.BigDecimal; import java.time.Instant; @@ -327,11 +329,12 @@ public class FormingPaymentInstructionDepositReturn implements ISessionStage { senderSbankName = company.getShortName(); } } - sDf03.setSbanknam1(senderSbankName); - sDf03.setSbanknam2(senderSbankName); - sDf03.setSbanknam3(senderSbankName); - sDf03.setSbanknam4(senderSbankName); - sDf03.setSbanknam5(senderSbankName); + SpecifUtil.fillSegmentsBy35Symbols(senderSbankName, + sDf03::setSbanknam1, + sDf03::setSbanknam2, + sDf03::setSbanknam3, + sDf03::setSbanknam4, + sDf03::setSbanknam5); sDf03.setC_acc_cred(paymentInstruction.getDebitLeg_account()); @@ -344,15 +347,17 @@ public class FormingPaymentInstructionDepositReturn implements ISessionStage { addresseeSbankName = company.getShortName(); } } - sDf03.setRbanknam1(addresseeSbankName); - sDf03.setRbanknam2(addresseeSbankName); - sDf03.setRbanknam3(addresseeSbankName); - sDf03.setRbanknam4(addresseeSbankName); - sDf03.setRbanknam5(addresseeSbankName); + SpecifUtil.fillSegmentsBy35Symbols(addresseeSbankName, + sDf03::setRbanknam1, + sDf03::setRbanknam2, + sDf03::setRbanknam3, + sDf03::setRbanknam4, + sDf03::setRbanknam5); sDf03.setPay_date(payDateFormatter.format(paymentInstruction.getPaymentDate())); sDf03.setPay_val("RUR"); - sDf03.setSum_deb(paymentInstruction.getDebitLeg_amount() != null ? paymentInstruction.getDebitLeg_amount().toString() : ""); + 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()); @@ -366,7 +371,7 @@ public class FormingPaymentInstructionDepositReturn implements ISessionStage { sDf12.setId(idGenerator.nextId()); sDf12.setOutDocument(sDf12.getId().toString()); sDf12.setDirection("DELFREE"); - sDf12.setQuantity(paymentInstruction.getCreditLeg_amount().toString()); + sDf12.setQuantity(BigDecimalUtil.limitDecimalPlaces(paymentInstruction.getCreditLeg_amount().toString(), 2)); sDf12.setSecurityCode(paymentInstruction.getCreditLeg_securityId().toString()); sDf12.setDepoCodeSender(paymentInstruction.getCreditLeg_account()); sDf12.setDepoCodeAdressee(paymentInstruction.getDebitLeg_account()); diff --git a/clearing-parent/clearing-service/src/main/java/ru/spcex/clearing/session/stage/impl/FormingPaymentInstructionReturnMkr.java b/clearing-parent/clearing-service/src/main/java/ru/spcex/clearing/session/stage/impl/FormingPaymentInstructionReturnMkr.java index 0d7721270..2f1d42e08 100644 --- a/clearing-parent/clearing-service/src/main/java/ru/spcex/clearing/session/stage/impl/FormingPaymentInstructionReturnMkr.java +++ b/clearing-parent/clearing-service/src/main/java/ru/spcex/clearing/session/stage/impl/FormingPaymentInstructionReturnMkr.java @@ -18,6 +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.builder.PaymentInstructionBuilder; import ru.spcex.clearing.session.stage.ISessionStage; import ru.spcex.clearing.session.stage.StageResult; @@ -31,6 +32,7 @@ import ru.spcex.platform.imdg.api.predicate.ImdgPredicate; import ru.spcex.platform.imdg.api.predicate.ImdgPredicateBuilder; import ru.spcex.platform.imdg.api.predicate.specific.RegistryCodeSqlBuilder; import ru.spcex.platform.utils.enumeration.IEnumKey; +import ru.spcex.platform.utils.number.BigDecimalUtil; import ru.spcex.platform.utils.time.TimeUtil; import java.math.BigDecimal; @@ -268,11 +270,13 @@ public class FormingPaymentInstructionReturnMkr implements ISessionStage { senderSbankName = company.getShortName(); } } - sDf03.setSbanknam1(senderSbankName); - sDf03.setSbanknam2(senderSbankName); - sDf03.setSbanknam3(senderSbankName); - sDf03.setSbanknam4(senderSbankName); - sDf03.setSbanknam5(senderSbankName); + SpecifUtil.fillSegmentsBy35Symbols(senderSbankName, + sDf03::setSbanknam1, + sDf03::setSbanknam2, + sDf03::setSbanknam3, + sDf03::setSbanknam4, + sDf03::setSbanknam5 + ); sDf03.setC_acc_cred(paymentInstruction.getDebitLeg_account()); @@ -285,15 +289,18 @@ public class FormingPaymentInstructionReturnMkr implements ISessionStage { addresseeSbankName = company.getShortName(); } } - sDf03.setRbanknam1(addresseeSbankName); - sDf03.setRbanknam2(addresseeSbankName); - sDf03.setRbanknam3(addresseeSbankName); - sDf03.setRbanknam4(addresseeSbankName); - sDf03.setRbanknam5(addresseeSbankName); + 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"); - sDf03.setSum_deb(paymentInstruction.getDebitLeg_amount() != null ? paymentInstruction.getDebitLeg_amount().toString() : ""); + 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()); @@ -307,7 +314,7 @@ public class FormingPaymentInstructionReturnMkr implements ISessionStage { sDf12.setId(idGenerator.nextId()); sDf12.setOutDocument(sDf12.getId().toString()); sDf12.setDirection("DELFREE"); - sDf12.setQuantity(paymentInstruction.getCreditLeg_amount().toString()); + sDf12.setQuantity(BigDecimalUtil.limitDecimalPlaces(paymentInstruction.getCreditLeg_amount().toString(), 2)); sDf12.setSecurityCode(paymentInstruction.getCreditLeg_securityId().toString()); sDf12.setDepoCodeSender(paymentInstruction.getCreditLeg_account()); sDf12.setDepoCodeAdressee(paymentInstruction.getDebitLeg_account()); diff --git a/clearing-parent/clearing-service/src/test/java/ru/spcex/clearing/service/SpecifUtilTest.java b/clearing-parent/clearing-service/src/test/java/ru/spcex/clearing/service/SpecifUtilTest.java index 254e32488..fa2e7f367 100644 --- a/clearing-parent/clearing-service/src/test/java/ru/spcex/clearing/service/SpecifUtilTest.java +++ b/clearing-parent/clearing-service/src/test/java/ru/spcex/clearing/service/SpecifUtilTest.java @@ -3,6 +3,8 @@ package ru.spcex.clearing.service; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import java.util.concurrent.atomic.AtomicReference; + class SpecifUtilTest { @Test public void testDivideRoundUp() { @@ -61,16 +63,153 @@ class SpecifUtilTest { "01234567890123456789012345678912345" + "outside of scope" ); - Assertions.assertEquals(6, splitted.length); - for (String s : splitted) { - Assertions.assertEquals("01234567890123456789012345678912345", s); + Assertions.assertEquals(7, splitted.length); + for (int i = 0; i < splitted.length; i++) { + if (i != 6) { + Assertions.assertEquals("01234567890123456789012345678912345", splitted[i]); + } else { + Assertions.assertEquals("outside of scope", splitted[i]); + } } } - - - // ""; } + @Test + public void testSplitAndFill() { + { + AtomicReference part0 = new AtomicReference<>(); + AtomicReference part1 = new AtomicReference<>(); + + //40 symbols + SpecifUtil.fillSegmentsBy35Symbols("0123456789012345678901234567890123456789", part0::set, part1::set); + Assertions.assertNotNull(part0.get()); + Assertions.assertNotNull(part1.get()); + Assertions.assertEquals("01234567890123456789012345678901234", part0.get()); + Assertions.assertEquals("56789", part1.get()); + } + + { + AtomicReference part0 = new AtomicReference<>(); + AtomicReference part1 = new AtomicReference<>(); + + //35 symbols + SpecifUtil.fillSegmentsBy35Symbols("01234567890123456789012345678901234", part0::set, part1::set); + Assertions.assertNotNull(part0.get()); + Assertions.assertNull(part1.get()); + Assertions.assertEquals("01234567890123456789012345678901234", part0.get()); + + } + + { + AtomicReference part0 = new AtomicReference<>(); + AtomicReference part1 = new AtomicReference<>(); + + //10 symbols + SpecifUtil.fillSegmentsBy35Symbols("0123456789", part0::set, part1::set); + Assertions.assertNotNull(part0.get()); + Assertions.assertNull(part1.get()); + Assertions.assertEquals("0123456789", part0.get()); + } + + { + AtomicReference part0 = new AtomicReference<>(); + AtomicReference part1 = new AtomicReference<>(); + + //0 symbols + SpecifUtil.fillSegmentsBy35Symbols("", part0::set, part1::set); + Assertions.assertNull(part0.get()); + Assertions.assertNull(part1.get()); + } + + { + AtomicReference part0 = new AtomicReference<>(); + AtomicReference part1 = new AtomicReference<>(); + + //80 symbols + SpecifUtil.fillSegmentsBy35Symbols("0123456789012345678901234567890123456789" + + "0123456789012345678901234567890123456789", part0::set, part1::set); + Assertions.assertNotNull(part0.get()); + Assertions.assertNotNull(part1.get()); + Assertions.assertEquals("01234567890123456789012345678901234", part0.get()); + Assertions.assertEquals("56789012345678901234567890123456789", part1.get()); + + } + + { + AtomicReference part0 = new AtomicReference<>(); + AtomicReference part1 = new AtomicReference<>(); + AtomicReference part2 = new AtomicReference<>(); + + //80 symbols + SpecifUtil.fillSegmentsBy35Symbols("0123456789012345678901234567890123456789" + + "0123456789012345678901234567890123456789", part0::set, part1::set, part2::set); + Assertions.assertNotNull(part0.get()); + Assertions.assertNotNull(part1.get()); + Assertions.assertNotNull(part2.get()); + Assertions.assertEquals("01234567890123456789012345678901234", part0.get()); + Assertions.assertEquals("56789012345678901234567890123456789", part1.get()); + Assertions.assertEquals("0123456789", part2.get()); + + } + + { + AtomicReference part0 = new AtomicReference<>(); + AtomicReference part1 = new AtomicReference<>(); + AtomicReference part2 = new AtomicReference<>(); + AtomicReference part3 = new AtomicReference<>(); + AtomicReference part4 = new AtomicReference<>(); + + //maximum symbols + SpecifUtil.fillSegmentsBy35Symbols("01234567890123456789012345678912345" + + "01234567890123456789012345678912345" + + "01234567890123456789012345678912345" + + "01234567890123456789012345678912345" + + "01234567890123456789012345678912345" + + "outside of scope", part0::set, part1::set, part2::set, part3::set, part4::set); + + Assertions.assertNotNull(part0.get()); + Assertions.assertNotNull(part1.get()); + Assertions.assertNotNull(part2.get()); + Assertions.assertNotNull(part3.get()); + Assertions.assertNotNull(part4.get()); + Assertions.assertEquals("01234567890123456789012345678912345", part0.get()); + Assertions.assertEquals("01234567890123456789012345678912345", part1.get()); + Assertions.assertEquals("01234567890123456789012345678912345", part2.get()); + Assertions.assertEquals("01234567890123456789012345678912345", part3.get()); + Assertions.assertEquals("01234567890123456789012345678912345", part4.get()); + } + + { + AtomicReference part0 = new AtomicReference<>(); + AtomicReference part1 = new AtomicReference<>(); + AtomicReference part2 = new AtomicReference<>(); + AtomicReference part3 = new AtomicReference<>(); + AtomicReference part4 = new AtomicReference<>(); + AtomicReference part5 = new AtomicReference<>(); + + //> 35*5 symbols but 6 setters + SpecifUtil.fillSegmentsBy35Symbols("01234567890123456789012345678912345" + + "01234567890123456789012345678912345" + + "01234567890123456789012345678912345" + + "01234567890123456789012345678912345" + + "01234567890123456789012345678912345" + + "outside of scope", part0::set, part1::set, part2::set, part3::set, part4::set, part5::set); + + Assertions.assertNotNull(part0.get()); + Assertions.assertNotNull(part1.get()); + Assertions.assertNotNull(part2.get()); + Assertions.assertNotNull(part3.get()); + Assertions.assertNotNull(part4.get()); + Assertions.assertNotNull(part5.get()); + Assertions.assertEquals("01234567890123456789012345678912345", part0.get()); + Assertions.assertEquals("01234567890123456789012345678912345", part1.get()); + Assertions.assertEquals("01234567890123456789012345678912345", part2.get()); + Assertions.assertEquals("01234567890123456789012345678912345", part3.get()); + Assertions.assertEquals("01234567890123456789012345678912345", part4.get()); + Assertions.assertEquals("outside of scope", part5.get()); + } + } + } \ No newline at end of file diff --git a/platform-parent/platform-utils/src/main/java/ru/spcex/platform/utils/number/BigDecimalUtil.java b/platform-parent/platform-utils/src/main/java/ru/spcex/platform/utils/number/BigDecimalUtil.java index c458709f9..9bc4ac8ba 100644 --- a/platform-parent/platform-utils/src/main/java/ru/spcex/platform/utils/number/BigDecimalUtil.java +++ b/platform-parent/platform-utils/src/main/java/ru/spcex/platform/utils/number/BigDecimalUtil.java @@ -1,5 +1,7 @@ package ru.spcex.platform.utils.number; +import ru.spcex.platform.utils.text.TextUtil; + import java.math.BigDecimal; public class BigDecimalUtil { @@ -18,6 +20,24 @@ public class BigDecimalUtil { } } + /** + * Для кейсов когда есть String поле с десятичной частью, и хотим ограничить число знаков после запятой + */ + public static String limitDecimalPlaces(String number, int decimalPlaces) { + if (number == null) { + return null; + } + if (TextUtil.isEmpty(number)) { + return number; + } + int indexOfDot = number.lastIndexOf('.'); + if (indexOfDot == -1 && (indexOfDot = number.lastIndexOf(',')) == -1) { + return number; + } + int maximumIndex = Math.min(number.length(), indexOfDot + decimalPlaces + 1); + return number.substring(0, maximumIndex); + } + public static BigDecimal safeBD(BigDecimal bd) { return bd == null ? BigDecimal.ZERO : bd; }