diff options
Diffstat (limited to 'src/org/traccar/reports/Summary.java')
-rw-r--r-- | src/org/traccar/reports/Summary.java | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/src/org/traccar/reports/Summary.java b/src/org/traccar/reports/Summary.java index d4171f644..14f8b7839 100644 --- a/src/org/traccar/reports/Summary.java +++ b/src/org/traccar/reports/Summary.java @@ -16,17 +16,23 @@ */ package org.traccar.reports; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.sql.SQLException; +import java.util.ArrayList; import java.util.Collection; import java.util.Date; import javax.json.Json; import javax.json.JsonArrayBuilder; +import org.jxls.transform.poi.PoiTransformer; +import org.jxls.util.JxlsHelper; import org.traccar.Context; import org.traccar.model.Position; import org.traccar.reports.model.SummaryReport; -import org.traccar.web.CsvBuilder; import org.traccar.web.JsonConverter; public final class Summary { @@ -78,14 +84,23 @@ public final class Summary { return json.build().toString(); } - public static String getCsv(long userId, Collection<Long> deviceIds, Collection<Long> groupIds, - Date from, Date to) throws SQLException { - CsvBuilder csv = new CsvBuilder(); - csv.addHeaderLine(new SummaryReport()); + public static void getExcel(OutputStream outputStream, + long userId, Collection<Long> deviceIds, Collection<Long> groupIds, + Date from, Date to) throws SQLException, IOException { + ArrayList<SummaryReport> summaries = new ArrayList<>(); for (long deviceId: ReportUtils.getDeviceList(deviceIds, groupIds)) { Context.getPermissionsManager().checkDevice(userId, deviceId); - csv.addLine(calculateSummaryResult(deviceId, from, to)); + summaries.add(calculateSummaryResult(deviceId, from, to)); + } + String templatePath = Context.getConfig().getString("report.templatesPath", + "templates/export/"); + try (InputStream inputStream = new FileInputStream(templatePath + "/summary.xlsx")) { + org.jxls.common.Context jxlsContext = PoiTransformer.createInitialContext(); + jxlsContext.putVar("summaries", summaries); + jxlsContext.putVar("from", from); + jxlsContext.putVar("to", to); + JxlsHelper.getInstance().setUseFastFormulaProcessor(false) + .processTemplate(inputStream, outputStream, jxlsContext); } - return csv.build(); } } |