한글파일 다운로드 수정
parent
4e7c8516c1
commit
d38244b1b3
@ -0,0 +1,130 @@
|
||||
package cokr.xit.base.file.hwp;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
import cokr.xit.fims.cmmn.Print;
|
||||
import cokr.xit.fims.cmmn.hwp.AddUtil;
|
||||
import cokr.xit.fims.cmmn.hwp.format.HWPFormat;
|
||||
import cokr.xit.fims.sprt.PrintOption;
|
||||
import cokr.xit.foundation.UserInfo;
|
||||
import cokr.xit.foundation.data.DataObject;
|
||||
import kr.dogfoot.hwplib.object.HWPFile;
|
||||
import kr.dogfoot.hwplib.reader.HWPReader;
|
||||
|
||||
public class HWPWriter {
|
||||
protected Print print;
|
||||
protected HWPFormat format;
|
||||
|
||||
protected UserInfo printRequestUserInfo;
|
||||
|
||||
public void setPrintRequestUserInfo(UserInfo printRequestUserInfo) {
|
||||
this.printRequestUserInfo = printRequestUserInfo;
|
||||
};
|
||||
public UserInfo getPrintRequestUserInfo() {
|
||||
return this.printRequestUserInfo;
|
||||
};
|
||||
public HWPFormat setFormat(HWPFormat format) {
|
||||
return this.format = format;
|
||||
};
|
||||
|
||||
public Map<String, Object> makeFileFromHwpFormat(String formatType, Print print, PrintOption printOption, List<DataObject> dataObjectList) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
this.print = new Print();
|
||||
this.format.setting(print);
|
||||
|
||||
|
||||
int totalDataCount = dataObjectList.size();
|
||||
List<String> partFileList = new ArrayList<>();
|
||||
this.format.calcTotalPartFileCount(totalDataCount);
|
||||
|
||||
|
||||
try {
|
||||
|
||||
int dataIndex = 0;
|
||||
for(int partFileIndex = 0; partFileIndex < this.format.getTotalPartFileCount(); partFileIndex++) {
|
||||
|
||||
//새 파일 생성
|
||||
String resultHwpPath = this.format.newFileFromFormatFile(print);
|
||||
HWPFile resultFile = HWPReader.fromFile(resultHwpPath);
|
||||
|
||||
//공통사항 세팅
|
||||
this.format.writeGlobalInfo(resultFile, dataObjectList, printOption, print);
|
||||
|
||||
kr.dogfoot.hwplib.writer.HWPWriter.toFile(resultFile, resultHwpPath);
|
||||
|
||||
//데이터 건별 처리
|
||||
for(int recordIndex = 0; recordIndex < this.format.getRecordPerPartFile(); recordIndex++) {
|
||||
if(dataIndex < dataObjectList.size()) {
|
||||
DataObject dataObject = dataObjectList.get(dataIndex);
|
||||
|
||||
if(formatType.equals("list")) {
|
||||
InputStream attachFormatIS = new ClassPathResource(this.format.getAttachFormatFilePath()).getInputStream();
|
||||
HWPFile attachFormatFile = HWPReader.fromInputStream(attachFormatIS);
|
||||
|
||||
this.format.writeSingleDataInfo(null, attachFormatFile, dataObject, print);
|
||||
|
||||
AddUtil.insertTableInCell(attachFormatFile, resultFile, "내부");
|
||||
|
||||
} else if(formatType.equals("info")){
|
||||
|
||||
this.format.writeSingleDataInfo(resultFile, null, dataObject, print);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(formatType.equals("list")) {
|
||||
dataIndex++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(!formatType.equals("list")) {
|
||||
dataIndex++;
|
||||
}
|
||||
|
||||
kr.dogfoot.hwplib.writer.HWPWriter.toFile(resultFile, resultHwpPath);
|
||||
partFileList.add(resultHwpPath);
|
||||
}
|
||||
|
||||
//결과파일 병합
|
||||
if(partFileList.size() >= 2) {
|
||||
String basePath = partFileList.get(0);
|
||||
HWPFile baseFile = HWPReader.fromFile(basePath);
|
||||
|
||||
|
||||
for(int i=2; i <= partFileList.size();i++) {
|
||||
String attachPath = partFileList.get(i-1);
|
||||
HWPFile attachFile = HWPReader.fromFile(attachPath);
|
||||
AddUtil.appendToLast(attachFile, baseFile);
|
||||
}
|
||||
|
||||
kr.dogfoot.hwplib.writer.HWPWriter.toFile(baseFile, basePath);
|
||||
|
||||
for(int i=2; i <= partFileList.size();i++) {
|
||||
(new File(partFileList.get(i-1))).delete();
|
||||
}
|
||||
}
|
||||
|
||||
String downlaodFileName = print.getFormatKorName()+"_"+print.getPrintRequestDt()+".hwp";
|
||||
result.put("filename", downlaodFileName);
|
||||
String filePath = partFileList.get(0);
|
||||
result.put("filePath", filePath);
|
||||
result.put("file", new File(filePath));
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("한글 파일 출력 중 오류가 발생하였습니다.");
|
||||
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package cokr.xit.base.file.pdf;
|
||||
|
||||
public class PDFWriter {
|
||||
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
package cokr.xit.fims.cmmn.hwp;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import cokr.xit.fims.sprt.PrintOption;
|
||||
import cokr.xit.foundation.data.DataObject;
|
||||
import kr.dogfoot.hwplib.object.HWPFile;
|
||||
|
||||
public interface HWPFormatWriter {
|
||||
|
||||
|
||||
|
||||
/** 포맷 형식별 기초 설정 적용.
|
||||
* @param hwpPrintUtil
|
||||
* @return
|
||||
*/
|
||||
void setting(HWPPrintUtil hwpPrintUtil);
|
||||
|
||||
void setting(HWPPrintUtil hwpPrintUtil, int cnt);
|
||||
|
||||
/** 한글파일 공통사항 적용
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
void writeGlobalInfo(HWPFile baseFile, List<DataObject> dataObjectList,
|
||||
PrintOption printOption, HWPPrintUtil hwpPrintUtil);
|
||||
|
||||
/** 데이터 건별 한글파일 처리
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
void writeSingleDataInfo(HWPFile baseFile, HWPFile attachFile, DataObject dataObject,
|
||||
HWPPrintUtil hwpPrintUtil);
|
||||
|
||||
}
|
@ -0,0 +1,95 @@
|
||||
package cokr.xit.fims.cmmn.hwp.format;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
import cokr.xit.fims.cmmn.CmmnUtil;
|
||||
import cokr.xit.fims.cmmn.Print;
|
||||
import cokr.xit.fims.cmmn.hwp.AddUtil;
|
||||
import cokr.xit.fims.cmmn.hwp.ClickHereEditor;
|
||||
import cokr.xit.fims.cmmn.hwp.InsertingImageCell;
|
||||
import cokr.xit.fims.sprt.PrintOption;
|
||||
import cokr.xit.foundation.data.DataFormat;
|
||||
import cokr.xit.foundation.data.DataObject;
|
||||
import kr.dogfoot.hwplib.object.HWPFile;
|
||||
import kr.dogfoot.hwplib.reader.HWPReader;
|
||||
|
||||
|
||||
public class CvlcptOrgn extends HWPFormat {
|
||||
|
||||
@Override
|
||||
public void setting(Print print) {
|
||||
print.setFormatName("cvlcptOrgn");
|
||||
print.setFormatKorName("민원원본내역");
|
||||
|
||||
this.setFormatType("info");
|
||||
this.setRecordPerPartFile(1);
|
||||
|
||||
this.setBaseFormatFilePath("template/hwp/cvlcptOrgnl_text.hwp");
|
||||
this.setAttachFormatFilePath("template/hwp/cvlcptOrgnl_photo.hwp");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setting(Print print, int cnt) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeGlobalInfo(HWPFile baseFile, List<DataObject> dataObjectList, PrintOption printOption,
|
||||
Print print) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeSingleDataInfo(HWPFile baseFile, HWPFile attachFile, DataObject dataObject, Print print) {
|
||||
|
||||
ClickHereEditor baseFileEditor = new ClickHereEditor(baseFile);
|
||||
|
||||
baseFileEditor.set("신청자", dataObject.string("CVLCPT_APLCNT_NM"));
|
||||
baseFileEditor.set("접수일자", DataFormat.yyyy_mm_dd(dataObject.string("CVLCPT_RCPT_YMD")));
|
||||
|
||||
String cvlcptRrcsPrnmntDt = dataObject.string("CVLCPT_PRCS_PRNMNT_DT");
|
||||
if(cvlcptRrcsPrnmntDt.length() > 8) {
|
||||
cvlcptRrcsPrnmntDt = cvlcptRrcsPrnmntDt.substring(0, 8);
|
||||
}
|
||||
|
||||
baseFileEditor.set("처리기한", DataFormat.yyyy_mm_dd(cvlcptRrcsPrnmntDt));
|
||||
baseFileEditor.set("접수번호", dataObject.string("CVLCPT_RCPT_NO"));
|
||||
baseFileEditor.set("목록번호", dataObject.string("CVLCPT_LIST_NO"));
|
||||
|
||||
String cvlcptAplyCn = dataObject.string("CVLCPT_APLY_CN");
|
||||
cvlcptAplyCn = CmmnUtil.escapeHTMLEntity(cvlcptAplyCn);
|
||||
baseFileEditor.set("민원내용", cvlcptAplyCn);
|
||||
|
||||
try {
|
||||
|
||||
if(dataObject.string("PHOTO0") != null && !dataObject.string("PHOTO0").equals("")) {
|
||||
System.out.println("원본사진있음");
|
||||
|
||||
int photoCnt = dataObject.number("ORGN_PHOTO_CNT").intValue();
|
||||
int PHOTO_COUNT_PER_PAGE = 4;
|
||||
|
||||
for(int i=0; i < photoCnt; i += PHOTO_COUNT_PER_PAGE) {
|
||||
|
||||
InputStream attachFormatIS = new ClassPathResource(this.attachFormatFilePath).getInputStream();
|
||||
HWPFile attachFormatFile = HWPReader.fromInputStream(attachFormatIS);
|
||||
InsertingImageCell.IMPL_InsertPicture(attachFormatFile, "왼쪽위사진", dataObject.string("PHOTO"+i));
|
||||
if(i+1 < photoCnt)
|
||||
InsertingImageCell.IMPL_InsertPicture(attachFormatFile, "오른쪽위사진", dataObject.string("PHOTO"+(i+1)));
|
||||
if(i+2 < photoCnt)
|
||||
InsertingImageCell.IMPL_InsertPicture(attachFormatFile, "왼쪽아래사진", dataObject.string("PHOTO"+(i+2)));
|
||||
if(i+3 < photoCnt)
|
||||
InsertingImageCell.IMPL_InsertPicture(attachFormatFile, "오른쪽아래사진", dataObject.string("PHOTO"+(i+3)));
|
||||
AddUtil.appendToLast(attachFormatFile, baseFile);
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
System.out.println("원본사진없음");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("[F]"+e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue