파일목록 조회 Depth 추가

This commit is contained in:
Harry M. You
2025-12-04 11:36:28 +09:00
parent 345794ce69
commit bce49b7a0b
3 changed files with 29 additions and 24 deletions

View File

@@ -5,6 +5,7 @@ import com.kamco.cd.kamcoback.code.service.CommonCodeService;
import com.kamco.cd.kamcoback.config.api.ApiResponseDto;
import com.kamco.cd.kamcoback.mapsheet.dto.FileDto.FilesDto;
import com.kamco.cd.kamcoback.mapsheet.dto.FileDto.FoldersDto;
import com.kamco.cd.kamcoback.mapsheet.dto.FileDto.SrchFilesDepthDto;
import com.kamco.cd.kamcoback.mapsheet.dto.FileDto.SrchFilesDto;
import com.kamco.cd.kamcoback.mapsheet.dto.FileDto.SrchFoldersDto;
import com.kamco.cd.kamcoback.mapsheet.dto.MapSheetMngDto;
@@ -48,7 +49,8 @@ public class MapSheetMngApiController {
return ApiResponseDto.createOK(mapSheetMngService.getFolderAll(srchDto));
}
@Operation(summary = "파일목록 조회", description = "파일목록 조회")
@Operation(summary = "지정폴더내 파일목록 조회", description = "지정폴더내 파일목록 조회")
@ApiResponses(
value = {
@ApiResponse(
@@ -67,7 +69,7 @@ public class MapSheetMngApiController {
return ApiResponseDto.createOK(mapSheetMngService.getFilesAll(srchDto));
}
@Operation(summary = "파일목록 조회", description = "파일목록 조회")
@Operation(summary = "지정폴더(하위폴더포함) 파일목록 조회", description = "지정폴더(하위폴더포함) 파일목록 조회")
@ApiResponses(
value = {
@ApiResponse(
@@ -81,7 +83,7 @@ public class MapSheetMngApiController {
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
})
@PostMapping("/file-all-list")
public ApiResponseDto<FilesDto> getAllFiles(@RequestBody SrchFilesDto srchDto) {
public ApiResponseDto<FilesDto> getAllFiles(@RequestBody SrchFilesDepthDto srchDto) {
return ApiResponseDto.createOK(mapSheetMngService.getFilesDepthAll(srchDto));
}

View File

@@ -1,5 +1,6 @@
package com.kamco.cd.kamcoback.mapsheet.dto;
import com.fasterxml.jackson.annotation.JsonView;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import java.util.List;
@@ -23,7 +24,7 @@ public class FileDto {
@NoArgsConstructor
@AllArgsConstructor
public static class SrchFilesDto {
@Schema(description = "디렉토리경로", example = "/data")
@Schema(description = "디렉토리경로", example = "D:\\kamco\\2022\\캠코_2021_2022_34602060_D1")
@NotNull
private String dirPath;
@@ -42,6 +43,17 @@ public class FileDto {
@Schema(description = "파일종료위치", example = "100")
@NotNull
private Integer endPos;
}
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public static class SrchFilesDepthDto extends SrchFilesDto {
@Schema(description = "최대폴더Depth", example = "5")
@NotNull
private Integer maxDepth;
}
@Schema(name = "FolderDto", description = "폴더 정보")

View File

@@ -7,6 +7,7 @@ import com.kamco.cd.kamcoback.mapsheet.dto.FileDto;
import com.kamco.cd.kamcoback.mapsheet.dto.FileDto.FilesDto;
import com.kamco.cd.kamcoback.mapsheet.dto.FileDto.FolderDto;
import com.kamco.cd.kamcoback.mapsheet.dto.FileDto.FoldersDto;
import com.kamco.cd.kamcoback.mapsheet.dto.FileDto.SrchFilesDepthDto;
import com.kamco.cd.kamcoback.mapsheet.dto.FileDto.SrchFilesDto;
import com.kamco.cd.kamcoback.mapsheet.dto.FileDto.SrchFoldersDto;
import com.kamco.cd.kamcoback.mapsheet.dto.MapSheetMngDto;
@@ -181,19 +182,22 @@ public class MapSheetMngService {
}
}
FilesDto filesDto = new FilesDto(dirPath, fileTotCnt, fileTotSize, files);
return filesDto;
return new FilesDto(dirPath, fileTotCnt, fileTotSize, files);
}
public FilesDto getFilesDepthAll(SrchFilesDto srchDto) {
public FilesDto getFilesDepthAll(SrchFilesDepthDto srchDto) {
int maxDepth = 20;
Path startPath = Paths.get(srchDto.getDirPath());
int maxDepth = srchDto.getMaxDepth();
String dirPath = srchDto.getDirPath();
String extension = srchDto.getExtension();
String sortType = srchDto.getSortType();
int startPos = srchDto.getStartPos();
int endPos = srchDto.getEndPos();
int limit = endPos - startPos + 1;
Set<String> targetExtensions = createExtensionSet(extension);
List<FileDto.Basic> fileDtoList = new ArrayList<>();
@@ -202,6 +206,7 @@ public class MapSheetMngService {
int fileTotCnt = 0;
long fileTotSize = 0;
try (Stream<Path> stream = Files.walk(startPath, maxDepth)) {
fileDtoList =
@@ -214,6 +219,8 @@ public class MapSheetMngService {
|| extension.equals("*")
|| targetExtensions.contains(extractExtension(p)))
.sorted(getFileComparator(sortType))
.skip(startPos)
.limit(limit)
.map(
path -> {
int depth = path.getNameCount();
@@ -236,23 +243,7 @@ public class MapSheetMngService {
fileTotCnt = fileDtoList.size();
fileTotSize = fileDtoList.stream().mapToLong(FileDto.Basic::getFileSize).sum();
/*
if( sort.equals("name")) {
fileDtoList.sort(
Comparator.comparing(
FileDto.Basic::getFileNm, String.CASE_INSENSITIVE_ORDER
)
.reversed());
}
else if( sort.equals("date")) {
fileDtoList.sort(
Comparator.comparing(
FileDto.Basic::getLastModified
)
.reversed());
}
*/
} catch (IOException e) {
System.err.println("파일 I/O 오류 발생: " + e.getMessage());