From dd975f48d2cd5ab873d80b38bd755e441ba6e443 Mon Sep 17 00:00:00 2001 From: "Harry M. You" Date: Wed, 3 Dec 2025 17:45:53 +0900 Subject: [PATCH] =?UTF-8?q?=ED=8F=B4=EB=8D=94=20validation=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mapsheet/MapSheetMngApiController.java | 21 ++++ .../cd/kamcoback/mapsheet/dto/FileDto.java | 15 ++- .../mapsheet/service/MapSheetMngService.java | 102 +++++++++++++----- 3 files changed, 111 insertions(+), 27 deletions(-) diff --git a/src/main/java/com/kamco/cd/kamcoback/mapsheet/MapSheetMngApiController.java b/src/main/java/com/kamco/cd/kamcoback/mapsheet/MapSheetMngApiController.java index 9f860352..a5667ad5 100644 --- a/src/main/java/com/kamco/cd/kamcoback/mapsheet/MapSheetMngApiController.java +++ b/src/main/java/com/kamco/cd/kamcoback/mapsheet/MapSheetMngApiController.java @@ -68,6 +68,27 @@ public class MapSheetMngApiController { return ApiResponseDto.createOK(mapSheetMngService.getFilesAll(srchDto)); } + @Operation(summary = "파일목록 조회", description = "파일목록 조회") + @ApiResponses( + value = { + @ApiResponse( + responseCode = "200", + description = "조회 성공", + content = + @Content( + mediaType = "application/json", + schema = @Schema(implementation = CommonCodeDto.Basic.class))), + @ApiResponse(responseCode = "404", description = "코드를 찾을 수 없음", content = @Content), + @ApiResponse(responseCode = "500", description = "서버 오류", content = @Content) + }) + @PostMapping("/file-all-list") + public ApiResponseDto getAllFiles(@RequestBody SrchFilesDto srchDto) { + + return ApiResponseDto.createOK(mapSheetMngService.getFilesDepthAll(srchDto)); + } + + + /** * 오류데이터 목록 조회 * diff --git a/src/main/java/com/kamco/cd/kamcoback/mapsheet/dto/FileDto.java b/src/main/java/com/kamco/cd/kamcoback/mapsheet/dto/FileDto.java index e62f41d3..6ba902f3 100644 --- a/src/main/java/com/kamco/cd/kamcoback/mapsheet/dto/FileDto.java +++ b/src/main/java/com/kamco/cd/kamcoback/mapsheet/dto/FileDto.java @@ -23,10 +23,15 @@ public class FileDto { @NoArgsConstructor @AllArgsConstructor public static class SrchFilesDto { + @Schema(description = "디렉토리경로", example = "/data") @NotNull private String dirPath; + @Schema(description = "전체(*), cpg,dbf,geojson등", example = "*") @NotNull private String extension; + @Schema(description = "파일명(name), 최종수정일(date)", example = "name") @NotNull private String sortType; + @Schema(description = "파일시작위치", example = "1") @NotNull private Integer startPos; + @Schema(description = "파일종료위치", example = "100") @NotNull private Integer endPos; } @@ -86,15 +91,19 @@ public class FileDto { public static class Basic { private final String fileNm; - private final String filePath; + private final String parentFolderNm; + private final String parentPath; + private final String fullPath; private final String extension; private final long fileSize; private final String lastModified; public Basic( - String fileNm, String filePath, String extension, long fileSize, String lastModified) { + String fileNm, String parentFolderNm, String parentPath, String fullPath, String extension, long fileSize, String lastModified) { this.fileNm = fileNm; - this.filePath = filePath; + this.parentFolderNm = parentFolderNm; + this.parentPath = parentPath; + this.fullPath = fullPath; this.extension = extension; this.fileSize = fileSize; this.lastModified = lastModified; diff --git a/src/main/java/com/kamco/cd/kamcoback/mapsheet/service/MapSheetMngService.java b/src/main/java/com/kamco/cd/kamcoback/mapsheet/service/MapSheetMngService.java index 764e21fa..a4785ef3 100644 --- a/src/main/java/com/kamco/cd/kamcoback/mapsheet/service/MapSheetMngService.java +++ b/src/main/java/com/kamco/cd/kamcoback/mapsheet/service/MapSheetMngService.java @@ -67,11 +67,8 @@ public class MapSheetMngService { String parentPath = path.getParent().toString(); String fullPath = path.toAbsolutePath().toString(); - boolean isValid = true; - if( NameValidator.containsKorean(folderNm) || - NameValidator.containsWhitespaceRegex(folderNm) ){ - isValid = false; - } + boolean isValid = !NameValidator.containsKorean(folderNm) && + !NameValidator.containsWhitespaceRegex(folderNm); File directory = new File(fullPath); File[] childFolders = directory.listFiles(File::isDirectory); @@ -82,27 +79,24 @@ public class MapSheetMngService { } FileTime time = null; + String lastModified = ""; try { time = Files.getLastModifiedTime(path); + lastModified = dttmFormat.format(new Date(time.toMillis())); } catch (IOException e) { throw new RuntimeException(e); } - String lastModified = dttmFormat.format(new Date(time.toMillis())); - - FolderDto folderDto = - new FolderDto( - folderNm, - parentFolderNm, - parentPath, - fullPath, - depth, - childCnt, - lastModified, - isValid - ); - - return folderDto; + return new FolderDto( + folderNm, + parentFolderNm, + parentPath, + fullPath, + depth, + childCnt, + lastModified, + isValid + ); }) .collect(Collectors.toList()); @@ -122,9 +116,9 @@ public class MapSheetMngService { throw new RuntimeException(e); } - FoldersDto foldersDto = new FoldersDto(dirPath, folderTotCnt, folderErrTotCnt, folderDtoList); + // FoldersDto foldersDto = new FoldersDto(dirPath, folderTotCnt, folderErrTotCnt, folderDtoList); - return foldersDto; + return new FoldersDto(dirPath, folderTotCnt, folderErrTotCnt, folderDtoList); } public FilesDto getFilesAll(SrchFilesDto srchDto) { @@ -161,12 +155,17 @@ public class MapSheetMngService { // 생성자를 통해 객체를 만들고 리스트에 추가 String fileName = file.getName(); - String filePath = file.getAbsolutePath(); + String parentPath = file.getParent(); + String fullPath = file.getAbsolutePath(); String ext = FilenameUtils.getExtension(fileName); + + Path path = Paths.get(parentPath); + String parentFolderNm = path.getFileName().toString(); + long fileSize = file.length(); String lastModified = dttmFormat.format(new Date(file.lastModified())); - files.add(new FileDto.Basic(fileName, filePath, ext, fileSize, lastModified)); + files.add(new FileDto.Basic(fileName, parentFolderNm, parentPath, fullPath, ext, fileSize, lastModified)); fileTotCnt = fileTotCnt + 1; fileTotSize = fileTotSize + fileSize; @@ -181,6 +180,61 @@ public class MapSheetMngService { return filesDto; } + + + public FilesDto getFilesDepthAll(SrchFilesDto srchDto) { + + int maxDepth = 20; + Path startPath = Paths.get(srchDto.getDirPath()); + String dirPath = srchDto.getDirPath(); + String extension = srchDto.getExtension(); + + List fileDtoList = new ArrayList<>(); + SimpleDateFormat dttmFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + int fileTotCnt = 0; + long fileTotSize = 0; + + try (Stream stream = Files.walk(startPath, maxDepth)) { + + fileDtoList = + stream + .filter(Files::isRegularFile) + .map( + path -> { + + int depth = path.getNameCount(); + + String fileNm = path.getFileName().toString(); + String ext = FilenameUtils.getExtension(fileNm); + String parentFolderNm = path.getParent().getFileName().toString(); + String parentPath = path.getParent().toString(); + String fullPath = path.toAbsolutePath().toString(); + + File file = new File(fullPath); + long fileSize = file.length(); + String lastModified = dttmFormat.format(new Date(file.lastModified())); + + return new FileDto.Basic(fileNm, parentFolderNm, parentPath, fullPath, ext, fileSize, lastModified); + }) + .collect(Collectors.toList()); + + fileTotCnt = fileDtoList.size(); + fileTotSize = fileDtoList.stream() + .mapToLong(FileDto.Basic::getFileSize) + .sum(); + + } catch (IOException e) { + System.err.println("파일 I/O 오류 발생: " + e.getMessage()); + } + + + FilesDto filesDto = new FilesDto(dirPath, fileTotCnt, fileTotSize, fileDtoList); + + return filesDto; + } + + public Page findMapSheetErrorList( MapSheetMngDto.@Valid searchReq searchReq) { return mapSheetMngCoreService.findMapSheetErrorList(searchReq);