TIF,TWF Pari Upload System Update
This commit is contained in:
@@ -2,12 +2,12 @@ package com.kamco.cd.kamcoback.postgres.core;
|
||||
|
||||
import com.kamco.cd.kamcoback.code.dto.CommonCodeDto;
|
||||
import com.kamco.cd.kamcoback.code.dto.CommonCodeDto.Basic;
|
||||
import com.kamco.cd.kamcoback.code.dto.CommonCodeDto.SearchReq;
|
||||
import com.kamco.cd.kamcoback.common.service.BaseCoreService;
|
||||
import com.kamco.cd.kamcoback.config.api.ApiResponseDto.ApiResponseCode;
|
||||
import com.kamco.cd.kamcoback.config.api.ApiResponseDto.ResponseObj;
|
||||
import com.kamco.cd.kamcoback.postgres.entity.CommonCodeEntity;
|
||||
import com.kamco.cd.kamcoback.postgres.repository.code.CommonCodeRepository;
|
||||
import com.kamco.cd.kamcoback.code.dto.CommonCodeDto.SearchReq;
|
||||
import jakarta.persistence.EntityNotFoundException;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -52,10 +52,7 @@ public class MapSheetMngCoreService {
|
||||
.findMapSheetMngHstInfo(hstUid)
|
||||
.orElseThrow(EntityNotFoundException::new));
|
||||
|
||||
// TODO: local TEST 시 각자 경로 수정하기
|
||||
// TODO: application.yml 에 active profile : local 로 임시 변경하여 테스트
|
||||
String localPath = "";
|
||||
// String localPath = "C:\\Users\\gypark\\Desktop\\file";
|
||||
String rootDir = ORIGINAL_IMAGES_PATH + "/" + entity.get().getMngYyyy();
|
||||
if (activeEnv.equals("local")) {
|
||||
rootDir = localPath + rootDir;
|
||||
@@ -68,6 +65,59 @@ public class MapSheetMngCoreService {
|
||||
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;
|
||||
|
||||
@@ -2,7 +2,10 @@ package com.kamco.cd.kamcoback.postgres.core;
|
||||
|
||||
import com.kamco.cd.kamcoback.common.utils.FIleChecker;
|
||||
import com.kamco.cd.kamcoback.mapsheet.dto.ImageryDto;
|
||||
import com.kamco.cd.kamcoback.postgres.entity.MapSheetMngHstEntity;
|
||||
import com.kamco.cd.kamcoback.postgres.repository.mapsheet.MapSheetMngFileCheckerRepository;
|
||||
import com.kamco.cd.kamcoback.postgres.repository.mapsheet.MapSheetMngRepository;
|
||||
import java.util.Optional;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.domain.Page;
|
||||
@@ -13,6 +16,7 @@ import org.springframework.stereotype.Service;
|
||||
public class MapSheetMngFileCheckerCoreService {
|
||||
|
||||
private final MapSheetMngFileCheckerRepository mapSheetMngFileCheckerRepository;
|
||||
private final MapSheetMngRepository mapSheetMngRepository;
|
||||
|
||||
private static final String ORIGINAL_IMAGES_PATH = "/app/original-images";
|
||||
|
||||
@@ -50,4 +54,8 @@ public class MapSheetMngFileCheckerCoreService {
|
||||
|
||||
return new ImageryDto.SyncReturn(flag, syncCnt, tfwErrCnt, tifErrCnt);
|
||||
}
|
||||
|
||||
public Optional<MapSheetMngHstEntity> findHstByUid(Long hstUid) {
|
||||
return mapSheetMngRepository.findMapSheetMngHstInfo(hstUid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +50,4 @@ public class MapSheetMngFileEntity {
|
||||
|
||||
@Column(name = "file_size")
|
||||
private Long fileSize;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -78,4 +78,13 @@ public class MapSheetMngHstEntity extends CommonDateEntity {
|
||||
|
||||
@Column(name = "sync_check_end_dttm")
|
||||
private ZonedDateTime syncCheckEndDttm;
|
||||
|
||||
@Column(name = "tif_size_bytes")
|
||||
private Long tifSizeBytes;
|
||||
|
||||
@Column(name = "tfw_size_bytes")
|
||||
private Long tfwSizeBytes;
|
||||
|
||||
@Column(name = "total_size_bytes")
|
||||
private Long totalSizeBytes;
|
||||
}
|
||||
|
||||
@@ -24,4 +24,6 @@ public interface MapSheetMngRepositoryCustom {
|
||||
|
||||
Page<MapSheetMngDto.ErrorDataDto> findMapSheetErrorList(
|
||||
MapSheetMngDto.@Valid ErrorSearchReq searchReq);
|
||||
|
||||
void updateHstFileSizes(Long hstUid, long tifSizeBytes, long tfwSizeBytes, long totalSizeBytes);
|
||||
}
|
||||
|
||||
@@ -266,6 +266,19 @@ public class MapSheetMngRepositoryImpl extends QuerydslRepositorySupport
|
||||
.fetchOne());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateHstFileSizes(
|
||||
Long hstUid, long tifSizeBytes, long tfwSizeBytes, long totalSizeBytes) {
|
||||
String sql =
|
||||
"UPDATE tb_map_sheet_mng_hst SET tif_size_bytes = :tif, tfw_size_bytes = :tfw, total_size_bytes = :tot WHERE hst_uid = :uid";
|
||||
Query query = (Query) em.createNativeQuery(sql);
|
||||
query.setParameter("tif", tifSizeBytes);
|
||||
query.setParameter("tfw", tfwSizeBytes);
|
||||
query.setParameter("tot", totalSizeBytes);
|
||||
query.setParameter("uid", hstUid);
|
||||
query.executeUpdate();
|
||||
}
|
||||
|
||||
private NumberExpression<Integer> rowNum() {
|
||||
return Expressions.numberTemplate(
|
||||
Integer.class, "row_number() over(order by {0} desc)", mapSheetMngHstEntity.createdDate);
|
||||
|
||||
Reference in New Issue
Block a user