게시판 에디터 이미지 삭제 시 파일 삭제 및 데이터 제거 추가
This commit is contained in:
parent
38d4c401c3
commit
dc7ab68fc6
@ -114,6 +114,8 @@ public class MapDto extends ListOrderedMap {
|
|||||||
result.add(clazz.cast(item));
|
result.add(clazz.cast(item));
|
||||||
} else if (clazz.equals(Long.class) && item instanceof Integer) {
|
} else if (clazz.equals(Long.class) && item instanceof Integer) {
|
||||||
result.add(clazz.cast(Long.valueOf((Integer) item)));
|
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)) {
|
} else if (item instanceof Map && clazz.equals(MapDto.class)) {
|
||||||
result.add(clazz.cast(new MapDto((Map<String, Object>) item)));
|
result.add(clazz.cast(new MapDto((Map<String, Object>) item)));
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -73,7 +73,7 @@ public class ImageUploadController {
|
|||||||
Files.write(filePath, file.getBytes());
|
Files.write(filePath, file.getBytes());
|
||||||
|
|
||||||
String fileUrl = "upload/img/board/" + fileName;
|
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();
|
MapDto map = new MapDto();
|
||||||
if(fileIndex != 0) map.put("fileIndex", fileIndex);
|
if(fileIndex != 0) map.put("fileIndex", fileIndex);
|
||||||
|
|||||||
@ -19,6 +19,7 @@ import java.math.BigInteger;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
@ -83,6 +84,7 @@ public class localbordService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
@Transactional
|
||||||
public BigInteger insertBoard(MapDto map) {
|
public BigInteger insertBoard(MapDto map) {
|
||||||
// 익명게시판이면 회원 정보를 null로 설정
|
// 익명게시판이면 회원 정보를 null로 설정
|
||||||
if ("300102".equals(String.valueOf(map.get("LOCBRDTYP")))) {
|
if ("300102".equals(String.valueOf(map.get("LOCBRDTYP")))) {
|
||||||
@ -99,6 +101,13 @@ public class localbordService {
|
|||||||
map.put("editorImgList", editorUploadedImgList);
|
map.put("editorImgList", editorUploadedImgList);
|
||||||
this.updateBoardIndexToFile(map);
|
this.updateBoardIndexToFile(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 에디터 수정 시 업로드 된 에디터 이미지 삭제
|
||||||
|
if(map.get("editorDeleteImgList") != null) {
|
||||||
|
ArrayList<String> editorDeleteImgList = (ArrayList<String>) map.getList("editorDeleteImgList", String.class);
|
||||||
|
String[] array = editorDeleteImgList.stream().toArray(String[]::new);
|
||||||
|
this.deleteFileAndData(array);
|
||||||
|
}
|
||||||
|
|
||||||
return (BigInteger) map.get("LOCBRDSEQ");
|
return (BigInteger) map.get("LOCBRDSEQ");
|
||||||
}
|
}
|
||||||
@ -416,12 +425,15 @@ public class localbordService {
|
|||||||
// 제거 첨부파일 삭제
|
// 제거 첨부파일 삭제
|
||||||
if(map.get("delFileIdx") != null) {
|
if(map.get("delFileIdx") != null) {
|
||||||
String[] array = String.valueOf(map.get("delFileIdx")).split(",");
|
String[] array = String.valueOf(map.get("delFileIdx")).split(",");
|
||||||
List<String> delListInfo = this.selectDelFileInfo(array); // 삭제할 파일 정보 조회
|
this.deleteFileAndData(array);
|
||||||
for(String item : delListInfo) {
|
|
||||||
fileService.removeFile(item); // 파일 삭제
|
|
||||||
}
|
|
||||||
this.deleteFileInfo(array); // db 데이터 삭제
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 에디터 수정 시 업로드 된 에디터 이미지 삭제
|
||||||
|
if(map.get("editorDeleteImgList") != null) {
|
||||||
|
String[] array = String.valueOf(map.get("editorDeleteImgList")).split(",");
|
||||||
|
this.deleteFileAndData(array);
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return ApiResponse.error(HttpStatus.INTERNAL_SERVER_ERROR, "게시물이 수정에 실패하였습니다.");
|
return ApiResponse.error(HttpStatus.INTERNAL_SERVER_ERROR, "게시물이 수정에 실패하였습니다.");
|
||||||
}
|
}
|
||||||
@ -441,6 +453,19 @@ public class localbordService {
|
|||||||
private int updateBoardIndexToFile(MapDto map) {
|
private int updateBoardIndexToFile(MapDto map) {
|
||||||
return boardMapper.updateBoardIndexToFile(map);
|
return boardMapper.updateBoardIndexToFile(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 실제 파일 삭제 및 db 데이터 제거
|
||||||
|
*
|
||||||
|
* @param array
|
||||||
|
*/
|
||||||
|
private void deleteFileAndData(String[] array) {
|
||||||
|
List<String> delListInfo = this.selectDelFileInfo(array); // 삭제할 파일 정보 조회
|
||||||
|
for(String item : delListInfo) {
|
||||||
|
fileService.removeFile(item); // 파일 삭제
|
||||||
|
}
|
||||||
|
this.deleteFileInfo(array);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 삭제 첨부파일 정보 조회
|
* 삭제 첨부파일 정보 조회
|
||||||
@ -530,7 +555,7 @@ public class localbordService {
|
|||||||
/**
|
/**
|
||||||
* Garbage File Collector
|
* Garbage File Collector
|
||||||
*/
|
*/
|
||||||
@Scheduled(cron = "0 0 2 * * *", zone = "Asia/Seoul")
|
@Scheduled(cron = "0 0 2 1 * *", zone = "Asia/Seoul")
|
||||||
public void deleteTrashFiles() {
|
public void deleteTrashFiles() {
|
||||||
List<FileVo> list = this.selectFilesBoardIndexIsNull();
|
List<FileVo> list = this.selectFilesBoardIndexIsNull();
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user