dbf-exporter http://jira.mfd.msk:8088/browse/CLS-529 S_DF54 формат
This commit is contained in:
parent
e2740347ba
commit
2d08c7d589
3 changed files with 47 additions and 3 deletions
|
|
@ -4,6 +4,7 @@ import com.linuxense.javadbf.DBFDataType;
|
||||||
import com.linuxense.javadbf.DBFField;
|
import com.linuxense.javadbf.DBFField;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import ru.clearing.classes.statics.data.sdf.SDf54;
|
import ru.clearing.classes.statics.data.sdf.SDf54;
|
||||||
|
import ru.spcex.platform.utils.number.BigDecimalUtil;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -35,7 +36,7 @@ public class S_DF54_Converter extends DFConverter<SDf54> {
|
||||||
values.add(typeMatch(entity.getOp_order()));
|
values.add(typeMatch(entity.getOp_order()));
|
||||||
values.add(typeMatch(entity.getPay_date()));
|
values.add(typeMatch(entity.getPay_date()));
|
||||||
values.add(typeMatch(entity.getPay_val()));
|
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.getSclientn1()));
|
||||||
values.add(typeMatch(entity.getSclientn2()));
|
values.add(typeMatch(entity.getSclientn2()));
|
||||||
values.add(typeMatch(entity.getSclientn3()));
|
values.add(typeMatch(entity.getSclientn3()));
|
||||||
|
|
@ -60,7 +61,7 @@ public class S_DF54_Converter extends DFConverter<SDf54> {
|
||||||
public DBFField[] getDBFHeaders() {
|
public DBFField[] getDBFHeaders() {
|
||||||
List<DBFField> dbfFields = new LinkedList<>();
|
List<DBFField> dbfFields = new LinkedList<>();
|
||||||
dbfFields.add(new DBFField("SEG_TYPE", DBFDataType.CHARACTER, 1));
|
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("DOCNM_REF", DBFDataType.CHARACTER, 16));
|
||||||
dbfFields.add(new DBFField("DOCNMPREV", DBFDataType.CHARACTER, 16));
|
dbfFields.add(new DBFField("DOCNMPREV", DBFDataType.CHARACTER, 16));
|
||||||
dbfFields.add(new DBFField("SBANKCODE", DBFDataType.CHARACTER, 12));
|
dbfFields.add(new DBFField("SBANKCODE", DBFDataType.CHARACTER, 12));
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package ru.spcex.platform.utils.number;
|
package ru.spcex.platform.utils.number;
|
||||||
|
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
import ru.spcex.platform.utils.text.TextUtil;
|
import ru.spcex.platform.utils.text.TextUtil;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
|
@ -38,6 +39,14 @@ public class BigDecimalUtil {
|
||||||
* Для кейсов когда есть String поле с десятичной частью, и хотим ограничить число знаков после запятой
|
* Для кейсов когда есть String поле с десятичной частью, и хотим ограничить число знаков после запятой
|
||||||
*/
|
*/
|
||||||
public static String limitDecimalPlaces(String number, int decimalPlaces) {
|
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) {
|
if (number == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -46,10 +55,20 @@ public class BigDecimalUtil {
|
||||||
}
|
}
|
||||||
int indexOfDot = number.lastIndexOf('.');
|
int indexOfDot = number.lastIndexOf('.');
|
||||||
if (indexOfDot == -1 && (indexOfDot = number.lastIndexOf(',')) == -1) {
|
if (indexOfDot == -1 && (indexOfDot = number.lastIndexOf(',')) == -1) {
|
||||||
|
if (fillZero && decimalPlaces > 0) {
|
||||||
|
number += ".";
|
||||||
|
for (int i = 0; i < decimalPlaces; i++)
|
||||||
|
number += "0";
|
||||||
|
}
|
||||||
return number;
|
return number;
|
||||||
}
|
}
|
||||||
int maximumIndex = Math.min(number.length(), indexOfDot + decimalPlaces + 1);
|
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) {
|
public static BigDecimal safeBD(BigDecimal bd) {
|
||||||
|
|
|
||||||
|
|
@ -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));
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue