파일목록 조회 Depth 추가
This commit is contained in:
@@ -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.config.api.ApiResponseDto;
|
||||||
import com.kamco.cd.kamcoback.mapsheet.dto.FileDto.FilesDto;
|
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.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.SrchFilesDto;
|
||||||
import com.kamco.cd.kamcoback.mapsheet.dto.FileDto.SrchFoldersDto;
|
import com.kamco.cd.kamcoback.mapsheet.dto.FileDto.SrchFoldersDto;
|
||||||
import com.kamco.cd.kamcoback.mapsheet.dto.MapSheetMngDto;
|
import com.kamco.cd.kamcoback.mapsheet.dto.MapSheetMngDto;
|
||||||
@@ -48,7 +49,8 @@ public class MapSheetMngApiController {
|
|||||||
return ApiResponseDto.createOK(mapSheetMngService.getFolderAll(srchDto));
|
return ApiResponseDto.createOK(mapSheetMngService.getFolderAll(srchDto));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "파일목록 조회", description = "파일목록 조회")
|
|
||||||
|
@Operation(summary = "지정폴더내 파일목록 조회", description = "지정폴더내 파일목록 조회")
|
||||||
@ApiResponses(
|
@ApiResponses(
|
||||||
value = {
|
value = {
|
||||||
@ApiResponse(
|
@ApiResponse(
|
||||||
@@ -67,7 +69,7 @@ public class MapSheetMngApiController {
|
|||||||
return ApiResponseDto.createOK(mapSheetMngService.getFilesAll(srchDto));
|
return ApiResponseDto.createOK(mapSheetMngService.getFilesAll(srchDto));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "파일목록 조회", description = "파일목록 조회")
|
@Operation(summary = "지정폴더(하위폴더포함) 파일목록 조회", description = "지정폴더(하위폴더포함) 파일목록 조회")
|
||||||
@ApiResponses(
|
@ApiResponses(
|
||||||
value = {
|
value = {
|
||||||
@ApiResponse(
|
@ApiResponse(
|
||||||
@@ -81,7 +83,7 @@ public class MapSheetMngApiController {
|
|||||||
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
|
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
|
||||||
})
|
})
|
||||||
@PostMapping("/file-all-list")
|
@PostMapping("/file-all-list")
|
||||||
public ApiResponseDto<FilesDto> getAllFiles(@RequestBody SrchFilesDto srchDto) {
|
public ApiResponseDto<FilesDto> getAllFiles(@RequestBody SrchFilesDepthDto srchDto) {
|
||||||
|
|
||||||
return ApiResponseDto.createOK(mapSheetMngService.getFilesDepthAll(srchDto));
|
return ApiResponseDto.createOK(mapSheetMngService.getFilesDepthAll(srchDto));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.kamco.cd.kamcoback.mapsheet.dto;
|
package com.kamco.cd.kamcoback.mapsheet.dto;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonView;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -23,7 +24,7 @@ public class FileDto {
|
|||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public static class SrchFilesDto {
|
public static class SrchFilesDto {
|
||||||
@Schema(description = "디렉토리경로", example = "/data")
|
@Schema(description = "디렉토리경로", example = "D:\\kamco\\2022\\캠코_2021_2022_34602060_D1")
|
||||||
@NotNull
|
@NotNull
|
||||||
private String dirPath;
|
private String dirPath;
|
||||||
|
|
||||||
@@ -42,6 +43,17 @@ public class FileDto {
|
|||||||
@Schema(description = "파일종료위치", example = "100")
|
@Schema(description = "파일종료위치", example = "100")
|
||||||
@NotNull
|
@NotNull
|
||||||
private Integer endPos;
|
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 = "폴더 정보")
|
@Schema(name = "FolderDto", description = "폴더 정보")
|
||||||
|
|||||||
@@ -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.FilesDto;
|
||||||
import com.kamco.cd.kamcoback.mapsheet.dto.FileDto.FolderDto;
|
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.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.SrchFilesDto;
|
||||||
import com.kamco.cd.kamcoback.mapsheet.dto.FileDto.SrchFoldersDto;
|
import com.kamco.cd.kamcoback.mapsheet.dto.FileDto.SrchFoldersDto;
|
||||||
import com.kamco.cd.kamcoback.mapsheet.dto.MapSheetMngDto;
|
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());
|
Path startPath = Paths.get(srchDto.getDirPath());
|
||||||
|
int maxDepth = srchDto.getMaxDepth();
|
||||||
String dirPath = srchDto.getDirPath();
|
String dirPath = srchDto.getDirPath();
|
||||||
String extension = srchDto.getExtension();
|
String extension = srchDto.getExtension();
|
||||||
String sortType = srchDto.getSortType();
|
String sortType = srchDto.getSortType();
|
||||||
|
|
||||||
|
int startPos = srchDto.getStartPos();
|
||||||
|
int endPos = srchDto.getEndPos();
|
||||||
|
int limit = endPos - startPos + 1;
|
||||||
|
|
||||||
Set<String> targetExtensions = createExtensionSet(extension);
|
Set<String> targetExtensions = createExtensionSet(extension);
|
||||||
|
|
||||||
List<FileDto.Basic> fileDtoList = new ArrayList<>();
|
List<FileDto.Basic> fileDtoList = new ArrayList<>();
|
||||||
@@ -202,6 +206,7 @@ public class MapSheetMngService {
|
|||||||
int fileTotCnt = 0;
|
int fileTotCnt = 0;
|
||||||
long fileTotSize = 0;
|
long fileTotSize = 0;
|
||||||
|
|
||||||
|
|
||||||
try (Stream<Path> stream = Files.walk(startPath, maxDepth)) {
|
try (Stream<Path> stream = Files.walk(startPath, maxDepth)) {
|
||||||
|
|
||||||
fileDtoList =
|
fileDtoList =
|
||||||
@@ -214,6 +219,8 @@ public class MapSheetMngService {
|
|||||||
|| extension.equals("*")
|
|| extension.equals("*")
|
||||||
|| targetExtensions.contains(extractExtension(p)))
|
|| targetExtensions.contains(extractExtension(p)))
|
||||||
.sorted(getFileComparator(sortType))
|
.sorted(getFileComparator(sortType))
|
||||||
|
.skip(startPos)
|
||||||
|
.limit(limit)
|
||||||
.map(
|
.map(
|
||||||
path -> {
|
path -> {
|
||||||
int depth = path.getNameCount();
|
int depth = path.getNameCount();
|
||||||
@@ -236,23 +243,7 @@ public class MapSheetMngService {
|
|||||||
fileTotCnt = fileDtoList.size();
|
fileTotCnt = fileDtoList.size();
|
||||||
fileTotSize = fileDtoList.stream().mapToLong(FileDto.Basic::getFileSize).sum();
|
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) {
|
} catch (IOException e) {
|
||||||
System.err.println("파일 I/O 오류 발생: " + e.getMessage());
|
System.err.println("파일 I/O 오류 발생: " + e.getMessage());
|
||||||
|
|||||||
Reference in New Issue
Block a user