dbf-importer swt-importer Забирать и обрабатывать файлы в порядке времени изменения на sftp (2))
This commit is contained in:
parent
939ea451a1
commit
4a0df9bb48
2 changed files with 21 additions and 2 deletions
|
|
@ -10,6 +10,7 @@ import org.springframework.stereotype.Service;
|
||||||
import ru.spcex.clearing.dbf.importer.logic.Processor;
|
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.ResultContainer;
|
||||||
import ru.spcex.clearing.dbf.importer.logic.data.enums.ETable;
|
import ru.spcex.clearing.dbf.importer.logic.data.enums.ETable;
|
||||||
|
import ru.spcex.platform.utils.collection.Pair;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
|
@ -59,13 +60,22 @@ public class DBFImporterService {
|
||||||
} else {
|
} else {
|
||||||
log.trace("no files were found");
|
log.trace("no files were found");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Сортировка по возрастанию времени изменения - обрабатывать только в таком порядке
|
||||||
|
List<Pair<File, ETable>> orderByTimeFiles = new ArrayList<>();
|
||||||
for (Map.Entry<ETable, List<File>> newFilesEntry : newFiles.entrySet()) {
|
for (Map.Entry<ETable, List<File>> newFilesEntry : newFiles.entrySet()) {
|
||||||
ETable currTable = newFilesEntry.getKey();
|
ETable currTable = newFilesEntry.getKey();
|
||||||
List<File> fileList = newFilesEntry.getValue();
|
List<File> fileList = newFilesEntry.getValue();
|
||||||
for (File dbfFile : fileList) {
|
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 {
|
} finally {
|
||||||
if (newFiles != null && newFiles.size() > 0) {
|
if (newFiles != null && newFiles.size() > 0) {
|
||||||
cleanFiles(newFiles);
|
cleanFiles(newFiles);
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import org.springframework.stereotype.Service;
|
||||||
import ru.spcex.clearing.swt.importer.logic.Processor;
|
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.ResultContainer;
|
||||||
import ru.spcex.clearing.swt.importer.logic.data.enums.ETable;
|
import ru.spcex.clearing.swt.importer.logic.data.enums.ETable;
|
||||||
|
import ru.spcex.platform.utils.collection.Pair;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
|
@ -81,13 +82,21 @@ public class SWTImporterService {
|
||||||
} else {
|
} else {
|
||||||
log.trace("no files were found");
|
log.trace("no files were found");
|
||||||
}
|
}
|
||||||
|
// Сортировка по возрастанию времени изменения - обрабатывать только в таком порядке
|
||||||
|
List<Pair<File, ETable>> orderByTimeFiles = new ArrayList<>();
|
||||||
for (Map.Entry<ETable, List<File>> newFilesEntry : newFiles.entrySet()) {
|
for (Map.Entry<ETable, List<File>> newFilesEntry : newFiles.entrySet()) {
|
||||||
ETable currTable = newFilesEntry.getKey();
|
ETable currTable = newFilesEntry.getKey();
|
||||||
List<File> fileList = newFilesEntry.getValue();
|
List<File> fileList = newFilesEntry.getValue();
|
||||||
for (File swtFile : fileList) {
|
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 {
|
} finally {
|
||||||
if (newFiles != null && newFiles.size() > 0) {
|
if (newFiles != null && newFiles.size() > 0) {
|
||||||
cleanFiles(newFiles);
|
cleanFiles(newFiles);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue