public String renewalPdf(PolicyInformationDO policyInfo, String totalPremium, String renewalDate,String path, HttpServletRequest request,HttpServletResponse response,String type) {
try {
Policy pdo = policyInfo.getPolicy();
PolicyHolder holderDO = policyInfo.getPolicyHolder();
List<PolicyInsured> insuredList = policyInfo.getPolicyInsuredlist();
String policyNo = pdo.getPolicyNo();
String insurNames = "";
for (int i = 1; i < insuredList.size(); i++) {
insurNames = insurNames + insuredList.get(i).getName() + " ";
}
String planname = "";
String planCode = pdo.getPlanCode();
if("YALJYSA".equals(planCode) || "YABJLJYSA".equals(planCode) || "0261000217".equals(planCode) || "0231000516".equals(planCode)
|| "YALJYSSHXBA".equals(planCode) || "YALJYSBJXBA".equals(planCode) || "0261000217XB".equals(planCode) || "0231000516XB".equals(planCode) ){
planname = "计划一住院";
}else if("YALJYSC".equals(planCode) || "YABJLJYSC".equals(planCode) || "0261000218".equals(planCode) || "0231000517".equals(planCode)
|| "YALJYSSHXBB".equals(planCode) || "YALJYSBJXBC".equals(planCode) || "0261000218XB".equals(planCode) || "0231000517XB".equals(planCode) ){
planname = "计划一住院+门诊";
}else if("YALJYSB".equals(planCode) || "YABJLJYSB".equals(planCode) || "0261000219".equals(planCode) || "0231000518".equals(planCode)
|| "YALJYSSHXBC".equals(planCode) || "YALJYSBJXBB".equals(planCode) || "0261000219XB".equals(planCode) || "0231000518XB".equals(planCode)){
planname = "计划二住院";
}else if("YALJYSD".equals(planCode) || "YABJLJYSD".equals(planCode) || "0261000220".equals(planCode) || "0231000519".equals(planCode)
|| "YALJYSSHXBD".equals(planCode) || "YALJYSBJXBD".equals(planCode) || "0261000220XB".equals(planCode) || "0231000519XB".equals(planCode) ){
planname = "计划二住院+门诊";
}else if("YALJYSE".equals(planCode) || "YABJLJYSE".equals(planCode) || "0261000221".equals(planCode) || "0231000520".equals(planCode)
|| "YALJYSSHXBE".equals(planCode) || "YALJYSBJXBE".equals(planCode) || "0261000221XB".equals(planCode) || "0231000520XB".equals(planCode)){
planname = "计划三住院";
}
BaseFont bf = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H",
BaseFont.NOT_EMBEDDED);
Font FontChinese = new Font(bf, 10, Font.NORMAL);
String pdfUrl="pdfjasper/tongzhi.jasper";
ClassPathResource pubKeyResource = new ClassPathResource(pdfUrl);
JasperReport jasperReport = (JasperReport) JRLoader
.loadObjectFromFile(pubKeyResource.getFile().toString());
Map<String, Object> parameters = new HashMap<String, Object>();
// ****设置头参数
parameters.put("policyNo", policyNo);
parameters.put("holderName", holderDO.getName());
parameters.put("mainInsuredName", insuredList.get(0).getName());
parameters.put("insureds", insurNames);
parameters.put("plans", "定制"+planname+",住院责任(详见附表)");
parameters.put("renewalPrieum", totalPremium);
parameters.put("renewalDate", renewalDate);
response.setContentType("application/msword");
response.addHeader("Content-Disposition", "attachment; filename=\"renewal00001.pdf\"");
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, new JREmptyDataSource());
if(!"".equals(path)){
String tmpfilePath ="/datavg/apache-tomcat-6.0.44/webapps/examples/renewal/";
//String tmpfilePath = request.getSession().getServletContext().getRealPath("/")+"pdf"+File.separator+"yongan"+File.separator;
/*if(type.equals("preview")){ //浏览
tmpfilePath=path;
}*/
System.out.println("===========================文件生成路径tmpfilePath="+tmpfilePath);
File localFile = new File(tmpfilePath);
if(!localFile.exists()){
System.out.println("创建文件");
localFile.mkdir();
}
JasperExportManager.exportReportToPdfFile(jasperPrint, tmpfilePath + "renewal00001.pdf");
// JasperExportManager.exportReportToPdfStream(jasperPrint, new FileOutputStream(new File("/datavg/renewal00001.pdf")));
}else {
// 导出为PDF
JRPdfExporter exporter = new JRPdfExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM,
response.getOutputStream());
exporter.exportReport();// 导出
}
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("====================================23412341234");
return null;
}
用jasper模板生成PDF
最新推荐文章于 2024-06-13 15:23:35 发布