Commit 69def107 authored by 盖献康's avatar 盖献康

PDF - 检验报告 - 除数据基本完成

parent aabd85e5
......@@ -131,7 +131,7 @@ public class InspectionReportPdfVO {
private String taskNumber;
/**
*
* 样品数量
*/
private String sampleSum;
......@@ -140,6 +140,11 @@ public class InspectionReportPdfVO {
*/
private String vehicleType;
/**
* 车辆型号
*/
private String vehicleModel;
/**
* 车辆识别码
*/
......
......@@ -5,7 +5,7 @@ import com.itextpdf.text.pdf.*;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.PdfBaseWriter;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.domain.vo.PhotoStorageVO;
import com.ruoyi.domain.vo.InspectionReportPdfVO;
import com.ruoyi.domain.vo.ReviewEnterpriseArchiveViewVO;
import com.ruoyi.service.PdfTemplateManagementService;
import com.ruoyi.service.ReviewEnterpriseArchiveService;
......@@ -76,23 +76,15 @@ public class PdfTemplateManagementServiceImpl implements PdfTemplateManagementSe
BaseFont bf = BaseFont.createFont("STSongStd-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
fields.addSubstitutionFont(bf);
// 渲染
// fillData(fields, map, ps);
renderData(fields);
// 测试数据
InspectionReportPdfVO inspectionReportPdfVO = requireData();
PhotoStorageVO photoStorageVO = new PhotoStorageVO();
Class<? extends PhotoStorageVO> aClass = photoStorageVO.getClass();
Field[] declaredFields = aClass.getDeclaredFields();
for (Field field : declaredFields) {
String name = field.getName();
System.out.println(name);
}
// 渲染数据
renderData(fields, inspectionReportPdfVO);
//必须要调用这个,否则文档不会生成的
ps.setFormFlattening(true);
if(ps != null){
ps.close();
}
ps.close();
//生成pdf路径存放的路径
fos = response.getOutputStream();
fos.write(bos.toByteArray());
......@@ -113,6 +105,40 @@ public class PdfTemplateManagementServiceImpl implements PdfTemplateManagementSe
}
}
private InspectionReportPdfVO requireData() {
InspectionReportPdfVO inspectionReportPdfVO = InspectionReportPdfVO.builder()
.reportNumber("报告编号")
.productName("产品名称")
.productModel("产品型号")
.entrustedUnit("委托单位")
.inspectionCenterName("检验中心名称")
.inspectionCenterAddress("检验中心地址")
.inspectionCenterTelephone("检验中心电话")
.inspectionCenterPostcode("检验中心邮编")
.clientAddress("委托单位地址")
.entrustedUnitTelephone("委托单位电话")
.clientPostalCode("委托单位邮编")
.sampleName("样品名称")
.typeSpecification("型号规格")
.productionEnterprise("生产企业")
.sampleSender("送养着")
.sampleDeliveryDate("送样日期")
.sampleQuantity("样品数量")
.productionDate("生产日期")
.inspectionItem("检验项目")
.testConclusion("检验结论")
.issueDate("签发日期")
.remark("备注")
.taskNumber("任务编号")
.sampleSum("样品数量")
.vehicleType("车俩类型")
.vehicleModel("车辆型号")
.vehicleIdentificationNumber("车辆识别码")
.sampleNumberSummary("样品编号汇总")
.build();
return inspectionReportPdfVO;
}
/**
* 企业留档文件PDF下载
* @param taskId
......@@ -213,8 +239,20 @@ public class PdfTemplateManagementServiceImpl implements PdfTemplateManagementSe
* 渲染数据
* @param fields
*/
private void renderData(AcroFields fields) {
private void renderData(AcroFields fields, InspectionReportPdfVO inspectionReportPdfVO) throws Exception {
// 取出当前对象所有属性,并赋值到模板里
Class<? extends InspectionReportPdfVO> aClass = inspectionReportPdfVO.getClass();
Field[] declaredFields = aClass.getDeclaredFields();
for (Field field : declaredFields) {
String name = field.getName();
String key = name.replaceAll("([a-z])([A-Z])", "$1_$2").toLowerCase();
field.setAccessible(true);
Object o = field.get(inspectionReportPdfVO);
if (o != null) {
String value = o.toString();
fields.setField(key, value);
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment