报表制作2(传入一个sql主键 含子报表)
报表js
$scope.printCpTempletMasterDetail = function (cpId) { var parameters = { reportFileName: "reports/doctorstation/CpTempletMasterDetail.jasper", parameters: { 'cpId': cpId } }; var printInfoObject = { type: "report", appletParameters: { is_direct_print: true, is_display: false, printer_name: null, report_url: "api/jasper-prints/doctor-station/cp-order-detail" }, reportParameter: parameters }; HrUtils.postMessageToBaseFrame(printInfoObject, "*"); };
报表DoctorstationPrintResource.java
package com.heren.his.report.api; import com.heren.his.report.facade.DoctorstationPrintFacade; import com.heren.his.report.vo.JasperPrintParamsVo; import net.sf.jasperreports.engine.JasperPrint; import javax.ws.rs.*; import javax.ws.rs.core.MediaType; @Path("doctor-station") public class DoctorstationPrintResource { @javax.inject.Inject private DoctorstationPrintFacade doctorstationPrintFacade; /** * 打印路径明细 * @param parameters * @return */ @GET @Path("cp-order-detail") @Produces({MediaType.APPLICATION_OCTET_STREAM}) public JasperPrint fillCpTempletMasterDetailReport(@QueryParam("parameter") JasperPrintParamsVo parameters){ return doctorstationPrintFacade.fillCpTempletMasterDetailReport(parameters); } }
报表DoctorstationPrintFacade.java
package com.heren.his.report.facade; import com.google.common.base.Strings; import com.heren.his.report.common.HrResultSet; import com.heren.his.report.vo.JasperPrintParamsVo; import com.heren.his.report.vo.doctorstation.ErOutpBloodDetail; import com.heren.his.report.vo.doctorstation.ErOutpBloodVO; import com.heren.his.report.vo.doctorstation.MedicalRecordInfoVO; import net.sf.jasperreports.engine.JasperPrint; import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource; import net.sf.jasperreports.engine.data.JRMapCollectionDataSource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.inject.Inject; import java.util.ArrayList; import java.util.List; import java.util.Map; import static com.heren.his.report.util.ReportUtils.obtainJasperReportByFileName; public class DoctorstationPrintFacade extends BaseJasperFillFacade { private static final Logger LOGGER = LoggerFactory.getLogger(DoctorstationPrintFacade.class); @Inject private MedicalInfoDataFacade medicalInfoDataFacade; /** * 打印路径医嘱明细 * * @param jasperPrintParamsVo * @return */ public JasperPrint fillCpTempletMasterDetailReport(JasperPrintParamsVo jasperPrintParamsVo) { LOGGER.debug("填充报表[{}];填充时使用参数:[{}]。", jasperPrintParamsVo.getReportFileName(), jasperPrintParamsVo.getParameters()); Map reportParam = jasperPrintParamsVo.getParameters();//js里面的cpId reportParam.put("SUBREPORT_DIR", "reports/doctorstation/"); return hrFillReportWithConnection(obtainJasperReportByFileName(jasperPrintParamsVo.getReportFileName()), reportParam); } }
报表
1:创建主报表master.jrxml
先在master.jrxml新建两个parameters,名字是上面代码中红色标注的 如下图
cpId是用来写sql的主键,而SUBREPORT_DIR是用来连接子报表的一个地址
开始写master.jrxml的sql语句如下图
写完sql点击Read Fields就可以把master.jrxml里用到的参数放置在Fields里面了
完善master.jrxml
2:建立子报表 nurse.jrxml
下面这个STAGE_ID是从父报表传到子报表的参数(因为子报表也需要写sql也需要查询条件)
子报表建立完成
最主要的一点配置子报表如下
然后把连接子报表的SUBREPORT_DIR变量设置一下如下
生成.jasper文件如下
做测试如下