Search in sources :

Example 1 with EasyExcelListGenerator

use of com.rebuild.core.service.datareport.EasyExcelListGenerator in project rebuild by getrebuild.

the class ReportTemplateController method preview.

@GetMapping("/report-templates/preview")
public void preview(@IdParam ID reportId, HttpServletResponse response) throws IOException {
    Object[] report = Application.createQueryNoFilter("select belongEntity,templateType from DataReportConfig where configId = ?").setParameter(1, reportId).unique();
    Entity entity = MetadataHelper.getEntity((String) report[0]);
    String sql = String.format("select %s from %s order by modifiedOn desc", entity.getPrimaryField().getName(), entity.getName());
    Object[] random = Application.createQueryNoFilter(sql).unique();
    if (random == null) {
        response.sendError(400, Language.L("未找到可供预览的记录"));
        return;
    }
    File file;
    try {
        // 列表报表
        if (ObjectUtils.toInt(report[1]) == DataReportManager.TYPE_LIST) {
            JSONObject queryData = JSONUtils.toJSONObject(new String[] { "pageSize", "entity" }, new Object[] { 2, report[0] });
            file = new EasyExcelListGenerator(reportId, queryData).generate();
        } else {
            file = new EasyExcelGenerator(reportId, (ID) random[0]).generate();
        }
    } catch (ConfigurationException ex) {
        response.sendError(500, ex.getLocalizedMessage());
        return;
    }
    FileDownloader.downloadTempFile(response, file, null);
}
Also used : Entity(cn.devezhao.persist4j.Entity) JSONObject(com.alibaba.fastjson.JSONObject) ConfigurationException(com.rebuild.core.configuration.ConfigurationException) JSONObject(com.alibaba.fastjson.JSONObject) EasyExcelListGenerator(com.rebuild.core.service.datareport.EasyExcelListGenerator) File(java.io.File) EasyExcelGenerator(com.rebuild.core.service.datareport.EasyExcelGenerator) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 2 with EasyExcelListGenerator

use of com.rebuild.core.service.datareport.EasyExcelListGenerator in project rebuild by getrebuild.

the class DataExporter method export.

/**
 * 通过模板导出
 *
 * @param useReport
 * @return
 * @see com.rebuild.core.service.datareport.EasyExcelListGenerator
 */
public File export(ID useReport) {
    if (useReport == null) {
        File tmp = RebuildConfiguration.getFileOfTemp(String.format("RBEXPORT-%d.csv", System.currentTimeMillis()));
        exportCsv(tmp);
        return tmp;
    } else {
        EasyExcelListGenerator generator = new EasyExcelListGenerator(useReport, this.queryData);
        generator.setUser(getUser());
        File file = generator.generate();
        count = generator.getExportCount();
        return file;
    }
}
Also used : EasyExcelListGenerator(com.rebuild.core.service.datareport.EasyExcelListGenerator)

Aggregations

EasyExcelListGenerator (com.rebuild.core.service.datareport.EasyExcelListGenerator)2 Entity (cn.devezhao.persist4j.Entity)1 JSONObject (com.alibaba.fastjson.JSONObject)1 ConfigurationException (com.rebuild.core.configuration.ConfigurationException)1 EasyExcelGenerator (com.rebuild.core.service.datareport.EasyExcelGenerator)1 File (java.io.File)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1