feat: 외부연계데이타 응답처리 반영(zip file 생성)

main
minuk926 2 years ago
parent eb34d48729
commit f43cc499ce

@ -23,6 +23,7 @@ import kr.xit.framework.biz.cmm.model.CmmFileDTO;
import kr.xit.framework.biz.cmm.service.ICmmFileService;
import kr.xit.framework.support.exception.BizRuntimeException;
import kr.xit.framework.support.util.Checks;
import kr.xit.framework.support.util.CmmFileUtils;
import kr.xit.framework.support.util.constants.MessageKey;
import kr.xit.framework.support.util.xml.XmlParseUtils;
import lombok.RequiredArgsConstructor;
@ -134,11 +135,8 @@ public class EcCtznSttemntService implements IEcCtznSttemntService {
//-----------------------------------------------------
@Override
public void sendCtznSttemntRespons(CtznStmtDTO.CtznStmtDtl dto) {
public String sendCtznSttemntRespons(CtznStmtDTO.CtznStmtDtl dto) {
final String fileName = dto.getInterfaceSeqN()+dto.getCtznSttemntDetailSn();
List<CmmFileDTO.FileDtl> fileDtlList = cmmFileService.findFilesByJobSeCodeAndJobId(
CmmFileDTO.FileMst.builder()
@ -146,8 +144,6 @@ public class EcCtznSttemntService implements IEcCtznSttemntService {
.fileJobId(dto.getInterfaceSeqN()+dto.getCtznSttemntDetailSn())
.build());
List<File> fileList = new ArrayList<>();
String tgtPath = null;
for (CmmFileDTO.FileDtl dtl : fileDtlList) {
@ -188,8 +184,9 @@ public class EcCtznSttemntService implements IEcCtznSttemntService {
.build();
String xmlStr = XmlParseUtils.writeObjectToXml(sendDto, NatlNewspaperSendXmlDTO.class);
// xml 응답데이타
byte[] bytes = xmlStr.getBytes();
Path path = Paths.get(tgtPath + "/res.xml");
Path path = Paths.get(tgtPath + fileName + ".xml");
try {
Files.write(path, bytes);
} catch (IOException e) {
@ -198,6 +195,12 @@ public class EcCtznSttemntService implements IEcCtznSttemntService {
fileList.add(path.toFile());
log.debug("{}", fileList);
String zipFullFileName = CmmFileUtils.compressZip(fileList, tgtPath, fileName+".zip");
fileList.forEach(f -> {
if(f.exists()) f.delete();
});
return zipFullFileName;
}
@Override

@ -486,4 +486,5 @@ public class EcNatlNewspaperService implements IEcNatlNewspaperService {
dateStr = dateStr.substring(0,4) + "/" + dateStr.substring(4);
return "/" + dateStr;
}
}

@ -30,7 +30,7 @@ public interface IEcCtznSttemntService {
//-----------------------------------------------------
// 단속 처리 결과 전송
//-----------------------------------------------------
void sendCtznSttemntRespons(final CtznStmtDTO.CtznStmtDtl dto);
String sendCtznSttemntRespons(final CtznStmtDTO.CtznStmtDtl dto);
void dragAndDropSaveImg(final Map<String, Object>paraMap);

@ -147,19 +147,12 @@ public class EcCtznSttemntController {
@RequestMapping("/sendCtznSttemntRespons")
public ModelAndView sendCtznSttemntRespons(final CtznStmtDTO.CtznStmtDtl dto) {
ModelAndView mav = new ModelAndView(FrameworkConstants.JSON_VIEW);
log.debug(dto.toString());
service.sendCtznSttemntRespons(dto);
AjaxMessageMapRenderer.success(mav, MessageKey.CMM_SUCCESS);
return mav;
// return ResultResponse.of(
// fileService.findFilesByJobSeCodeAndJobId(
// CmmFileDTO.FileMst.builder()
// .jobSeCode(getFileJobSeCode(regltSeCode))
// .fileJobId(extrlRegltCntcId)
// .build()).stream()
// .filter(dtl -> !Objects.equals("png", dtl.getFileExtsn()))
// .collect(Collectors.toList())
// );
// ModelAndView mav = new ModelAndView(FrameworkConstants.JSON_VIEW);
// log.debug(dto.toString());
// String rtnFileFullPath = service.sendCtznSttemntRespons(dto);
// AjaxMessageMapRenderer.success(mav, MessageKey.CMM_SUCCESS);
// return mav;
return ResultResponse.of(service.sendCtznSttemntRespons(dto));
}
}

@ -139,6 +139,11 @@ public class CmmFileMgtController {
download(sb.toString(), fileDtlDTO.getOrginlFileNm(), response);
}
@RequestMapping("/downloadFromFileFullPath")
public void downloadFromFileFullPath(final String fileFullPath, final String fileName, HttpServletResponse response) {
download(fileFullPath, fileName, response);
}
private void download(String absFile, String fileName, HttpServletResponse response) {
Path path = Paths.get(absFile);

@ -15,7 +15,7 @@ import kr.xit.framework.support.util.constants.MessageKey;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class FileUtils {
public class CmmFileUtils {
/**
* zip
@ -24,11 +24,11 @@ public class FileUtils {
* @param zipFilePath zip file folder
* @param zipFileName zip file name
*/
public void compressZip(final String filePath, final List<String> fileNameList, final String zipFilePath, final String zipFileName) {
public static String compressZip(final String filePath, final List<String> fileNameList, final String zipFilePath, final String zipFileName) {
List<File> fileList = new ArrayList<>();
fileNameList.forEach(s -> fileList.add(new File(filePath, s)));
compressZip(fileList, zipFilePath, zipFileName);
return compressZip(fileList, zipFilePath, zipFileName);
}
/**
@ -37,7 +37,7 @@ public class FileUtils {
* @param zipFilePath zip file folder
* @param zipFileName zip file name
*/
public void compressZip(final List<File> fileList, final String zipFilePath, final String zipFileName) {
public static String compressZip(final List<File> fileList, final String zipFilePath, final String zipFileName) {
File zipFile = new File(zipFilePath, zipFileName);
byte[] buff = new byte[4096];
@ -61,6 +61,8 @@ public class FileUtils {
}
});
return zipFilePath + "/" + zipFileName;
} catch (FileNotFoundException e) {
log.error("zip파일 생성 오류::{}", e.getLocalizedMessage());
throw BizRuntimeException.create(MessageKey.CUSTOM_MSG, "zip 파일생성 오류[대상파일 미존재]");

@ -208,5 +208,4 @@
, updusr = #{updusr}
WHERE extrl_reglt_cntc_id = #{extrlRegltCntcId}
</update>
</mapper>

@ -53,6 +53,7 @@
<!-- 데이터 출력 -->
<div id="grid"></div>
<script type="text/javascript" src="${pageContext.request.contextPath}/resources/framework/js/cmm/cmmDownloadImg.js" defer></script>
<script type="text/javaScript">
/**************************************************************************
* Global Variable
@ -117,13 +118,35 @@
}
,onClickSendResponse: function(props){
const rowData = props.grid.getRow(props.rowKey);
const fileName = rowData.interfaceSeqN + rowData.ctznSttemntDetailSn + '.zip';
cmmBizAjax('단속 데이타 전송 처리', {
url: '<c:url value="/fims/biz/ec/sendCtznSttemntRespons.do"/>'
, data: rowData
})
if(!confirm('단속 데이타를 전송 처리 하시겠습니까?')) return false;
$.ajax({
url : '<c:url value="/fims/biz/ec/sendCtznSttemntRespons.do"/>',
data : rowData,
type : "post",
global : false,
async: false,
beforeSend:function(jqXhr, settings) {
jqXhr.setRequestHeader('AJAX',true);
}
,success: (res) => {
const data = {fileFullPath: res.data?.contents, fileName: 'download.zip'};
fetch(
'<c:url value="/framework/biz/cmm/file/downloadFromFileFullPath.do"/>'
,{
method: 'post'
,body: JSON.stringify(data)
}
)
.then(response => response.blob())
.then(blob => {
downloadFile(blob, fileName);
//fnBiz.pagePopup('sendResponse', {data: rowData});
});
}
})
}
}

@ -78,6 +78,29 @@ function sttemntImgDownload(cmmFileDtls, appendElementId, reqDTO, isEditor) {
//<img src="/resources/framework/images/common/noImage.png"/>
}
/**
* file download 실행
* @param blob
* @param fileName
*/
function downloadFile(blob, fileName){
const url = URL.createObjectURL(blob);
const anchorElement = document.createElement('a');
document.body.appendChild(anchorElement);
anchorElement.download = fileName; // a tag에 download 속성을 줘서 클릭할 때 다운로드가 일어날 수 있도록 하기
anchorElement.href = url; // href에 url 달아주기
anchorElement.click(); // 코드 상으로 클릭을 해줘서 다운로드를 트리거
// cleanup - 쓰임을 다한 url 객체 삭제
anchorElement.onload = () => {
URL.revokeObjectUrl(url);
}
//URL.revokeObjectUrl(url);
document.body.removeChild(anchorElement); // cleanup - 쓰임을 다한 a 태그 삭제
}
/**
* <pre>
* 첨부파일 정보 목록으로 부터 이미지 download

Loading…
Cancel
Save