博客
关于我
开源UReport 整合到产品中实践简要:(四)UReport 自定义mysql数据库表的存储器
阅读量:566 次
发布时间:2019-03-09

本文共 4361 字,大约阅读时间需要 14 分钟。

UReport2报表存储机制文档

一、默认报表存储器

UReport2默认提供的"服务器文件系统"报表存储机制,实际上通过实现ReportProvider接口来实现。该接口定义了报表文件的基本操作方法,具体如下:

public interface ReportProvider {    InputStream loadReport(String file);    void deleteReport(String file);    List
getReportFiles(); void saveReport(String file, String content); String getName(); boolean disabled(); String getPrefix();}

实现ReportProvider接口后,只需将实现类配置到Spring中,便可使UReport2检测并加载该存储器。

二、自定义MySQL报表存储器

要定义自定义报表存储器,需实现ReportProvider接口,并将实现类配置到Spring中。同时,需设计相应的数据库表结构。以下是一个示例表结构(ID为雪花主键):

sys_ureportfile (    id                 UUID,    reportname         VARCHAR(255),    xmlcontent         BLOB,    gmt_create         DATETIME,    gmt_modified       DATETIME,    primary key (id))

三、代码结构

将UReport2的默认存储器和自定义存储器(如MySQL存储器)放在同一个模块中,形成UReport报表公用模块。

以下是一个实现ReportProvider的MySQL存储器类:

package com.zjm.gwork.ureport.reportProvider.provider;import com.bstek.ureport.provider.report.ReportFile;import com.bstek.ureport.provider.report.ReportProvider;import com.zjm.gwork.ureport.reportProvider.model.SysUreportfile;import com.zjm.gwork.ureport.reportProvider.service.UReportFileService;import com.zjm.gwork.utils.KeyWorker;import lombok.Setter;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.boot.context.properties.ConfigurationProperties;import org.springframework.stereotype.Component;import java.io.ByteArrayInputStream;import java.io.InputStream;import java.io.UnsupportedEncodingException;import java.util.ArrayList;import java.util.List;import java.util.UUID;@Component("mysql-provider")public class MySQLProvider implements ReportProvider {    private static final String NAME = "mysql-provider";    private String prefix = "mysql:";    private boolean disabled = false;    @Autowired    private UReportFileService uReportFileService;    @Override    public InputStream loadReport(String file) {        SysUreportfile ureportFileEntity = uReportFileService.getReportFileByName(getCorrectName(file));        byte[] content = ureportFileEntity.getXmlcontent();        return new ByteArrayInputStream(content);    }    @Override    public void deleteReport(String file) {        uReportFileService.removeReportFileByName(getCorrectName(file));    }    @Override    public List
getReportFiles() { List
list = uReportFileService.listAllReportFile(); List
reportList = new ArrayList<>(); for (SysUreportfile ureportFileEntity : list) { reportList.add(new ReportFile(ureportFileEntity.getReportname(), ureportFileEntity.getGmtModified())); } return reportList; } @Override public void saveReport(String file, String content) { file = getCorrectName(file); SysUreportfile ureportFileEntity = uReportFileService.getReportFileByName(file); Date currentDate = new Date(); if (ureportFileEntity == null) { ureportFileEntity = new SysUreportfile(); ureportFileEntity.setId(KeyWorker.getInstance().getNextId()); ureportFileEntity.setReportname(file); ureportFileEntity.setXmlcontent(content.getBytes()); ureportFileEntity.setGmtCreate(currentDate); ureportFileEntity.setGmtModified(currentDate); uReportFileService.saveReportFile(ureportFileEntity); } else { ureportFileEntity.setXmlcontent(content.getBytes()); ureportFileEntity.setGmtModified(currentDate); uReportFileService.updateReportFile(ureportFileEntity); } } @Override public String getName() { return NAME; } @Override public boolean disabled() { return disabled; } @Override public String getPrefix() { return prefix; } private String getCorrectName(String name) { if (name.startsWith(prefix)) { name = name.substring(prefix.length(), name.length()); } return name; }}

四、配置说明

要禁用默认报表存储器,可通过配置文件设置ureport.disableFileProvider=true。配置文件内容如下:

ureport.disableHttpSessionReportCache=falseureport.disableFileProvider=trueureport.fileStoreDir=/WEB-INF/ureportfilesureport.debug=true

五、使用说明

  • 实现ReportProvider接口的类需标注@Component,并配置在Spring中。
  • 默认存储器可通过ReportProviderLoader自动发现。
  • 自定义存储器需在配置中指定前缀,例如ureport.mysql.provider.prefix=mysql:
  • 通过以上配置和实现,可以灵活管理UReport2的报表存储机制。

    转载地址:http://qfrpz.baihongyu.com/

    你可能感兴趣的文章
    PHP数据访问的多重查询(租房子查询)
    查看>>
    RabbitMQ - 如保证消息的可靠性?(消息确认、消息持久化、失败重试机制)
    查看>>
    RabbitMQ - 基于 SpringAMQP 带你实现五种消息队列模型
    查看>>
    php数组函数分析--array_column
    查看>>
    php数组去重复数据的小例子
    查看>>
    php数组实现:哈希 +双向链表
    查看>>
    PHP数组排序函数array_multisort()函数详解(二)
    查看>>
    php数组的几个函数和超全局变量
    查看>>
    PHP文件上传详解
    查看>>
    PHP文件锁
    查看>>
    php文本框输入制定文本,php – 当用户没有向文本框输入任何内容时...
    查看>>
    PHP时间戳和日期相互转换操作总结
    查看>>
    php时间戳知识点,php 时间戳函数总结与示例
    查看>>
    php更新数据库失败,php – 无法更新MySQL数据库
    查看>>
    php机器人聊天对话框,基于AIML的PHP聊天机器人
    查看>>
    PHP查找数组中最大值与最小值
    查看>>
    php查最大值,在PHP数组中查找最大值
    查看>>
    php标签筛选,关于PHP CodeIgniter框架中通过<a>标签和url做多条件分类筛选
    查看>>
    php根据年月日计算年龄
    查看>>
    RabbitMQ - 单机部署(超详细)
    查看>>