From dc7ab68fc65ea39bb417360f34209fe724245800 Mon Sep 17 00:00:00 2001 From: nevermoregb Date: Mon, 24 Mar 2025 13:57:43 +0900 Subject: [PATCH] =?UTF-8?q?=EA=B2=8C=EC=8B=9C=ED=8C=90=20=EC=97=90?= =?UTF-8?q?=EB=94=94=ED=84=B0=20=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20=EC=8B=9C=20=ED=8C=8C=EC=9D=BC=20=EC=82=AD=EC=A0=9C?= =?UTF-8?q?=20=EB=B0=8F=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EC=A0=9C=EA=B1=B0?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../company/localhost/common/dto/MapDto.java | 2 + .../common/ImageUploadController.java | 2 +- .../localhost/service/localbordService.java | 37 ++++++++++++++++--- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/main/java/io/company/localhost/common/dto/MapDto.java b/src/main/java/io/company/localhost/common/dto/MapDto.java index 0c36484..4fd9e11 100644 --- a/src/main/java/io/company/localhost/common/dto/MapDto.java +++ b/src/main/java/io/company/localhost/common/dto/MapDto.java @@ -114,6 +114,8 @@ public class MapDto extends ListOrderedMap { result.add(clazz.cast(item)); } else if (clazz.equals(Long.class) && item instanceof Integer) { result.add(clazz.cast(Long.valueOf((Integer) item))); + } else if (clazz.equals(String.class) && item instanceof Integer) { + result.add(clazz.cast(String.valueOf((Integer) item))); } else if (item instanceof Map && clazz.equals(MapDto.class)) { result.add(clazz.cast(new MapDto((Map) item))); } else { diff --git a/src/main/java/io/company/localhost/controller/common/ImageUploadController.java b/src/main/java/io/company/localhost/controller/common/ImageUploadController.java index 5066fb1..0fd8b4d 100644 --- a/src/main/java/io/company/localhost/controller/common/ImageUploadController.java +++ b/src/main/java/io/company/localhost/controller/common/ImageUploadController.java @@ -73,7 +73,7 @@ public class ImageUploadController { Files.write(filePath, file.getBytes()); String fileUrl = "upload/img/board/" + fileName; - long fileIndex = insertUploadEditorImageInfo(fileName, originalFileName, fileUrl, fileExtension, fileSize); + long fileIndex = insertUploadEditorImageInfo(fileName, originalFileName, filePath.toString(), fileExtension, fileSize); MapDto map = new MapDto(); if(fileIndex != 0) map.put("fileIndex", fileIndex); diff --git a/src/main/java/io/company/localhost/service/localbordService.java b/src/main/java/io/company/localhost/service/localbordService.java index 2550762..20baf62 100644 --- a/src/main/java/io/company/localhost/service/localbordService.java +++ b/src/main/java/io/company/localhost/service/localbordService.java @@ -19,6 +19,7 @@ import java.math.BigInteger; import java.util.ArrayList; import java.util.List; import java.util.UUID; +import java.util.stream.Collectors; import org.springframework.http.HttpStatus; import org.springframework.scheduling.annotation.Scheduled; @@ -83,6 +84,7 @@ public class localbordService { } @SuppressWarnings("unchecked") + @Transactional public BigInteger insertBoard(MapDto map) { // 익명게시판이면 회원 정보를 null로 설정 if ("300102".equals(String.valueOf(map.get("LOCBRDTYP")))) { @@ -99,6 +101,13 @@ public class localbordService { map.put("editorImgList", editorUploadedImgList); this.updateBoardIndexToFile(map); } + + // 에디터 수정 시 업로드 된 에디터 이미지 삭제 + if(map.get("editorDeleteImgList") != null) { + ArrayList editorDeleteImgList = (ArrayList) map.getList("editorDeleteImgList", String.class); + String[] array = editorDeleteImgList.stream().toArray(String[]::new); + this.deleteFileAndData(array); + } return (BigInteger) map.get("LOCBRDSEQ"); } @@ -416,12 +425,15 @@ public class localbordService { // 제거 첨부파일 삭제 if(map.get("delFileIdx") != null) { String[] array = String.valueOf(map.get("delFileIdx")).split(","); - List delListInfo = this.selectDelFileInfo(array); // 삭제할 파일 정보 조회 - for(String item : delListInfo) { - fileService.removeFile(item); // 파일 삭제 - } - this.deleteFileInfo(array); // db 데이터 삭제 + this.deleteFileAndData(array); } + + // 에디터 수정 시 업로드 된 에디터 이미지 삭제 + if(map.get("editorDeleteImgList") != null) { + String[] array = String.valueOf(map.get("editorDeleteImgList")).split(","); + this.deleteFileAndData(array); + } + } else { return ApiResponse.error(HttpStatus.INTERNAL_SERVER_ERROR, "게시물이 수정에 실패하였습니다."); } @@ -441,6 +453,19 @@ public class localbordService { private int updateBoardIndexToFile(MapDto map) { return boardMapper.updateBoardIndexToFile(map); } + + /** + * 실제 파일 삭제 및 db 데이터 제거 + * + * @param array + */ + private void deleteFileAndData(String[] array) { + List delListInfo = this.selectDelFileInfo(array); // 삭제할 파일 정보 조회 + for(String item : delListInfo) { + fileService.removeFile(item); // 파일 삭제 + } + this.deleteFileInfo(array); + } /** * 삭제 첨부파일 정보 조회 @@ -530,7 +555,7 @@ public class localbordService { /** * Garbage File Collector */ - @Scheduled(cron = "0 0 2 * * *", zone = "Asia/Seoul") + @Scheduled(cron = "0 0 2 1 * *", zone = "Asia/Seoul") public void deleteTrashFiles() { List list = this.selectFilesBoardIndexIsNull();