diff --git a/samplefiles/crdn1.png b/samplefiles/crdn1.png new file mode 100644 index 00000000..114ec28b Binary files /dev/null and b/samplefiles/crdn1.png differ diff --git a/samplefiles/crdn2.png b/samplefiles/crdn2.png new file mode 100644 index 00000000..41433f66 Binary files /dev/null and b/samplefiles/crdn2.png differ diff --git a/samplefiles/crdn3.png b/samplefiles/crdn3.png new file mode 100644 index 00000000..351be7d0 Binary files /dev/null and b/samplefiles/crdn3.png differ diff --git a/samplefiles/crdn4.png b/samplefiles/crdn4.png new file mode 100644 index 00000000..e6c2274c Binary files /dev/null and b/samplefiles/crdn4.png differ diff --git a/samplefiles/crdn5.png b/samplefiles/crdn5.png new file mode 100644 index 00000000..9e5fae13 Binary files /dev/null and b/samplefiles/crdn5.png differ diff --git a/samplefiles/crdn6.png b/samplefiles/crdn6.png new file mode 100644 index 00000000..ac461b5d Binary files /dev/null and b/samplefiles/crdn6.png differ diff --git a/samplefiles/crdn7.png b/samplefiles/crdn7.png new file mode 100644 index 00000000..ad467854 Binary files /dev/null and b/samplefiles/crdn7.png differ diff --git a/src/main/java/cokr/xit/fims/cmmn/pdf/PDFFormat.java b/src/main/java/cokr/xit/fims/cmmn/pdf/PDFFormat.java index c8098280..2342c4cd 100644 --- a/src/main/java/cokr/xit/fims/cmmn/pdf/PDFFormat.java +++ b/src/main/java/cokr/xit/fims/cmmn/pdf/PDFFormat.java @@ -38,6 +38,13 @@ public abstract class PDFFormat { return new DefaultOtptArtclStng("image", otptArtclNm, dscrp, otptBscVl); } + /** + * 이미지 묶음 출력요소 정의한다. + */ + public DefaultOtptArtclStng images(String otptArtclNm, String dscrp, String otptBscVl){ + return new DefaultOtptArtclStng("images", otptArtclNm, dscrp, otptBscVl); + } + /** * 포맷원형에 출력요소를 추가한다. */ @@ -62,6 +69,9 @@ public abstract class PDFFormat { public abstract String getMappingValue(String otptArtclNm, String defaultValue, boolean forPost, DataObject dataObject, PrintOption printOption, PDFPrintUtil pdfPrintUtil); + public abstract List getMappingValues(String otptArtclNm, String defaultValue, boolean forPost, + DataObject dataObject, PrintOption printOption, PDFPrintUtil pdfPrintUtil); + /** * 우편물 출력요소에 매핑될 값을 반환한다. */ @@ -93,4 +103,6 @@ public abstract class PDFFormat { public abstract DataObject createSampleData(); + + } diff --git a/src/main/java/cokr/xit/fims/cmmn/pdf/PDFPrintUtil.java b/src/main/java/cokr/xit/fims/cmmn/pdf/PDFPrintUtil.java index ea32e32f..3c0b530c 100644 --- a/src/main/java/cokr/xit/fims/cmmn/pdf/PDFPrintUtil.java +++ b/src/main/java/cokr/xit/fims/cmmn/pdf/PDFPrintUtil.java @@ -5,6 +5,7 @@ import java.io.IOException; 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; @@ -228,13 +229,144 @@ public class PDFPrintUtil extends PrintUtil { try { if(!imagePath.equals("")) { PDImageXObject image = PDImageXObject.createFromFile(imagePath, doc); - contentStream.drawImage(image, xyAbsolute[0], xyAbsolute[1], size[0], size[1]); + contentStream.drawImage(image, xyAbsolute[0], xyAbsolute[1]-size[1], size[0], size[1]); } } catch (IOException e) { throw new RuntimeException("PDF 파일 출력 중 오류가 발생하였습니다."); } } + public List devideImageArea(float[] totAreaPstn, float[] totAreaSize, int imageCntSetting, int dataImageCnt) { + List result = new ArrayList(); + + 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; @@ -372,4 +504,6 @@ public class PDFPrintUtil extends PrintUtil { throw new RuntimeException("글꼴 로드 오류"); } } + + } diff --git a/src/main/java/cokr/xit/fims/cmmn/pdf/Pstn.java b/src/main/java/cokr/xit/fims/cmmn/pdf/Pstn.java index f794f723..24833e22 100644 --- a/src/main/java/cokr/xit/fims/cmmn/pdf/Pstn.java +++ b/src/main/java/cokr/xit/fims/cmmn/pdf/Pstn.java @@ -13,4 +13,8 @@ public class Pstn { private float left; private float top; + + public float[] to2Float() { + return new float[] { this.left, this.top }; + } } diff --git a/src/main/java/cokr/xit/fims/cmmn/pdf/PstnAndSize.java b/src/main/java/cokr/xit/fims/cmmn/pdf/PstnAndSize.java new file mode 100644 index 00000000..0f231f55 --- /dev/null +++ b/src/main/java/cokr/xit/fims/cmmn/pdf/PstnAndSize.java @@ -0,0 +1,61 @@ +package cokr.xit.fims.cmmn.pdf; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class PstnAndSize { + public PstnAndSize(float left, float top, float width, float height){ + this.left = left; + this.top = top; + this.width = width; + this.height = height; + } + + public PstnAndSize(Pstn pstn, Size size){ + this.left = pstn.getLeft(); + this.top = pstn.getTop(); + this.width = size.getWidth(); + this.height = size.getHeight(); + } + + public PstnAndSize(Pstn pstn, float width, float height){ + this.left = pstn.getLeft(); + this.top = pstn.getTop(); + this.width = width; + this.height = height; + } + + public PstnAndSize(float left, float top, Size size){ + this.left = left; + this.top = top; + this.width = size.getWidth(); + this.height = size.getHeight(); + } + + private float left; + private float top; + private float width; + private float height; + + public Pstn getPstn() { + return new Pstn(this.left, this.top); + } + public Size getSize() { + return new Size(this.width, this.height); + } + + public float[] to4Float() { + return new float[] { this.left, this.top, this.width, this.height }; + } + + public PstnAndSize x2Width() { + this.width = this.width * 2.0f; + return this; + } + public PstnAndSize x2Height() { + this.height = this.height * 2.0f; + return this; + } +} diff --git a/src/main/java/cokr/xit/fims/cmmn/pdf/Size.java b/src/main/java/cokr/xit/fims/cmmn/pdf/Size.java new file mode 100644 index 00000000..7da4bfe8 --- /dev/null +++ b/src/main/java/cokr/xit/fims/cmmn/pdf/Size.java @@ -0,0 +1,20 @@ +package cokr.xit.fims.cmmn.pdf; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class Size { + public Size(float width, float height){ + this.width = width; + this.height = height; + } + + private float width; + private float height; + + public float[] to2Float() { + return new float[] { this.width, this.height }; + } +} diff --git a/src/main/java/cokr/xit/fims/cmmn/pdf/format/Advntce.java b/src/main/java/cokr/xit/fims/cmmn/pdf/format/Advntce.java index 0b8eb082..bc7718cf 100644 --- a/src/main/java/cokr/xit/fims/cmmn/pdf/format/Advntce.java +++ b/src/main/java/cokr/xit/fims/cmmn/pdf/format/Advntce.java @@ -1,5 +1,8 @@ package cokr.xit.fims.cmmn.pdf.format; +import java.util.ArrayList; +import java.util.List; + import cokr.xit.fims.cmmn.CmmnUtil; import cokr.xit.fims.cmmn.FactionUtil; import cokr.xit.fims.cmmn.pdf.PDFFormat; @@ -32,10 +35,8 @@ public class Advntce extends PDFFormat { add( image("background","배경이미지","").a4(0, 0).letter(0, 0).size(0, 0), - image("photo1","단속사진1","").a4(0, 0).letter(0, 0).size(0, 0), - image("photo2","단속사진2","").a4(0, 0).letter(0, 0).size(0, 0), - image("photo3","단속사진3","").a4(0, 0).letter(0, 0).size(0, 0), - image("photo4","단속사진4","").a4(0, 0).letter(0, 0).size(0, 0), + images("crdnPhoto","단속사진","").a4(110, 100).letter(116, 95).size(90, 80), + image("rprsCrdnPhoto","대표단속사진","").a4(10, 200).letter(10, 186).size(80, 80), text("rtpyrNm","수신자명",""), text("rtpyrNo","수신자번호",""), @@ -98,19 +99,9 @@ public class Advntce extends PDFFormat { case "background" -> { result = dataObject.string(""); } - case "photo1" -> { + case "rprsCrdnPhoto" -> { //대표사진 result = dataObject.string("CRDN_PHOTO1"); } - case "photo2" -> { - result = dataObject.string("CRDN_PHOTO2"); - } - case "photo3" -> { - result = dataObject.string("CRDN_PHOTO3"); - } - case "photo4" -> { - result = dataObject.string("CRDN_PHOTO4"); - } - case "rtpyrNm" -> { result = dataObject.string("RTPYR_NM"); } @@ -316,12 +307,34 @@ public class Advntce extends PDFFormat { dataObject.put("VR_ACTNO10", "101010-00-000000"); dataObject.put("EPAY_NO", "00000-0-00-00-000000000"); dataObject.put("FFNLG_CRDN_AMT", "100000"); - dataObject.put("CRDN_PHOTO1", ""); - dataObject.put("CRDN_PHOTO2", ""); - dataObject.put("CRDN_PHOTO3", ""); - dataObject.put("CRDN_PHOTO4", ""); + + dataObject.put("CRDN_PHOTO1", "samplefiles/crdn1.png"); + dataObject.put("CRDN_PHOTO2", "samplefiles/crdn2.png"); + dataObject.put("CRDN_PHOTO3", "samplefiles/crdn3.png"); + dataObject.put("CRDN_PHOTO4", "samplefiles/crdn4.png"); + dataObject.put("CRDN_PHOTO5", "samplefiles/crdn5.png"); + dataObject.put("CRDN_PHOTO6", "samplefiles/crdn6.png"); + dataObject.put("CRDN_PHOTO7", "samplefiles/crdn7.png"); return dataObject; } + @Override + public List getMappingValues(String otptArtclNm, String defaultValue, boolean forPost, + DataObject dataObject, PrintOption printOption, PDFPrintUtil pdfPrintUtil) { + List result = new ArrayList(); + + switch(otptArtclNm) { + case "crdnPhoto" -> { + int i = 1; + while(!dataObject.string("CRDN_PHOTO"+i).equals("")) { + result.add(dataObject.string("CRDN_PHOTO"+i)); + i++; + } + } + } + + return result; + } + } diff --git a/src/main/java/cokr/xit/fims/sprt/service/bean/Sprt01ServiceBean.java b/src/main/java/cokr/xit/fims/sprt/service/bean/Sprt01ServiceBean.java index 9d6aa22f..e47e9db0 100644 --- a/src/main/java/cokr/xit/fims/sprt/service/bean/Sprt01ServiceBean.java +++ b/src/main/java/cokr/xit/fims/sprt/service/bean/Sprt01ServiceBean.java @@ -33,6 +33,7 @@ import cokr.xit.fims.cmmn.hwp.format.RequestForDelivery; import cokr.xit.fims.cmmn.pdf.DefaultOtptArtclStng; import cokr.xit.fims.cmmn.pdf.PDFFormat; import cokr.xit.fims.cmmn.pdf.PDFPrintUtil; +import cokr.xit.fims.cmmn.pdf.PstnAndSize; import cokr.xit.fims.cmmn.pdf.format.Advntce; import cokr.xit.fims.cmmn.service.bean.FactionBean; import cokr.xit.fims.cmmn.service.bean.StngBean; @@ -284,6 +285,24 @@ public class Sprt01ServiceBean extends AbstractServiceBean implements Sprt01Serv 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 crndId = dataObject.string("CRDN_ID"); + + FileQuery fileQuery = new FileQuery(); + fileQuery.setInfoType(Crdn.INF_TYPE); + fileQuery.setInfoKeys(crndId); + List fileInfoList = fileBean.getFileList(fileQuery); + if(fileInfoList != null && fileInfoList.size() > 0) { + + for(int j=0; j otptArtclStngList = otptStngMapper.selectOtptArtclStngList(otptStngQuery); + //출력요소별 속성 정보 추가 pdfFormat.appendOtptAttribute(otptArtclStngList); + //출력 요소 정렬 Comparator 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 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); @@ -421,6 +447,33 @@ public class Sprt01ServiceBean extends AbstractServiceBean implements Sprt01Serv pdfPrintUtil.insertImage(doc, contentStream, imagePath, pstn, size); + } else if(prototypeStng.getComponentType().equals("images")) { + + List imagePaths = pdfFormat.getMappingValues(otptArtclNm,defaultValue,forPost,dataObject,printOption,pdfPrintUtil); + + if(otptArtclNm.equals("crdnPhoto")) { + if(rprsCrdnPhotoYn) { + imagePaths.remove(0); + } + } + + int printCntSetting = otptBscStng.number("OTPT_PHOTO_CNT").intValue(); + int dataImageCnt = imagePaths.size(); + + if(printCntSetting != 0 && dataImageCnt != 0) { + + List devideInfos = pdfPrintUtil.devideImageArea(pstn, size, printCntSetting, dataImageCnt); + + for (int i=0; i< devideInfos.size(); i++){ + PstnAndSize devideInfo = devideInfos.get(i); + + pdfPrintUtil.insertImage(doc, contentStream, + imagePaths.get(i), devideInfo.getPstn().to2Float(), devideInfo.getSize().to2Float()); + + } + + } + } } diff --git a/src/main/webapp/WEB-INF/jsp/fims/sprt/sprt01200-main.jsp b/src/main/webapp/WEB-INF/jsp/fims/sprt/sprt01200-main.jsp index 6854a009..3ce18aaf 100644 --- a/src/main/webapp/WEB-INF/jsp/fims/sprt/sprt01200-main.jsp +++ b/src/main/webapp/WEB-INF/jsp/fims/sprt/sprt01200-main.jsp @@ -248,7 +248,7 @@