diff --git a/src/main/java/cokr/xit/base/file/hwp/HWPWriter.java b/src/main/java/cokr/xit/base/file/hwp/HWPWriter.java index 1a37bed4..5a2f6f69 100644 --- a/src/main/java/cokr/xit/base/file/hwp/HWPWriter.java +++ b/src/main/java/cokr/xit/base/file/hwp/HWPWriter.java @@ -13,7 +13,6 @@ import cokr.xit.fims.cmmn.Print; import cokr.xit.fims.cmmn.hwp.AddUtil; import cokr.xit.fims.cmmn.hwp.format.HWPFormat; import cokr.xit.fims.sprt.PrintOption; -import cokr.xit.foundation.UserInfo; import cokr.xit.foundation.data.DataObject; import kr.dogfoot.hwplib.object.HWPFile; import kr.dogfoot.hwplib.reader.HWPReader; @@ -22,23 +21,17 @@ public class HWPWriter { protected Print print; protected HWPFormat format; - protected UserInfo printRequestUserInfo; - - public void setPrintRequestUserInfo(UserInfo printRequestUserInfo) { - this.printRequestUserInfo = printRequestUserInfo; - }; - public UserInfo getPrintRequestUserInfo() { - return this.printRequestUserInfo; + public void setFormat(HWPFormat format) { + this.format = format; }; - public HWPFormat setFormat(HWPFormat format) { - return this.format = format; + public void setPrint(Print print) { + this.print = print; }; - public Map makeFileFromHwpFormat(String formatType, Print print, PrintOption printOption, List dataObjectList) { + public Map makeFileFromHwpFormat(String formatType, PrintOption printOption, List dataObjectList) { Map result = new HashMap<>(); - this.print = new Print(); - this.format.setting(print); + this.format.setting(this.print); int totalDataCount = dataObjectList.size(); @@ -52,11 +45,11 @@ public class HWPWriter { 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); //공통사항 세팅 - this.format.writeGlobalInfo(resultFile, dataObjectList, printOption, print); + this.format.writeGlobalInfo(resultFile, dataObjectList, printOption, this.print); kr.dogfoot.hwplib.writer.HWPWriter.toFile(resultFile, resultHwpPath); @@ -69,13 +62,13 @@ public class HWPWriter { InputStream attachFormatIS = new ClassPathResource(this.format.getAttachFormatFilePath()).getInputStream(); HWPFile attachFormatFile = HWPReader.fromInputStream(attachFormatIS); - this.format.writeSingleDataInfo(null, attachFormatFile, dataObject, print); + this.format.writeSingleDataInfo(null, attachFormatFile, dataObject, this.print); AddUtil.insertTableInCell(attachFormatFile, resultFile, "내부"); } 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); String filePath = partFileList.get(0); result.put("filePath", filePath); diff --git a/src/main/java/cokr/xit/base/file/pdf/PDFWriter.java b/src/main/java/cokr/xit/base/file/pdf/PDFWriter.java index 1b1a097c..862f3a3c 100644 --- a/src/main/java/cokr/xit/base/file/pdf/PDFWriter.java +++ b/src/main/java/cokr/xit/base/file/pdf/PDFWriter.java @@ -1,5 +1,803 @@ 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 { + protected String paper; + protected Print print; + protected PDFPrintFormat format; + + protected DataObject otptBscStng; + protected List 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 otptArtclStngList) { + this.otptArtclStngList = otptArtclStngList; + }; + public Map makePdfFile(String formatType, String formatName, PrintOption printOption, List dataObjectList) { + Map result = new HashMap<>(); + + + + String resultFilePath = this.filePathForNewFile(); + PDDocument doc = new PDDocument();//pdf문서 생성 + + //폰트 로드 + Map fontMap = this.getFontMap(doc); + + //용지 크기 설정 + PDRectangle paper = null; + if(this.paper.equals("01")) { + paper = PDRectangle.A4; + } else { + paper = PDRectangle.LETTER; + } + + + List prototypeStngList = this.format.getPrototypeStngs(); + + try { + + + //출력요소별 속성 정보 추가 + this.format.appendOtptAttribute(this.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); + 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 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 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 imagePaths = this.format.getMappingValues(otptArtclNm,defaultValue,forPost,dataObject,printOption,print); + + List imageKeys = new ArrayList(); + List> mosSets = new ArrayList>(); + 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 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 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 textList = new ArrayList(); + + 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 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; + } + + 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 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 getFontMap(PDDocument doc) { + try { + Map 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); + } + } } diff --git a/src/main/java/cokr/xit/fims/cmmn/Print.java b/src/main/java/cokr/xit/fims/cmmn/Print.java index 1d129fe7..d6bf90ee 100644 --- a/src/main/java/cokr/xit/fims/cmmn/Print.java +++ b/src/main/java/cokr/xit/fims/cmmn/Print.java @@ -68,10 +68,7 @@ public class Print { return this.fileNameIndex = fileNameIndex; } - - - - public float mmToPt(float mm) { + public static float mmToPt(float mm) { return mm * 2.83465f; } diff --git a/src/main/java/cokr/xit/fims/cmmn/hwp/format/CvlcptOrgn.java b/src/main/java/cokr/xit/fims/cmmn/hwp/format/CvlcptOrgn.java index 9057b0bc..39f10d96 100644 --- a/src/main/java/cokr/xit/fims/cmmn/hwp/format/CvlcptOrgn.java +++ b/src/main/java/cokr/xit/fims/cmmn/hwp/format/CvlcptOrgn.java @@ -64,7 +64,6 @@ public class CvlcptOrgn extends HWPFormat { try { if(dataObject.string("PHOTO0") != null && !dataObject.string("PHOTO0").equals("")) { - System.out.println("원본사진있음"); int photoCnt = dataObject.number("ORGN_PHOTO_CNT").intValue(); int PHOTO_COUNT_PER_PAGE = 4; @@ -84,8 +83,6 @@ public class CvlcptOrgn extends HWPFormat { } - } else { - System.out.println("원본사진없음"); } } catch (Exception e) { throw new RuntimeException("[F]"+e); diff --git a/src/main/java/cokr/xit/fims/cmmn/pdf/print/PDFPrintUtil.java b/src/main/java/cokr/xit/fims/cmmn/pdf/print/PDFPrintUtil.java index 4ef4148d..d5547d33 100644 --- a/src/main/java/cokr/xit/fims/cmmn/pdf/print/PDFPrintUtil.java +++ b/src/main/java/cokr/xit/fims/cmmn/pdf/print/PDFPrintUtil.java @@ -1,518 +1,11 @@ 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.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 { - 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 textList = new ArrayList(); - - 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 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; - } - - 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 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 getFontMap(PDDocument doc) { - try { - Map 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); - } - } } diff --git a/src/main/java/cokr/xit/fims/cmmn/pdf/print/format/Advntce.java b/src/main/java/cokr/xit/fims/cmmn/pdf/print/format/Advntce.java index 743530ca..951f66ad 100644 --- a/src/main/java/cokr/xit/fims/cmmn/pdf/print/format/Advntce.java +++ b/src/main/java/cokr/xit/fims/cmmn/pdf/print/format/Advntce.java @@ -5,7 +5,7 @@ import java.util.List; import java.util.Map; 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.sprt.PrintOption; import cokr.xit.foundation.data.DataFormat; @@ -16,6 +16,14 @@ import cokr.xit.foundation.data.DataObject; */ public class Advntce extends PDFPrintFormat { + + + @Override + public void setting(Print print) { + print.setFormatKorName("사전통지서"); + this.sndngSeCd = "02"; + } + public Advntce(){ addForPost( image("postSenderLogo","우편물송신자로고","").a4(10, 0).letter(10, 0).size(0, 0), @@ -88,11 +96,11 @@ public class Advntce extends PDFPrintFormat { */ @Override public String getMappingValue(String otptArtclNm, String defaultValue, boolean forPost, - DataObject dataObject, PrintOption printOption, PDFPrintUtil pdfPrintUtil) { + DataObject dataObject, PrintOption printOption, Print print) { String result = ""; if(forPost) { - return this.getValueForPost(otptArtclNm, defaultValue, dataObject, printOption, pdfPrintUtil); + return this.getValueForPost(otptArtclNm, defaultValue, dataObject, printOption, print); } Map globalVariable = printOption.getGlobalVariable(); @@ -199,23 +207,23 @@ public class Advntce extends PDFPrintFormat { } case "otptYmd" -> { - result = DataFormat.yyyy_mm_dd(pdfPrintUtil.getPrintRequestDt().substring(0,8)); + result = DataFormat.yyyy_mm_dd(print.getPrintRequestDt().substring(0,8)); } case "otptDt" -> { - result = CmmnUtil.yyyy_mm_dd_hh_mm_ss(pdfPrintUtil.getPrintRequestDt()); + result = CmmnUtil.yyyy_mm_dd_hh_mm_ss(print.getPrintRequestDt()); } case "otptYYYY" -> { - result = pdfPrintUtil.getPrintRequestDt().substring(0,4); + result = print.getPrintRequestDt().substring(0,4); } case "otptMM" -> { - result = pdfPrintUtil.getPrintRequestDt().substring(4,6); + result = print.getPrintRequestDt().substring(4,6); } case "otptDD" -> { - result = pdfPrintUtil.getPrintRequestDt().substring(6,8); + result = print.getPrintRequestDt().substring(6,8); } case "offcsText" -> { - String instNm = (String) pdfPrintUtil.getPrintRequestUserInfo().getInfo().get("instNm"); + String instNm = (String) print.getPrintRequestUserInfo().getInfo().get("instNm"); instNm = FactionUtil.getLastWord(instNm); instNm = FactionUtil.getInstituteLeader(instNm, true); result = instNm; @@ -237,7 +245,7 @@ public class Advntce extends PDFPrintFormat { */ @Override public String getValueForPost(String otptArtclNm, String defaultValue, - DataObject dataObject, PrintOption printOption, PDFPrintUtil pdfPrintUtil) { + DataObject dataObject, PrintOption printOption, Print print) { String result = ""; switch(otptArtclNm) { @@ -257,10 +265,10 @@ public class Advntce extends PDFPrintFormat { result = printOption.getGlobalVariable().get("logoFilePath"); } case "postSenderInst" -> { - result = (String)pdfPrintUtil.getPrintRequestUserInfo().getInfo().get("instNm"); + result = (String)print.getPrintRequestUserInfo().getInfo().get("instNm"); } case "postSenderDept" -> { - result = (String)pdfPrintUtil.getPrintRequestUserInfo().getInfo().get("deptNm"); + result = (String)print.getPrintRequestUserInfo().getInfo().get("deptNm"); } case "postSenderAddr" -> { result = printOption.getGlobalVariable().get("instAddr"); @@ -285,7 +293,7 @@ public class Advntce extends PDFPrintFormat { @Override public List getMappingValues(String otptArtclNm, String defaultValue, boolean forPost, - DataObject dataObject, PrintOption printOption, PDFPrintUtil pdfPrintUtil) { + DataObject dataObject, PrintOption printOption, Print print) { List result = new ArrayList(); switch(otptArtclNm) { diff --git a/src/main/java/cokr/xit/fims/cmmn/pdf/print/format/Nht.java b/src/main/java/cokr/xit/fims/cmmn/pdf/print/format/Nht.java index 954a736f..c4aa2a3e 100644 --- a/src/main/java/cokr/xit/fims/cmmn/pdf/print/format/Nht.java +++ b/src/main/java/cokr/xit/fims/cmmn/pdf/print/format/Nht.java @@ -5,7 +5,7 @@ import java.util.List; import java.util.Map; 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.sprt.PrintOption; import cokr.xit.foundation.data.DataFormat; @@ -13,6 +13,12 @@ import cokr.xit.foundation.data.DataObject; public class Nht extends PDFPrintFormat { + @Override + public void setting(Print print) { + print.setFormatKorName("고지서"); + sndngSeCd = "03"; + } + public Nht() { addForPost( image("postSenderLogo","우편물송신자로고","").a4(10, 0).letter(10, 0).size(0, 0), @@ -95,11 +101,11 @@ public class Nht extends PDFPrintFormat { */ @Override public String getMappingValue(String otptArtclNm, String defaultValue, boolean forPost, - DataObject dataObject, PrintOption printOption, PDFPrintUtil pdfPrintUtil) { + DataObject dataObject, PrintOption printOption, Print print) { String result = ""; if(forPost) { - return this.getValueForPost(otptArtclNm, defaultValue, dataObject, printOption, pdfPrintUtil); + return this.getValueForPost(otptArtclNm, defaultValue, dataObject, printOption, print); } Map globalVariable = printOption.getGlobalVariable(); @@ -267,23 +273,23 @@ public class Nht extends PDFPrintFormat { } case "otptYmd" -> { - result = DataFormat.yyyy_mm_dd(pdfPrintUtil.getPrintRequestDt().substring(0,8)); + result = DataFormat.yyyy_mm_dd(print.getPrintRequestDt().substring(0,8)); } case "otptDt" -> { - result = CmmnUtil.yyyy_mm_dd_hh_mm_ss(pdfPrintUtil.getPrintRequestDt()); + result = CmmnUtil.yyyy_mm_dd_hh_mm_ss(print.getPrintRequestDt()); } case "otptYYYY" -> { - result = pdfPrintUtil.getPrintRequestDt().substring(0,4); + result = print.getPrintRequestDt().substring(0,4); } case "otptMM" -> { - result = pdfPrintUtil.getPrintRequestDt().substring(4,6); + result = print.getPrintRequestDt().substring(4,6); } case "otptDD" -> { - result = pdfPrintUtil.getPrintRequestDt().substring(6,8); + result = print.getPrintRequestDt().substring(6,8); } case "offcsText" -> { - String instNm = (String) pdfPrintUtil.getPrintRequestUserInfo().getInfo().get("instNm"); + String instNm = (String) print.getPrintRequestUserInfo().getInfo().get("instNm"); instNm = FactionUtil.getLastWord(instNm); instNm = FactionUtil.getInstituteLeader(instNm, true); result = instNm; @@ -305,7 +311,7 @@ public class Nht extends PDFPrintFormat { */ @Override public String getValueForPost(String otptArtclNm, String defaultValue, - DataObject dataObject, PrintOption printOption, PDFPrintUtil pdfPrintUtil) { + DataObject dataObject, PrintOption printOption, Print print) { String result = ""; switch(otptArtclNm) { @@ -325,10 +331,10 @@ public class Nht extends PDFPrintFormat { result = printOption.getGlobalVariable().get("logoFilePath"); } case "postSenderInst" -> { - result = (String)pdfPrintUtil.getPrintRequestUserInfo().getInfo().get("instNm"); + result = (String)print.getPrintRequestUserInfo().getInfo().get("instNm"); } case "postSenderDept" -> { - result = (String)pdfPrintUtil.getPrintRequestUserInfo().getInfo().get("deptNm"); + result = (String)print.getPrintRequestUserInfo().getInfo().get("deptNm"); } case "postSenderAddr" -> { result = printOption.getGlobalVariable().get("instAddr"); @@ -352,7 +358,7 @@ public class Nht extends PDFPrintFormat { @Override public List getMappingValues(String otptArtclNm, String defaultValue, boolean forPost, - DataObject dataObject, PrintOption printOption, PDFPrintUtil pdfPrintUtil) { + DataObject dataObject, PrintOption printOption, Print print) { List result = new ArrayList(); switch(otptArtclNm) { diff --git a/src/main/java/cokr/xit/fims/cmmn/pdf/print/format/PDFPrintFormat.java b/src/main/java/cokr/xit/fims/cmmn/pdf/print/format/PDFPrintFormat.java index 77be5226..1130bb75 100644 --- a/src/main/java/cokr/xit/fims/cmmn/pdf/print/format/PDFPrintFormat.java +++ b/src/main/java/cokr/xit/fims/cmmn/pdf/print/format/PDFPrintFormat.java @@ -3,12 +3,16 @@ package cokr.xit.fims.cmmn.pdf.print.format; import java.util.ArrayList; 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.PDFPrintUtil; import cokr.xit.fims.sprt.PrintOption; import cokr.xit.foundation.data.DataObject; public abstract class PDFPrintFormat { + protected String sndngSeCd; + + + public abstract void setting(Print print); protected List prototypeStngs = new ArrayList(); @@ -69,16 +73,16 @@ public abstract class PDFPrintFormat { * 출력요소에 매핑될 값을 반환한다. */ 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 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, - 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 List getMosSet(String imageKey, DataObject dataObject) { + if((List)dataObject.get("MOS"+imageKey) != null) { + return (List)dataObject.get("MOS"+imageKey); + } else { + return null; + } + } + diff --git a/src/main/java/cokr/xit/fims/cvlc/web/Cvlc01Controller.java b/src/main/java/cokr/xit/fims/cvlc/web/Cvlc01Controller.java index 99a37fd0..c0071eeb 100644 --- a/src/main/java/cokr/xit/fims/cvlc/web/Cvlc01Controller.java +++ b/src/main/java/cokr/xit/fims/cvlc/web/Cvlc01Controller.java @@ -252,8 +252,9 @@ public class Cvlc01Controller extends ApplicationController { factionBean.initUserInfo(userInfo); Print print = new Print(); print.setPrintRequestUserInfo(userInfo); + hwpWriter.setPrint(print); hwpWriter.setFormat(new CvlcptOrgn()); - Map result = hwpWriter.makeFileFromHwpFormat("info", print, printOption, dataObjectList); + Map result = hwpWriter.makeFileFromHwpFormat("info", printOption, dataObjectList); mav.addAllObjects(result); return mav; diff --git a/src/main/java/cokr/xit/fims/excl/web/Excl02Controller.java b/src/main/java/cokr/xit/fims/excl/web/Excl02Controller.java index 82168eaa..62e57cdb 100644 --- a/src/main/java/cokr/xit/fims/excl/web/Excl02Controller.java +++ b/src/main/java/cokr/xit/fims/excl/web/Excl02Controller.java @@ -357,11 +357,11 @@ public class Excl02Controller extends ApplicationController { factionBean.initUserInfo(userInfo); Print print = new Print(); print.setPrintRequestUserInfo(userInfo); - + hwpWriter.setPrint(print); hwpWriter.setFormat(new DlbrDecsnList()); List dataObjectList = opnnSbmsnBean.getOpnnSbmsnDlbrDecsns(req); - Map result = hwpWriter.makeFileFromHwpFormat("info", print, printOption, dataObjectList); + Map result = hwpWriter.makeFileFromHwpFormat("info", printOption, dataObjectList); ModelAndView mav = new ModelAndView("downloadView"); mav.addAllObjects(result); diff --git a/src/main/java/cokr/xit/fims/sndb/web/Sndb01Controller.java b/src/main/java/cokr/xit/fims/sndb/web/Sndb01Controller.java index 46106774..6dfae144 100644 --- a/src/main/java/cokr/xit/fims/sndb/web/Sndb01Controller.java +++ b/src/main/java/cokr/xit/fims/sndb/web/Sndb01Controller.java @@ -1,6 +1,7 @@ package cokr.xit.fims.sndb.web; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -12,6 +13,9 @@ import org.springframework.web.servlet.ModelAndView; import cokr.xit.base.code.CommonCode; 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.CellDef; 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.CmmnUtil; 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.crdn.Crdn; import cokr.xit.fims.mngt.service.bean.FactionBean; import cokr.xit.fims.mngt.service.bean.TaskBean; 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.SvbtcService; 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.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.bean.MediaBean; import cokr.xit.foundation.UserInfo; import cokr.xit.foundation.data.DataObject; @@ -123,12 +134,24 @@ public class Sndb01Controller extends ApplicationController { @Resource(name="stngBean") private StngBean stngBean; + @Resource(name="fileBean") + private FileBean fileBean; + @Resource(name="factionBean") private FactionBean factionBean; @Resource(name="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)을 연다. * @return /sndb/sndb01/010-main */ @@ -1482,8 +1505,9 @@ public class Sndb01Controller extends ApplicationController { Print print = new Print(); print.setPrintRequestUserInfo(userInfo); + hwpWriter.setPrint(print); - result = hwpWriter.makeFileFromHwpFormat("list", print, printOption, dataObjectList); + result = hwpWriter.makeFileFromHwpFormat("list", printOption, dataObjectList); ModelAndView mav = new ModelAndView("jsonView"); @@ -1633,7 +1657,90 @@ public class Sndb01Controller extends ApplicationController { crdnIds[iLoop] = list.get(iLoop).string("CRDN_ID"); } - Map result = integrationSearchService.makePdfFile("info", "advntce", printOption, crdnIds); + List dataObjectList = new ArrayList(); + 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 fileInfoList = fileBean.getFileList(fileQuery); + if(fileInfoList != null && fileInfoList.size() > 0) { + + for(int j=0; j 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 otptArtclStngList = otptStngMapper.selectOtptArtclStngList(otptStngQuery); + pdfWriter.setOtptArtclStngList(otptArtclStngList); + pdfWriter.setPaper(paperSeCd); + + DataObject sggStngInfo = stngBean.getStng("sgg"); + DataObject deptStngInfo = stngBean.getStng("dept"); + // + Map globalVariable = printOption.getGlobalVariable(); + if(globalVariable == null) { + globalVariable = new HashMap(); + } + 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 result = pdfWriter.makePdfFile("info", "advntce", printOption, dataObjectList); mav.addAllObjects(result); diff --git a/src/main/java/cokr/xit/fims/sprt/MediaUtil.java b/src/main/java/cokr/xit/fims/sprt/MediaUtil.java new file mode 100644 index 00000000..1472b75a --- /dev/null +++ b/src/main/java/cokr/xit/fims/sprt/MediaUtil.java @@ -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 getTransformedMosaic(List mosaicInfos, InputStream inputStream, PstnAndSize pstnAndSize_in_print) { + List 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; + } + +} diff --git a/src/main/java/cokr/xit/fims/sprt/service/IntegrationSearchService.java b/src/main/java/cokr/xit/fims/sprt/service/IntegrationSearchService.java index 86dd9ad1..f58b1d01 100644 --- a/src/main/java/cokr/xit/fims/sprt/service/IntegrationSearchService.java +++ b/src/main/java/cokr/xit/fims/sprt/service/IntegrationSearchService.java @@ -32,16 +32,6 @@ public interface IntegrationSearchService { String updateEtcCn(String etcCn, String... crdnIds); - /** pdf 출력물을 생성한다. - * @param formatType 서식유형 ,formatName 서식명, printOption 출력옵션, crdnIds 출력대상 - * @return map 출력 요청 결과 - *
  • filename: 다운로드 파일명
  • - *
  • filePath: 결과 파일 경로
  • - *
  • file: 결과 파일
  • - *
- */ - Map makePdfFile(String formatType, String formatName, PrintOption printOption, String[] crdnIds); - /** 외주요청 파일을 생성한다. * @param formatName 서식명, printOption 출력옵션, crdnIds 출력대상 * @return map 출력 요청 결과 diff --git a/src/main/java/cokr/xit/fims/sprt/service/bean/IntegrationSearchServiceBean.java b/src/main/java/cokr/xit/fims/sprt/service/bean/IntegrationSearchServiceBean.java index aef08f72..b5ee644a 100644 --- a/src/main/java/cokr/xit/fims/sprt/service/bean/IntegrationSearchServiceBean.java +++ b/src/main/java/cokr/xit/fims/sprt/service/bean/IntegrationSearchServiceBean.java @@ -10,46 +10,28 @@ import java.nio.file.Files; import java.nio.file.StandardCopyOption; 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 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 cokr.xit.base.file.service.FileQuery; import cokr.xit.base.file.service.bean.FileBean; import cokr.xit.fims.cmmn.CmmnUtil; 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.crdn.Crdn; import cokr.xit.fims.crdn.dao.CrdnListMapper; 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.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.foundation.UserInfo; import cokr.xit.foundation.component.AbstractServiceBean; import cokr.xit.foundation.data.DataObject; import net.lingala.zip4j.ZipFile; @@ -110,331 +92,6 @@ public class IntegrationSearchServiceBean extends AbstractServiceBean implements - @Override - public Map makePdfFile(String formatType, String formatName, PrintOption printOption, String[] crdnIds) { - Map 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 dataObjectList = new ArrayList(); - 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 fileInfoList = fileBean.getFileList(fileQuery); - if(fileInfoList != null && fileInfoList.size() > 0) { - - for(int j=0; j 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 globalVariable = printOption.getGlobalVariable(); - if(globalVariable == null) { - globalVariable = new HashMap(); - } - 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 prototypeStngList = pdfFormat.getPrototypeStngs(); - - try { - - //출력 요소별 설정 - List 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); - 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 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 imagePaths = pdfFormat.getMappingValues(otptArtclNm,defaultValue,forPost,dataObject,printOption,pdfPrintUtil); - List imageKeys = new ArrayList(); - 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 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 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 public Map makeOutsourcingFile(String formatName, PrintOption printOption, String[] crdnIds) { diff --git a/src/main/java/cokr/xit/fims/sprt/service/bean/MediaBean.java b/src/main/java/cokr/xit/fims/sprt/service/bean/MediaBean.java index 77f17d34..83e718c9 100644 --- a/src/main/java/cokr/xit/fims/sprt/service/bean/MediaBean.java +++ b/src/main/java/cokr/xit/fims/sprt/service/bean/MediaBean.java @@ -1,14 +1,11 @@ package cokr.xit.fims.sprt.service.bean; -import java.awt.image.BufferedImage; import java.io.InputStream; -import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.annotation.Resource; -import javax.imageio.ImageIO; import org.assertj.core.util.Arrays; 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.fims.cmmn.pdf.PstnAndSize; import cokr.xit.fims.crdn.dao.CrdnInfoMapper; +import cokr.xit.fims.sprt.MediaUtil; import cokr.xit.fims.sprt.Sprt; import cokr.xit.fims.sprt.dao.MediaMapper; import cokr.xit.foundation.AbstractComponent; @@ -107,39 +105,10 @@ public class MediaBean extends AbstractComponent { } public List getTransformedMosaic(String imageKey, InputStream inputStream, PstnAndSize pstnAndSize_in_print) { - List result = new ArrayList<>(); + List mosaicInfos = this.getMosaicList(imageKey); + return MediaUtil.getTransformedMosaic(mosaicInfos, inputStream, pstnAndSize_in_print); - 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 mosaicInfos = this.getMosaicList(imageKey); - - 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) { diff --git a/src/main/java/cokr/xit/fims/sprt/web/Sprt01Controller.java b/src/main/java/cokr/xit/fims/sprt/web/Sprt01Controller.java index 968cc252..3a3e8340 100644 --- a/src/main/java/cokr/xit/fims/sprt/web/Sprt01Controller.java +++ b/src/main/java/cokr/xit/fims/sprt/web/Sprt01Controller.java @@ -19,6 +19,7 @@ import com.fasterxml.jackson.core.type.TypeReference; import cokr.xit.base.code.CommonCode; 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; @@ -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.ReportOnClaims; 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.crdn.Crdn; 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.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.bean.MediaBean; import cokr.xit.fims.sprt.service.bean.OtptStngBean; import cokr.xit.fims.stat.dao.StatMapper; import cokr.xit.foundation.UserInfo; @@ -120,6 +125,9 @@ public class Sprt01Controller extends ApplicationController { @Resource(name = "factionBean") private FactionBean factionBean; + @Resource(name = "mediaBean") + private MediaBean mediaBean; + @Resource(name = "stngBean") private StngBean stngBean; @@ -129,6 +137,9 @@ public class Sprt01Controller extends ApplicationController { @Resource(name = "integrationSearchMapper") private IntegrationSearchMapper integrationSearchMapper; + @Resource(name = "otptStngMapper") + private OtptStngMapper otptStngMapper; + /**통합 조회 메인화면(fims/sprt/sprt01/010-main)을 연다. * * @return /fims/sprt/sprt01010 @@ -450,12 +461,13 @@ public class Sprt01Controller extends ApplicationController { factionBean.initUserInfo(userInfo); Print print = new Print(); print.setPrintRequestUserInfo(userInfo); + hwpWriter.setPrint(print); DataObject sggStngInfo = stngBean.getStng("sgg"); DataObject deptStngInfo = stngBean.getStng("dept"); hwpWriter.setFormat(new CrdnList()); - Map result = hwpWriter.makeFileFromHwpFormat("list", print, printOption, DataObjectList); + Map result = hwpWriter.makeFileFromHwpFormat("list", printOption, DataObjectList); ModelAndView mav = new ModelAndView("downloadView"); mav.addAllObjects(result); @@ -497,12 +509,14 @@ public class Sprt01Controller extends ApplicationController { factionBean.initUserInfo(userInfo); Print print = new Print(); print.setPrintRequestUserInfo(userInfo); + hwpWriter.setPrint(print); DataObject sggStngInfo = stngBean.getStng("sgg"); DataObject deptStngInfo = stngBean.getStng("dept"); hwpWriter.setFormat(new CrdnConfirm()); - Map result = hwpWriter.makeFileFromHwpFormat("info", print, printOption, dataObjectList); + + Map result = hwpWriter.makeFileFromHwpFormat("info", printOption, dataObjectList); ModelAndView mav = new ModelAndView("downloadView"); mav.addAllObjects(result); @@ -550,6 +564,7 @@ public class Sprt01Controller extends ApplicationController { factionBean.initUserInfo(userInfo); Print print = new Print(); print.setPrintRequestUserInfo(userInfo); + hwpWriter.setPrint(print); DataObject sggStngInfo = stngBean.getStng("sgg"); DataObject deptStngInfo = stngBean.getStng("dept"); @@ -560,7 +575,7 @@ public class Sprt01Controller extends ApplicationController { printOption.setGlobalVariable(globalVariable2); hwpWriter.setFormat(new RequestForDelivery()); - Map result = hwpWriter.makeFileFromHwpFormat("list", print, printOption, dataObjectList); + Map result = hwpWriter.makeFileFromHwpFormat("list", printOption, dataObjectList); mav.addAllObjects(result); return mav; } @@ -593,11 +608,12 @@ public class Sprt01Controller extends ApplicationController { factionBean.initUserInfo(userInfo); Print print = new Print(); print.setPrintRequestUserInfo(userInfo); + hwpWriter.setPrint(print); DataObject sggStngInfo = stngBean.getStng("sgg"); DataObject deptStngInfo = stngBean.getStng("dept"); Map 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; globalVariable2.put("deptAddr", deptAddr); globalVariable2.put("deptTelno", deptStngInfo.string("DEPT_TELNO")); @@ -606,7 +622,7 @@ public class Sprt01Controller extends ApplicationController { printOption.setGlobalVariable(globalVariable2); hwpWriter.setFormat(new ReportOnClaims()); - Map result = hwpWriter.makeFileFromHwpFormat("list", print, printOption, dataObjectList); + Map result = hwpWriter.makeFileFromHwpFormat("list", printOption, dataObjectList); mav.addAllObjects(result); @@ -631,12 +647,13 @@ public class Sprt01Controller extends ApplicationController { factionBean.initUserInfo(userInfo); Print print = new Print(); print.setPrintRequestUserInfo(userInfo); + hwpWriter.setPrint(print); DataObject sggStngInfo = stngBean.getStng("sgg"); DataObject deptStngInfo = stngBean.getStng("dept"); hwpWriter.setFormat(new RcvmtConfirm()); - Map result = hwpWriter.makeFileFromHwpFormat("info", print, printOption, dataObjectList); + Map result = hwpWriter.makeFileFromHwpFormat("info", printOption, dataObjectList); mav.addAllObjects(result); return mav; @@ -660,7 +677,88 @@ public class Sprt01Controller extends ApplicationController { public ModelAndView makeAdvntcePdf(PrintOption printOption, String[] crdnIds) { ModelAndView mav = new ModelAndView("downloadView"); - Map result = integrationSearchService.makePdfFile("info", "advntce", printOption, crdnIds); + List dataObjectList = new ArrayList(); + 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 fileInfoList = fileBean.getFileList(fileQuery); + if(fileInfoList != null && fileInfoList.size() > 0) { + + for(int j=0; j 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 otptArtclStngList = otptStngMapper.selectOtptArtclStngList(otptStngQuery); + pdfWriter.setOtptArtclStngList(otptArtclStngList); + pdfWriter.setPaper(paperSeCd); + + + DataObject sggStngInfo = stngBean.getStng("sgg"); + DataObject deptStngInfo = stngBean.getStng("dept"); + // + Map globalVariable = printOption.getGlobalVariable(); + if(globalVariable == null) { + globalVariable = new HashMap(); + } + 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 result = pdfWriter.makePdfFile("info", "advntce", printOption, dataObjectList); mav.addAllObjects(result); return mav; @@ -697,8 +795,90 @@ public class Sprt01Controller extends ApplicationController { */ public ModelAndView makeNhtPdf(PrintOption printOption, String[] crdnIds) { ModelAndView mav = new ModelAndView("downloadView"); + List dataObjectList = new ArrayList(); + + 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 fileInfoList = fileBean.getFileList(fileQuery); + if(fileInfoList != null && fileInfoList.size() > 0) { + + for(int j=0; j 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 otptArtclStngList = otptStngMapper.selectOtptArtclStngList(otptStngQuery); + pdfWriter.setOtptArtclStngList(otptArtclStngList); + + pdfWriter.setPaper(paperSeCd); + + + DataObject sggStngInfo = stngBean.getStng("sgg"); + DataObject deptStngInfo = stngBean.getStng("dept"); + // + Map globalVariable = printOption.getGlobalVariable(); + if(globalVariable == null) { + globalVariable = new HashMap(); + } + 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 result = integrationSearchService.makePdfFile("info", "nht", printOption, crdnIds); + Map result = pdfWriter.makePdfFile("info", "nht", printOption, dataObjectList); mav.addAllObjects(result); return mav;