瀏覽代碼

no message

master
[email protected] 3 週之前
父節點
當前提交
e8b21c117a
共有 1 個檔案被更改,包括 186 行新增205 行删除
  1. +186
    -205
      src/main/java/com/ffii/lioner/modules/lioner/pdf/service/PdfService.java

+ 186
- 205
src/main/java/com/ffii/lioner/modules/lioner/pdf/service/PdfService.java 查看文件

@@ -4,56 +4,40 @@ import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import org.apache.commons.lang3.math.NumberUtils;
import org.apache.pdfbox.Loader;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm;
import org.apache.pdfbox.pdmodel.interactive.form.PDField;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import com.ffii.lioner.modules.lioner.pdf.entity.Pdf;
import com.ffii.lioner.modules.lioner.pdf.entity.PdfRepository;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ffii.core.exception.NotFoundException;
import com.ffii.core.exception.UnprocessableEntityException;
import com.ffii.core.support.AbstractBaseEntityService;
import com.ffii.core.support.JdbcDao;
import com.ffii.core.utils.BeanUtils;
import com.ffii.lioner.modules.common.service.AuditLogService;
import com.ffii.lioner.modules.lioner.commonField.entity.CommonField;
import com.ffii.lioner.modules.lioner.commonField.service.CommonFieldService;
import com.ffii.lioner.modules.lioner.entity.ImpEvent;
import com.ffii.lioner.modules.lioner.pdf.entity.Pdf;
import com.ffii.lioner.modules.lioner.pdf.entity.PdfRepository;
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;
import com.ffii.lioner.modules.master.entity.SubDivision;
import com.itextpdf.forms.PdfAcroForm;
import com.itextpdf.forms.fields.PdfFormField;
import com.itextpdf.io.source.ByteArrayOutputStream;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfReader;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ffii.core.exception.NotFoundException;
import com.ffii.core.exception.UnprocessableEntityException;
import com.ffii.core.support.AbstractBaseEntityService;
import com.ffii.core.support.JdbcDao;
import com.ffii.core.utils.BeanUtils;
import com.ffii.core.utils.JsonUtils;
import com.ffii.core.utils.Params;

import jakarta.persistence.Table;

@Service
public class PdfService extends AbstractBaseEntityService<Pdf, Long, PdfRepository> {
@@ -258,7 +242,7 @@ public class PdfService extends AbstractBaseEntityService<Pdf, Long, PdfReposito

if (form != null) {
/* START of copying the source fields if exist */
/* START of copying the source fields if exist */
if(sourceForm != null){
for (Map.Entry<String, PdfFormField> entry : sourceForm.getFormFields().entrySet()) {
PdfFormField sourceField = entry.getValue();
@@ -266,11 +250,13 @@ public class PdfService extends AbstractBaseEntityService<Pdf, Long, PdfReposito
if(sourceField.getFieldName() != null){
String sourceFieldName = sourceField.getFieldName().toUnicodeString();
if(sourceField.getValue() != null){
String sourceFieldValue = sourceField.getValue().toString();
String sourceFieldValue = sourceField.getValueAsString();
PdfFormField targetField = form.getField(sourceFieldName);
//logger.info("Field '" + sourceFieldName + "' as '" + sourceFieldValue + "' from source set in target PDF.");

if (targetField != null) {
targetField.setValue(sourceFieldValue); // Set the value in the target field
targetField.setValue(sourceFieldValue); // Set the value in the target field
} else {
//System.out.println("Field '" + sourceFieldName + "' from source not found in target PDF.");
}
@@ -308,221 +294,216 @@ public class PdfService extends AbstractBaseEntityService<Pdf, Long, PdfReposito

if("IDA".equals(formCode)){ // This is IDA
logger.info("Processing IDA form (ID: 1)");
setValueIfPresent(form, "fill_6", commonField.getName(), "commonField.getName()");
setValueIfPresent(form, "fill_7", commonField.getNameChi(), "commonField.getNameChi()");
setValueIfPresent(form, "fill_11", commonField.getIdCard(), "commonField.getIdCard()");
setValueIfPresent(form, "fill_6", commonField.getName(), null);
setValueIfPresent(form, "fill_7", commonField.getNameChi(), null);
setValueIfPresent(form, "fill_11", commonField.getIdCard(), null);

/* Page1 Start */
setValueIfPresent(form, "gender_m", commonField.getGenderMale(), "commonField.getGenderMale()");
setValueIfPresent(form, "gender_f", commonField.getGenderFemale(), "commonField.getGenderFemale()");
setValueIfPresent(form, "gender_m", commonField.getGenderMale(), null);
setValueIfPresent(form, "gender_f", commonField.getGenderFemale(), null);

setValueIfPresent(form, "date_dd", commonField.getDdDateOfBirth(), "commonField.getDdDateOfBirth()");
setValueIfPresent(form, "date_mm", commonField.getMmDateOfBirth(), "commonField.getMmDateOfBirth()");
setValueIfPresent(form, "date_yyyy", commonField.getYyyyDateOfBirth(), "commonField.getYyyyDateOfBirth()");
setValueIfPresent(form, "date_dd", commonField.getDdDateOfBirth(), null);
setValueIfPresent(form, "date_mm", commonField.getMmDateOfBirth(), null);
setValueIfPresent(form, "date_yyyy", commonField.getYyyyDateOfBirth(), null);
setValueIfPresent(form, "fill_17", commonField.getContactNo(), "commonField.getContactNo()");
setValueIfPresent(form, "edu_pri", commonField.getEduPri(), "commonField.getEduPri()");
setValueIfPresent(form, "edu_sec", commonField.getEduSec(), "commonField.getEduSec()");
setValueIfPresent(form, "edu_post_sec", commonField.getEduPostSec(), "commonField.getEduPostSec()");
setValueIfPresent(form, "fill_17", commonField.getContactNo(), null);
setValueIfPresent(form, "edu_pri", commonField.getEduPri(), null);
setValueIfPresent(form, "edu_sec", commonField.getEduSec(), null);
setValueIfPresent(form, "edu_post_sec", commonField.getEduPostSec(), null);
/* Page1 End */
/* Page2 Start */
setValueIfPresent(form, "own_income", commonField.getOwn_income(), "commonField.getOwn_income()");
setValueIfPresent(form, "savings", commonField.getSavings(), "commonField.getSavings()");
setValueIfPresent(form, "premium_financing", commonField.getPremium_financing(), "commonField.getPremium_financing()");
setValueIfPresent(form, "others_funds", commonField.getOthers_funds(), "commonField.getOthers_funds()");
setValueIfPresent(form, "others_funds_desc", commonField.getOthers_funds_desc(), "commonField.getOthers_funds_desc()");
setValueIfPresent(form, "own_income", commonField.getOwn_income(), null);
setValueIfPresent(form, "savings", commonField.getSavings(), null);
setValueIfPresent(form, "premium_financing", commonField.getPremium_financing(), null);
setValueIfPresent(form, "others_funds", commonField.getOthers_funds(), null);
setValueIfPresent(form, "others_funds_desc", commonField.getOthers_funds_desc(), null);
/* Page2 End */
/* Page3 Start */
setValueIfPresent(form, "fill_26_4", commonField.getFna_c1a_amount(), "commonField.getFna_c1a_amount()");
setValueIfPresent(form, "fill_26_4", commonField.getFna_c1a_amount(), null);
/* Page3 End */
/* Page4 Start */
setValueIfPresent(form, "total_asset", commonField.getFna_c2a_amount(), "commonField.getFna_c2a_amount()");
setValueIfPresent(form, "fill_56", commonField.getFna_c2b_amount(), "commonField.getFna_c2b_amount()");
/* Page4 End */
setValueIfPresent(form, "total_asset", commonField.getFna_c2a_amount(), null);
setValueIfPresent(form, "fill_56", commonField.getFna_c2b_amount(), null);

} else if("FNA".equals(formCode)){ // This is FNA
//logger.info("Processing FNA form (ID: 2)");
/* Page1 Start */
setValueIfPresent(form, "fna_a_name", commonField.getName(), "commonField.getName()");
setValueIfPresent(form, "fna_a_birth", commonField.getDateOfBirth(), "commonField.getDateOfBirth()");
setValueIfPresent(form, "fna_a_occupation", commonField.getOccupation(), "commonField.getOccupation()");
setValueIfPresent(form, "fna_a_primary", commonField.getEduPri(), "commonField.getEduPri()");
setValueIfPresent(form, "fna_a_secondary", commonField.getEduSec(), "commonField.getEduSec()");
setValueIfPresent(form, "fna_a_tertiary", commonField.getEduTer(), "commonField.getEduTer()");
setValueIfPresent(form, "fna_a_tertiary", commonField.getEduTer(), "commonField.getEduTer()");
setValueIfPresent(form, "fna_a_marital", commonField.getMaritalStatus(), "commonField.getMaritalStatus()");
setValueIfPresent(form, "fna_a_contact", commonField.getContactNo(), "commonField.getContactNo()");
setValueIfPresent(form, "fna_a_dependents", commonField.getNoOfDependents(), "commonField.getNoOfDependents()");
setValueIfPresent(form, "fna_c1a_amount", commonField.getFna_c1a_amount(), "commonField.getFna_c1a_amount()");
setValueIfPresent(form, "fna_c1b_amount", commonField.getFna_c1b_amount(), "commonField.getFna_c1b_amount()");
setValueIfPresent(form, "fna_c1c_1_amount", commonField.getFna_c1c_1_amount(), "commonField.getFna_c1c_1_amount()");
setValueIfPresent(form, "fna_c1c_2_amount", commonField.getFna_c1c_2_amount(), "commonField.getFna_c1c_2_amount()");
setValueIfPresent(form, "fna_c1c_3_amount", commonField.getFna_c1c_3_amount(), "commonField.getFna_c1c_3_amount()");
setValueIfPresent(form, "fna_c1d_amount", commonField.getFna_c1d_amount(), "commonField.getFna_c1d_amount()");
setValueIfPresent(form, "fna_c2a_amount", commonField.getFna_c2a_amount(), "commonField.getFna_c2a_amount()");
setValueIfPresent(form, "fna_c2b_amount", commonField.getFna_c2b_amount(), "commonField.getFna_c2b_amount()");
setValueIfPresent(form, "fna_c2c_amount", commonField.getFna_c2c_amount(), "commonField.getFna_c2c_amount()");
setValueIfPresent(form, "fna_c2d_amount", commonField.getFna_c2d_amount(), "commonField.getFna_c2d_amount()");
setValueIfPresent(form, "fna_c2e_amount", commonField.getFna_c2e_amount(), "commonField.getFna_c2e_amount()");
setValueIfPresent(form, "fna_b1_a", commonField.getFna_b1_a(), "commonField.getFna_b1_a()");
setValueIfPresent(form, "fna_b1_a_amount", commonField.getFna_b1_a_amount(), "commonField.getFna_b1_a_amount()");
setValueIfPresent(form, "fna_b1_b", commonField.getFna_b1_b(), "commonField.getFna_b1_b()");
setValueIfPresent(form, "fna_b1a_4_amount", commonField.getFna_b1a_4_amount(), "commonField.getFna_b1a_4_amount()");
setValueIfPresent(form, "fna_b1_c", commonField.getFna_b1_c(), "commonField.getFna_b1_c()");
setValueIfPresent(form, "fna_b1_d", commonField.getFna_b1_d(), "commonField.getFna_b1_d()");
setValueIfPresent(form, "fna_b1_d_year", commonField.getFna_b1_d_year(), "commonField.getFna_b1_d_year()");
setValueIfPresent(form, "fna_b1_d_amount", commonField.getFna_b1_d_amount(), "commonField.getFna_b1_d_amount()");
setValueIfPresent(form, "fna_a_name", commonField.getName(), null);
setValueIfPresent(form, "fna_a_birth", commonField.getDateOfBirth(), null);
setValueIfPresent(form, "fna_a_occupation", commonField.getOccupation(), null);
setValueIfPresent(form, "fna_a_primary", commonField.getEduPri(), null);
setValueIfPresent(form, "fna_a_secondary", commonField.getEduSec(), null);
setValueIfPresent(form, "fna_a_tertiary", commonField.getEduTer(), null);
setValueIfPresent(form, "fna_a_tertiary", commonField.getEduTer(), null);
setValueIfPresent(form, "fna_a_marital", commonField.getMaritalStatus(), null);
setValueIfPresent(form, "fna_a_contact", commonField.getContactNo(), null);
setValueIfPresent(form, "fna_a_dependents", commonField.getNoOfDependents(), null);
setValueIfPresent(form, "fna_c1a_amount", commonField.getFna_c1a_amount(), null);
setValueIfPresent(form, "fna_c1b_amount", commonField.getFna_c1b_amount(), null);
setValueIfPresent(form, "fna_c1c_1_amount", commonField.getFna_c1c_1_amount(), null);
setValueIfPresent(form, "fna_c1c_2_amount", commonField.getFna_c1c_2_amount(), null);
setValueIfPresent(form, "fna_c1c_3_amount", commonField.getFna_c1c_3_amount(), null);
setValueIfPresent(form, "fna_c1d_amount", commonField.getFna_c1d_amount(), null);
setValueIfPresent(form, "fna_c2a_amount", commonField.getFna_c2a_amount(), null);
setValueIfPresent(form, "fna_c2b_amount", commonField.getFna_c2b_amount(), null);
setValueIfPresent(form, "fna_c2c_amount", commonField.getFna_c2c_amount(), null);
setValueIfPresent(form, "fna_c2d_amount", commonField.getFna_c2d_amount(), null);
setValueIfPresent(form, "fna_c2e_amount", commonField.getFna_c2e_amount(), null);
setValueIfPresent(form, "fna_b1_a", commonField.getFna_b1_a(), null);
setValueIfPresent(form, "fna_b1_a_amount", commonField.getFna_b1_a_amount(), null);
setValueIfPresent(form, "fna_b1_b", commonField.getFna_b1_b(), null);
setValueIfPresent(form, "fna_b1a_4_amount", commonField.getFna_b1a_4_amount(), null);
setValueIfPresent(form, "fna_b1_c", commonField.getFna_b1_c(), null);
setValueIfPresent(form, "fna_b1_d", commonField.getFna_b1_d(), null);
setValueIfPresent(form, "fna_b1_d_year", commonField.getFna_b1_d_year(), null);
setValueIfPresent(form, "fna_b1_d_amount", commonField.getFna_b1_d_amount(), null);
/* Page1 End */
/* Page2 Start */
setValueIfPresent(form, "fna_b1_e", commonField.getFna_b1_e(), "commonField.getFna_b1_e()");
setValueIfPresent(form, "fna_b1_f", commonField.getFna_b1_f(), "commonField.getFna_b1_f()");
setValueIfPresent(form, "fna_b1_f_other", commonField.getFna_b1_f_other(), "commonField.getFna_b1_f_other()");
setValueIfPresent(form, "fna_b1_f_desc", commonField.getFna_b1_f_desc(), "commonField.getFna_b1_f_desc()");
setValueIfPresent(form, "fna_b2_a", commonField.getFna_b2_a(), "commonField.getFna_b2_a()");
setValueIfPresent(form, "fna_b2_b", commonField.getFna_b2_b(), "commonField.getFna_b2_b()");
setValueIfPresent(form, "fna_b2_d", commonField.getFna_b2_d(), "commonField.getFna_b2_d()");
setValueIfPresent(form, "fna_b2_e", commonField.getFna_b2_e(), "commonField.getFna_b2_e()");
setValueIfPresent(form, "fna_b2_f", commonField.getFna_b2_f(), "commonField.getFna_b2_f()");
setValueIfPresent(form, "fna_b2_g", commonField.getFna_b2_g(), "commonField.getFna_b2_g()");
setValueIfPresent(form, "fna_b1_e", commonField.getFna_b1_e(), "on");
setValueIfPresent(form, "fna_b1_f", commonField.getFna_b1_f(), "on");
setValueIfPresent(form, "fna_b1_f_other", commonField.getFna_b1_f_other(), null);
setValueIfPresent(form, "fna_b1_f_desc", commonField.getFna_b1_f_desc(), "on");
setValueIfPresent(form, "fna_b2_a", commonField.getFna_b2_a(), "on");
setValueIfPresent(form, "fna_b2_b", commonField.getFna_b2_b(), "on");
setValueIfPresent(form, "fna_b2_d", commonField.getFna_b2_d(), "on");
setValueIfPresent(form, "fna_b2_e", commonField.getFna_b2_e(), "on");
setValueIfPresent(form, "fna_b2_f", commonField.getFna_b2_f(), "on");
setValueIfPresent(form, "fna_b2_g", commonField.getFna_b2_g(), "on");
/* Page2 End */
/* Page3 Start */
setValueIfPresent(form, "fna_c1e_10", commonField.getFna_c1e_10(), "commonField.getFna_c1e_10()");
setValueIfPresent(form, "fna_c1e_10_20", commonField.getFna_c1e_10_20(), "commonField.getFna_c1e_10_20()");
setValueIfPresent(form, "fna_c1e_21_30", commonField.getFna_c1e_21_30(), "commonField.getFna_c1e_21_30()");
setValueIfPresent(form, "fna_c1e_31_40", commonField.getFna_c1e_31_40(), "commonField.getFna_c1e_31_40()");
setValueIfPresent(form, "fna_c1e_41_50", commonField.getFna_c1e_41_50(), "commonField.getFna_c1e_41_50()");
setValueIfPresent(form, "fna_c1e_50", commonField.getFna_c1e_50(), "commonField.getFna_c1e_50()");
setValueIfPresent(form, "fna_c1e_10", commonField.getFna_c1e_10(), "on");
setValueIfPresent(form, "fna_c1e_10_20", commonField.getFna_c1e_10_20(), "on");
setValueIfPresent(form, "fna_c1e_21_30", commonField.getFna_c1e_21_30(), "on");
setValueIfPresent(form, "fna_c1e_31_40", commonField.getFna_c1e_31_40(), "on");
setValueIfPresent(form, "fna_c1e_41_50", commonField.getFna_c1e_41_50(), "on");
setValueIfPresent(form, "fna_c1e_50", commonField.getFna_c1e_50(), "on");
/* Page3 End */
/* Page4 Start */
setValueIfPresent(form, "fna_c2f_10", commonField.getFna_c2f_10(), "commonField.getFna_c2f_10()");
setValueIfPresent(form, "fna_c2f_10_20", commonField.getFna_c2f_10_20(), "commonField.getFna_c2f_10_20()");
setValueIfPresent(form, "fna_c2f_21_30", commonField.getFna_c2f_21_30(), "commonField.getFna_c2f_21_30()");
setValueIfPresent(form, "fna_c2f_31_40", commonField.getFna_c2f_31_40(), "commonField.getFna_c2f_31_40()");
setValueIfPresent(form, "fna_c2f_41_50", commonField.getFna_c2f_41_50(), "commonField.getFna_c2f_41_50()");
setValueIfPresent(form, "fna_c2f_50", commonField.getFna_c2f_50(), "commonField.getFna_c2f_50()");
setValueIfPresent(form, "fna_c2f_10", commonField.getFna_c2f_10(), "on");
setValueIfPresent(form, "fna_c2f_10_20", commonField.getFna_c2f_10_20(), "on");
setValueIfPresent(form, "fna_c2f_21_30", commonField.getFna_c2f_21_30(), "on");
setValueIfPresent(form, "fna_c2f_31_40", commonField.getFna_c2f_31_40(), "on");
setValueIfPresent(form, "fna_c2f_41_50", commonField.getFna_c2f_41_50(), "on");
setValueIfPresent(form, "fna_c2f_50", commonField.getFna_c2f_50(), "on");
/* Page4 End */
/* Page5 End */
setValueIfPresent(form, "fna_c3a_2_5", commonField.getFna_c3a_2_5(), "commonField.getFna_c3a_2_5()");
setValueIfPresent(form, "fna_c3a_6_10", commonField.getFna_c3a_6_10(), "commonField.getFna_c3a_6_10()");
setValueIfPresent(form, "fna_c3a_11_15", commonField.getFna_c3a_11_15(), "commonField.getFna_c3a_11_15()");
setValueIfPresent(form, "fna_c3a_16_20", commonField.getFna_c3a_16_20(), "commonField.getFna_c3a_16_20()");
setValueIfPresent(form, "fna_c3a_20", commonField.getFna_c3a_20(), "commonField.getFna_c3a_20()");
setValueIfPresent(form, "fna_c3a_life", commonField.getFna_c3a_life(), "commonField.getFna_c3a_life()");
setValueIfPresent(form, "fna_c3a_single_pay", commonField.getFna_c3a_single_pay(), "commonField.getFna_c3a_single_pay()");
setValueIfPresent(form, "fna_a_retire", commonField.getFna_a_retire(), "commonField.getFna_a_retire()");
setValueIfPresent(form, "fna_c3b_salary", commonField.getFna_c3b_salary(), "commonField.getFna_c3b_salary()");
setValueIfPresent(form, "fna_c3b_income", commonField.getFna_c3b_income(), "commonField.getFna_c3b_income()");
setValueIfPresent(form, "fna_c3b_saving", commonField.getFna_c3b_saving(), "commonField.getFna_c3b_saving()");
setValueIfPresent(form, "fna_c3b_investments", commonField.getFna_c3b_investments(), "commonField.getFna_c3b_investments()");
setValueIfPresent(form, "fna_c3b_policy", commonField.getFna_c3b_policy(), "commonField.getFna_c3b_policy()");
setValueIfPresent(form, "fna_c3b_others", commonField.getFna_c3b_others(), "commonField.getFna_c3b_others()");
setValueIfPresent(form, "fna_c3b_desc", commonField.getFna_c3b_desc(), "commonField.getFna_c3b_desc()");
setValueIfPresent(form, "fna_c3a_2_5", commonField.getFna_c3a_2_5(), "on");
setValueIfPresent(form, "fna_c3a_6_10", commonField.getFna_c3a_6_10(), "on");
setValueIfPresent(form, "fna_c3a_11_15", commonField.getFna_c3a_11_15(), "on");
setValueIfPresent(form, "fna_c3a_16_20", commonField.getFna_c3a_16_20(), "on");
setValueIfPresent(form, "fna_c3a_20", commonField.getFna_c3a_20(), "on");
setValueIfPresent(form, "fna_c3a_life", commonField.getFna_c3a_life(), "on");
setValueIfPresent(form, "fna_c3a_single_pay", commonField.getFna_c3a_single_pay(), "on");
setValueIfPresent(form, "fna_a_retire", commonField.getFna_a_retire(), "on");
setValueIfPresent(form, "fna_c3b_salary", commonField.getFna_c3b_salary(), "on");
setValueIfPresent(form, "fna_c3b_income", commonField.getFna_c3b_income(), "on");
setValueIfPresent(form, "fna_c3b_saving", commonField.getFna_c3b_saving(), "on");
setValueIfPresent(form, "fna_c3b_investments", commonField.getFna_c3b_investments(), "on");
setValueIfPresent(form, "fna_c3b_policy", commonField.getFna_c3b_policy(), "on");
setValueIfPresent(form, "fna_c3b_others", commonField.getFna_c3b_others(), "on");
setValueIfPresent(form, "fna_c3b_desc", commonField.getFna_c3b_desc(), null);
/* Page5 End */

} else if("HSBCFIN".equals(formCode)){ // This is HSBCFIN
//logger.info("Processing HSBCFIN form (ID: 3)");
/* Page1 Start */
setValueIfPresent(form, "fill_3", commonField.getName(), "commonField.getName()");
setValueIfPresent(form, "fill_4", commonField.getNameChi(), "commonField.getNameChi()");
setValueIfPresent(form, "fill_5", commonField.getGender(), "commonField.getGender()");
setValueIfPresent(form, "fill_6", commonField.getDateOfBirth(), "commonField.getDateOfBirth()");
setValueIfPresent(form, "fill_9", commonField.getOccupation(), "commonField.getOccupation()");
setValueIfPresent(form, "fill_7", commonField.getMaritalStatus(), "commonField.getMaritalStatus()");
setValueIfPresent(form, "fill_8", commonField.getNoOfDependents(), "commonField.getNoOfDependents()");
setValueIfPresent(form, "fill_10", commonField.getContactNo(), "commonField.getContactNo()");
setValueIfPresent(form, "fill_3", commonField.getName(), null);
setValueIfPresent(form, "fill_4", commonField.getNameChi(), null);
setValueIfPresent(form, "fill_5", commonField.getGender(), null);
setValueIfPresent(form, "fill_6", commonField.getDateOfBirth(), null);
setValueIfPresent(form, "fill_9", commonField.getOccupation(), null);
setValueIfPresent(form, "fill_7", commonField.getMaritalStatus(), null);
setValueIfPresent(form, "fill_8", commonField.getNoOfDependents(), null);
setValueIfPresent(form, "fill_10", commonField.getContactNo(), null);;
setValueIfPresent(form, "toggle_1", commonField.getEduPri(), "commonField.getEduPri()");
setValueIfPresent(form, "toggle_2", commonField.getEduSec(), "commonField.getEduSec()");
setValueIfPresent(form, "toggle_3", commonField.getEduPostSec(), "commonField.getEduPostSec()");
setValueIfPresent(form, "toggle_3", commonField.getEduTer(), "commonField.getEduTer()"); //it may by filled in IDA edu ter
setValueIfPresent(form, "toggle_1", commonField.getEduPri(), null);
setValueIfPresent(form, "toggle_2", commonField.getEduSec(), null);
setValueIfPresent(form, "toggle_3", commonField.getEduPostSec(), null);
setValueIfPresent(form, "toggle_3", commonField.getEduTer(), null);
setValueIfPresent(form, "fill_11", NumberUtils.toScaledBigDecimal(NumberUtils.toScaledBigDecimal(commonField.getFna_c1a_amount(), 0, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(12))).toString() , "commonField.getFna_c1a_amount()"); //annual salary
setValueIfPresent(form, "fill_12", NumberUtils.toScaledBigDecimal(NumberUtils.toScaledBigDecimal(commonField.getFna_c1b_amount(), 0, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(12))).toString() , "commonField.getFna_c1b_amount()"); //annual salary
setValueIfPresent(form, "fill_11", NumberUtils.toScaledBigDecimal(NumberUtils.toScaledBigDecimal(commonField.getFna_c1a_amount(), 0, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(12))).toString() , null); //annual
setValueIfPresent(form, "fill_12", NumberUtils.toScaledBigDecimal(NumberUtils.toScaledBigDecimal(commonField.getFna_c1b_amount(), 0, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(12))).toString() , null); //annual
setValueIfPresent(form, "fill_12a", commonField.getFna_c1c_3_amount(), "commonField.getFna_c1c_3_amount()");
setValueIfPresent(form, "fill_13", commonField.getFna_c1c_3_amount(), "commonField.getFna_c1c_3_amount()");
setValueIfPresent(form, "fill_14", commonField.getFna_c1c_2_amount(), "commonField.getFna_c1c_2_amount()");
setValueIfPresent(form, "fill_16", commonField.getFna_c1d_amount(), "commonField.getFna_c1d_amount()");
setValueIfPresent(form, "fill_12a", commonField.getFna_c1c_3_amount(), null);
setValueIfPresent(form, "fill_13", commonField.getFna_c1c_3_amount(), null);
setValueIfPresent(form, "fill_14", commonField.getFna_c1c_2_amount(), null);
setValueIfPresent(form, "fill_16", commonField.getFna_c1d_amount(), null);
/* Page1 End */
/* Page2 Start */
setValueIfPresent(form, "fill_01", commonField.getFna_c2a_amount(), "commonField.getFna_c2a_amount()");
setValueIfPresent(form, "fill_02", commonField.getFna_c2b_amount(), "commonField.getFna_c2b_amount()");
setValueIfPresent(form, "fill_03", commonField.getFna_c2c_amount(), "commonField.getFna_c2c_amount()");
setValueIfPresent(form, "fill_04", commonField.getFna_c2d_amount(), "commonField.getFna_c2d_amount()");
setValueIfPresent(form, "fill_05", commonField.getFna_c2e_amount(), "commonField.getFna_c2e_amount()");
setValueIfPresent(form, "Financial Protection", commonField.getFna_b1_a(), "commonField.getFna_b1_a()");
setValueIfPresent(form, "Preparation", commonField.getFna_b1_b(), "commonField.getFna_b1_b()");
setValueIfPresent(form, "Providing", commonField.getFna_b1_c(), "commonField.getFna_b1_c()");
setValueIfPresent(form, "Saving", commonField.getFna_b1_d(), "commonField.getFna_b1_d()");
setValueIfPresent(form, "Investment", commonField.getFna_b1_e(), "commonField.getFna_b1_e()");
setValueIfPresent(form, "Others", commonField.getFna_b1_f(), "commonField.getFna_b1_f()");
setValueIfPresent(form, "fill_8_2", commonField.getFna_b1_f_other(), "commonField.getFna_b1_f_other()");
setValueIfPresent(form, "fill_8_21", commonField.getFna_b1_f_desc(), "commonField.getFna_b1_f_desc()");
setValueIfPresent(form, "fill_01", commonField.getFna_c2a_amount(), null);
setValueIfPresent(form, "fill_02", commonField.getFna_c2b_amount(), null);
setValueIfPresent(form, "fill_03", commonField.getFna_c2c_amount(), null);
setValueIfPresent(form, "fill_04", commonField.getFna_c2d_amount(), null);
setValueIfPresent(form, "fill_05", commonField.getFna_c2e_amount(), null);
setValueIfPresent(form, "Financial Protection", commonField.getFna_b1_a(), null);
setValueIfPresent(form, "Preparation", commonField.getFna_b1_b(), null);
setValueIfPresent(form, "Providing", commonField.getFna_b1_c(), null);;
setValueIfPresent(form, "Saving", commonField.getFna_b1_d(), null);
setValueIfPresent(form, "Investment", commonField.getFna_b1_e(), null);
setValueIfPresent(form, "Others", commonField.getFna_b1_f(), null);
setValueIfPresent(form, "fill_8_2", commonField.getFna_b1_f_other(), null);
setValueIfPresent(form, "fill_8_21", commonField.getFna_b1_f_desc(), null);
/* Page2 End */
/* Page3 Start */
setValueIfPresent(form, "toggle_91", commonField.getFna_b1_a(), "commonField.getFna_b1_a()");
setValueIfPresent(form, "fill_1_4", commonField.getFna_b1_a_amount(), "commonField.getFna_b1_a_amount()");
setValueIfPresent(form, "fill_1_4b", commonField.getFna_b1_b(), "commonField.getFna_b1_b()");
setValueIfPresent(form, "toggle_93", commonField.getFna_b1_d(), "commonField.getFna_b1_d()");
setValueIfPresent(form, "fill_1_4c", commonField.getFna_b1_d_year(), "commonField.getFna_b1_d_year()");
setValueIfPresent(form, "fill_1_4d", commonField.getFna_b1_d_year(), "commonField.getFna_b1_d_year()");
setValueIfPresent(form, "fill_1_4e", commonField.getFna_b1_d_amount(), "commonField.getFna_b1_d_amount()");
setValueIfPresent(form, "toggle_4_2", commonField.getFna_b2_a(), "commonField.getFna_b2_a()");
setValueIfPresent(form, "toggle_5", commonField.getFna_b2_b(), "commonField.getFna_b2_b()");
setValueIfPresent(form, "toggle_6", commonField.getFna_b2_c(), "commonField.getFna_b2_c()");
setValueIfPresent(form, "toggle_7", commonField.getFna_b2_d(), "commonField.getFna_b2_d()");
setValueIfPresent(form, "toggle_8", commonField.getFna_b2_e(), "commonField.getFna_b2_e()");
setValueIfPresent(form, "toggle_9", commonField.getFna_b2_f(), "commonField.getFna_b2_f()");
setValueIfPresent(form, "toggle_10", commonField.getFna_b2_g(), "commonField.getFna_b2_g()");
setValueIfPresent(form, "toggle_91", commonField.getFna_b1_a(), null);
setValueIfPresent(form, "fill_1_4", commonField.getFna_b1_a_amount(), null);
setValueIfPresent(form, "fill_1_4b", commonField.getFna_b1_b(), null);
setValueIfPresent(form, "toggle_93", commonField.getFna_b1_d(), null);
setValueIfPresent(form, "fill_1_4c", commonField.getFna_b1_d_year(), null);
setValueIfPresent(form, "fill_1_4d", commonField.getFna_b1_d_year(), null);
setValueIfPresent(form, "fill_1_4e", commonField.getFna_b1_d_amount(), null);
setValueIfPresent(form, "toggle_4_2", commonField.getFna_b2_a(), null);
setValueIfPresent(form, "toggle_5", commonField.getFna_b2_b(), null);
setValueIfPresent(form, "toggle_6", commonField.getFna_b2_c(), null);
setValueIfPresent(form, "toggle_7", commonField.getFna_b2_d(), null);
setValueIfPresent(form, "toggle_8", commonField.getFna_b2_e(), null);
setValueIfPresent(form, "toggle_9", commonField.getFna_b2_f(), null);
setValueIfPresent(form, "toggle_10", commonField.getFna_b2_g(), null);
/* Page3 End */
/* Page4 Start */
setValueIfPresent(form, "toggle_1_2", commonField.getFna_c3a_2_5(), "commonField.getFna_c3a_2_5()");
setValueIfPresent(form, "toggle_2_2", commonField.getFna_c3a_6_10(), "commonField.getFna_c3a_6_10()");
setValueIfPresent(form, "toggle_3_2", commonField.getFna_c3a_11_15(), "commonField.getFna_c3a_11_15()");
setValueIfPresent(form, "toggle_4_3", commonField.getFna_c3a_16_20(), "commonField.getFna_c3a_16_20()");
setValueIfPresent(form, "toggle_5_2", commonField.getFna_c3a_20(), "commonField.getFna_c3a_20()");
setValueIfPresent(form, "toggle_6_2", commonField.getFna_c3a_life(), "commonField.getFna_c3a_life()");
setValueIfPresent(form, "toggle_6_2_sum", commonField.getFna_c3a_2_5(), "commonField.getFna_c3a_2_5()");
setValueIfPresent(form, "toggle_1_2", commonField.getFna_c3a_2_5(), null);
setValueIfPresent(form, "toggle_2_2", commonField.getFna_c3a_6_10(), null);
setValueIfPresent(form, "toggle_3_2", commonField.getFna_c3a_11_15(), null);
setValueIfPresent(form, "toggle_4_3", commonField.getFna_c3a_16_20(), null);
setValueIfPresent(form, "toggle_5_2", commonField.getFna_c3a_20(), null);
setValueIfPresent(form, "toggle_6_2", commonField.getFna_c3a_life(), null);
setValueIfPresent(form, "toggle_6_2_sum", commonField.getFna_c3a_2_5(), null);
/* Page4 End */
/* Page5 Start */
setValueIfPresent(form, "toggle_1f", commonField.getFna_c3b_income(), "commonField.getFna_c3b_income()");
setValueIfPresent(form, "toggle_1g", commonField.getFna_c3b_saving(), "commonField.getFna_c3b_saving()");
setValueIfPresent(form, "toggle_1h", commonField.getFna_c3b_policy(), "commonField.getFna_c3b_policy()");
setValueIfPresent(form, "toggle_1i56", commonField.getFna_c3b_others(), "commonField.getFna_c3b_others()");
setValueIfPresent(form, "Text3", commonField.getFna_c3b_desc(), "commonField.getFna_c3b_desc()");
setValueIfPresent(form, "Check Box6", commonField.getFna_c1e_10(), "commonField.getFna_c1e_10()");
setValueIfPresent(form, "Check Box7", commonField.getFna_c1e_10_20(), "commonField.getFna_c1e_10_20()");
setValueIfPresent(form, "Check Box8", commonField.getFna_c1e_21_30(), "commonField.getFna_c1e_21_30()");
setValueIfPresent(form, "Check Box9", commonField.getFna_c1e_31_40(), "commonField.getFna_c1e_31_40()");
setValueIfPresent(form, "Check Box10", commonField.getFna_c1e_41_50(), "commonField.getFna_c1e_41_50()");
setValueIfPresent(form, "Check Box11", commonField.getFna_c1e_50(), "commonField.getFna_c1e_50()");
setValueIfPresent(form, "Check Box12", commonField.getFna_c2f_10(), "commonField.getFna_c2f_10()");
setValueIfPresent(form, "Check Box13", commonField.getFna_c2f_10_20(), "commonField.getFna_c2f_10_20()");
setValueIfPresent(form, "Check Box14", commonField.getFna_c2f_21_30(), "commonField.getFna_c2f_21_30()");
setValueIfPresent(form, "Check Box15", commonField.getFna_c2f_31_40(), "commonField.getFna_c2f_31_40()");
setValueIfPresent(form, "Check Box16", commonField.getFna_c2f_41_50(), "commonField.getFna_c2f_41_50()");
setValueIfPresent(form, "Check Box17", commonField.getFna_c2f_50(), "commonField.getFna_c2f_50()");
setValueIfPresent(form, "toggle_1f", commonField.getFna_c3b_income(), null);
setValueIfPresent(form, "toggle_1g", commonField.getFna_c3b_saving(), null);
setValueIfPresent(form, "toggle_1h", commonField.getFna_c3b_policy(), null);
setValueIfPresent(form, "toggle_1i56", commonField.getFna_c3b_others(), null);
setValueIfPresent(form, "Text3", commonField.getFna_c3b_desc(), null);
setValueIfPresent(form, "Check Box6", commonField.getFna_c1e_10(), null);
setValueIfPresent(form, "Check Box7", commonField.getFna_c1e_10_20(), null);
setValueIfPresent(form, "Check Box8", commonField.getFna_c1e_21_30(), null);
setValueIfPresent(form, "Check Box9", commonField.getFna_c1e_31_40(), null);
setValueIfPresent(form, "Check Box10", commonField.getFna_c1e_41_50(), null);
setValueIfPresent(form, "Check Box11", commonField.getFna_c1e_50(), null);
setValueIfPresent(form, "Check Box12", commonField.getFna_c2f_10(), null);
setValueIfPresent(form, "Check Box13", commonField.getFna_c2f_10_20(), null);
setValueIfPresent(form, "Check Box14", commonField.getFna_c2f_21_30(), null);
setValueIfPresent(form, "Check Box15", commonField.getFna_c2f_31_40(), null);
setValueIfPresent(form, "Check Box16", commonField.getFna_c2f_41_50(), null);
setValueIfPresent(form, "Check Box17", commonField.getFna_c2f_50(), null);
/* Page5 End */
}

// These fields are set unconditionally if commonField is not null
// Ensure these fields exist across all your templates or handle them conditionally
setValueIfPresent(form, "address", "123 Main St, Anytown, USA", "hardcoded address");
setValueIfPresent(form, "dateOfBirth", "01/01/1990", "hardcoded dateOfBirth");
}

//form.flattenFields(); // Flatten fields after setting all values
@@ -917,10 +898,10 @@ public class PdfService extends AbstractBaseEntityService<Pdf, Long, PdfReposito
//logger.info("closed");
}

private void setValueIfPresent(PdfAcroForm form, String fieldName, String value, String valueSource) {
private void setValueIfPresent(PdfAcroForm form, String fieldName, String value, String doOnlyIfValue) {
PdfFormField field = form.getField(fieldName);
if (field != null) {
if (value != null) {
if ((doOnlyIfValue == null || doOnlyIfValue.equals(value)) && value != null) {
try {
field.setValue(value);
// logger.info("Set field '{}' to value '{}' (from {})", fieldName, value, valueSource);


Loading…
取消
儲存