| | |
| | | import com.doumee.core.constants.ResponseStatus; |
| | | import com.doumee.core.exception.BusinessException; |
| | | import com.doumee.core.utils.Constants; |
| | | import com.doumee.dao.business.model.ApplyChagneDetail; |
| | | import com.doumee.dao.business.model.ApplyChange; |
| | | import com.doumee.dao.business.model.ApplyDetail; |
| | | import com.doumee.dao.business.model.InsuranceApply; |
| | | import com.doumee.dao.business.model.*; |
| | | import com.github.xiaoymin.knife4j.core.util.CollectionUtils; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.Data; |
| | | import org.apache.commons.lang3.StringUtils; |
| | |
| | | import java.nio.charset.Charset; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * Excel导出实现 |
| | |
| | | private Field field; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 导出 合并单 换厂 申请详单 |
| | | * @param data 数据 |
| | | * @param sheetName Sheet名称 |
| | | */ |
| | | public String exportUnionChangeOtherUnitExcelToPdf (UnionChange data, String sheetName) { |
| | | SXSSFWorkbook sxssfWorkbook; |
| | | try { |
| | | sxssfWorkbook = new SXSSFWorkbook(); |
| | | Sheet sheet = sxssfWorkbook.createSheet(sheetName); |
| | | for (int i = 0; i < 8; i++) { |
| | | sheet.setColumnWidth(i, ((i==3|| i== 4|| i== 5 ||i== 6 || i==7)?16:8) * 2 * 256); |
| | | } |
| | | sheet.createFreezePane(0, 1); |
| | | sheet.addMergedRegion(new CellRangeAddress(0 ,0,0,7)); |
| | | Row title = sheet.createRow(0); |
| | | title.setHeight((short) 2000); |
| | | Cell c = title.createCell(0); |
| | | c.setCellValue(sheetName); |
| | | configFirstCell(sxssfWorkbook,c); |
| | | for (int i = 0; i < 8; i++) { |
| | | if(i>0){ |
| | | title.createCell(i).setCellValue(""); |
| | | } |
| | | configTitleCell(sxssfWorkbook,title.getCell(i)); |
| | | } |
| | | Row header1 = sheet.createRow(1); |
| | | header1.createCell(0).setCellValue("投保人"); |
| | | header1.createCell(1).setCellValue("保险方案"); |
| | | header1.createCell(2).setCellValue(""); |
| | | header1.createCell(3).setCellValue(""); |
| | | header1.createCell(4).setCellValue("保单号"); |
| | | header1.createCell(5).setCellValue("保险生效起期"); |
| | | header1.createCell(6).setCellValue("保险生效止期"); |
| | | header1.createCell(7).setCellValue("换厂人数"); |
| | | header1.createCell(8).setCellValue("期望批单生效期"); |
| | | for (int i = 0; i < 9; i++) { |
| | | configFirstCell(sxssfWorkbook,header1.getCell(i)); |
| | | } |
| | | sheet.addMergedRegion(new CellRangeAddress(1 ,1,1,3)); |
| | | |
| | | Row header2 = sheet.createRow(2); |
| | | header2.createCell(0).setCellValue(data.getShopName()); |
| | | header2.createCell(1).setCellValue(data.getSolutionsName()); |
| | | header2.createCell(2).setCellValue(""); |
| | | header2.createCell(3).setCellValue(""); |
| | | header2.createCell(4).setCellValue(data.getApplyCode()); |
| | | header2.createCell(5).setCellValue(com.doumee.core.utils.DateUtil.getPlusTime2(data.getStartTime())); |
| | | header2.createCell(6).setCellValue(com.doumee.core.utils.DateUtil.getPlusTime2(data.getEndTime())); |
| | | header2.createCell(7).setCellValue(data.getApplyChagneDetailList().stream().filter(i->i.getType().equals(Constants.TWO)).collect(Collectors.toList()).size()); |
| | | header2.createCell(8).setCellValue(com.doumee.core.utils.DateUtil.getPlusTime2(data.getApplyStartTime())); |
| | | sheet.addMergedRegion(new CellRangeAddress(2 ,2,1,3)); |
| | | for (int i = 0; i < 9; i++) { |
| | | configDataCell(sxssfWorkbook,header2.getCell(i)); |
| | | } |
| | | |
| | | |
| | | Row header3 = sheet.createRow(3); |
| | | header3.createCell(0).setCellValue("被保险人"); |
| | | header3.createCell(1).setCellValue(data.getCompanyNames()); |
| | | header3.createCell(2).setCellValue(""); |
| | | header3.createCell(3).setCellValue(""); |
| | | header3.createCell(4).setCellValue(""); |
| | | header3.createCell(5).setCellValue(""); |
| | | header3.createCell(6).setCellValue(""); |
| | | header3.createCell(7).setCellValue(""); |
| | | header3.createCell(8).setCellValue(""); |
| | | for (int i = 0; i < 9; i++) { |
| | | configFirstCell(sxssfWorkbook,header3.getCell(i)); |
| | | } |
| | | sheet.addMergedRegion(new CellRangeAddress(3 ,3,1,8)); |
| | | |
| | | |
| | | Row header4 = sheet.createRow(4); |
| | | header4.createCell(0).setCellValue("序号"); |
| | | header4.createCell(1).setCellValue("员工姓名"); |
| | | header4.createCell(2).setCellValue("性别"); |
| | | header4.createCell(3).setCellValue("身份证号"); |
| | | header4.createCell(4).setCellValue("被保险人"); |
| | | header4.createCell(5).setCellValue("原派遣单位"); |
| | | header4.createCell(6).setCellValue("原所所属工种"); |
| | | header4.createCell(7).setCellValue("更改后派遣单位"); |
| | | header4.createCell(8).setCellValue("更改后所属工种"); |
| | | for (int i = 0; i < 9; i++) { |
| | | configFirstCell(sxssfWorkbook,header4.getCell(i)); |
| | | } |
| | | |
| | | List<ApplyChagneDetail> otherChangeDetailList = data.getApplyChagneDetailList().stream().filter(i->i.getType().equals(Constants.TWO)).collect(Collectors.toList()); |
| | | |
| | | Integer row = 4; |
| | | |
| | | if(CollectionUtils.isNotEmpty(otherChangeDetailList)){ |
| | | row = row + 1; |
| | | Row header5 = sheet.createRow(row); |
| | | header5.createCell(0).setCellValue("序号"); |
| | | header5.createCell(1).setCellValue("员工姓名"); |
| | | header5.createCell(2).setCellValue("性别"); |
| | | header5.createCell(3).setCellValue("身份证号"); |
| | | header5.createCell(4).setCellValue("被保险人"); |
| | | header5.createCell(5).setCellValue("原派遣单位"); |
| | | header5.createCell(6).setCellValue("原所属工种"); |
| | | header5.createCell(7).setCellValue("更改后派遣单位"); |
| | | header5.createCell(8).setCellValue("更改后所属工种"); |
| | | for (int i = 0; i < 9; i++) { |
| | | configFirstCell(sxssfWorkbook,header5.getCell(i)); |
| | | } |
| | | for (int rowIndex = 0; rowIndex < otherChangeDetailList.size(); rowIndex++) { |
| | | row = row + 1; |
| | | Row header6 = sheet.createRow(row); |
| | | ApplyChagneDetail applyChagneDetail = otherChangeDetailList.get(rowIndex); |
| | | header6.createCell(0).setCellValue(rowIndex + 1); |
| | | header6.createCell(1).setCellValue(applyChagneDetail.getMemberName()); |
| | | header6.createCell(2).setCellValue(Constants.equalsInteger(applyChagneDetail.getSex(),0)?"男":(Constants.equalsInteger(applyChagneDetail.getSex(),1)?"女":"-")); |
| | | header6.createCell(3).setCellValue(applyChagneDetail.getIdcardNo()); |
| | | header6.createCell(4).setCellValue(applyChagneDetail.getCompanyName()); |
| | | header6.createCell(5).setCellValue(applyChagneDetail.getOldDuName()); |
| | | header6.createCell(6).setCellValue(applyChagneDetail.getOldWorkTypeName()); |
| | | header6.createCell(7).setCellValue(applyChagneDetail.getDuName()); |
| | | header6.createCell(8).setCellValue(applyChagneDetail.getWorkTypeName()); |
| | | for (int i = 0; i < 9; i++) { |
| | | configFirstCell(sxssfWorkbook,header6.getCell(i)); |
| | | } |
| | | } |
| | | } |
| | | int rowIndex = row + 1 ; |
| | | Row header6= sheet.createRow(rowIndex); |
| | | header6.createCell(0).setCellValue("投保企业申明:\n" + |
| | | "1、在申请书上填写的一切内容属实,否则本企业承担一切法律责任。\n" + |
| | | "2、由于变更受益人产生的法律纠纷本企业愿承担一切法律责任。\n" + |
| | | "3、本申请表的签章为本企业亲自签署,如由此产生的法律纠纷本企业愿承担一切法律责任。\n"); |
| | | for (int i = 1; i < 9; i++) { |
| | | header6.createCell(i).setCellValue(""); |
| | | } |
| | | for (int i =0; i < 9; i++) { |
| | | if(i>0){ |
| | | header6.createCell(i).setCellValue(""); |
| | | } |
| | | configInfoCell(sxssfWorkbook,header6.getCell(i),HorizontalAlignment.LEFT); |
| | | } |
| | | header6.setHeight((short) 2000); |
| | | sheet.addMergedRegion(new CellRangeAddress(rowIndex ,rowIndex,0,8)); |
| | | Row header7= sheet.createRow(rowIndex+1); |
| | | header7.setHeight((short) 3000); |
| | | header7.createCell(0).setCellValue("投保人签章 : \n \n \n" +"日期: 年 月 日 "); |
| | | for (int i =0; i < 9; i++) { |
| | | if(i>0){ |
| | | header7.createCell(i).setCellValue(""); |
| | | } |
| | | configInfoCell(sxssfWorkbook,header7.getCell(i),HorizontalAlignment.RIGHT); |
| | | } |
| | | sheet.addMergedRegion(new CellRangeAddress(rowIndex+1 ,rowIndex+1,0,8)); |
| | | |
| | | //临时缓冲区 |
| | | ByteArrayOutputStream out = new ByteArrayOutputStream(); |
| | | //创建临时文件 |
| | | sxssfWorkbook.write(out); |
| | | byte [] bookByteAry = out.toByteArray(); |
| | | InputStream in = new ByteArrayInputStream(bookByteAry); |
| | | String tempExcel = saveIsToFile(in); |
| | | String tempPdf =System.getProperty("java.io.tmpdir")+File.separator+UUID.randomUUID().toString()+".pdf"; |
| | | // ExcelToPdfTool.excelToPdf(in,tempPdf);//转PDF |
| | | ExcelToPdfTool.excelToPdf(tempExcel,tempPdf);//转PDF |
| | | File f = new File(tempPdf); |
| | | if(f!=null && f.isFile() && f.length()>0){ |
| | | return tempPdf; |
| | | } |
| | | } catch (Exception e) { |
| | | // throw new BusinessException(ResponseStatus.EXPORT_EXCEL_ERROR, e); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 导出 合并单加减保申请详单 |
| | | * @param data 数据 |
| | | * @param sheetName Sheet名称 |
| | | */ |
| | | public String exportUnionChangeExcelToPdf (UnionChange data, String sheetName) { |
| | | SXSSFWorkbook sxssfWorkbook; |
| | | try { |
| | | sxssfWorkbook = new SXSSFWorkbook(); |
| | | Sheet sheet = sxssfWorkbook.createSheet(sheetName); |
| | | for (int i = 0; i < 12; i++) { |
| | | sheet.setColumnWidth(i, ((i==3|| i==4|| i== 5 || i==9||i==10|| i==11)?16:8) * 2 * 256); |
| | | } |
| | | sheet.createFreezePane(0, 1); |
| | | sheet.addMergedRegion(new CellRangeAddress(0 ,0,0,11)); |
| | | Row title = sheet.createRow(0); |
| | | title.setHeight((short) 2000); |
| | | for (int i = 0; i < 12; i++) { |
| | | title.createCell(i).setCellValue(i==0?sheetName:""); |
| | | configTitleCell(sxssfWorkbook,title.getCell(i)); |
| | | } |
| | | Row header1 = sheet.createRow(1); |
| | | header1.createCell(0).setCellValue("投保人"); |
| | | header1.createCell(1).setCellValue("保险方案"); |
| | | header1.createCell(2).setCellValue("保单号"); |
| | | header1.createCell(3).setCellValue("保险生效起期"); |
| | | header1.createCell(4).setCellValue("保险生效止期"); |
| | | header1.createCell(5).setCellValue("加保人数"); |
| | | header1.createCell(6).setCellValue("减保人数"); |
| | | header1.createCell(7).setCellValue("期望批单生效期"); |
| | | for (int i = 0; i < 8; i++) { |
| | | configFirstCell(sxssfWorkbook,header1.getCell(i)); |
| | | } |
| | | |
| | | Row header2 = sheet.createRow(2); |
| | | header2.createCell(0).setCellValue(data.getShopName()); |
| | | header2.createCell(1).setCellValue(data.getSolutionsName()); |
| | | header2.createCell(2).setCellValue(data.getApplyCode()); |
| | | header2.createCell(3).setCellValue(com.doumee.core.utils.DateUtil.getPlusTime2(data.getStartTime())); |
| | | header2.createCell(4).setCellValue(com.doumee.core.utils.DateUtil.getPlusTime2(data.getEndTime())); |
| | | header2.createCell(5).setCellValue(data.getApplyChagneDetailList().stream().filter(i->i.getType().equals(Constants.ZERO)).collect(Collectors.toList()).size()); |
| | | header2.createCell(6).setCellValue(data.getApplyChagneDetailList().stream().filter(i->i.getType().equals(Constants.ONE)).collect(Collectors.toList()).size()); |
| | | header2.createCell(7).setCellValue(com.doumee.core.utils.DateUtil.getPlusTime2(data.getValidTime())); |
| | | for (int i = 0; i < 8; i++) { |
| | | configDataCell(sxssfWorkbook, header2.getCell(i)); |
| | | } |
| | | |
| | | Row header3 = sheet.createRow(3); |
| | | header3.createCell(0).setCellValue("被保险人"); |
| | | header3.createCell(1).setCellValue(data.getCompanyNames()); |
| | | header3.createCell(2).setCellValue(""); |
| | | header3.createCell(3).setCellValue(""); |
| | | header3.createCell(4).setCellValue(""); |
| | | header3.createCell(5).setCellValue(""); |
| | | header3.createCell(6).setCellValue(""); |
| | | header3.createCell(7).setCellValue(""); |
| | | for (int i = 0; i < 8; i++) { |
| | | configFirstCell(sxssfWorkbook,header3.getCell(i)); |
| | | } |
| | | sheet.addMergedRegion(new CellRangeAddress(3 ,3,1,7)); |
| | | |
| | | Integer row = 4; |
| | | List<ApplyChagneDetail> addChangeDetailList = data.getApplyChagneDetailList().stream().filter(i->i.getType().equals(Constants.ZERO)).collect(Collectors.toList()); |
| | | if(CollectionUtils.isNotEmpty(addChangeDetailList)){ |
| | | Row header4 = sheet.createRow(row); |
| | | header4.createCell(0).setCellValue("加保人员"); |
| | | for (int i = 0; i < 8; i++) { |
| | | configFirstCell(sxssfWorkbook, header4.getCell(i)); |
| | | } |
| | | sheet.addMergedRegion(new CellRangeAddress(row ,row,0,7)); |
| | | row = row + 1; |
| | | Row header5 = sheet.createRow(row); |
| | | header5.createCell(0).setCellValue("序号"); |
| | | header5.createCell(1).setCellValue("员工姓名"); |
| | | header5.createCell(2).setCellValue("性别"); |
| | | header5.createCell(3).setCellValue("身份证号"); |
| | | header5.createCell(4).setCellValue("被保险人"); |
| | | header5.createCell(5).setCellValue("派遣单位"); |
| | | header5.createCell(6).setCellValue(""); |
| | | header5.createCell(7).setCellValue("所属工种"); |
| | | for (int i = 0; i < 8; i++) { |
| | | configFirstCell(sxssfWorkbook,header5.getCell(i)); |
| | | } |
| | | sheet.addMergedRegion(new CellRangeAddress(row ,row,5,6)); |
| | | for (int rowIndex = 0; rowIndex < addChangeDetailList.size(); rowIndex++) { |
| | | row = row + 1 ; |
| | | Row header6 = sheet.createRow(row); |
| | | ApplyChagneDetail applyChagneDetail = addChangeDetailList.get(rowIndex); |
| | | header6.createCell(0).setCellValue(rowIndex + 1); |
| | | header6.createCell(1).setCellValue(applyChagneDetail.getMemberName()); |
| | | header6.createCell(2).setCellValue(Constants.equalsInteger(applyChagneDetail.getSex(),0)?"男":(Constants.equalsInteger(applyChagneDetail.getSex(),1)?"女":"-")); |
| | | header6.createCell(3).setCellValue(applyChagneDetail.getIdcardNo()); |
| | | header6.createCell(4).setCellValue(applyChagneDetail.getCompanyName()); |
| | | header6.createCell(5).setCellValue(applyChagneDetail.getDuName()); |
| | | header6.createCell(6).setCellValue(""); |
| | | header6.createCell(7).setCellValue(applyChagneDetail.getWorkTypeName()); |
| | | for (int i = 0; i < 8; i++) { |
| | | configFirstCell(sxssfWorkbook,header6.getCell(i)); |
| | | } |
| | | sheet.addMergedRegion(new CellRangeAddress(row ,row,5,6)); |
| | | } |
| | | } |
| | | |
| | | List<ApplyChagneDetail> reduceChangeDetailList = data.getApplyChagneDetailList().stream().filter(i->i.getType().equals(Constants.ONE)).collect(Collectors.toList()); |
| | | row = row + 1; |
| | | if(CollectionUtils.isNotEmpty(reduceChangeDetailList)){ |
| | | Row header4 = sheet.createRow(row); |
| | | header4.createCell(0).setCellValue("减保人员"); |
| | | for (int i = 0; i < 8; i++) { |
| | | configFirstCell(sxssfWorkbook, header4.getCell(i)); |
| | | } |
| | | sheet.addMergedRegion(new CellRangeAddress(row ,row,0,7)); |
| | | |
| | | row = row + 1; |
| | | Row header5 = sheet.createRow(row); |
| | | header5.createCell(0).setCellValue("序号"); |
| | | header5.createCell(1).setCellValue("员工姓名"); |
| | | header5.createCell(2).setCellValue("性别"); |
| | | header5.createCell(3).setCellValue("身份证号"); |
| | | header5.createCell(4).setCellValue("被保险人"); |
| | | header5.createCell(5).setCellValue("派遣单位"); |
| | | header5.createCell(6).setCellValue(""); |
| | | header5.createCell(7).setCellValue("所属工种"); |
| | | for (int i = 0; i < 8; i++) { |
| | | configFirstCell(sxssfWorkbook,header5.getCell(i)); |
| | | } |
| | | sheet.addMergedRegion(new CellRangeAddress(row ,row,5,6)); |
| | | |
| | | row = row + 1 ; |
| | | for (int rowIndex = 0; rowIndex < reduceChangeDetailList.size(); rowIndex++) { |
| | | row = row + rowIndex; |
| | | Row header6 = sheet.createRow(row); |
| | | ApplyChagneDetail applyChagneDetail = reduceChangeDetailList.get(rowIndex); |
| | | header6.createCell(0).setCellValue(rowIndex + 1); |
| | | header6.createCell(1).setCellValue(applyChagneDetail.getMemberName()); |
| | | header6.createCell(2).setCellValue(Constants.equalsInteger(applyChagneDetail.getSex(),0)?"男":(Constants.equalsInteger(applyChagneDetail.getSex(),1)?"女":"-")); |
| | | header6.createCell(3).setCellValue(applyChagneDetail.getIdcardNo()); |
| | | header6.createCell(4).setCellValue(applyChagneDetail.getCompanyName()); |
| | | header6.createCell(5).setCellValue(applyChagneDetail.getDuName()); |
| | | header6.createCell(6).setCellValue(""); |
| | | header6.createCell(7).setCellValue(applyChagneDetail.getWorkTypeName()); |
| | | for (int i = 0; i < 8; i++) { |
| | | configFirstCell(sxssfWorkbook,header6.getCell(i)); |
| | | } |
| | | sheet.addMergedRegion(new CellRangeAddress(row ,row,5,6)); |
| | | } |
| | | } |
| | | |
| | | int rowIndex = row + 1; |
| | | Row header6= sheet.createRow(rowIndex); |
| | | header6.createCell(0).setCellValue("投保企业申明:\n" + |
| | | "1、在申请书上填写的一切内容属实,否则本企业承担一切法律责任。\n" + |
| | | "2、由于变更受益人产生的法律纠纷本企业愿承担一切法律责任。\n" + |
| | | "3、本申请表的签章为本企业亲自签署,如由此产生的法律纠纷本企业愿承担一切法律责任。\n"); |
| | | for (int i = 1; i < 8; i++) { |
| | | header6.createCell(i).setCellValue(""); |
| | | } |
| | | for (int i =0; i < 8; i++) { |
| | | if(i>0){ |
| | | header6.createCell(i).setCellValue(""); |
| | | } |
| | | configInfoCell(sxssfWorkbook,header6.getCell(i),HorizontalAlignment.LEFT); |
| | | } |
| | | header6.setHeight((short) 2000); |
| | | sheet.addMergedRegion(new CellRangeAddress(rowIndex ,rowIndex,0,11)); |
| | | Row header7= sheet.createRow(rowIndex+1); |
| | | header7.setHeight((short) 3000); |
| | | header7.createCell(0).setCellValue("投保人签章 : \n \n \n" +"日期: 年 月 日 "); |
| | | for (int i =0; i < 8; i++) { |
| | | if(i>0){ |
| | | header7.createCell(i).setCellValue(""); |
| | | } |
| | | configInfoCell(sxssfWorkbook,header7.getCell(i),HorizontalAlignment.RIGHT); |
| | | } |
| | | sheet.addMergedRegion(new CellRangeAddress(rowIndex+1 ,rowIndex+1,0,11)); |
| | | |
| | | //临时缓冲区 |
| | | ByteArrayOutputStream out = new ByteArrayOutputStream(); |
| | | //创建临时文件 |
| | | sxssfWorkbook.write(out); |
| | | byte [] bookByteAry = out.toByteArray(); |
| | | InputStream in = new ByteArrayInputStream(bookByteAry); |
| | | String tempExcel = saveIsToFile(in); |
| | | String tempPdf =System.getProperty("java.io.tmpdir")+File.separator+UUID.randomUUID().toString()+".pdf"; |
| | | // ExcelToPdfTool.excelToPdf(in,tempPdf);//转PDF |
| | | ExcelToPdfTool.excelToPdf(tempExcel,tempPdf);//转PDF |
| | | File f = new File(tempPdf); |
| | | if(f!=null && f.isFile() && f.length()>0){ |
| | | return tempPdf; |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | // throw new BusinessException(ResponseStatus.EXPORT_EXCEL_ERROR, e); |
| | | } |
| | | return null; |
| | | } |
| | | } |