영상관리 수정 반영

This commit is contained in:
Moon
2025-12-19 13:55:55 +09:00
parent dfe5ef50fc
commit 988ba96a7a
9 changed files with 326 additions and 200 deletions

View File

@@ -5,10 +5,8 @@ import static java.lang.String.CASE_INSENSITIVE_ORDER;
import com.kamco.cd.kamcoback.common.exception.DuplicateFileException;
import com.kamco.cd.kamcoback.common.exception.ValidationException;
import com.kamco.cd.kamcoback.common.utils.FIleChecker;
import com.kamco.cd.kamcoback.common.utils.NameValidator;
import com.kamco.cd.kamcoback.config.FileConfig;
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.FoldersDto;
import com.kamco.cd.kamcoback.mapsheet.dto.FileDto.SrchFilesDepthDto;
import com.kamco.cd.kamcoback.mapsheet.dto.FileDto.SrchFilesDto;
@@ -17,21 +15,17 @@ import com.kamco.cd.kamcoback.mapsheet.dto.ImageryDto;
import com.kamco.cd.kamcoback.postgres.core.MapSheetMngFileCheckerCoreService;
import com.kamco.cd.kamcoback.postgres.entity.MapSheetMngFileEntity;
import com.kamco.cd.kamcoback.postgres.repository.mapsheet.MapSheetMngFileRepository;
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.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FilenameUtils;
@@ -56,85 +50,16 @@ public class MapSheetMngFileCheckerService {
Path startPath = Paths.get(fileConfig.getRootSyncDir() + srchDto.getDirPath());
String dirPath = fileConfig.getRootSyncDir() + srchDto.getDirPath();
String sortType = "name desc";
// Path startPath = Paths.get(fileConfig.getRootSyncDir()+srchDto.getDirPath());
// String dirPath = fileConfig.getRootSyncDir()+srchDto.getDirPath();
List<FIleChecker.Folder> folderList = FIleChecker.getFolderAll(dirPath);
int maxDepth = 1;
int folderTotCnt = folderList.size();
int folderErrTotCnt =
(int)
folderList.stream().filter(dto -> dto.getIsValid().toString().equals("false")).count();
int folderTotCnt = 0;
int folderErrTotCnt = 0;
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().getFileName().toString();
String parentPath = path.getParent().toString();
String fullPath = path.toAbsolutePath().toString();
boolean isValid =
!NameValidator.containsKorean(folderNm)
&& !NameValidator.containsWhitespaceRegex(folderNm);
File directory = new File(fullPath);
File[] childFolders = directory.listFiles(File::isDirectory);
long childCnt = 0;
if (childFolders != null) {
childCnt = childFolders.length;
}
FileTime time = null;
String lastModified = "";
try {
time = Files.getLastModifiedTime(path);
lastModified = dttmFormat.format(new Date(time.toMillis()));
} catch (IOException e) {
throw new RuntimeException(e);
}
return new FolderDto(
folderNm,
parentFolderNm,
parentPath,
fullPath,
depth,
childCnt,
lastModified,
isValid);
})
.collect(Collectors.toList());
folderDtoList.sort(
Comparator.comparing(
FolderDto::getFolderNm, CASE_INSENSITIVE_ORDER // 대소문자 구분 없이
)
.reversed());
folderTotCnt = folderDtoList.size();
folderErrTotCnt =
(int)
folderDtoList.stream()
.filter(dto -> dto.getIsValid().toString().equals("false"))
.count();
} catch (IOException e) {
throw new RuntimeException(e);
}
return new FoldersDto(dirPath, folderTotCnt, folderErrTotCnt, folderDtoList);
return new FoldersDto(dirPath, folderTotCnt, folderErrTotCnt, folderList);
}
public FilesDto getFilesAll(SrchFilesDto srchDto) {

View File

@@ -65,17 +65,6 @@ public class MapSheetMngService {
return mapSheetMngCoreService.mngDataSave(AddReq);
}
/*
public MapSheetMngDto.DmlReturn uploadFile(MultipartFile file, Long hstUid) {
return mapSheetMngCoreService.uploadFile(file, hstUid);
}
public MapSheetMngDto.DmlReturn deleteFile(MapSheetMngDto.DeleteFileReq req) {
return mapSheetMngCoreService.deleteFile(req);
}
*/
public DmlReturn uploadProcess(@Valid List<Long> hstUidList) {
return mapSheetMngCoreService.uploadProcess(hstUidList);
}
@@ -88,12 +77,22 @@ public class MapSheetMngService {
public DmlReturn uploadPair(
MultipartFile tfwFile,
MultipartFile tifFile,
// String targetPath,
Long hstUid) {
String rootPath = fileConfig.getRootSyncDir();
String tmpPath = fileConfig.getTmpSyncDir();
ErrorDataDto errDto = mapSheetMngCoreService.findMapSheetError(hstUid);
if (errDto == null) {
return new DmlReturn("fail", "NO hstUid Data");
}
//파일검증용 임시저장 폴더 확인
if( ! FIleChecker.mkDir(tmpPath) )
{
return new DmlReturn("fail", "CREATE TEMP FOLDER ERROR");
}
// 파일 유효성 검증
if (tfwFile == null || tfwFile.isEmpty() || tfwFile.getSize() == 0) {
return new DmlReturn("fail", "TFW SIZE 오류");
@@ -101,35 +100,27 @@ public class MapSheetMngService {
return new DmlReturn("fail", "TIF SIZE 오류");
}
if (!tfwFile
.getOriginalFilename()
.substring(tfwFile.getOriginalFilename().lastIndexOf('.') + 1)
.toLowerCase()
.equals("tfw")) {
//확장자명 체크
if( ! FIleChecker.checkExtensions(tfwFile.getOriginalFilename(), "tfw") )
{
return new DmlReturn("fail", "TFW FILENAME ERROR");
} else if (!tifFile
.getOriginalFilename()
.substring(tifFile.getOriginalFilename().lastIndexOf('.') + 1)
.toLowerCase()
.equals("tif")) {
}
else if( ! FIleChecker.checkExtensions(tifFile.getOriginalFilename(), "tif") )
{
return new DmlReturn("fail", "TIF FILENAME ERROR");
}
ErrorDataDto errDto = mapSheetMngCoreService.findMapSheetError(hstUid);
if (errDto == null) {
return new DmlReturn("fail", "NO hstUid Data");
}
MngDto mngDto = mapSheetMngCoreService.findMapSheetMng(errDto.getMngYyyy());
String targetYearDir = mngDto.getMngPath();
//중복체크
List<FIleChecker.Basic> basicTfwList =
FIleChecker.getFilesFromAllDepth(
targetYearDir, tfwFile.getOriginalFilename(), "tfw", 100, "name", 0, 100);
targetYearDir, tfwFile.getOriginalFilename(), "tfw");
List<FIleChecker.Basic> basicTifList =
FIleChecker.getFilesFromAllDepth(
targetYearDir, tifFile.getOriginalFilename(), "tif", 100, "name", 0, 100);
targetYearDir, tifFile.getOriginalFilename(), "tif");
int tfwCnt =
(int)
@@ -148,7 +139,7 @@ public class MapSheetMngService {
String tifMsg = "";
if (tfwCnt > 0) tfwMsg = tfwFile.getOriginalFilename();
if (tifCnt > 0) tifMsg = tifFile.getOriginalFilename();
return new DmlReturn("fail", tfwMsg + "," + tifMsg + " DUPLICATE ERROR");
return new DmlReturn("duplicate", tfwMsg + "," + tifMsg);
}
File directory = new File(tmpPath);
@@ -168,7 +159,7 @@ public class MapSheetMngService {
if (!FIleChecker.cmmndGdalInfo(tifTmpPath)) return new DmlReturn("fail", "TIF TYPE ERROR");
if (!FIleChecker.checkTfw(tfwTmpPath)) return new DmlReturn("fail", "TFW TYPE ERROR");
// 싱크파일목록 가저오기
// 싱크파일목록으로 업로드 경로 확인
List<MngFilesDto> mngFiles = mapSheetMngCoreService.findIdToMapSheetFileList(hstUid);
String uploadPath = "";
for (MngFilesDto dto : mngFiles) {
@@ -178,8 +169,8 @@ public class MapSheetMngService {
Path tfwTargetPath = null;
Path tifTargetPath = null;
Path uploadTargetPath = null;
//파일이 존재하지 않을 경우(0개) 해당년도 다른 파일경로로 참조
if (uploadPath.isEmpty()) {
MngFilesDto filesDto =
mapSheetMngCoreService.findYyyyToMapSheetFilePathRefer(errDto.getMngYyyy());
@@ -189,11 +180,13 @@ public class MapSheetMngService {
tifTargetPath = Paths.get(uploadPath).resolve(tifFile.getOriginalFilename());
}
// String searchDir =
//업로드 경로 확인(없으면 생성)
if( ! FIleChecker.mkDir(uploadPath) )
{
return new DmlReturn("fail", "CREATE FOLDER ERROR");
}
try {
uploadTargetPath = Paths.get(uploadPath);
Files.createDirectories(uploadTargetPath);
Files.move(tfwTmpSavePath, tfwTargetPath, StandardCopyOption.REPLACE_EXISTING);
Files.move(tifTmpSavePath, tifTargetPath, StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
@@ -201,8 +194,13 @@ public class MapSheetMngService {
}
// hst업데이트
mapSheetMngCoreService.updateMapSheetMngHstSyncCheckState(
hstUid, uploadPath, tfwFile.getOriginalFilename(), tifFile.getOriginalFilename());
MapSheetMngDto.SyncCheckStateReqUpdateDto updReqSyncCheckState = new MapSheetMngDto.SyncCheckStateReqUpdateDto();
updReqSyncCheckState.setHstUid(hstUid);
updReqSyncCheckState.setFilePath(uploadPath);
updReqSyncCheckState.setSyncCheckTfwFileName(tfwFile.getOriginalFilename());
updReqSyncCheckState.setSyncCheckTifFileName(tifFile.getOriginalFilename());
updReqSyncCheckState.setSyncCheckState("DONE");
mapSheetMngCoreService.updateMapSheetMngHstSyncCheckState(updReqSyncCheckState);
// 파일정보 업데이트
mapSheetMngCoreService.deleteByHstUidMngFile(hstUid);
@@ -233,8 +231,13 @@ public class MapSheetMngService {
@Transactional
public DmlReturn deleteByFileUidMngFile(List<Long> fileUids) {
long hstUid = 0;
//hstUid = 149049;
for (Long uid : fileUids) {
MapSheetMngDto.MngFilesDto dto = mapSheetMngCoreService.findIdToMapSheetFile(uid);
hstUid = dto.getHstUid();
String filePath = dto.getFilePath() + "/" + dto.getFileName();
Path path = Paths.get(filePath);
try {
@@ -250,6 +253,9 @@ public class MapSheetMngService {
DmlReturn dmlReturn = mapSheetMngCoreService.deleteByFileUidMngFile(uid);
}
//중복제거 확인후 처리상태(DONE)변경
if( hstUid > 0 )mapSheetMngCoreService.updateByHstUidSyncCheckState(hstUid);
return new DmlReturn("success", fileUids.size() + "개 파일이 삭제되었습니다.");
}
}