use of com.rebuild.core.service.datareport.EasyExcelGenerator 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.EasyExcelGenerator in project rebuild by getrebuild.
the class ReportsController method reportGenerate.
@RequestMapping({ "report/generate", "report/export" })
public void reportGenerate(@PathVariable String entity, @IdParam(name = "report") ID reportId, @IdParam(name = "record") ID recordId, HttpServletRequest request, HttpServletResponse response) throws IOException {
File file = new EasyExcelGenerator(reportId, recordId).generate();
String fileName = getReportName(entity, reportId, file);
if (ServletUtils.isAjaxRequest(request)) {
JSON data = JSONUtils.toJSONObject(new String[] { "fileKey", "fileName" }, new Object[] { file.getName(), fileName });
writeSuccess(response, data);
} else {
FileDownloader.downloadTempFile(response, file, fileName);
}
}
use of com.rebuild.core.service.datareport.EasyExcelGenerator in project rebuild by getrebuild.
the class ReportTemplateController method preview.
@GetMapping("/report-templates/preview")
public void preview(@IdParam ID reportId, HttpServletRequest request, HttpServletResponse response) throws IOException {
Object[] report = Application.createQueryNoFilter("select belongEntity 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 {
File template = DataReportManager.instance.getTemplateFile(entity, reportId);
file = new EasyExcelGenerator(template, (ID) random[0]).generate();
} catch (ConfigurationException ex) {
response.sendError(400, Language.L("未找到可供预览的记录"));
return;
}
FileDownloader.setDownloadHeaders(request, response, file.getName());
FileDownloader.writeLocalFile(file, response);
}
Aggregations