From e5629aa1a78f4807d99dcb1e844d842b6a6ed84c Mon Sep 17 00:00:00 2001 From: leebeomjun Date: Thu, 25 Apr 2024 15:21:17 +0900 Subject: [PATCH] =?UTF-8?q?=EC=99=B8=EC=A3=BC=EC=9A=94=EC=B2=AD=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EC=83=9D=EC=84=B1=20=ED=9B=84=20=EC=82=AD=EC=A0=9C?= =?UTF-8?q?=20=EC=B2=98=EB=A6=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xit/fims/cmmn/OutsourcingFileMaker.java | 66 +++++++++++++++---- .../xit/fims/cmmn/hwp/format/HWPFormat.java | 2 + .../xit/fims/sndb/web/Sndb01Controller.java | 4 +- .../xit/fims/sprt/web/Sprt01Controller.java | 8 +-- 4 files changed, 60 insertions(+), 20 deletions(-) diff --git a/src/main/java/cokr/xit/fims/cmmn/OutsourcingFileMaker.java b/src/main/java/cokr/xit/fims/cmmn/OutsourcingFileMaker.java index 3169709d..2c4d0abb 100644 --- a/src/main/java/cokr/xit/fims/cmmn/OutsourcingFileMaker.java +++ b/src/main/java/cokr/xit/fims/cmmn/OutsourcingFileMaker.java @@ -6,6 +6,7 @@ import java.io.FileInputStream; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; +import java.io.OutputStream; import java.nio.file.Files; import java.nio.file.StandardCopyOption; import java.text.SimpleDateFormat; @@ -16,16 +17,29 @@ import java.util.Map; import org.egovframe.rte.fdl.string.EgovStringUtil; +import cokr.xit.foundation.Downloadable; import cokr.xit.foundation.data.DataFormat; import cokr.xit.foundation.data.DataObject; import net.lingala.zip4j.ZipFile; public class OutsourcingFileMaker { + protected String printKorName; + protected PrintOption printOption; + protected List data; + protected List printStngItems; + + protected String resultZipFilePath; + + public OutsourcingFileMaker(String printKorName, PrintOption printOption, List printStngItems, + List data){ + this.printKorName = printKorName; + this.printOption = printOption; + this.data = data; + this.printStngItems = printStngItems; + } - - public Map makeOutsourcingFile(String printKorName, PrintOption printOption, - List dataObjectList, List printStngItems) { + public Map makeFile() { Map result = new HashMap<>(); Hangul hangul = new Hangul(2); @@ -60,8 +74,8 @@ public class OutsourcingFileMaker { imagesFolderPathFile.mkdirs(); } - for(int i=0; i < dataObjectList.size(); i++) { - DataObject dataObject = dataObjectList.get(i); + for(int i=0; i < data.size(); i++) { + DataObject dataObject = data.get(i); CmmnUtil.setOcrInfo(dataObject); CmmnUtil.setBarcode(dataObject); @@ -103,18 +117,18 @@ public class OutsourcingFileMaker { } - File file = new File(metaFilePath); - if (!file.exists()) { - if(!file.createNewFile()) { + File metaFile = new File(metaFilePath); + if (!metaFile.exists()) { + if(!metaFile.createNewFile()) { throw new RuntimeException("외주파일생성 중 오류가 발생하였습니다."); }; } - FileWriter fw = new FileWriter(file); + FileWriter fw = new FileWriter(metaFile); BufferedWriter writer = new BufferedWriter(fw); - for(int i=0; i < dataObjectList.size(); i++) { - DataObject dataObject = dataObjectList.get(i); + for(int i=0; i < data.size(); i++) { + DataObject dataObject = data.get(i); if(i != 0) { writer.write("\n"); @@ -202,9 +216,15 @@ public class OutsourcingFileMaker { zipFile.addFolder(new File(imagesFolderPath)); zipFile.close(); - result.put("filename", zipFileName); - result.put("filePath", zipFilePath); - result.put("file", new File(zipFilePath)); + metaFile.delete(); + File[] images = imagesFolderPathFile.listFiles(); + for(File image : images) { + image.delete(); + } + imagesFolderPathFile.delete(); + + resultZipFilePath = zipFilePath; + result.put("download", this.getDownloadable().setFilename(zipFileName)); } catch (IOException e) { throw new RuntimeException("외주파일생성 중 오류가 발생하였습니다."); @@ -212,4 +232,22 @@ public class OutsourcingFileMaker { return result; } + + + public void write(OutputStream out) { + try { + FileInputStream fis = new FileInputStream(resultZipFilePath); + fis.transferTo(out); + fis.close(); + new File(resultZipFilePath).delete(); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public Downloadable getDownloadable() { + return new Downloadable() + .setContentType("application/zip") + .setWriter(this::write); + } } diff --git a/src/main/java/cokr/xit/fims/cmmn/hwp/format/HWPFormat.java b/src/main/java/cokr/xit/fims/cmmn/hwp/format/HWPFormat.java index 1019a1ad..4811a700 100644 --- a/src/main/java/cokr/xit/fims/cmmn/hwp/format/HWPFormat.java +++ b/src/main/java/cokr/xit/fims/cmmn/hwp/format/HWPFormat.java @@ -90,6 +90,8 @@ public abstract class HWPFormat { result.put("downloadData", data); result.put("dataNames", getDownloadDataNames()); + new File(resultFilePath).delete(); + return result; }; diff --git a/src/main/java/cokr/xit/fims/sndb/web/Sndb01Controller.java b/src/main/java/cokr/xit/fims/sndb/web/Sndb01Controller.java index 1bd18189..8e6a37e7 100644 --- a/src/main/java/cokr/xit/fims/sndb/web/Sndb01Controller.java +++ b/src/main/java/cokr/xit/fims/sndb/web/Sndb01Controller.java @@ -1861,9 +1861,9 @@ public class Sndb01Controller extends ApplicationController { stngQuery.setSndngSeCd("02"); List printStngItems = outsourcingStngBean.getArtclStngList(stngQuery); - OutsourcingFileMaker osMaker = new OutsourcingFileMaker(); + OutsourcingFileMaker osMaker = new OutsourcingFileMaker("사전통지", printOption, printStngItems, dataObjectList); - Map result = osMaker.makeOutsourcingFile("사전통지", printOption, dataObjectList, printStngItems); + Map result = osMaker.makeFile(); mav.addAllObjects(result); diff --git a/src/main/java/cokr/xit/fims/sprt/web/Sprt01Controller.java b/src/main/java/cokr/xit/fims/sprt/web/Sprt01Controller.java index 3cc06156..9070f682 100644 --- a/src/main/java/cokr/xit/fims/sprt/web/Sprt01Controller.java +++ b/src/main/java/cokr/xit/fims/sprt/web/Sprt01Controller.java @@ -871,9 +871,9 @@ public class Sprt01Controller extends ApplicationController { stngQuery.setSndngSeCd("02"); List printStngItems = outsourcingStngBean.getArtclStngList(stngQuery); - OutsourcingFileMaker osMaker = new OutsourcingFileMaker(); + OutsourcingFileMaker osMaker = new OutsourcingFileMaker("사전통지", printOption, printStngItems, dataObjectList); - Map result = osMaker.makeOutsourcingFile("사전통지", printOption, dataObjectList, printStngItems); + Map result = osMaker.makeFile(); mav.addAllObjects(result); return mav; @@ -1102,9 +1102,9 @@ public class Sprt01Controller extends ApplicationController { stngQuery.setSndngSeCd("03"); List printStngItems = outsourcingStngBean.getArtclStngList(stngQuery); - OutsourcingFileMaker osMaker = new OutsourcingFileMaker(); + OutsourcingFileMaker osMaker = new OutsourcingFileMaker("고지서", printOption, printStngItems, dataObjectList); - Map result = osMaker.makeOutsourcingFile("고지서", printOption, dataObjectList, printStngItems); + Map result = osMaker.makeFile(); mav.addAllObjects(result); return mav;