dbf-exporter поправил S_DF08_Converter.java
This commit is contained in:
parent
98028949b5
commit
cfbd12ccc5
3 changed files with 45 additions and 3 deletions
|
|
@ -50,6 +50,12 @@
|
|||
<artifactId>classes</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- TEST -->
|
||||
<dependency>
|
||||
<groupId>org.testng</groupId>
|
||||
<artifactId>testng</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
|||
|
|
@ -5,6 +5,9 @@ import com.linuxense.javadbf.DBFField;
|
|||
import org.springframework.stereotype.Service;
|
||||
import ru.clearing.classes.statics.data.sdf.SDf08;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -14,7 +17,7 @@ public class S_DF08_Converter extends DFConverter<SDf08> {
|
|||
public Object[] toObjectArray(SDf08 entity) {
|
||||
List<Object> values = new LinkedList<>();
|
||||
values.add(convertStrToLong(entity.getNumber()));
|
||||
values.add(convertStrToLong(entity.getDatetime()));
|
||||
values.add(typeMatch(entity.getDatetime()));
|
||||
return values.toArray(Object[]::new);
|
||||
}
|
||||
|
||||
|
|
@ -22,12 +25,24 @@ public class S_DF08_Converter extends DFConverter<SDf08> {
|
|||
public DBFField[] getDBFHeaders() {
|
||||
List<DBFField> dbfFields = new LinkedList<>();
|
||||
dbfFields.add(new DBFField("NUMBER", DBFDataType.NUMERIC, 10));
|
||||
dbfFields.add(new DBFField("DATETIME", DBFDataType.NUMERIC, 13));
|
||||
dbfFields.add(new DBFField("DATETIME", DBFDataType.DATE));
|
||||
return dbfFields.toArray(DBFField[]::new);
|
||||
}
|
||||
|
||||
private Long convertStrToLong(String s) {
|
||||
Long convertStrToLong(String s) {
|
||||
if (s == null) return null;
|
||||
return Long.valueOf(s);
|
||||
}
|
||||
|
||||
private static final DateTimeFormatter DATE_FMT = DateTimeFormatter.ofPattern("dd.MM.yyyy");
|
||||
private static final DateTimeFormatter DATE_TIME_FMT = DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm:ss");
|
||||
|
||||
Object convertStrToDate(String s) {
|
||||
if (s == null) return null;
|
||||
if (s.matches("\\d{2}.\\d{2}.\\d{4}")) {
|
||||
return typeMatch(LocalDate.parse(s, DATE_FMT));
|
||||
} else {
|
||||
return typeMatch(LocalDateTime.parse(s, DATE_TIME_FMT));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
package ru.spcex.clearing.dbf.exporter.services.converters;
|
||||
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
public class S_DF08_ConverterTest {
|
||||
@Test
|
||||
public void testTestConvertStrToLong() {
|
||||
S_DF08_Converter converter = new S_DF08_Converter();
|
||||
Assert.assertNull(converter.convertStrToLong(null));
|
||||
Assert.assertEquals(1L, converter.convertStrToLong("1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTestConvertStrToDate() {
|
||||
S_DF08_Converter converter = new S_DF08_Converter();
|
||||
Assert.assertNull(converter.convertStrToDate(null));
|
||||
Assert.assertEquals("2022-12-29", converter.convertStrToDate("29.12.2022").toString());
|
||||
Assert.assertEquals("2023-01-13T15:32:01", converter.convertStrToDate("13.01.2023 15:32:01").toString());
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue