• 报表制作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文件如下

    做测试如下

  • 相关阅读:
    剑指OFFER之合并有序链表(九度OJ1519)
    剑指OFFER之反转链表(九度OJ1518)
    剑指OFFER之链表中倒数第k个节点(九度OJ1517)
    一分钟教你在博客园中制作自己的动态云球形标签页
    剑指OFFER之调整数组顺序使奇数位于偶数前面找(九度OJ1516)
    剑指OFFER之打印1到最大的N位数(九度OJ1515)
    剑指OFFER之矩形覆盖(九度OJ1390)
    剑指OFFER之数值的整数次方(九度OJ1514)
    剑指OFFER之变态跳台阶(九度OJ1389)
    剑指OFFER之二进制中1的个数(九度OJ1513)
  • 原文地址:https://www.cnblogs.com/ms-grf/p/6756243.html
Copyright © 2020-2023  润新知