수신 파일 추출 시 갯수 조건 추가

master
mjkhan21 2 months ago
parent 1a08178bd0
commit 25f442ec3f

@ -9,6 +9,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import cokr.xit.foundation.component.ScheduledBean;
@ -174,7 +175,7 @@ public abstract class FileJobBean extends ScheduledBean {
* @return
*/
protected String config(String key) {
return config().getJobConf(jobName(), key);
return ifEmpty(config().getJobConf(jobName(), key), () -> config().getDefault(key));
}
/** .
@ -184,7 +185,7 @@ public abstract class FileJobBean extends ScheduledBean {
*/
protected List<Path> getFilePaths(String dir, Predicate<Path> filter) {
try (Stream<Path> walk = Files.list(Paths.get(dir))) {
return walk.filter(ifEmpty(filter, path -> true)).toList();
return walk.filter(ifEmpty(filter, path -> true)).collect(Collectors.toList());
} catch (Exception e) {
throw runtimeException(e);
}
@ -224,12 +225,28 @@ public abstract class FileJobBean extends ScheduledBean {
* @return
*/
protected List<Path> getReceivedFilePaths(Predicate<Path> filter) {
return getReceivedFilePaths(filter, 0);
}
/** , .
* @param filter . .
* @param fetchSize
* <ul><li>0 </li>
* <li>1 </li>
* </ul>
* @return
*/
protected List<Path> getReceivedFilePaths(Predicate<Path> filter, int fetchSize) {
String receiveDir = receiveDir(),
workingDir = receiveWorkingDir();
Predicate<Path> test = ifEmpty(filter, Files::isRegularFile);
List<Path> paths = getFilePaths(receiveDir, test);
if (paths.isEmpty()) return Collections.emptyList();
int size = paths.size();
if (size < 1) return Collections.emptyList();
if (fetchSize > 0 && size > fetchSize)
paths.subList(fetchSize, size).clear();
move(paths, workingDir);

Loading…
Cancel
Save