영상관리 수정

This commit is contained in:
Moon
2025-12-26 15:13:27 +09:00
parent a2f2af4282
commit 8ff5ac68f0
6 changed files with 72 additions and 234 deletions

View File

@@ -27,8 +27,6 @@ public class MapSheetMngCoreService {
private final MapSheetMngRepository mapSheetMngRepository;
private static final String ORIGINAL_IMAGES_PATH = "/app/original-images";
@Value("{spring.profiles.active}")
private String activeEnv;
@@ -53,7 +51,6 @@ public class MapSheetMngCoreService {
}
public int findByYearFileNameFileCount(int mngYyyy, String fileName) {
return mapSheetMngRepository.findByYearFileNameFileCount(mngYyyy, fileName);
}
@@ -61,7 +58,6 @@ public class MapSheetMngCoreService {
public MapSheetMngDto.DmlReturn mngFileSave(@Valid MapSheetMngDto.MngFileAddReq addReq) {
mapSheetMngRepository.mngFileSave(addReq);
// int hstCnt = mapSheetMngRepository.insertMapSheetOrgDataToMapSheetMngHst(saved.getMngYyyy());
return new MapSheetMngDto.DmlReturn("success", "파일정보저장되었습니다.");
}
@@ -79,8 +75,8 @@ public class MapSheetMngCoreService {
return mapSheetMngRepository.findMapSheetError(hstUid);
}
public List<MapSheetMngDto.MngFilesDto> findIdToMapSheetFileList(Long hstUid) {
return mapSheetMngRepository.findIdToMapSheetFileList(hstUid);
public List<MapSheetMngDto.MngFilesDto> findByHstUidMapSheetFileList(Long hstUid) {
return mapSheetMngRepository.findByHstUidMapSheetFileList(hstUid);
}
public MapSheetMngDto.MngFilesDto findYyyyToMapSheetFilePathRefer(int mngYyyy) {
@@ -91,91 +87,7 @@ public class MapSheetMngCoreService {
return mapSheetMngRepository.findByFileUidMapSheetFile(fileUid);
}
public MapSheetMngDto.DmlReturn uploadProcess(@Valid List<Long> hstUidList) {
int count = 0;
if (!Objects.isNull(hstUidList) && !hstUidList.isEmpty()) {
for (Long hstUid : hstUidList) {
Optional<MapSheetMngHstEntity> entity =
Optional.ofNullable(
mapSheetMngRepository
.findMapSheetMngHstInfo(hstUid)
.orElseThrow(EntityNotFoundException::new));
String localPath = "";
String rootDir = ORIGINAL_IMAGES_PATH + "/" + entity.get().getMngYyyy();
if (activeEnv.equals("local")) {
rootDir = localPath + rootDir;
}
String filename = entity.get().getMapSheetNum();
String[] extensions = {"tif", "tfw"};
boolean flag = allExtensionsExist(rootDir, filename, extensions);
if (flag) {
count += 1;
}
// 파일 크기 계산 및 저장
try (Stream<Path> paths = Files.walk(Paths.get(rootDir))) {
List<Path> matched =
paths
.filter(Files::isRegularFile)
.filter(
p -> {
String name = p.getFileName().toString();
return name.equals(filename + ".tif") || name.equals(filename + ".tfw");
})
.collect(Collectors.toList());
long tifSize =
matched.stream()
.filter(p -> p.getFileName().toString().endsWith(".tif"))
.mapToLong(
p -> {
try {
return Files.size(p);
} catch (IOException e) {
return 0L;
}
})
.sum();
long tfwSize =
matched.stream()
.filter(p -> p.getFileName().toString().endsWith(".tfw"))
.mapToLong(
p -> {
try {
return Files.size(p);
} catch (IOException e) {
return 0L;
}
})
.sum();
entity.get().setTifSizeBytes(tifSize);
entity.get().setTfwSizeBytes(tfwSize);
entity.get().setTotalSizeBytes(tifSize + tfwSize);
// 엔터티 저장 -> 커스텀 업데이트로 변경
mapSheetMngRepository.updateHstFileSizes(
entity.get().getHstUid(), tifSize, tfwSize, tifSize + tfwSize);
} catch (IOException e) {
// 크기 계산 실패 시 0으로 저장
entity.get().setTifSizeBytes(0L);
entity.get().setTfwSizeBytes(0L);
entity.get().setTotalSizeBytes(0L);
mapSheetMngRepository.updateHstFileSizes(entity.get().getHstUid(), 0L, 0L, 0L);
}
/*
MapSheetMngDto.DataState dataState =
flag ? MapSheetMngDto.DataState.SUCCESS : MapSheetMngDto.DataState.FAIL;
entity.get().updateDataState(dataState);
*/
}
}
return new MapSheetMngDto.DmlReturn("success", count + "개 업로드 성공하였습니다.");
}
public MapSheetMngDto.DmlReturn updateExceptUseInference(@Valid List<Long> hstUidList) {
if (!Objects.isNull(hstUidList) && !hstUidList.isEmpty()) {
@@ -192,40 +104,9 @@ public class MapSheetMngCoreService {
return new MapSheetMngDto.DmlReturn("success", hstUidList.size() + "개 추론제외 업데이트 하였습니다.");
}
/**
* 특정 파일명 + 여러 확장자가 모두 존재하는지 확인
*
* @param rootDir 검색할 최상위 디렉토리
* @param filename 파일명 (확장자 제외)
* @param extensions 확인할 확장자 배열 (예: {"tif", "tfw"})
* @return 모든 확장자가 존재하면 true, 하나라도 없으면 false
*/
public static boolean allExtensionsExist(String rootDir, String filename, String... extensions) {
try (Stream<Path> paths = Files.walk(Paths.get(rootDir))) {
// 모든 파일명을 Set으로 저장
Set<String> fileNames =
paths
.filter(Files::isRegularFile)
.map(p -> p.getFileName().toString())
.collect(Collectors.toSet());
// 모든 확장자 파일 존재 여부 확인
for (String ext : extensions) {
String target = filename + "." + ext;
if (!fileNames.contains(target)) {
return false; // 하나라도 없으면 false
}
}
return true; // 모두 존재하면 true
} catch (IOException e) {
throw new RuntimeException("File search error", e);
}
}
public MapSheetMngDto.DmlReturn mngDataSave(@Valid MapSheetMngDto.AddReq addReq) {
public int mngDataSave(@Valid MapSheetMngDto.AddReq addReq) {
MapSheetMngEntity entity = new MapSheetMngEntity();
entity.setMngYyyy(addReq.getMngYyyy());
@@ -234,10 +115,10 @@ public class MapSheetMngCoreService {
mapSheetMngRepository.deleteByMngYyyyMngAll(addReq.getMngYyyy());
MapSheetMngEntity saved = mapSheetMngRepository.save(entity);
int hstCnt = mapSheetMngRepository.insertMapSheetOrgDataToMapSheetMngHst(saved.getMngYyyy());
int hstCnt = mapSheetMngRepository.insertMapSheetOrgDataToMapSheetMngHst(saved.getMngYyyy(), saved.getMngPath());
mapSheetMngRepository.updateYearState(saved.getMngYyyy(), "DONE");
return new MapSheetMngDto.DmlReturn("success", saved.getMngYyyy().toString());
return hstCnt;
}
public List<MapSheetMngDto.MngFilesDto> findHstUidToMapSheetFileList(Long hstUid) {
@@ -248,37 +129,13 @@ public class MapSheetMngCoreService {
mapSheetMngRepository.deleteByFileUidMngFile(fileUid);
}
public MapSheetMngDto.DmlReturn updateByHstUidSyncCheckState(Long hstUid) {
MapSheetMngDto.SyncCheckStateReqUpdateDto reqDto =
new MapSheetMngDto.SyncCheckStateReqUpdateDto();
reqDto.setHstUid(hstUid);
List<MapSheetMngDto.MngFilesDto> filesDto =
mapSheetMngRepository.findHstUidToMapSheetFileList(hstUid);
for (MapSheetMngDto.MngFilesDto dto : filesDto) {
if (dto.getFileExt().equals("tif")) reqDto.setSyncCheckTifFileName(dto.getFileName());
else if (dto.getFileExt().equals("tfw")) reqDto.setSyncCheckTfwFileName(dto.getFileName());
reqDto.setFilePath(dto.getFilePath());
}
String fileState = "DONE";
if (filesDto.size() > 2) fileState = "DONE";
reqDto.setSyncCheckState(fileState);
public void updateByHstUidSyncCheckState(MapSheetMngDto.SyncCheckStateReqUpdateDto reqDto) {
mapSheetMngRepository.updateMapSheetMngHstSyncCheckState(reqDto);
mapSheetMngRepository.updateByHstUidMngFileState(hstUid, fileState);
return new MapSheetMngDto.DmlReturn("success", hstUid + " : 상태변경되었습니다.");
}
public MapSheetMngDto.DmlReturn updateByFileUidFileState(Long fileUid, String fileState) {
public void updateByFileUidFileState(Long fileUid, String fileState) {
mapSheetMngRepository.updateByFileUidMngFileState(fileUid, fileState);
return new MapSheetMngDto.DmlReturn("success", fileUid + " : 상태변경되었습니다.");
}
public void deleteByNotInFileUidMngFile(Long hstUid, List<Long> fileUids){

View File

@@ -19,7 +19,7 @@ public interface MapSheetMngRepositoryCustom {
Optional<MapSheetMngHstEntity> findMapSheetMngHstInfo(Long hstUid);
int insertMapSheetOrgDataToMapSheetMngHst(int mngYyyy);
int insertMapSheetOrgDataToMapSheetMngHst(int mngYyyy, String mngPath);
List<MapSheetMngDto.MngFilesDto> findHstUidToMapSheetFileList(Long hstUid);
@@ -54,7 +54,7 @@ public interface MapSheetMngRepositoryCustom {
MapSheetMngDto.ErrorDataDto findMapSheetError(Long hstUid);
List<MapSheetMngDto.MngFilesDto> findIdToMapSheetFileList(Long hstUid);
List<MapSheetMngDto.MngFilesDto> findByHstUidMapSheetFileList(Long hstUid);
MapSheetMngDto.MngFilesDto findByFileUidMapSheetFile(Long fileUid);

View File

@@ -448,10 +448,11 @@ public class MapSheetMngRepositoryImpl extends QuerydslRepositorySupport
}
@Override
public List<MapSheetMngDto.MngFilesDto> findIdToMapSheetFileList(Long hstUid) {
public List<MapSheetMngDto.MngFilesDto> findByHstUidMapSheetFileList(Long hstUid) {
BooleanBuilder whereBuilder = new BooleanBuilder();
whereBuilder.and(mapSheetMngFileEntity.hstUid.eq(hstUid));
whereBuilder.and(mapSheetMngFileEntity.fileDel.eq(false));
List<MapSheetMngDto.MngFilesDto> foundContent =
queryFactory
@@ -725,13 +726,14 @@ public class MapSheetMngRepositoryImpl extends QuerydslRepositorySupport
}
@Override
public int insertMapSheetOrgDataToMapSheetMngHst(int mngYyyy) {
public int insertMapSheetOrgDataToMapSheetMngHst(int mngYyyy, String mngPath) {
String sql =
"""
INSERT INTO tb_map_sheet_mng_hst
(
mng_yyyy
,map_sheet_path
,map_sheet_code
,map_sheet_num
,map_sheet_name
@@ -741,14 +743,15 @@ public class MapSheetMngRepositoryImpl extends QuerydslRepositorySupport
,use_inference
)
select
:mngYyyy as mng_yyyy
,fid as map_sheet_code
,mapidcd_no::INTEGER as map_sheet_num
,mapid_nm as map_sheet_name
,fid as map_sheet_code_src
,5000 as scale_ratio
,((mapidcd_no::INTEGER)/1000) as ref_map_sheet_num
,use_inference
:mngYyyy as mng_yyyy,
:mngPath as map_sheet_path,
fid as map_sheet_code,
mapidcd_no as map_sheet_num,
mapid_nm as map_sheet_name,
fid as map_sheet_code_src,
5000 as scale_ratio,
((mapidcd_no::INTEGER)/1000) as ref_map_sheet_num,
use_inference
from
tb_map_inkx_5k
""";
@@ -756,6 +759,7 @@ public class MapSheetMngRepositoryImpl extends QuerydslRepositorySupport
// Native Query 생성 및 실행
Query query = (Query) em.createNativeQuery(sql);
query.setParameter("mngYyyy", mngYyyy);
query.setParameter("mngPath", mngPath);
int exeCnt = query.executeUpdate(); // 실행 (영향받은 행의 개수 반환)