aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2023-06-11 08:08:53 -0700
committerGitHub <noreply@github.com>2023-06-11 08:08:53 -0700
commitdf96f168eb4439beb044d301bcbf96502df62151 (patch)
treedc93a52b303eebcbaa3538e902a21563a7dab4c2 /src/main/java/org
parent62ff6c8464dbdd8eb07e8347b356b8739b8c9008 (diff)
parentc98f4706e648e835ef7ac460e4a12381562515cd (diff)
downloadtrackermap-server-df96f168eb4439beb044d301bcbf96502df62151.tar.gz
trackermap-server-df96f168eb4439beb044d301bcbf96502df62151.tar.bz2
trackermap-server-df96f168eb4439beb044d301bcbf96502df62151.zip
Merge pull request #5114 from LiGuru/master
Add increment value attribute on Duplicate Device Name for Route Report.
Diffstat (limited to 'src/main/java/org')
-rw-r--r--src/main/java/org/traccar/reports/RouteReportProvider.java10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/main/java/org/traccar/reports/RouteReportProvider.java b/src/main/java/org/traccar/reports/RouteReportProvider.java
index 6d44259e6..a1d004dd1 100644
--- a/src/main/java/org/traccar/reports/RouteReportProvider.java
+++ b/src/main/java/org/traccar/reports/RouteReportProvider.java
@@ -42,12 +42,15 @@ import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
+import java.util.Map;
+import java.util.HashMap;
public class RouteReportProvider {
private final Config config;
private final ReportUtils reportUtils;
private final Storage storage;
+ private final Map<String, Integer> namesCount = new HashMap<>();
@Inject
public RouteReportProvider(Config config, ReportUtils reportUtils, Storage storage) {
@@ -67,6 +70,11 @@ public class RouteReportProvider {
return result;
}
+
+ private String getUniqueSheetName(String key) {
+ namesCount.compute(key, (k, value) -> (value == null) ? 1 : (value + 1));
+ return (namesCount.get(key) > 1 ? key + "-" + namesCount.get(key) : key);
+ }
public void getExcel(OutputStream outputStream,
long userId, Collection<Long> deviceIds, Collection<Long> groupIds,
Date from, Date to) throws StorageException, IOException {
@@ -78,7 +86,7 @@ public class RouteReportProvider {
var positions = PositionUtil.getPositions(storage, device.getId(), from, to);
DeviceReportSection deviceRoutes = new DeviceReportSection();
deviceRoutes.setDeviceName(device.getName());
- sheetNames.add(WorkbookUtil.createSafeSheetName(deviceRoutes.getDeviceName()));
+ sheetNames.add(WorkbookUtil.createSafeSheetName(getUniqueSheetName(deviceRoutes.getDeviceName())));
if (device.getGroupId() > 0) {
Group group = storage.getObject(Group.class, new Request(
new Columns.All(), new Condition.Equals("id", device.getGroupId())));