Search in sources :

Example 1 with DeviceReport

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);
    }
}
Also used : Group(org.traccar.model.Group) Device(org.traccar.model.Device) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) StopReport(org.traccar.reports.model.StopReport) FileInputStream(java.io.FileInputStream) DeviceReport(org.traccar.reports.model.DeviceReport)

Example 2 with DeviceReport

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);
    }
}
Also used : Group(org.traccar.model.Group) HashMap(java.util.HashMap) Device(org.traccar.model.Device) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) FileInputStream(java.io.FileInputStream) Event(org.traccar.model.Event) DeviceReport(org.traccar.reports.model.DeviceReport) Geofence(org.traccar.model.Geofence)

Example 3 with DeviceReport

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);
    }
}
Also used : Group(org.traccar.model.Group) Device(org.traccar.model.Device) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) StopReport(org.traccar.reports.model.StopReport) FileInputStream(java.io.FileInputStream) DeviceReport(org.traccar.reports.model.DeviceReport)

Example 4 with DeviceReport

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);
    }
}
Also used : Group(org.traccar.model.Group) HashMap(java.util.HashMap) Device(org.traccar.model.Device) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) Maintenance(org.traccar.model.Maintenance) FileInputStream(java.io.FileInputStream) Event(org.traccar.model.Event) DeviceReport(org.traccar.reports.model.DeviceReport) Geofence(org.traccar.model.Geofence)

Example 5 with DeviceReport

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);
    }
}
Also used : Group(org.traccar.model.Group) Position(org.traccar.model.Position) Device(org.traccar.model.Device) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) FileInputStream(java.io.FileInputStream) DeviceReport(org.traccar.reports.model.DeviceReport)

Aggregations

FileInputStream (java.io.FileInputStream)8 InputStream (java.io.InputStream)8 ArrayList (java.util.ArrayList)8 Device (org.traccar.model.Device)8 Group (org.traccar.model.Group)8 DeviceReport (org.traccar.reports.model.DeviceReport)8 HashMap (java.util.HashMap)2 Event (org.traccar.model.Event)2 Geofence (org.traccar.model.Geofence)2 Position (org.traccar.model.Position)2 StopReport (org.traccar.reports.model.StopReport)2 TripReport (org.traccar.reports.model.TripReport)2 Maintenance (org.traccar.model.Maintenance)1