Event report by alarm type

This commit is contained in:
Anton Tananaev 2024-12-23 16:18:07 -08:00
parent d1a7121b67
commit a01a3eb4b0
3 changed files with 21 additions and 9 deletions

View File

@ -163,11 +163,12 @@ public class ReportResource extends SimpleObjectResource<Report> {
@QueryParam("deviceId") List<Long> deviceIds,
@QueryParam("groupId") List<Long> groupIds,
@QueryParam("type") List<String> types,
@QueryParam("alarm") List<String> alarms,
@QueryParam("from") Date from,
@QueryParam("to") Date to) throws StorageException {
permissionsService.checkRestriction(getUserId(), UserRestrictions::getDisableReports);
LogAction.report(getUserId(), false, "events", from, to, deviceIds, groupIds);
return eventsReportProvider.getObjects(getUserId(), deviceIds, groupIds, types, from, to);
return eventsReportProvider.getObjects(getUserId(), deviceIds, groupIds, types, alarms, from, to);
}
@Path("events")
@ -177,13 +178,14 @@ public class ReportResource extends SimpleObjectResource<Report> {
@QueryParam("deviceId") List<Long> deviceIds,
@QueryParam("groupId") List<Long> groupIds,
@QueryParam("type") List<String> types,
@QueryParam("alarm") List<String> alarms,
@QueryParam("from") Date from,
@QueryParam("to") Date to,
@QueryParam("mail") boolean mail) throws StorageException {
permissionsService.checkRestriction(getUserId(), UserRestrictions::getDisableReports);
return executeReport(getUserId(), mail, stream -> {
LogAction.report(getUserId(), false, "events", from, to, deviceIds, groupIds);
eventsReportProvider.getExcel(stream, getUserId(), deviceIds, groupIds, types, from, to);
eventsReportProvider.getExcel(stream, getUserId(), deviceIds, groupIds, types, alarms, from, to);
});
}
@ -194,10 +196,11 @@ public class ReportResource extends SimpleObjectResource<Report> {
@QueryParam("deviceId") List<Long> deviceIds,
@QueryParam("groupId") List<Long> groupIds,
@QueryParam("type") List<String> types,
@QueryParam("alarm") List<String> alarms,
@QueryParam("from") Date from,
@QueryParam("to") Date to,
@PathParam("type") String type) throws StorageException {
return getEventsExcel(deviceIds, groupIds, types, from, to, type.equals("mail"));
return getEventsExcel(deviceIds, groupIds, types, alarms, from, to, type.equals("mail"));
}
@Path("summary")

View File

@ -1,5 +1,5 @@
/*
* Copyright 2016 - 2022 Anton Tananaev (anton@traccar.org)
* Copyright 2016 - 2024 Anton Tananaev (anton@traccar.org)
* Copyright 2016 - 2018 Andrey Kunitsyn (andrey@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
@ -71,9 +71,17 @@ public class EventsReportProvider {
new Order("eventTime")));
}
private boolean filterType(Collection<String> types, Collection<String> alarms, Event event) {
if (!types.contains(event.getType())) {
return false;
}
return !event.getType().equals(Event.TYPE_ALARM) || alarms.isEmpty()
|| alarms.contains(event.getString(Position.KEY_ALARM));
}
public Collection<Event> getObjects(
long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
Collection<String> types, Date from, Date to) throws StorageException {
Collection<String> types, Collection<String> alarms, Date from, Date to) throws StorageException {
reportUtils.checkPeriodLimit(from, to);
ArrayList<Event> result = new ArrayList<>();
@ -81,7 +89,7 @@ public class EventsReportProvider {
Collection<Event> events = getEvents(device.getId(), from, to);
boolean all = types.isEmpty() || types.contains(Event.ALL_EVENTS);
for (Event event : events) {
if (all || types.contains(event.getType())) {
if (all || filterType(types, alarms, event)) {
long geofenceId = event.getGeofenceId();
long maintenanceId = event.getMaintenanceId();
if ((geofenceId == 0 || reportUtils.getObject(userId, Geofence.class, geofenceId) != null)
@ -97,7 +105,8 @@ public class EventsReportProvider {
public void getExcel(
OutputStream outputStream, long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
Collection<String> types, Date from, Date to) throws StorageException, IOException {
Collection<String> types, Collection<String> alarms,
Date from, Date to) throws StorageException, IOException {
reportUtils.checkPeriodLimit(from, to);
ArrayList<DeviceReportSection> devicesEvents = new ArrayList<>();
@ -110,7 +119,7 @@ public class EventsReportProvider {
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())) {
if (all || filterType(types, alarms, event)) {
long geofenceId = event.getGeofenceId();
long maintenanceId = event.getMaintenanceId();
if (geofenceId != 0) {

View File

@ -121,7 +121,7 @@ public class TaskReports extends SingleScheduleTask {
case "events" -> {
var eventsReportProvider = injector.getInstance(EventsReportProvider.class);
reportMailer.sendAsync(user.getId(), stream -> eventsReportProvider.getExcel(
stream, user.getId(), deviceIds, groupIds, List.of(), from, to));
stream, user.getId(), deviceIds, groupIds, List.of(), List.of(), from, to));
}
case "route" -> {
var routeReportProvider = injector.getInstance(RouteReportProvider.class);