refactor(device): 优化文件列表获取逻辑

- 移除了不必要的循环遍历,简化了代码结构
- 仅根据起始日期获取一次文件列表,提高了效率- 清除了无用的日历操作,减少了代码复杂性
This commit is contained in:
2025-09-09 13:32:58 +08:00
parent 9e9e245801
commit ac91921c28

View File

@@ -69,23 +69,15 @@ public class AliOssStorageOperator extends ADeviceStorageOperator {
if (startDate == null || endDate == null) {
return null;
}
List<FileObject> fileList = new ArrayList<>();
if (startDate.after(endDate)) {
return fileList;
}
Calendar calendar = Calendar.getInstance();
calendar.setTime(startDate);
calendar.set(Calendar.SECOND, 0);
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
while (calendar.getTime().before(endDate)) {
String prefix = dateFormat.format(calendar.getTime());
List<FileObject> fileListByPrefix = getOssFileListByPrefix(prefix);
if (fileListByPrefix == null) {
List<FileObject> fileList = getOssFileListByPrefix(prefix);
if (fileList == null) {
return null;
}
fileList.addAll(fileListByPrefix);
calendar.add(Calendar.DATE, 1);
}
calendar.clear();
return fileList.stream()
.sorted(Comparator.comparing(FileObject::getCreateTime))