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

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

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

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

Loading…
Cancel
Save