외주요청파일 생성 후 삭제 처리 추가

main
이범준 7 months ago
parent be3d699c83
commit e5629aa1a7

@ -6,6 +6,7 @@ import java.io.FileInputStream;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.StandardCopyOption; import java.nio.file.StandardCopyOption;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
@ -16,16 +17,29 @@ import java.util.Map;
import org.egovframe.rte.fdl.string.EgovStringUtil; import org.egovframe.rte.fdl.string.EgovStringUtil;
import cokr.xit.foundation.Downloadable;
import cokr.xit.foundation.data.DataFormat; import cokr.xit.foundation.data.DataFormat;
import cokr.xit.foundation.data.DataObject; import cokr.xit.foundation.data.DataObject;
import net.lingala.zip4j.ZipFile; import net.lingala.zip4j.ZipFile;
public class OutsourcingFileMaker { public class OutsourcingFileMaker {
protected String printKorName;
protected PrintOption printOption;
protected List<DataObject> data;
protected List<DataObject> printStngItems;
protected String resultZipFilePath;
public OutsourcingFileMaker(String printKorName, PrintOption printOption, List<DataObject> printStngItems,
List<DataObject> data){
this.printKorName = printKorName;
this.printOption = printOption;
this.data = data;
this.printStngItems = printStngItems;
}
public Map<String, Object> makeFile() {
public Map<String, Object> makeOutsourcingFile(String printKorName, PrintOption printOption,
List<DataObject> dataObjectList, List<DataObject> printStngItems) {
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
Hangul hangul = new Hangul(2); Hangul hangul = new Hangul(2);
@ -60,8 +74,8 @@ public class OutsourcingFileMaker {
imagesFolderPathFile.mkdirs(); imagesFolderPathFile.mkdirs();
} }
for(int i=0; i < dataObjectList.size(); i++) { for(int i=0; i < data.size(); i++) {
DataObject dataObject = dataObjectList.get(i); DataObject dataObject = data.get(i);
CmmnUtil.setOcrInfo(dataObject); CmmnUtil.setOcrInfo(dataObject);
CmmnUtil.setBarcode(dataObject); CmmnUtil.setBarcode(dataObject);
@ -103,18 +117,18 @@ public class OutsourcingFileMaker {
} }
File file = new File(metaFilePath); File metaFile = new File(metaFilePath);
if (!file.exists()) { if (!metaFile.exists()) {
if(!file.createNewFile()) { if(!metaFile.createNewFile()) {
throw new RuntimeException("외주파일생성 중 오류가 발생하였습니다."); throw new RuntimeException("외주파일생성 중 오류가 발생하였습니다.");
}; };
} }
FileWriter fw = new FileWriter(file); FileWriter fw = new FileWriter(metaFile);
BufferedWriter writer = new BufferedWriter(fw); BufferedWriter writer = new BufferedWriter(fw);
for(int i=0; i < dataObjectList.size(); i++) { for(int i=0; i < data.size(); i++) {
DataObject dataObject = dataObjectList.get(i); DataObject dataObject = data.get(i);
if(i != 0) { if(i != 0) {
writer.write("\n"); writer.write("\n");
@ -202,9 +216,15 @@ public class OutsourcingFileMaker {
zipFile.addFolder(new File(imagesFolderPath)); zipFile.addFolder(new File(imagesFolderPath));
zipFile.close(); zipFile.close();
result.put("filename", zipFileName); metaFile.delete();
result.put("filePath", zipFilePath); File[] images = imagesFolderPathFile.listFiles();
result.put("file", new File(zipFilePath)); for(File image : images) {
image.delete();
}
imagesFolderPathFile.delete();
resultZipFilePath = zipFilePath;
result.put("download", this.getDownloadable().setFilename(zipFileName));
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException("외주파일생성 중 오류가 발생하였습니다."); throw new RuntimeException("외주파일생성 중 오류가 발생하였습니다.");
@ -212,4 +232,22 @@ public class OutsourcingFileMaker {
return result; 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);
}
} }

@ -90,6 +90,8 @@ public abstract class HWPFormat {
result.put("downloadData", data); result.put("downloadData", data);
result.put("dataNames", getDownloadDataNames()); result.put("dataNames", getDownloadDataNames());
new File(resultFilePath).delete();
return result; return result;
}; };

@ -1861,9 +1861,9 @@ public class Sndb01Controller extends ApplicationController {
stngQuery.setSndngSeCd("02"); stngQuery.setSndngSeCd("02");
List<DataObject> printStngItems = outsourcingStngBean.getArtclStngList(stngQuery); List<DataObject> printStngItems = outsourcingStngBean.getArtclStngList(stngQuery);
OutsourcingFileMaker osMaker = new OutsourcingFileMaker(); OutsourcingFileMaker osMaker = new OutsourcingFileMaker("사전통지", printOption, printStngItems, dataObjectList);
Map<String, Object> result = osMaker.makeOutsourcingFile("사전통지", printOption, dataObjectList, printStngItems); Map<String, Object> result = osMaker.makeFile();
mav.addAllObjects(result); mav.addAllObjects(result);

@ -871,9 +871,9 @@ public class Sprt01Controller extends ApplicationController {
stngQuery.setSndngSeCd("02"); stngQuery.setSndngSeCd("02");
List<DataObject> printStngItems = outsourcingStngBean.getArtclStngList(stngQuery); List<DataObject> printStngItems = outsourcingStngBean.getArtclStngList(stngQuery);
OutsourcingFileMaker osMaker = new OutsourcingFileMaker(); OutsourcingFileMaker osMaker = new OutsourcingFileMaker("사전통지", printOption, printStngItems, dataObjectList);
Map<String, Object> result = osMaker.makeOutsourcingFile("사전통지", printOption, dataObjectList, printStngItems); Map<String, Object> result = osMaker.makeFile();
mav.addAllObjects(result); mav.addAllObjects(result);
return mav; return mav;
@ -1102,9 +1102,9 @@ public class Sprt01Controller extends ApplicationController {
stngQuery.setSndngSeCd("03"); stngQuery.setSndngSeCd("03");
List<DataObject> printStngItems = outsourcingStngBean.getArtclStngList(stngQuery); List<DataObject> printStngItems = outsourcingStngBean.getArtclStngList(stngQuery);
OutsourcingFileMaker osMaker = new OutsourcingFileMaker(); OutsourcingFileMaker osMaker = new OutsourcingFileMaker("고지서", printOption, printStngItems, dataObjectList);
Map<String, Object> result = osMaker.makeOutsourcingFile("고지서", printOption, dataObjectList, printStngItems); Map<String, Object> result = osMaker.makeFile();
mav.addAllObjects(result); mav.addAllObjects(result);
return mav; return mav;

Loading…
Cancel
Save