use of org.traccar.reports.model.DeviceReport in project traccar by traccar.
the class Stops 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> devicesStops = new ArrayList<>();
ArrayList<String> sheetNames = new ArrayList<>();
for (long deviceId : ReportUtils.getDeviceList(deviceIds, groupIds)) {
Context.getPermissionsManager().checkDevice(userId, deviceId);
Collection<StopReport> stops = detectStops(deviceId, from, to);
DeviceReport deviceStops = new DeviceReport();
Device device = Context.getIdentityManager().getById(deviceId);
deviceStops.setDeviceName(device.getName());
sheetNames.add(WorkbookUtil.createSafeSheetName(deviceStops.getDeviceName()));
if (device.getGroupId() != 0) {
Group group = Context.getGroupsManager().getById(device.getGroupId());
if (group != null) {
deviceStops.setGroupName(group.getName());
}
}
deviceStops.setObjects(stops);
devicesStops.add(deviceStops);
}
String templatePath = Context.getConfig().getString("report.templatesPath", "templates/export/");
try (InputStream inputStream = new FileInputStream(templatePath + "/stops.xlsx")) {
org.jxls.common.Context jxlsContext = ReportUtils.initializeContext(userId);
jxlsContext.putVar("devices", devicesStops);
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 traccar.
the class Events method getExcel.
public static void getExcel(OutputStream outputStream, long userId, Collection<Long> deviceIds, Collection<Long> groupIds, Collection<String> types, Date from, Date to) throws SQLException, IOException {
ReportUtils.checkPeriodLimit(from, to);
ArrayList<DeviceReport> devicesEvents = new ArrayList<>();
ArrayList<String> sheetNames = new ArrayList<>();
HashMap<Long, String> geofenceNames = new HashMap<>();
for (long deviceId : ReportUtils.getDeviceList(deviceIds, groupIds)) {
Context.getPermissionsManager().checkDevice(userId, deviceId);
Collection<Event> events = Context.getDataManager().getEvents(deviceId, from, to);
boolean all = types.isEmpty() || types.contains(Event.ALL_EVENTS);
for (Iterator<Event> iterator = events.iterator(); iterator.hasNext(); ) {
Event event = iterator.next();
if (all || types.contains(event.getType())) {
long geofenceId = event.getGeofenceId();
if (geofenceId != 0) {
if (Context.getGeofenceManager().checkItemPermission(userId, geofenceId)) {
Geofence geofence = Context.getGeofenceManager().getById(geofenceId);
if (geofence != null) {
geofenceNames.put(geofenceId, geofence.getName());
}
} else {
iterator.remove();
}
}
} else {
iterator.remove();
}
}
DeviceReport deviceEvents = new DeviceReport();
Device device = Context.getIdentityManager().getById(deviceId);
deviceEvents.setDeviceName(device.getName());
sheetNames.add(WorkbookUtil.createSafeSheetName(deviceEvents.getDeviceName()));
if (device.getGroupId() != 0) {
Group group = Context.getGroupsManager().getById(device.getGroupId());
if (group != null) {
deviceEvents.setGroupName(group.getName());
}
}
deviceEvents.setObjects(events);
devicesEvents.add(deviceEvents);
}
String templatePath = Context.getConfig().getString("report.templatesPath", "templates/export/");
try (InputStream inputStream = new FileInputStream(templatePath + "/events.xlsx")) {
org.jxls.common.Context jxlsContext = ReportUtils.initializeContext(userId);
jxlsContext.putVar("devices", devicesEvents);
jxlsContext.putVar("sheetNames", sheetNames);
jxlsContext.putVar("geofenceNames", geofenceNames);
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 Stops 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> devicesStops = new ArrayList<>();
ArrayList<String> sheetNames = new ArrayList<>();
for (long deviceId : ReportUtils.getDeviceList(deviceIds, groupIds)) {
Context.getPermissionsManager().checkDevice(userId, deviceId);
Collection<StopReport> stops = detectStops(deviceId, from, to);
DeviceReport deviceStops = new DeviceReport();
Device device = Context.getIdentityManager().getById(deviceId);
deviceStops.setDeviceName(device.getName());
sheetNames.add(WorkbookUtil.createSafeSheetName(deviceStops.getDeviceName()));
if (device.getGroupId() != 0) {
Group group = Context.getGroupsManager().getById(device.getGroupId());
if (group != null) {
deviceStops.setGroupName(group.getName());
}
}
deviceStops.setObjects(stops);
devicesStops.add(deviceStops);
}
String templatePath = Context.getConfig().getString("report.templatesPath", "templates/export/");
try (InputStream inputStream = new FileInputStream(templatePath + "/stops.xlsx")) {
org.jxls.common.Context jxlsContext = ReportUtils.initializeContext(userId);
jxlsContext.putVar("devices", devicesStops);
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 Events method getExcel.
public static void getExcel(OutputStream outputStream, long userId, Collection<Long> deviceIds, Collection<Long> groupIds, Collection<String> types, Date from, Date to) throws StorageException, IOException {
ReportUtils.checkPeriodLimit(from, to);
ArrayList<DeviceReport> devicesEvents = new ArrayList<>();
ArrayList<String> sheetNames = new ArrayList<>();
HashMap<Long, String> geofenceNames = new HashMap<>();
HashMap<Long, String> maintenanceNames = new HashMap<>();
for (long deviceId : ReportUtils.getDeviceList(deviceIds, groupIds)) {
Context.getPermissionsManager().checkDevice(userId, deviceId);
Collection<Event> events = Context.getDataManager().getEvents(deviceId, from, to);
boolean all = types.isEmpty() || types.contains(Event.ALL_EVENTS);
for (Iterator<Event> iterator = events.iterator(); iterator.hasNext(); ) {
Event event = iterator.next();
if (all || types.contains(event.getType())) {
long geofenceId = event.getGeofenceId();
long maintenanceId = event.getMaintenanceId();
if (geofenceId != 0) {
if (Context.getGeofenceManager().checkItemPermission(userId, geofenceId)) {
Geofence geofence = Context.getGeofenceManager().getById(geofenceId);
if (geofence != null) {
geofenceNames.put(geofenceId, geofence.getName());
}
} else {
iterator.remove();
}
} else if (maintenanceId != 0) {
if (Context.getMaintenancesManager().checkItemPermission(userId, maintenanceId)) {
Maintenance maintenance = Context.getMaintenancesManager().getById(maintenanceId);
if (maintenance != null) {
maintenanceNames.put(maintenanceId, maintenance.getName());
}
} else {
iterator.remove();
}
}
} else {
iterator.remove();
}
}
DeviceReport deviceEvents = new DeviceReport();
Device device = Context.getIdentityManager().getById(deviceId);
deviceEvents.setDeviceName(device.getName());
sheetNames.add(WorkbookUtil.createSafeSheetName(deviceEvents.getDeviceName()));
if (device.getGroupId() != 0) {
Group group = Context.getGroupsManager().getById(device.getGroupId());
if (group != null) {
deviceEvents.setGroupName(group.getName());
}
}
deviceEvents.setObjects(events);
devicesEvents.add(deviceEvents);
}
String templatePath = Context.getConfig().getString("report.templatesPath", "templates/export/");
try (InputStream inputStream = new FileInputStream(templatePath + "/events.xlsx")) {
org.jxls.common.Context jxlsContext = ReportUtils.initializeContext(userId);
jxlsContext.putVar("devices", devicesEvents);
jxlsContext.putVar("sheetNames", sheetNames);
jxlsContext.putVar("geofenceNames", geofenceNames);
jxlsContext.putVar("maintenanceNames", maintenanceNames);
jxlsContext.putVar("from", from);
jxlsContext.putVar("to", to);
ReportUtils.processTemplateWithSheets(inputStream, outputStream, jxlsContext);
}
}
use of org.traccar.reports.model.DeviceReport in project traccar by traccar.
the class Route 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> 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);
}
}
Aggregations