From f726af08aea1ea417cbf5476247bb1f4318d7913 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=EC=84=B1=EC=98=81?= Date: Tue, 30 Sep 2025 14:26:35 +0900 Subject: [PATCH] =?UTF-8?q?=EC=9E=AC=EB=B6=80=EA=B3=BC=20=EC=8B=A0?= =?UTF-8?q?=EA=B7=9C=EB=A1=9C=EC=A7=81=20init?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/egovframework/util/FileUtil.java | 14 ++++--- .../main/controller/CrdnRelevyController.java | 2 +- .../service/impl/CrdnRelevyServiceImpl.java | 41 +++++++++++++++---- src/main/resources/application-dev.yml | 4 +- src/main/resources/application-local.yml | 6 +-- src/main/resources/application-prd.yml | 4 +- .../main/CrdnRelevyMapper_maria.xml | 11 ++--- 7 files changed, 56 insertions(+), 26 deletions(-) diff --git a/src/main/java/egovframework/util/FileUtil.java b/src/main/java/egovframework/util/FileUtil.java index 1886bff..03e21e2 100644 --- a/src/main/java/egovframework/util/FileUtil.java +++ b/src/main/java/egovframework/util/FileUtil.java @@ -647,24 +647,26 @@ public class FileUtil { * @return 복사 성공 여부 * @throws IOException 파일 복사 실패 시 예외 발생 */ - public boolean copyFile(String sourcePath, String targetPath) throws IOException { - if (sourcePath == null || targetPath == null) { + public boolean copyFile(String sourcePath, String uploadDir, String targetPath) throws IOException { + if (sourcePath == null || targetPath == null || uploadDir == null) { throw new IOException("원본 또는 대상 파일 경로가 null입니다."); } - File sourceFile = new File(sourcePath); - File targetFile = new File(targetPath); + File sourceFile = new File(uploadPath + File.separator + sourcePath); + File targetFile = new File(uploadPath + File.separator + targetPath); // 원본 파일 존재 여부 확인 if (!sourceFile.exists()) { - throw new IOException("원본 파일이 존재하지 않습니다: " + sourcePath); + throw new IOException("원본 파일이 존재하지 않습니다: " + uploadPath + File.separator + sourcePath); } // 원본 파일이 일반 파일인지 확인 if (!sourceFile.isFile()) { - throw new IOException("원본이 일반 파일이 아닙니다: " + sourcePath); + throw new IOException("원본이 일반 파일이 아닙니다: " + uploadPath + File.separator + sourcePath); } + createDirectoryIfNotExists( uploadPath + File.separator + uploadDir); + // 대상 디렉토리 생성 File targetDir = targetFile.getParentFile(); if (targetDir != null && !targetDir.exists()) { diff --git a/src/main/java/go/kr/project/crdn/crndRegistAndView/main/controller/CrdnRelevyController.java b/src/main/java/go/kr/project/crdn/crndRegistAndView/main/controller/CrdnRelevyController.java index 5dd1a6a..b236b78 100644 --- a/src/main/java/go/kr/project/crdn/crndRegistAndView/main/controller/CrdnRelevyController.java +++ b/src/main/java/go/kr/project/crdn/crndRegistAndView/main/controller/CrdnRelevyController.java @@ -110,7 +110,7 @@ public class CrdnRelevyController { @ApiResponse(responseCode = "200", description = "성공"), @ApiResponse(responseCode = "400", description = "잘못된 요청") }) - public ResponseEntity saveRelevy(@RequestBody CrdnRelevyVO relevyVO) { + public ResponseEntity saveRelevy(@ModelAttribute CrdnRelevyVO relevyVO) { log.debug("재부과 저장 요청: {}", relevyVO); diff --git a/src/main/java/go/kr/project/crdn/crndRegistAndView/main/service/impl/CrdnRelevyServiceImpl.java b/src/main/java/go/kr/project/crdn/crndRegistAndView/main/service/impl/CrdnRelevyServiceImpl.java index 65f2356..8bb9317 100644 --- a/src/main/java/go/kr/project/crdn/crndRegistAndView/main/service/impl/CrdnRelevyServiceImpl.java +++ b/src/main/java/go/kr/project/crdn/crndRegistAndView/main/service/impl/CrdnRelevyServiceImpl.java @@ -1,6 +1,7 @@ package go.kr.project.crdn.crndRegistAndView.main.service.impl; import egovframework.exception.MessageException; +import egovframework.util.DateUtil; import egovframework.util.FileUtil; import go.kr.project.crdn.crndRegistAndView.main.mapper.CrdnRegistAndViewMapper; import go.kr.project.crdn.crndRegistAndView.main.mapper.CrdnRelevyMapper; @@ -10,9 +11,11 @@ import go.kr.project.crdn.crndRegistAndView.main.service.CrdnRegistAndViewServic import go.kr.project.crdn.crndRegistAndView.main.service.CrdnRelevyService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.io.File; import java.io.IOException; import java.time.LocalDate; import java.time.LocalDateTime; @@ -46,6 +49,15 @@ public class CrdnRelevyServiceImpl implements CrdnRelevyService { private final CrdnRegistAndViewService crdnRegistAndViewService; private final FileUtil fileUtil; + /** 날짜 유틸리티 */ + private final DateUtil dateUtil; + + @Value("${file.upload.sub-dirs.crdn-act-photo}") + String atcFileStorePath; + + @Value("${file.upload.sub-dirs.crdn-actn-photo}") + String atcnFileStorePath; + @Override public CrdnRelevyVO selectCrdnPstnInfoOne(CrdnRelevyVO crdnRelevyVO) { @@ -164,7 +176,7 @@ public class CrdnRelevyServiceImpl implements CrdnRelevyService { private void copyPhysicalFile(CrdnPhotoVO srcPhoto, CrdnRelevyVO relevyVO) { try { // 원본 파일 전체 경로 구성 - String srcFilePath = srcPhoto.getCrdnPhotoPath() + "/" + srcPhoto.getCrdnPhotoNm(); + String srcFilePath = srcPhoto.getCrdnPhotoPath() + File.separator + srcPhoto.getCrdnPhotoNm(); // UUID를 이용한 새로운 저장 파일명 생성 (기존 로직 사용) String fileExt = ""; @@ -174,12 +186,12 @@ public class CrdnRelevyServiceImpl implements CrdnRelevyService { } String newStrgFileNm = UUID.randomUUID() + "." + fileExt; - // 새로운 파일 경로 구성 (동일한 디렉토리 구조 유지) - String newFilePath = srcPhoto.getCrdnPhotoPath(); // 동일한 경로 사용 - String targetFilePath = newFilePath + "/" + newStrgFileNm; + // 신규파일은 새로운 경로에 저장 + String uploadDir = generateUploadDirectoryPath(srcPhoto); + String targetFilePath = uploadDir + File.separator + newStrgFileNm; // 물리적 파일 복사 - boolean copySuccess = fileUtil.copyFile(srcFilePath, targetFilePath); + boolean copySuccess = fileUtil.copyFile(srcFilePath, uploadDir, targetFilePath); if (copySuccess) { // 복사된 파일 정보로 데이터베이스 업데이트 @@ -189,12 +201,11 @@ public class CrdnRelevyServiceImpl implements CrdnRelevyService { updateParams.put("newCrdnNo", relevyVO.getNewCrdnNo()); updateParams.put("crdnPhotoSn", srcPhoto.getCrdnPhotoSn()); updateParams.put("crdnPhotoNm", newStrgFileNm); - + updateParams.put("crdnPhotoPath", uploadDir); int updateResult = relevyMapper.updateRelevyPhotoInfo(updateParams); if (updateResult <= 0) { throw new MessageException("첨부파일 정보 업데이트 실패: " + srcPhoto.getOrgnlPhotoNm()); } - log.debug("파일 복사 성공: {} -> {}", srcFilePath, targetFilePath); } else { throw new MessageException("파일 복사 실패: " + srcPhoto.getOrgnlPhotoNm()); @@ -209,6 +220,22 @@ public class CrdnRelevyServiceImpl implements CrdnRelevyService { } } + // 행위사진, 조치사진 경로 추출 + private String generateUploadDirectoryPath(CrdnPhotoVO srcPhoto) { + String uploadPath = atcFileStorePath; + // 년월 정보 추출 + String yearMonth = dateUtil.getCurrentYearMonth(); + // 년월 디렉토리를 포함한 경로 생성 + String crdnPhotoSeCd = srcPhoto.getCrdnPhotoSeCd(); + if( "1".equals(crdnPhotoSeCd) ){ //행위사진 + uploadPath = atcFileStorePath; + }else if( "2".equals(crdnPhotoSeCd) ){ //조치사진 + uploadPath = atcnFileStorePath; + } + String uploadDir = uploadPath + File.separator + yearMonth; + return uploadDir; + } + /** * 년도별 시퀀스 존재 여부를 확인하고 없으면 생성한다. diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 0baaa36..dcd948e 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -105,8 +105,8 @@ file: bbs-notice: bbs/notice # 공지사항 sample 파일 저장 경로 bbs-post: bbs/post # 게시판 파일 저장 경로 html-editor: common/html_editor # HTML 에디터 파일 저장 경로 - crdn-act-photo: crdn/act # 단속행위 사진 - crdn-actn-photo: crdn/actn # 단속행위 조치 사진 + crdn-act-photo: crdn-act-photo # 단속행위 사진 + crdn-actn-photo: crdn-actn-photo # 단속행위 조치 사진 # Juso API configuration juso: diff --git a/src/main/resources/application-local.yml b/src/main/resources/application-local.yml index 9ecaf1b..c78d05f 100644 --- a/src/main/resources/application-local.yml +++ b/src/main/resources/application-local.yml @@ -71,7 +71,7 @@ server: timeout: 60m # 세션 타임아웃을 60분으로 증가 cookie: http-only: true - secure: true # 개발환경에서는 false, 운영환경에서는 true + secure: false # 개발환경에서는 false, 운영환경에서는 true same-site: lax tracking-modes: cookie @@ -105,8 +105,8 @@ file: bbs-notice: bbs/notice # 공지사항 sample 파일 저장 경로 bbs-post: bbs/post # 게시판 파일 저장 경로 html-editor: common/html_editor # HTML 에디터 파일 저장 경로 - crdn-act-photo: crdn/act # 단속행위 사진 - crdn-actn-photo: crdn/actn # 단속행위 조치 사진 + crdn-act-photo: crdn-act-photo # 단속행위 사진 + crdn-actn-photo: crdn-actn-photo # 단속행위 조치 사진 # Juso API configuration juso: diff --git a/src/main/resources/application-prd.yml b/src/main/resources/application-prd.yml index 68a9ce6..8dc8bd7 100644 --- a/src/main/resources/application-prd.yml +++ b/src/main/resources/application-prd.yml @@ -112,8 +112,8 @@ file: bbs-notice: bbs/notice # 공지사항 sample 파일 저장 경로 bbs-post: bbs/post # 게시판 파일 저장 경로 html-editor: common/html_editor # HTML 에디터 파일 저장 경로 - crdn-act-photo: crdn/act # 단속행위 사진 - crdn-actn-photo: crdn/actn # 단속행위 조치 사진 + crdn-act-photo: crdn-act-photo # 단속행위 사진 + crdn-actn-photo: crdn-actn-photo # 단속행위 조치 사진 # Juso API configuration juso: diff --git a/src/main/resources/mybatis/mapper/crdn/crndRegistAndView/main/CrdnRelevyMapper_maria.xml b/src/main/resources/mybatis/mapper/crdn/crndRegistAndView/main/CrdnRelevyMapper_maria.xml index 6cc7e34..9180ffa 100644 --- a/src/main/resources/mybatis/mapper/crdn/crndRegistAndView/main/CrdnRelevyMapper_maria.xml +++ b/src/main/resources/mybatis/mapper/crdn/crndRegistAndView/main/CrdnRelevyMapper_maria.xml @@ -89,7 +89,7 @@ RELEVY_YN, /* 재부과 여부 - 'Y' */ AGRVTN_LEVY_TRGT_YN, /* 가중 부과 대상 여부 */ CRDN_PRCS_STTS_CD, /* 단속 처리 상태 코드 - 30 (시정명령) */ - CRDN_PRCS_YMD, /* 단속 처리 일자 - 현재 일자 */ + CRDN_PRCS_YMD, /* 단속 처리 일자 */ REG_DT, RGTR, DEL_YN @@ -108,7 +108,7 @@ 'Y', /* 재부과 여부 */ AGRVTN_LEVY_TRGT_YN, '30', /* 시정명령 상태 */ - NOW(), /* 현재 일자 */ + CRDN_PRCS_YMD, /* 단속 처리 일자 */ NOW(), #{rgtr}, 'N' @@ -120,7 +120,7 @@ - / CrdnRelevyMapper.insertCrdnPstnInfo : 위치 정보 복사 / + /* CrdnRelevyMapper.insertCrdnPstnInfo : 위치 정보 복사 */ INSERT INTO tb_pstn_info ( PSTN_INFO_ID, CRDN_YR, @@ -200,9 +200,9 @@ ) SELECT LPAD(NEXTVAL(seq_ownr_info_id), 10, '0'), + SGG_CD, #{newCrdnYr}, #{newCrdnNo}, - SGG_CD, PSTN_INFO_ID, OWNR_ID, NOW(), @@ -398,7 +398,8 @@ /* CrdnRelevyMapper.updateRelevyPhotoInfo : 재부과 첨부파일 정보 업데이트 */ UPDATE tb_crdn_photo - SET CRDN_PHOTO_NM = #{crdnPhotoNm} + SET CRDN_PHOTO_NM = #{crdnPhotoNm}, + CRDN_PHOTO_PATH = #{crdnPhotoPath} WHERE CRDN_YR = #{newCrdnYr} AND CRDN_NO = #{newCrdnNo} AND CRDN_PHOTO_SN = #{crdnPhotoSn}