From e234b65bc6bc350769a9b9ddd4a6cb9ab8e65dc7 Mon Sep 17 00:00:00 2001 From: "Harry M. You" Date: Tue, 2 Dec 2025 14:16:40 +0900 Subject: [PATCH] =?UTF-8?q?=EC=98=81=EC=83=81=EA=B4=80=EB=A6=AC=20->=20?= =?UTF-8?q?=ED=8F=B4=EB=8D=94=EC=84=A0=ED=83=9D=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mapsheet/MapSheetMngApiController.java | 79 ++++++++++ .../cd/kamcoback/mapsheet/dto/FileDto.java | 111 +++++++++++++ .../mapsheet/service/MapSheetMngService.java | 148 ++++++++++++++++++ 3 files changed, 338 insertions(+) create mode 100644 src/main/java/com/kamco/cd/kamcoback/mapsheet/MapSheetMngApiController.java create mode 100644 src/main/java/com/kamco/cd/kamcoback/mapsheet/dto/FileDto.java create mode 100644 src/main/java/com/kamco/cd/kamcoback/mapsheet/service/MapSheetMngService.java diff --git a/src/main/java/com/kamco/cd/kamcoback/mapsheet/MapSheetMngApiController.java b/src/main/java/com/kamco/cd/kamcoback/mapsheet/MapSheetMngApiController.java new file mode 100644 index 00000000..607c95a8 --- /dev/null +++ b/src/main/java/com/kamco/cd/kamcoback/mapsheet/MapSheetMngApiController.java @@ -0,0 +1,79 @@ +package com.kamco.cd.kamcoback.mapsheet; + +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.service.MapSheetMngService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@Tag(name = "영상 관리", description = "영상 관리 API") +@RestController +@RequiredArgsConstructor +@RequestMapping({"/demo/mapsheet", "/api/mapsheet"}) +public class MapSheetMngApiController { + + private final CommonCodeService commonCodeService; + private final MapSheetMngService mapSheetMngService; + + @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) + }) + @GetMapping("/folders") + public ApiResponseDto> getDir( + @RequestParam String dirPath, + @Parameter(schema = @Schema(allowableValues = {"geojson", "prj", "shp", "shx","*"})) + @RequestParam String extension + ) { + + return ApiResponseDto.createOK(mapSheetMngService.getFolderAll(dirPath)); + } + + + + + + + + + + + + + + +} 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 new file mode 100644 index 00000000..78647dd5 --- /dev/null +++ b/src/main/java/com/kamco/cd/kamcoback/mapsheet/dto/FileDto.java @@ -0,0 +1,111 @@ +package com.kamco.cd.kamcoback.mapsheet.dto; + +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotNull; +import java.util.ArrayList; +import java.util.List; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + + +public class FileDto { + + + @Getter + @Setter + @NoArgsConstructor + @AllArgsConstructor + public static class SrchDto { + + @NotNull private String dirPath; + @NotNull private String extension; + @NotNull private String sortType; + @NotNull private Integer startPos; + @NotNull private Integer endPos; + + + + } + + @Schema(name = "FolderDto", description = "폴더 정보") + @Getter + public static class FolderDto { + private final String folderNm; + private final String parentFolderNm; + private final String parentPath; + private final String fullPath; + private final int depth; + private final int fileCnt; + private final String lastModified; + + public FolderDto( + String folderNm, + String parentFolderNm, + String parentPath, + String fullPath, + int depth, + int fileCnt, + String lastModified + ) { + this.folderNm = folderNm; + this.parentFolderNm = parentFolderNm; + this.parentPath = parentPath; + this.fullPath = fullPath; + this.depth = depth; + this.fileCnt = fileCnt; + this.lastModified = lastModified; + } + + } + + @Schema(name = "File Basic", description = "파일 기본 정보") + @Getter + public static class Basic { + + private final String fileNm; + private final String filePath; + private final String extension; + private final long fileSize; + private final String lastModified; + + public Basic( + String fileNm, + String filePath, + String extension, + long fileSize, + String lastModified + ) { + this.fileNm = fileNm; + this.filePath = filePath; + this.extension = extension; + this.fileSize = fileSize; + this.lastModified = lastModified; + } + } + + @Schema(name = "FilesDto", description = "파일 목록 정보") + @Getter + public static class FilesDto { + private final String dirPath; + private final int fileTotCnt; + private final long fileTotSize; + private final List files; + + public FilesDto( + String dirPath, + int fileTotCnt, + long fileTotSize, + List files + + ) { + this.dirPath = dirPath; + this.fileTotCnt = fileTotCnt; + this.fileTotSize = fileTotSize; + this.files = files; + } + } + + +} 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 new file mode 100644 index 00000000..fee8bf8b --- /dev/null +++ b/src/main/java/com/kamco/cd/kamcoback/mapsheet/service/MapSheetMngService.java @@ -0,0 +1,148 @@ +package com.kamco.cd.kamcoback.mapsheet.service; + +import com.kamco.cd.kamcoback.mapsheet.dto.FileDto.FolderDto; +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.attribute.FileTime; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Comparator; +import java.util.Date; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import lombok.RequiredArgsConstructor; +import org.apache.commons.io.FilenameUtils; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +@Transactional(readOnly = true) +public class MapSheetMngService { + + //private final MapSheetAnalDataCoreService mapSheetAnalDataCoreService; + + public List getFolderAll(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 + // 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 + // 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; + + } + +}