납품데이터 등록 시 totalSize 추가
This commit is contained in:
@@ -4,8 +4,11 @@ import com.kamco.cd.training.common.enums.LearnDataRegister;
|
||||
import com.kamco.cd.training.dataset.dto.DatasetDto.AddDeliveriesReq;
|
||||
import com.kamco.cd.training.dataset.dto.DatasetDto.DatasetMngRegDto;
|
||||
import com.kamco.cd.training.postgres.core.DatasetCoreService;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.stream.Stream;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
@@ -76,6 +79,7 @@ public class DatasetAsyncService {
|
||||
datasetMngRegDto.setTitle(title);
|
||||
datasetMngRegDto.setMemo(req.getMemo());
|
||||
datasetMngRegDto.setDatasetPath(req.getFilePath());
|
||||
datasetMngRegDto.setTotalSize(getDirectorySize(req.getFilePath())); // 선택한 폴더 안의 모든 파일 용량 합계
|
||||
|
||||
// 마스터 저장
|
||||
datasetUid = datasetCoreService.insertDatasetMngData(datasetMngRegDto);
|
||||
@@ -126,4 +130,24 @@ public class DatasetAsyncService {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Long getDirectorySize(String filePath) {
|
||||
Path selectedPath = Paths.get(filePath);
|
||||
|
||||
try (Stream<Path> paths = Files.walk(selectedPath)) {
|
||||
return paths
|
||||
.filter(Files::isRegularFile)
|
||||
.mapToLong(
|
||||
path -> {
|
||||
try {
|
||||
return Files.size(path);
|
||||
} catch (IOException e) {
|
||||
return 0L;
|
||||
}
|
||||
})
|
||||
.sum();
|
||||
} catch (IOException e) {
|
||||
return 0L;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user