From 22f54d1246b1e658d799bf4a2e6020bf2f77e275 Mon Sep 17 00:00:00 2001 From: leebj Date: Mon, 8 Jul 2024 18:15:58 +0900 Subject: [PATCH] =?UTF-8?q?=ED=95=9C=EA=B8=80=EB=AC=B8=EC=84=9C=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EC=83=9D=EC=84=B1=EC=8B=9C=20=EB=8B=A8=EA=B1=B4?= =?UTF-8?q?=EC=9D=B8=20=EA=B2=BD=EC=9A=B0=20DB=EC=A0=80=EC=9E=A5,=20?= =?UTF-8?q?=EB=8B=A4=EA=B1=B4=EC=9D=B8=20=EA=B2=BD=EC=9A=B0=20=EC=A6=89?= =?UTF-8?q?=EC=8B=9C=20=EB=8B=A4=EC=9A=B4=EB=A1=9C=EB=93=9C=EB=90=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95=ED=95=A8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xit/adds/nims/web/AddsNimsController.java | 103 ++++++++++-------- .../WEB-INF/jsp/adds/nims/dsuseDoc-main.jsp | 52 ++++++--- 2 files changed, 95 insertions(+), 60 deletions(-) diff --git a/src/main/java/cokr/xit/adds/nims/web/AddsNimsController.java b/src/main/java/cokr/xit/adds/nims/web/AddsNimsController.java index e1d7d8e..60988fe 100644 --- a/src/main/java/cokr/xit/adds/nims/web/AddsNimsController.java +++ b/src/main/java/cokr/xit/adds/nims/web/AddsNimsController.java @@ -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 dataForDoc = fromJson(dtls, new TypeReference>() {}); @@ -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 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 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 dataForDoc = fromJson(dtls, new TypeReference>() {}); @@ -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 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 result = form.andDownload(); + mav.addAllObjects(result); return mav; } //------------------------------------------------------------------------------------------------- diff --git a/src/main/webapp/WEB-INF/jsp/adds/nims/dsuseDoc-main.jsp b/src/main/webapp/WEB-INF/jsp/adds/nims/dsuseDoc-main.jsp index a4a81b1..29905c1 100644 --- a/src/main/webapp/WEB-INF/jsp/adds/nims/dsuseDoc-main.jsp +++ b/src/main/webapp/WEB-INF/jsp/adds/nims/dsuseDoc-main.jsp @@ -445,19 +445,41 @@ return; } - ajax.get({ + $.ajax({ url: url, - data: { dtls : JSON.stringify(dtls) } , - success:resp => { - if(resp.saved){ - - let downloadUrl = wctx.url("/file/download.do"); - let downloadParam = "fileID="+resp.fileId; - document.location.href = downloadUrl+"?"+downloadParam; + 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 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(); });