From f080cdb62e2ffdc5c8c6317d144758b9b242a4e5 Mon Sep 17 00:00:00 2001 From: kelvinsuen Date: Tue, 29 Jul 2025 15:31:32 +0800 Subject: [PATCH] fix pdf get template --- .../lioner/pdf/service/PdfService.java | 24 ++++++++++++++++--- .../template/service/TemplateService.java | 21 +--------------- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/ffii/lioner/modules/lioner/pdf/service/PdfService.java b/src/main/java/com/ffii/lioner/modules/lioner/pdf/service/PdfService.java index 36e0d32..74da92b 100644 --- a/src/main/java/com/ffii/lioner/modules/lioner/pdf/service/PdfService.java +++ b/src/main/java/com/ffii/lioner/modules/lioner/pdf/service/PdfService.java @@ -205,13 +205,32 @@ public class PdfService extends AbstractBaseEntityService getLastPdf(Long clientId, Long templateId) { + StringBuilder sql = new StringBuilder("SELECT" + + " ff.id, " + + " ff.remarks, " + + " f.filename, " + + " fb.bytes AS blobValue " + + " FROM filled_form ff " + + " LEFT JOIN file f ON f.id = ff.fileId " + + " LEFT JOIN file_blob fb ON f.id = fb.fileId " + + " WHERE ff.deleted = FALSE " + + " AND ff.clientId = :clientId " + + " AND ff.templateId = :templateId " + + " ORDER BY ff.id DESC LIMIT 1 " + ); + return jdbcDao.queryForMap(sql.toString(), Map.of("clientId", clientId, "templateId", templateId)).orElse(null); + } + //This included the common fields getting - public byte[] getTemplateForm(byte[] pdfBytes, Long templateId, Long clientId) throws IOException { + public byte[] getTemplateForm(byte[] pdfBytes, Long clientId, Long templateId) throws IOException { Map template = templateService.loadTemplate(templateId); //Search if there have an old form having the form code - Map sourcePdf = templateService.getLastPdfByFormCode((String)template.get("remarks"), clientId); + Map sourcePdf = getLastPdf(clientId, templateId); + if (sourcePdf == null) { sourcePdf = template; } byte[] sourcePdfBytes = (byte[])sourcePdf.get("blobValue"); + String formCode = (String)template.get("remarks"); //byte[] modifiedPdfBytes = pdfBytes; @@ -286,7 +305,6 @@ public class PdfService extends AbstractBaseEntityService getLastPdfByFormCode(String formCode, Long clientId) { - StringBuilder sql = new StringBuilder("SELECT" - + " t.id, " - + " t.name, " - + " t.remarks, " - + " f.filename, " - + " fb.bytes AS blobValue " - + " FROM filled_form ff " - + " LEFT JOIN template t ON ff.templateId = t.id " - + " LEFT JOIN file f ON f.id = t.fileId " - + " LEFT JOIN file_blob fb ON f.id = fb.fileId " - + " WHERE t.deleted = FALSE " - + " AND t.remarks = :formCode and ff.clientId = :clientId " - + " ORDER BY ff.id DESC LIMIT 1 " - ); - return jdbcDao.queryForMap(sql.toString(), Map.of("clientId", clientId, "formCode", formCode)).orElseThrow(NotFoundException::new); - } - public Map loadPDF(Long id) { // Pdf pdfInstance = find(id).orElseThrow(NotFoundException::new); // byte[] blobBytes = fileService.getfileBlob(pdfInstance.getFileId());