dbf-importer swt-importer Забирать и обрабатывать файлы в порядке времени изменения на sftp (2))

This commit is contained in:
AKurakin 2023-11-16 16:29:45 +03:00
parent 939ea451a1
commit 4a0df9bb48
2 changed files with 21 additions and 2 deletions

View file

@ -10,6 +10,7 @@ import org.springframework.stereotype.Service;
import ru.spcex.clearing.dbf.importer.logic.Processor;
import ru.spcex.clearing.dbf.importer.logic.data.ResultContainer;
import ru.spcex.clearing.dbf.importer.logic.data.enums.ETable;
import ru.spcex.platform.utils.collection.Pair;
import java.io.File;
import java.nio.file.Path;
@ -59,13 +60,22 @@ public class DBFImporterService {
} else {
log.trace("no files were found");
}
// Сортировка по возрастанию времени изменения - обрабатывать только в таком порядке
List<Pair<File, ETable>> orderByTimeFiles = new ArrayList<>();
for (Map.Entry<ETable, List<File>> newFilesEntry : newFiles.entrySet()) {
ETable currTable = newFilesEntry.getKey();
List<File> fileList = newFilesEntry.getValue();
for (File dbfFile : fileList) {
processor.process(ResultContainer.createNewTask(currTable, dbfFile));
orderByTimeFiles.add(new Pair<>(dbfFile, currTable));
}
}
orderByTimeFiles.sort(Comparator.comparingLong(iF -> iF.getFirst().lastModified()));
for (Pair<File, ETable> newFilesEntry : orderByTimeFiles) {
ETable currTable = newFilesEntry.getSecond();
File dbfFile = newFilesEntry.getFirst();
processor.process(ResultContainer.createNewTask(currTable, dbfFile));
}
} finally {
if (newFiles != null && newFiles.size() > 0) {
cleanFiles(newFiles);

View file

@ -10,6 +10,7 @@ import org.springframework.stereotype.Service;
import ru.spcex.clearing.swt.importer.logic.Processor;
import ru.spcex.clearing.swt.importer.logic.data.ResultContainer;
import ru.spcex.clearing.swt.importer.logic.data.enums.ETable;
import ru.spcex.platform.utils.collection.Pair;
import java.io.File;
import java.nio.file.Path;
@ -81,13 +82,21 @@ public class SWTImporterService {
} else {
log.trace("no files were found");
}
// Сортировка по возрастанию времени изменения - обрабатывать только в таком порядке
List<Pair<File, ETable>> orderByTimeFiles = new ArrayList<>();
for (Map.Entry<ETable, List<File>> newFilesEntry : newFiles.entrySet()) {
ETable currTable = newFilesEntry.getKey();
List<File> fileList = newFilesEntry.getValue();
for (File swtFile : fileList) {
processor.process(ResultContainer.createNewTask(currTable, swtFile));
orderByTimeFiles.add(new Pair<>(swtFile, currTable));
}
}
orderByTimeFiles.sort(Comparator.comparingLong(iF -> iF.getFirst().lastModified()));
for (Pair<File, ETable> newFilesEntry : orderByTimeFiles) {
ETable currTable = newFilesEntry.getSecond();
File swtFile = newFilesEntry.getFirst();
processor.process(ResultContainer.createNewTask(currTable, swtFile));
}
} finally {
if (newFiles != null && newFiles.size() > 0) {
cleanFiles(newFiles);