dbf-exporter http://jira.mfd.msk:8088/browse/CLS-474 начало
This commit is contained in:
parent
5ccf3ed734
commit
807dffdc92
10 changed files with 74 additions and 1 deletions
|
|
@ -6,8 +6,10 @@ import org.springframework.integration.sftp.session.SftpFileInfo;
|
|||
import ru.spcex.clearing.dbf.exporter.logic.data.ResultContainer;
|
||||
|
||||
import java.io.File;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
|
|
@ -32,6 +34,16 @@ public enum FilenameTemplate {
|
|||
.append(".DBF").toString();
|
||||
}
|
||||
},
|
||||
df_section_dateTime_counter_samteDate {
|
||||
@Override
|
||||
public String getFileName(ResultContainer resultContainer, List<SftpFileInfo> files) {
|
||||
return appendSection(resultContainer)
|
||||
.append(dateTime(resultContainer))
|
||||
.append(counter(resultContainer, files))
|
||||
.append(".DBF").toString();
|
||||
//todo изменить логику для частичного сохранения имени(даты). Будут присылать в месте с generationId имя sourceName
|
||||
}
|
||||
},
|
||||
df_section_dateTime_counter_mamberCode {
|
||||
@Override
|
||||
public String getFileName(ResultContainer resultContainer, List<SftpFileInfo> files) {
|
||||
|
|
@ -107,6 +119,39 @@ public enum FilenameTemplate {
|
|||
return res;
|
||||
}
|
||||
|
||||
|
||||
protected LocalDate dateFromFilesInDir(String prefixOfTable, List<SftpFileInfo> files) {
|
||||
final Logger log = LoggerFactory.getLogger(getClass());
|
||||
|
||||
HashSet<LocalDate> dates = new HashSet<>();
|
||||
for (SftpFileInfo file : files) {
|
||||
if (file.isDirectory()) continue;
|
||||
String name = file.getFilename();
|
||||
String[] splitName = name.split("_");
|
||||
if (splitName.length < 3) {
|
||||
log.info("Filename did not contains 3 or 4+ separator \"_\": " + name);
|
||||
continue;
|
||||
}
|
||||
String prefix = splitName[0];
|
||||
String timestamp = splitName[2];
|
||||
|
||||
try {
|
||||
if (timestamp.startsWith("PRC"))
|
||||
timestamp = timestamp.substring(3);
|
||||
timestamp = timestamp.substring(0, Math.min(6, timestamp.length()));
|
||||
LocalDate dt = LocalDate.parse(timestamp, utilFormatter);
|
||||
dates.add(dt);
|
||||
} catch (Exception e) {
|
||||
log.warn("Can not parse timestamp \"{}\" as {}: {}", timestamp, utilFormatter, e.getMessage());
|
||||
}
|
||||
}
|
||||
if (dates.isEmpty()) return null;
|
||||
if (dates.size() == 1) return dates.iterator().next(); // normal
|
||||
LocalDate maxDate = dates.stream().max(LocalDate::compareTo).orElse(null);
|
||||
log.warn("Parsed too many dates: {}; select max {}", dates, maxDate);
|
||||
return maxDate;
|
||||
}
|
||||
|
||||
private static final DateTimeFormatter tsFormatter = DateTimeFormatter.ofPattern("yyMMddHHmm");
|
||||
private static final DateTimeFormatter utilFormatter = DateTimeFormatter.ofPattern("yyMMdd");
|
||||
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ public class PrepareDBFFile extends Stage implements InitializingBean {
|
|||
private static final Map<Table, FilenameTemplate> nameTemplates = new EnumMap<>(Table.class);
|
||||
|
||||
static {
|
||||
nameTemplates.put(Table.S_DF02, FilenameTemplate.df_section_dateTime_counter);
|
||||
nameTemplates.put(Table.S_DF02, FilenameTemplate.df_section_dateTime_counter_samteDate);
|
||||
nameTemplates.put(Table.S_DF03, FilenameTemplate.df_section_dateTime_counter);
|
||||
nameTemplates.put(Table.S_DF05, FilenameTemplate.df_section_dateTime);
|
||||
nameTemplates.put(Table.S_DF07, FilenameTemplate.df_section_dateTime_counter);
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import com.jcraft.jsch.ChannelSftp.LsEntry;
|
|||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.integration.sftp.session.SftpFileInfo;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
|
@ -25,4 +26,15 @@ class FilenameTemplateTest {
|
|||
// count = FilenameTemplate.df_section_dateTime.countSameFilesInDir("DF-02", files);
|
||||
// assertEquals(0, count);
|
||||
}
|
||||
|
||||
@Test
|
||||
void dateFromFilesInDir() {
|
||||
LsEntry lsEntry = mock(LsEntry.class);
|
||||
doReturn("DF-02_S_PRC2305191321_1.DBF").when(lsEntry).getFilename();
|
||||
SftpFileInfo sftpFileInfo = spy(new SftpFileInfo(lsEntry));
|
||||
doReturn(false).when(sftpFileInfo).isDirectory();
|
||||
List<SftpFileInfo> files = List.of(sftpFileInfo);
|
||||
LocalDate maxDate = FilenameTemplate.df_section_dateTime_counter_samteDate.dateFromFilesInDir("DF-02", files);
|
||||
assertEquals(LocalDate.of(2023,5,19), maxDate);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
To:SPCE
|
||||
From:CSO
|
||||
Type:512
|
||||
Date/Time:20230717/1639
|
||||
:20:SPCEX_20230717Q8712-512
|
||||
:21:NONREF
|
||||
:35B:ISIN MFBEL-BV-08:Ðåñïóáëèêà Áåëàðóñü:îáëèãàöèè
|
||||
:60A:SHS0,
|
||||
:83D:747200000AT0:ÏÀÎ "Ïðîìñâÿçüáàíê"
|
||||
:20C:Ïîðó÷åíèå XXX202304061703 îò 2023-04-06
|
||||
:35A:SHS9900000,
|
||||
:23:8712
|
||||
:66A:RECFREE
|
||||
:87D:747288887ZT0
|
||||
:30:20230406
|
||||
:62A:SHS9900000,
|
||||
Loading…
Add table
Reference in a new issue