파일 업로드 팝업, 중복파일 제거 팝업 기능 적용

This commit is contained in:
DanielLee
2025-12-12 11:03:07 +09:00
parent baf6ca7758
commit a231970903
4 changed files with 179 additions and 98 deletions

View File

@@ -20,6 +20,7 @@ import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
@Service
@RequiredArgsConstructor
@@ -33,24 +34,68 @@ public class MapSheetMngCoreService {
private String activeEnv;
public Page<MapSheetMngDto.ErrorDataDto> findMapSheetErrorList(
MapSheetMngDto.@Valid searchReq searchReq) {
MapSheetMngDto.@Valid searchReq searchReq) {
return mapSheetMngRepository.findMapSheetErrorList(searchReq);
}
public Page<MapSheetMngDto.MngDto> findMapSheetMngList(
MapSheetMngDto.@Valid searchReq searchReq) {
MapSheetMngDto.@Valid searchReq searchReq) {
return mapSheetMngRepository.findMapSheetMngList(searchReq);
}
public MapSheetMngDto.DmlReturn uploadFile(MultipartFile file, Long hstUid) {
MapSheetMngHstEntity entity =
mapSheetMngRepository
.findMapSheetMngHstInfo(hstUid)
.orElseThrow(() -> new EntityNotFoundException("해당 이력이 존재하지 않습니다."));
String localPath = "";
String rootDir = ORIGINAL_IMAGES_PATH + "/" + entity.getMngYyyy();
if ("local".equals(activeEnv)) {
rootDir = localPath + rootDir;
}
try {
Path uploadPath = Paths.get(rootDir);
if (!Files.exists(uploadPath)) {
Files.createDirectories(uploadPath);
}
String originalFilename = file.getOriginalFilename();
if (originalFilename == null) {
throw new IllegalArgumentException("파일명이 없습니다.");
}
Path filePath = uploadPath.resolve(originalFilename);
file.transferTo(filePath);
return new MapSheetMngDto.DmlReturn("success", "파일 업로드 성공");
} catch (IOException e) {
throw new RuntimeException("파일 업로드 실패", e);
}
}
public MapSheetMngDto.DmlReturn deleteFile(MapSheetMngDto.DeleteFileReq req) {
try {
Path filePath = Paths.get(req.getFilePath());
if (Files.deleteIfExists(filePath)) {
return new MapSheetMngDto.DmlReturn("success", "파일 삭제 성공");
} else {
return new MapSheetMngDto.DmlReturn("fail", "파일이 존재하지 않습니다.");
}
} catch (IOException e) {
throw new RuntimeException("파일 삭제 실패", e);
}
}
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));
Optional.ofNullable(
mapSheetMngRepository
.findMapSheetMngHstInfo(hstUid)
.orElseThrow(EntityNotFoundException::new));
// TODO: local TEST 시 각자 경로 수정하기
// TODO: application.yml 에 active profile : local 로 임시 변경하여 테스트
@@ -82,10 +127,10 @@ public class MapSheetMngCoreService {
if (!Objects.isNull(hstUidList) && !hstUidList.isEmpty()) {
for (Long hstUid : hstUidList) {
Optional<MapSheetMngHstEntity> entity =
Optional.ofNullable(
mapSheetMngRepository
.findMapSheetMngHstInfo(hstUid)
.orElseThrow(EntityNotFoundException::new));
Optional.ofNullable(
mapSheetMngRepository
.findMapSheetMngHstInfo(hstUid)
.orElseThrow(EntityNotFoundException::new));
// entity.get().updateUseInference(true);
}
@@ -106,10 +151,10 @@ public class MapSheetMngCoreService {
// 모든 파일명을 Set으로 저장
Set<String> fileNames =
paths
.filter(Files::isRegularFile)
.map(p -> p.getFileName().toString())
.collect(Collectors.toSet());
paths
.filter(Files::isRegularFile)
.map(p -> p.getFileName().toString())
.collect(Collectors.toSet());
// 모든 확장자 파일 존재 여부 확인
for (String ext : extensions) {