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 607c95a8..d0ae311d 100644 --- a/src/main/java/com/kamco/cd/kamcoback/mapsheet/MapSheetMngApiController.java +++ b/src/main/java/com/kamco/cd/kamcoback/mapsheet/MapSheetMngApiController.java @@ -4,6 +4,8 @@ import com.kamco.cd.kamcoback.code.dto.CommonCodeDto; import com.kamco.cd.kamcoback.code.service.CommonCodeService; import com.kamco.cd.kamcoback.config.api.ApiResponseDto; 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.SrchDto; import com.kamco.cd.kamcoback.mapsheet.service.MapSheetMngService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; @@ -34,7 +36,7 @@ import org.springframework.web.bind.annotation.RestController; @Tag(name = "영상 관리", description = "영상 관리 API") @RestController @RequiredArgsConstructor -@RequestMapping({"/demo/mapsheet", "/api/mapsheet"}) +@RequestMapping({"/api/mapsheet"}) public class MapSheetMngApiController { private final CommonCodeService commonCodeService; @@ -53,16 +55,36 @@ public class MapSheetMngApiController { @ApiResponse(responseCode = "404", description = "코드를 찾을 수 없음", content = @Content), @ApiResponse(responseCode = "500", description = "서버 오류", content = @Content) }) - @GetMapping("/folders") + @PostMapping("/getFolders") public ApiResponseDto> getDir( - @RequestParam String dirPath, - @Parameter(schema = @Schema(allowableValues = {"geojson", "prj", "shp", "shx","*"})) - @RequestParam String extension + @RequestParam String dirPath ) { return ApiResponseDto.createOK(mapSheetMngService.getFolderAll(dirPath)); } + @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("/getFiles") + public ApiResponseDto getFiles( + @RequestBody SrchDto srchDto + ) { + + return ApiResponseDto.createOK(mapSheetMngService.getFilesAll(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 78647dd5..72d0d6f1 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 @@ -37,7 +37,7 @@ public class FileDto { private final String parentPath; private final String fullPath; private final int depth; - private final int fileCnt; + private final long childCnt; private final String lastModified; public FolderDto( @@ -46,7 +46,7 @@ public class FileDto { String parentPath, String fullPath, int depth, - int fileCnt, + long childCnt, String lastModified ) { this.folderNm = folderNm; @@ -54,7 +54,7 @@ public class FileDto { this.parentPath = parentPath; this.fullPath = fullPath; this.depth = depth; - this.fileCnt = fileCnt; + this.childCnt = childCnt; 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 fee8bf8b..24a65f97 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 @@ -1,6 +1,9 @@ package com.kamco.cd.kamcoback.mapsheet.service; +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.SrchDto; import java.io.File; import java.io.IOException; import java.nio.file.Files; @@ -36,65 +39,6 @@ public class MapSheetMngService { SimpleDateFormat dttmFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - try (Stream stream = Files.walk(startPath, maxDepth)) { - - folderDtoList = stream - // 1. 디렉토리만 필터링 - .filter(Files::isDirectory) - //.filter(p -> !p.toString().equals(dirPath)) - .map(path -> { - - int depth = path.getNameCount(); - String folderNm = path.getFileName().toString(); - String parentFolderNm = path.getParent().toString().replace(dirPath+"\\", "").replace("\\", "/" ); - String parentPath = path.getParent().toString().replace("\\", "/" ); - String fullPath = path.toAbsolutePath().toString().replace("\\", "/" ); - - FileTime time = null; - try { - time = Files.getLastModifiedTime(path); - } catch (IOException e) { - throw new RuntimeException(e); - } - - String lastModified = dttmFormat.format(new Date(time.toMillis())); - - FolderDto folderDto = new FolderDto( - folderNm, - parentFolderNm, - parentPath, - fullPath, - depth, - 0, - lastModified - ); - - return folderDto; - }) - .collect(Collectors.toList()); - - folderDtoList.sort(Comparator.comparing( - FolderDto::getFolderNm, - String.CASE_INSENSITIVE_ORDER // 대소문자 구분 없이 - ).reversed()); - - } catch (IOException e) { - throw new RuntimeException(e); - } - - return folderDtoList; - - } - - - public List getFolders(String dirPath) { - - Path startPath = Paths.get(dirPath); - int maxDepth = 1; - - List folderDtoList = List.of(); - SimpleDateFormat dttmFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - try (Stream stream = Files.walk(startPath, maxDepth)) { folderDtoList = stream @@ -105,9 +49,17 @@ public class MapSheetMngService { int depth = path.getNameCount(); String folderNm = path.getFileName().toString(); - String parentFolderNm = path.getParent().toString().replace(dirPath+"\\", "").replace("\\", "/" ); - String parentPath = path.getParent().toString().replace("\\", "/" ); - String fullPath = path.toAbsolutePath().toString().replace("\\", "/" ); + String parentFolderNm = path.getParent().getFileName().toString(); + String parentPath = path.getParent().toString(); + String fullPath = path.toAbsolutePath().toString(); + + File directory = new File(fullPath); + File[] childFolders = directory.listFiles(File::isDirectory); + + long childCnt = 0; + if (childFolders != null) { + childCnt = childFolders.length; + } FileTime time = null; try { @@ -124,7 +76,7 @@ public class MapSheetMngService { parentPath, fullPath, depth, - 0, + childCnt, lastModified ); @@ -145,4 +97,71 @@ public class MapSheetMngService { } + + public FilesDto getFilesAll(SrchDto srchDto) { + + String dirPath = srchDto.getDirPath(); + String extension = srchDto.getExtension(); + String sortType = srchDto.getSortType(); + int startPos = srchDto.getStartPos(); + int endPos = srchDto.getEndPos(); + File dir = new File(dirPath); + File[] fileList = dir.listFiles(); + + List files = new ArrayList<>(); + SimpleDateFormat dttmFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + + int fileListPos = 0; + int fileTotCnt = 0; + long fileTotSize = 0; + + if( fileList != null ) + { + if( sortType.equals("name")){ + Arrays.sort(fileList); + } + else if( sortType.equals("date")){ + Arrays.sort(fileList, Comparator.comparingLong(File::lastModified)); + } + + for (File file : fileList) { + if (file.isFile() ) { // 파일인 경우만 + if( extension.equals("*") || file.getName().endsWith("."+extension) ) { + + fileListPos = fileListPos + 1; + + if( startPos <= fileListPos && endPos >= fileListPos ) { + + // 생성자를 통해 객체를 만들고 리스트에 추가 + String fileName = file.getName(); + String filePath = file.getAbsolutePath(); + String ext = FilenameUtils.getExtension(fileName); + long fileSize = file.length(); + String lastModified = dttmFormat.format(new Date(file.lastModified())); + + files.add(new FileDto.Basic(fileName, filePath, ext, fileSize, lastModified)); + + fileTotCnt = fileTotCnt + 1; + fileTotSize = fileTotSize + fileSize; + + } + } + } + } + + } + + + FilesDto filesDto = new FilesDto( + dirPath, + fileTotCnt, + fileTotSize, + files); + + + + return filesDto; + + } + }