Quellcode durchsuchen

PDF service & controller update & clean-up

master
kelvinsuen vor 1 Monat
Ursprung
Commit
2d1ebad854
3 geänderte Dateien mit 41 neuen und 40 gelöschten Zeilen
  1. +16
    -23
      src/main/java/com/ffii/lioner/modules/lioner/pdf/service/PdfService.java
  2. +24
    -16
      src/main/java/com/ffii/lioner/modules/lioner/pdf/web/PdfController.java
  3. +1
    -1
      src/main/java/com/ffii/lioner/modules/lioner/template/service/TemplateService.java

+ 16
- 23
src/main/java/com/ffii/lioner/modules/lioner/pdf/service/PdfService.java Datei anzeigen

@@ -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<Pdf, Long, PdfReposito
return file;
}

//This included the common fields getting
public byte[] getTemplateForm(Long templateId, Long clientId) {
// String filename;
// switch (templateId.intValue()) {
// case 1:
// filename = "IDA.pdf";
// break;
// case 2:
// filename = "FNA.pdf";
// break;
// case 3:
// filename = "HSBCFIN.pdf";
// break;
// default:
// filename = "HSBCFIN.pdf";
// };
// ClassPathResource pdfFile = new ClassPathResource(pdf_path + filename);
public Map<String, Object> getTemplate(Long templateId, Long clientId) {
Map<String, Object> 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<Pdf, Long, PdfReposito
// logger.info("id? " + id);
CommonField commonField = commonFieldService.find(commonFieldId).orElse(null);

Template template = templateService.find(templateId).orElseThrow();

if(commonField == null){
logger.info("No common field data found for clientId: " + clientId);
// do nothing
@@ -252,7 +243,7 @@ public class PdfService extends AbstractBaseEntityService<Pdf, Long, PdfReposito
// It's highly recommended to check if the field exists before setting its value
// This prevents NullPointerExceptions if a field is missing in a template
//temp using the remarks as form code
String formCode = (String)template.get("remarks");
String formCode = (String)template.getRemarks();

if("IDA".equals(formCode)){ // This is IDA
logger.info("Processing IDA form (ID: 1)");
@@ -273,7 +264,7 @@ public class PdfService extends AbstractBaseEntityService<Pdf, Long, PdfReposito
setValueIfPresent(form, "fill_5", commonField.getGender(), "commonField.getGender()");
setValueIfPresent(form, "fill_6", commonField.getDateOfBirth(), "commonField.getDateOfBirth()"); // Note: fill_6 used here again
setValueIfPresent(form, "fill_9", commonField.getOccupation(), "commonField.getOccupation()");
}
}

// These fields are set unconditionally if commonField is not null
// Ensure these fields exist across all your templates or handle them conditionally
@@ -338,9 +329,11 @@ public class PdfService extends AbstractBaseEntityService<Pdf, Long, PdfReposito

StringBuilder sql = new StringBuilder("SELECT"
+ " ff.*, "
+ " f.filename, "
+ " fb.bytes AS blobValue"
+ " FROM filled_form ff "
+ " LEFT JOIN file_blob fb ON ff.fileId = fb.fileId "
+ " LEFT JOIN file f ON fb.fileId = f.id "
+ " WHERE ff.deleted = FALSE"
+ " AND ff.id = :id "
);
@@ -416,7 +409,7 @@ public class PdfService extends AbstractBaseEntityService<Pdf, Long, PdfReposito
case "fill_6" -> 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)) {


+ 24
- 16
src/main/java/com/ffii/lioner/modules/lioner/pdf/web/PdfController.java Datei anzeigen

@@ -79,28 +79,36 @@ public class PdfController {
}

// Endpoint to serve the initial template PDF
@GetMapping(value = "/template", produces = MediaType.APPLICATION_PDF_VALUE)
public ResponseEntity<byte[]> 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<byte[]> 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<byte[]> getPdfTemplate(@RequestParam Long templateId, @RequestParam Long clientId) throws IOException {
public Map<String, Object> getPdfTemplate(@RequestParam Long templateId, @RequestParam Long clientId) throws IOException {
Map<String, Object> 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<byte[]> getPdfTemplateById(@PathVariable Long id) throws IOException {
// @GetMapping(value = "/template/{id}", produces = MediaType.APPLICATION_PDF_VALUE)
// public ResponseEntity<byte[]> 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)


+ 1
- 1
src/main/java/com/ffii/lioner/modules/lioner/template/service/TemplateService.java Datei anzeigen

@@ -164,7 +164,7 @@ public class TemplateService extends AbstractBaseEntityService<Template, Long, T
if (args.containsKey("createDateTo"))
sql.append(" AND t.created <= :createDateTo ");
}
sql.append(" ORDER BY t.id desc ");
sql.append(" ORDER BY t.id asc ");

return jdbcDao.queryForList(sql.toString(), args);
}


Laden…
Abbrechen
Speichern