|
|
|
|
@ -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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 년도별 시퀀스 존재 여부를 확인하고 없으면 생성한다.
|
|
|
|
|
|