aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/reports/Summary.java
diff options
context:
space:
mode:
authorAbyss777 <abyss@fox5.ru>2016-10-17 14:02:23 +0500
committerAbyss777 <abyss@fox5.ru>2016-10-17 14:02:23 +0500
commitc613143105d9f7c898dd3fb236d683b76cf8a42c (patch)
tree0facff2ac16b5d0067fc651fd5024aa2b668ebaf /src/org/traccar/reports/Summary.java
parent83ca0476167d91f16f18ae3cc532d56cd97f743e (diff)
downloadtrackermap-server-c613143105d9f7c898dd3fb236d683b76cf8a42c.tar.gz
trackermap-server-c613143105d9f7c898dd3fb236d683b76cf8a42c.tar.bz2
trackermap-server-c613143105d9f7c898dd3fb236d683b76cf8a42c.zip
- Implement export reports to excel
- Migrate csv export to /api/positions
Diffstat (limited to 'src/org/traccar/reports/Summary.java')
-rw-r--r--src/org/traccar/reports/Summary.java29
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..e7f41bcd6 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.summary.template.excel",
+ "templates/export/summary.xlsx");
+ try (InputStream inputStream = new FileInputStream(templatePath)) {
+ 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();
}
}