From 44b2507d993ef5a56ca1962870efa11c3ecb7723 Mon Sep 17 00:00:00 2001 From: thkim Date: Mon, 18 Mar 2024 10:41:07 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EA=B4=80=EB=A6=AC=EC=9E=90=20-=20?= =?UTF-8?q?=ED=8C=9D=EC=97=85=20=EA=B4=80=EB=A6=AC=20>=20=ED=8A=B9?= =?UTF-8?q?=EC=A0=95=20=EA=B8=80=20=EC=88=98=EC=A0=95=20=EC=8B=9C,=20?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20=EC=97=AC=EB=9F=AC=EA=B0=9C=20=EC=9D=BC=20?= =?UTF-8?q?=EA=B2=BD=EC=9A=B0=20=ED=8C=8C=EC=9D=BC=20=EB=AA=A9=EB=A1=9D?= =?UTF-8?q?=EC=9D=B4=20=EC=95=88=20=EB=82=98=ED=83=80=EB=82=98=EB=8A=94=20?= =?UTF-8?q?=EB=AC=B8=EC=A0=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../popUp/controller/PopUpApiController.java | 8 +- .../popUp/service/PopUpApiService.java | 10 +-- .../service/impl/PopUpApiServiceImpl.java | 43 +++++++---- .../repository/TnAttachFileRepository.java | 3 +- .../kcscbackend/file/service/FileService.java | 74 ++++++++++++------- 5 files changed, 89 insertions(+), 49 deletions(-) diff --git a/kcsc-back-end/src/main/java/com/dbnt/kcscbackend/admin/contents/popUp/controller/PopUpApiController.java b/kcsc-back-end/src/main/java/com/dbnt/kcscbackend/admin/contents/popUp/controller/PopUpApiController.java index 5e25e94..acb0b56 100644 --- a/kcsc-back-end/src/main/java/com/dbnt/kcscbackend/admin/contents/popUp/controller/PopUpApiController.java +++ b/kcsc-back-end/src/main/java/com/dbnt/kcscbackend/admin/contents/popUp/controller/PopUpApiController.java @@ -88,13 +88,13 @@ public class PopUpApiController { @AuthenticationPrincipal LoginVO loginVO, final MultipartHttpServletRequest multiRequest, CreatePopupVO createPopupVO, - @RequestParam(required = false) MultipartFile file + @RequestParam(required = false) MultipartFile[] files ) throws Exception { ResultVO resultVO = new ResultVO(); try { - resultVO = popUpApiService.contentsApiPopUpManageCreate(resultVO, request, loginVO, multiRequest, createPopupVO, file); + resultVO = popUpApiService.contentsApiPopUpManageCreate(resultVO, request, loginVO, multiRequest, createPopupVO, files); } catch (Exception e) { resultVO.setResultCode(ResponseCode.FAILED.getCode()); resultVO.setResultMessage(e.getMessage()); @@ -129,14 +129,14 @@ public class PopUpApiController { HttpServletRequest request, @AuthenticationPrincipal LoginVO loginVO, UpdatePopupVO updatePopupVO, - @RequestParam(required = false) MultipartFile file, + @RequestParam(required = false) MultipartFile[] files, @PathVariable("popupId") Long popupId ) throws Exception { ResultVO resultVO = new ResultVO(); try { - resultVO = popUpApiService.contentsApiPopUpManageUpdate(resultVO, request, loginVO, updatePopupVO, file, popupId); + resultVO = popUpApiService.contentsApiPopUpManageUpdate(resultVO, request, loginVO, updatePopupVO, files, popupId); } catch (Exception e) { resultVO.setResultCode(ResponseCode.FAILED.getCode()); resultVO.setResultMessage(e.getMessage()); diff --git a/kcsc-back-end/src/main/java/com/dbnt/kcscbackend/admin/contents/popUp/service/PopUpApiService.java b/kcsc-back-end/src/main/java/com/dbnt/kcscbackend/admin/contents/popUp/service/PopUpApiService.java index e01f810..c621b66 100644 --- a/kcsc-back-end/src/main/java/com/dbnt/kcscbackend/admin/contents/popUp/service/PopUpApiService.java +++ b/kcsc-back-end/src/main/java/com/dbnt/kcscbackend/admin/contents/popUp/service/PopUpApiService.java @@ -16,10 +16,10 @@ import javax.servlet.http.HttpServletRequest; 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 file) throws Exception; - public ResultVO contentsApiPopUpManageRead(ResultVO resultVO, HttpServletRequest request, LoginVO user, Long popupId) throws Exception; - public ResultVO contentsApiPopUpManageUpdate(ResultVO resultVO, HttpServletRequest request, LoginVO user, UpdatePopupVO updatePopupVO, MultipartFile file, Long popupId) throws Exception; - public ResultVO contentsApiPopUpManageDelete(ResultVO resultVO, HttpServletRequest request, LoginVO user, Long popupId) throws Exception; - public ResultVO contentsApiPopUpManageUpdateActivationSwitch(ResultVO resultVO, HttpServletRequest request, LoginVO user, String checked, Long popupId) 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 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; } \ No newline at end of file diff --git a/kcsc-back-end/src/main/java/com/dbnt/kcscbackend/admin/contents/popUp/service/impl/PopUpApiServiceImpl.java b/kcsc-back-end/src/main/java/com/dbnt/kcscbackend/admin/contents/popUp/service/impl/PopUpApiServiceImpl.java index b174159..202b52e 100644 --- a/kcsc-back-end/src/main/java/com/dbnt/kcscbackend/admin/contents/popUp/service/impl/PopUpApiServiceImpl.java +++ b/kcsc-back-end/src/main/java/com/dbnt/kcscbackend/admin/contents/popUp/service/impl/PopUpApiServiceImpl.java @@ -103,7 +103,7 @@ public class PopUpApiServiceImpl extends EgovAbstractServiceImpl implements PopU @Override - public ResultVO contentsApiPopUpManageCreate(ResultVO resultVO, HttpServletRequest request, LoginVO user, final MultipartHttpServletRequest multiRequest, CreatePopupVO createPopupVO, MultipartFile file) throws Exception { + public ResultVO contentsApiPopUpManageCreate(ResultVO resultVO, HttpServletRequest request, LoginVO user, final MultipartHttpServletRequest multiRequest, CreatePopupVO createPopupVO, MultipartFile[] files) throws Exception { System.out.println( "\n--------------------------------------------------------------\n" + @@ -115,7 +115,7 @@ public class PopUpApiServiceImpl extends EgovAbstractServiceImpl implements PopU ); - String fileGrpId = fileService.addTnAttachFile(request, user, file, this.getMiddlePath()); + String fileGrpId = fileService.addTnAttachFile(request, user, files, this.getMiddlePath()); Map response = tnPopupMngRepository.spAddTnPopupMng( createPopupVO.getTitle(), @@ -173,14 +173,25 @@ public class PopUpApiServiceImpl extends EgovAbstractServiceImpl implements PopU dto.put("schdulEndde", tnPopupMng.getPopupEndDate().plusHours(9).format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"))); // 날짜/시간의 종료 일시 - yyyyMMddHHmmss //첨부파일명을 가져온다. - TnAttachFile tnAttachFile = tnAttachFileRepository.findByFileGrpId(tnPopupMng.getFileGrpId()).orElse(null); + List tnAttachFileList = tnAttachFileRepository.findByFileGrpId(tnPopupMng.getFileGrpId()).orElse(null); - if( tnAttachFile != null ) { - dto.put("fileName", tnAttachFile.getFileOldName()); + if( tnAttachFileList != null ) { + List> files = new ArrayList>(); + for (TnAttachFile item : tnAttachFileList) { + Map fileDto = new HashMap(); + fileDto.put("seq", item.getFileSeq()); + fileDto.put("name", item.getFileOldName()); + files.add(fileDto); + } + dto.put("files", files); } else { - dto.put("fileName", null); + dto.put("files", null); } + + + + resultVO.setResult(dto); resultVO.setResultCode(ResponseCode.SUCCESS.getCode()); resultVO.setResultMessage(ResponseCode.SUCCESS.getMessage()); @@ -189,33 +200,37 @@ public class PopUpApiServiceImpl extends EgovAbstractServiceImpl implements PopU } @Override - public ResultVO contentsApiPopUpManageUpdate(ResultVO resultVO, HttpServletRequest request, LoginVO user, UpdatePopupVO updatePopupVO, MultipartFile file, Long popupId) throws Exception { + public ResultVO contentsApiPopUpManageUpdate(ResultVO resultVO, HttpServletRequest request, LoginVO user, UpdatePopupVO updatePopupVO, MultipartFile[] files, Long popupSeq) throws Exception { System.out.println( "\n--------------------------------------------------------------\n" + request.getRequestURI() + " IN:" + "\n--------------------------------------------------------------\n" + "updatePopupVO:" + "\n" + updatePopupVO.toString() + "\n" + - "popupId:" + "\n" + - popupId + "\n" + + "popupSeq:" + "\n" + + popupSeq + "\n" + "\n--------------------------------------------------------------\n" ); // 유효성 검사 실시 - int isValid = tnPopupMngRepository.spIsValidTnPopupMngId( popupId.intValue() ); + int isValid = tnPopupMngRepository.spIsValidTnPopupMngId( popupSeq.intValue() ); if( isValid == 0 ) { throw new Exception("대상이 존재하지 않습니다."); } - if( Long.parseLong(updatePopupVO.getStartDate()) > Long.parseLong(updatePopupVO.getEndDate()) ) { + if( Long.parseLong(updatePopupVO.getStartDate()) > Long.parseLong(updatePopupVO.getEndDate()) ) { throw new Exception("종료일시는 시작일시보다 앞 설 수 없습니다."); } - String fileGrpId = fileService.addTnAttachFile(request, user, file, this.getMiddlePath()); + // 기존 첨부된 file이 있다면 기존 fileGrpId을 활용한다. + TnPopupMng tnPopupMng = tnPopupMngRepository.findByPopupSeq(popupSeq); + + String fileGrpId = tnPopupMng.getFileGrpId(); + fileGrpId = fileService.addTnAttachFile(request, user, files, this.getMiddlePath(), fileGrpId); Map response = tnPopupMngRepository.spUpdateTnPopupMng( - popupId.intValue(), + popupSeq.intValue(), updatePopupVO.getTitle(), updatePopupVO.getStartDate(), updatePopupVO.getEndDate(), @@ -230,7 +245,7 @@ public class PopUpApiServiceImpl extends EgovAbstractServiceImpl implements PopU Map dto = new HashMap(); dto.put("errorMessage", response.get("_error_message") ); - dto.put("popupId", popupId); + dto.put("popupId", popupSeq); resultVO.setResult(dto); resultVO.setResultCode(ResponseCode.SUCCESS.getCode()); diff --git a/kcsc-back-end/src/main/java/com/dbnt/kcscbackend/file/repository/TnAttachFileRepository.java b/kcsc-back-end/src/main/java/com/dbnt/kcscbackend/file/repository/TnAttachFileRepository.java index 9584ded..1b5c577 100644 --- a/kcsc-back-end/src/main/java/com/dbnt/kcscbackend/file/repository/TnAttachFileRepository.java +++ b/kcsc-back-end/src/main/java/com/dbnt/kcscbackend/file/repository/TnAttachFileRepository.java @@ -6,12 +6,13 @@ import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.query.Procedure; import org.springframework.data.repository.query.Param; +import java.util.List; import java.util.Map; import java.util.Optional; public interface TnAttachFileRepository extends JpaRepository { - Optional findByFileGrpId(String fileGrpId); + Optional> findByFileGrpId(String fileGrpId); @Procedure("make_file_grp_id") String makeFileGrpId( String modiId ); diff --git a/kcsc-back-end/src/main/java/com/dbnt/kcscbackend/file/service/FileService.java b/kcsc-back-end/src/main/java/com/dbnt/kcscbackend/file/service/FileService.java index 3da38f8..78d6c9d 100644 --- a/kcsc-back-end/src/main/java/com/dbnt/kcscbackend/file/service/FileService.java +++ b/kcsc-back-end/src/main/java/com/dbnt/kcscbackend/file/service/FileService.java @@ -13,10 +13,7 @@ import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import java.io.File; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; +import java.util.*; @Service @RequiredArgsConstructor @@ -32,7 +29,7 @@ public class FileService { if(tnAttachFile.getFileSeq()!=null){ tnAttachFile = tnAttachFileRepository.findById(tnAttachFile.getFileSeq()).orElse(null); }else{ - tnAttachFile = tnAttachFileRepository.findByFileGrpId(tnAttachFile.getFileGrpId()).orElse(null); + tnAttachFile = Objects.requireNonNull(tnAttachFileRepository.findByFileGrpId(tnAttachFile.getFileGrpId()).orElse(null)).get(0); } int downCnt = tnAttachFile.getDownCnt()==null?0: tnAttachFile.getDownCnt(); tnAttachFile.setDownCnt(downCnt+1); @@ -50,50 +47,77 @@ public class FileService { * TN_ATTACH_FILE 참고. * @param request * @param user - * @param file + * @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); + } + public String addTnAttachFile(HttpServletRequest request, LoginVO user, MultipartFile file, String middlePath) throws Exception { + MultipartFile[] files = new MultipartFile[1]; + return this.addTnAttachFile(request, user, files, middlePath); + } + + /** + * 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, String fileGrpId) throws Exception { String ipAddress = NetworkUtil.getClientIpAddress(request); - String fileGrpId = null; - if( file != null && !file.isEmpty()) { + + if( fileGrpId == null || fileGrpId.trim().isEmpty()) { + //String fileGrpId = UUID.randomUUID().toString(); + fileGrpId = tnAttachFileRepository.makeFileGrpId(user.getId()); + } + + + for (MultipartFile file : files) {if( file != null && !file.isEmpty()) { Map filesMap = new HashMap(); filesMap.put("file", file); - //String fileGrpId = UUID.randomUUID().toString(); - fileGrpId = tnAttachFileRepository.makeFileGrpId(user.getId()); - - List files = fileUtil.parseFileInf(filesMap, "", 0, middlePath, null); + List fileVoList = fileUtil.parseFileInf(filesMap, "", 0, middlePath, null); int nCount = 1; // 업로드된 file을 tnAttachFile에 insert한다. - for (Iterator iter = files.iterator(); iter.hasNext(); nCount++) { + for (Iterator iter = fileVoList.iterator(); iter.hasNext(); nCount++) { 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 + 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; }