博客
关于我
开源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/

    你可能感兴趣的文章
    python前端之css
    查看>>
    Python制作进度条,原来有这么多方法
    查看>>
    Python制作简单的学生成绩管理系统
    查看>>
    python制作甘特图的基本知识(附Demo)
    查看>>
    python制作一个简单的服务器,【Python】 做一个简单的 http 服务器
    查看>>
    Python到底能做什么?它的优点在哪?
    查看>>
    python利用pytorch库导出图像分割算子
    查看>>
    python利用pyshark监听网卡来抓包其中pyshark中摸索的一些可用参数
    查看>>
    python利用excel分析过杀漏失
    查看>>
    python判断汉字数目
    查看>>
    python判断文件是空的,如果是空的,就删除
    查看>>
    python判断密码是否正确_python密码判断是否符合要求的方法
    查看>>
    python判断字符串包含中文_Python 判断字符串是否包含中文
    查看>>
    python删除第一行_Python 乱码指北:一行删掉根目录
    查看>>
    Python删除列表元素的三种方法
    查看>>
    python初步学习-python数据类型-集合(set)
    查看>>
    python列表生成字典_Python中将字典转换为列表的方法
    查看>>
    python列表对应元素合并为列表及判断一个列表是几维
    查看>>
    python列表去重复后按照顺序_从包含不可共元素的Python列表中删除重复元素,同时保留顺序?...
    查看>>
    python列表前几个_python之列表
    查看>>