|
@@ -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.entity.ImpEvent; |
|
|
import com.ffii.lioner.modules.lioner.pdf.req.UpdatePdfReq; |
|
|
import com.ffii.lioner.modules.lioner.pdf.req.UpdatePdfReq; |
|
|
import com.ffii.lioner.modules.lioner.service.FileService; |
|
|
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.lioner.template.service.TemplateService; |
|
|
import com.ffii.lioner.modules.common.SecurityUtils; |
|
|
import com.ffii.lioner.modules.common.SecurityUtils; |
|
|
import com.ffii.lioner.modules.common.service.AuditLogService; |
|
|
import com.ffii.lioner.modules.common.service.AuditLogService; |
|
@@ -194,28 +195,16 @@ public class PdfService extends AbstractBaseEntityService<Pdf, Long, PdfReposito |
|
|
return file; |
|
|
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); |
|
|
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; |
|
|
byte[] modifiedPdfBytes = pdfBytes; |
|
|
|
|
|
|
|
@@ -245,6 +234,8 @@ public class PdfService extends AbstractBaseEntityService<Pdf, Long, PdfReposito |
|
|
// logger.info("id? " + id); |
|
|
// logger.info("id? " + id); |
|
|
CommonField commonField = commonFieldService.find(commonFieldId).orElse(null); |
|
|
CommonField commonField = commonFieldService.find(commonFieldId).orElse(null); |
|
|
|
|
|
|
|
|
|
|
|
Template template = templateService.find(templateId).orElseThrow(); |
|
|
|
|
|
|
|
|
if(commonField == null){ |
|
|
if(commonField == null){ |
|
|
logger.info("No common field data found for clientId: " + clientId); |
|
|
logger.info("No common field data found for clientId: " + clientId); |
|
|
// do nothing |
|
|
// 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 |
|
|
// 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"); |
|
|
|
|
|
|
|
|
String formCode = (String)template.getRemarks(); |
|
|
|
|
|
|
|
|
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)"); |
|
@@ -273,7 +264,7 @@ public class PdfService extends AbstractBaseEntityService<Pdf, Long, PdfReposito |
|
|
setValueIfPresent(form, "fill_5", commonField.getGender(), "commonField.getGender()"); |
|
|
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_6", commonField.getDateOfBirth(), "commonField.getDateOfBirth()"); // Note: fill_6 used here again |
|
|
setValueIfPresent(form, "fill_9", commonField.getOccupation(), "commonField.getOccupation()"); |
|
|
setValueIfPresent(form, "fill_9", commonField.getOccupation(), "commonField.getOccupation()"); |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// These fields are set unconditionally if commonField is not null |
|
|
// These fields are set unconditionally if commonField is not null |
|
|
// Ensure these fields exist across all your templates or handle them conditionally |
|
|
// 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" |
|
|
StringBuilder sql = new StringBuilder("SELECT" |
|
|
+ " ff.*, " |
|
|
+ " ff.*, " |
|
|
|
|
|
+ " f.filename, " |
|
|
+ " fb.bytes AS blobValue" |
|
|
+ " fb.bytes AS blobValue" |
|
|
+ " FROM filled_form ff " |
|
|
+ " FROM filled_form ff " |
|
|
+ " LEFT JOIN file_blob fb ON ff.fileId = fb.fileId " |
|
|
+ " LEFT JOIN file_blob fb ON ff.fileId = fb.fileId " |
|
|
|
|
|
+ " LEFT JOIN file f ON fb.fileId = f.id " |
|
|
+ " WHERE ff.deleted = FALSE" |
|
|
+ " WHERE ff.deleted = FALSE" |
|
|
+ " AND ff.id = :id " |
|
|
+ " AND ff.id = :id " |
|
|
); |
|
|
); |
|
@@ -416,7 +409,7 @@ public class PdfService extends AbstractBaseEntityService<Pdf, Long, PdfReposito |
|
|
case "fill_6" -> commonField.setName(fieldValue); |
|
|
case "fill_6" -> commonField.setName(fieldValue); |
|
|
case "fill_7" -> commonField.setNameChi(fieldValue); |
|
|
case "fill_7" -> commonField.setNameChi(fieldValue); |
|
|
case "fill_11" -> commonField.setIdCard(fieldValue); |
|
|
case "fill_11" -> commonField.setIdCard(fieldValue); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case "gender_m" -> { |
|
|
case "gender_m" -> { |
|
|
commonField.setGenderMale(fieldValue); |
|
|
commonField.setGenderMale(fieldValue); |
|
|
if("on".equals(fieldValue)) { |
|
|
if("on".equals(fieldValue)) { |
|
|