Search in sources :

Example 21 with Device

use of org.traccar.model.Device 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 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 22 with Device

use of org.traccar.model.Device in project traccar by tananaev.

the class TestIdentityManager method createDevice.

private static Device createDevice() {
    Device device = new Device();
    device.setId(1);
    device.setName("test");
    device.setUniqueId("123456789012345");
    return device;
}
Also used : Device(org.traccar.model.Device)

Example 23 with Device

use of org.traccar.model.Device in project traccar by tananaev.

the class GroupTreeTest method createDevice.

private static Device createDevice(long id, String name, long parent) {
    Device device = new Device();
    device.setId(id);
    device.setName(name);
    device.setGroupId(parent);
    return device;
}
Also used : Device(org.traccar.model.Device)

Example 24 with Device

use of org.traccar.model.Device 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 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)

Example 25 with Device

use of org.traccar.model.Device 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 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);
    }
}
Also used : TripReport(org.traccar.reports.model.TripReport) Group(org.traccar.model.Group) 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

Device (org.traccar.model.Device)33 Position (org.traccar.model.Position)10 Event (org.traccar.model.Event)9 Group (org.traccar.model.Group)7 SQLException (java.sql.SQLException)6 HashMap (java.util.HashMap)6 ArrayList (java.util.ArrayList)5 FileInputStream (java.io.FileInputStream)4 InputStream (java.io.InputStream)4 DeviceReport (org.traccar.reports.model.DeviceReport)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 HashSet (java.util.HashSet)3 Map (java.util.Map)2 DeviceState (org.traccar.model.DeviceState)2 Geofence (org.traccar.model.Geofence)2 Permission (org.traccar.model.Permission)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 InetSocketAddress (java.net.InetSocketAddress)1