博客
关于我
开源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判断指定目录下是否存在文件
    查看>>
    php判断数组是否为空
    查看>>
    PHP判断数组是否有重复值、获取重复值
    查看>>
    springboot基于Web的社区留守儿童管理系统源码毕设+论文
    查看>>
    Springboot基于Redisson实现Redis分布式可重入锁【案例到源码分析】
    查看>>
    PHP利用正则表达式实现手机号码中间4位用星号(*)替换显示
    查看>>
    PHP加密与安全的最佳实践
    查看>>
    PHP加速器eaccelerator导致php-fpm进程卡死原因分析
    查看>>
    PHP区分 企业微信浏览器 | 普通微信浏览器 | 其他浏览器
    查看>>
    php原生代码怎么连表查询,PHP tp5中使用原生sql查询代码实例
    查看>>
    PHP去掉转义符
    查看>>
    php去除字符串开头或末尾的字符(例如逗号)
    查看>>
    php反射api
    查看>>
    PHP反射ReflectionClass、ReflectionMethod 入门教程
    查看>>
    PHP反射机制
    查看>>
    php取当天的最后一秒_Docker快速搭建PHP开发环境详细教程
    查看>>
    php取绝对值
    查看>>
    PHP变量内容的获取
    查看>>
    php各种常用的算法
    查看>>
    php各种缓存策略对比
    查看>>