fixed transaction order in CSV export
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -31,7 +31,7 @@ public interface AccountingService {
|
||||
var keys = List.of(Field.DATE, Field.SOURCE, Field.AMOUNT, Field.DESTINATION, Field.PURPOSE,Field.TAGS);
|
||||
var sb = new StringBuilder();
|
||||
keys.stream().map(Translatable::t).forEach(field -> sb.append(field).append(";"));
|
||||
transactions.stream().sorted(Comparator.comparing(Transaction::id))
|
||||
transactions.stream().sorted()
|
||||
.map(transaction -> transaction.csvLine(users, keys,";"))
|
||||
.forEach(line -> sb.append("\n").append(line));
|
||||
return sb.toString().getBytes(UTF_8);
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.time.ZoneOffset;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Transaction extends UmbrellaObject {
|
||||
public class Transaction extends UmbrellaObject implements Comparable<Transaction>{
|
||||
private final long accountId;
|
||||
private LocalDateTime date;
|
||||
private IdOrString source, destination;
|
||||
@@ -51,6 +51,12 @@ public class Transaction extends UmbrellaObject {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(Transaction other) {
|
||||
var order = date.compareTo(other.date);
|
||||
return order == 0 ? Long.compare(id(), other.id()) : order;
|
||||
}
|
||||
|
||||
public String csvLine(Map<Long, UmbrellaUser> users, List<String> keys, String delimiter) {
|
||||
return keys.stream().map(this::get).map(o -> resolveUsers(users,o)).map(o -> quote(o, delimiter)).collect(Collectors.joining(delimiter));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user