영상관리 -> 폴더선택 추가
This commit is contained in:
@@ -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<List<FileDto.FolderDto>> getDir(
|
||||||
|
@RequestParam String dirPath,
|
||||||
|
@Parameter(schema = @Schema(allowableValues = {"geojson", "prj", "shp", "shx","*"}))
|
||||||
|
@RequestParam String extension
|
||||||
|
) {
|
||||||
|
|
||||||
|
return ApiResponseDto.createOK(mapSheetMngService.getFolderAll(dirPath));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
111
src/main/java/com/kamco/cd/kamcoback/mapsheet/dto/FileDto.java
Normal file
111
src/main/java/com/kamco/cd/kamcoback/mapsheet/dto/FileDto.java
Normal file
@@ -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<Basic> files;
|
||||||
|
|
||||||
|
public FilesDto(
|
||||||
|
String dirPath,
|
||||||
|
int fileTotCnt,
|
||||||
|
long fileTotSize,
|
||||||
|
List<Basic> files
|
||||||
|
|
||||||
|
) {
|
||||||
|
this.dirPath = dirPath;
|
||||||
|
this.fileTotCnt = fileTotCnt;
|
||||||
|
this.fileTotSize = fileTotSize;
|
||||||
|
this.files = files;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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<FolderDto> getFolderAll(String dirPath) {
|
||||||
|
|
||||||
|
Path startPath = Paths.get(dirPath);
|
||||||
|
int maxDepth = 1;
|
||||||
|
|
||||||
|
List<FolderDto> folderDtoList = List.of();
|
||||||
|
SimpleDateFormat dttmFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
|
||||||
|
|
||||||
|
try (Stream<Path> 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<FolderDto> getFolders(String dirPath) {
|
||||||
|
|
||||||
|
Path startPath = Paths.get(dirPath);
|
||||||
|
int maxDepth = 1;
|
||||||
|
|
||||||
|
List<FolderDto> folderDtoList = List.of();
|
||||||
|
SimpleDateFormat dttmFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
|
||||||
|
try (Stream<Path> 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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user