use of org.traccar.reports.model.DeviceReport in project traccar by traccar.
the class Trips method getExcel.
public static void getExcel(OutputStream outputStream, long userId, Collection<Long> deviceIds, Collection<Long> groupIds, Date from, Date to) throws SQLException, IOException {
ReportUtils.checkPeriodLimit(from, to);
ArrayList<DeviceReport> devicesTrips = new ArrayList<>();
ArrayList<String> sheetNames = new ArrayList<>();
for (long deviceId : ReportUtils.getDeviceList(deviceIds, groupIds)) {
Context.getPermissionsManager().checkDevice(userId, deviceId);
Collection<TripReport> trips = detectTrips(deviceId, from, to);
DeviceReport deviceTrips = new DeviceReport();
Device device = Context.getIdentityManager().getById(deviceId);
deviceTrips.setDeviceName(device.getName());
sheetNames.add(WorkbookUtil.createSafeSheetName(deviceTrips.getDeviceName()));
if (device.getGroupId() != 0) {
Group group = Context.getGroupsManager().getById(device.getGroupId());
if (group != null) {
deviceTrips.setGroupName(group.getName());
}
}
deviceTrips.setObjects(trips);
devicesTrips.add(deviceTrips);
}
String templatePath = Context.getConfig().getString("report.templatesPath", "templates/export/");
try (InputStream inputStream = new FileInputStream(templatePath + "/trips.xlsx")) {
org.jxls.common.Context jxlsContext = ReportUtils.initializeContext(userId);
jxlsContext.putVar("devices", devicesTrips);
jxlsContext.putVar("sheetNames", sheetNames);
jxlsContext.putVar("from", from);
jxlsContext.putVar("to", to);
ReportUtils.processTemplateWithSheets(inputStream, outputStream, jxlsContext);
}
}
use of org.traccar.reports.model.DeviceReport in project traccar by tananaev.
the class Route method getExcel.
public static void getExcel(OutputStream outputStream, long userId, Collection<Long> deviceIds, Collection<Long> groupIds, Date from, Date to) throws StorageException, IOException {
ReportUtils.checkPeriodLimit(from, to);
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, to);
DeviceReport deviceRoutes = new DeviceReport();
Device device = Context.getIdentityManager().getById(deviceId);
deviceRoutes.setDeviceName(device.getName());
sheetNames.add(WorkbookUtil.createSafeSheetName(deviceRoutes.getDeviceName()));
if (device.getGroupId() != 0) {
Group group = Context.getGroupsManager().getById(device.getGroupId());
if (group != null) {
deviceRoutes.setGroupName(group.getName());
}
}
deviceRoutes.setObjects(positions);
devicesRoutes.add(deviceRoutes);
}
String templatePath = Context.getConfig().getString("report.templatesPath", "templates/export/");
try (InputStream inputStream = new FileInputStream(templatePath + "/route.xlsx")) {
org.jxls.common.Context jxlsContext = ReportUtils.initializeContext(userId);
jxlsContext.putVar("devices", devicesRoutes);
jxlsContext.putVar("sheetNames", sheetNames);
jxlsContext.putVar("from", from);
jxlsContext.putVar("to", to);
ReportUtils.processTemplateWithSheets(inputStream, outputStream, jxlsContext);
}
}
use of org.traccar.reports.model.DeviceReport in project traccar by tananaev.
the class Trips method getExcel.
public static void getExcel(OutputStream outputStream, long userId, Collection<Long> deviceIds, Collection<Long> groupIds, Date from, Date to) throws StorageException, IOException {
ReportUtils.checkPeriodLimit(from, to);
ArrayList<DeviceReport> devicesTrips = new ArrayList<>();
ArrayList<String> sheetNames = new ArrayList<>();
for (long deviceId : ReportUtils.getDeviceList(deviceIds, groupIds)) {
Context.getPermissionsManager().checkDevice(userId, deviceId);
Collection<TripReport> trips = detectTrips(deviceId, from, to);
DeviceReport deviceTrips = new DeviceReport();
Device device = Context.getIdentityManager().getById(deviceId);
deviceTrips.setDeviceName(device.getName());
sheetNames.add(WorkbookUtil.createSafeSheetName(deviceTrips.getDeviceName()));
if (device.getGroupId() != 0) {
Group group = Context.getGroupsManager().getById(device.getGroupId());
if (group != null) {
deviceTrips.setGroupName(group.getName());
}
}
deviceTrips.setObjects(trips);
devicesTrips.add(deviceTrips);
}
String templatePath = Context.getConfig().getString("report.templatesPath", "templates/export/");
try (InputStream inputStream = new FileInputStream(templatePath + "/trips.xlsx")) {
org.jxls.common.Context jxlsContext = ReportUtils.initializeContext(userId);
jxlsContext.putVar("devices", devicesTrips);
jxlsContext.putVar("sheetNames", sheetNames);
jxlsContext.putVar("from", from);
jxlsContext.putVar("to", to);
ReportUtils.processTemplateWithSheets(inputStream, outputStream, jxlsContext);
}
}
Aggregations