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);
}
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;
}
}
Aggregations