파일목록 조회 --> 모든 폴더 depth 조회하기 추가
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package com.kamco.cd.kamcoback.mapsheet.service;
|
||||
|
||||
import static java.lang.String.CASE_INSENSITIVE_ORDER;
|
||||
|
||||
import com.kamco.cd.kamcoback.common.utils.NameValidator;
|
||||
import com.kamco.cd.kamcoback.mapsheet.dto.FileDto;
|
||||
import com.kamco.cd.kamcoback.mapsheet.dto.FileDto.FilesDto;
|
||||
@@ -22,6 +24,7 @@ import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -102,12 +105,11 @@ public class MapSheetMngService {
|
||||
|
||||
folderDtoList.sort(
|
||||
Comparator.comparing(
|
||||
FolderDto::getFolderNm, String.CASE_INSENSITIVE_ORDER // 대소문자 구분 없이
|
||||
FolderDto::getFolderNm, CASE_INSENSITIVE_ORDER // 대소문자 구분 없이
|
||||
)
|
||||
.reversed());
|
||||
|
||||
folderTotCnt = folderDtoList.size();
|
||||
|
||||
folderErrTotCnt = (int)folderDtoList.stream()
|
||||
.filter(dto -> dto.getIsValid().toString().equals("false") )
|
||||
.count();
|
||||
@@ -188,6 +190,9 @@ public class MapSheetMngService {
|
||||
Path startPath = Paths.get(srchDto.getDirPath());
|
||||
String dirPath = srchDto.getDirPath();
|
||||
String extension = srchDto.getExtension();
|
||||
String sortType = srchDto.getSortType();
|
||||
|
||||
Set<String> targetExtensions = createExtensionSet(extension);
|
||||
|
||||
List<FileDto.Basic> fileDtoList = new ArrayList<>();
|
||||
SimpleDateFormat dttmFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
@@ -200,6 +205,12 @@ public class MapSheetMngService {
|
||||
fileDtoList =
|
||||
stream
|
||||
.filter(Files::isRegularFile)
|
||||
.filter(p -> extension == null ||
|
||||
extension.equals("") ||
|
||||
extension.equals("*") ||
|
||||
targetExtensions.contains(extractExtension(p))
|
||||
)
|
||||
.sorted(getFileComparator(sortType))
|
||||
.map(
|
||||
path -> {
|
||||
|
||||
@@ -224,16 +235,88 @@ public class MapSheetMngService {
|
||||
.mapToLong(FileDto.Basic::getFileSize)
|
||||
.sum();
|
||||
|
||||
/*
|
||||
if( sort.equals("name")) {
|
||||
fileDtoList.sort(
|
||||
Comparator.comparing(
|
||||
FileDto.Basic::getFileNm, String.CASE_INSENSITIVE_ORDER
|
||||
)
|
||||
.reversed());
|
||||
}
|
||||
else if( sort.equals("date")) {
|
||||
fileDtoList.sort(
|
||||
Comparator.comparing(
|
||||
FileDto.Basic::getLastModified
|
||||
)
|
||||
.reversed());
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
} catch (IOException e) {
|
||||
System.err.println("파일 I/O 오류 발생: " + e.getMessage());
|
||||
}
|
||||
|
||||
|
||||
FilesDto filesDto = new FilesDto(dirPath, fileTotCnt, fileTotSize, fileDtoList);
|
||||
|
||||
return filesDto;
|
||||
return new FilesDto(dirPath, fileTotCnt, fileTotSize, fileDtoList);
|
||||
}
|
||||
|
||||
public Set<String> createExtensionSet(String extensionString) {
|
||||
if (extensionString == null || extensionString.isBlank()) {
|
||||
return Set.of();
|
||||
}
|
||||
|
||||
// "java, class" -> ["java", " class"] -> [".java", ".class"]
|
||||
return Arrays.stream(extensionString.split(","))
|
||||
.map(ext -> ext.trim())
|
||||
.filter(ext -> !ext.isEmpty())
|
||||
.map(ext -> "." + ext.toLowerCase())
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
public String extractExtension(Path path) {
|
||||
String filename = path.getFileName().toString();
|
||||
int lastDotIndex = filename.lastIndexOf('.');
|
||||
|
||||
// 확장자가 없거나 파일명이 .으로 끝나는 경우
|
||||
if (lastDotIndex == -1 || lastDotIndex == filename.length() - 1 ) {
|
||||
return ""; // 빈 문자열 반환
|
||||
}
|
||||
|
||||
// 확장자 추출 및 소문자 변환
|
||||
return filename.substring(lastDotIndex).toLowerCase();
|
||||
}
|
||||
|
||||
|
||||
public Comparator<Path> getFileComparator(String sortType) {
|
||||
|
||||
// 파일 이름 비교 기본 Comparator (대소문자 무시)
|
||||
Comparator<Path> nameComparator = Comparator.comparing(
|
||||
path -> path.getFileName().toString(),
|
||||
CASE_INSENSITIVE_ORDER
|
||||
);
|
||||
|
||||
Comparator<Path> dateComparator = Comparator.comparing(
|
||||
path -> {
|
||||
try {
|
||||
return Files.getLastModifiedTime(path);
|
||||
} catch (IOException e) {
|
||||
return FileTime.fromMillis(0);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
if ("name desc".equalsIgnoreCase(sortType)) {
|
||||
return nameComparator.reversed();
|
||||
} else if ("date".equalsIgnoreCase(sortType)) {
|
||||
return dateComparator;
|
||||
} else if ("date desc".equalsIgnoreCase(sortType)) {
|
||||
return dateComparator.reversed();
|
||||
} else {
|
||||
return nameComparator;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Page<MapSheetMngDto.ErrorDataDto> findMapSheetErrorList(
|
||||
MapSheetMngDto.@Valid searchReq searchReq) {
|
||||
|
||||
Reference in New Issue
Block a user