-
Notifications
You must be signed in to change notification settings - Fork 7
/
account_book.go
74 lines (61 loc) · 1.39 KB
/
account_book.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package feidee
type AccountBook struct {
Categories []Category
Stores []IdName
Members []IdName
Accounts []IdName
Projects []IdName
}
// 根据科目名获取科目ID为索引的Map
func (accountBook AccountBook) CategoryIdMap() map[int]Category {
m := make(map[int]Category)
for _, category := range accountBook.Categories {
m[category.Id] = category
}
return m
}
// 根据科目名获取科目ID
func (accountBook AccountBook) CategoryIdByName(name string) int {
for _, item := range accountBook.Categories {
if item.Name == name {
return item.Id
}
}
return 0
}
// 根据商户名获取商户ID
func (accountBook AccountBook) StoreIdByName(name string) int {
for _, item := range accountBook.Stores {
if item.Name == name {
return item.Id
}
}
return 0
}
// 根据成员名获取成员ID
func (accountBook AccountBook) MemberIdByName(name string) int {
for _, item := range accountBook.Members {
if item.Name == name {
return item.Id
}
}
return 0
}
// 根据账户名获取账户ID
func (accountBook AccountBook) AccountIdByName(name string) int {
for _, item := range accountBook.Accounts {
if item.Name == name {
return item.Id
}
}
return 0
}
// 根据项目名获取项目ID
func (accountBook AccountBook) ProjectIdByName(name string) int {
for _, item := range accountBook.Projects {
if item.Name == name {
return item.Id
}
}
return 0
}