diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2017-03-16 19:01:05 +1300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-16 19:01:05 +1300 |
commit | 308d00b7f72b7455c58a98013fff06e227360097 (patch) | |
tree | 55367dae3f7e85c65432dfbf91adc4496df16254 /src/org/traccar/reports/Route.java | |
parent | 2f782faaf27ffdae3753e06a6386c1cd49b2ed16 (diff) | |
parent | f7a668371769a7b4c176e57626f23314e3838e1c (diff) | |
download | trackermap-server-308d00b7f72b7455c58a98013fff06e227360097.tar.gz trackermap-server-308d00b7f72b7455c58a98013fff06e227360097.tar.bz2 trackermap-server-308d00b7f72b7455c58a98013fff06e227360097.zip |
Merge pull request #3011 from Abyss777/reports_timezone
Use timezone from preferences for excel reports
Diffstat (limited to 'src/org/traccar/reports/Route.java')
-rw-r--r-- | src/org/traccar/reports/Route.java | 29 |
1 files changed, 4 insertions, 25 deletions
diff --git a/src/org/traccar/reports/Route.java b/src/org/traccar/reports/Route.java index c1acaf322..aa6b7105b 100644 --- a/src/org/traccar/reports/Route.java +++ b/src/org/traccar/reports/Route.java @@ -24,17 +24,8 @@ import java.sql.SQLException; import java.util.ArrayList; import java.util.Collection; import java.util.Date; -import java.util.List; import org.apache.poi.ss.util.WorkbookUtil; -import org.joda.time.DateTime; -import org.jxls.area.Area; -import org.jxls.builder.xls.XlsCommentAreaBuilder; -import org.jxls.common.CellRef; -import org.jxls.formula.StandardFormulaProcessor; -import org.jxls.transform.Transformer; -import org.jxls.transform.poi.PoiTransformer; -import org.jxls.util.TransformerFactory; import org.traccar.Context; import org.traccar.model.Device; import org.traccar.model.Group; @@ -58,13 +49,13 @@ public final class Route { public static void getExcel(OutputStream outputStream, long userId, Collection<Long> deviceIds, Collection<Long> groupIds, - DateTime from, DateTime to) throws SQLException, IOException { + Date from, Date to) throws SQLException, IOException { ArrayList<DeviceReport> devicesRoutes = new ArrayList<>(); ArrayList<String> sheetNames = new ArrayList<>(); for (long deviceId: ReportUtils.getDeviceList(deviceIds, groupIds)) { Context.getPermissionsManager().checkDevice(userId, deviceId); Collection<Position> positions = Context.getDataManager() - .getPositions(deviceId, from.toDate(), to.toDate()); + .getPositions(deviceId, from, to); DeviceReport deviceRoutes = new DeviceReport(); Device device = Context.getIdentityManager().getDeviceById(deviceId); deviceRoutes.setDeviceName(device.getName()); @@ -81,24 +72,12 @@ public final class Route { String templatePath = Context.getConfig().getString("report.templatesPath", "templates/export/"); try (InputStream inputStream = new FileInputStream(templatePath + "/route.xlsx")) { - org.jxls.common.Context jxlsContext = PoiTransformer.createInitialContext(); + org.jxls.common.Context jxlsContext = ReportUtils.initializeContext(userId); jxlsContext.putVar("devices", devicesRoutes); jxlsContext.putVar("sheetNames", sheetNames); jxlsContext.putVar("from", from); jxlsContext.putVar("to", to); - jxlsContext.putVar("distanceUnit", ReportUtils.getDistanceUnit(userId)); - jxlsContext.putVar("speedUnit", ReportUtils.getSpeedUnit(userId)); - jxlsContext.putVar("timezone", from.getZone()); - jxlsContext.putVar("bracketsRegex", "[\\{\\}\"]"); - Transformer transformer = TransformerFactory.createTransformer(inputStream, outputStream); - List<Area> xlsAreas = new XlsCommentAreaBuilder(transformer).build(); - for (Area xlsArea : xlsAreas) { - xlsArea.applyAt(new CellRef(xlsArea.getStartCellRef().getCellName()), jxlsContext); - xlsArea.setFormulaProcessor(new StandardFormulaProcessor()); - xlsArea.processFormulas(); - } - transformer.deleteSheet(xlsAreas.get(0).getStartCellRef().getSheetName()); - transformer.write(); + ReportUtils.processTemplateWithSheets(inputStream, outputStream, jxlsContext); } } } |