파일 업로드 팝업, 중복파일 제거 팝업 기능 적용
This commit is contained in:
@@ -15,7 +15,9 @@ import jakarta.validation.Valid;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
@Tag(name = "영상 관리", description = "영상 관리 API")
|
@Tag(name = "영상 관리", description = "영상 관리 API")
|
||||||
@RestController
|
@RestController
|
||||||
@@ -77,6 +79,21 @@ public class MapSheetMngApiController {
|
|||||||
return ApiResponseDto.ok(mapSheetMngService.mngDataSave(AddReq));
|
return ApiResponseDto.ok(mapSheetMngService.mngDataSave(AddReq));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "파일 업로드", description = "파일 업로드")
|
||||||
|
@PostMapping(value = "/file-upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||||
|
public ApiResponseDto<MapSheetMngDto.DmlReturn> uploadFile(
|
||||||
|
@RequestPart(value = "file") MultipartFile file,
|
||||||
|
@RequestParam(value = "hstUid") Long hstUid) {
|
||||||
|
return ApiResponseDto.ok(mapSheetMngService.uploadFile(file, hstUid));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "파일 삭제", description = "파일 삭제")
|
||||||
|
@PostMapping("/file-delete")
|
||||||
|
public ApiResponseDto<MapSheetMngDto.DmlReturn> deleteFile(
|
||||||
|
@RequestBody @Valid MapSheetMngDto.DeleteFileReq req) {
|
||||||
|
return ApiResponseDto.ok(mapSheetMngService.deleteFile(req));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param hstUidList
|
* @param hstUidList
|
||||||
* @return
|
* @return
|
||||||
|
|||||||
@@ -77,6 +77,16 @@ public class MapSheetMngDto {
|
|||||||
private String mngPath;
|
private String mngPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Schema(name = "DeleteFileReq", description = "파일 삭제 요청")
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public static class DeleteFileReq {
|
||||||
|
@Schema(description = "파일 경로", example = "/app/original-images/2024/00000001.tif")
|
||||||
|
private String filePath;
|
||||||
|
}
|
||||||
|
|
||||||
@Schema(name = "MngDto", description = "영상관리 검색 리턴")
|
@Schema(name = "MngDto", description = "영상관리 검색 리턴")
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import org.apache.commons.io.FilenameUtils;
|
|||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@@ -226,6 +227,14 @@ public class MapSheetMngService {
|
|||||||
return mapSheetMngCoreService.mngDataSave(AddReq);
|
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 MapSheetMngDto.DmlReturn uploadProcess(@Valid List<Long> hstUidList) {
|
public MapSheetMngDto.DmlReturn uploadProcess(@Valid List<Long> hstUidList) {
|
||||||
return mapSheetMngCoreService.uploadProcess(hstUidList);
|
return mapSheetMngCoreService.uploadProcess(hstUidList);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import lombok.RequiredArgsConstructor;
|
|||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@@ -42,6 +43,50 @@ public class MapSheetMngCoreService {
|
|||||||
return mapSheetMngRepository.findMapSheetMngList(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) {
|
public MapSheetMngDto.DmlReturn uploadProcess(@Valid List<Long> hstUidList) {
|
||||||
int count = 0;
|
int count = 0;
|
||||||
if (!Objects.isNull(hstUidList) && !hstUidList.isEmpty()) {
|
if (!Objects.isNull(hstUidList) && !hstUidList.isEmpty()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user