refactor : 차세대 파일 연계 메소드 위치 변경

main
이범준 1 year ago
parent 996c4b473b
commit f922ed7968

@ -15,6 +15,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import cokr.xit.foundation.component.AbstractServiceBean; import cokr.xit.foundation.component.AbstractServiceBean;
import kr.xit.fims.biz.cmm.service.FimsCrackdownMgtService; import kr.xit.fims.biz.cmm.service.FimsCrackdownMgtService;
import kr.xit.fims.biz.ec.util.NextGenInterfaceUtils;
import kr.xit.fims.framework.biz.cmm.service.XitFrameCodeService; import kr.xit.fims.framework.biz.cmm.service.XitFrameCodeService;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.ibatis.session.RowBounds; import org.apache.ibatis.session.RowBounds;
@ -416,7 +417,7 @@ public class FimsCrackdownMgtServiceBean extends AbstractServiceBean implements
.infKey(param.getExtnlInterfaceId()) .infKey(param.getExtnlInterfaceId())
.build()); .build());
NtriDTO.PhotoFileError errDTO = ExtnlInterfaceUtils.makeNtriInterfacePhotoZip( NtriDTO.PhotoFileError errDTO = NextGenInterfaceUtils.makeNtriInterfacePhotoZip(
param, param,
layoutDto, layoutDto,
fileDtlList, fileDtlList,

@ -5,11 +5,13 @@ import kr.xit.fims.framework.biz.util.ExtnlInterfaceUtils;
import kr.xit.fims.framework.support.exception.BizRuntimeException; import kr.xit.fims.framework.support.exception.BizRuntimeException;
import kr.xit.fims.framework.support.util.CommUtils; import kr.xit.fims.framework.support.util.CommUtils;
import kr.xit.fims.framework.support.util.constants.MessageKey; import kr.xit.fims.framework.support.util.constants.MessageKey;
import lombok.extern.slf4j.Slf4j;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.RandomAccessFile; import java.io.RandomAccessFile;
@Slf4j
public class ExtnlBusInstallInterfaceUtils { public class ExtnlBusInstallInterfaceUtils {
/** /**

@ -0,0 +1,162 @@
package kr.xit.fims.biz.ec.util;
import kr.xit.fims.biz.FimsConst;
import kr.xit.fims.biz.cmm.NtriDTO;
import kr.xit.fims.framework.biz.cmm.CmmFileDTO;
import kr.xit.fims.framework.support.exception.BizRuntimeException;
import kr.xit.fims.framework.support.util.Checks;
import kr.xit.fims.framework.support.util.DateUtils;
import kr.xit.fims.framework.support.util.FileUtils;
import lombok.extern.slf4j.Slf4j;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
@Slf4j
public class NextGenInterfaceUtils {
/**
* null, NtriDTO.PhotoFileError return
* @param paramDTO
* @param layoutDTO
* @param fileDtlList
* @param interfaceId
* @param uploadRootPath
* @param sendFilePath
* @param tempPath
* @return
*/
public static NtriDTO.PhotoFileError makeNtriInterfacePhotoZip(
final NtriDTO.PhotoSendRequest paramDTO,
final NtriDTO.CrackdownPhotoLayout layoutDTO,
final List<CmmFileDTO.FileDtl> fileDtlList,
final String interfaceId,
final String uploadRootPath,
final String sendFilePath,
final String tempPath) {
// TODO :: 시민신고는 DB 확정후 처리 반영 - 자치단체코드, 시스템코드 반영 필요
List<File> fileList = new ArrayList<>();
String tgtPath = "";
String curDt = DateUtils.getTodayAndNowTime("yyyyMMddHHmmss");
int index = 1;
// 파일에 정보를 기록하는 경우 true
boolean isFileCreate = (FimsConst.SendNtriPhotoInterfaceId.PARK_INTO_FILE.getCode().equals(interfaceId)
|| FimsConst.SendNtriPhotoInterfaceId.BUS_INSTALL_INTO_FILE.getCode().equals(interfaceId));
String fileNm = "";
// TODO :: 파일선별 필요
for (CmmFileDTO.FileDtl dtl : fileDtlList) {
if (Checks.isEmpty(tgtPath)) {
tgtPath = uploadRootPath + tempPath + "/" + dtl.getFilePath().split("/")[1];
}
try {
if(isFileCreate) {
//[인터페이스ID]_[파일생성일시]_[자치단체코드]_순번
// TODO :: 파일명 fix 필요
fileNm = String.format("%s_%s_%s_%d.jpg", interfaceId, curDt, "3800001", index);
}else {
// TODO :: 파일명 fix 필요
//[위반일+시]_[차량번호]_01_[장비코드]_01_[위반장소]_1_0000000000_000_000_순번
fileNm = String.format(
"%s_%s_01_%s_01_%s_1_0000000000_000_000_%d.jpg",
layoutDTO.getCrdnYmdTime(),
layoutDTO.getVhrno().trim(),
"CCTV1",
layoutDTO.getCrdnPlc().trim(),
index);
}
// 대상폴더 미 존재시 생성
File tgtFile = org.apache.commons.io.FileUtils.getFile(tgtPath, fileNm);
org.apache.commons.io.FileUtils.copyFile(
org.apache.commons.io.FileUtils.getFile(uploadRootPath + dtl.getFilePath(), dtl.getFileId())
, tgtFile
, true
);
fileList.add(tgtFile);
// TODO :: 파일선별 필요
if(FimsConst.SendNtriPhotoInterfaceId.PARK_INTO_FILE.getCode().equals(interfaceId)
||FimsConst.SendNtriPhotoInterfaceId.PARK_FILE_NAME.getCode().equals(interfaceId)){
if(index == 4) break;
}
// TODO :: 파일선별 필요
if(FimsConst.SendNtriPhotoInterfaceId.BUS_INSTALL_INTO_FILE.getCode().equals(interfaceId)
||FimsConst.SendNtriPhotoInterfaceId.BUS_INSTALL_FILE_NAME.getCode().equals(interfaceId)){
if(index == 7) break;
}
index++;
} catch (IOException e) {
fileList.forEach(f -> {
if(f.exists()) //noinspection ResultOfMethodCallIgnored
f.delete();
});
//FileUtils.removeDirectyAndFiles(tgtPath);
return new NtriDTO.PhotoFileError(paramDTO.getVhrno(),
String.format("%s%s", uploadRootPath + dtl.getFilePath(), dtl.getFileId()),
dtl.getOrginlFileNm());
}
}
Path path = null;
// 파일에 정보 파일을 사용할 경우에만 생성
if(isFileCreate) {
// TODO : 연계정보 생성 구체화
layoutDTO.setAtchFileCnt(String.valueOf(fileList.size()));
String layoutString = layoutDTO.toString(interfaceId);
byte[] bytes = layoutString.getBytes();
String infoTxt = String.format("/%s_%s_%s_0.txt", interfaceId, curDt, "3800001");
path = Paths.get(tgtPath + infoTxt);
try {
Files.write(path, bytes);
} catch (IOException e) {
fileList.forEach(f -> {
if (f.exists()) //noinspection ResultOfMethodCallIgnored
f.delete();
});
//FileUtils.removeDirectyAndFiles(tgtPath);
log.error(e.getLocalizedMessage());
e.printStackTrace();
throw BizRuntimeException.create(e.getLocalizedMessage());
}
fileList.add(path.toFile());
}
log.debug("{}", fileList);
/* [인테페이스아이디]_[파일생성일시]@[자치단체코드][시스템코드].ZIP */
FileUtils.compressZip(
fileList,
sendFilePath,
String.format("%s_%s@%s%s.ZIP", interfaceId, curDt, "3800001", "DCP"));
try {
// 파일정보 파일을 생성한 경우 txt file 삭제
if(isFileCreate) Files.deleteIfExists(path);
fileList.forEach(f -> {
if(f.exists()) //noinspection ResultOfMethodCallIgnored
f.delete();
});
// 작업파일 삭제
//FileUtils.removeDirectyAndFiles(tgtPath);
}catch (IOException ie){
log.error(ie.getLocalizedMessage());
ie.printStackTrace();
}
return null;
}
}

@ -25,149 +25,6 @@ import java.util.List;
@Slf4j @Slf4j
public class ExtnlInterfaceUtils { public class ExtnlInterfaceUtils {
/**
* null, NtriDTO.PhotoFileError return
* @param paramDTO
* @param layoutDTO
* @param fileDtlList
* @param interfaceId
* @param uploadRootPath
* @param sendFilePath
* @param tempPath
* @return
*/
public static NtriDTO.PhotoFileError makeNtriInterfacePhotoZip(
final NtriDTO.PhotoSendRequest paramDTO,
final NtriDTO.CrackdownPhotoLayout layoutDTO,
final List<CmmFileDTO.FileDtl> fileDtlList,
final String interfaceId,
final String uploadRootPath,
final String sendFilePath,
final String tempPath) {
// TODO :: 시민신고는 DB 확정후 처리 반영 - 자치단체코드, 시스템코드 반영 필요
List<File> fileList = new ArrayList<>();
String tgtPath = "";
String curDt = DateUtils.getTodayAndNowTime("yyyyMMddHHmmss");
int index = 1;
// 파일에 정보를 기록하는 경우 true
boolean isFileCreate = (FimsConst.SendNtriPhotoInterfaceId.PARK_INTO_FILE.getCode().equals(interfaceId)
|| FimsConst.SendNtriPhotoInterfaceId.BUS_INSTALL_INTO_FILE.getCode().equals(interfaceId));
String fileNm = "";
// TODO :: 파일선별 필요
for (CmmFileDTO.FileDtl dtl : fileDtlList) {
if (Checks.isEmpty(tgtPath)) {
tgtPath = uploadRootPath + tempPath + "/" + dtl.getFilePath().split("/")[1];
}
try {
if(isFileCreate) {
//[인터페이스ID]_[파일생성일시]_[자치단체코드]_순번
// TODO :: 파일명 fix 필요
fileNm = String.format("%s_%s_%s_%d.jpg", interfaceId, curDt, "3800001", index);
}else {
// TODO :: 파일명 fix 필요
//[위반일+시]_[차량번호]_01_[장비코드]_01_[위반장소]_1_0000000000_000_000_순번
fileNm = String.format(
"%s_%s_01_%s_01_%s_1_0000000000_000_000_%d.jpg",
layoutDTO.getCrdnYmdTime(),
layoutDTO.getVhrno().trim(),
"CCTV1",
layoutDTO.getCrdnPlc().trim(),
index);
}
// 대상폴더 미 존재시 생성
File tgtFile = org.apache.commons.io.FileUtils.getFile(tgtPath, fileNm);
org.apache.commons.io.FileUtils.copyFile(
org.apache.commons.io.FileUtils.getFile(uploadRootPath + dtl.getFilePath(), dtl.getFileId())
, tgtFile
, true
);
fileList.add(tgtFile);
// TODO :: 파일선별 필요
if(FimsConst.SendNtriPhotoInterfaceId.PARK_INTO_FILE.getCode().equals(interfaceId)
||FimsConst.SendNtriPhotoInterfaceId.PARK_FILE_NAME.getCode().equals(interfaceId)){
if(index == 4) break;
}
// TODO :: 파일선별 필요
if(FimsConst.SendNtriPhotoInterfaceId.BUS_INSTALL_INTO_FILE.getCode().equals(interfaceId)
||FimsConst.SendNtriPhotoInterfaceId.BUS_INSTALL_FILE_NAME.getCode().equals(interfaceId)){
if(index == 7) break;
}
index++;
} catch (IOException e) {
fileList.forEach(f -> {
if(f.exists()) //noinspection ResultOfMethodCallIgnored
f.delete();
});
//FileUtils.removeDirectyAndFiles(tgtPath);
return new NtriDTO.PhotoFileError(paramDTO.getVhrno(),
String.format("%s%s", uploadRootPath + dtl.getFilePath(), dtl.getFileId()),
dtl.getOrginlFileNm());
}
}
Path path = null;
// 파일에 정보 파일을 사용할 경우에만 생성
if(isFileCreate) {
// TODO : 연계정보 생성 구체화
layoutDTO.setAtchFileCnt(String.valueOf(fileList.size()));
String layoutString = layoutDTO.toString(interfaceId);
byte[] bytes = layoutString.getBytes();
String infoTxt = String.format("/%s_%s_%s_0.txt", interfaceId, curDt, "3800001");
path = Paths.get(tgtPath + infoTxt);
try {
Files.write(path, bytes);
} catch (IOException e) {
fileList.forEach(f -> {
if (f.exists()) //noinspection ResultOfMethodCallIgnored
f.delete();
});
//FileUtils.removeDirectyAndFiles(tgtPath);
log.error(e.getLocalizedMessage());
e.printStackTrace();
throw BizRuntimeException.create(e.getLocalizedMessage());
}
fileList.add(path.toFile());
}
log.debug("{}", fileList);
/* [인테페이스아이디]_[파일생성일시]@[자치단체코드][시스템코드].ZIP */
FileUtils.compressZip(
fileList,
sendFilePath,
String.format("%s_%s@%s%s.ZIP", interfaceId, curDt, "3800001", "DCP"));
try {
// 파일정보 파일을 생성한 경우 txt file 삭제
if(isFileCreate) Files.deleteIfExists(path);
fileList.forEach(f -> {
if(f.exists()) //noinspection ResultOfMethodCallIgnored
f.delete();
});
// 작업파일 삭제
//FileUtils.removeDirectyAndFiles(tgtPath);
}catch (IOException ie){
log.error(ie.getLocalizedMessage());
ie.printStackTrace();
}
return null;
}
public static String readBuff(RandomAccessFile raf, Long startPos, int readLength){ public static String readBuff(RandomAccessFile raf, Long startPos, int readLength){
try { try {
raf.seek(startPos); raf.seek(startPos);

Loading…
Cancel
Save