fix: resolve issue with incorrect deletion of single record
This commit is contained in:
@@ -96,6 +96,7 @@ class MergeService {
|
|||||||
|
|
||||||
static List<Object> _groupByTrainOrLoco(List<TrainRecord> records) {
|
static List<Object> _groupByTrainOrLoco(List<TrainRecord> records) {
|
||||||
final List<MergedTrainRecord> mergedRecords = [];
|
final List<MergedTrainRecord> mergedRecords = [];
|
||||||
|
final List<TrainRecord> singleRecords = [];
|
||||||
final Set<String> usedRecordIds = {};
|
final Set<String> usedRecordIds = {};
|
||||||
|
|
||||||
for (int i = 0; i < records.length; i++) {
|
for (int i = 0; i < records.length; i++) {
|
||||||
@@ -103,7 +104,6 @@ class MergeService {
|
|||||||
if (usedRecordIds.contains(record.uniqueId)) continue;
|
if (usedRecordIds.contains(record.uniqueId)) continue;
|
||||||
|
|
||||||
final group = <TrainRecord>[record];
|
final group = <TrainRecord>[record];
|
||||||
usedRecordIds.add(record.uniqueId);
|
|
||||||
|
|
||||||
for (int j = i + 1; j < records.length; j++) {
|
for (int j = i + 1; j < records.length; j++) {
|
||||||
final otherRecord = records[j];
|
final otherRecord = records[j];
|
||||||
@@ -137,11 +137,14 @@ class MergeService {
|
|||||||
|
|
||||||
if (trainMatch || locoMatch || (bothTrainEmpty && locoMatch)) {
|
if (trainMatch || locoMatch || (bothTrainEmpty && locoMatch)) {
|
||||||
group.add(otherRecord);
|
group.add(otherRecord);
|
||||||
usedRecordIds.add(otherRecord.uniqueId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (group.length >= 2) {
|
if (group.length >= 2) {
|
||||||
|
for (final record in group) {
|
||||||
|
usedRecordIds.add(record.uniqueId);
|
||||||
|
}
|
||||||
|
|
||||||
final firstRecord = group.first;
|
final firstRecord = group.first;
|
||||||
final train = firstRecord.train.trim();
|
final train = firstRecord.train.trim();
|
||||||
final loco = firstRecord.loco.trim();
|
final loco = firstRecord.loco.trim();
|
||||||
@@ -168,12 +171,12 @@ class MergeService {
|
|||||||
records: group,
|
records: group,
|
||||||
latestRecord: group.first,
|
latestRecord: group.first,
|
||||||
));
|
));
|
||||||
|
} else {
|
||||||
|
singleRecords.add(record);
|
||||||
|
usedRecordIds.add(record.uniqueId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final singleRecords =
|
|
||||||
records.where((r) => !usedRecordIds.contains(r.uniqueId)).toList();
|
|
||||||
|
|
||||||
final List<Object> result = [...mergedRecords, ...singleRecords];
|
final List<Object> result = [...mergedRecords, ...singleRecords];
|
||||||
result.sort((a, b) {
|
result.sort((a, b) {
|
||||||
final aTime = a is MergedTrainRecord
|
final aTime = a is MergedTrainRecord
|
||||||
|
|||||||
Reference in New Issue
Block a user