영상관리 -> 파일리스트 조회 추가
This commit is contained in:
@@ -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<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
|
||||
@@ -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<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