영상관리 -> 파일리스트 조회 추가
This commit is contained in:
@@ -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.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;
|
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 com.kamco.cd.kamcoback.mapsheet.service.MapSheetMngService;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
@@ -34,7 +36,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
@Tag(name = "영상 관리", description = "영상 관리 API")
|
@Tag(name = "영상 관리", description = "영상 관리 API")
|
||||||
@RestController
|
@RestController
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@RequestMapping({"/demo/mapsheet", "/api/mapsheet"})
|
@RequestMapping({"/api/mapsheet"})
|
||||||
public class MapSheetMngApiController {
|
public class MapSheetMngApiController {
|
||||||
|
|
||||||
private final CommonCodeService commonCodeService;
|
private final CommonCodeService commonCodeService;
|
||||||
@@ -53,16 +55,36 @@ public class MapSheetMngApiController {
|
|||||||
@ApiResponse(responseCode = "404", description = "코드를 찾을 수 없음", content = @Content),
|
@ApiResponse(responseCode = "404", description = "코드를 찾을 수 없음", content = @Content),
|
||||||
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
|
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
|
||||||
})
|
})
|
||||||
@GetMapping("/folders")
|
@PostMapping("/getFolders")
|
||||||
public ApiResponseDto<List<FileDto.FolderDto>> getDir(
|
public ApiResponseDto<List<FileDto.FolderDto>> getDir(
|
||||||
@RequestParam String dirPath,
|
@RequestParam String dirPath
|
||||||
@Parameter(schema = @Schema(allowableValues = {"geojson", "prj", "shp", "shx","*"}))
|
|
||||||
@RequestParam String extension
|
|
||||||
) {
|
) {
|
||||||
|
|
||||||
return ApiResponseDto.createOK(mapSheetMngService.getFolderAll(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<FilesDto> getFiles(
|
||||||
|
@RequestBody SrchDto srchDto
|
||||||
|
) {
|
||||||
|
|
||||||
|
return ApiResponseDto.createOK(mapSheetMngService.getFilesAll(srchDto));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ public class FileDto {
|
|||||||
private final String parentPath;
|
private final String parentPath;
|
||||||
private final String fullPath;
|
private final String fullPath;
|
||||||
private final int depth;
|
private final int depth;
|
||||||
private final int fileCnt;
|
private final long childCnt;
|
||||||
private final String lastModified;
|
private final String lastModified;
|
||||||
|
|
||||||
public FolderDto(
|
public FolderDto(
|
||||||
@@ -46,7 +46,7 @@ public class FileDto {
|
|||||||
String parentPath,
|
String parentPath,
|
||||||
String fullPath,
|
String fullPath,
|
||||||
int depth,
|
int depth,
|
||||||
int fileCnt,
|
long childCnt,
|
||||||
String lastModified
|
String lastModified
|
||||||
) {
|
) {
|
||||||
this.folderNm = folderNm;
|
this.folderNm = folderNm;
|
||||||
@@ -54,7 +54,7 @@ public class FileDto {
|
|||||||
this.parentPath = parentPath;
|
this.parentPath = parentPath;
|
||||||
this.fullPath = fullPath;
|
this.fullPath = fullPath;
|
||||||
this.depth = depth;
|
this.depth = depth;
|
||||||
this.fileCnt = fileCnt;
|
this.childCnt = childCnt;
|
||||||
this.lastModified = lastModified;
|
this.lastModified = lastModified;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
package com.kamco.cd.kamcoback.mapsheet.service;
|
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.FolderDto;
|
||||||
|
import com.kamco.cd.kamcoback.mapsheet.dto.FileDto.SrchDto;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
@@ -36,65 +39,6 @@ public class MapSheetMngService {
|
|||||||
SimpleDateFormat dttmFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
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)) {
|
try (Stream<Path> stream = Files.walk(startPath, maxDepth)) {
|
||||||
|
|
||||||
folderDtoList = stream
|
folderDtoList = stream
|
||||||
@@ -105,9 +49,17 @@ public class MapSheetMngService {
|
|||||||
|
|
||||||
int depth = path.getNameCount();
|
int depth = path.getNameCount();
|
||||||
String folderNm = path.getFileName().toString();
|
String folderNm = path.getFileName().toString();
|
||||||
String parentFolderNm = path.getParent().toString().replace(dirPath+"\\", "").replace("\\", "/" );
|
String parentFolderNm = path.getParent().getFileName().toString();
|
||||||
String parentPath = path.getParent().toString().replace("\\", "/" );
|
String parentPath = path.getParent().toString();
|
||||||
String fullPath = path.toAbsolutePath().toString().replace("\\", "/" );
|
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;
|
FileTime time = null;
|
||||||
try {
|
try {
|
||||||
@@ -124,7 +76,7 @@ public class MapSheetMngService {
|
|||||||
parentPath,
|
parentPath,
|
||||||
fullPath,
|
fullPath,
|
||||||
depth,
|
depth,
|
||||||
0,
|
childCnt,
|
||||||
lastModified
|
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<FileDto.Basic> 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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user