make tags of exported transaction data in the same order as they displayed in transaction
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/mayswind/ezbookkeeping/pkg/datastore"
|
"github.com/mayswind/ezbookkeeping/pkg/datastore"
|
||||||
"github.com/mayswind/ezbookkeeping/pkg/errs"
|
"github.com/mayswind/ezbookkeeping/pkg/errs"
|
||||||
"github.com/mayswind/ezbookkeeping/pkg/models"
|
"github.com/mayswind/ezbookkeeping/pkg/models"
|
||||||
|
"github.com/mayswind/ezbookkeeping/pkg/utils"
|
||||||
"github.com/mayswind/ezbookkeeping/pkg/uuid"
|
"github.com/mayswind/ezbookkeeping/pkg/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -440,5 +441,10 @@ func (s *TransactionTagService) GetGroupedTransactionTagIds(tagIndexes []*models
|
|||||||
transactionTagIds = append(transactionTagIds, tagIndex.TagId)
|
transactionTagIds = append(transactionTagIds, tagIndex.TagId)
|
||||||
allTransactionTagIds[tagIndex.TransactionId] = transactionTagIds
|
allTransactionTagIds[tagIndex.TransactionId] = transactionTagIds
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, tagIds := range allTransactionTagIds {
|
||||||
|
utils.Int64Sort(tagIds)
|
||||||
|
}
|
||||||
|
|
||||||
return allTransactionTagIds
|
return allTransactionTagIds
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
|
import "sort"
|
||||||
|
|
||||||
// Int64SliceEquals returns whether specific two int64 arrays equal
|
// Int64SliceEquals returns whether specific two int64 arrays equal
|
||||||
func Int64SliceEquals(s1, s2 []int64) bool {
|
func Int64SliceEquals(s1, s2 []int64) bool {
|
||||||
if (s1 == nil) != (s2 == nil) {
|
if (s1 == nil) != (s2 == nil) {
|
||||||
@@ -58,6 +60,13 @@ func ToUniqueInt64Slice(items []int64) []int64 {
|
|||||||
return uniqueItems
|
return uniqueItems
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Int64Sort sorts the specified array with int64 items
|
||||||
|
func Int64Sort(items []int64) {
|
||||||
|
sort.Slice(items, func(i, j int) bool {
|
||||||
|
return items[i] < items[j]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// ToSet returns a map where the keys are the items in the specified array
|
// ToSet returns a map where the keys are the items in the specified array
|
||||||
func ToSet(items []int64) map[int64]bool {
|
func ToSet(items []int64) map[int64]bool {
|
||||||
itemExistMap := make(map[int64]bool)
|
itemExistMap := make(map[int64]bool)
|
||||||
|
|||||||
@@ -131,6 +131,14 @@ func TestToUniqueInt64Slice_NilOrEmpty(t *testing.T) {
|
|||||||
assert.Equal(t, expectedValue, actualValue)
|
assert.Equal(t, expectedValue, actualValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestInt64Sort(t *testing.T) {
|
||||||
|
actualValue := []int64{4, 3, 2, 1, 5}
|
||||||
|
expectedValue := []int64{1, 2, 3, 4, 5}
|
||||||
|
|
||||||
|
Int64Sort(actualValue)
|
||||||
|
assert.Equal(t, expectedValue, actualValue)
|
||||||
|
}
|
||||||
|
|
||||||
func TestToSet(t *testing.T) {
|
func TestToSet(t *testing.T) {
|
||||||
arr := []int64{0, 1, 2, 3, 2, 4, 0}
|
arr := []int64{0, 1, 2, 3, 2, 4, 0}
|
||||||
actualValue := ToSet(arr)
|
actualValue := ToSet(arr)
|
||||||
|
|||||||
Reference in New Issue
Block a user