Przeglądaj źródła

fix pdf get template

master
kelvinsuen 4 tygodni temu
rodzic
commit
f080cdb62e
2 zmienionych plików z 22 dodań i 23 usunięć
  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 Wyświetl plik

@@ -205,13 +205,32 @@ public class PdfService extends AbstractBaseEntityService<Pdf, Long, PdfReposito
return template; 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 //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); Map<String, Object> template = templateService.loadTemplate(templateId);


//Search if there have an old form having the form code //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"); byte[] sourcePdfBytes = (byte[])sourcePdf.get("blobValue");
String formCode = (String)template.get("remarks");


//byte[] modifiedPdfBytes = pdfBytes; //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 // 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 // This prevents NullPointerExceptions if a field is missing in a template
//temp using the remarks as form code //temp using the remarks as form code
String formCode = (String)template.get("remarks");


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


+ 1
- 20
src/main/java/com/ffii/lioner/modules/lioner/template/service/TemplateService.java Wyświetl plik

@@ -146,8 +146,7 @@ public class TemplateService extends AbstractBaseEntityService<Template, Long, T
+ " t.fileId, " + " t.fileId, "
+ " t.created, " + " t.created, "
+ " t.modified, " + " t.modified, "
+ " f.filename, "
+ " fb.bytes "
+ " f.filename "
+ " FROM template t " + " FROM template t "
+ " LEFT JOIN file f ON f.id = t.fileId " + " LEFT JOIN file f ON f.id = t.fileId "
+ " LEFT JOIN file_blob fb ON f.id = fb.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); 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) { public Map<String, Object> loadPDF(Long id) {
// Pdf pdfInstance = find(id).orElseThrow(NotFoundException::new); // Pdf pdfInstance = find(id).orElseThrow(NotFoundException::new);
// byte[] blobBytes = fileService.getfileBlob(pdfInstance.getFileId()); // byte[] blobBytes = fileService.getfileBlob(pdfInstance.getFileId());


Ładowanie…
Anuluj
Zapisz