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 5c9cc15..afdb8d3 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 @@ -32,6 +32,7 @@ import com.ffii.lioner.modules.lioner.commonField.service.CommonFieldService; import com.ffii.lioner.modules.lioner.entity.ImpEvent; import com.ffii.lioner.modules.lioner.pdf.req.UpdatePdfReq; import com.ffii.lioner.modules.lioner.service.FileService; +import com.ffii.lioner.modules.lioner.template.entity.Template; import com.ffii.lioner.modules.lioner.template.service.TemplateService; import com.ffii.lioner.modules.common.SecurityUtils; import com.ffii.lioner.modules.common.service.AuditLogService; @@ -194,28 +195,16 @@ public class PdfService extends AbstractBaseEntityService getTemplate(Long templateId, Long clientId) { Map template = templateService.loadTemplate(templateId); - byte[] pdfBytes = (byte[])template.get("blobValue");; - // byte[] pdfBytes; + byte[] pdfBytes = (byte[])template.get("blobValue"); + template.put("blobValue", getTemplateForm(pdfBytes, clientId, templateId)); + + return template; + } + + public byte[] getTemplateForm(byte[] pdfBytes, Long clientId, Long templateId) { byte[] modifiedPdfBytes = pdfBytes; @@ -245,6 +234,8 @@ public class PdfService extends AbstractBaseEntityService commonField.setName(fieldValue); case "fill_7" -> commonField.setNameChi(fieldValue); case "fill_11" -> commonField.setIdCard(fieldValue); - + case "gender_m" -> { commonField.setGenderMale(fieldValue); if("on".equals(fieldValue)) { diff --git a/src/main/java/com/ffii/lioner/modules/lioner/pdf/web/PdfController.java b/src/main/java/com/ffii/lioner/modules/lioner/pdf/web/PdfController.java index eac37d3..9d2e697 100644 --- a/src/main/java/com/ffii/lioner/modules/lioner/pdf/web/PdfController.java +++ b/src/main/java/com/ffii/lioner/modules/lioner/pdf/web/PdfController.java @@ -79,28 +79,36 @@ public class PdfController { } // Endpoint to serve the initial template PDF - @GetMapping(value = "/template", produces = MediaType.APPLICATION_PDF_VALUE) - public ResponseEntity getPdfTemplate(@RequestParam Long templateId, @RequestParam Long clientId) throws IOException { - - byte[] pdfBytes = pdfService.getTemplateForm(templateId, clientId); + // @GetMapping(value = "/template2", produces = MediaType.APPLICATION_PDF_VALUE) + // public ResponseEntity getPdfTemplate(@RequestParam Long templateId, @RequestParam Long clientId) throws IOException { + // byte[] pdfBytes = pdfService.getTemplateForm(templateId, clientId); + + // HttpHeaders headers = new HttpHeaders(); + // headers.setContentDispositionFormData("inline", "template_form.pdf"); + // headers.setContentType(MediaType.APPLICATION_PDF); + // return new ResponseEntity<>(pdfBytes, headers, HttpStatus.OK); + // } - HttpHeaders headers = new HttpHeaders(); - headers.setContentDispositionFormData("inline", "template_form.pdf"); - headers.setContentType(MediaType.APPLICATION_PDF); - return new ResponseEntity<>(pdfBytes, headers, HttpStatus.OK); + // Endpoint to serve the initial template PDF + @GetMapping(value = "/template") + // public ResponseEntity getPdfTemplate(@RequestParam Long templateId, @RequestParam Long clientId) throws IOException { + public Map getPdfTemplate(@RequestParam Long templateId, @RequestParam Long clientId) throws IOException { + + Map pdfTemplate = pdfService.getTemplate(templateId, clientId); + return pdfTemplate; } // Get template by template id (Unused now) - @GetMapping(value = "/template/{id}", produces = MediaType.APPLICATION_PDF_VALUE) - public ResponseEntity getPdfTemplateById(@PathVariable Long id) throws IOException { + // @GetMapping(value = "/template/{id}", produces = MediaType.APPLICATION_PDF_VALUE) + // public ResponseEntity getPdfTemplateById(@PathVariable Long id) throws IOException { - byte[] pdfBytes = pdfService.getTemplateForm(id, (long) 0); + // byte[] pdfBytes = pdfService.getTemplateForm(id, (long) 0); - HttpHeaders headers = new HttpHeaders(); - headers.setContentDispositionFormData("inline", "template_form.pdf"); - headers.setContentType(MediaType.APPLICATION_PDF); - return new ResponseEntity<>(pdfBytes, headers, HttpStatus.OK); - } + // HttpHeaders headers = new HttpHeaders(); + // headers.setContentDispositionFormData("inline", "template_form.pdf"); + // headers.setContentType(MediaType.APPLICATION_PDF); + // return new ResponseEntity<>(pdfBytes, headers, HttpStatus.OK); + // } // Endpoint to receive the filled PDF from the frontend @Transactional(isolation = Isolation.SERIALIZABLE, rollbackFor = Exception.class, readOnly = false) diff --git a/src/main/java/com/ffii/lioner/modules/lioner/template/service/TemplateService.java b/src/main/java/com/ffii/lioner/modules/lioner/template/service/TemplateService.java index 43cfd2f..9dcae04 100644 --- a/src/main/java/com/ffii/lioner/modules/lioner/template/service/TemplateService.java +++ b/src/main/java/com/ffii/lioner/modules/lioner/template/service/TemplateService.java @@ -164,7 +164,7 @@ public class TemplateService extends AbstractBaseEntityService