영상관리 -> 폴더선택 추가

This commit is contained in:
Harry M. You
2025-12-02 14:16:40 +09:00
parent 2036a85df9
commit e234b65bc6
3 changed files with 338 additions and 0 deletions

View File

@@ -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;
}
}