Bladeren bron

fix pdf get template

master
kelvinsuen 4 weken geleden
bovenliggende
commit
f080cdb62e
2 gewijzigde bestanden met toevoegingen van 22 en 23 verwijderingen
  1. +21
    -3
      src/main/java/com/ffii/lioner/modules/lioner/pdf/service/PdfService.java
  2. +1
    -20
      src/main/java/com/ffii/lioner/modules/lioner/template/service/TemplateService.java

+ 21
- 3
src/main/java/com/ffii/lioner/modules/lioner/pdf/service/PdfService.java Bestand weergeven

@@ -205,13 +205,32 @@ public class PdfService extends AbstractBaseEntityService<Pdf, Long, PdfReposito
return template;
}

public Map<String, Object> 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<String, Object> template = templateService.loadTemplate(templateId);

//Search if there have an old form having the form code
Map<String, Object> sourcePdf = templateService.getLastPdfByFormCode((String)template.get("remarks"), clientId);
Map<String, Object> 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<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");

if("IDA".equals(formCode)){ // This is IDA
logger.info("Processing IDA form (ID: 1)");


+ 1
- 20
src/main/java/com/ffii/lioner/modules/lioner/template/service/TemplateService.java Bestand weergeven

@@ -146,8 +146,7 @@ public class TemplateService extends AbstractBaseEntityService<Template, Long, T
+ " t.fileId, "
+ " t.created, "
+ " t.modified, "
+ " f.filename, "
+ " fb.bytes "
+ " f.filename "
+ " FROM template t "
+ " LEFT JOIN file f ON f.id = t.fileId "
+ " LEFT JOIN file_blob fb ON f.id = fb.fileId "
@@ -185,24 +184,6 @@ public class TemplateService extends AbstractBaseEntityService<Template, Long, T
return jdbcDao.queryForMap(sql.toString(), Map.of("id", id)).orElseThrow(NotFoundException::new);
}

public Map<String, Object> 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<String, Object> loadPDF(Long id) {
// Pdf pdfInstance = find(id).orElseThrow(NotFoundException::new);
// byte[] blobBytes = fileService.getfileBlob(pdfInstance.getFileId());


Laden…
Annuleren
Opslaan