package cc.mrbird.febs.server.hr.service.impl; import cc.mrbird.febs.common.core.entity.QueryRequest; import cc.mrbird.febs.common.core.entity.system.DicItem; import cc.mrbird.febs.server.hr.entity.*; import cc.mrbird.febs.server.hr.feign.IRemoteDicItemService; import cc.mrbird.febs.server.hr.po.AvailableResult; import cc.mrbird.febs.server.hr.po.User; import cc.mrbird.febs.server.hr.service.*; import cc.mrbird.febs.server.hr.util.CreatePdf; import com.baomidou.mybatisplus.core.metadata.IPage; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.*; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @Service public class ExportPdfServiceImpl implements ExportPdfService { @Autowired private IEmpWorkExperienceService iEmpWorkExperienceService; @Autowired private IEmpBadRecordService iEmpBadRecordService; @Autowired private IEmpBaseInfoService iEmpBaseInfoService; @Autowired private IEmpContractInfoService iEmpContractInfoService; @Autowired private IEmpDimissionAttendService iEmpDimissionAttendService; @Autowired private IEmpDimissionLogService iEmpDimissionLogService; @Autowired private IEmpInsuranceService iEmpInsuranceService; @Autowired private IEmpJobChangeService iEmpJobChangeService; @Autowired private IEmpLaborTroubleService iEmpLaborTroubleService; @Autowired private IEmpLeaveInfoService iEmpLeaveInfoService; @Autowired private IEmpOccupationalService iEmpOccupationalService; @Autowired private IEmpOpenArchivesService iEmpOpenArchivesService; @Autowired private IEmpPhysicalExamService iEmpPhysicalExamService; @Autowired private IEmpRemarkinfoService iEmpRemarkinfoService; @Autowired private IEmpResignService iEmpResignService; @Autowired private IEmpUnemploymentService iEmpUnemploymentService; @Autowired private IEmpAccidentCasesService iEmpAccidentCasesService; @Autowired private IRemoteDicItemService iRemoteDicItemService; Logger logger = LoggerFactory.getLogger(ExportPdfServiceImpl.class); @Override public void exportPdf(String empNum, QueryRequest queryRequest, HttpServletRequest request, HttpServletResponse response) { try { //体检类型 Map physicalExamType = new HashMap<>(); for (DicItem m: (List)iRemoteDicItemService.dictType("PHYSICALEXAMTYPE")) { physicalExamType.put(m.getDicItemCode(),m.getDicItemName()); } //心电图 Map ecg = new HashMap<>(); for (DicItem m: (List)iRemoteDicItemService.dictType("ECG")) { ecg.put(m.getDicItemCode(),m.getDicItemName()); } //合同状态 Map contractstatus = new HashMap<>(); for (DicItem m: (List)iRemoteDicItemService.dictType("CONTRACTSTATUS")) { contractstatus.put(m.getDicItemCode(),m.getDicItemName()); } //调岗类型 Map changeType = new HashMap<>(); for (DicItem m: (List)iRemoteDicItemService.dictType("changeType")) { changeType.put(m.getDicItemCode(),m.getDicItemName()); } //请假类型 Map leavetype = new HashMap<>(); for (DicItem m: (List)iRemoteDicItemService.dictType("LEAVETYPE")) { leavetype.put(m.getDicItemCode(),m.getDicItemName()); } //入离职类型 Map lztype = new HashMap<>(); for (DicItem m: (List)iRemoteDicItemService.dictType("LZTYPE")) { lztype.put(m.getDicItemCode(),m.getDicItemName()); } //社保档位 Map insuranceGaers = new HashMap<>(); for (DicItem m: (List)iRemoteDicItemService.dictType("insuranceGaers")) { insuranceGaers.put(m.getDicItemCode(),m.getDicItemName()); } //社保是否已经报告 Map reportStatus = new HashMap<>(); for (DicItem m: (List)iRemoteDicItemService.dictType("reportStatus")) { reportStatus.put(m.getDicItemCode(),m.getDicItemName()); } //社保状态 Map applayStatus = new HashMap<>(); for (DicItem m: (List)iRemoteDicItemService.dictType("applayStatus")) { applayStatus.put(m.getDicItemCode(),m.getDicItemName()); } //是否住院 Map hospitalizatioFlag = new HashMap<>(); for (DicItem m: (List)iRemoteDicItemService.dictType("hospitalizatioFlag")) { hospitalizatioFlag.put(m.getDicItemCode(),m.getDicItemName()); } //仲裁类型 Map zctype = new HashMap<>(); for (DicItem m: (List)iRemoteDicItemService.dictType("ZCTYPE")) { zctype.put(m.getDicItemCode(),m.getDicItemName()); } //结案状态 Map settleStatus = new HashMap<>(); for (DicItem m: (List)iRemoteDicItemService.dictType("settleStatus")) { settleStatus.put(m.getDicItemCode(),m.getDicItemName()); } //性别 Map sex = new HashMap<>(); for (DicItem m: (List)iRemoteDicItemService.dictType("sex")) { sex.put(m.getDicItemCode(),m.getDicItemName()); } //员工类别 Map empType = new HashMap<>(); for (DicItem m: (List)iRemoteDicItemService.dictType("EMPTYPE")) { empType.put(m.getDicItemCode(),m.getDicItemName()); } //民族 Map NATION = new HashMap<>(); for (DicItem m: (List)iRemoteDicItemService.dictType("NATION")) { NATION.put(m.getDicItemCode(),m.getDicItemName()); } //婚姻状态 Map MARRIAGE = new HashMap<>(); for (DicItem m: (List)iRemoteDicItemService.dictType("MARRIAGE")) { MARRIAGE.put(m.getDicItemCode(),m.getDicItemName()); } //政治面貌 Map PLITICAL = new HashMap<>(); for (DicItem m: (List)iRemoteDicItemService.dictType("PLITICAL")) { PLITICAL.put(m.getDicItemCode(),m.getDicItemName()); } //最高学历 Map EDUCATION= new HashMap<>(); for (DicItem m: (List)iRemoteDicItemService.dictType("EDUCATION")) { EDUCATION.put(m.getDicItemCode(),m.getDicItemName()); } //籍贯 Map NATIVEPLACE= new HashMap<>(); /*for (DicItem m: (List)iRemoteDicItemService.dictType("NATIVEPLACE")) { NATIVEPLACE.put(m.getDicItemCode(),m.getDicItemName()); }*/ //保险类型 Map INSURANCETYPE= new HashMap<>(); for (DicItem m: (List)iRemoteDicItemService.dictType("INSURANCETYPE")) { INSURANCETYPE.put(m.getDicItemCode(),m.getDicItemName()); } //员工手册 Map handbookStatus= new HashMap<>(); for (DicItem m: (List)iRemoteDicItemService.dictType("handbookStatus")) { handbookStatus.put(m.getDicItemCode(),m.getDicItemName()); } //相关证件 Map certificateList= new HashMap<>(); for (DicItem m: (List)iRemoteDicItemService.dictType("certificateList")) { certificateList.put(m.getDicItemCode(),m.getDicItemName()); } logger.info(">>>>>>>>>>开始导出pdf>>>>>>>>>>"); //基本信息 String[] baseinfo = { "档案号", "姓名", "性别", "部门(护卫点)", "岗位", "员工类别", "民族", "年龄", "婚姻状态", "身份证有效期" , "身高(cm)" , "政治面貌", "出生日期", "最高学历", "籍贯", "户籍地址", "现住址", "保安员回执", "保安员证号", "档案情况", "银行名称" , "银行账号", "电话号码", "入职日期" , "保险类型", "社保电脑号", "招聘介绍人", "入司工龄", "工作证", "家庭成员及关系", "紧急联系电话", "员工手册", "相关证件" , "身份证号码"}; EmpBaseInfo baseInfo=new EmpBaseInfo(); baseInfo.setEmpNumb(empNum); List empBaseInfoList = iEmpBaseInfoService.findEmpBaseInfos(queryRequest, baseInfo).getRecords(); for (EmpBaseInfo empBaseInfo: empBaseInfoList){ empBaseInfo.setSexName(sex.get(empBaseInfo.getSex()==null?"":empBaseInfo.getSex())); empBaseInfo.setEmpTypeName(empType.get(empBaseInfo.getEmpType()==null?"":empBaseInfo.getEmpType())); empBaseInfo.setNationName(NATION.get(empBaseInfo.getNation()==null?"":empBaseInfo.getNation())); empBaseInfo.setMarriageName(MARRIAGE.get(empBaseInfo.getMarriage()==null?"":empBaseInfo.getMarriage())); empBaseInfo.setPoliticsName(PLITICAL.get(empBaseInfo.getPolitics()==null?"":empBaseInfo.getPolitics())); empBaseInfo.setEducationName(EDUCATION.get(empBaseInfo.getEducation()==null?"":empBaseInfo.getEducation())); empBaseInfo.setNativePlaceName(NATIVEPLACE.get(empBaseInfo.getNativePlace()==null?"":empBaseInfo.getNativePlace())); empBaseInfo.setInsuranceTypeName(INSURANCETYPE.get(empBaseInfo.getInsuranceType()==null?"":empBaseInfo.getInsuranceType())); empBaseInfo.setHandbookStatusName(handbookStatus.get(empBaseInfo.getHandbookStatus()==null?"":empBaseInfo.getHandbookStatus())); empBaseInfo.setCertificateListName(certificateList.get(empBaseInfo.getCertificateList()==null?"":empBaseInfo.getCertificateList())); } //工作经历 String[] workhead = { "开始时间", "结束时间", "工作单位", "主要工作内容"}; EmpWorkExperience empWorkExperiences=new EmpWorkExperience(); empWorkExperiences.setEmpNumb(empNum); empWorkExperiences.setDelFlag(0); List empWorkExperiences1 = iEmpWorkExperienceService.findEmpWorkExperiences(queryRequest, empWorkExperiences).getRecords(); //体检信息 String[] empPhysicalhead = { "体检医院", "体检日期", "体检类型", "血压", "转氨酶", "心电图", "体检结论", "复查记录", "备注"}; EmpPhysicalExam empPhysicalExam=new EmpPhysicalExam(); empPhysicalExam.setEmpNumb(empNum); List records = iEmpPhysicalExamService.findEmpPhysicalExams(queryRequest, empPhysicalExam).getRecords(); for (EmpPhysicalExam empPhysicalExam1:records){ empPhysicalExam1.setPhysicalExamTypeName(physicalExamType.get(empPhysicalExam1.getPhysicalExamType()==null?"":empPhysicalExam1.getPhysicalExamType())); } //合同信息 String[] empContractInfo = { "合同签订日期", "合同结束日期", "合同期限(年)", "合同状态", "合同办理人"}; EmpContractInfo empContractInfo1=new EmpContractInfo(); empContractInfo1.setEmpNumb(empNum); List empContractInfos = iEmpContractInfoService.findEmpContractinfos(queryRequest, empContractInfo1).getRecords(); for (EmpContractInfo empCon:empContractInfos){ empCon.setContractStatusName(contractstatus.get(empCon.getContractStatus()==null?"":empCon.getContractStatus())); } //调岗记录 String[] empJobChange = { "现部门", "现岗位", "姓名", "原部门", "原岗位", "调岗日期", "调岗类型"}; EmpJobChange empJobChange1=new EmpJobChange(); empJobChange1.setEmpNumb(empNum); List> empJobChangeList = iEmpJobChangeService.findEmpJobChanges(queryRequest, empJobChange1).getRecords(); for (Map map:empJobChangeList){ map.put("changeType",changeType.get(map.get("changeType")==null?"":map.get("changeType").toString())); } //请假记录 String[] leaveInfo = { "开始时间", "结束时间", "请假天数", "请假类型", "到岗时间", "报备人", "备注"}; EmpLeaveInfo empLeaveInfo=new EmpLeaveInfo(); empLeaveInfo.setEmpNumb(empNum); List empLeaveInfos = iEmpLeaveInfoService.findEmpLeaveInfos(queryRequest, empLeaveInfo).getRecords(); for (EmpLeaveInfo leaveInfo1:empLeaveInfos){ leaveInfo1.setLeaveTypeName(leavetype.get(leaveInfo1.getLeaveType()==null?"":leaveInfo1.getLeaveType())); } //辞职申请 String[] resign = { "辞职申请日期", "辞职事由", "汇报人", "备注"}; EmpResign empResign=new EmpResign(); empResign.setEmpNumb(empNum); List empResigns = iEmpResignService.findEmpResigns(queryRequest, empResign).getRecords(); //离职当月考勤 String[] dimissionAttend = { "离职考勤月份", "出勤天数", "加班(天)", "加班(小时)", "有无代扣款项", "请假(天)", "旷工(天)", "备注"}; EmpDimissionAttend empDimissionAttend=new EmpDimissionAttend(); empDimissionAttend.setEmpNumb(empNum); List dimissionAttends = iEmpDimissionAttendService.findEmpDimissionattends(queryRequest, empDimissionAttend).getRecords(); //入离职记录 String[] dimissionLog = { "入职日期", "离职日期", "离职类型", "自离天数", "报备人", "备注"}; EmpDimissionLog empDimissionLog=new EmpDimissionLog(); empDimissionLog.setEmpNumb(empNum); List> records1 = iEmpDimissionLogService.findEmpDimissionLogs(queryRequest, empDimissionLog).getRecords(); for (Map objectMap:records1){ objectMap.put("dimissionType",lztype.get(objectMap.get("dimissionType")==null?"":objectMap.get("dimissionType").toString())); } //失业金领取 String[] unemployment = { "失业金申请日期", "申报事由", "汇报人", "审核人", "备注"}; EmpUnemployment empUnemployment=new EmpUnemployment(); empUnemployment.setEmpNumb(empNum); List empUnemployments = iEmpUnemploymentService.findEmpUnemployments(queryRequest, empUnemployment).getRecords(); //社保申请 String[] insurance = { "社保申请日期", "申请人", "社保档位", "是否已报告", "状态", "审核人", "备注"}; EmpInsurance empInsurance=new EmpInsurance(); empInsurance.setEmpNumb(empNum); List empInsurances = iEmpInsuranceService.findEmpInsurances(queryRequest, empInsurance).getRecords(); for (EmpInsurance leaveInfo1:empInsurances){ leaveInfo1.setInsuranceGaers(insuranceGaers.get(leaveInfo1.getInsuranceGaers()==null?"":leaveInfo1.getInsuranceGaers())); leaveInfo1.setReportStatusName(reportStatus.get(leaveInfo1.getReportStatus()==null?"":String.valueOf(leaveInfo1.getReportStatus()))); leaveInfo1.setApplayStatusName(applayStatus.get(leaveInfo1.getApplayStatus()==null?"":String.valueOf(leaveInfo1.getApplayStatus()))); } //意外险案件 String[] accidentCases = { "受伤日期", "受伤地点", "受伤部位", "受伤经过描述", "意外险诊断", "就诊医院", "是否住院", "床号", "报案时间", "递交资料时间", "递交人", "医疗总费用", "保险赔付费用"}; EmpAccidentCases empAccidentCases=new EmpAccidentCases(); empAccidentCases.setEmpNumb(empNum); List empAccidentCases1 = iEmpAccidentCasesService.findEmpAccidentcasess(queryRequest, empAccidentCases).getRecords(); for (EmpAccidentCases leaveInfo1:empAccidentCases1){ leaveInfo1.setHospitalizatioFlagName(hospitalizatioFlag.get(leaveInfo1.getHospitalizatioFlag()==null?"":leaveInfo1.getHospitalizatioFlag())); } //工伤案件 String[] occupational = { "受伤日期", "受伤地点", "受伤部位", "受伤经过描述", "工伤诊断", "就诊医院", "就诊科室", "是否住院", "床号", "报案时间", "递交资料时间", "递交人", "医疗总费用", "已赔付医药费用"}; EmpOccupational empOccupational=new EmpOccupational(); empOccupational.setEmpNumb(empNum); List empOccupationals = iEmpOccupationalService.findEmpOccupationals(queryRequest, empOccupational).getRecords(); for (EmpOccupational leaveInfo1:empOccupationals){ leaveInfo1.setHospitalizatioFlagName(hospitalizatioFlag.get(leaveInfo1.getHospitalizatioFlag()==null?"":leaveInfo1.getHospitalizatioFlag())); } //劳资案件 String[] laborTrouble = { "仲裁日期", "仲裁类型", "仲裁事由", "报备人", "备注", "仲裁赔付(元)", "状态", "案结日期"}; EmpLaborTrouble empLaborTrouble=new EmpLaborTrouble(); empLaborTrouble.setEmpNumb(empNum); List empLaborTroubles = iEmpLaborTroubleService.findEmpLabortroubles(queryRequest, empLaborTrouble).getRecords(); for (EmpLaborTrouble leaveInfo1:empLaborTroubles){ leaveInfo1.setArbitrationTypeName(zctype.get(leaveInfo1.getArbitrationType()==null?"":leaveInfo1.getArbitrationType())); leaveInfo1.setArbitrationStatusName(reportStatus.get(leaveInfo1.getArbitrationStatus()==null?"":String.valueOf(leaveInfo1.getArbitrationStatus()))); } //不良记录 String[] badRecord = { "不良记录日期", "不良记录描述", "汇报人", "备注"}; EmpBadRecord empBadRecord=new EmpBadRecord(); empBadRecord.setEmpNumb(empNum); List empBadRecords = iEmpBadRecordService.findEmpBadrecords(queryRequest, empBadRecord).getRecords(); //备注 String[] remarkInfo = { "备注日期", "备注信息"}; EmpRemarkInfo empRemarkInfo=new EmpRemarkInfo(); empRemarkInfo.setEmpNumb(empNum); List empRemarkInfos = iEmpRemarkinfoService.findEmpRemarkinfos(queryRequest, empRemarkInfo).getRecords(); String filePath = new CreatePdf().generatePDFs(baseinfo,empBaseInfoList,workhead, empWorkExperiences1,empPhysicalhead,records, empContractInfo,empContractInfos, empJobChange,empJobChangeList, leaveInfo,empLeaveInfos, resign,empResigns, dimissionAttend,dimissionAttends, dimissionLog,records1, unemployment,empUnemployments, insurance,empInsurances, accidentCases,empAccidentCases1, occupational,empOccupationals, laborTrouble,empLaborTroubles, badRecord,empBadRecords, remarkInfo,empRemarkInfos,response); System.out.println(filePath); downloadPdf(filePath,request,response); logger.info(">>>>>>>>>>结束导出pdf>>>>>>>>>>"); } catch (Exception e) { e.printStackTrace(); logger.error(">>>>>>>>>>导出pdf 异常,原因为:" + e.getMessage()); } } public String downloadPdf( String filepath,HttpServletRequest request, HttpServletResponse response) throws IOException { File file = new File(filepath); if (!file.exists()) { request.setAttribute("error", "附件已删除或不存在"); // return "/error"; } InputStream in = null; OutputStream os = null; try { response.setContentType("application/pdf"); // 设置返回内容格式 in = new FileInputStream(file); //用该文件创建一个输入流 os = response.getOutputStream(); //创建输出流 byte[] b = new byte[1024]; while (in.read(b) != -1) { os.write(b); } in.close(); os.flush(); os.close(); } catch (Exception e) { try { if (null != in) { in.close(); } } catch (IOException e1) { e1.printStackTrace(); } try { if (null != os) { os.close(); } } catch (IOException e2) { e2.printStackTrace(); } } return null; } }