From 8c287e714cf5af89b1bc870056b58fbb70877e3a Mon Sep 17 00:00:00 2001 From: hjjeong Date: Tue, 27 Jan 2026 18:02:13 +0900 Subject: [PATCH] =?UTF-8?q?=EC=99=B8=EC=A3=BC=EA=B0=80=EA=B3=B5=EB=B0=9C?= =?UTF-8?q?=EC=A3=BC=EC=84=9C=20pdf=20=EC=B2=A8=EB=B6=80=20=EC=98=A4?= =?UTF-8?q?=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/com/pms/service/PurchaseOrderService.java | 81 +++++++++++++++++-- 1 file changed, 73 insertions(+), 8 deletions(-) diff --git a/src/com/pms/service/PurchaseOrderService.java b/src/com/pms/service/PurchaseOrderService.java index 056b096..2839a39 100644 --- a/src/com/pms/service/PurchaseOrderService.java +++ b/src/com/pms/service/PurchaseOrderService.java @@ -3007,11 +3007,30 @@ public class PurchaseOrderService { masterInfo.put("EXCELFILE_NAME", excelName); masterInfo.put("APPR_COMPLETE_DATE", frm2.format(cal.getTime())); - // 발주서 테이블 내용 생성 - String contents_table = this.makePoContentsTable(masterInfo, detailList, apprList, multiMasterList); + // pdfSessionId 확인 (PDF 첨부 여부 결정) + String pdfSessionId = CommonUtils.checkNull(paramMap.get("pdfSessionId")); + boolean isPdfAttach = false; - // 메일 본문 생성 (사용자 입력 내용 + 발주서 테이블) - String mailContents = this.makeMailContentsWithUserInput(contents, contents_table); + // PDF 파일 존재 여부 확인 + if(!"".equals(pdfSessionId)) { + String tempDir = System.getProperty("java.io.tmpdir"); + File pdfFile = new File(tempDir + File.separator + pdfSessionId + ".pdf"); + isPdfAttach = pdfFile.exists(); + } + + // 발주서 테이블 내용 생성 (PDF 첨부 시에는 사용하지 않음) + String contents_table = ""; + if(!isPdfAttach) { + contents_table = this.makePoContentsTable(masterInfo, detailList, apprList, multiMasterList); + } + + // 메일 본문 생성 (PDF 첨부 시에는 사용자 입력 내용만, 아니면 테이블 포함) + String mailContents = ""; + if(isPdfAttach) { + mailContents = this.makeMailContentsWithoutTable(contents); + } else { + mailContents = this.makeMailContentsWithUserInput(contents, contents_table); + } // 수신인 이메일 목록 생성 ArrayList toUserIdList = new ArrayList(); @@ -3044,10 +3063,26 @@ public class PurchaseOrderService { // 첨부파일 목록 생성 ArrayList attachFileList = new ArrayList(); - // 1. 발주서 엑셀 파일 첨부 - HashMap excelFile = this.makeMailAttachFileOrderSheet(masterInfo, contents_table); - if(excelFile != null) { - attachFileList.add(excelFile); + // 1. 발주서 첨부 (PDF 또는 엑셀) + if(isPdfAttach) { + // PDF 파일 첨부 + String tempDir = System.getProperty("java.io.tmpdir"); + File pdfFile = new File(tempDir + File.separator + pdfSessionId + ".pdf"); + String pdfFileName = "발주서_" + poNo + "_" + todayKor + ".pdf"; + + HashMap pdfFileMap = new HashMap(); + pdfFileMap.put(Constants.Db.COL_FILE_REAL_NAME, pdfFileName); + pdfFileMap.put(Constants.Db.COL_FILE_SAVED_NAME, pdfFile.getName()); + pdfFileMap.put(Constants.Db.COL_FILE_PATH, tempDir); + attachFileList.add(pdfFileMap); + + System.out.println("발주서 PDF 첨부 완료: " + pdfFile.getAbsolutePath()); + } else { + // 엑셀 파일 첨부 (PDF 없을 때) + HashMap excelFile = this.makeMailAttachFileOrderSheet(masterInfo, contents_table); + if(excelFile != null) { + attachFileList.add(excelFile); + } } // 2. 도면 파일 압축 첨부 (includeDrawingFiles가 Y인 경우에만) @@ -3108,6 +3143,36 @@ public class PurchaseOrderService { return resultMap; } + /** + * 사용자 입력 내용만으로 메일 본문 생성 (PDF 첨부 시 테이블 없이) + * @param userContents 사용자가 입력한 메일 내용 + * @return 완성된 메일 본문 + */ + private String makeMailContentsWithoutTable(String userContents) { + StringBuffer sb = new StringBuffer(); + sb.append(""); + sb.append(""); + sb.append(" "); + sb.append(" "); + sb.append(""); + sb.append(""); + + // 사용자 입력 내용 (줄바꿈을
로 변환) + sb.append("
"); + sb.append(userContents.replace("\n", "
")); + sb.append("
"); + + sb.append("
※ 발주서는 첨부파일(PDF)을 확인해주세요.
"); + sb.append(""); + sb.append(""); + + return sb.toString(); + } + /** * 사용자 입력 내용과 발주서 테이블을 합친 메일 본문 생성 * @param userContents 사용자가 입력한 메일 내용