feat: 관리자 - 팝업 관리 > 특정 글 수정 시, 특정 file 삭제하는 API 추가 건

thkim
thkim 2024-03-18 15:28:38 +09:00
parent ac4625a174
commit 3075d39606
4 changed files with 166 additions and 51 deletions

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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:" +
@ -223,12 +221,46 @@ public class PopUpApiServiceImpl extends EgovAbstractServiceImpl implements PopU
throw new Exception("종료일시는 시작일시보다 앞 설 수 없습니다.");
}
// 기존 첨부된 file이 있다면 기존 fileGrpId을 활용한다.
// 기존 첨부된 file이 있다면 기존 fileGrpId을 활용한다.
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(),
@ -258,12 +290,12 @@ public class PopUpApiServiceImpl extends EgovAbstractServiceImpl implements PopU
@Override
public ResultVO contentsApiPopUpManageDelete(ResultVO resultVO, HttpServletRequest request, LoginVO user, Long popupId) throws Exception {
System.out.println(
"\n--------------------------------------------------------------\n" +
request.getRequestURI() + " IN:" +
"\n--------------------------------------------------------------\n" +
"popupId:" + "\n" +
popupId + "\n" +
"\n--------------------------------------------------------------\n"
"\n--------------------------------------------------------------\n" +
request.getRequestURI() + " IN:" +
"\n--------------------------------------------------------------\n" +
"popupId:" + "\n" +
popupId + "\n" +
"\n--------------------------------------------------------------\n"
);
@ -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;
}
/**
* .

View File

@ -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,41 +77,73 @@ 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);
Map<String, MultipartFile> filesMap = new HashMap<String, MultipartFile>();
filesMap.put("file", file);
List<FileVO> fileVoList = fileUtil.parseFileInf(filesMap, "", 0, middlePath, null);
List<FileVO> fileVoList = fileUtil.parseFileInf(filesMap, "", 0, middlePath, null);
int nCount = 1;
// 업로드된 file을 tnAttachFile에 insert한다.
for (Iterator<FileVO> iter = fileVoList.iterator(); iter.hasNext(); nCount++) {
int nCount = 1;
// 업로드된 file을 tnAttachFile에 insert한다.
for (Iterator<FileVO> iter = fileVoList.iterator(); iter.hasNext(); nCount++) {
FileVO item = iter.next();
FileVO item = iter.next();
tnAttachFileRepository.spAddTnAttachFile(
fileGrpId,
nCount,
item.getOrignlFileNm(),
item.getStreFileNm() + "." + item.getFileExtsn(),
(item.getFileStreCours() + File.separator + item.getAtchFileId()).replaceAll("\\\\", "/"),
Long.parseLong(item.getFileMg()),
item.getFileExtsn(),
ipAddress,
user.getId(),
null,
null,
null
);
tnAttachFileRepository.spAddTnAttachFile(
fileGrpId,
nCount,
item.getOrignlFileNm(),
item.getStreFileNm() + "." + item.getFileExtsn(),
(item.getFileStreCours() + File.separator + item.getAtchFileId()).replaceAll("\\\\", "/"),
Long.parseLong(item.getFileMg()),
item.getFileExtsn(),
ipAddress,
user.getId(),
null,
null,
null
);
}
}
}
}
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);
}
}