feat: 관리자 - 팝업 관리 > 특정 글 수정 시, 특정 file 삭제하는 API 추가 건
parent
ac4625a174
commit
3075d39606
|
|
@ -129,6 +129,7 @@ public class PopUpApiController {
|
|||
HttpServletRequest request,
|
||||
@AuthenticationPrincipal LoginVO loginVO,
|
||||
UpdatePopupVO updatePopupVO,
|
||||
@RequestParam(required = false) long[] survivingFiles,
|
||||
@RequestParam(required = false) MultipartFile[] files,
|
||||
@PathVariable("popupId") Long popupId
|
||||
) throws Exception {
|
||||
|
|
@ -136,7 +137,7 @@ public class PopUpApiController {
|
|||
ResultVO resultVO = new ResultVO();
|
||||
|
||||
try {
|
||||
resultVO = popUpApiService.contentsApiPopUpManageUpdate(resultVO, request, loginVO, updatePopupVO, files, popupId);
|
||||
resultVO = popUpApiService.contentsApiPopUpManageUpdate(resultVO, request, loginVO, updatePopupVO, files, survivingFiles, popupId);
|
||||
} catch (Exception e) {
|
||||
resultVO.setResultCode(ResponseCode.FAILED.getCode());
|
||||
resultVO.setResultMessage(e.getMessage());
|
||||
|
|
@ -233,7 +234,6 @@ public class PopUpApiController {
|
|||
);
|
||||
|
||||
return resultVO;
|
||||
|
||||
}
|
||||
|
||||
@Operation(
|
||||
|
|
@ -273,6 +273,43 @@ public class PopUpApiController {
|
|||
return resultVO;
|
||||
}
|
||||
|
||||
@Operation(
|
||||
summary = "팝업 관리에서 특정 첨부 파일을 삭제하는 API",
|
||||
description = "관리자 단에서 '컨텐츠 관리' > '팝업 관리' 페이지에서 특정 팝업 수정 후 첨부된 file 삭제하는 API.",
|
||||
tags = {"PopUpApiController"}
|
||||
)
|
||||
@ApiResponses(value = {
|
||||
@ApiResponse(responseCode = "200", description = "등록 성공"),
|
||||
@ApiResponse(responseCode = "403", description = "인가된 사용자가 아님"),
|
||||
})
|
||||
@DeleteMapping(value = "/contents/api/popup-manage/file/{fileSeq}")
|
||||
public ResultVO deleteFileContentsApiPopUpManage
|
||||
(
|
||||
@AuthenticationPrincipal LoginVO user,
|
||||
HttpServletRequest request,
|
||||
@PathVariable("fileSeq") Long fileSeq
|
||||
) throws Exception {
|
||||
|
||||
ResultVO resultVO = new ResultVO();
|
||||
try {
|
||||
resultVO = popUpApiService.deleteFileContentsApiPopUpManage(resultVO, request, user, fileSeq);
|
||||
} catch (Exception e) {
|
||||
resultVO.setResultCode(ResponseCode.FAILED.getCode());
|
||||
resultVO.setResultMessage(e.getMessage());
|
||||
}
|
||||
|
||||
System.out.println(
|
||||
"\n--------------------------------------------------------------\n" +
|
||||
request.getRequestURI() + " OUT:" +
|
||||
"\n--------------------------------------------------------------\n" +
|
||||
"resultVO.toString():" + "\n" +
|
||||
resultVO.toString() + "\n" +
|
||||
"\n--------------------------------------------------------------\n"
|
||||
);
|
||||
|
||||
return resultVO;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@ public interface PopUpApiService {
|
|||
public ResultVO contentsApiPopUpManageList(ResultVO resultVO, HttpServletRequest request, LoginVO user, Pageable pageable) throws Exception;
|
||||
public ResultVO contentsApiPopUpManageCreate(ResultVO resultVO, HttpServletRequest request, LoginVO user, final MultipartHttpServletRequest multiRequest, CreatePopupVO createPopupVO, MultipartFile[] files) throws Exception;
|
||||
public ResultVO contentsApiPopUpManageRead(ResultVO resultVO, HttpServletRequest request, LoginVO user, Long popupSeq) throws Exception;
|
||||
public ResultVO contentsApiPopUpManageUpdate(ResultVO resultVO, HttpServletRequest request, LoginVO user, UpdatePopupVO updatePopupVO, MultipartFile[] files, Long popupSeq) throws Exception;
|
||||
public ResultVO contentsApiPopUpManageUpdate(ResultVO resultVO, HttpServletRequest request, LoginVO user, UpdatePopupVO updatePopupVO, MultipartFile[] files, long[] survivingFiles, Long popupSeq) throws Exception;
|
||||
public ResultVO contentsApiPopUpManageDelete(ResultVO resultVO, HttpServletRequest request, LoginVO user, Long popupSeq) throws Exception;
|
||||
public ResultVO contentsApiPopUpManageUpdateActivationSwitch(ResultVO resultVO, HttpServletRequest request, LoginVO user, String checked, Long popupSeq) throws Exception;
|
||||
|
||||
public ResultVO deleteFileContentsApiPopUpManage(ResultVO resultVO, HttpServletRequest request, LoginVO user, Long fileSeq) throws Exception;
|
||||
}
|
||||
|
|
@ -40,8 +40,6 @@ public class PopUpApiServiceImpl extends EgovAbstractServiceImpl implements PopU
|
|||
private final TnPopupMngRepository tnPopupMngRepository;
|
||||
private final TnPopupMngRepositoryWithoutPopupContents tnPopupMngRepositoryWithoutPopupContents;
|
||||
|
||||
private final TnAttachFileRepository tnAttachFileRepository;
|
||||
|
||||
private final FileService fileService;
|
||||
|
||||
|
||||
|
|
@ -173,7 +171,7 @@ public class PopUpApiServiceImpl extends EgovAbstractServiceImpl implements PopU
|
|||
dto.put("schdulEndde", tnPopupMng.getPopupEndDate().plusHours(9).format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"))); // 날짜/시간의 종료 일시 - yyyyMMddHHmmss
|
||||
|
||||
//첨부파일명을 가져온다.
|
||||
List<TnAttachFile> tnAttachFileList = tnAttachFileRepository.findByFileGrpId(tnPopupMng.getFileGrpId()).orElse(null);
|
||||
List<TnAttachFile> tnAttachFileList = fileService.findByFileGrpId(tnPopupMng.getFileGrpId());
|
||||
|
||||
if( tnAttachFileList != null ) {
|
||||
List<Map<String, Object>> files = new ArrayList<Map<String, Object>>();
|
||||
|
|
@ -200,7 +198,7 @@ public class PopUpApiServiceImpl extends EgovAbstractServiceImpl implements PopU
|
|||
}
|
||||
|
||||
@Override
|
||||
public ResultVO contentsApiPopUpManageUpdate(ResultVO resultVO, HttpServletRequest request, LoginVO user, UpdatePopupVO updatePopupVO, MultipartFile[] files, Long popupSeq) throws Exception {
|
||||
public ResultVO contentsApiPopUpManageUpdate(ResultVO resultVO, HttpServletRequest request, LoginVO user, UpdatePopupVO updatePopupVO, MultipartFile[] files, long[] survivingFiles, Long popupSeq) throws Exception {
|
||||
System.out.println(
|
||||
"\n--------------------------------------------------------------\n" +
|
||||
request.getRequestURI() + " IN:" +
|
||||
|
|
@ -227,8 +225,42 @@ public class PopUpApiServiceImpl extends EgovAbstractServiceImpl implements PopU
|
|||
TnPopupMng tnPopupMng = tnPopupMngRepository.findByPopupSeq(popupSeq);
|
||||
|
||||
String fileGrpId = tnPopupMng.getFileGrpId();
|
||||
List<TnAttachFile> tnAttachFileList = fileService.findByFileGrpId(tnPopupMng.getFileGrpId());
|
||||
|
||||
if( survivingFiles == null ) {
|
||||
|
||||
//기존 file을 모두 삭제한다.
|
||||
if( fileGrpId != null ) {
|
||||
if( tnAttachFileList != null ) {
|
||||
for (TnAttachFile item : tnAttachFileList) {
|
||||
fileService.deleteTnAttachFile(request, user, item.getFileSeq().longValue());
|
||||
}
|
||||
}
|
||||
fileGrpId = null;
|
||||
}
|
||||
} else {
|
||||
// 살아남은 file을 제외한 나머지 file을 삭제한다.
|
||||
if( tnAttachFileList != null ) {
|
||||
boolean isFound = false;
|
||||
for (TnAttachFile item : tnAttachFileList) {
|
||||
for( long oldFileSeq : survivingFiles) {
|
||||
if( oldFileSeq == item.getFileSeq() ) {
|
||||
isFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( !isFound ) {
|
||||
fileService.deleteTnAttachFile(request, user, item.getFileSeq().longValue());
|
||||
}
|
||||
isFound = false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fileGrpId = fileService.addTnAttachFile(request, user, files, this.getMiddlePath(), fileGrpId);
|
||||
|
||||
|
||||
Map<String, Object> response = tnPopupMngRepository.spUpdateTnPopupMng(
|
||||
popupSeq.intValue(),
|
||||
updatePopupVO.getTitle(),
|
||||
|
|
@ -338,6 +370,28 @@ public class PopUpApiServiceImpl extends EgovAbstractServiceImpl implements PopU
|
|||
return resultVO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultVO deleteFileContentsApiPopUpManage(ResultVO resultVO, HttpServletRequest request, LoginVO user, Long fileSeq) throws Exception {
|
||||
System.out.println(
|
||||
"\n--------------------------------------------------------------\n" +
|
||||
request.getRequestURI() + " IN:" +
|
||||
"\n--------------------------------------------------------------\n" +
|
||||
"fileSeq:" + "\n" +
|
||||
fileSeq + "\n" +
|
||||
"\n--------------------------------------------------------------\n"
|
||||
);
|
||||
|
||||
Map<String, Object> dto = new HashMap<String, Object>();
|
||||
|
||||
fileService.deleteTnAttachFile(request, user, fileSeq);
|
||||
|
||||
resultVO.setResult(dto);
|
||||
resultVO.setResultCode(ResponseCode.SUCCESS.getCode());
|
||||
resultVO.setResultMessage(ResponseCode.SUCCESS.getMessage());
|
||||
|
||||
return resultVO;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 파일이 저장될 중간 경로를 생성한다.
|
||||
|
|
|
|||
|
|
@ -42,18 +42,6 @@ public class FileService {
|
|||
|
||||
|
||||
|
||||
/**
|
||||
* TN_ATTACH_FILE table에 insert 후, 파일 그룹 ID를 return 한다.
|
||||
* TN_ATTACH_FILE 참고.
|
||||
* @param request
|
||||
* @param user
|
||||
* @param files
|
||||
* @param middlePath 파일이 저장될 중간 경로다.
|
||||
* D:/kcscUploadFiles/XXXX/abc.jpg XXXX에 해당하는 경로다.
|
||||
* 참고로 D:/kcscUploadFiles 값은 application-xxx.properties에 있는 Globals.fileStorePath를 통해 얻는다.
|
||||
* @return 파일 그룹 ID
|
||||
* @throws Exception
|
||||
*/
|
||||
public String addTnAttachFile(HttpServletRequest request, LoginVO user, MultipartFile[] files, String middlePath) throws Exception {
|
||||
return this.addTnAttachFile(request, user, files, middlePath, null);
|
||||
}
|
||||
|
|
@ -76,6 +64,10 @@ public class FileService {
|
|||
* @throws Exception
|
||||
*/
|
||||
public String addTnAttachFile(HttpServletRequest request, LoginVO user, MultipartFile[] files, String middlePath, String fileGrpId) throws Exception {
|
||||
|
||||
if( files == null ) {
|
||||
return fileGrpId;
|
||||
}
|
||||
String ipAddress = NetworkUtil.getClientIpAddress(request);
|
||||
|
||||
|
||||
|
|
@ -85,7 +77,8 @@ public class FileService {
|
|||
}
|
||||
|
||||
|
||||
for (MultipartFile file : files) {if( file != null && !file.isEmpty()) {
|
||||
for (MultipartFile file : files) {
|
||||
if( file != null && !file.isEmpty()) {
|
||||
|
||||
Map<String, MultipartFile> filesMap = new HashMap<String, MultipartFile>();
|
||||
filesMap.put("file", file);
|
||||
|
|
@ -118,8 +111,39 @@ public class FileService {
|
|||
}
|
||||
|
||||
|
||||
|
||||
return fileGrpId;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 특정 파일 하나를 삭제한다.
|
||||
* @param request
|
||||
* @param user
|
||||
* @param fileSeq
|
||||
* @return 삭제 성공 시, true. 실패 시, 예외
|
||||
* @throws Exception 예외
|
||||
*/
|
||||
public boolean deleteTnAttachFile(HttpServletRequest request, LoginVO user, Long fileSeq) throws Exception {
|
||||
|
||||
//파일을 삭제한다.
|
||||
|
||||
TnAttachFile tnAttachFile = tnAttachFileRepository.findById(fileSeq.intValue()).orElse(null);
|
||||
|
||||
if( tnAttachFile == null ) {
|
||||
throw new Exception("대상이 존재하지 않습니다.");
|
||||
}
|
||||
|
||||
String fileFullPath = tnAttachFile.getFilePath() + tnAttachFile.getFileNewName();
|
||||
|
||||
File file = new File(fileFullPath);
|
||||
file.delete();
|
||||
|
||||
tnAttachFileRepository.deleteById(fileSeq.intValue());
|
||||
return true;
|
||||
}
|
||||
|
||||
public List<TnAttachFile> findByFileGrpId(String fileGrpId) throws Exception {
|
||||
return tnAttachFileRepository.findByFileGrpId(fileGrpId).orElse(null);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue