|
|
@@ -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)"); |
|
|
|