|
@@ -1,23 +1,29 @@
|
|
|
package com.jpsoft.picc.modules.common.utils;
|
|
|
|
|
|
+import cn.hutool.core.convert.Convert;
|
|
|
import com.itextpdf.text.*;
|
|
|
import com.itextpdf.text.pdf.*;
|
|
|
-import com.itextpdf.text.pdf.codec.Base64;
|
|
|
import com.itextpdf.text.pdf.draw.LineSeparator;
|
|
|
+import com.jpsoft.picc.modules.business.entity.InsuranceApplication;
|
|
|
+import com.jpsoft.picc.modules.business.entity.InsurancePolicyMember;
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.io.FileOutputStream;
|
|
|
import java.io.InputStream;
|
|
|
import java.io.OutputStream;
|
|
|
-import java.util.ArrayList;
|
|
|
+import java.text.DecimalFormat;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* @author 墨鱼_mo
|
|
|
* @date 2020-2-5 18:39
|
|
|
*/
|
|
|
+
|
|
|
public class ItextPDFUtil {
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 斜角排列、全屏多个重复的花式文字水印
|
|
|
*
|
|
@@ -97,10 +103,13 @@ public class ItextPDFUtil {
|
|
|
}
|
|
|
|
|
|
|
|
|
- public static void createPdf(List list)throws Exception{
|
|
|
+ public static void createPdf(InsuranceApplication insuranceApplication, List<Map<String,Object>> mapList,List<InsurancePolicyMember> list,String logoUrl,String downloadFilePath)throws Exception{
|
|
|
//测试pdf保存路径
|
|
|
- String filePath = "C:/Users/Administrator/Desktop/test4.pdf";
|
|
|
- File file = new File(filePath);
|
|
|
+ // String filePath = "C:/Users/Administrator/Desktop/投保单.pdf";
|
|
|
+ File file = new File(downloadFilePath);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
//创建文件
|
|
@@ -116,12 +125,23 @@ public class ItextPDFUtil {
|
|
|
writer.setPageEvent(new MyHeaderFooter());
|
|
|
//打开文件
|
|
|
document.open();
|
|
|
- // 4.向文档中添加内容
|
|
|
- new ItextPDFUtil().generatePDF(document);
|
|
|
- //关闭文档
|
|
|
+ try{
|
|
|
+ // 4.向文档中添加内容
|
|
|
+ new ItextPDFUtil().generatePDF(document,insuranceApplication,mapList,list,logoUrl);
|
|
|
+ }catch (Exception ex){
|
|
|
+ throw new Exception(ex.getMessage());
|
|
|
+ }finally {
|
|
|
+ //关闭文档
|
|
|
+ document.close();
|
|
|
+ //关闭书写器
|
|
|
+ writer.close();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /* //关闭文档
|
|
|
document.close();
|
|
|
//关闭书写器
|
|
|
- writer.close();
|
|
|
+ writer.close();*/
|
|
|
|
|
|
}
|
|
|
|
|
@@ -150,8 +170,9 @@ public class ItextPDFUtil {
|
|
|
|
|
|
// 生成PDF文件
|
|
|
|
|
|
- public void generatePDF(Document document) throws Exception {
|
|
|
- Image image1 = Image.getInstance("C:/Users/Administrator/Desktop/picc/logo.png");
|
|
|
+ public void generatePDF(Document document,InsuranceApplication insuranceApplication, List<Map<String,Object>> mapList,List<InsurancePolicyMember> list,String logoUrl) throws Exception {
|
|
|
+ // Image image1 = Image.getInstance("C:/Users/Administrator/Desktop/picc/logo.png");
|
|
|
+ Image image1 = Image.getInstance(logoUrl);
|
|
|
Paragraph p1 = new Paragraph("00000000000001", titlefont);
|
|
|
//设置文字居中 0靠左 1,居中 2,靠右
|
|
|
p1.setAlignment(2);
|
|
@@ -183,41 +204,77 @@ public class ItextPDFUtil {
|
|
|
PdfPTable table = PdfTable.createTable(new float[]{20, 65, 60, 70, 60, 65,120});
|
|
|
table.addCell(PdfTable.createCell("一、投保人、被保险人信息", textfont, Element.ALIGN_LEFT, 7,1,BaseColor.PINK, true));
|
|
|
table.addCell(PdfTable.createCell("投保人名称", textfont, Element.ALIGN_CENTER,2,1,BaseColor.WHITE,false));
|
|
|
- table.addCell(PdfTable.createCell("", textfont, Element.ALIGN_CENTER,3,1,BaseColor.WHITE,false));
|
|
|
+ table.addCell(PdfTable.createCell(insuranceApplication.getInsuredName(), textfont, Element.ALIGN_CENTER,3,1,BaseColor.WHITE,false));
|
|
|
table.addCell(PdfTable.createCell("联系电话", textfont, Element.ALIGN_CENTER,1,1,BaseColor.WHITE,false));
|
|
|
- table.addCell(PdfTable.createCell("", textfont, Element.ALIGN_CENTER,1,1,BaseColor.WHITE,false));
|
|
|
+ table.addCell(PdfTable.createCell(insuranceApplication.getInsuredTel(), textfont, Element.ALIGN_CENTER,1,1,BaseColor.WHITE,false));
|
|
|
|
|
|
table.addCell(PdfTable.createCell("被保险人信息", textfont, Element.ALIGN_CENTER,1,5,BaseColor.WHITE,false));
|
|
|
|
|
|
table.addCell(PdfTable.createCell("名 称", textfont, Element.ALIGN_CENTER,1,1,BaseColor.WHITE,false));
|
|
|
- table.addCell(PdfTable.createCell("", textfont, Element.ALIGN_CENTER,3,1,BaseColor.WHITE,false));
|
|
|
+ table.addCell(PdfTable.createCell(insuranceApplication.getInsuredName(), textfont, Element.ALIGN_CENTER,3,1,BaseColor.WHITE,false));
|
|
|
table.addCell(PdfTable.createCell("营业性质", textfont, Element.ALIGN_CENTER,1,1,BaseColor.WHITE,false));
|
|
|
- table.addCell(PdfTable.createCell("", textfont, Element.ALIGN_CENTER,1,1,BaseColor.WHITE,false));
|
|
|
+ table.addCell(PdfTable.createCell(insuranceApplication.getBusinessNature(), textfont, Element.ALIGN_CENTER,1,1,BaseColor.WHITE,false));
|
|
|
|
|
|
table.addCell(PdfTable.createCell("证件类型", textfont, Element.ALIGN_CENTER,1,1,BaseColor.WHITE,false));
|
|
|
- table.addCell(PdfTable.createCell("□组织机构代码证\n" +"□税务登记证\n" +"□工商登记证\n"+"□营业执照", textfont, Element.ALIGN_LEFT,3,1,BaseColor.WHITE,false));
|
|
|
+ table.addCell(PdfTable.createCell("√组织机构代码证\n" +"□税务登记证\n" +"□工商登记证\n"+"□营业执照", textfont, Element.ALIGN_LEFT,3,1,BaseColor.WHITE,false));
|
|
|
table.addCell(PdfTable.createCell("证件号码", textfont, Element.ALIGN_CENTER,1,1,BaseColor.WHITE,false));
|
|
|
- table.addCell(PdfTable.createCell("", textfont, Element.ALIGN_CENTER,1,1,BaseColor.WHITE,false));
|
|
|
+ table.addCell(PdfTable.createCell(insuranceApplication.getUsccCode(), textfont, Element.ALIGN_CENTER,1,1,BaseColor.WHITE,false));
|
|
|
|
|
|
table.addCell(PdfTable.createCell("营业范围", textfont, Element.ALIGN_CENTER,1,1,BaseColor.WHITE,false));
|
|
|
- table.addCell(PdfTable.createCell("", textfont, Element.ALIGN_CENTER,3,1,BaseColor.WHITE,false));
|
|
|
+ table.addCell(PdfTable.createCell(insuranceApplication.getBusinessScope(), textfont, Element.ALIGN_CENTER,3,1,BaseColor.WHITE,false));
|
|
|
table.addCell(PdfTable.createCell("行业类别", textfont, Element.ALIGN_CENTER,1,1,BaseColor.WHITE,false));
|
|
|
- table.addCell(PdfTable.createCell("", textfont, Element.ALIGN_CENTER,1,1,BaseColor.WHITE,false));
|
|
|
+ table.addCell(PdfTable.createCell(insuranceApplication.getIndustryType(), textfont, Element.ALIGN_CENTER,1,1,BaseColor.WHITE,false));
|
|
|
|
|
|
table.addCell(PdfTable.createCell("雇员人数", textfont, Element.ALIGN_CENTER,1,1,BaseColor.WHITE,false));
|
|
|
- table.addCell(PdfTable.createCell("", textfont, Element.ALIGN_CENTER,1,1,BaseColor.WHITE,false));
|
|
|
+ table.addCell(PdfTable.createCell(String.valueOf(insuranceApplication.getEmployeesNumber()), textfont, Element.ALIGN_CENTER,1,1,BaseColor.WHITE,false));
|
|
|
table.addCell(PdfTable.createCell("投保人数", textfont, Element.ALIGN_CENTER,1,1,BaseColor.WHITE,false));
|
|
|
- table.addCell(PdfTable.createCell("", textfont, Element.ALIGN_CENTER,1,1,BaseColor.WHITE,false));
|
|
|
+ table.addCell(PdfTable.createCell(String.valueOf(list.size()), textfont, Element.ALIGN_CENTER,1,1,BaseColor.WHITE,false));
|
|
|
table.addCell(PdfTable.createCell("联系电话", textfont, Element.ALIGN_CENTER,1,1,BaseColor.WHITE,false));
|
|
|
- table.addCell(PdfTable.createCell("", textfont, Element.ALIGN_CENTER,1,1,BaseColor.WHITE,false));
|
|
|
+ table.addCell(PdfTable.createCell(insuranceApplication.getInsuredTel(), textfont, Element.ALIGN_CENTER,1,1,BaseColor.WHITE,false));
|
|
|
|
|
|
table.addCell(PdfTable.createCell("联系地址", textfont, Element.ALIGN_CENTER,1,1,BaseColor.WHITE,false));
|
|
|
- table.addCell(PdfTable.createCell("", textfont, Element.ALIGN_CENTER,3,1,BaseColor.WHITE,false));
|
|
|
+ table.addCell(PdfTable.createCell(insuranceApplication.getCompanyAddress(), textfont, Element.ALIGN_CENTER,3,1,BaseColor.WHITE,false));
|
|
|
table.addCell(PdfTable.createCell("邮 编", textfont, Element.ALIGN_CENTER,1,1,BaseColor.WHITE,false));
|
|
|
- table.addCell(PdfTable.createCell("", textfont, Element.ALIGN_CENTER,1,1,BaseColor.WHITE,false));
|
|
|
+ table.addCell(PdfTable.createCell(insuranceApplication.getPostal(), textfont, Element.ALIGN_CENTER,1,1,BaseColor.WHITE,false));
|
|
|
|
|
|
table.addCell(PdfTable.createCell("近三年损失情况(时间、原因、损失金额)", textfont, Element.ALIGN_CENTER,2,1,BaseColor.WHITE,false));
|
|
|
- table.addCell(PdfTable.createCell("", textfont, Element.ALIGN_CENTER,5,1,BaseColor.WHITE,false));
|
|
|
+ table.addCell(PdfTable.createCell(insuranceApplication.getLossInRecentYears(), textfont, Element.ALIGN_CENTER,5,1,BaseColor.WHITE,false));
|
|
|
+
|
|
|
+
|
|
|
+ // List<Map<String,Object>> mapList = (List<Map<String, Object>>) map.get("insuranceDefinitionLimitList");
|
|
|
+ //累计责任限额
|
|
|
+ String cumulativeValue = "";
|
|
|
+ //每次事故
|
|
|
+ String accidentValue = "";
|
|
|
+ //每人伤亡
|
|
|
+ String casualtiesValue = "";
|
|
|
+ //每人医疗
|
|
|
+ String medicalCareValue = "";
|
|
|
+ //法律费用
|
|
|
+ String lawValue = "";
|
|
|
+
|
|
|
+
|
|
|
+ for (Map<String,Object> mapData : mapList){
|
|
|
+ if ("累计责任限额".equals(mapData.get("name"))){
|
|
|
+ cumulativeValue = (String)mapData.get("limit")+(String)mapData.get("unit");
|
|
|
+ }
|
|
|
+ if ("每次事故责任限额".equals(mapData.get("name"))){
|
|
|
+ accidentValue = (String)mapData.get("limit")+(String)mapData.get("unit");
|
|
|
+ }
|
|
|
+ if ("伤亡责任限额".equals(mapData.get("name"))){
|
|
|
+ casualtiesValue = (String)mapData.get("limit")+(String)mapData.get("unit");
|
|
|
+ }
|
|
|
+ if ("医疗费用限额".equals(mapData.get("name"))){
|
|
|
+ medicalCareValue = (String)mapData.get("limit")+(String)mapData.get("unit");
|
|
|
+ }
|
|
|
+ if ("累计法律诉讼费用限额".equals(mapData.get("name"))){
|
|
|
+ lawValue = (String)mapData.get("limit")+(String)mapData.get("unit");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
table.addCell(PdfTable.createCell("二、承保信息", textfont, Element.ALIGN_LEFT, 7,1,BaseColor.PINK, true));
|
|
|
|
|
@@ -228,21 +285,21 @@ public class ItextPDFUtil {
|
|
|
table.addCell(PdfTable.createCell("保险费(元)", textfont, Element.ALIGN_CENTER,1,1,BaseColor.WHITE,false));
|
|
|
|
|
|
table.addCell(PdfTable.createCell("累计责任限额", textfont, Element.ALIGN_CENTER,3,1,BaseColor.WHITE,false));
|
|
|
- table.addCell(PdfTable.createCell("", textfont, Element.ALIGN_CENTER,1,1,BaseColor.WHITE,false));
|
|
|
- table.addCell(PdfTable.createCell("", textfont, Element.ALIGN_CENTER,1,6,BaseColor.WHITE,false));
|
|
|
+ table.addCell(PdfTable.createCell(cumulativeValue, textfont, Element.ALIGN_CENTER,1,1,BaseColor.WHITE,false));
|
|
|
+ table.addCell(PdfTable.createCell(String.valueOf(insuranceApplication.getInsuranceFee()), textfont, Element.ALIGN_CENTER,1,6,BaseColor.WHITE,false));
|
|
|
|
|
|
table.addCell(PdfTable.createCell("每次事故责任限额", textfont, Element.ALIGN_CENTER,1,4,BaseColor.WHITE,false));
|
|
|
table.addCell(PdfTable.createCell("每次事故责任限额", textfont, Element.ALIGN_CENTER,2,1,BaseColor.WHITE,false));
|
|
|
- table.addCell(PdfTable.createCell("", textfont, Element.ALIGN_CENTER,1,1,BaseColor.WHITE,false));
|
|
|
+ table.addCell(PdfTable.createCell(accidentValue, textfont, Element.ALIGN_CENTER,1,1,BaseColor.WHITE,false));
|
|
|
|
|
|
table.addCell(PdfTable.createCell("每人伤亡责任限额", textfont, Element.ALIGN_CENTER,2,1,BaseColor.WHITE,false));
|
|
|
- table.addCell(PdfTable.createCell("", textfont, Element.ALIGN_CENTER,1,1,BaseColor.WHITE,false));
|
|
|
+ table.addCell(PdfTable.createCell(casualtiesValue, textfont, Element.ALIGN_CENTER,1,1,BaseColor.WHITE,false));
|
|
|
|
|
|
table.addCell(PdfTable.createCell("每人医疗费用责任限额", textfont, Element.ALIGN_CENTER,2,1,BaseColor.WHITE,false));
|
|
|
- table.addCell(PdfTable.createCell("", textfont, Element.ALIGN_CENTER,1,1,BaseColor.WHITE,false));
|
|
|
+ table.addCell(PdfTable.createCell(medicalCareValue, textfont, Element.ALIGN_CENTER,1,1,BaseColor.WHITE,false));
|
|
|
|
|
|
table.addCell(PdfTable.createCell("法律费用责任限额", textfont, Element.ALIGN_CENTER,2,1,BaseColor.WHITE,false));
|
|
|
- table.addCell(PdfTable.createCell("", textfont, Element.ALIGN_CENTER,1,1,BaseColor.WHITE,false));
|
|
|
+ table.addCell(PdfTable.createCell(lawValue, textfont, Element.ALIGN_CENTER,1,1,BaseColor.WHITE,false));
|
|
|
|
|
|
table.addCell(PdfTable.createCell("每次事故每人医疗费用免赔额", textfont, Element.ALIGN_CENTER,3,1,BaseColor.WHITE,false));
|
|
|
table.addCell(PdfTable.createCell("", textfont, Element.ALIGN_CENTER,1,1,BaseColor.WHITE,false));
|
|
@@ -261,10 +318,12 @@ public class ItextPDFUtil {
|
|
|
table.addCell(PdfTable.createCell("", textfont, Element.ALIGN_CENTER,1,1,BaseColor.WHITE,false));
|
|
|
|
|
|
table.addCell(PdfTable.createCell("保险费合计(人民币)", textfont, Element.ALIGN_CENTER,2,1,BaseColor.WHITE,false));
|
|
|
- table.addCell(PdfTable.createCell("(大写):\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000(小写):¥ ", textfont, Element.ALIGN_LEFT,5,1,BaseColor.WHITE,false));
|
|
|
+ table.addCell(PdfTable.createCell("(大写):"+ Convert.digitToChinese(insuranceApplication.getInsuranceFee())+"\u3000\u3000\u3000\u3000(小写):¥ "+new DecimalFormat("#,##0.00").format(insuranceApplication.getInsuranceFee()).toString(), textfont, Element.ALIGN_LEFT,5,1,BaseColor.WHITE,false));
|
|
|
+
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日");
|
|
|
|
|
|
table.addCell(PdfTable.createCell("保险期间", textfont, Element.ALIGN_CENTER,2,1,BaseColor.WHITE,false));
|
|
|
- table.addCell(PdfTable.createCell("自\u3000\u3000\u3000年\u3000月\u3000日零时起至\u3000\u3000\u3000年\u3000月\u3000日二十四时止。", textfont, Element.ALIGN_CENTER,5,1,BaseColor.WHITE,false));
|
|
|
+ table.addCell(PdfTable.createCell("自"+simpleDateFormat.format(insuranceApplication.getStartTime())+"零时起至"+simpleDateFormat.format(insuranceApplication.getEndTime())+"二十四时止。", textfont, Element.ALIGN_CENTER,5,1,BaseColor.WHITE,false));
|
|
|
|
|
|
table.addCell(PdfTable.createCell("保险合同争议处理", textfont, Element.ALIGN_CENTER,2,1,BaseColor.WHITE,false));
|
|
|
table.addCell(PdfTable.createCell("□提交______________仲裁委员会仲裁 □诉讼", textfont, Element.ALIGN_LEFT,5,1,BaseColor.WHITE,false));
|
|
@@ -347,16 +406,16 @@ public class ItextPDFUtil {
|
|
|
table4.addCell(PdfTable.createCell("岗位/工种", textfont, Element.ALIGN_CENTER, 1,1,BaseColor.WHITE, true));
|
|
|
table4.addCell(PdfTable.createCell("健康情况", textfont, Element.ALIGN_CENTER, 1,1,BaseColor.WHITE, true));
|
|
|
|
|
|
- List list = new ArrayList();
|
|
|
+ // List<InsurancePolicyMember> list = new ArrayList();
|
|
|
for (int i =0;i<list.size();i++){
|
|
|
- table4.addCell(PdfTable.createCell(list.get(i).toString(), textfont, Element.ALIGN_CENTER, 1,1,BaseColor.WHITE, true));
|
|
|
- table4.addCell(PdfTable.createCell(list.get(i).toString(), textfont, Element.ALIGN_CENTER, 1,1,BaseColor.WHITE, true));
|
|
|
- table4.addCell(PdfTable.createCell(list.get(i).toString(), textfont, Element.ALIGN_CENTER, 1,1,BaseColor.WHITE, true));
|
|
|
- table4.addCell(PdfTable.createCell(list.get(i).toString(), textfont, Element.ALIGN_CENTER, 1,1,BaseColor.WHITE, true));
|
|
|
- table4.addCell(PdfTable.createCell(list.get(i).toString(), textfont, Element.ALIGN_CENTER, 1,1,BaseColor.WHITE, true));
|
|
|
- table4.addCell(PdfTable.createCell(list.get(i).toString(), textfont, Element.ALIGN_CENTER, 1,1,BaseColor.WHITE, true));
|
|
|
- table4.addCell(PdfTable.createCell(list.get(i).toString(), textfont, Element.ALIGN_CENTER, 1,1,BaseColor.WHITE, true));
|
|
|
- table4.addCell(PdfTable.createCell(list.get(i).toString(), textfont, Element.ALIGN_CENTER, 1,1,BaseColor.WHITE, true));
|
|
|
+ table4.addCell(PdfTable.createCell(String.valueOf(i+1), textfont, Element.ALIGN_CENTER, 1,1,BaseColor.WHITE, true));
|
|
|
+ table4.addCell(PdfTable.createCell(list.get(i).getCompanyMember().getName(), textfont, Element.ALIGN_CENTER, 1,1,BaseColor.WHITE, true));
|
|
|
+ table4.addCell(PdfTable.createCell(list.get(i).getCompanyMember().getCardType(), textfont, Element.ALIGN_CENTER, 1,1,BaseColor.WHITE, true));
|
|
|
+ table4.addCell(PdfTable.createCell(list.get(i).getCompanyMember().getCardNo(), textfont, Element.ALIGN_CENTER, 1,1,BaseColor.WHITE, true));
|
|
|
+ table4.addCell(PdfTable.createCell(list.get(i).getCompanyMember().getSex()==true?"男":"女", textfont, Element.ALIGN_CENTER, 1,1,BaseColor.WHITE, true));
|
|
|
+ table4.addCell(PdfTable.createCell(String.valueOf(list.get(i).getCompanyMember().getAge()), textfont, Element.ALIGN_CENTER, 1,1,BaseColor.WHITE, true));
|
|
|
+ table4.addCell(PdfTable.createCell(list.get(i).getCompanyMember().getJobName(), textfont, Element.ALIGN_CENTER, 1,1,BaseColor.WHITE, true));
|
|
|
+ table4.addCell(PdfTable.createCell(list.get(i).getCompanyMember().getHealthStatus(), textfont, Element.ALIGN_CENTER, 1,1,BaseColor.WHITE, true));
|
|
|
}
|
|
|
|
|
|
|