http://jira.mfd.msk:8088/browse/CLS-45 --- Изменения касаются наименования выгружаемых файлов
This commit is contained in:
parent
102f6f7ce6
commit
873a437a82
1 changed files with 58 additions and 6 deletions
|
|
@ -14,6 +14,7 @@ import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -21,7 +22,10 @@ import java.util.Objects;
|
||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
public class PrepareDBFFile extends Stage implements InitializingBean {
|
public class PrepareDBFFile extends Stage implements InitializingBean {
|
||||||
private static DateTimeFormatter tsFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm-ss");
|
private static final String SECTION = "U";
|
||||||
|
private static final String CODE_OF_MEMBER = null;
|
||||||
|
private static DateTimeFormatter tsFormatter = DateTimeFormatter.ofPattern("yyMMddHHmm");
|
||||||
|
private static DateTimeFormatter utilFormatter = DateTimeFormatter.ofPattern("yyMMdd");
|
||||||
private final AProperties properties;
|
private final AProperties properties;
|
||||||
private String outDir;
|
private String outDir;
|
||||||
|
|
||||||
|
|
@ -34,11 +38,7 @@ public class PrepareDBFFile extends Stage implements InitializingBean {
|
||||||
Objects.requireNonNull(resultContainer.getTableForExport());
|
Objects.requireNonNull(resultContainer.getTableForExport());
|
||||||
|
|
||||||
Table table = resultContainer.getTableForExport();
|
Table table = resultContainer.getTableForExport();
|
||||||
File dbfFile = new File(String.format("%s%s%s_%s.dbf",
|
File dbfFile = new File(prepareFilename(table, SECTION, CODE_OF_MEMBER, outDir));
|
||||||
outDir,
|
|
||||||
File.separator,
|
|
||||||
table.getFilePrefix(),
|
|
||||||
tsFormatter.format(LocalDateTime.now())));
|
|
||||||
try {
|
try {
|
||||||
Path dbfFilePath = dbfFile.toPath();
|
Path dbfFilePath = dbfFile.toPath();
|
||||||
Files.deleteIfExists(dbfFilePath);
|
Files.deleteIfExists(dbfFilePath);
|
||||||
|
|
@ -61,4 +61,56 @@ public class PrepareDBFFile extends Stage implements InitializingBean {
|
||||||
if (!outDirFile.exists()) Files.createDirectories(outDirFile.toPath());
|
if (!outDirFile.exists()) Files.createDirectories(outDirFile.toPath());
|
||||||
this.outDir = outDirPath;
|
this.outDir = outDirPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String prepareFilename(Table table, String section, String codeOfMember, String outDir) {
|
||||||
|
StringBuilder result = new StringBuilder();
|
||||||
|
String prefixOfTable = table.getFilePrefix();
|
||||||
|
String time = "PRC" + tsFormatter.format(LocalDateTime.now());
|
||||||
|
|
||||||
|
result.append(outDir);
|
||||||
|
result.append(File.separator);
|
||||||
|
result.append(prefixOfTable.toUpperCase(Locale.ROOT));
|
||||||
|
result.append('_');
|
||||||
|
result.append(section);
|
||||||
|
result.append('_');
|
||||||
|
result.append(time);
|
||||||
|
result.append('_');
|
||||||
|
|
||||||
|
if (!prefixOfTable.equalsIgnoreCase("DF-05")) {
|
||||||
|
result.append(countSameFilesInDir(prefixOfTable, outDir) + 1);
|
||||||
|
result.append('_');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (codeOfMember != null) {
|
||||||
|
result.append(codeOfMember);
|
||||||
|
}
|
||||||
|
result.append(".DBF");
|
||||||
|
return result.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Integer countSameFilesInDir(String prefixOfTable, String outDir) {
|
||||||
|
int res = 1;
|
||||||
|
File directory = new File(outDir);
|
||||||
|
if (directory.exists()) {
|
||||||
|
for (File file : Objects.requireNonNull(directory.listFiles())) {
|
||||||
|
String name = file.getName();
|
||||||
|
String[] splitName = name.split("_");
|
||||||
|
String prefix = splitName[0];
|
||||||
|
String timestamp = splitName[2];
|
||||||
|
String timestampNow = utilFormatter.format(LocalDateTime.now());
|
||||||
|
|
||||||
|
if (prefix.equalsIgnoreCase(prefixOfTable) && timestamp.contains(timestampNow)) {
|
||||||
|
String counter = splitName[3];
|
||||||
|
//prepare for substring for counter
|
||||||
|
int positionOfDot = counter.indexOf('.');
|
||||||
|
if (positionOfDot != -1) {
|
||||||
|
counter = counter.substring(0, positionOfDot);
|
||||||
|
}
|
||||||
|
res = Integer.max(res, Integer.parseInt(counter));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue