한글문서파일 생성시 단건인 경우 DB저장, 다건인 경우 즉시 다운로드되도록 수정함.

dev
이범준 4 months ago
parent 4d81700ad1
commit 22f54d1246

@ -5,6 +5,8 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -232,7 +234,7 @@ public class AddsNimsController extends ApplicationController {
@RequestMapping(value="/makeDisposeResultReportHwp.do", name="폐기결과보고서 HWP파일 생성") @RequestMapping(value="/makeDisposeResultReportHwp.do", name="폐기결과보고서 HWP파일 생성")
public ModelAndView makeDisposeResultReportHwp(String dtls) { public ModelAndView makeDisposeResultReportHwp(String dtls) {
ModelAndView mav = new ModelAndView(); ModelAndView mav = new ModelAndView();
mav.setViewName("jsonView"); mav.setViewName("downloadView");
List<DataObject> dataForDoc = fromJson(dtls, new TypeReference<ArrayList<DataObject>>() {}); List<DataObject> dataForDoc = fromJson(dtls, new TypeReference<ArrayList<DataObject>>() {});
@ -271,29 +273,36 @@ public class AddsNimsController extends ApplicationController {
//1.한글문서파일 데이터 입력 //1.한글문서파일 데이터 입력
DisposeResultReport form = new DisposeResultReport(print, printOption, dataForDoc); DisposeResultReport form = new DisposeResultReport(print, printOption, dataForDoc);
//2.한글문서파일 생성 //2.한글문서파일 생성
String resultFilePath = form.makeFile().andGetPath(); form.makeFile();
File file = new File(resultFilePath); //3.DB 저장, 스토리지 저장
String newFileId = ""; List<String> dscdmngIds = IntStream.rangeClosed(1, dataForDoc.size()).boxed().map(i -> {
String before = ""; return dataForDoc.get(i-1).string("dscdmngId");
boolean changeDscdmngId = false; }).collect(Collectors.toList());
for(DataObject data : dataForDoc) { boolean allEqual = dscdmngIds.stream().distinct().count() <= 1;
if(!before.equals(data.string("dscdmngId"))) { if(allEqual) {
changeDscdmngId = true; String resultFilePath = form.andGetPath();
} else { File file = new File(resultFilePath);
changeDscdmngId = false; String newFileId = "";
} String before = "";
if(changeDscdmngId) { boolean changeDscdmngId = false;
Relation rel = new Relation().setInfoType("200").setSubType("01").setInfoKey(data.string("dscdmngId")); for(DataObject data : dataForDoc) {
FileInfo fileInfo = new FileInfo.Factory().create(rel, file); if(!before.equals(data.string("dscdmngId"))) {
fileInfo.setName(print.getFormatKorName()+".hwp"); changeDscdmngId = true;
int effected = fileService.create(fileInfo); } else {
newFileId = fileInfo.getId(); changeDscdmngId = false;
}
if(changeDscdmngId) {
Relation rel = new Relation().setInfoType("200").setSubType("01").setInfoKey(data.string("dscdmngId"));
FileInfo fileInfo = new FileInfo.Factory().create(rel, file);
fileInfo.setName(print.getFormatKorName()+".hwp");
int effected = fileService.create(fileInfo);
newFileId = fileInfo.getId();
}
} }
} }
file.delete(); //4.다운로드
HashMap<String, Object> result = form.andDownload();
mav.addObject("fileId", newFileId); mav.addAllObjects(result);
mav.addObject("saved", true);
return mav; return mav;
} }
@ -302,7 +311,7 @@ public class AddsNimsController extends ApplicationController {
@RequestMapping(value="/makeDisposeProcessDetailsHwp.do", name="폐기 처리 내역 및 사진 HWP파일 생성") @RequestMapping(value="/makeDisposeProcessDetailsHwp.do", name="폐기 처리 내역 및 사진 HWP파일 생성")
public ModelAndView makeDisposeProcessDetailsHwp(String dtls) { public ModelAndView makeDisposeProcessDetailsHwp(String dtls) {
ModelAndView mav = new ModelAndView(); ModelAndView mav = new ModelAndView();
mav.setViewName("jsonView"); mav.setViewName("downloadView");
List<DataObject> dataForDoc = fromJson(dtls, new TypeReference<ArrayList<DataObject>>() {}); List<DataObject> dataForDoc = fromJson(dtls, new TypeReference<ArrayList<DataObject>>() {});
@ -383,29 +392,37 @@ public class AddsNimsController extends ApplicationController {
//1.한글문서파일 데이터 입력 //1.한글문서파일 데이터 입력
DisposeProcessDetails form = new DisposeProcessDetails(print, printOption, dataForDoc, partitions); DisposeProcessDetails form = new DisposeProcessDetails(print, printOption, dataForDoc, partitions);
//2.한글문서파일 생성 //2.한글문서파일 생성
String resultFilePath = form.makeFile().andGetPath(); form.makeFile();
File file = new File(resultFilePath); //3.DB 저장, 스토리지 저장
String newFileId = ""; List<String> dscdmngIds = IntStream.rangeClosed(1, dataForDoc.size()).boxed().map(i -> {
before = ""; return dataForDoc.get(i-1).string("dscdmngId");
changeDscdmngId = false; }).collect(Collectors.toList());
for(DataObject data : dataForDoc) { boolean allEqual = dscdmngIds.stream().distinct().count() <= 1;
if(!before.equals(data.string("dscdmngId"))) { if(allEqual) {
changeDscdmngId = true; String resultFilePath = form.andGetPath();
} else { File file = new File(resultFilePath);
changeDscdmngId = false; String newFileId = "";
} before = "";
if(changeDscdmngId) { changeDscdmngId = false;
Relation rel = new Relation().setInfoType("200").setSubType("02").setInfoKey(data.string("dscdmngId")); for(DataObject data : dataForDoc) {
FileInfo fileInfo = new FileInfo.Factory().create(rel, file); if(!before.equals(data.string("dscdmngId"))) {
fileInfo.setName(print.getFormatKorName()+".hwp"); changeDscdmngId = true;
int effected= fileService.create(fileInfo); } else {
newFileId = fileInfo.getId(); changeDscdmngId = false;
}
if(changeDscdmngId) {
Relation rel = new Relation().setInfoType("200").setSubType("02").setInfoKey(data.string("dscdmngId"));
FileInfo fileInfo = new FileInfo.Factory().create(rel, file);
fileInfo.setName(print.getFormatKorName()+".hwp");
int effected= fileService.create(fileInfo);
newFileId = fileInfo.getId();
}
} }
} }
file.delete();
mav.addObject("fileId", newFileId); //4.다운로드
mav.addObject("saved", true); HashMap<String, Object> result = form.andDownload();
mav.addAllObjects(result);
return mav; return mav;
} }
//------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------

@ -445,19 +445,41 @@
return; return;
} }
ajax.get({ $.ajax({
url: url, url: url,
data: { dtls : JSON.stringify(dtls) } , data: { dtls : JSON.stringify(dtls) },
success:resp => { xhrFields: { responseType: 'blob' },
if(resp.saved){ success:(blob, status, xhr) => {
let disposition = xhr.getResponseHeader('Content-Disposition');
let downloadUrl = wctx.url("/file/download.do"); if(disposition && disposition.indexOf('attachment') !== -1) {
let downloadParam = "fileID="+resp.fileId; let filenameRegex = /filename[^;=\n]*=(([']).*?\2|[^;\n]*)/;
document.location.href = downloadUrl+"?"+downloadParam; let matches = filenameRegex.exec(disposition);
if(matches != null && matches[1]) {
filename = matches[1].replace(/[']/g, '');
}
}
filename = decodeURIComponent(filename);
if(filename.startsWith("\"")){
filename = filename.substring(1);
}
if(filename.endsWith("\"")){
filename = filename.substring(0,filename.length - 1);
}
let URL0 = (window.URL || window.webkitURL);
let downloadUrl = URL0.createObjectURL(blob);
let a = document.createElement("a");
a.href = downloadUrl;
a.download = filename;
document.body.appendChild(a);
a.click();
a.remove();
if($("#tbody--${pageName}").find("td input[type='checkbox']:checked").length == 1){
$P.control.load($P.control.pageNum); $P.control.load($P.control.pageNum);
} }
} }
}); });
}; };
@ -470,14 +492,10 @@
* 버튼 clickEvent * 버튼 clickEvent
**************************************************************************/ **************************************************************************/
// 업무 구분 변경 이벤트 // 업무 구분 변경 이벤트
$P.fnResetAndChangeBiz = (taskSeCd) => { $P.fnReset = () => {
// 업무 구분 코드
if (typeof taskSeCd == "undefined" || taskSeCd == null || taskSeCd == "") {
taskSeCd = $("#layout-navbar input[name='taskSeCd']:checked").val();
}
// 초기 기본 설정 // 초기 기본 설정
$P.initForm(taskSeCd); $P.initForm();
// dataset 초기화 // dataset 초기화
$P.control.dataset.clear(); $P.control.dataset.clear();
@ -521,7 +539,7 @@
// 이벤트 설정 // 이벤트 설정
$P.setEvent = () => { $P.setEvent = () => {
// 기본 버튼 이벤트 // 기본 버튼 이벤트
$("#btnReset--${pageName}").on("click", () => $P.fnResetAndChangeBiz()); // 초기화 $("#btnReset--${pageName}").on("click", () => $P.fnReset()); // 초기화
$("#btnSearch--${pageName}").on("click", () => $P.fnSearchList()); // 검색 $("#btnSearch--${pageName}").on("click", () => $P.fnSearchList()); // 검색
$("#btnExcel--${pageName}").on("click", () => $P.fnExcel()); // 엑셀 $("#btnExcel--${pageName}").on("click", () => $P.fnExcel()); // 엑셀
@ -565,7 +583,7 @@
} }
// 초기 화면 설정 // 초기 화면 설정
$P.initForm = (taskSeCd) => { $P.initForm = () => {
// 화면 초기화 // 화면 초기화
$("#frmSearch--${pageName}")[0].reset(); $("#frmSearch--${pageName}")[0].reset();
@ -594,7 +612,7 @@
$P.setEvent(); $P.setEvent();
// 2. 초기 설정 및 업무 구분 변경 // 2. 초기 설정 및 업무 구분 변경
$P.fnResetAndChangeBiz($("#layout-navbar input[name='taskSeCd']:checked").val()); $P.fnReset();
}); });

Loading…
Cancel
Save