使用 Jaspersoft Studio 设计报表样式

用你熟悉的环境设计一套最简单的模板,名称定义为: Reports.jrxml
report_template.png
下载源文件:report.jrxml

  • 语法比较特殊,需要努力学习
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="report1" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="84feeac3-d1f7-4503-84bf-fc3fa153df55">
    <queryString>
        <![CDATA[]]>
    </queryString>
    <field name="id" class="java.lang.Long"/>
    <field name="price" class="java.math.BigDecimal"/>
    <field name="quantity" class="java.lang.Integer"/>
    <field name="categoryName" class="java.lang.String"/>
    <field name="name" class="java.lang.String"/>
    <background>
        <band splitType="Stretch"/>
    </background>
    <title>
        <band height="36" splitType="Stretch"/>
    </title>
    <pageHeader>
        <band height="49" splitType="Stretch">
            <staticText>
                <reportElement x="170" y="10" width="230" height="30" uuid="04d35299-5eb0-4a34-b340-3ca5cf8290fc"/>
                <textElement>
                    <font fontName="宋体" size="20"/>
                </textElement>
                <text><![CDATA[Product List | 产品列表]]></text>
            </staticText>
        </band>
    </pageHeader>
    <columnHeader>
        <band height="37" splitType="Stretch">
            <staticText>
                <reportElement x="0" y="10" width="70" height="20" uuid="bcaf85c0-57ff-4a34-af27-cbf1330125ae"/>
                <textElement>
                    <font fontName="宋体" isBold="true"/>
                </textElement>
                <text><![CDATA[ID]]></text>
            </staticText>
            <staticText>
                <reportElement x="90" y="10" width="100" height="20" uuid="faf9b9ee-7cf2-4ea5-80b8-d371c3c753b9"/>
                <textElement>
                    <font fontName="宋体" isBold="true"/>
                </textElement>
                <text><![CDATA[名称]]></text>
            </staticText>
            <staticText>
                <reportElement x="210" y="10" width="70" height="20" uuid="93727672-9f69-4856-aa26-33837e8dc417"/>
                <textElement>
                    <font fontName="宋体" isBold="true"/>
                </textElement>
                <text><![CDATA[价格]]></text>
            </staticText>
            <staticText>
                <reportElement x="314" y="10" width="70" height="20" uuid="09b47abe-09b2-479a-bb76-9770e361a23c"/>
                <textElement>
                    <font fontName="宋体" isBold="true"/>
                </textElement>
                <text><![CDATA[数量]]></text>
            </staticText>
            <staticText>
                <reportElement x="410" y="10" width="100" height="20" uuid="c258f47b-da6a-418d-a5e0-892388ec65c5"/>
                <textElement>
                    <font fontName="宋体" isBold="true"/>
                </textElement>
                <text><![CDATA[类别]]></text>
            </staticText>
        </band>
    </columnHeader>
    <detail>
        <band height="39" splitType="Stretch">
            <textField>
                <reportElement x="0" y="4" width="70" height="16" uuid="99fa4c16-cfe2-4482-828e-4439abb9e8f0"/>
                <textFieldExpression><![CDATA[$F{id}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="210" y="4" width="70" height="16" uuid="ba6e9cfa-6d4c-470b-8bc4-eb2e3411c21e"/>
                <textFieldExpression><![CDATA[$F{price}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="310" y="4" width="70" height="16" uuid="447253d3-d268-4873-b0b7-9c174c6a7c9f"/>
                <textFieldExpression><![CDATA[$F{quantity}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="410" y="4" width="100" height="16" uuid="8992d0ad-1f5e-4210-b50b-1e29dc66f119"/>
                <textFieldExpression><![CDATA[$F{categoryName}]]></textFieldExpression>
            </textField>
            <line>
                <reportElement x="-3" y="27" width="521" height="1" uuid="9b493a65-a499-4199-90bb-b3fedbe45f85"/>
            </line>
            <textField>
                <reportElement x="90" y="4" width="100" height="16" uuid="fcdd8979-dc44-46e3-be56-11e5f33b8e0c">
                    <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="73fad7b3-74b5-4436-bd46-d2b9c3c113fd"/>
                </reportElement>
                <textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
    <columnFooter>
        <band height="45" splitType="Stretch"/>
    </columnFooter>
    <pageFooter>
        <band height="54" splitType="Stretch"/>
    </pageFooter>
    <summary>
        <band height="42" splitType="Stretch"/>
    </summary>
</jasperReport>

新建 Spring Boot 项目

  • 新建 Spring Boot 项目,不多说
    需包含的内容比较特殊,pom.xml,jasperreports 是依赖包,jasperreports-fonts 是字体支持包
        <dependency>
            <groupId>net.sf.jasperreports</groupId>
            <artifactId>jasperreports</artifactId>
            <version>6.15.0</version>
        </dependency>
        <dependency>
            <groupId>net.sf.jasperreports</groupId>
            <artifactId>jasperreports-fonts</artifactId>
            <version>6.15.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-support</artifactId>
            <version>2.0.8</version>
        </dependency>
  • 新建各种类
    controller, domain, repository, service, 其他,大概目录结构如下

report2.png

  • 创建 Postgresql 数据表
CREATE TABLE public.product
(
    id bigint NOT NULL,
    name character varying(255) COLLATE pg_catalog."default",
    price numeric,
    quantity integer,
    category_name character varying(255) COLLATE pg_catalog."default",
    CONSTRAINT product_pkey PRIMARY KEY (id)
)

集成 JasperReports 到 Spring Boot 项目

中文支持文章:Spring Boot 集成 JasperReports,并支持中文PDF

  • Service 服务层处理要求
@RequestMapping(value = "/report", method = RequestMethod.GET)
    public void report(HttpServletResponse response, @RequestParam(name = "type", defaultValue = "pdf") String type) throws Exception {

        JRBeanCollectionDataSource dataSource = new JRBeanCollectionDataSource(productService.report());
        InputStream inputStream = this.getClass().getResourceAsStream("/report_templates/report.jrxml");
        JasperReport jasperReport = JasperCompileManager.compileReport(inputStream);
        JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null, dataSource);

        switch (type) {
        case "html":
            response.setContentType("text/html;charset=utf-8");
            HtmlExporter exporter = new HtmlExporter(DefaultJasperReportsContext.getInstance());
            exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
            exporter.setExporterOutput(new SimpleHtmlExporterOutput(response.getWriter()));
            exporter.exportReport();
            break;

        case "pdf":

        default:
            JRPdfExporter exporterPdf = new JRPdfExporter();
            exporterPdf.setExporterInput(new SimpleExporterInput(jasperPrint));
            OutputStream outputStream = response.getOutputStream();
            exporterPdf.setExporterOutput(new SimpleOutputStreamExporterOutput(outputStream));
            exporterPdf.exportReport();
            break;
        }

    }
  • 可以是 HTML 版本
    r1.png
  • 也可以是 PDF 版本
    r2.png

源码下载: https://github.com/jiekechoo/YiqisoftReport

  • 新建 docker-compose.yml
version: '2'
services:
  web:
    image: odoo:14.0
    depends_on:
      - db
    ports:
      - "8069:8069"
    volumes:
      - odoo-web-data:/var/lib/odoo
      - ./config:/etc/odoo
      - ./addons:/mnt/extra-addons
  db:
    image: postgres:10
    environment:
      - POSTGRES_DB=postgres
      - POSTGRES_PASSWORD=odoo
      - POSTGRES_USER=odoo
      - PGDATA=/var/lib/postgresql/data/pgdata
    volumes:
      - odoo-db-data:/var/lib/postgresql/data/pgdata
volumes:
  odoo-web-data:
  odoo-db-data:
  • 启动 docker
docker-compose up -d
<VirtualHost *:80>
    DocumentRoot "/var/www/html/odoo.cn"
    ServerName www.odoo.cn
    RewriteEngine on
    RewriteCond %{SERVER_PORT} !^443$
    RewriteRule ^(.*)$ https://%{SERVER_NAME}$1 [L,R]
    <Directory "/var/www/html/odoo.cn">
        allow from all
        Options None
        Require all granted
    </Directory>
</VirtualHost>
<VirtualHost *:443>
    DocumentRoot "/var/www/html/odoo.cn"
    ServerName www.odoo.cn
    RewriteEngine on
    <Directory "/var/www/html/odoo.cn">
        allow from all
        Options FollowSymLinks
        Require all granted
        AllowOverride All 
    </Directory>
    SSLEngine on
    SSLCertificateFile /etc/httpd/conf.d/www.odoo.cn_public.crt
    SSLCertificateKeyFile /etc/httpd/conf.d/www.odoo.cn.key
    SSLCertificateChainFile /etc/httpd/conf.d/www.odoo.cn_chain.crt
    ProxyRequests Off
    ProxyPreserveHost On
    ProxyPass / http://127.0.0.1:8069/
    ProxyPassReverse / http://127.0.0.1:8069/
    ProxyErrorOverride off
</VirtualHost>
  • 打开浏览器 http://www.odoo.cn ,直接访问域名,注意要使用 https 需申请域名 ssl 证书

产品特性

YiAIR-86-印刷-2.png

  • 无线远传:NB-IoT全网通
  • 干电池供电:2节AA电池(5号)
  • 静态功耗:< 20uA,可用1年*
  • 温/湿度精度:±0.2℃/±3%
  • 私有化 IoT 平台:多租户管理
  • 尺寸:86 x 86 x 30mm

适用范围

  • 供暖、冷链、厂房、仓库
  • 办公室、会议室、学校、幼儿园
  • 酒店、医院、商场、咖啡厅
  • 酒吧、餐馆、地铁、地下室

多租户

多租户.png

仪表板

dashboard.png

  • 编辑 docker-compose.yml
version: "3.7"
services:
  db:
    image: postgres:11.6
    restart: always
    environment:
      POSTGRES_DB: postgres
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
      PGDATA: /var/lib/postgresql/data
    volumes:
      - db-data:/var/lib/postgresql/data
    ports:
      - "5432:5432"
 
  pgadmin:
    image: dpage/pgadmin4
    restart: always
    environment:
      PGADMIN_DEFAULT_EMAIL: admin@yiqisoft.cn
      PGADMIN_DEFAULT_PASSWORD: talent
      PGADMIN_LISTEN_PORT: 80
    ports:
      - "8088:80"
    volumes:
      - pgadmin-data:/var/lib/pgadmin
    links:
      - "db:pgsql-server"
volumes:
  db-data:
  pgadmin-data:

注意:文件保存在本地 volumes 中,如果需要再次使用,请保存!

  • 启动
docker-compose up -d
  • 登录 pgAdmin 4

打开本地浏览器 http://localhost:8080 , 使用用户名 admin@yiqisoft.cn 和密码 talent 登录

假设 ThingsBoard 以 docker 方式运行,需要通过反向映射来提供服务,为了加强安全性,用 https 和 wss,但是,wss 映射需要注意最后几行配置。

<VirtualHost *>
    DocumentRoot /var/www/iot
    ServerName iot.domain
    RewriteEngine on
    RewriteCond %{SERVER_PORT} !^443$
    RewriteRule ^(.*)$ https://%{SERVER_NAME}$1 [L,R]

    <Directory /var/www/iot>
        allow from all
        Options None
        Require all granted
    </Directory>
</VirtualHost>
<VirtualHost *:443>
    DocumentRoot "/var/www/iot"
    ServerName iot.doamin
    <Directory "/var/www/iot">
    allow from all
    Options FollowSymLinks
    Require all granted
    AllowOverride All 
    </Directory>
    SSLEngine on
    SSLCertificateFile /etc/httpd/conf.d/server.crt
    SSLCertificateKeyFile /etc/httpd/conf.d/server.key
    SSLCertificateChainFile /etc/httpd/conf.d/ca.crt

    ProxyPreserveHost On
    ProxyPass / http://127.0.0.1:8088/
    ProxyPassReverse / http://127.0.0.1:8088/
    ProxyPass /api/ws ws://127.0.0.1:8088/
    ProxyPassReverse /api/ws ws://127.0.0.1:8088/

    RewriteEngine on
    RewriteCond %{HTTP:Upgrade} =websocket [NC]
    RewriteRule /(.*) ws://127.0.0.1:8088/$1 [P,L]
</VirtualHost>