简体   繁体   English

如何将json数据从主报表传递到子报表 Jaspersoft Studio

[英]How to pass json data from main report to subreport Jaspersoft Studio

I want to create a report like this我想创建一个这样的报告在此处输入图片说明

I have the structure of the tables created, in the page 2 the source data is a JSON with a list of products and its properties.我创建了表的结构,在第 2 页中,源数据是带有产品及其属性列表的 JSON。 I want to shows the JSON data into the tables, actually have a subreport with the tables, but don't know how pass the JSON data to the subreport and its fill according to the productList key in JSON data.我想将 JSON 数据显示到表中,实际上有一个带有表的子报表,但不知道如何根据 JSON 数据中的 productList 键将 JSON 数据传递给子报表及其填充。 The report fills from a java class that receives the data from the user.报告从接收用户数据的 java 类填充。

I don't know how to fill the tables of the page 2, can anyone helps me?我不知道如何填写第 2 页的表格,有人可以帮助我吗?

This is my code in Jaspersoft Studio 6.10这是我在 Jaspersoft Studio 6.10 中的代码

Main Report主要报告

https://app.box.com/s/qhl0158r03g9jowrhofojd6pkodwkojs

SubReport子报表

https://app.box.com/s/gt5h19qxj1gs5ldghvajd3umx720dwgp

Java class (Fill the report) Java类(填写报告)

    ...
    JasperReport jr = null;

    //DATA TO THE REPORT
    String nombreCliente = "Caracol Radio LTDA.";
    String contactoCliente = "3694100";
    String nombreUsuario = "David";
    String apellidoUsuario = "Torres";
    String cargoUsuario = "Aux. Administrativo";
    String nombreEmpresaCondicionesComerciales = "BIO BOLSA";
    String tipoCuentaCondicionesComerciales = "Ahorros";
    String bancoCondicionesComerciales = "Davivienda";
    String numeroCuentaCondicionesComerciales = "481670000670";
    String domicilioCondicionesEntrega = "Bogotá";
    String simboloMonedaCondicionesEntrega = "$";
    String embalajeSuperiorCondicionesEntrega = "800.000";
    String impuestoCondicionesEntrega = "iva";
    String domicilioFueraCondicionesEntrega = "iva";
    String capacidadInstaladaOrdenProduccion = "1.000.000";

    String tipoEmpresa = "S.A.S";
    String regimenEmpresa = "Regimen Comun";
    String nitEmpresa = "900.390.537-1";
    String telefonosEmpresa = "Tels: (57) (1) 7137516 EXT 1142 – 7138731 - 2033205 Cel: (57) 300 275 45 51";
    String correoWebEmpresa = "Web: www.biobolsa.com.co   E-mail: pchacon@biobolsa.com.co";
    String direccionEmpresa = "Fábrica CRA 57 NO 45 A – 52 SUR LA SEVILLANA";
    String ciudadEmpresa = "Bogotá D.C, Colombia";

    Map<String, Object> parametros = new HashMap<String, Object>();
    parametros.put("NombreCliente", nombreCliente);
    parametros.put("ContactoCliente", contactoCliente);
    parametros.put("NombreUsuario", nombreUsuario);
    parametros.put("ApellidoUsuario", apellidoUsuario);
    parametros.put("CargoUsuario", cargoUsuario);
    parametros.put("TipoEmpresa", tipoEmpresa);
    parametros.put("Regimen", regimenEmpresa);
    parametros.put("Nit", nitEmpresa);
    parametros.put("Telefonos", telefonosEmpresa);
    parametros.put("WebCorreo", correoWebEmpresa);
    parametros.put("Direccion", direccionEmpresa);
    parametros.put("Ciudad", ciudadEmpresa);
    parametros.put("NombreEmpresaCondicionesComerciales", nombreEmpresaCondicionesComerciales);
    parametros.put("TipoCuentaCondicionesComerciales", tipoCuentaCondicionesComerciales);
    parametros.put("BancoCondicionesComerciales", bancoCondicionesComerciales);
    parametros.put("NumeroCuentaCondicionesComerciales", numeroCuentaCondicionesComerciales);
    parametros.put("DomicilioCondicionesEntrega", domicilioCondicionesEntrega);
    parametros.put("SimboloMonedaCondicionesEntrega", simboloMonedaCondicionesEntrega);
    parametros.put("EmbalajeSuperiorCondicionesEntrega", embalajeSuperiorCondicionesEntrega);
    parametros.put("ImpuestoCondicionesEntrega", impuestoCondicionesEntrega);
    parametros.put("DomicilioFueraCondicionesEntrega", domicilioFueraCondicionesEntrega);
    parametros.put("CapacidadInstaladaOrdenProduccion", capacidadInstaladaOrdenProduccion);

    try {
        jr = JasperCompileManager.compileReport("PATH\\TO\\REPORT\\ReporteBiobolsa.jrxml");
        JasperPrint jp = JasperFillManager.fillReport(jr, parametros, new JREmptyDataSource());
        JasperExportManager.exportReportToPdfFile(jp, "PATH\\TO\\EXPORT\\PDFBiobolsa.pdf");


        return Response
                .status(Response.Status.OK)
                .entity("OK.......!!")
                .build();
    } catch (JRException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();

        return Response
                .status(Response.Status.INTERNAL_SERVER_ERROR)
                .entity("ERROR.......!!")
                .build();
    }

JSON data JSON 数据

{
"productList": [{
            "productNumber": 1,
            "modelo": "Bolsa Deportiva Plana",
            "tela": "Tafeta",
            "dimensiones": "40x35",
            "destino": "Bog, D.C",
            "accesoriosModelo": [{
                "nombre": "Cordon"
            },{
                "nombre": "Accesorio 2"
            },{
                "nombre": "Accesorio 3"
            }],
            "accesoriosAdicionales": [{
                "nombre": "Bolsillo (30x40)"
            },{
                "nombre": "Accesorio Adicional 2"
            },{
                "nombre": "Accesorio Adicional 3"
            }],
            "estampado": [{
                "nombre": "Cara Frontal – 1 Tinta"
            },{
                "nombre": "Cara Posterior – 1 Tinta"
            },{
                "nombre": "Estampado 3"
            }],
            "observaciones": "Observacion de Prueba",
            "cantidad": 500,
            "vrUnitario": 1200,
            "subTotal": 600000,
            "iva": 50000,
            "total": 650000
        },
        {
            "productNumber": 2,
            "modelo": "Bolsa Deportiva",
            "tela": "Otra",
            "dimensiones": "50x20",
            "destino": "Bog, D.C",
            "accesoriosModelo": [{
                "nombre": "Cremallera"
            },{
                "nombre": "Accesorio 2"
            },{
                "nombre": "Accesorio 3"
            }],
            "accesoriosAdicionales": [{
                "nombre": "Botones"
            },{
                "nombre": "Accesorio Adicional 2"
            },{
                "nombre": "Accesorio Adicional 3"
            }],
            "estampado": [{
                "nombre": "Cara Posterior – 1 Tinta"
            }],
            "observaciones": "Observacion de Prueba",
            "cantidad": 400,
            "vrUnitario": 900,
            "subTotal": 360000,
            "iva": 40000,
            "total": 400000
        }
    ]
}

How do you give the JSON data to the report?你如何将 JSON 数据提供给报告? If you give the data over a java program via parameters to your MainReport you have to define the parameters in the report.如果您通过 Java 程序通过参数将数据提供给 MainReport,则必须在报告中定义参数。 When you want to give the data to your subreport, you have to define the exact same parameter in both reports (sub and main).当您想为子报表提供数据时,您必须在两个报表(子报表和主报表)中定义完全相同的参数。 It is important that you DON'T use the parameter (datasource) you wanne use for your table in another way too.重要的是,您不要以其他方式使用您想要用于表的参数(数据源)。 Jasper uses datasources only one time, if you want to use the same datasource for a table and a chart (cause you wanne show the same data in two different ways) you have to give two different datasources with the same data to the report. Jasper 只使用数据源一次,如果您想对表格和图表使用相同的数据源(因为您想以两种不同的方式显示相同的数据),您必须为报表提供具有相同数据的两个不同数据源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM