aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNikolay Vlahovski <nvlahovski@gmail.com>2023-06-11 13:30:48 +0300
committerNikolay Vlahovski <nvlahovski@gmail.com>2023-06-11 13:30:48 +0300
commit873f08a8fd6e5e521e8c81421ebc2c3ea642ee52 (patch)
treee34fc87c565feecfe96afe6563d0de67d77443bd /src
parent62ff6c8464dbdd8eb07e8347b356b8739b8c9008 (diff)
downloadtrackermap-server-873f08a8fd6e5e521e8c81421ebc2c3ea642ee52.tar.gz
trackermap-server-873f08a8fd6e5e521e8c81421ebc2c3ea642ee52.tar.bz2
trackermap-server-873f08a8fd6e5e521e8c81421ebc2c3ea642ee52.zip
Add increment value attribute on Duplicate Device Name for Route Report.
Declaring uniqueSheetsTitle Add private method getUniqueSheetName Usage in getExcel sheetNames
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/traccar/reports/RouteReportProvider.java11
1 files changed, 10 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..bec1470bd 100644
--- a/src/main/java/org/traccar/reports/RouteReportProvider.java
+++ b/src/main/java/org/traccar/reports/RouteReportProvider.java
@@ -42,6 +42,9 @@ 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;
+import java.util.concurrent.atomic.AtomicInteger;
public class RouteReportProvider {
@@ -66,7 +69,13 @@ public class RouteReportProvider {
}
return result;
}
+ private final Map<String, Integer> uniqueSheetsTitle = new HashMap<>();
+ private String getUniqueSheetName(String key) {
+ AtomicInteger atomic = new AtomicInteger(uniqueSheetsTitle.getOrDefault(key, -1));
+ uniqueSheetsTitle.put(key, atomic.incrementAndGet());
+ return (uniqueSheetsTitle.get(key) > 0 ? key + "-" + uniqueSheetsTitle.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 +87,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())));