File Delete Add
This commit is contained in:
@@ -12,7 +12,6 @@ import java.nio.file.Path;
|
|||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
@@ -30,7 +29,8 @@ public class MapSheetMngCoreService {
|
|||||||
|
|
||||||
private static final String ORIGINAL_IMAGES_PATH = "/app/original-images";
|
private static final String ORIGINAL_IMAGES_PATH = "/app/original-images";
|
||||||
|
|
||||||
@Value("{spring.profiles.active}")
|
// Fix: property placeholder syntax
|
||||||
|
@Value("${spring.profiles.active}")
|
||||||
private String activeEnv;
|
private String activeEnv;
|
||||||
|
|
||||||
public Page<MapSheetMngDto.ErrorDataDto> findMapSheetErrorList(
|
public Page<MapSheetMngDto.ErrorDataDto> findMapSheetErrorList(
|
||||||
@@ -62,7 +62,7 @@ public class MapSheetMngCoreService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String originalFilename = file.getOriginalFilename();
|
String originalFilename = file.getOriginalFilename();
|
||||||
if (originalFilename == null) {
|
if (originalFilename == null || originalFilename.isBlank()) {
|
||||||
throw new IllegalArgumentException("파일명이 없습니다.");
|
throw new IllegalArgumentException("파일명이 없습니다.");
|
||||||
}
|
}
|
||||||
Path filePath = uploadPath.resolve(originalFilename);
|
Path filePath = uploadPath.resolve(originalFilename);
|
||||||
@@ -88,54 +88,48 @@ public class MapSheetMngCoreService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public MapSheetMngDto.DmlReturn uploadProcess(@Valid List<Long> hstUidList) {
|
public MapSheetMngDto.DmlReturn uploadProcess(@Valid List<Long> hstUidList) {
|
||||||
int count = 0;
|
if (Objects.isNull(hstUidList) || hstUidList.isEmpty()) {
|
||||||
if (!Objects.isNull(hstUidList) && !hstUidList.isEmpty()) {
|
throw new IllegalArgumentException("처리할 대상이 없습니다.");
|
||||||
|
}
|
||||||
|
int successCount = 0;
|
||||||
|
int failCount = 0;
|
||||||
|
|
||||||
for (Long hstUid : hstUidList) {
|
for (Long hstUid : hstUidList) {
|
||||||
Optional<MapSheetMngHstEntity> entity =
|
MapSheetMngHstEntity hst =
|
||||||
Optional.ofNullable(
|
|
||||||
mapSheetMngRepository
|
mapSheetMngRepository
|
||||||
.findMapSheetMngHstInfo(hstUid)
|
.findMapSheetMngHstInfo(hstUid)
|
||||||
.orElseThrow(EntityNotFoundException::new));
|
.orElseThrow(() -> new EntityNotFoundException("해당 이력이 존재하지 않습니다."));
|
||||||
|
|
||||||
// TODO: local TEST 시 각자 경로 수정하기
|
String localPath = ""; // 필요 시 로컬 테스트 경로 설정
|
||||||
// TODO: application.yml 에 active profile : local 로 임시 변경하여 테스트
|
String rootDir = ORIGINAL_IMAGES_PATH + "/" + hst.getMngYyyy();
|
||||||
String localPath = "";
|
if ("local".equals(activeEnv)) {
|
||||||
// String localPath = "C:\\Users\\gypark\\Desktop\\file";
|
|
||||||
String rootDir = ORIGINAL_IMAGES_PATH + "/" + entity.get().getMngYyyy();
|
|
||||||
if (activeEnv.equals("local")) {
|
|
||||||
rootDir = localPath + rootDir;
|
rootDir = localPath + rootDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
String filename = entity.get().getMapSheetNum();
|
String filename = hst.getMapSheetNum();
|
||||||
String[] extensions = {"tif", "tfw"};
|
String[] extensions = {"tif", "tfw"};
|
||||||
boolean flag = allExtensionsExist(rootDir, filename, extensions);
|
boolean existBoth = allExtensionsExist(rootDir, filename, extensions);
|
||||||
if (flag) {
|
|
||||||
count += 1;
|
String state = existBoth ? "SUCCESS" : "NOT";
|
||||||
|
mapSheetMngRepository.updateUploadProcessResult(hstUid, state);
|
||||||
|
|
||||||
|
if (existBoth) {
|
||||||
|
successCount++;
|
||||||
|
} else {
|
||||||
|
failCount++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
String msg = String.format("업로드 처리 완료: 성공 %d건, 실패 %d건", successCount, failCount);
|
||||||
MapSheetMngDto.DataState dataState =
|
return new MapSheetMngDto.DmlReturn("success", msg);
|
||||||
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) {
|
public MapSheetMngDto.DmlReturn updateExceptUseInference(@Valid List<Long> hstUidList) {
|
||||||
if (!Objects.isNull(hstUidList) && !hstUidList.isEmpty()) {
|
if (Objects.isNull(hstUidList) || hstUidList.isEmpty()) {
|
||||||
for (Long hstUid : hstUidList) {
|
throw new IllegalArgumentException("처리할 대상이 없습니다.");
|
||||||
Optional<MapSheetMngHstEntity> entity =
|
|
||||||
Optional.ofNullable(
|
|
||||||
mapSheetMngRepository
|
|
||||||
.findMapSheetMngHstInfo(hstUid)
|
|
||||||
.orElseThrow(EntityNotFoundException::new));
|
|
||||||
|
|
||||||
// entity.get().updateUseInference(true);
|
|
||||||
}
|
}
|
||||||
}
|
long updated = mapSheetMngRepository.updateExceptUseInference(hstUidList);
|
||||||
return new MapSheetMngDto.DmlReturn("success", hstUidList.size() + "개 추론제외 업데이트 하였습니다.");
|
return new MapSheetMngDto.DmlReturn("success", updated + "개 추론제외 업데이트 하였습니다.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.kamco.cd.kamcoback.postgres.repository.mapsheet;
|
|||||||
import com.kamco.cd.kamcoback.mapsheet.dto.MapSheetMngDto;
|
import com.kamco.cd.kamcoback.mapsheet.dto.MapSheetMngDto;
|
||||||
import com.kamco.cd.kamcoback.postgres.entity.MapSheetMngHstEntity;
|
import com.kamco.cd.kamcoback.postgres.entity.MapSheetMngHstEntity;
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
|
|
||||||
@@ -14,4 +15,14 @@ public interface MapSheetMngRepositoryCustom {
|
|||||||
Page<MapSheetMngDto.MngDto> findMapSheetMngList(MapSheetMngDto.@Valid searchReq searchReq);
|
Page<MapSheetMngDto.MngDto> findMapSheetMngList(MapSheetMngDto.@Valid searchReq searchReq);
|
||||||
|
|
||||||
Optional<MapSheetMngHstEntity> findMapSheetMngHstInfo(Long hstUid);
|
Optional<MapSheetMngHstEntity> findMapSheetMngHstInfo(Long hstUid);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* hstUid 목록에 대해 추론 사용 여부(use_inference)를 'N'으로 업데이트하고 타임스탬프를 기록합니다.
|
||||||
|
*
|
||||||
|
* @return 업데이트된 행 수
|
||||||
|
*/
|
||||||
|
long updateExceptUseInference(List<Long> hstUidList);
|
||||||
|
|
||||||
|
/** 업로드 처리 결과에 따라 data_state를 업데이트합니다. 성공 시 'SUCCESS', 실패 시 'NOT' 등으로 설정합니다. */
|
||||||
|
long updateUploadProcessResult(Long hstUid, String dataState);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import com.querydsl.core.types.dsl.NumberExpression;
|
|||||||
import com.querydsl.core.types.dsl.StringExpression;
|
import com.querydsl.core.types.dsl.StringExpression;
|
||||||
import com.querydsl.jpa.impl.JPAQueryFactory;
|
import com.querydsl.jpa.impl.JPAQueryFactory;
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
|
import java.time.ZonedDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@@ -100,27 +101,6 @@ public class MapSheetMngRepositoryImpl extends QuerydslRepositorySupport
|
|||||||
whereBuilder.and(mapSheetMngEntity.mngYyyy.eq(searchReq.getMngYyyy()));
|
whereBuilder.and(mapSheetMngEntity.mngYyyy.eq(searchReq.getMngYyyy()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
QMapSheetMngEntity m = mapSheetMngEntity;
|
|
||||||
QMapSheetMngHstEntity h = mapSheetMngHstEntity;
|
|
||||||
|
|
||||||
List<MapSheetSummaryDto> summaryContent =
|
|
||||||
queryFactory
|
|
||||||
.select(
|
|
||||||
Projections.constructor(
|
|
||||||
MapSheetSummaryDto.class,
|
|
||||||
mapSheetMngHstEntity.mngYyyy,
|
|
||||||
mapSheetMngHstEntity.mngYyyy.count().as("syncTotCnt"),
|
|
||||||
new CaseBuilder()
|
|
||||||
.when(mapSheetMngHstEntity.syncState.eq("DONE")).then(1L).otherwise(0L)
|
|
||||||
.sum().as("syncStateDoneCnt")
|
|
||||||
))
|
|
||||||
.from(mapSheetMngHstEntity)
|
|
||||||
.groupBy(mapSheetMngHstEntity.mngYyyy) // mng_yyyy 별로 그룹핑
|
|
||||||
.fetch();
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
List<MapSheetMngDto.MngDto> foundContent =
|
List<MapSheetMngDto.MngDto> foundContent =
|
||||||
queryFactory
|
queryFactory
|
||||||
.select(
|
.select(
|
||||||
@@ -192,6 +172,32 @@ public class MapSheetMngRepositoryImpl extends QuerydslRepositorySupport
|
|||||||
.fetchOne());
|
.fetchOne());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long updateExceptUseInference(List<Long> hstUidList) {
|
||||||
|
ZonedDateTime now = ZonedDateTime.now();
|
||||||
|
long affected =
|
||||||
|
queryFactory
|
||||||
|
.update(mapSheetMngHstEntity)
|
||||||
|
.set(mapSheetMngHstEntity.useInference, "N")
|
||||||
|
.set(mapSheetMngHstEntity.useInferenceDttm, now)
|
||||||
|
.where(mapSheetMngHstEntity.hstUid.in(hstUidList))
|
||||||
|
.execute();
|
||||||
|
return affected;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long updateUploadProcessResult(Long hstUid, String dataState) {
|
||||||
|
ZonedDateTime now = ZonedDateTime.now();
|
||||||
|
long affected =
|
||||||
|
queryFactory
|
||||||
|
.update(mapSheetMngHstEntity)
|
||||||
|
.set(mapSheetMngHstEntity.dataState, dataState)
|
||||||
|
.set(mapSheetMngHstEntity.dataStateDttm, now)
|
||||||
|
.where(mapSheetMngHstEntity.hstUid.eq(hstUid))
|
||||||
|
.execute();
|
||||||
|
return affected;
|
||||||
|
}
|
||||||
|
|
||||||
private NumberExpression<Integer> rowNum() {
|
private NumberExpression<Integer> rowNum() {
|
||||||
return Expressions.numberTemplate(
|
return Expressions.numberTemplate(
|
||||||
Integer.class, "row_number() over(order by {0} desc)", mapSheetMngHstEntity.createdDate);
|
Integer.class, "row_number() over(order by {0} desc)", mapSheetMngHstEntity.createdDate);
|
||||||
|
|||||||
Reference in New Issue
Block a user