소스 정리

main
mjkhan21 8 months ago
parent 10c2241099
commit 63724ece3d

@ -10,6 +10,7 @@ import java.util.Comparator;
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.Stream;
import org.apache.pdfbox.pdmodel.common.PDRectangle; import org.apache.pdfbox.pdmodel.common.PDRectangle;
import org.apache.pdfbox.pdmodel.font.PDType0Font; import org.apache.pdfbox.pdmodel.font.PDType0Font;
@ -61,10 +62,10 @@ public abstract class PDFPrintFormat extends AbstractComponent {
this.otptBscStng = otptBscStng; this.otptBscStng = otptBscStng;
this.otptArtclStngList = otptArtclStngList; this.otptArtclStngList = otptArtclStngList;
this.paperSeCd = paperSeCd; this.paperSeCd = paperSeCd;
if (paperSeCd.equals("01")) { switch (paperSeCd) {
this.paperMilimeter = new float[] {210.0f , 297.0f}; case "01": this.paperMilimeter = new float[] {210.0f , 297.0f}; break;
} else if (paperSeCd.equals("02")){ case "02": this.paperMilimeter = new float[] {216.0f , 279.0f}; break;
this.paperMilimeter = new float[] {216.0f , 279.0f}; default: break;
} }
} }
@ -136,9 +137,9 @@ public abstract class PDFPrintFormat extends AbstractComponent {
* . * .
*/ */
public void addForPost(DefaultOtptArtclStng... prototypeStngs){ public void addForPost(DefaultOtptArtclStng... prototypeStngs){
for (DefaultOtptArtclStng prototypeStng : prototypeStngs) { this.prototypeStngs.addAll(Stream.of(prototypeStngs)
this.prototypeStngs.add(prototypeStng.post()); .map(setting -> setting.post()).toList()
} );
}; };
/** /**
@ -214,7 +215,6 @@ public abstract class PDFPrintFormat extends AbstractComponent {
Map<String, PDType0Font> fontMap = getFontMap(writer = new PDFWriter()); Map<String, PDType0Font> fontMap = getFontMap(writer = new PDFWriter());
//용지 크기 설정 //용지 크기 설정
writer.paper("01".equals(this.paperSeCd) ? "A4" : "LETTER"); writer.paper("01".equals(this.paperSeCd) ? "A4" : "LETTER");
List<DefaultOtptArtclStng> prototypeStngList = getPrototypeStngs(); List<DefaultOtptArtclStng> prototypeStngList = getPrototypeStngs();
try { try {
@ -236,7 +236,6 @@ public abstract class PDFPrintFormat extends AbstractComponent {
.sorted(comparator1.thenComparing(comparator2)) .sorted(comparator1.thenComparing(comparator2))
.toList(); .toList();
//대표단속사진 설정 여부 확인 //대표단속사진 설정 여부 확인
boolean rprsCrdnPhotoYn = otptArtclStngList.stream() boolean rprsCrdnPhotoYn = otptArtclStngList.stream()
.filter(item -> item.string("OTPT_ARTCL_NM").equals("rprsCrdnPhoto")) .filter(item -> item.string("OTPT_ARTCL_NM").equals("rprsCrdnPhoto"))
@ -267,7 +266,8 @@ public abstract class PDFPrintFormat extends AbstractComponent {
boolean forPost = prototypeStng.isForPost(); boolean forPost = prototypeStng.isForPost();
String defaultValue = prototypeStng.getOtptBscVl(); String defaultValue = prototypeStng.getOtptBscVl();
if (prototypeStng.getComponentType().equals("text")) { String componentType = prototypeStng.getComponentType();
if ("text".equals(componentType)) {
String align = this.getAlign(prototypeStng, otptArtclStng); String align = this.getAlign(prototypeStng, otptArtclStng);
String lineChgYn = this.getLineChgYn(prototypeStng, otptArtclStng); String lineChgYn = this.getLineChgYn(prototypeStng, otptArtclStng);
PDType0Font font = this.getFontType(prototypeStng, otptArtclStng, fontMap); PDType0Font font = this.getFontType(prototypeStng, otptArtclStng, fontMap);
@ -280,7 +280,7 @@ public abstract class PDFPrintFormat extends AbstractComponent {
this.writeText(writer, textValue, pstn, size[0], align, lineChgYn this.writeText(writer, textValue, pstn, size[0], align, lineChgYn
, font, fontSz, fontStyle, fontColr); , font, fontSz, fontStyle, fontColr);
} else if (prototypeStng.getComponentType().equals("image")) { } else if ("image".equals(componentType)) {
String imagePath = this.getMappingValue(otptArtclNm,defaultValue,forPost,dataObject,printOption,this.print); String imagePath = this.getMappingValue(otptArtclNm,defaultValue,forPost,dataObject,printOption,this.print);
@ -294,15 +294,12 @@ public abstract class PDFPrintFormat extends AbstractComponent {
File imageFile = new File(imagePath); File imageFile = new File(imagePath);
if (!imageFile.exists()) { if (!imageFile.exists()) {
if (otptArtclNm.equals("offcs")) { if (otptArtclNm.equals("offcs"))
throw new HttpStatusCodeException(500, "{\"failed\":true,\"description\":\"직인 파일을 찾을 수 없습니다.\"}", true); throw new HttpStatusCodeException(500, "{\"failed\":true,\"description\":\"직인 파일을 찾을 수 없습니다.\"}", true);
} if (otptArtclNm.equals("background"))
if (otptArtclNm.equals("background")) {
throw new HttpStatusCodeException(500, "{\"failed\":true,\"description\":\"배경이미지 파일을 찾을 수 없습니다.\"}", true); throw new HttpStatusCodeException(500, "{\"failed\":true,\"description\":\"배경이미지 파일을 찾을 수 없습니다.\"}", true);
} if (otptArtclNm.equals("postSenderLogo"))
if (otptArtclNm.equals("postSenderLogo")) {
throw new HttpStatusCodeException(500, "{\"failed\":true,\"description\":\"우편물 송신자 로고 파일을 찾을 수 없습니다.\"}", true); throw new HttpStatusCodeException(500, "{\"failed\":true,\"description\":\"우편물 송신자 로고 파일을 찾을 수 없습니다.\"}", true);
}
continue; continue;
} }
@ -339,7 +336,7 @@ public abstract class PDFPrintFormat extends AbstractComponent {
} }
} else if (prototypeStng.getComponentType().equals("images")) { } else if ("images".equals(componentType)) {
List<String> imagePaths = this.getMappingValues(otptArtclNm,defaultValue,forPost,dataObject,printOption,this.print); List<String> imagePaths = this.getMappingValues(otptArtclNm,defaultValue,forPost,dataObject,printOption,this.print);
@ -417,23 +414,20 @@ public abstract class PDFPrintFormat extends AbstractComponent {
}//출력항목 loop 끝 }//출력항목 loop 끝
if (!completeFoldLine) { if (!completeFoldLine) {
if (!otptBscStng.string("FOLD_LINE_PSTN_SE_CD").equals("")) { if (!isEmpty(otptBscStng.string("FOLD_LINE_PSTN_SE_CD"))) {
this.renderFoldLine(writer, otptBscStng.string("FOLD_LINE_PSTN_SE_CD")); this.renderFoldLine(writer, otptBscStng.string("FOLD_LINE_PSTN_SE_CD"));
} }
} }
writer.endPage(); writer.endPage();
} //출력자료건수 loop 끝 } //출력자료건수 loop 끝
String downloadFileName = this.print.getFormatKorName()+"_"+this.print.getPrintRequestDt()+".pdf"; String downloadFileName = this.print.getFormatKorName()+"_"+this.print.getPrintRequestDt()+".pdf";
result.put("download", writer.getDownloadable().setFilename(downloadFileName)); result.put("download", writer.getDownloadable().setFilename(downloadFileName));
result.put("downloadData", data); result.put("downloadData", data);
result.put("dataNames", this.filterDownloadDataNames()); result.put("dataNames", this.filterDownloadDataNames());
} catch(FileNotFoundException e) { } catch(FileNotFoundException e) {
throw new RuntimeException("파일을 찾을 수 없습니다."); throw new RuntimeException("파일을 찾을 수 없습니다.");
} catch(HttpStatusCodeException e) { } catch(HttpStatusCodeException e) {
throw e; throw e;
@ -444,8 +438,6 @@ public abstract class PDFPrintFormat extends AbstractComponent {
return result; return result;
} }
/** /**
* mm pdf . * mm pdf .
*/ */
@ -468,19 +460,14 @@ public abstract class PDFPrintFormat extends AbstractComponent {
float[] XYmm, float textAreaWidth_mm, String align, String newLineYn, float[] XYmm, float textAreaWidth_mm, String align, String newLineYn,
PDType0Font font, int fontSize, RenderingMode fontStyle, PDColor fontColor) { PDType0Font font, int fontSize, RenderingMode fontStyle, PDColor fontColor) {
try { try {
if (allText == null) { if (allText == null)
allText = ""; allText = "";
} if (isEmpty(newLineYn))
if (newLineYn == null || newLineYn.equals("")) {
newLineYn = "N"; newLineYn = "N";
}
float[] xyAbsolute = this.toPDFCoordinate(XYmm).absolute(); float[] xyAbsolute = this.toPDFCoordinate(XYmm).absolute();
float textAreaWidth_pt = CmmnUtil.mmToPt(textAreaWidth_mm); float textAreaWidth_pt = CmmnUtil.mmToPt(textAreaWidth_mm);
float allTextWidth = calcTextWidth(font, fontSize, allText); float allTextWidth = calcTextWidth(font, fontSize, allText);
String textArr[]; String textArr[];
if (allText.equals("") || allText.length() == 1 || textAreaWidth_pt == 0 if (allText.equals("") || allText.length() == 1 || textAreaWidth_pt == 0
|| (allTextWidth <= textAreaWidth_pt) || (allTextWidth <= textAreaWidth_pt)
@ -699,9 +686,8 @@ public abstract class PDFPrintFormat extends AbstractComponent {
} }
public PstnAndSize[][] mergeLastImageCell(PstnAndSize[][] d2, String mergeDirection) { public PstnAndSize[][] mergeLastImageCell(PstnAndSize[][] d2, String mergeDirection) {
if (!mergeDirection.equals("up") && !mergeDirection.equals("left")) { if (!"up".equals(mergeDirection) && !"left".equals(mergeDirection))
throw new RuntimeException("PDF 파일 출력 중 오류가 발생하였습니다."); throw new RuntimeException("PDF 파일 출력 중 오류가 발생하였습니다.");
}
int xLengthOfD2 = d2.length; int xLengthOfD2 = d2.length;
int yLengthOfD2 = d2[0].length; int yLengthOfD2 = d2[0].length;
@ -782,10 +768,10 @@ public abstract class PDFPrintFormat extends AbstractComponent {
} }
public float[] getPstnStng(DefaultOtptArtclStng prototypeStng, DataObject sggStng, String paperSeCd) { public float[] getPstnStng(DefaultOtptArtclStng prototypeStng, DataObject sggStng, String paperSeCd) {
if (!sggStng.string("LEFT_PSTN").equals("") && !sggStng.string("TOP_PSTN").equals("")) { if (!isEmpty(sggStng.get("LEFT_PSTN")) && !isEmpty(sggStng.get("TOP_PSTN"))) {
return new float[] { return new float[] {
sggStng.number("LEFT_PSTN").floatValue(), toFloat(sggStng.get("LEFT_PSTN")),
sggStng.number("TOP_PSTN").floatValue() toFloat(sggStng.get("TOP_PSTN"))
}; };
} else { } else {
return new float[] { return new float[] {
@ -814,10 +800,10 @@ public abstract class PDFPrintFormat extends AbstractComponent {
} }
public float[] getSize(DefaultOtptArtclStng prototypeStng, DataObject sggStng) { public float[] getSize(DefaultOtptArtclStng prototypeStng, DataObject sggStng) {
if (!sggStng.string("WIDTH_SZ").equals("")) { if (!isEmpty(sggStng.get("WIDTH_SZ"))) {
return new float[] { return new float[] {
sggStng.number("WIDTH_SZ").floatValue(), toFloat(sggStng.get("WIDTH_SZ")),
sggStng.number("HEIGHT_SZ").floatValue() toFloat(sggStng.get("HEIGHT_SZ"))
}; };
} else { } else {
return new float[] { return new float[] {

Loading…
Cancel
Save