diff --git a/clearing-parent/dbf-exporter/src/main/java/ru/spcex/clearing/dbf/exporter/services/converters/S_DF54_Converter.java b/clearing-parent/dbf-exporter/src/main/java/ru/spcex/clearing/dbf/exporter/services/converters/S_DF54_Converter.java index 0b9aff09f..796b57368 100644 --- a/clearing-parent/dbf-exporter/src/main/java/ru/spcex/clearing/dbf/exporter/services/converters/S_DF54_Converter.java +++ b/clearing-parent/dbf-exporter/src/main/java/ru/spcex/clearing/dbf/exporter/services/converters/S_DF54_Converter.java @@ -4,6 +4,7 @@ import com.linuxense.javadbf.DBFDataType; import com.linuxense.javadbf.DBFField; import org.springframework.stereotype.Service; import ru.clearing.classes.statics.data.sdf.SDf54; +import ru.spcex.platform.utils.number.BigDecimalUtil; import java.util.LinkedList; import java.util.List; @@ -35,7 +36,7 @@ public class S_DF54_Converter extends DFConverter { values.add(typeMatch(entity.getOp_order())); values.add(typeMatch(entity.getPay_date())); values.add(typeMatch(entity.getPay_val())); - values.add(typeMatch(entity.getSum_deb())); + values.add(typeMatch(BigDecimalUtil.limitDecimalPlaces(entity.getSum_deb(), 2, true))); values.add(typeMatch(entity.getSclientn1())); values.add(typeMatch(entity.getSclientn2())); values.add(typeMatch(entity.getSclientn3())); @@ -60,7 +61,7 @@ public class S_DF54_Converter extends DFConverter { public DBFField[] getDBFHeaders() { List dbfFields = new LinkedList<>(); dbfFields.add(new DBFField("SEG_TYPE", DBFDataType.CHARACTER, 1)); - dbfFields.add(new DBFField("DOC_TYPE", DBFDataType.CHARACTER, 13)); + dbfFields.add(new DBFField("DOC_TYPE", DBFDataType.CHARACTER, 4)); dbfFields.add(new DBFField("DOCNM_REF", DBFDataType.CHARACTER, 16)); dbfFields.add(new DBFField("DOCNMPREV", DBFDataType.CHARACTER, 16)); dbfFields.add(new DBFField("SBANKCODE", DBFDataType.CHARACTER, 12)); 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 5f3400f05..b238d0f1e 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,6 @@ package ru.spcex.platform.utils.number; +import org.springframework.util.StringUtils; import ru.spcex.platform.utils.text.TextUtil; import java.math.BigDecimal; @@ -38,6 +39,14 @@ public class BigDecimalUtil { * Для кейсов когда есть String поле с десятичной частью, и хотим ограничить число знаков после запятой */ public static String limitDecimalPlaces(String number, int decimalPlaces) { + return limitDecimalPlaces(number, decimalPlaces, false); + } + + /** + * Для кейсов когда есть String поле с десятичной частью, и хотим ограничить число знаков после запятой + * @param fillZero - дополнить 0 если не хватает знаков дробной части + */ + public static String limitDecimalPlaces(String number, int decimalPlaces, boolean fillZero) { if (number == null) { return null; } @@ -46,10 +55,20 @@ public class BigDecimalUtil { } int indexOfDot = number.lastIndexOf('.'); if (indexOfDot == -1 && (indexOfDot = number.lastIndexOf(',')) == -1) { + if (fillZero && decimalPlaces > 0) { + number += "."; + for (int i = 0; i < decimalPlaces; i++) + number += "0"; + } return number; } int maximumIndex = Math.min(number.length(), indexOfDot + decimalPlaces + 1); - return number.substring(0, maximumIndex); + number = number.substring(0, maximumIndex); + if (fillZero && decimalPlaces > 0) { + while (number.length() - indexOfDot <= decimalPlaces) + number += "0"; + } + return number; } public static BigDecimal safeBD(BigDecimal bd) { diff --git a/platform-parent/platform-utils/src/test/java/ru/spcex/platform/utils/number/BigDecimalUtilTest.java b/platform-parent/platform-utils/src/test/java/ru/spcex/platform/utils/number/BigDecimalUtilTest.java new file mode 100644 index 000000000..be5b5f9d7 --- /dev/null +++ b/platform-parent/platform-utils/src/test/java/ru/spcex/platform/utils/number/BigDecimalUtilTest.java @@ -0,0 +1,24 @@ +package ru.spcex.platform.utils.number; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class BigDecimalUtilTest { + + @Test + void limitDecimalPlaces() { + Assertions.assertEquals("123.45", BigDecimalUtil.limitDecimalPlaces("123.45", 2)); + Assertions.assertEquals("123.4", BigDecimalUtil.limitDecimalPlaces("123.45", 1)); + Assertions.assertEquals("123.", BigDecimalUtil.limitDecimalPlaces("123.", 1)); + Assertions.assertEquals("123", BigDecimalUtil.limitDecimalPlaces("123", 1)); + Assertions.assertEquals("123.", BigDecimalUtil.limitDecimalPlaces("123.45", 0)); + Assertions.assertEquals("123", BigDecimalUtil.limitDecimalPlaces("123", 0)); + + Assertions.assertEquals("123.41", BigDecimalUtil.limitDecimalPlaces("123.4123", 2, true)); + Assertions.assertEquals("123.40", BigDecimalUtil.limitDecimalPlaces("123.4", 2, true)); + Assertions.assertEquals("123.00", BigDecimalUtil.limitDecimalPlaces("123.", 2, true)); + Assertions.assertEquals("123.00", BigDecimalUtil.limitDecimalPlaces("123", 2, true)); + } +} \ No newline at end of file