yz
2021-05-28 511a66546a655c9e5b44317ca82ae60fe5f2bf0d
febs-server/febs-server-hr/src/main/java/cc/mrbird/febs/server/hr/util/CreatePdf.java
@@ -22,6 +22,8 @@
import java.util.List;
import java.util.Map;
import static com.itextpdf.text.pdf.PdfName.BOX;
public class CreatePdf {
   Document document = new Document();// 建立一个Document对象
@@ -36,8 +38,8 @@
      try {
         // 设置中文显示
         bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
         headfont = new Font(bfChinese, 15, Font.BOLD);// 设置字体大小
         keyfont = new Font(bfChinese, 10, Font.BOLD);// 设置字体大小
         headfont = new Font(bfChinese, 15, Font.NORMAL);// 设置字体大小
         keyfont = new Font(bfChinese, 10, Font.NORMAL);// 设置字体大小
         textfont = new Font(bfChinese, 10, Font.NORMAL);// 设置字体大小
      } catch (Exception e) {
         e.printStackTrace();
@@ -78,7 +80,7 @@
      }
   }
   int maxWidth = 800;
   int maxWidth = 770;
   /**
    * 为表格添加一个内容
@@ -95,6 +97,7 @@
      PdfPCell cell = new PdfPCell();
      cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
      cell.setHorizontalAlignment(align);
      cell.setFixedHeight(20);
      cell.setPhrase(new Phrase(value, font));
      return cell;
   }
@@ -109,6 +112,13 @@
    * @return 添加的文本框
    */
   public PdfPCell createCell(String value, Font font) {
      PdfPCell cell = new PdfPCell();
      cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
      cell.setHorizontalAlignment(Element.ALIGN_CENTER);
      cell.setPhrase(new Phrase(value, font));
      return cell;
   }
   private PdfPCell createCells(String value, Font font) {
      PdfPCell cell = new PdfPCell();
      cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
      cell.setHorizontalAlignment(Element.ALIGN_CENTER);
@@ -187,6 +197,13 @@
      Font fontChinese = new Font(bfChinese, 12, Font.NORMAL);
      return fontChinese;
   }
   public static Font getPdfChineseFonts() throws Exception {
      BaseFont bfChinese = BaseFont.createFont("STSongStd-Light", "UniGB-UCS2-H",
            BaseFont.NOT_EMBEDDED);
      Font fontChinese = new Font(bfChinese, 35, Font.NORMAL);
      return fontChinese;
   }
   /**
    * 为表格添加一个内容
    *
@@ -208,7 +225,7 @@
      cell.setHorizontalAlignment(align);
      cell.setColspan(colspan);
      cell.setPhrase(new Phrase(value, font));
      cell.setPadding(3.0f);
      cell.setPadding(2.0f);
      cell.setMinimumHeight(30);
      cell.setBorderColorBottom(BaseColor.BLACK);
      cell.setBorderColorLeft(BaseColor.BLACK);
@@ -224,7 +241,7 @@
   public static void setTableStyle(PdfPTable table, PdfPCell cell) {
// 设置表格样式
      table.setLockedWidth(true);
      table.setTotalWidth(800);
      table.setTotalWidth(770);
      table.setHorizontalAlignment(Element.ALIGN_LEFT);
// 设置单元格样式
      cell.setMinimumHeight(35);
@@ -318,7 +335,8 @@
      DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
      document.addHeader("标题","标题");
      EmpBaseInfo empBaseInfo = empBaseInfoList.get(0);
      PdfPTable workheadtable = createTable(workheadlength);
      float[] ls={3.0f,3.0f,3.0f,3.0f};
      PdfPTable workheadtable = createTable(ls);
      PdfPTable empPhysicalheadtable = createTable(empPhysicalheadlength);
      PdfPTable empContractInfotable = createTable(empContractInfolength);
      PdfPTable empJobChangetable = createTable(empJobChangelength);
@@ -329,12 +347,12 @@
      PdfPTable unemploymenttable = createTable(unemploymentlength);
      PdfPTable insurancetable = createTable(insurancelength);
      PdfPTable accidentCasestable = createTable(accidentCaseslength);
      PdfPTable occupationaltable = createTable(occupationallength);
      PdfPTable occtable = createTable(occupationallength);
      PdfPTable laborTroubletable = createTable(laborTroublelength);
      PdfPTable badRecordtable = createTable(badRecordlength);
      PdfPTable remarkInfotable = createTable(remarkInfolength);
      Object[][] basicDatas = {
            {"档案号",empBaseInfo.getEmpNumb(),
            {"编号",empBaseInfo.getEmpNumb(),
                  "姓名",empBaseInfo.getEmpName(),
                  "性别",empBaseInfo.getSexName()},
            {"部门(护卫点)",empBaseInfo.getDeptName(),
@@ -345,7 +363,7 @@
                  "婚姻状态",empBaseInfo.getMarriageName()==null?"":empBaseInfo.getMarriageName()},
            {"身份证有效期",empBaseInfo.getCertificateValidity()==null?"":format1.format(empBaseInfo.getCertificateValidity()),
                  "身高(cm)",empBaseInfo.getStature()==null?"":empBaseInfo.getStature(),
                  "政治面貌",empBaseInfo.getNativePlaceName()==null?"":empBaseInfo.getNativePlaceName()},
                  "政治面貌",empBaseInfo.getPoliticsName()==null?"":empBaseInfo.getPoliticsName()},
            {"出生日期",empBaseInfo.getBirthdate()==null?"":format1.format(empBaseInfo.getBirthdate()),
                  "最高学历",empBaseInfo.getEducationName()==null?"":empBaseInfo.getEducationName(),
                  "籍贯",empBaseInfo.getNativePlaceName()==null?"":empBaseInfo.getNativePlaceName()},
@@ -367,11 +385,9 @@
            {"紧急联系电话",empBaseInfo.getUrgencyPhone()==null?"":empBaseInfo.getUrgencyPhone(),
                  "员工手册",empBaseInfo.getHandbookStatusName()==null?"":empBaseInfo.getHandbookStatusName(),
                  "相关证件",empBaseInfo.getCertificateListName()==null?"":empBaseInfo.getCertificateListName()},
            {"身份证号码",empBaseInfo.getCertificateNumb()==null?"":empBaseInfo.getCertificateNumb()}};
            {"身份证号码",empBaseInfo.getCertificateNumb()==null?"":empBaseInfo.getCertificateNumb(),
                  "员工状态",empBaseInfo.getEmpStatusName()==null?"":empBaseInfo.getEmpStatusName(),
                  "入职类型",empBaseInfo.getEntryTypeName()==null?"":empBaseInfo.getEntryTypeName()}};
      //生成三列表格
      PdfPTable table1 = new PdfPTable(1);
      PdfPCell cell1 = new PdfPCell();
@@ -380,25 +396,30 @@
      cell1.setBorderWidthBottom(0);
      cell1.setBorderWidthLeft(0);
      cell1.setUseAscender(true);
      cell1.setUseDescender(true);
      cell1.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);//水平居中
      Paragraph para = null;
      try {
         para = new Paragraph(empBaseInfo.getEmpName()+"的档案", getPdfChineseFont());
         para = new Paragraph("员工档案", getPdfChineseFonts());
      } catch (Exception e) {
         e.printStackTrace();
      }
      //设置该段落为居中显示
      cell1.setPhrase(para);
      table1.addCell(cell1);
      Image img =null;
      String image="http://120.24.23.155:8301/hr/empBaseInfo/image/"+empBaseInfo.getEmpId()+"";
      try {
         img = Image.getInstance(image);
      } catch (BadElementException e) {
         e.printStackTrace();
      } catch (IOException e) {
         e.printStackTrace();
      }
      if(img!=null){
         img.setAlignment(Element.ALIGN_LEFT);
         img.scaleAbsolute(120,125);
      }
//         每个cell的宽度
      float[] widthss = {400, 400, 400, 400,400, 400};
@@ -406,6 +427,7 @@
      PdfPTable basicTable = new PdfPTable(widthss);
      basicTable.addCell(createCell("基本信息:", keyfont, Element.ALIGN_LEFT,basicDatas.length, false));
      basicTable.addCell(createCell("档案号:"+empBaseInfo.getArchivesNumb(), keyfont, Element.ALIGN_RIGHT,basicDatas.length, false));
      // 添加备注,靠左,不显示边框
//         外层循环表格的行
      for (int i = 0; i < basicDatas.length; i++) {
@@ -453,9 +475,11 @@
      // 添加备注,靠左,不显示边框
      accidentCasestable.addCell(createCell("意外险案件:", keyfont, Element.ALIGN_LEFT, accidentCaseslength, false));
      // 添加备注,靠左,不显示边框
      occupationaltable.addCell(createCell("工伤案件:", keyfont, Element.ALIGN_LEFT, occupationallength, false));
      // 添加备注,靠左,不显示边框
      laborTroubletable.addCell(createCell("劳资案件:", keyfont, Element.ALIGN_LEFT, laborTroublelength, false));// 添加备注,靠左,不显示边框
      occtable.addCell(createCell("工伤案件:", keyfont, Element.ALIGN_LEFT, occupationallength, false));
      badRecordtable.addCell(createCell("不良记录:", keyfont, Element.ALIGN_LEFT, badRecordlength, false));
      // 添加备注,靠左,不显示边框
      remarkInfotable.addCell(createCell("备注:", keyfont, Element.ALIGN_LEFT, remarkInfolength, false));
@@ -497,11 +521,11 @@
      for (int i = 0; i < accidentCaseslength; i++) {
         accidentCasestable.addCell(createCell(accidentCases[i], keyfont, Element.ALIGN_CENTER));
      }
      for (int i = 0; i < occupationallength; i++) {
         occupationaltable.addCell(createCell(occupational[i], keyfont, Element.ALIGN_CENTER));
      }
      for (int i = 0; i < laborTroublelength; i++) {
         laborTroubletable.addCell(createCell(laborTrouble[i], keyfont, Element.ALIGN_CENTER));
      }
      for (int i = 0; i < occupationallength; i++) {
         occtable.addCell(createCell(occupational[i], keyfont, Element.ALIGN_CENTER));
      }
      for (int i = 0; i < badRecordlength; i++) {
         badRecordtable.addCell(createCell(badRecord[i], keyfont, Element.ALIGN_CENTER));
@@ -509,7 +533,7 @@
      for (int i = 0; i < remarkInfolength; i++) {
         remarkInfotable.addCell(createCell(remarkInfo[i], keyfont, Element.ALIGN_CENTER));
      }
         int re=1;
      if (null != empWorkExperiences1 && empWorkExperiences1.size() > 0) {
         int size = empWorkExperiences1.size();
         for (int i = 0; i < size; i++) {
@@ -520,6 +544,7 @@
            workheadtable.addCell(createCell(user.getJobContent()==null?"":user.getJobContent() , textfont));
         }
      }
      int re1=1;
      if (null != records && records.size() > 0) {
         int size = records.size();
         for (int i = 0; i < size; i++) {
@@ -535,6 +560,7 @@
            empPhysicalheadtable.addCell(createCell(user.getRemark()==null?"":user.getRemark(), textfont));
         }
      }
      int re2=1;
      if (null != empContractInfos && empContractInfos.size() > 0) {
         int size = empContractInfos.size();
         for (int i = 0; i < size; i++) {
@@ -544,8 +570,10 @@
            empContractInfotable.addCell(createCell(user.getContractPeriod()==null?"":String.valueOf(user.getContractPeriod()), textfont));
            empContractInfotable.addCell(createCell(user.getContractStatusName()==null?"":user.getContractStatusName(), textfont));
            empContractInfotable.addCell(createCell(user.getTransactor()==null?"":user.getTransactor() , textfont));
            empContractInfotable.addCell(createCell(user.getRemark()==null?"":user.getRemark() , textfont));
         }
      }
      int re3=1;
      if (null != empJobChangeList && empJobChangeList.size() > 0) {
         int size = empJobChangeList.size();
         for (int i = 0; i < size; i++) {
@@ -557,8 +585,11 @@
            empJobChangetable.addCell(createCell(user.get("oldJobName")==null?"":user.get("oldJobName").toString(), textfont));
            empJobChangetable.addCell(createCell(user.get("changeDate")==null?"":user.get("changeDate").toString(), textfont));
            empJobChangetable.addCell(createCell(user.get("changeType")==null?"":user.get("changeType").toString(), textfont));
            empJobChangetable.addCell(createCell(user.get("changeReason")==null?"":user.get("changeReason").toString(), textfont));
         }
      }
      int re4=1;
      if (null != records1 && records1.size() > 0) {
         int size = records1.size();
         for (int i = 0; i < size; i++) {
@@ -571,6 +602,7 @@
            dimissionLogtable.addCell(createCell(user.get("remark")==null?"":user.get("remark").toString(), textfont));
         }
      }
      int re5=1;
      if (null != empLeaveInfos && empLeaveInfos.size() > 0) {
         int size = empLeaveInfos.size();
         for (int i = 0; i < size; i++) {
@@ -584,6 +616,7 @@
            leaveInfotable.addCell(createCell(user.getRemark()==null?"":user.getRemark() , textfont));
         }
      }
      int re6=1;
      if (null != empResigns && empResigns.size() > 0) {
         int size = empResigns.size();
         for (int i = 0; i < size; i++) {
@@ -594,6 +627,7 @@
            resigntable.addCell(createCell(user.getRemark()==null?"":user.getRemark() , textfont));
         }
      }
      int re7=1;
      if (null != dimissionAttends && dimissionAttends.size() > 0) {
         int size = dimissionAttends.size();
         for (int i = 0; i < size; i++) {
@@ -608,6 +642,7 @@
            dimissionAttendtable.addCell(createCell(user.getRemark()==null?"":user.getRemark() , textfont));
         }
      }
      int re8=1;
      if (null != empUnemployments && empUnemployments.size() > 0) {
         int size = empUnemployments.size();
         for (int i = 0; i < size; i++) {
@@ -619,6 +654,7 @@
            unemploymenttable.addCell(createCell(user.getRemark()==null?"":user.getRemark() , textfont));
         }
      }
      int re9=1;
      if (null != empInsurances && empInsurances.size() > 0) {
         int size = empInsurances.size();
         for (int i = 0; i < size; i++) {
@@ -632,6 +668,7 @@
            insurancetable.addCell(createCell(user.getRemark()==null?"":user.getRemark() , textfont));
         }
      }
      int re10=1;
      if (null != empAccidentCases1 && empAccidentCases1.size() > 0) {
         int size = empAccidentCases1.size();
         for (int i = 0; i < size; i++) {
@@ -649,27 +686,10 @@
            accidentCasestable.addCell(createCell(user.getSbumitBy()==null?"":user.getSbumitBy().toString(), textfont));
            accidentCasestable.addCell(createCell(user.getExpensesFee()==null?"":user.getExpensesFee().toString(), textfont));
            accidentCasestable.addCell(createCell(user.getInnsureFee()==null?"":user.getInnsureFee().toString() , textfont));
            accidentCasestable.addCell(createCell(user.getSettleStatusName()==null?"":user.getSettleStatusName().toString() , textfont));
         }
      }
      if (null != empOccupationals && empOccupationals.size() > 0) {
         int size = empOccupationals.size();
         for (int i = 0; i < size; i++) {
            EmpOccupational user = empOccupationals.get(i);
            occupationaltable.addCell(createCell(user.getInjuredTime()==null?"":format1.format(user.getInjuredTime()), textfont));
            occupationaltable.addCell(createCell(user.getInjuredAddress()==null?"":user.getInjuredAddress().toString() , textfont));
            occupationaltable.addCell(createCell(user.getInjuredPart()==null?"":user.getInjuredPart().toString(), textfont));
            occupationaltable.addCell(createCell(user.getInjuredDescribe()==null?"":user.getInjuredDescribe().toString(), textfont));
            occupationaltable.addCell(createCell(user.getInjuredDiacrisis()==null?"":user.getInjuredDiacrisis().toString(), textfont));
            occupationaltable.addCell(createCell(user.getHospitalName()==null?"":user.getHospitalName().toString(), textfont));
            occupationaltable.addCell(createCell(user.getHospitalizatioFlagName()==null?"":user.getHospitalizatioFlagName().toString(), textfont));
            occupationaltable.addCell(createCell(user.getBedNumb()==null?"":user.getBedNumb().toString(), textfont));
            occupationaltable.addCell(createCell(user.getReportTime()==null?"":format1.format(user.getReportTime()), textfont));
            occupationaltable.addCell(createCell(user.getSubmitTime()==null?"":format1.format(user.getSubmitTime()), textfont));
            occupationaltable.addCell(createCell(user.getSbumitBy()==null?"":user.getSbumitBy().toString(), textfont));
            occupationaltable.addCell(createCell(user.getExpensesFee()==null?"":user.getExpensesFee().toString(), textfont));
            occupationaltable.addCell(createCell(user.getCompensated()==null?"":user.getCompensated().toString() , textfont));
         }
      }
      int re11=1;
      if (null != empLaborTroubles && empLaborTroubles.size() > 0) {
         int size = empLaborTroubles.size();
         for (int i = 0; i < size; i++) {
@@ -684,6 +704,29 @@
            laborTroubletable.addCell(createCell(user.getSettleDate()==null?"":format1.format(user.getSettleDate()), textfont));
         }
      }
      int re12=1;
      if (null != empOccupationals && empOccupationals.size() > 0) {
         int size = empOccupationals.size();
         for (int i = 0; i < size; i++) {
            EmpOccupational user = empOccupationals.get(i);
            occtable.addCell(createCell(user.getInjuredTime()==null?"":format1.format(user.getInjuredTime()), textfont));
            occtable.addCell(createCell(user.getInjuredAddress()==null?"":user.getInjuredAddress().toString() , textfont));
            occtable.addCell(createCell(user.getInjuredPart()==null?"":user.getInjuredPart().toString(), textfont));
            occtable.addCell(createCell(user.getInjuredDescribe()==null?"":user.getInjuredDescribe().toString(), textfont));
            occtable.addCell(createCell(user.getInjuredDiacrisis()==null?"":user.getInjuredDiacrisis().toString(), textfont));
            occtable.addCell(createCell(user.getHospitalName()==null?"":user.getHospitalName().toString(), textfont));
            occtable.addCell(createCell(user.getTreatmentName()==null?"":user.getTreatmentName().toString(), textfont));
            occtable.addCell(createCell(user.getHospitalizatioFlagName()==null?"":user.getHospitalizatioFlagName().toString(), textfont));
            occtable.addCell(createCell(user.getBedNumb()==null?"":user.getBedNumb().toString(), textfont));
            occtable.addCell(createCell(user.getReportTime()==null?"":format1.format(user.getReportTime()), textfont));
            occtable.addCell(createCell(user.getSubmitTime()==null?"":format1.format(user.getSubmitTime()), textfont));
            occtable.addCell(createCell(user.getSbumitBy()==null?"":user.getSbumitBy().toString(), textfont));
            occtable.addCell(createCell(user.getExpensesFee()==null?"":user.getExpensesFee().toString(), textfont));
            occtable.addCell(createCell(user.getCompensated()==null?"":user.getCompensated().toString() , textfont));
            occtable.addCell(createCell(user.getSettleStatusName()==null?"":user.getSettleStatusName().toString() , textfont));
         }
      }
      int re13=1;
      if (null != empBadRecords && empBadRecords.size() > 0) {
         int size = empBadRecords.size();
         for (int i = 0; i < size; i++) {
@@ -694,6 +737,7 @@
            badRecordtable.addCell(createCell(user.getRemark()==null?"":user.getRemark().toString(), textfont));
         }
      }
      int re14=1;
      if (null != empRemarkInfos && empRemarkInfos.size() > 0) {
         int size = empRemarkInfos.size();
         for (int i = 0; i < size; i++) {
@@ -704,6 +748,9 @@
      }
      try {
         document.add(table1);
         if(img!=null){
            document.add(img);
         }
         // 将表格添加到文档中
         document.add(basicTable);
         document.add(workheadtable);
@@ -717,8 +764,8 @@
         document.add(unemploymenttable);
         document.add(insurancetable);
         document.add(accidentCasestable);
         document.add(occupationaltable);
         document.add(laborTroubletable);
         document.add(occtable);
         document.add(badRecordtable);
         document.add(remarkInfotable);
      } catch (DocumentException e) {
@@ -729,6 +776,7 @@
      document.close();
   }
   /**
    * 提供外界调用的接口,生成以head为表头,list为数据的pdf
    *