pdf 다운로드 수정

main
이범준 9 months ago
parent d38244b1b3
commit d52ea88613

@ -13,7 +13,6 @@ import cokr.xit.fims.cmmn.Print;
import cokr.xit.fims.cmmn.hwp.AddUtil; import cokr.xit.fims.cmmn.hwp.AddUtil;
import cokr.xit.fims.cmmn.hwp.format.HWPFormat; import cokr.xit.fims.cmmn.hwp.format.HWPFormat;
import cokr.xit.fims.sprt.PrintOption; import cokr.xit.fims.sprt.PrintOption;
import cokr.xit.foundation.UserInfo;
import cokr.xit.foundation.data.DataObject; import cokr.xit.foundation.data.DataObject;
import kr.dogfoot.hwplib.object.HWPFile; import kr.dogfoot.hwplib.object.HWPFile;
import kr.dogfoot.hwplib.reader.HWPReader; import kr.dogfoot.hwplib.reader.HWPReader;
@ -22,23 +21,17 @@ public class HWPWriter {
protected Print print; protected Print print;
protected HWPFormat format; protected HWPFormat format;
protected UserInfo printRequestUserInfo; public void setFormat(HWPFormat format) {
this.format = format;
public void setPrintRequestUserInfo(UserInfo printRequestUserInfo) {
this.printRequestUserInfo = printRequestUserInfo;
};
public UserInfo getPrintRequestUserInfo() {
return this.printRequestUserInfo;
}; };
public HWPFormat setFormat(HWPFormat format) { public void setPrint(Print print) {
return this.format = format; this.print = print;
}; };
public Map<String, Object> makeFileFromHwpFormat(String formatType, Print print, PrintOption printOption, List<DataObject> dataObjectList) { public Map<String, Object> makeFileFromHwpFormat(String formatType, PrintOption printOption, List<DataObject> dataObjectList) {
Map<String, Object> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
this.print = new Print(); this.format.setting(this.print);
this.format.setting(print);
int totalDataCount = dataObjectList.size(); int totalDataCount = dataObjectList.size();
@ -52,11 +45,11 @@ public class HWPWriter {
for(int partFileIndex = 0; partFileIndex < this.format.getTotalPartFileCount(); partFileIndex++) { for(int partFileIndex = 0; partFileIndex < this.format.getTotalPartFileCount(); partFileIndex++) {
//새 파일 생성 //새 파일 생성
String resultHwpPath = this.format.newFileFromFormatFile(print); String resultHwpPath = this.format.newFileFromFormatFile(this.print);
HWPFile resultFile = HWPReader.fromFile(resultHwpPath); HWPFile resultFile = HWPReader.fromFile(resultHwpPath);
//공통사항 세팅 //공통사항 세팅
this.format.writeGlobalInfo(resultFile, dataObjectList, printOption, print); this.format.writeGlobalInfo(resultFile, dataObjectList, printOption, this.print);
kr.dogfoot.hwplib.writer.HWPWriter.toFile(resultFile, resultHwpPath); kr.dogfoot.hwplib.writer.HWPWriter.toFile(resultFile, resultHwpPath);
@ -69,13 +62,13 @@ public class HWPWriter {
InputStream attachFormatIS = new ClassPathResource(this.format.getAttachFormatFilePath()).getInputStream(); InputStream attachFormatIS = new ClassPathResource(this.format.getAttachFormatFilePath()).getInputStream();
HWPFile attachFormatFile = HWPReader.fromInputStream(attachFormatIS); HWPFile attachFormatFile = HWPReader.fromInputStream(attachFormatIS);
this.format.writeSingleDataInfo(null, attachFormatFile, dataObject, print); this.format.writeSingleDataInfo(null, attachFormatFile, dataObject, this.print);
AddUtil.insertTableInCell(attachFormatFile, resultFile, "내부"); AddUtil.insertTableInCell(attachFormatFile, resultFile, "내부");
} else if(formatType.equals("info")){ } else if(formatType.equals("info")){
this.format.writeSingleDataInfo(resultFile, null, dataObject, print); this.format.writeSingleDataInfo(resultFile, null, dataObject, this.print);
} }
} }
@ -113,7 +106,7 @@ public class HWPWriter {
} }
} }
String downlaodFileName = print.getFormatKorName()+"_"+print.getPrintRequestDt()+".hwp"; String downlaodFileName = this.print.getFormatKorName()+"_"+this.print.getPrintRequestDt()+".hwp";
result.put("filename", downlaodFileName); result.put("filename", downlaodFileName);
String filePath = partFileList.get(0); String filePath = partFileList.get(0);
result.put("filePath", filePath); result.put("filePath", filePath);

@ -1,5 +1,803 @@
package cokr.xit.base.file.pdf; package cokr.xit.base.file.pdf;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.apache.pdfbox.pdmodel.common.PDRectangle;
import org.apache.pdfbox.pdmodel.font.PDType0Font;
import org.apache.pdfbox.pdmodel.graphics.color.PDColor;
import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject;
import org.apache.pdfbox.pdmodel.graphics.state.RenderingMode;
import org.egovframe.rte.fdl.string.EgovStringUtil;
import org.springframework.core.io.ClassPathResource;
import cokr.xit.fims.cmmn.CmmnUtil;
import cokr.xit.fims.cmmn.Print;
import cokr.xit.fims.cmmn.pdf.PDFColors;
import cokr.xit.fims.cmmn.pdf.PDFCoordinate;
import cokr.xit.fims.cmmn.pdf.Pstn;
import cokr.xit.fims.cmmn.pdf.PstnAndSize;
import cokr.xit.fims.cmmn.pdf.Size;
import cokr.xit.fims.cmmn.pdf.print.DefaultOtptArtclStng;
import cokr.xit.fims.cmmn.pdf.print.format.PDFPrintFormat;
import cokr.xit.fims.sprt.MediaUtil;
import cokr.xit.fims.sprt.PrintOption;
import cokr.xit.foundation.data.DataObject;
public class PDFWriter { public class PDFWriter {
protected String paper;
protected Print print;
protected PDFPrintFormat format;
protected DataObject otptBscStng;
protected List<DataObject> otptArtclStngList;
protected float[] paperMilimeter = new float[2];
public void setPaper(String paperType) {
this.paper = paperType;
if(paperType.equals("01")) {
this.paperMilimeter = new float[] {210.0f , 297.0f};
} else if(paperType.equals("02")){
this.paperMilimeter = new float[] {216.0f , 279.0f};
}
}
public void setFormat(PDFPrintFormat format) {
this.format = format;
};
public void setPrint(Print print) {
this.print = print;
};
public void setOtptBscStng(DataObject otptBscStng) {
this.otptBscStng = otptBscStng;
};
public void setOtptArtclStngList(List<DataObject> otptArtclStngList) {
this.otptArtclStngList = otptArtclStngList;
};
public Map<String, Object> makePdfFile(String formatType, String formatName, PrintOption printOption, List<DataObject> dataObjectList) {
Map<String, Object> result = new HashMap<>();
String resultFilePath = this.filePathForNewFile();
PDDocument doc = new PDDocument();//pdf문서 생성
//폰트 로드
Map<String, PDType0Font> fontMap = this.getFontMap(doc);
//용지 크기 설정
PDRectangle paper = null;
if(this.paper.equals("01")) {
paper = PDRectangle.A4;
} else {
paper = PDRectangle.LETTER;
}
List<DefaultOtptArtclStng> prototypeStngList = this.format.getPrototypeStngs();
try {
//출력요소별 속성 정보 추가
this.format.appendOtptAttribute(this.otptArtclStngList);
//출력 요소 정렬
Comparator<DataObject> comparator1 = (item1, item2) -> {
int int1 = item1.string("UNIQUE_YN").equals("Y") ? 0 : 1;
int int2 = item2.string("UNIQUE_YN").equals("Y") ? 0 : 1;
return Integer.compare(int1, int2);
};
Comparator<DataObject> comparator2 = (item1, item2) -> {
int int1 = item1.number("OTPT_ARTCL_ORDR").intValue();
int int2 = item2.number("OTPT_ARTCL_ORDR").intValue();
return Integer.compare(int1, int2);
};
otptArtclStngList = otptArtclStngList.stream()
.sorted(comparator1.thenComparing(comparator2)).collect(Collectors.toList());
//대표단속사진 설정 여부 확인
boolean rprsCrdnPhotoYn = false;
if(otptArtclStngList.stream().filter(item -> item.string("OTPT_ARTCL_NM").equals("rprsCrdnPhoto")).count() > 0) {
rprsCrdnPhotoYn = true;
}
for(DataObject dataObject : dataObjectList) {
//페이지생성(건별)
PDPage blankPage = new PDPage(paper);
doc.addPage(blankPage);
// 작업 페이지 설정
PDPage page = doc.getPage(doc.getNumberOfPages()-1);
// 컨텐츠 스트림 열기
PDPageContentStream contentStream = new PDPageContentStream(doc, page);
boolean completeFoldLine = false;
for(DataObject otptArtclStng : otptArtclStngList) {
String otptArtclNm = otptArtclStng.string("OTPT_ARTCL_NM");
if(!otptArtclNm.equals("background") && !completeFoldLine) {
//접는곳 점선 그리기
if(!otptBscStng.string("FOLD_LINE_PSTN_SE_CD").equals("")) {
this.renderFoldLine(contentStream, paper, otptBscStng.string("FOLD_LINE_PSTN_SE_CD"));
}
completeFoldLine = true;
}
DefaultOtptArtclStng prototypeStng = prototypeStngList.stream()
.filter(item -> item.getOtptArtclNm().equals(otptArtclNm)).toList().get(0);
float[] pstn = this.getPstnStng(prototypeStng, otptArtclStng, this.paper);
float[] size = this.getSize(prototypeStng, otptArtclStng);
boolean forPost = prototypeStng.isForPost();
String defaultValue = prototypeStng.getOtptBscVl();
if(prototypeStng.getComponentType().equals("text")) {
String align = this.getAlign(prototypeStng, otptArtclStng);
String lineChgYn = this.getLineChgYn(prototypeStng, otptArtclStng);
PDType0Font font = this.getFontType(prototypeStng, otptArtclStng, fontMap);
int fontSz = this.getFontSize(prototypeStng, otptArtclStng);
RenderingMode fontStyle = this.getFontStyle(prototypeStng, otptArtclStng);
PDColor fontColor = this.getFontColor(prototypeStng, otptArtclStng);
String textValue = this.format.getMappingValue(otptArtclNm,defaultValue,forPost,dataObject,printOption,print);
this.writeText(contentStream, textValue, pstn, size[0], align, lineChgYn
, font, fontSz, fontStyle, fontColor);
} else if(prototypeStng.getComponentType().equals("image")) {
String imagePath = this.format.getMappingValue(otptArtclNm,defaultValue,forPost,dataObject,printOption,print);
if(EgovStringUtil.null2void(imagePath).equals("")) {
continue;
}
if(!imagePath.startsWith("files")) {
imagePath = CmmnUtil.copyStaticResource(imagePath, false);
}
File imageFile = new File(imagePath);
InputStream is = new FileInputStream(imageFile);
String imageKey = "";
List<DataObject> mosSet = null;
if(otptArtclNm.equals("rprsCrdnPhoto")) {
imageKey = this.format.getMappingValue(otptArtclNm+"Key",defaultValue,forPost,dataObject,printOption,print);
mosSet = this.format.getMosSet(imageKey, dataObject);
}
this.insertImage(doc, contentStream, is, pstn, size);
if(otptArtclNm.equals("rprsCrdnPhoto") && !imageKey.equals("") && mosSet != null) {
File imageFile0 = new File(imagePath);
InputStream is0 = new FileInputStream(imageFile0);
List<PstnAndSize> transformedMosaicInfos = MediaUtil.getTransformedMosaic(
mosSet, is0, new PstnAndSize(pstn[0],pstn[1], size[0], size[1])
);
for(int k=0; k < transformedMosaicInfos.size(); k++) {
PstnAndSize mosaicInfo = transformedMosaicInfos.get(k);
InputStream blackImageStream = new ClassPathResource("samplefiles/black.png").getInputStream();
this.insertImage(doc, contentStream, blackImageStream,
mosaicInfo.getPstn().to2Float(), mosaicInfo.getSize().to2Float());
}
}
} else if(prototypeStng.getComponentType().equals("images")) {
List<String> imagePaths = this.format.getMappingValues(otptArtclNm,defaultValue,forPost,dataObject,printOption,print);
List<String> imageKeys = new ArrayList<String>();
List<List<DataObject>> mosSets = new ArrayList<List<DataObject>>();
if(otptArtclNm.equals("crdnPhoto")) {
imageKeys = this.format.getMappingValues(otptArtclNm+"Key",defaultValue,forPost,dataObject,printOption,print);
if(rprsCrdnPhotoYn && imagePaths.size() > 0) {
imageKeys.remove(0);
}
for(String imageKey : imageKeys) {
mosSets.add(this.format.getMosSet(imageKey, dataObject));
}
}
if(otptArtclNm.equals("crdnPhoto")) {
if(rprsCrdnPhotoYn && imagePaths.size() > 0) {
imagePaths.remove(0);
}
}
int printCntSetting = otptBscStng.number("OTPT_PHOTO_CNT").intValue();
int dataImageCnt = imagePaths.size();
if(printCntSetting != 0 && dataImageCnt != 0) {
List<PstnAndSize> devideInfos = this.devideImageArea(pstn, size, printCntSetting, dataImageCnt);
for (int i=0; i< devideInfos.size(); i++){
PstnAndSize devideInfo = devideInfos.get(i);
if(EgovStringUtil.null2void(imagePaths.get(i)).equals("")) {
continue;
}
if(!imagePaths.get(i).startsWith("files")) {
imagePaths.set(i, CmmnUtil.copyStaticResource(imagePaths.get(i), false));
}
String imagePath = imagePaths.get(i);
File imageFile = new File(imagePath);
InputStream is = new FileInputStream(imageFile);
this.insertImage(doc, contentStream, is,
devideInfo.getPstn().to2Float(), devideInfo.getSize().to2Float());
if(otptArtclNm.equals("crdnPhoto") && !imageKeys.isEmpty() && !mosSets.isEmpty()) {
if(mosSets.get(i) != null) {
String imagePath0 = imagePaths.get(i);
File imageFile0 = new File(imagePath0);
InputStream is0 = new FileInputStream(imageFile0);
List<PstnAndSize> transformedMosaicInfos = MediaUtil.getTransformedMosaic(
mosSets.get(i), is0, devideInfo
);
for(int k=0; k < transformedMosaicInfos.size(); k++) {
PstnAndSize mosaicInfo = transformedMosaicInfos.get(k);
InputStream blackImageStream = new ClassPathResource("samplefiles/black.png").getInputStream();
this.insertImage(doc, contentStream, blackImageStream,
mosaicInfo.getPstn().to2Float(), mosaicInfo.getSize().to2Float());
}
}
}
}
}
}
}//출력항목 loop 끝
if(!completeFoldLine) {
if(!otptBscStng.string("FOLD_LINE_PSTN_SE_CD").equals("")) {
this.renderFoldLine(contentStream, paper, otptBscStng.string("FOLD_LINE_PSTN_SE_CD"));
}
}
contentStream.close();
} //출력자료건수 loop 끝
doc.save(resultFilePath);
doc.close();
String downloadFileName = print.getFormatKorName()+"_"+print.getPrintRequestDt()+".pdf";
result.put("filename", downloadFileName);
result.put("filePath", resultFilePath);
result.put("file", new File(resultFilePath));
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("출력오류."+e);
}
return result;
}
public String filePathForNewFile() {
SimpleDateFormat ymdhmsFormat = new SimpleDateFormat("yyyyMMddHHmmss");
String currentTime = ymdhmsFormat.format(new Date());
String year = currentTime.substring(0, 4);
String month = currentTime.substring(4, 6);
String day = currentTime.substring(6, 8);
String fileResultRootPath = "files" + File.separator + "result" + File.separator + "print";
String fileResultFolderPath = fileResultRootPath
+ File.separator + year + File.separator + month + File.separator + day;
File formatFileResultFolder = new File(fileResultFolderPath);
if(!formatFileResultFolder.exists()) {
formatFileResultFolder.mkdirs();
}
String resultPdfPath = fileResultFolderPath
+ File.separator + currentTime + "_" + (print.getFileNameIndex()) + ".pdf";
print.setFileNameIndex(print.getFileNameIndex()+1);
return resultPdfPath;
}
/**
* mm pdf .
*/
public PDFCoordinate toPDFCoordinate(float[] XYmm) {
float Xmm = XYmm[0];
float Ymm = XYmm[1];
float Xpt = Print.mmToPt(Xmm);
float Ypt = Print.mmToPt(Ymm);
float YptMax = Print.mmToPt(this.paperMilimeter[1]);
return new PDFCoordinate(Xpt, Ypt, YptMax);
}
/**
* pdf .
*/
public void writeText(PDPageContentStream contentStream, String allText,
float[] XYmm, float textAreaWidth_mm, String align, String newLineYn,
PDType0Font font, int fontSize, RenderingMode fontStyle, PDColor fontColor) {
try {
if(allText == null) {
allText = "";
}
if(newLineYn == null || newLineYn.equals("")) {
newLineYn = "N";
}
float[] xyAbsolute = this.toPDFCoordinate(XYmm).absolute();
float textAreaWidth_pt = Print.mmToPt(textAreaWidth_mm);
float allTextWidth = calcTextWidth(font, fontSize, allText);
String textArr[];
if(allText.equals("") || allText.length() == 1 || textAreaWidth_pt == 0
|| (allTextWidth <= textAreaWidth_pt)
|| newLineYn.equals("N")) {
textArr = new String[] { allText };
} else {
textArr = splitByLineForLargeText(font, fontSize, allText, textAreaWidth_pt);
}
String firstLine = textArr[0];
float firstLineWidth = calcTextWidth(font, fontSize, firstLine);
contentStream.beginText();
contentStream.setFont(font, fontSize);
contentStream.setRenderingMode(fontStyle);
contentStream.setNonStrokingColor(fontColor);
float resultY = xyAbsolute[1] - fontSize;
float firstLineAlignCorrection = 0;
if(align.equals("right")) {
firstLineAlignCorrection = textAreaWidth_pt - firstLineWidth;
} else if(align.equals("center")) {
firstLineAlignCorrection = (textAreaWidth_pt - firstLineWidth)/2.0f;
}
float resultX = xyAbsolute[0] + firstLineAlignCorrection;
contentStream.newLineAtOffset(resultX, resultY);
contentStream.showText(textArr[0]);
if(textArr.length > 1) {
float beforeLineWidth = firstLineWidth;
for(int i = 1; i < textArr.length; i++) {
String thisLine = textArr[i];
float thisLineWidth = this.calcTextWidth(font, fontSize, thisLine);
float alignCorrection = 0;
if(align.equals("right")) {
alignCorrection = beforeLineWidth - thisLineWidth;
} if(align.equals("center")) {
alignCorrection = (beforeLineWidth - thisLineWidth)/2.0f;
}
contentStream.newLineAtOffset(alignCorrection, -(fontSize + 1));
contentStream.showText(thisLine);
beforeLineWidth = thisLineWidth;
}
}
contentStream.endText();
} catch (IOException e) {
throw new RuntimeException("PDF 파일 출력 중 오류가 발생하였습니다."+e);
}
}
/**
* , (pt) .
*/
public float calcTextWidth(PDType0Font font, int fontSize, String text) {
try {
return (font.getStringWidth(text) / 1000.0f) * fontSize;
} catch (IOException e) {
throw new RuntimeException("PDF 파일 출력 중 오류가 발생하였습니다.");
}
}
/**
* .
*/
public String[] splitByLineForLargeText(PDType0Font font, int fontSize, String allText, float textAreaWidth_pt) {
float allTextWidth = calcTextWidth(font, fontSize, allText);
if(allText.equals("") || allText.length() == 1 || textAreaWidth_pt == 0
|| (allTextWidth <= textAreaWidth_pt)
) {
return new String[] { allText };
}
ArrayList<String> textList = new ArrayList<String>();
while(!allText.equals("")) {
int lengthForLine = this.getLengthForLine(font, fontSize, allText, textAreaWidth_pt);
String newLine = allText.substring(0,lengthForLine);
textList.add(newLine);
allText = allText.substring(lengthForLine);
}
return textList.toArray(new String[textList.size()]);
}
/**
* .
*/
private int getLengthForLine(PDType0Font font, int fontSize, String allText, float textAreaWidth_pt) {
int forLine = allText.length();
if(forLine <= 1) {
return forLine;
};
for( ; ; forLine--) {
if(forLine == 1) {
break;
}
boolean hit = ( this.calcTextWidth(font, fontSize, allText.substring(0, forLine)) <= textAreaWidth_pt );
if(hit) {
break;
}
}
return forLine;
}
/**
* pdf .
*/
public void insertImage(PDDocument doc, PDPageContentStream contentStream, InputStream imageStream, float[] XYmm,
float[] SIZEmm) {
float[] xyAbsolute = this.toPDFCoordinate(XYmm).absolute();
float[] size = new float[] {
Print.mmToPt(SIZEmm[0]),Print.mmToPt(SIZEmm[1])
};
try {
PDImageXObject image = PDImageXObject.createFromByteArray(doc, imageStream.readAllBytes(), "temp");
contentStream.drawImage(image, xyAbsolute[0], xyAbsolute[1]-size[1], size[0], size[1]);
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("PDF 파일 출력 중 오류가 발생하였습니다."+e);
}
}
public List<PstnAndSize> devideImageArea(float[] totAreaPstn, float[] totAreaSize, int imageCntSetting, int dataImageCnt) {
List<PstnAndSize> result = new ArrayList<PstnAndSize>();
int printable = imageCntSetting <= dataImageCnt ? imageCntSetting : dataImageCnt;
if(printable <= 1) {
result.add(new PstnAndSize(totAreaPstn[0], totAreaPstn[1], totAreaSize[0], totAreaSize[1]));
return result;
}
boolean longerThenWidth = totAreaSize[1] > totAreaSize[0];
int xLengthOfD2 = 0;
int yLengthOfD2 = 0;
if(printable == 2){
if(longerThenWidth) {
xLengthOfD2 = 1;
yLengthOfD2 = 2;
} else {
xLengthOfD2 = 2;
yLengthOfD2 = 1;
}
} else if(printable == 3 || printable == 4){
xLengthOfD2 = 2;
yLengthOfD2 = 2;
} else if(printable == 5 || printable == 6){
if(longerThenWidth) {
xLengthOfD2 = 2;
yLengthOfD2 = 3;
} else {
xLengthOfD2 = 3;
yLengthOfD2 = 2;
}
} else {
throw new RuntimeException("PDF 파일 출력 중 오류가 발생하였습니다.");
}
PstnAndSize[][] d2Array = new PstnAndSize[xLengthOfD2][yLengthOfD2];
Size cellSize = new Size(totAreaSize[0] / (xLengthOfD2 * 1.0f), totAreaSize[1] / (yLengthOfD2 * 1.0f));
d2Array[0][0] = new PstnAndSize(totAreaPstn[0], totAreaPstn[1], cellSize.getWidth(), cellSize.getHeight());
d2Array = this.fillImageCells(d2Array);
//출력영역 크기 병합
if(printable == 3 || printable == 5) {
boolean longerThenWidth_cell = cellSize.getHeight() > cellSize.getWidth();
if(longerThenWidth_cell) {
d2Array = this.mergeLastImageCell(d2Array, "left");
} else {
d2Array = this.mergeLastImageCell(d2Array, "up");
}
}
for(int y=0; y < yLengthOfD2; y++) {
for(int x=0; x < xLengthOfD2; x++) {
if(d2Array[x][y] != null) {
result.add(d2Array[x][y]);
}
}
}
return result;
}
private PstnAndSize[][] fillImageCells(PstnAndSize[][] d2) {
int xLengthOfD2 = d2.length;
int yLengthOfD2 = d2[0].length;
PstnAndSize firstCell = d2[0][0];
Size cellSize = firstCell.getSize();
float cellWidth = cellSize.getWidth();
float cellHeight = cellSize.getHeight();
Pstn startPoint = firstCell.getPstn();
float spX = startPoint.getLeft();
float spY = startPoint.getTop();
for(int x=0; x < xLengthOfD2; x++) {
for(int y=0; y < yLengthOfD2; y++) {
if(x != 0 || y != 0) {
d2[x][y] = new PstnAndSize(spX + (cellWidth * (x * 1.0f)), spY + (cellHeight * (y * 1.0f)), cellSize);
}
}
}
return d2;
}
public PstnAndSize[][] mergeLastImageCell(PstnAndSize[][] d2, String mergeDirection) {
if(!mergeDirection.equals("up") && !mergeDirection.equals("left")) {
throw new RuntimeException("PDF 파일 출력 중 오류가 발생하였습니다.");
}
int xLengthOfD2 = d2.length;
int yLengthOfD2 = d2[0].length;
int lastCellIndexX = xLengthOfD2-1;
int lastCellIndexY = yLengthOfD2-1;
int mergeTargetCellIndexX = 0;
int mergeTargetCellIndexY = 0;
if(mergeDirection.equals("up")) {
mergeTargetCellIndexX = lastCellIndexX;
mergeTargetCellIndexY = lastCellIndexY-1;
}
if(mergeDirection.equals("left")) {
mergeTargetCellIndexX = lastCellIndexX-1;
mergeTargetCellIndexY = lastCellIndexY;
}
//병합대상셀
if(mergeDirection.equals("up")) {
d2[mergeTargetCellIndexX][mergeTargetCellIndexY] = (d2[mergeTargetCellIndexX][mergeTargetCellIndexY]).x2Height();
}
if(mergeDirection.equals("left")) {
d2[mergeTargetCellIndexX][mergeTargetCellIndexY] = (d2[mergeTargetCellIndexX][mergeTargetCellIndexY]).x2Width();
}
//마지막셀
d2[lastCellIndexX][lastCellIndexY] = null;
return d2;
}
/**
* pdf .
*/
public void renderFoldLine(PDPageContentStream contentStream, PDRectangle paper, String foldCode) {
if(foldCode.equals("") && !foldCode.equals("01") && !foldCode.equals("02")) {
return;
}
float paperWidth = paper.getWidth();
float partHeight;
if(foldCode.equals("01")) {
if(paper.A4.equals(paper)) {
partHeight = 99;
} else {
partHeight = 93;
}
} else {
partHeight = 93;
}
float margin = 0;
if(foldCode.equals("02")) {
margin = 18;
}
float bottomFold = margin + partHeight; //하단접는곳
float topFold = margin + (partHeight * 2); //상단접는곳
float bottomFold_pt = Print.mmToPt(bottomFold);
float topFold_pt = Print.mmToPt(topFold);
try {
contentStream.setLineDashPattern(new float[]{3,1}, 0);
contentStream.moveTo(0, topFold_pt);
contentStream.lineTo(paperWidth, topFold_pt);
contentStream.stroke();
contentStream.moveTo(0, bottomFold_pt);
contentStream.lineTo(paperWidth, bottomFold_pt);
contentStream.stroke();
contentStream.setLineDashPattern(new float[]{}, 0);
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("PDF 파일 출력 중 오류가 발생하였습니다."+e);
}
}
public float[] getPstnStng(DefaultOtptArtclStng prototypeStng, DataObject sggStng, String paperSeCd) {
if(!sggStng.string("LEFT_PSTN").equals("") && !sggStng.string("TOP_PSTN").equals("")) {
return new float[] {
sggStng.number("LEFT_PSTN").floatValue(),
sggStng.number("TOP_PSTN").floatValue()
};
} else {
return new float[] {
prototypeStng.getLeftPstn(paperSeCd),
prototypeStng.getTopPstn(paperSeCd)
};
}
}
public PDType0Font getFontType(DefaultOtptArtclStng prototypeStng, DataObject sggStng, Map<String, PDType0Font> fontMap) {
if(sggStng != null && !sggStng.isEmpty() && !sggStng.string("FONT_NM").equals("")) {
return fontMap.get(sggStng.string("FONT_NM"));
} else {
return fontMap.get(prototypeStng.getFontNm());
}
}
public int getFontSize(DefaultOtptArtclStng prototypeStng, DataObject sggStng) {
if(!sggStng.string("FONT_SZ").equals("")) {
return sggStng.number("FONT_SZ").intValue();
} else {
return prototypeStng.getFontSz();
}
}
public RenderingMode getFontStyle(DefaultOtptArtclStng prototypeStng, DataObject sggStng) {
if(!sggStng.string("FONT_STYLE").equals("")) {
return RenderingMode.valueOf(sggStng.string("FONT_STYLE"));
} else {
return RenderingMode.valueOf(prototypeStng.getFontStyle());
}
}
public PDColor getFontColor(DefaultOtptArtclStng prototypeStng, DataObject sggStng) {
if(!sggStng.string("FONT_COLOR").equals("")) {
return PDFColors.getColor(sggStng.string("FONT_COLOR"));
} else {
return PDFColors.getColor(prototypeStng.getFontColor());
}
}
public float[] getSize(DefaultOtptArtclStng prototypeStng, DataObject sggStng) {
if(!sggStng.string("WIDTH_SZ").equals("")) {
return new float[] {
sggStng.number("WIDTH_SZ").floatValue(),
sggStng.number("HEIGHT_SZ").floatValue()
};
} else {
return new float[] {
prototypeStng.getWidthSz(),
prototypeStng.getHeightSz()
};
}
}
public String getAlign(DefaultOtptArtclStng prototypeStng, DataObject sggStng) {
if(!sggStng.string("TEXT_SORT").equals("")) {
return sggStng.string("TEXT_SORT");
} else {
return prototypeStng.getTextSort();
}
}
public String getLineChgYn(DefaultOtptArtclStng prototypeStng, DataObject sggStng) {
if(!sggStng.string("LINE_CHG_YN").equals("")) {
return sggStng.string("LINE_CHG_YN");
} else {
return prototypeStng.getLineChgYn();
}
}
public Map<String, PDType0Font> getFontMap(PDDocument doc) {
try {
Map<String, PDType0Font> fontMap = Map.of(
"notokrBold", PDType0Font.load(doc, new ClassPathResource("fonts/notokr-bold.ttf").getInputStream()),
"gulim", PDType0Font.load(doc, new ClassPathResource("fonts/gulim.ttf").getInputStream()),
"gulimche", PDType0Font.load(doc, new ClassPathResource("fonts/gulimche.ttf").getInputStream()),
"batang", PDType0Font.load(doc, new ClassPathResource("fonts/batang.ttf").getInputStream()),
"batangche", PDType0Font.load(doc, new ClassPathResource("fonts/batangche.ttf").getInputStream()),
"dotum", PDType0Font.load(doc, new ClassPathResource("fonts/dotum.ttf").getInputStream()),
"dotumche", PDType0Font.load(doc, new ClassPathResource("fonts/dotumche.ttf").getInputStream()),
"gungsuh", PDType0Font.load(doc, new ClassPathResource("fonts/gungsuh.ttf").getInputStream()),
"gungsuhche", PDType0Font.load(doc, new ClassPathResource("fonts/gungsuhche.ttf").getInputStream())
);
return fontMap;
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("글꼴 로드 오류"+e);
}
}
} }

@ -68,10 +68,7 @@ public class Print {
return this.fileNameIndex = fileNameIndex; return this.fileNameIndex = fileNameIndex;
} }
public static float mmToPt(float mm) {
public float mmToPt(float mm) {
return mm * 2.83465f; return mm * 2.83465f;
} }

@ -64,7 +64,6 @@ public class CvlcptOrgn extends HWPFormat {
try { try {
if(dataObject.string("PHOTO0") != null && !dataObject.string("PHOTO0").equals("")) { if(dataObject.string("PHOTO0") != null && !dataObject.string("PHOTO0").equals("")) {
System.out.println("원본사진있음");
int photoCnt = dataObject.number("ORGN_PHOTO_CNT").intValue(); int photoCnt = dataObject.number("ORGN_PHOTO_CNT").intValue();
int PHOTO_COUNT_PER_PAGE = 4; int PHOTO_COUNT_PER_PAGE = 4;
@ -84,8 +83,6 @@ public class CvlcptOrgn extends HWPFormat {
} }
} else {
System.out.println("원본사진없음");
} }
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException("[F]"+e); throw new RuntimeException("[F]"+e);

@ -1,518 +1,11 @@
package cokr.xit.fims.cmmn.pdf.print; package cokr.xit.fims.cmmn.pdf.print;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.apache.pdfbox.pdmodel.common.PDRectangle;
import org.apache.pdfbox.pdmodel.font.PDType0Font;
import org.apache.pdfbox.pdmodel.graphics.color.PDColor;
import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject;
import org.apache.pdfbox.pdmodel.graphics.state.RenderingMode;
import org.springframework.core.io.ClassPathResource;
import cokr.xit.fims.cmmn.Print; import cokr.xit.fims.cmmn.Print;
import cokr.xit.fims.cmmn.pdf.PDFColors;
import cokr.xit.fims.cmmn.pdf.PDFCoordinate;
import cokr.xit.fims.cmmn.pdf.Pstn;
import cokr.xit.fims.cmmn.pdf.PstnAndSize;
import cokr.xit.fims.cmmn.pdf.Size;
import cokr.xit.foundation.data.DataObject;
public class PDFPrintUtil extends Print { public class PDFPrintUtil extends Print {
private float[] paperMilimeter = new float[2];
public void setting(String paperType) {
if(paperType.equals("01")) {
this.paperMilimeter = new float[] {210.0f , 297.0f};
} else if(paperType.equals("02")){
this.paperMilimeter = new float[] {216.0f , 279.0f};
}
}
public String filePathForNewFile() {
SimpleDateFormat ymdhmsFormat = new SimpleDateFormat("yyyyMMddHHmmss");
String currentTime = ymdhmsFormat.format(new Date());
String year = currentTime.substring(0, 4);
String month = currentTime.substring(4, 6);
String day = currentTime.substring(6, 8);
String fileResultRootPath = "files" + File.separator + "result" + File.separator + "print";
String fileResultFolderPath = fileResultRootPath
+ File.separator + year + File.separator + month + File.separator + day;
File formatFileResultFolder = new File(fileResultFolderPath);
if(!formatFileResultFolder.exists()) {
formatFileResultFolder.mkdirs();
}
String resultPdfPath = fileResultFolderPath
+ File.separator + currentTime + "_" + (this.fileNameIndex++) + ".pdf";
return resultPdfPath;
}
/**
* mm pdf .
*/
public PDFCoordinate toPDFCoordinate(float[] XYmm) {
float Xmm = XYmm[0];
float Ymm = XYmm[1];
float Xpt = mmToPt(Xmm);
float Ypt = mmToPt(Ymm);
float YptMax = mmToPt(this.paperMilimeter[1]);
return new PDFCoordinate(Xpt, Ypt, YptMax);
}
/**
* pdf .
*/
public void writeText(PDPageContentStream contentStream, String allText,
float[] XYmm, float textAreaWidth_mm, String align, String newLineYn,
PDType0Font font, int fontSize, RenderingMode fontStyle, PDColor fontColor) {
try {
if(allText == null) {
allText = "";
}
if(newLineYn == null || newLineYn.equals("")) {
newLineYn = "N";
}
float[] xyAbsolute = this.toPDFCoordinate(XYmm).absolute();
float textAreaWidth_pt = mmToPt(textAreaWidth_mm);
float allTextWidth = calcTextWidth(font, fontSize, allText);
String textArr[];
if(allText.equals("") || allText.length() == 1 || textAreaWidth_pt == 0
|| (allTextWidth <= textAreaWidth_pt)
|| newLineYn.equals("N")) {
textArr = new String[] { allText };
} else {
textArr = splitByLineForLargeText(font, fontSize, allText, textAreaWidth_pt);
}
String firstLine = textArr[0];
float firstLineWidth = calcTextWidth(font, fontSize, firstLine);
contentStream.beginText();
contentStream.setFont(font, fontSize);
contentStream.setRenderingMode(fontStyle);
contentStream.setNonStrokingColor(fontColor);
float resultY = xyAbsolute[1] - fontSize;
float firstLineAlignCorrection = 0;
if(align.equals("right")) {
firstLineAlignCorrection = textAreaWidth_pt - firstLineWidth;
} else if(align.equals("center")) {
firstLineAlignCorrection = (textAreaWidth_pt - firstLineWidth)/2.0f;
}
float resultX = xyAbsolute[0] + firstLineAlignCorrection;
contentStream.newLineAtOffset(resultX, resultY);
contentStream.showText(textArr[0]);
if(textArr.length > 1) {
float beforeLineWidth = firstLineWidth;
for(int i = 1; i < textArr.length; i++) {
String thisLine = textArr[i];
float thisLineWidth = this.calcTextWidth(font, fontSize, thisLine);
float alignCorrection = 0;
if(align.equals("right")) {
alignCorrection = beforeLineWidth - thisLineWidth;
} if(align.equals("center")) {
alignCorrection = (beforeLineWidth - thisLineWidth)/2.0f;
}
contentStream.newLineAtOffset(alignCorrection, -(fontSize + 1));
contentStream.showText(thisLine);
beforeLineWidth = thisLineWidth;
}
}
contentStream.endText();
} catch (IOException e) {
throw new RuntimeException("PDF 파일 출력 중 오류가 발생하였습니다."+e);
}
}
/**
* , (pt) .
*/
public float calcTextWidth(PDType0Font font, int fontSize, String text) {
try {
return (font.getStringWidth(text) / 1000.0f) * fontSize;
} catch (IOException e) {
throw new RuntimeException("PDF 파일 출력 중 오류가 발생하였습니다.");
}
}
/**
* .
*/
public String[] splitByLineForLargeText(PDType0Font font, int fontSize, String allText, float textAreaWidth_pt) {
float allTextWidth = calcTextWidth(font, fontSize, allText);
if(allText.equals("") || allText.length() == 1 || textAreaWidth_pt == 0
|| (allTextWidth <= textAreaWidth_pt)
) {
return new String[] { allText };
}
ArrayList<String> textList = new ArrayList<String>();
while(!allText.equals("")) {
int lengthForLine = this.getLengthForLine(font, fontSize, allText, textAreaWidth_pt);
String newLine = allText.substring(0,lengthForLine);
textList.add(newLine);
allText = allText.substring(lengthForLine);
}
return textList.toArray(new String[textList.size()]);
}
/**
* .
*/
private int getLengthForLine(PDType0Font font, int fontSize, String allText, float textAreaWidth_pt) {
int forLine = allText.length();
if(forLine <= 1) {
return forLine;
};
for( ; ; forLine--) {
if(forLine == 1) {
break;
}
boolean hit = ( this.calcTextWidth(font, fontSize, allText.substring(0, forLine)) <= textAreaWidth_pt );
if(hit) {
break;
}
}
return forLine;
}
/**
* pdf .
*/
public void insertImage(PDDocument doc, PDPageContentStream contentStream, InputStream imageStream, float[] XYmm,
float[] SIZEmm) {
float[] xyAbsolute = this.toPDFCoordinate(XYmm).absolute();
float[] size = new float[] {
mmToPt(SIZEmm[0]),mmToPt(SIZEmm[1])
};
try {
PDImageXObject image = PDImageXObject.createFromByteArray(doc, imageStream.readAllBytes(), "temp");
contentStream.drawImage(image, xyAbsolute[0], xyAbsolute[1]-size[1], size[0], size[1]);
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("PDF 파일 출력 중 오류가 발생하였습니다."+e);
}
}
public List<PstnAndSize> devideImageArea(float[] totAreaPstn, float[] totAreaSize, int imageCntSetting, int dataImageCnt) {
List<PstnAndSize> result = new ArrayList<PstnAndSize>();
int printable = imageCntSetting <= dataImageCnt ? imageCntSetting : dataImageCnt;
if(printable <= 1) {
result.add(new PstnAndSize(totAreaPstn[0], totAreaPstn[1], totAreaSize[0], totAreaSize[1]));
return result;
}
boolean longerThenWidth = totAreaSize[1] > totAreaSize[0];
int xLengthOfD2 = 0;
int yLengthOfD2 = 0;
if(printable == 2){
if(longerThenWidth) {
xLengthOfD2 = 1;
yLengthOfD2 = 2;
} else {
xLengthOfD2 = 2;
yLengthOfD2 = 1;
}
} else if(printable == 3 || printable == 4){
xLengthOfD2 = 2;
yLengthOfD2 = 2;
} else if(printable == 5 || printable == 6){
if(longerThenWidth) {
xLengthOfD2 = 2;
yLengthOfD2 = 3;
} else {
xLengthOfD2 = 3;
yLengthOfD2 = 2;
}
} else {
throw new RuntimeException("PDF 파일 출력 중 오류가 발생하였습니다.");
}
PstnAndSize[][] d2Array = new PstnAndSize[xLengthOfD2][yLengthOfD2];
Size cellSize = new Size(totAreaSize[0] / (xLengthOfD2 * 1.0f), totAreaSize[1] / (yLengthOfD2 * 1.0f));
d2Array[0][0] = new PstnAndSize(totAreaPstn[0], totAreaPstn[1], cellSize.getWidth(), cellSize.getHeight());
d2Array = this.fillImageCells(d2Array);
//출력영역 크기 병합
if(printable == 3 || printable == 5) {
boolean longerThenWidth_cell = cellSize.getHeight() > cellSize.getWidth();
if(longerThenWidth_cell) {
d2Array = this.mergeLastImageCell(d2Array, "left");
} else {
d2Array = this.mergeLastImageCell(d2Array, "up");
}
}
for(int y=0; y < yLengthOfD2; y++) {
for(int x=0; x < xLengthOfD2; x++) {
if(d2Array[x][y] != null) {
result.add(d2Array[x][y]);
}
}
}
return result;
}
private PstnAndSize[][] fillImageCells(PstnAndSize[][] d2) {
int xLengthOfD2 = d2.length;
int yLengthOfD2 = d2[0].length;
PstnAndSize firstCell = d2[0][0];
Size cellSize = firstCell.getSize();
float cellWidth = cellSize.getWidth();
float cellHeight = cellSize.getHeight();
Pstn startPoint = firstCell.getPstn();
float spX = startPoint.getLeft();
float spY = startPoint.getTop();
for(int x=0; x < xLengthOfD2; x++) {
for(int y=0; y < yLengthOfD2; y++) {
if(x != 0 || y != 0) {
d2[x][y] = new PstnAndSize(spX + (cellWidth * (x * 1.0f)), spY + (cellHeight * (y * 1.0f)), cellSize);
}
}
}
return d2;
}
public PstnAndSize[][] mergeLastImageCell(PstnAndSize[][] d2, String mergeDirection) {
if(!mergeDirection.equals("up") && !mergeDirection.equals("left")) {
throw new RuntimeException("PDF 파일 출력 중 오류가 발생하였습니다.");
}
int xLengthOfD2 = d2.length;
int yLengthOfD2 = d2[0].length;
int lastCellIndexX = xLengthOfD2-1;
int lastCellIndexY = yLengthOfD2-1;
int mergeTargetCellIndexX = 0;
int mergeTargetCellIndexY = 0;
if(mergeDirection.equals("up")) {
mergeTargetCellIndexX = lastCellIndexX;
mergeTargetCellIndexY = lastCellIndexY-1;
}
if(mergeDirection.equals("left")) {
mergeTargetCellIndexX = lastCellIndexX-1;
mergeTargetCellIndexY = lastCellIndexY;
}
//병합대상셀
if(mergeDirection.equals("up")) {
d2[mergeTargetCellIndexX][mergeTargetCellIndexY] = (d2[mergeTargetCellIndexX][mergeTargetCellIndexY]).x2Height();
}
if(mergeDirection.equals("left")) {
d2[mergeTargetCellIndexX][mergeTargetCellIndexY] = (d2[mergeTargetCellIndexX][mergeTargetCellIndexY]).x2Width();
}
//마지막셀
d2[lastCellIndexX][lastCellIndexY] = null;
return d2;
}
/**
* pdf .
*/
public void renderFoldLine(PDPageContentStream contentStream, PDRectangle paper, String foldCode) {
if(foldCode.equals("") && !foldCode.equals("01") && !foldCode.equals("02")) {
return;
}
float paperWidth = paper.getWidth();
float partHeight;
if(foldCode.equals("01")) {
if(paper.A4.equals(paper)) {
partHeight = 99;
} else {
partHeight = 93;
}
} else {
partHeight = 93;
}
float margin = 0;
if(foldCode.equals("02")) {
margin = 18;
}
float bottomFold = margin + partHeight; //하단접는곳
float topFold = margin + (partHeight * 2); //상단접는곳
float bottomFold_pt = mmToPt(bottomFold);
float topFold_pt = mmToPt(topFold);
try {
contentStream.setLineDashPattern(new float[]{3,1}, 0);
contentStream.moveTo(0, topFold_pt);
contentStream.lineTo(paperWidth, topFold_pt);
contentStream.stroke();
contentStream.moveTo(0, bottomFold_pt);
contentStream.lineTo(paperWidth, bottomFold_pt);
contentStream.stroke();
contentStream.setLineDashPattern(new float[]{}, 0);
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("PDF 파일 출력 중 오류가 발생하였습니다."+e);
}
}
public float[] getPstnStng(DefaultOtptArtclStng prototypeStng, DataObject sggStng, String paperSeCd) {
if(!sggStng.string("LEFT_PSTN").equals("") && !sggStng.string("TOP_PSTN").equals("")) {
return new float[] {
sggStng.number("LEFT_PSTN").floatValue(),
sggStng.number("TOP_PSTN").floatValue()
};
} else {
return new float[] {
prototypeStng.getLeftPstn(paperSeCd),
prototypeStng.getTopPstn(paperSeCd)
};
}
}
public PDType0Font getFontType(DefaultOtptArtclStng prototypeStng, DataObject sggStng, Map<String, PDType0Font> fontMap) {
if(sggStng != null && !sggStng.isEmpty() && !sggStng.string("FONT_NM").equals("")) {
return fontMap.get(sggStng.string("FONT_NM"));
} else {
return fontMap.get(prototypeStng.getFontNm());
}
}
public int getFontSize(DefaultOtptArtclStng prototypeStng, DataObject sggStng) {
if(!sggStng.string("FONT_SZ").equals("")) {
return sggStng.number("FONT_SZ").intValue();
} else {
return prototypeStng.getFontSz();
}
}
public RenderingMode getFontStyle(DefaultOtptArtclStng prototypeStng, DataObject sggStng) {
if(!sggStng.string("FONT_STYLE").equals("")) {
return RenderingMode.valueOf(sggStng.string("FONT_STYLE"));
} else {
return RenderingMode.valueOf(prototypeStng.getFontStyle());
}
}
public PDColor getFontColor(DefaultOtptArtclStng prototypeStng, DataObject sggStng) {
if(!sggStng.string("FONT_COLOR").equals("")) {
return PDFColors.getColor(sggStng.string("FONT_COLOR"));
} else {
return PDFColors.getColor(prototypeStng.getFontColor());
}
}
public float[] getSize(DefaultOtptArtclStng prototypeStng, DataObject sggStng) {
if(!sggStng.string("WIDTH_SZ").equals("")) {
return new float[] {
sggStng.number("WIDTH_SZ").floatValue(),
sggStng.number("HEIGHT_SZ").floatValue()
};
} else {
return new float[] {
prototypeStng.getWidthSz(),
prototypeStng.getHeightSz()
};
}
}
public String getAlign(DefaultOtptArtclStng prototypeStng, DataObject sggStng) {
if(!sggStng.string("TEXT_SORT").equals("")) {
return sggStng.string("TEXT_SORT");
} else {
return prototypeStng.getTextSort();
}
}
public String getLineChgYn(DefaultOtptArtclStng prototypeStng, DataObject sggStng) {
if(!sggStng.string("LINE_CHG_YN").equals("")) {
return sggStng.string("LINE_CHG_YN");
} else {
return prototypeStng.getLineChgYn();
}
}
public Map<String, PDType0Font> getFontMap(PDDocument doc) {
try {
Map<String, PDType0Font> fontMap = Map.of(
"notokrBold", PDType0Font.load(doc, new ClassPathResource("fonts/notokr-bold.ttf").getInputStream()),
"gulim", PDType0Font.load(doc, new ClassPathResource("fonts/gulim.ttf").getInputStream()),
"gulimche", PDType0Font.load(doc, new ClassPathResource("fonts/gulimche.ttf").getInputStream()),
"batang", PDType0Font.load(doc, new ClassPathResource("fonts/batang.ttf").getInputStream()),
"batangche", PDType0Font.load(doc, new ClassPathResource("fonts/batangche.ttf").getInputStream()),
"dotum", PDType0Font.load(doc, new ClassPathResource("fonts/dotum.ttf").getInputStream()),
"dotumche", PDType0Font.load(doc, new ClassPathResource("fonts/dotumche.ttf").getInputStream()),
"gungsuh", PDType0Font.load(doc, new ClassPathResource("fonts/gungsuh.ttf").getInputStream()),
"gungsuhche", PDType0Font.load(doc, new ClassPathResource("fonts/gungsuhche.ttf").getInputStream())
);
return fontMap;
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("글꼴 로드 오류"+e);
}
}
} }

@ -5,7 +5,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import cokr.xit.fims.cmmn.CmmnUtil; import cokr.xit.fims.cmmn.CmmnUtil;
import cokr.xit.fims.cmmn.pdf.print.PDFPrintUtil; import cokr.xit.fims.cmmn.Print;
import cokr.xit.fims.mngt.FactionUtil; import cokr.xit.fims.mngt.FactionUtil;
import cokr.xit.fims.sprt.PrintOption; import cokr.xit.fims.sprt.PrintOption;
import cokr.xit.foundation.data.DataFormat; import cokr.xit.foundation.data.DataFormat;
@ -16,6 +16,14 @@ import cokr.xit.foundation.data.DataObject;
*/ */
public class Advntce extends PDFPrintFormat { public class Advntce extends PDFPrintFormat {
@Override
public void setting(Print print) {
print.setFormatKorName("사전통지서");
this.sndngSeCd = "02";
}
public Advntce(){ public Advntce(){
addForPost( addForPost(
image("postSenderLogo","우편물송신자로고","").a4(10, 0).letter(10, 0).size(0, 0), image("postSenderLogo","우편물송신자로고","").a4(10, 0).letter(10, 0).size(0, 0),
@ -88,11 +96,11 @@ public class Advntce extends PDFPrintFormat {
*/ */
@Override @Override
public String getMappingValue(String otptArtclNm, String defaultValue, boolean forPost, public String getMappingValue(String otptArtclNm, String defaultValue, boolean forPost,
DataObject dataObject, PrintOption printOption, PDFPrintUtil pdfPrintUtil) { DataObject dataObject, PrintOption printOption, Print print) {
String result = ""; String result = "";
if(forPost) { if(forPost) {
return this.getValueForPost(otptArtclNm, defaultValue, dataObject, printOption, pdfPrintUtil); return this.getValueForPost(otptArtclNm, defaultValue, dataObject, printOption, print);
} }
Map<String, String> globalVariable = printOption.getGlobalVariable(); Map<String, String> globalVariable = printOption.getGlobalVariable();
@ -199,23 +207,23 @@ public class Advntce extends PDFPrintFormat {
} }
case "otptYmd" -> { case "otptYmd" -> {
result = DataFormat.yyyy_mm_dd(pdfPrintUtil.getPrintRequestDt().substring(0,8)); result = DataFormat.yyyy_mm_dd(print.getPrintRequestDt().substring(0,8));
} }
case "otptDt" -> { case "otptDt" -> {
result = CmmnUtil.yyyy_mm_dd_hh_mm_ss(pdfPrintUtil.getPrintRequestDt()); result = CmmnUtil.yyyy_mm_dd_hh_mm_ss(print.getPrintRequestDt());
} }
case "otptYYYY" -> { case "otptYYYY" -> {
result = pdfPrintUtil.getPrintRequestDt().substring(0,4); result = print.getPrintRequestDt().substring(0,4);
} }
case "otptMM" -> { case "otptMM" -> {
result = pdfPrintUtil.getPrintRequestDt().substring(4,6); result = print.getPrintRequestDt().substring(4,6);
} }
case "otptDD" -> { case "otptDD" -> {
result = pdfPrintUtil.getPrintRequestDt().substring(6,8); result = print.getPrintRequestDt().substring(6,8);
} }
case "offcsText" -> { case "offcsText" -> {
String instNm = (String) pdfPrintUtil.getPrintRequestUserInfo().getInfo().get("instNm"); String instNm = (String) print.getPrintRequestUserInfo().getInfo().get("instNm");
instNm = FactionUtil.getLastWord(instNm); instNm = FactionUtil.getLastWord(instNm);
instNm = FactionUtil.getInstituteLeader(instNm, true); instNm = FactionUtil.getInstituteLeader(instNm, true);
result = instNm; result = instNm;
@ -237,7 +245,7 @@ public class Advntce extends PDFPrintFormat {
*/ */
@Override @Override
public String getValueForPost(String otptArtclNm, String defaultValue, public String getValueForPost(String otptArtclNm, String defaultValue,
DataObject dataObject, PrintOption printOption, PDFPrintUtil pdfPrintUtil) { DataObject dataObject, PrintOption printOption, Print print) {
String result = ""; String result = "";
switch(otptArtclNm) { switch(otptArtclNm) {
@ -257,10 +265,10 @@ public class Advntce extends PDFPrintFormat {
result = printOption.getGlobalVariable().get("logoFilePath"); result = printOption.getGlobalVariable().get("logoFilePath");
} }
case "postSenderInst" -> { case "postSenderInst" -> {
result = (String)pdfPrintUtil.getPrintRequestUserInfo().getInfo().get("instNm"); result = (String)print.getPrintRequestUserInfo().getInfo().get("instNm");
} }
case "postSenderDept" -> { case "postSenderDept" -> {
result = (String)pdfPrintUtil.getPrintRequestUserInfo().getInfo().get("deptNm"); result = (String)print.getPrintRequestUserInfo().getInfo().get("deptNm");
} }
case "postSenderAddr" -> { case "postSenderAddr" -> {
result = printOption.getGlobalVariable().get("instAddr"); result = printOption.getGlobalVariable().get("instAddr");
@ -285,7 +293,7 @@ public class Advntce extends PDFPrintFormat {
@Override @Override
public List<String> getMappingValues(String otptArtclNm, String defaultValue, boolean forPost, public List<String> getMappingValues(String otptArtclNm, String defaultValue, boolean forPost,
DataObject dataObject, PrintOption printOption, PDFPrintUtil pdfPrintUtil) { DataObject dataObject, PrintOption printOption, Print print) {
List<String> result = new ArrayList<String>(); List<String> result = new ArrayList<String>();
switch(otptArtclNm) { switch(otptArtclNm) {

@ -5,7 +5,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import cokr.xit.fims.cmmn.CmmnUtil; import cokr.xit.fims.cmmn.CmmnUtil;
import cokr.xit.fims.cmmn.pdf.print.PDFPrintUtil; import cokr.xit.fims.cmmn.Print;
import cokr.xit.fims.mngt.FactionUtil; import cokr.xit.fims.mngt.FactionUtil;
import cokr.xit.fims.sprt.PrintOption; import cokr.xit.fims.sprt.PrintOption;
import cokr.xit.foundation.data.DataFormat; import cokr.xit.foundation.data.DataFormat;
@ -13,6 +13,12 @@ import cokr.xit.foundation.data.DataObject;
public class Nht extends PDFPrintFormat { public class Nht extends PDFPrintFormat {
@Override
public void setting(Print print) {
print.setFormatKorName("고지서");
sndngSeCd = "03";
}
public Nht() { public Nht() {
addForPost( addForPost(
image("postSenderLogo","우편물송신자로고","").a4(10, 0).letter(10, 0).size(0, 0), image("postSenderLogo","우편물송신자로고","").a4(10, 0).letter(10, 0).size(0, 0),
@ -95,11 +101,11 @@ public class Nht extends PDFPrintFormat {
*/ */
@Override @Override
public String getMappingValue(String otptArtclNm, String defaultValue, boolean forPost, public String getMappingValue(String otptArtclNm, String defaultValue, boolean forPost,
DataObject dataObject, PrintOption printOption, PDFPrintUtil pdfPrintUtil) { DataObject dataObject, PrintOption printOption, Print print) {
String result = ""; String result = "";
if(forPost) { if(forPost) {
return this.getValueForPost(otptArtclNm, defaultValue, dataObject, printOption, pdfPrintUtil); return this.getValueForPost(otptArtclNm, defaultValue, dataObject, printOption, print);
} }
Map<String, String> globalVariable = printOption.getGlobalVariable(); Map<String, String> globalVariable = printOption.getGlobalVariable();
@ -267,23 +273,23 @@ public class Nht extends PDFPrintFormat {
} }
case "otptYmd" -> { case "otptYmd" -> {
result = DataFormat.yyyy_mm_dd(pdfPrintUtil.getPrintRequestDt().substring(0,8)); result = DataFormat.yyyy_mm_dd(print.getPrintRequestDt().substring(0,8));
} }
case "otptDt" -> { case "otptDt" -> {
result = CmmnUtil.yyyy_mm_dd_hh_mm_ss(pdfPrintUtil.getPrintRequestDt()); result = CmmnUtil.yyyy_mm_dd_hh_mm_ss(print.getPrintRequestDt());
} }
case "otptYYYY" -> { case "otptYYYY" -> {
result = pdfPrintUtil.getPrintRequestDt().substring(0,4); result = print.getPrintRequestDt().substring(0,4);
} }
case "otptMM" -> { case "otptMM" -> {
result = pdfPrintUtil.getPrintRequestDt().substring(4,6); result = print.getPrintRequestDt().substring(4,6);
} }
case "otptDD" -> { case "otptDD" -> {
result = pdfPrintUtil.getPrintRequestDt().substring(6,8); result = print.getPrintRequestDt().substring(6,8);
} }
case "offcsText" -> { case "offcsText" -> {
String instNm = (String) pdfPrintUtil.getPrintRequestUserInfo().getInfo().get("instNm"); String instNm = (String) print.getPrintRequestUserInfo().getInfo().get("instNm");
instNm = FactionUtil.getLastWord(instNm); instNm = FactionUtil.getLastWord(instNm);
instNm = FactionUtil.getInstituteLeader(instNm, true); instNm = FactionUtil.getInstituteLeader(instNm, true);
result = instNm; result = instNm;
@ -305,7 +311,7 @@ public class Nht extends PDFPrintFormat {
*/ */
@Override @Override
public String getValueForPost(String otptArtclNm, String defaultValue, public String getValueForPost(String otptArtclNm, String defaultValue,
DataObject dataObject, PrintOption printOption, PDFPrintUtil pdfPrintUtil) { DataObject dataObject, PrintOption printOption, Print print) {
String result = ""; String result = "";
switch(otptArtclNm) { switch(otptArtclNm) {
@ -325,10 +331,10 @@ public class Nht extends PDFPrintFormat {
result = printOption.getGlobalVariable().get("logoFilePath"); result = printOption.getGlobalVariable().get("logoFilePath");
} }
case "postSenderInst" -> { case "postSenderInst" -> {
result = (String)pdfPrintUtil.getPrintRequestUserInfo().getInfo().get("instNm"); result = (String)print.getPrintRequestUserInfo().getInfo().get("instNm");
} }
case "postSenderDept" -> { case "postSenderDept" -> {
result = (String)pdfPrintUtil.getPrintRequestUserInfo().getInfo().get("deptNm"); result = (String)print.getPrintRequestUserInfo().getInfo().get("deptNm");
} }
case "postSenderAddr" -> { case "postSenderAddr" -> {
result = printOption.getGlobalVariable().get("instAddr"); result = printOption.getGlobalVariable().get("instAddr");
@ -352,7 +358,7 @@ public class Nht extends PDFPrintFormat {
@Override @Override
public List<String> getMappingValues(String otptArtclNm, String defaultValue, boolean forPost, public List<String> getMappingValues(String otptArtclNm, String defaultValue, boolean forPost,
DataObject dataObject, PrintOption printOption, PDFPrintUtil pdfPrintUtil) { DataObject dataObject, PrintOption printOption, Print print) {
List<String> result = new ArrayList<String>(); List<String> result = new ArrayList<String>();
switch(otptArtclNm) { switch(otptArtclNm) {

@ -3,12 +3,16 @@ package cokr.xit.fims.cmmn.pdf.print.format;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import cokr.xit.fims.cmmn.Print;
import cokr.xit.fims.cmmn.pdf.print.DefaultOtptArtclStng; import cokr.xit.fims.cmmn.pdf.print.DefaultOtptArtclStng;
import cokr.xit.fims.cmmn.pdf.print.PDFPrintUtil;
import cokr.xit.fims.sprt.PrintOption; import cokr.xit.fims.sprt.PrintOption;
import cokr.xit.foundation.data.DataObject; import cokr.xit.foundation.data.DataObject;
public abstract class PDFPrintFormat { public abstract class PDFPrintFormat {
protected String sndngSeCd;
public abstract void setting(Print print);
protected List<DefaultOtptArtclStng> prototypeStngs = new ArrayList<DefaultOtptArtclStng>(); protected List<DefaultOtptArtclStng> prototypeStngs = new ArrayList<DefaultOtptArtclStng>();
@ -69,16 +73,16 @@ public abstract class PDFPrintFormat {
* . * .
*/ */
public abstract String getMappingValue(String otptArtclNm, String defaultValue, boolean forPost, public abstract String getMappingValue(String otptArtclNm, String defaultValue, boolean forPost,
DataObject dataObject, PrintOption printOption, PDFPrintUtil pdfPrintUtil); DataObject dataObject, PrintOption printOption, Print print);
public abstract List<String> getMappingValues(String otptArtclNm, String defaultValue, boolean forPost, public abstract List<String> getMappingValues(String otptArtclNm, String defaultValue, boolean forPost,
DataObject dataObject, PrintOption printOption, PDFPrintUtil pdfPrintUtil); DataObject dataObject, PrintOption printOption, Print print);
/** /**
* . * .
*/ */
public abstract String getValueForPost(String otptArtclNm, String defaultValue, public abstract String getValueForPost(String otptArtclNm, String defaultValue,
DataObject dataObject, PrintOption printOption, PDFPrintUtil pdfPrintUtil); DataObject dataObject, PrintOption printOption, Print print);
/** /**
* ( , , , , ) . * ( , , , , ) .
@ -108,6 +112,14 @@ public abstract class PDFPrintFormat {
*/ */
public abstract DataObject createSampleData(); public abstract DataObject createSampleData();
public List<DataObject> getMosSet(String imageKey, DataObject dataObject) {
if((List<DataObject>)dataObject.get("MOS"+imageKey) != null) {
return (List<DataObject>)dataObject.get("MOS"+imageKey);
} else {
return null;
}
}

@ -252,8 +252,9 @@ public class Cvlc01Controller extends ApplicationController {
factionBean.initUserInfo(userInfo); factionBean.initUserInfo(userInfo);
Print print = new Print(); Print print = new Print();
print.setPrintRequestUserInfo(userInfo); print.setPrintRequestUserInfo(userInfo);
hwpWriter.setPrint(print);
hwpWriter.setFormat(new CvlcptOrgn()); hwpWriter.setFormat(new CvlcptOrgn());
Map<String, Object> result = hwpWriter.makeFileFromHwpFormat("info", print, printOption, dataObjectList); Map<String, Object> result = hwpWriter.makeFileFromHwpFormat("info", printOption, dataObjectList);
mav.addAllObjects(result); mav.addAllObjects(result);
return mav; return mav;

@ -357,11 +357,11 @@ public class Excl02Controller extends ApplicationController {
factionBean.initUserInfo(userInfo); factionBean.initUserInfo(userInfo);
Print print = new Print(); Print print = new Print();
print.setPrintRequestUserInfo(userInfo); print.setPrintRequestUserInfo(userInfo);
hwpWriter.setPrint(print);
hwpWriter.setFormat(new DlbrDecsnList()); hwpWriter.setFormat(new DlbrDecsnList());
List<DataObject> dataObjectList = opnnSbmsnBean.getOpnnSbmsnDlbrDecsns(req); List<DataObject> dataObjectList = opnnSbmsnBean.getOpnnSbmsnDlbrDecsns(req);
Map<String,Object> result = hwpWriter.makeFileFromHwpFormat("info", print, printOption, dataObjectList); Map<String,Object> result = hwpWriter.makeFileFromHwpFormat("info", printOption, dataObjectList);
ModelAndView mav = new ModelAndView("downloadView"); ModelAndView mav = new ModelAndView("downloadView");
mav.addAllObjects(result); mav.addAllObjects(result);

@ -1,6 +1,7 @@
package cokr.xit.fims.sndb.web; package cokr.xit.fims.sndb.web;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -12,6 +13,9 @@ import org.springframework.web.servlet.ModelAndView;
import cokr.xit.base.code.CommonCode; import cokr.xit.base.code.CommonCode;
import cokr.xit.base.file.hwp.HWPWriter; import cokr.xit.base.file.hwp.HWPWriter;
import cokr.xit.base.file.pdf.PDFWriter;
import cokr.xit.base.file.service.FileQuery;
import cokr.xit.base.file.service.bean.FileBean;
import cokr.xit.base.file.xls.XLSWriter; import cokr.xit.base.file.xls.XLSWriter;
import cokr.xit.base.file.xls.XLSWriter.CellDef; import cokr.xit.base.file.xls.XLSWriter.CellDef;
import cokr.xit.base.file.xls.XLSWriter.Styler; import cokr.xit.base.file.xls.XLSWriter.Styler;
@ -20,7 +24,9 @@ import cokr.xit.base.web.ApplicationController;
import cokr.xit.fims.cmmn.CmmnQuery; import cokr.xit.fims.cmmn.CmmnQuery;
import cokr.xit.fims.cmmn.CmmnUtil; import cokr.xit.fims.cmmn.CmmnUtil;
import cokr.xit.fims.cmmn.Print; import cokr.xit.fims.cmmn.Print;
import cokr.xit.fims.cmmn.pdf.print.format.Advntce;
import cokr.xit.fims.cmmn.service.bean.StngBean; import cokr.xit.fims.cmmn.service.bean.StngBean;
import cokr.xit.fims.crdn.Crdn;
import cokr.xit.fims.mngt.service.bean.FactionBean; import cokr.xit.fims.mngt.service.bean.FactionBean;
import cokr.xit.fims.mngt.service.bean.TaskBean; import cokr.xit.fims.mngt.service.bean.TaskBean;
import cokr.xit.fims.sndb.SndbQuery; import cokr.xit.fims.sndb.SndbQuery;
@ -31,8 +37,13 @@ import cokr.xit.fims.sndb.service.SndngDtlService;
import cokr.xit.fims.sndb.service.SndngService; import cokr.xit.fims.sndb.service.SndngService;
import cokr.xit.fims.sndb.service.SvbtcService; import cokr.xit.fims.sndb.service.SvbtcService;
import cokr.xit.fims.sndb.service.bean.SvbtcBean; import cokr.xit.fims.sndb.service.bean.SvbtcBean;
import cokr.xit.fims.sprt.OtptStngQuery;
import cokr.xit.fims.sprt.PrintOption; import cokr.xit.fims.sprt.PrintOption;
import cokr.xit.fims.sprt.SprtQuery;
import cokr.xit.fims.sprt.dao.IntegrationSearchMapper;
import cokr.xit.fims.sprt.dao.OtptStngMapper;
import cokr.xit.fims.sprt.service.IntegrationSearchService; import cokr.xit.fims.sprt.service.IntegrationSearchService;
import cokr.xit.fims.sprt.service.bean.MediaBean;
import cokr.xit.foundation.UserInfo; import cokr.xit.foundation.UserInfo;
import cokr.xit.foundation.data.DataObject; import cokr.xit.foundation.data.DataObject;
@ -123,12 +134,24 @@ public class Sndb01Controller extends ApplicationController {
@Resource(name="stngBean") @Resource(name="stngBean")
private StngBean stngBean; private StngBean stngBean;
@Resource(name="fileBean")
private FileBean fileBean;
@Resource(name="factionBean") @Resource(name="factionBean")
private FactionBean factionBean; private FactionBean factionBean;
@Resource(name="svbtcBean") @Resource(name="svbtcBean")
private SvbtcBean svbtcBean; private SvbtcBean svbtcBean;
@Resource(name="mediaBean")
private MediaBean mediaBean;
@Resource(name="otptStngMapper")
private OtptStngMapper otptStngMapper;
@Resource(name="integrationSearchMapper")
private IntegrationSearchMapper integrationSearchMapper;
/** (sndb/sndb01/010-main) . /** (sndb/sndb01/010-main) .
* @return /sndb/sndb01/010-main * @return /sndb/sndb01/010-main
*/ */
@ -1482,8 +1505,9 @@ public class Sndb01Controller extends ApplicationController {
Print print = new Print(); Print print = new Print();
print.setPrintRequestUserInfo(userInfo); print.setPrintRequestUserInfo(userInfo);
hwpWriter.setPrint(print);
result = hwpWriter.makeFileFromHwpFormat("list", print, printOption, dataObjectList); result = hwpWriter.makeFileFromHwpFormat("list", printOption, dataObjectList);
ModelAndView mav = new ModelAndView("jsonView"); ModelAndView mav = new ModelAndView("jsonView");
@ -1633,7 +1657,90 @@ public class Sndb01Controller extends ApplicationController {
crdnIds[iLoop] = list.get(iLoop).string("CRDN_ID"); crdnIds[iLoop] = list.get(iLoop).string("CRDN_ID");
} }
Map<String, Object> result = integrationSearchService.makePdfFile("info", "advntce", printOption, crdnIds); List<DataObject> dataObjectList = new ArrayList<DataObject>();
if(crdnIds.length == 1 && crdnIds[0].equals("sample")) {
DataObject sample = new Advntce().createSampleData();
dataObjectList.add(sample);
} else {
SprtQuery sprtQuery = new SprtQuery();
sprtQuery.setCrdnIds(crdnIds);
dataObjectList = integrationSearchMapper.selectIntegrationDataList(sprtQuery);
for(int i=0; i < dataObjectList.size(); i++) {
DataObject dataObject = dataObjectList.get(i);
String crdnId = dataObject.string("CRDN_ID");
FileQuery fileQuery = new FileQuery();
fileQuery.setInfoType(Crdn.INF_TYPE);
fileQuery.setInfoKeys(crdnId);
List<DataObject> fileInfoList = fileBean.getFileList(fileQuery);
if(fileInfoList != null && fileInfoList.size() > 0) {
for(int j=0; j<fileInfoList.size(); j++) {
dataObject.set("CRDN_PHOTO"+(j+1), fileInfoList.get(j).string("URL"));
dataObject.set("CRDN_PHOTO"+(j+1)+"KEY", fileInfoList.get(j).string("FILE_ID"));
List<DataObject> mosSet = mediaBean.getMosaicList(fileInfoList.get(j).string("FILE_ID"));
if(mosSet != null && !mosSet.isEmpty()) {
dataObject.set("MOS"+fileInfoList.get(j).string("FILE_ID"), mosSet);
}
}
}
}
}
PDFWriter pdfWriter = new PDFWriter();
Print print = new Print();
UserInfo userInfo = currentUser();
factionBean.initUserInfo(userInfo);
print.setPrintRequestUserInfo(userInfo);
pdfWriter.setPrint(print);
pdfWriter.setFormat(new Advntce());
//출력물 기본 설정
OtptStngQuery otptStngQuery = new OtptStngQuery();
otptStngQuery.setSggCd((String)userInfo.getInfo().get("sggCd"));
String paperSeCd = printOption.getPaperSeCd();
String taskSeCd = printOption.getTaskSeCd();
otptStngQuery.setTaskSeCd(taskSeCd);
otptStngQuery.setSndngSeCd("02");
otptStngQuery.setPaperSeCd(paperSeCd);
DataObject otptBscStng = otptStngMapper.selectOtptBscStng(otptStngQuery);
if(otptBscStng == null) {
otptBscStng = new DataObject();
}
pdfWriter.setOtptBscStng(otptBscStng);
//출력 요소별 설정
List<DataObject> otptArtclStngList = otptStngMapper.selectOtptArtclStngList(otptStngQuery);
pdfWriter.setOtptArtclStngList(otptArtclStngList);
pdfWriter.setPaper(paperSeCd);
DataObject sggStngInfo = stngBean.getStng("sgg");
DataObject deptStngInfo = stngBean.getStng("dept");
//
Map<String, String> globalVariable = printOption.getGlobalVariable();
if(globalVariable == null) {
globalVariable = new HashMap<String, String>();
}
globalVariable.put("offcsFilePath", sggStngInfo.string("OFFCS_FILE_PATH"));
globalVariable.put("logoFilePath", sggStngInfo.string("LOGO_FILE_PATH"));
globalVariable.put("instAddr", sggStngInfo.string("INST_ADDR"));
globalVariable.put("instDaddr", sggStngInfo.string("INST_DADDR"));
globalVariable.put("instZip", sggStngInfo.string("INST_ZIP"));
globalVariable.put("deptTelno", deptStngInfo.string("DEPT_TELNO"));
globalVariable.put("deptFxno", deptStngInfo.string("DEPT_FXNO"));
if(!otptBscStng.string("BCRN_IMG_PATH").equals("")) {
globalVariable.put("bcrnImgPath", otptBscStng.string("BCRN_IMG_PATH"));
}
printOption.setGlobalVariable(globalVariable);
Map<String, Object> result = pdfWriter.makePdfFile("info", "advntce", printOption, dataObjectList);
mav.addAllObjects(result); mav.addAllObjects(result);

@ -0,0 +1,49 @@
package cokr.xit.fims.sprt;
import java.awt.image.BufferedImage;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import javax.imageio.ImageIO;
import cokr.xit.fims.cmmn.pdf.PstnAndSize;
import cokr.xit.foundation.data.DataObject;
public class MediaUtil {
public static List<PstnAndSize> getTransformedMosaic(List<DataObject> mosaicInfos, InputStream inputStream, PstnAndSize pstnAndSize_in_print) {
List<PstnAndSize> result = new ArrayList<>();
try {
BufferedImage image = ImageIO.read(inputStream);
float originalWidth = image.getWidth(null);
float originalHeight = image.getHeight(null);
float transX = pstnAndSize_in_print.getWidth() / originalWidth;
float transY = pstnAndSize_in_print.getHeight() / originalHeight;
if(mosaicInfos != null) {
for(int k=0; k < mosaicInfos.size(); k++) {
DataObject mosaicInfo = mosaicInfos.get(k);
float x = mosaicInfo.number("X_AXS").floatValue();
float y = mosaicInfo.number("Y_AXS").floatValue();
float w = mosaicInfo.number("MOSC_LT").floatValue();
float h = mosaicInfo.number("MOSC_HG").floatValue();
PstnAndSize mosaic = new PstnAndSize(x, y, w, h);
mosaic.transXY(transX, transY);
mosaic.addPstn(pstnAndSize_in_print.getPstn());
result.add(mosaic);
}
}
} catch (Exception e) {
throw new RuntimeException("이미지 모자이크 처리 오류");
}
return result;
}
}

@ -32,16 +32,6 @@ public interface IntegrationSearchService {
String updateEtcCn(String etcCn, String... crdnIds); String updateEtcCn(String etcCn, String... crdnIds);
/** pdf .
* @param formatType ,formatName , printOption , crdnIds
* @return map
* <ul><li>filename: </li>
* <li>filePath: </li>
* <li>file: </li>
* </ul>
*/
Map<String, Object> makePdfFile(String formatType, String formatName, PrintOption printOption, String[] crdnIds);
/** . /** .
* @param formatName , printOption , crdnIds * @param formatName , printOption , crdnIds
* @return map * @return map

@ -10,46 +10,28 @@ import java.nio.file.Files;
import java.nio.file.StandardCopyOption; import java.nio.file.StandardCopyOption;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
import javax.annotation.Resource; import javax.annotation.Resource;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.apache.pdfbox.pdmodel.common.PDRectangle;
import org.apache.pdfbox.pdmodel.font.PDType0Font;
import org.apache.pdfbox.pdmodel.graphics.color.PDColor;
import org.apache.pdfbox.pdmodel.graphics.state.RenderingMode;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import cokr.xit.base.file.service.FileQuery; import cokr.xit.base.file.service.FileQuery;
import cokr.xit.base.file.service.bean.FileBean; import cokr.xit.base.file.service.bean.FileBean;
import cokr.xit.fims.cmmn.CmmnUtil; import cokr.xit.fims.cmmn.CmmnUtil;
import cokr.xit.fims.cmmn.Hangul; import cokr.xit.fims.cmmn.Hangul;
import cokr.xit.fims.cmmn.pdf.PstnAndSize;
import cokr.xit.fims.cmmn.pdf.print.DefaultOtptArtclStng;
import cokr.xit.fims.cmmn.pdf.print.PDFPrintUtil;
import cokr.xit.fims.cmmn.pdf.print.format.Advntce;
import cokr.xit.fims.cmmn.pdf.print.format.Nht;
import cokr.xit.fims.cmmn.pdf.print.format.PDFPrintFormat;
import cokr.xit.fims.cmmn.service.bean.StngBean; import cokr.xit.fims.cmmn.service.bean.StngBean;
import cokr.xit.fims.crdn.Crdn; import cokr.xit.fims.crdn.Crdn;
import cokr.xit.fims.crdn.dao.CrdnListMapper; import cokr.xit.fims.crdn.dao.CrdnListMapper;
import cokr.xit.fims.mngt.service.bean.FactionBean; import cokr.xit.fims.mngt.service.bean.FactionBean;
import cokr.xit.fims.sprt.OtptStngQuery;
import cokr.xit.fims.sprt.PrintOption; import cokr.xit.fims.sprt.PrintOption;
import cokr.xit.fims.sprt.SprtQuery; import cokr.xit.fims.sprt.SprtQuery;
import cokr.xit.fims.sprt.dao.IntegrationSearchMapper; import cokr.xit.fims.sprt.dao.IntegrationSearchMapper;
import cokr.xit.fims.sprt.dao.OtptStngMapper; import cokr.xit.fims.sprt.dao.OtptStngMapper;
import cokr.xit.fims.sprt.service.IntegrationSearchService; import cokr.xit.fims.sprt.service.IntegrationSearchService;
import cokr.xit.foundation.UserInfo;
import cokr.xit.foundation.component.AbstractServiceBean; import cokr.xit.foundation.component.AbstractServiceBean;
import cokr.xit.foundation.data.DataObject; import cokr.xit.foundation.data.DataObject;
import net.lingala.zip4j.ZipFile; import net.lingala.zip4j.ZipFile;
@ -110,331 +92,6 @@ public class IntegrationSearchServiceBean extends AbstractServiceBean implements
@Override
public Map<String, Object> makePdfFile(String formatType, String formatName, PrintOption printOption, String[] crdnIds) {
Map<String, Object> result = new HashMap<>();
PDFPrintFormat pdfFormat = null;
if(formatName.equals("advntce")) {
pdfFormat = new Advntce();
} else if(formatName.equals("nht")) {
pdfFormat = new Nht();
}
String sndngSeCd = "";
if(formatName.equals("advntce")) {
sndngSeCd = "02";
} else if(formatName.equals("nht")) {
sndngSeCd = "03";
}
String paperSeCd = printOption.getPaperSeCd();
String taskSeCd = printOption.getTaskSeCd();
DataObject userStngInfo = stngBean.getStng("user");
DataObject sggStngInfo = stngBean.getStng("sgg");
DataObject deptStngInfo = stngBean.getStng("dept");
PDFPrintUtil pdfPrintUtil = new PDFPrintUtil();
if(formatName.equals("advntce")) {
pdfPrintUtil.setFormatKorName("사전통지서");
} else if(formatName.equals("nht")) {
pdfPrintUtil.setFormatKorName("고지서");
}
UserInfo userInfo = currentUser();
factionBean.initUserInfo(userInfo);
pdfPrintUtil.setPrintRequestUserInfo(userInfo);
String printUserSggCd = (String) pdfPrintUtil.getPrintRequestUserInfo().getInfo().get("sggCd");
pdfPrintUtil.setting(paperSeCd);
List<DataObject> dataObjectList = new ArrayList<DataObject>();
if(crdnIds.length == 1 && crdnIds[0].equals("sample")) {
DataObject sample = pdfFormat.createSampleData();
dataObjectList.add(sample);
} else {
SprtQuery sprtQuery = new SprtQuery();
sprtQuery.setCrdnIds(crdnIds);
dataObjectList = integrationSearchMapper.selectIntegrationDataList(sprtQuery);
for(int i=0; i < dataObjectList.size(); i++) {
DataObject dataObject = dataObjectList.get(i);
String crdnId = dataObject.string("CRDN_ID");
FileQuery fileQuery = new FileQuery();
fileQuery.setInfoType(Crdn.INF_TYPE);
fileQuery.setInfoKeys(crdnId);
List<DataObject> fileInfoList = fileBean.getFileList(fileQuery);
if(fileInfoList != null && fileInfoList.size() > 0) {
for(int j=0; j<fileInfoList.size(); j++) {
dataObject.set("CRDN_PHOTO"+(j+1), fileInfoList.get(j).string("URL"));
dataObject.set("CRDN_PHOTO"+(j+1)+"KEY", fileInfoList.get(j).string("FILE_ID"));
}
}
}
}
String resultFilePath = pdfPrintUtil.filePathForNewFile();
PDDocument doc = new PDDocument();//pdf문서 생성
//폰트 로드
Map<String, PDType0Font> fontMap = pdfPrintUtil.getFontMap(doc);
//용지 크기 설정
PDRectangle paper = null;
if(paperSeCd.equals("01")) {
paper = PDRectangle.A4;
} else {
paper = PDRectangle.LETTER;
}
//출력물 기본 설정
OtptStngQuery otptStngQuery = new OtptStngQuery();
otptStngQuery.setSggCd(printUserSggCd);
otptStngQuery.setTaskSeCd(taskSeCd);
otptStngQuery.setSndngSeCd(sndngSeCd);
otptStngQuery.setPaperSeCd(paperSeCd);
DataObject otptBscStng = otptStngMapper.selectOtptBscStng(otptStngQuery);
if(otptBscStng == null) {
otptBscStng = new DataObject();
}
//
Map<String, String> globalVariable = printOption.getGlobalVariable();
if(globalVariable == null) {
globalVariable = new HashMap<String, String>();
}
globalVariable.put("offcsFilePath", sggStngInfo.string("OFFCS_FILE_PATH"));
globalVariable.put("logoFilePath", sggStngInfo.string("LOGO_FILE_PATH"));
globalVariable.put("instAddr", sggStngInfo.string("INST_ADDR"));
globalVariable.put("instDaddr", sggStngInfo.string("INST_DADDR"));
globalVariable.put("instZip", sggStngInfo.string("INST_ZIP"));
globalVariable.put("deptTelno", deptStngInfo.string("DEPT_TELNO"));
globalVariable.put("deptFxno", deptStngInfo.string("DEPT_FXNO"));
if(!otptBscStng.string("BCRN_IMG_PATH").equals("")) {
globalVariable.put("bcrnImgPath", otptBscStng.string("BCRN_IMG_PATH"));
}
printOption.setGlobalVariable(globalVariable);
List<DefaultOtptArtclStng> prototypeStngList = pdfFormat.getPrototypeStngs();
try {
//출력 요소별 설정
List<DataObject> otptArtclStngList = otptStngMapper.selectOtptArtclStngList(otptStngQuery);
//출력요소별 속성 정보 추가
pdfFormat.appendOtptAttribute(otptArtclStngList);
//출력 요소 정렬
Comparator<DataObject> comparator1 = (item1, item2) -> {
int int1 = item1.string("UNIQUE_YN").equals("Y") ? 0 : 1;
int int2 = item2.string("UNIQUE_YN").equals("Y") ? 0 : 1;
return Integer.compare(int1, int2);
};
Comparator<DataObject> comparator2 = (item1, item2) -> {
int int1 = item1.number("OTPT_ARTCL_ORDR").intValue();
int int2 = item2.number("OTPT_ARTCL_ORDR").intValue();
return Integer.compare(int1, int2);
};
otptArtclStngList = otptArtclStngList.stream()
.sorted(comparator1.thenComparing(comparator2)).collect(Collectors.toList());
//대표단속사진 설정 여부 확인
boolean rprsCrdnPhotoYn = false;
if(otptArtclStngList.stream().filter(item -> item.string("OTPT_ARTCL_NM").equals("rprsCrdnPhoto")).count() > 0) {
rprsCrdnPhotoYn = true;
}
for(DataObject dataObject : dataObjectList) {
//페이지생성(건별)
PDPage blankPage = new PDPage(paper);
doc.addPage(blankPage);
// 작업 페이지 설정
PDPage page = doc.getPage(doc.getNumberOfPages()-1);
// 컨텐츠 스트림 열기
PDPageContentStream contentStream = new PDPageContentStream(doc, page);
boolean completeFoldLine = false;
for(DataObject otptArtclStng : otptArtclStngList) {
String otptArtclNm = otptArtclStng.string("OTPT_ARTCL_NM");
if(!otptArtclNm.equals("background") && !completeFoldLine) {
//접는곳 점선 그리기
if(!otptBscStng.string("FOLD_LINE_PSTN_SE_CD").equals("")) {
pdfPrintUtil.renderFoldLine(contentStream, paper, otptBscStng.string("FOLD_LINE_PSTN_SE_CD"));
}
completeFoldLine = true;
}
DefaultOtptArtclStng prototypeStng = prototypeStngList.stream()
.filter(item -> item.getOtptArtclNm().equals(otptArtclNm)).toList().get(0);
float[] pstn = pdfPrintUtil.getPstnStng(prototypeStng, otptArtclStng, paperSeCd);
float[] size = pdfPrintUtil.getSize(prototypeStng, otptArtclStng);
boolean forPost = prototypeStng.isForPost();
String defaultValue = prototypeStng.getOtptBscVl();
if(prototypeStng.getComponentType().equals("text")) {
String align = pdfPrintUtil.getAlign(prototypeStng, otptArtclStng);
String lineChgYn = pdfPrintUtil.getLineChgYn(prototypeStng, otptArtclStng);
PDType0Font font = pdfPrintUtil.getFontType(prototypeStng, otptArtclStng, fontMap);
int fontSz = pdfPrintUtil.getFontSize(prototypeStng, otptArtclStng);
RenderingMode fontStyle = pdfPrintUtil.getFontStyle(prototypeStng, otptArtclStng);
PDColor fontColor = pdfPrintUtil.getFontColor(prototypeStng, otptArtclStng);
String textValue = pdfFormat.getMappingValue(otptArtclNm,defaultValue,forPost,dataObject,printOption,pdfPrintUtil);
pdfPrintUtil.writeText(contentStream, textValue, pstn, size[0], align, lineChgYn
, font, fontSz, fontStyle, fontColor);
} else if(prototypeStng.getComponentType().equals("image")) {
String imagePath = pdfFormat.getMappingValue(otptArtclNm,defaultValue,forPost,dataObject,printOption,pdfPrintUtil);
if(ifEmpty(imagePath, ()->"").equals("")) {
continue;
}
if(!imagePath.startsWith("files")) {
imagePath = CmmnUtil.copyStaticResource(imagePath, false);
}
File imageFile = new File(imagePath);
InputStream is = new FileInputStream(imageFile);
String imageKey = "";
if(otptArtclNm.equals("rprsCrdnPhoto")) {
imageKey = pdfFormat.getMappingValue(otptArtclNm+"Key",defaultValue,forPost,dataObject,printOption,pdfPrintUtil);
}
pdfPrintUtil.insertImage(doc, contentStream, is, pstn, size);
if(otptArtclNm.equals("rprsCrdnPhoto") && !imageKey.equals("")) {
File imageFile0 = new File(imagePath);
InputStream is0 = new FileInputStream(imageFile0);
List<PstnAndSize> transformedMosaicInfos = mediaBean.getTransformedMosaic(
imageKey, is0, new PstnAndSize(pstn[0],pstn[1], size[0], size[1])
);
for(int k=0; k < transformedMosaicInfos.size(); k++) {
PstnAndSize mosaicInfo = transformedMosaicInfos.get(k);
InputStream blackImageStream = new ClassPathResource("samplefiles/black.png").getInputStream();
pdfPrintUtil.insertImage(doc, contentStream, blackImageStream,
mosaicInfo.getPstn().to2Float(), mosaicInfo.getSize().to2Float());
}
}
} else if(prototypeStng.getComponentType().equals("images")) {
List<String> imagePaths = pdfFormat.getMappingValues(otptArtclNm,defaultValue,forPost,dataObject,printOption,pdfPrintUtil);
List<String> imageKeys = new ArrayList<String>();
if(otptArtclNm.equals("crdnPhoto")) {
imageKeys = pdfFormat.getMappingValues(otptArtclNm+"Key",defaultValue,forPost,dataObject,printOption,pdfPrintUtil);
if(rprsCrdnPhotoYn && imagePaths.size() > 0) {
imageKeys.remove(0);
}
}
if(otptArtclNm.equals("crdnPhoto")) {
if(rprsCrdnPhotoYn && imagePaths.size() > 0) {
imagePaths.remove(0);
}
}
int printCntSetting = otptBscStng.number("OTPT_PHOTO_CNT").intValue();
int dataImageCnt = imagePaths.size();
if(printCntSetting != 0 && dataImageCnt != 0) {
List<PstnAndSize> devideInfos = pdfPrintUtil.devideImageArea(pstn, size, printCntSetting, dataImageCnt);
for (int i=0; i< devideInfos.size(); i++){
PstnAndSize devideInfo = devideInfos.get(i);
if(ifEmpty(imagePaths.get(i), ()-> "").equals("")) {
continue;
}
if(!imagePaths.get(i).startsWith("files")) {
imagePaths.set(i, CmmnUtil.copyStaticResource(imagePaths.get(i), false));
}
String imagePath = imagePaths.get(i);
File imageFile = new File(imagePath);
InputStream is = new FileInputStream(imageFile);
pdfPrintUtil.insertImage(doc, contentStream, is,
devideInfo.getPstn().to2Float(), devideInfo.getSize().to2Float());
if(otptArtclNm.equals("crdnPhoto") && !imageKeys.isEmpty()) {
String imagePath0 = imagePaths.get(i);
File imageFile0 = new File(imagePath0);
InputStream is0 = new FileInputStream(imageFile0);
List<PstnAndSize> transformedMosaicInfos = mediaBean.getTransformedMosaic(
imageKeys.get(i), is0, devideInfo
);
for(int k=0; k < transformedMosaicInfos.size(); k++) {
PstnAndSize mosaicInfo = transformedMosaicInfos.get(k);
InputStream blackImageStream = new ClassPathResource("samplefiles/black.png").getInputStream();
pdfPrintUtil.insertImage(doc, contentStream, blackImageStream,
mosaicInfo.getPstn().to2Float(), mosaicInfo.getSize().to2Float());
}
}
}
}
}
}//출력항목 loop 끝
if(!completeFoldLine) {
if(!otptBscStng.string("FOLD_LINE_PSTN_SE_CD").equals("")) {
pdfPrintUtil.renderFoldLine(contentStream, paper, otptBscStng.string("FOLD_LINE_PSTN_SE_CD"));
}
}
contentStream.close();
} //출력자료건수 loop 끝
doc.save(resultFilePath);
doc.close();
String downloadFileName = pdfPrintUtil.getFormatKorName()+"_"+pdfPrintUtil.getPrintRequestDt()+".pdf";
result.put("filename", downloadFileName);
result.put("filePath", resultFilePath);
result.put("file", new File(resultFilePath));
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("출력오류."+e);
}
return result;
}
@Override @Override
public Map<String, Object> makeOutsourcingFile(String formatName, PrintOption printOption, String[] crdnIds) { public Map<String, Object> makeOutsourcingFile(String formatName, PrintOption printOption, String[] crdnIds) {

@ -1,14 +1,11 @@
package cokr.xit.fims.sprt.service.bean; package cokr.xit.fims.sprt.service.bean;
import java.awt.image.BufferedImage;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.imageio.ImageIO;
import org.assertj.core.util.Arrays; import org.assertj.core.util.Arrays;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -17,6 +14,7 @@ import cokr.xit.base.file.service.FileQuery;
import cokr.xit.base.file.service.bean.FileBean; import cokr.xit.base.file.service.bean.FileBean;
import cokr.xit.fims.cmmn.pdf.PstnAndSize; import cokr.xit.fims.cmmn.pdf.PstnAndSize;
import cokr.xit.fims.crdn.dao.CrdnInfoMapper; import cokr.xit.fims.crdn.dao.CrdnInfoMapper;
import cokr.xit.fims.sprt.MediaUtil;
import cokr.xit.fims.sprt.Sprt; import cokr.xit.fims.sprt.Sprt;
import cokr.xit.fims.sprt.dao.MediaMapper; import cokr.xit.fims.sprt.dao.MediaMapper;
import cokr.xit.foundation.AbstractComponent; import cokr.xit.foundation.AbstractComponent;
@ -107,39 +105,10 @@ public class MediaBean extends AbstractComponent {
} }
public List<PstnAndSize> getTransformedMosaic(String imageKey, InputStream inputStream, PstnAndSize pstnAndSize_in_print) { public List<PstnAndSize> getTransformedMosaic(String imageKey, InputStream inputStream, PstnAndSize pstnAndSize_in_print) {
List<PstnAndSize> result = new ArrayList<>();
try {
BufferedImage image = ImageIO.read(inputStream);
float originalWidth = image.getWidth(null);
float originalHeight = image.getHeight(null);
float transX = pstnAndSize_in_print.getWidth() / originalWidth;
float transY = pstnAndSize_in_print.getHeight() / originalHeight;
List<DataObject> mosaicInfos = this.getMosaicList(imageKey); List<DataObject> mosaicInfos = this.getMosaicList(imageKey);
return MediaUtil.getTransformedMosaic(mosaicInfos, inputStream, pstnAndSize_in_print);
if(mosaicInfos != null) {
for(int k=0; k < mosaicInfos.size(); k++) {
DataObject mosaicInfo = mosaicInfos.get(k);
float x = mosaicInfo.number("X_AXS").floatValue();
float y = mosaicInfo.number("Y_AXS").floatValue();
float w = mosaicInfo.number("MOSC_LT").floatValue();
float h = mosaicInfo.number("MOSC_HG").floatValue();
PstnAndSize mosaic = new PstnAndSize(x, y, w, h);
mosaic.transXY(transX, transY);
mosaic.addPstn(pstnAndSize_in_print.getPstn());
result.add(mosaic);
}
}
} catch (Exception e) {
throw new RuntimeException("이미지 모자이크 처리 오류");
}
return result;
} }
public int reorder(String fileId, int i) { public int reorder(String fileId, int i) {

@ -19,6 +19,7 @@ import com.fasterxml.jackson.core.type.TypeReference;
import cokr.xit.base.code.CommonCode; import cokr.xit.base.code.CommonCode;
import cokr.xit.base.file.hwp.HWPWriter; import cokr.xit.base.file.hwp.HWPWriter;
import cokr.xit.base.file.pdf.PDFWriter;
import cokr.xit.base.file.service.FileQuery; import cokr.xit.base.file.service.FileQuery;
import cokr.xit.base.file.service.bean.FileBean; import cokr.xit.base.file.service.bean.FileBean;
import cokr.xit.base.file.xls.XLSWriter; import cokr.xit.base.file.xls.XLSWriter;
@ -34,6 +35,8 @@ import cokr.xit.fims.cmmn.hwp.format.CrdnList;
import cokr.xit.fims.cmmn.hwp.format.RcvmtConfirm; import cokr.xit.fims.cmmn.hwp.format.RcvmtConfirm;
import cokr.xit.fims.cmmn.hwp.format.ReportOnClaims; import cokr.xit.fims.cmmn.hwp.format.ReportOnClaims;
import cokr.xit.fims.cmmn.hwp.format.RequestForDelivery; import cokr.xit.fims.cmmn.hwp.format.RequestForDelivery;
import cokr.xit.fims.cmmn.pdf.print.format.Advntce;
import cokr.xit.fims.cmmn.pdf.print.format.Nht;
import cokr.xit.fims.cmmn.service.bean.StngBean; import cokr.xit.fims.cmmn.service.bean.StngBean;
import cokr.xit.fims.crdn.Crdn; import cokr.xit.fims.crdn.Crdn;
import cokr.xit.fims.crdn.CrdnQuery; import cokr.xit.fims.crdn.CrdnQuery;
@ -47,7 +50,9 @@ import cokr.xit.fims.sprt.OtptStngQuery;
import cokr.xit.fims.sprt.PrintOption; import cokr.xit.fims.sprt.PrintOption;
import cokr.xit.fims.sprt.SprtQuery; import cokr.xit.fims.sprt.SprtQuery;
import cokr.xit.fims.sprt.dao.IntegrationSearchMapper; import cokr.xit.fims.sprt.dao.IntegrationSearchMapper;
import cokr.xit.fims.sprt.dao.OtptStngMapper;
import cokr.xit.fims.sprt.service.IntegrationSearchService; import cokr.xit.fims.sprt.service.IntegrationSearchService;
import cokr.xit.fims.sprt.service.bean.MediaBean;
import cokr.xit.fims.sprt.service.bean.OtptStngBean; import cokr.xit.fims.sprt.service.bean.OtptStngBean;
import cokr.xit.fims.stat.dao.StatMapper; import cokr.xit.fims.stat.dao.StatMapper;
import cokr.xit.foundation.UserInfo; import cokr.xit.foundation.UserInfo;
@ -120,6 +125,9 @@ public class Sprt01Controller extends ApplicationController {
@Resource(name = "factionBean") @Resource(name = "factionBean")
private FactionBean factionBean; private FactionBean factionBean;
@Resource(name = "mediaBean")
private MediaBean mediaBean;
@Resource(name = "stngBean") @Resource(name = "stngBean")
private StngBean stngBean; private StngBean stngBean;
@ -129,6 +137,9 @@ public class Sprt01Controller extends ApplicationController {
@Resource(name = "integrationSearchMapper") @Resource(name = "integrationSearchMapper")
private IntegrationSearchMapper integrationSearchMapper; private IntegrationSearchMapper integrationSearchMapper;
@Resource(name = "otptStngMapper")
private OtptStngMapper otptStngMapper;
/** (fims/sprt/sprt01/010-main) . /** (fims/sprt/sprt01/010-main) .
* *
* @return /fims/sprt/sprt01010 * @return /fims/sprt/sprt01010
@ -450,12 +461,13 @@ public class Sprt01Controller extends ApplicationController {
factionBean.initUserInfo(userInfo); factionBean.initUserInfo(userInfo);
Print print = new Print(); Print print = new Print();
print.setPrintRequestUserInfo(userInfo); print.setPrintRequestUserInfo(userInfo);
hwpWriter.setPrint(print);
DataObject sggStngInfo = stngBean.getStng("sgg"); DataObject sggStngInfo = stngBean.getStng("sgg");
DataObject deptStngInfo = stngBean.getStng("dept"); DataObject deptStngInfo = stngBean.getStng("dept");
hwpWriter.setFormat(new CrdnList()); hwpWriter.setFormat(new CrdnList());
Map<String,Object> result = hwpWriter.makeFileFromHwpFormat("list", print, printOption, DataObjectList); Map<String,Object> result = hwpWriter.makeFileFromHwpFormat("list", printOption, DataObjectList);
ModelAndView mav = new ModelAndView("downloadView"); ModelAndView mav = new ModelAndView("downloadView");
mav.addAllObjects(result); mav.addAllObjects(result);
@ -497,12 +509,14 @@ public class Sprt01Controller extends ApplicationController {
factionBean.initUserInfo(userInfo); factionBean.initUserInfo(userInfo);
Print print = new Print(); Print print = new Print();
print.setPrintRequestUserInfo(userInfo); print.setPrintRequestUserInfo(userInfo);
hwpWriter.setPrint(print);
DataObject sggStngInfo = stngBean.getStng("sgg"); DataObject sggStngInfo = stngBean.getStng("sgg");
DataObject deptStngInfo = stngBean.getStng("dept"); DataObject deptStngInfo = stngBean.getStng("dept");
hwpWriter.setFormat(new CrdnConfirm()); hwpWriter.setFormat(new CrdnConfirm());
Map<String,Object> result = hwpWriter.makeFileFromHwpFormat("info", print, printOption, dataObjectList);
Map<String,Object> result = hwpWriter.makeFileFromHwpFormat("info", printOption, dataObjectList);
ModelAndView mav = new ModelAndView("downloadView"); ModelAndView mav = new ModelAndView("downloadView");
mav.addAllObjects(result); mav.addAllObjects(result);
@ -550,6 +564,7 @@ public class Sprt01Controller extends ApplicationController {
factionBean.initUserInfo(userInfo); factionBean.initUserInfo(userInfo);
Print print = new Print(); Print print = new Print();
print.setPrintRequestUserInfo(userInfo); print.setPrintRequestUserInfo(userInfo);
hwpWriter.setPrint(print);
DataObject sggStngInfo = stngBean.getStng("sgg"); DataObject sggStngInfo = stngBean.getStng("sgg");
DataObject deptStngInfo = stngBean.getStng("dept"); DataObject deptStngInfo = stngBean.getStng("dept");
@ -560,7 +575,7 @@ public class Sprt01Controller extends ApplicationController {
printOption.setGlobalVariable(globalVariable2); printOption.setGlobalVariable(globalVariable2);
hwpWriter.setFormat(new RequestForDelivery()); hwpWriter.setFormat(new RequestForDelivery());
Map<String,Object> result = hwpWriter.makeFileFromHwpFormat("list", print, printOption, dataObjectList); Map<String,Object> result = hwpWriter.makeFileFromHwpFormat("list", printOption, dataObjectList);
mav.addAllObjects(result); mav.addAllObjects(result);
return mav; return mav;
} }
@ -593,11 +608,12 @@ public class Sprt01Controller extends ApplicationController {
factionBean.initUserInfo(userInfo); factionBean.initUserInfo(userInfo);
Print print = new Print(); Print print = new Print();
print.setPrintRequestUserInfo(userInfo); print.setPrintRequestUserInfo(userInfo);
hwpWriter.setPrint(print);
DataObject sggStngInfo = stngBean.getStng("sgg"); DataObject sggStngInfo = stngBean.getStng("sgg");
DataObject deptStngInfo = stngBean.getStng("dept"); DataObject deptStngInfo = stngBean.getStng("dept");
Map<String, String> globalVariable2 = printOption.getGlobalVariable(); Map<String, String> globalVariable2 = printOption.getGlobalVariable();
String deptNm = (String) hwpWriter.getPrintRequestUserInfo().getInfo().get("deptNm"); String deptNm = (String) print.getPrintRequestUserInfo().getInfo().get("deptNm");
String deptAddr = sggStngInfo.string("INST_FULL_ADDR") + " " + deptNm; String deptAddr = sggStngInfo.string("INST_FULL_ADDR") + " " + deptNm;
globalVariable2.put("deptAddr", deptAddr); globalVariable2.put("deptAddr", deptAddr);
globalVariable2.put("deptTelno", deptStngInfo.string("DEPT_TELNO")); globalVariable2.put("deptTelno", deptStngInfo.string("DEPT_TELNO"));
@ -606,7 +622,7 @@ public class Sprt01Controller extends ApplicationController {
printOption.setGlobalVariable(globalVariable2); printOption.setGlobalVariable(globalVariable2);
hwpWriter.setFormat(new ReportOnClaims()); hwpWriter.setFormat(new ReportOnClaims());
Map<String,Object> result = hwpWriter.makeFileFromHwpFormat("list", print, printOption, dataObjectList); Map<String,Object> result = hwpWriter.makeFileFromHwpFormat("list", printOption, dataObjectList);
mav.addAllObjects(result); mav.addAllObjects(result);
@ -631,12 +647,13 @@ public class Sprt01Controller extends ApplicationController {
factionBean.initUserInfo(userInfo); factionBean.initUserInfo(userInfo);
Print print = new Print(); Print print = new Print();
print.setPrintRequestUserInfo(userInfo); print.setPrintRequestUserInfo(userInfo);
hwpWriter.setPrint(print);
DataObject sggStngInfo = stngBean.getStng("sgg"); DataObject sggStngInfo = stngBean.getStng("sgg");
DataObject deptStngInfo = stngBean.getStng("dept"); DataObject deptStngInfo = stngBean.getStng("dept");
hwpWriter.setFormat(new RcvmtConfirm()); hwpWriter.setFormat(new RcvmtConfirm());
Map<String,Object> result = hwpWriter.makeFileFromHwpFormat("info", print, printOption, dataObjectList); Map<String,Object> result = hwpWriter.makeFileFromHwpFormat("info", printOption, dataObjectList);
mav.addAllObjects(result); mav.addAllObjects(result);
return mav; return mav;
@ -660,7 +677,88 @@ public class Sprt01Controller extends ApplicationController {
public ModelAndView makeAdvntcePdf(PrintOption printOption, String[] crdnIds) { public ModelAndView makeAdvntcePdf(PrintOption printOption, String[] crdnIds) {
ModelAndView mav = new ModelAndView("downloadView"); ModelAndView mav = new ModelAndView("downloadView");
Map<String, Object> result = integrationSearchService.makePdfFile("info", "advntce", printOption, crdnIds); List<DataObject> dataObjectList = new ArrayList<DataObject>();
if(crdnIds.length == 1 && crdnIds[0].equals("sample")) {
DataObject sample = new Advntce().createSampleData();
dataObjectList.add(sample);
} else {
SprtQuery sprtQuery = new SprtQuery();
sprtQuery.setCrdnIds(crdnIds);
dataObjectList = integrationSearchMapper.selectIntegrationDataList(sprtQuery);
for(int i=0; i < dataObjectList.size(); i++) {
DataObject dataObject = dataObjectList.get(i);
String crdnId = dataObject.string("CRDN_ID");
FileQuery fileQuery = new FileQuery();
fileQuery.setInfoType(Crdn.INF_TYPE);
fileQuery.setInfoKeys(crdnId);
List<DataObject> fileInfoList = fileBean.getFileList(fileQuery);
if(fileInfoList != null && fileInfoList.size() > 0) {
for(int j=0; j<fileInfoList.size(); j++) {
dataObject.set("CRDN_PHOTO"+(j+1), fileInfoList.get(j).string("URL"));
dataObject.set("CRDN_PHOTO"+(j+1)+"KEY", fileInfoList.get(j).string("FILE_ID"));
List<DataObject> mosSet = mediaBean.getMosaicList(fileInfoList.get(j).string("FILE_ID"));
if(mosSet != null && !mosSet.isEmpty()) {
dataObject.set("MOS"+fileInfoList.get(j).string("FILE_ID"), mosSet);
}
}
}
}
}
PDFWriter pdfWriter = new PDFWriter();
Print print = new Print();
UserInfo userInfo = currentUser();
factionBean.initUserInfo(userInfo);
print.setPrintRequestUserInfo(userInfo);
pdfWriter.setPrint(print);
pdfWriter.setFormat(new Advntce());
//출력물 기본 설정
OtptStngQuery otptStngQuery = new OtptStngQuery();
String paperSeCd = printOption.getPaperSeCd();
String taskSeCd = printOption.getTaskSeCd();
otptStngQuery.setSggCd((String)userInfo.getInfo().get("sggCd"));
otptStngQuery.setTaskSeCd(taskSeCd);
otptStngQuery.setSndngSeCd("02");
otptStngQuery.setPaperSeCd(paperSeCd);
DataObject otptBscStng = otptStngMapper.selectOtptBscStng(otptStngQuery);
if(otptBscStng == null) {
otptBscStng = new DataObject();
}
pdfWriter.setOtptBscStng(otptBscStng);
//출력 요소별 설정
List<DataObject> otptArtclStngList = otptStngMapper.selectOtptArtclStngList(otptStngQuery);
pdfWriter.setOtptArtclStngList(otptArtclStngList);
pdfWriter.setPaper(paperSeCd);
DataObject sggStngInfo = stngBean.getStng("sgg");
DataObject deptStngInfo = stngBean.getStng("dept");
//
Map<String, String> globalVariable = printOption.getGlobalVariable();
if(globalVariable == null) {
globalVariable = new HashMap<String, String>();
}
globalVariable.put("offcsFilePath", sggStngInfo.string("OFFCS_FILE_PATH"));
globalVariable.put("logoFilePath", sggStngInfo.string("LOGO_FILE_PATH"));
globalVariable.put("instAddr", sggStngInfo.string("INST_ADDR"));
globalVariable.put("instDaddr", sggStngInfo.string("INST_DADDR"));
globalVariable.put("instZip", sggStngInfo.string("INST_ZIP"));
globalVariable.put("deptTelno", deptStngInfo.string("DEPT_TELNO"));
globalVariable.put("deptFxno", deptStngInfo.string("DEPT_FXNO"));
if(!otptBscStng.string("BCRN_IMG_PATH").equals("")) {
globalVariable.put("bcrnImgPath", otptBscStng.string("BCRN_IMG_PATH"));
}
printOption.setGlobalVariable(globalVariable);
Map<String, Object> result = pdfWriter.makePdfFile("info", "advntce", printOption, dataObjectList);
mav.addAllObjects(result); mav.addAllObjects(result);
return mav; return mav;
@ -697,8 +795,90 @@ public class Sprt01Controller extends ApplicationController {
*/ */
public ModelAndView makeNhtPdf(PrintOption printOption, String[] crdnIds) { public ModelAndView makeNhtPdf(PrintOption printOption, String[] crdnIds) {
ModelAndView mav = new ModelAndView("downloadView"); ModelAndView mav = new ModelAndView("downloadView");
List<DataObject> dataObjectList = new ArrayList<DataObject>();
if(crdnIds.length == 1 && crdnIds[0].equals("sample")) {
DataObject sample = new Advntce().createSampleData();
dataObjectList.add(sample);
} else {
SprtQuery sprtQuery = new SprtQuery();
sprtQuery.setCrdnIds(crdnIds);
dataObjectList = integrationSearchMapper.selectIntegrationDataList(sprtQuery);
for(int i=0; i < dataObjectList.size(); i++) {
DataObject dataObject = dataObjectList.get(i);
String crdnId = dataObject.string("CRDN_ID");
FileQuery fileQuery = new FileQuery();
fileQuery.setInfoType(Crdn.INF_TYPE);
fileQuery.setInfoKeys(crdnId);
List<DataObject> fileInfoList = fileBean.getFileList(fileQuery);
if(fileInfoList != null && fileInfoList.size() > 0) {
for(int j=0; j<fileInfoList.size(); j++) {
dataObject.set("CRDN_PHOTO"+(j+1), fileInfoList.get(j).string("URL"));
dataObject.set("CRDN_PHOTO"+(j+1)+"KEY", fileInfoList.get(j).string("FILE_ID"));
List<DataObject> mosSet = mediaBean.getMosaicList(fileInfoList.get(j).string("FILE_ID"));
if(mosSet != null && !mosSet.isEmpty()) {
dataObject.set("MOS"+fileInfoList.get(j).string("FILE_ID"), mosSet);
}
}
}
}
}
PDFWriter pdfWriter = new PDFWriter();
Print print = new Print();
UserInfo userInfo = currentUser();
factionBean.initUserInfo(userInfo);
print.setPrintRequestUserInfo(userInfo);
pdfWriter.setPrint(print);
pdfWriter.setFormat(new Nht());
//출력물 기본 설정
OtptStngQuery otptStngQuery = new OtptStngQuery();
String paperSeCd = printOption.getPaperSeCd();
String taskSeCd = printOption.getTaskSeCd();
otptStngQuery.setSggCd((String)userInfo.getInfo().get("sggCd"));
otptStngQuery.setTaskSeCd(taskSeCd);
otptStngQuery.setSndngSeCd("03");
otptStngQuery.setPaperSeCd(paperSeCd);
DataObject otptBscStng = otptStngMapper.selectOtptBscStng(otptStngQuery);
if(otptBscStng == null) {
otptBscStng = new DataObject();
}
pdfWriter.setOtptBscStng(otptBscStng);
//출력 요소별 설정
List<DataObject> otptArtclStngList = otptStngMapper.selectOtptArtclStngList(otptStngQuery);
pdfWriter.setOtptArtclStngList(otptArtclStngList);
pdfWriter.setPaper(paperSeCd);
DataObject sggStngInfo = stngBean.getStng("sgg");
DataObject deptStngInfo = stngBean.getStng("dept");
//
Map<String, String> globalVariable = printOption.getGlobalVariable();
if(globalVariable == null) {
globalVariable = new HashMap<String, String>();
}
globalVariable.put("offcsFilePath", sggStngInfo.string("OFFCS_FILE_PATH"));
globalVariable.put("logoFilePath", sggStngInfo.string("LOGO_FILE_PATH"));
globalVariable.put("instAddr", sggStngInfo.string("INST_ADDR"));
globalVariable.put("instDaddr", sggStngInfo.string("INST_DADDR"));
globalVariable.put("instZip", sggStngInfo.string("INST_ZIP"));
globalVariable.put("deptTelno", deptStngInfo.string("DEPT_TELNO"));
globalVariable.put("deptFxno", deptStngInfo.string("DEPT_FXNO"));
if(!otptBscStng.string("BCRN_IMG_PATH").equals("")) {
globalVariable.put("bcrnImgPath", otptBscStng.string("BCRN_IMG_PATH"));
}
printOption.setGlobalVariable(globalVariable);
Map<String, Object> result = integrationSearchService.makePdfFile("info", "nht", printOption, crdnIds); Map<String, Object> result = pdfWriter.makePdfFile("info", "nht", printOption, dataObjectList);
mav.addAllObjects(result); mav.addAllObjects(result);
return mav; return mav;

Loading…
Cancel
Save