-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
119 lines (103 loc) · 2.39 KB
/
util.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package http
import (
"strconv"
"strings"
"go-common/library/log"
bm "go-common/library/net/http/blademaster"
"go-common/library/xstr"
)
type intsParam struct {
value string
p *[]int64
}
type intParam struct {
value string
p *int64
}
func dealNumsmap(intsparams []*intsParam) error {
for _, isp := range intsparams {
if isp.value != "" {
ids, err := xstr.SplitInts(isp.value)
if err != nil {
log.Error("strconv.ParseInt(%s) error(%v)", isp.value, err)
return err
}
*isp.p = ids
}
}
return nil
}
func dealNummap(intparams []*intParam) error {
for _, ip := range intparams {
if ip.value != "" {
id, err := strconv.ParseInt(ip.value, 10, 64)
if err != nil {
log.Error("strconv.ParseInt(%s) error(%v)", ip.value, err)
return err
}
*ip.p = id
}
}
return nil
}
// adjustOrder will convert order field from request to search service
func adjustOrder(subject string, order string) string {
SubOrderFields := map[string]map[string]string{
"group": {
"last_time": "lasttime",
},
"tag": {
"count": "tag_all_num",
"handling": "tag_todo_num",
},
"challenge": {},
"log": {
"ctime": "opt_ctime",
},
}
orderFields, ok := SubOrderFields[subject]
if !ok {
return order
}
field, ok := orderFields[order]
if !ok {
return order
}
return field
}
// read permissions of an admin
// only use workflow permissions in platform
// like WF_BUSINESS_2_ROUND_11
// round > 10 means feedback flow
// one admin only has one flow permission in a business
func parsePermission(permissions []string) (permissionMap map[int8]int64) {
//permissionMap map[business]round
//var regex = `^WF_BUSINESS_[1-9]\d*_ROUND_[1-9]\d*`
permissionMap = make(map[int8]int64)
for _, str := range permissions {
splitStr := strings.Split(str, "_")
if len(splitStr) == 5 && splitStr[0] == "WF" && splitStr[1] == "BUSINESS" && splitStr[3] == "ROUND" {
business, err := strconv.ParseInt(splitStr[2], 10, 32)
if err != nil {
continue
}
round, err := strconv.ParseInt(splitStr[4], 10, 32)
if err != nil {
continue
}
permissionMap[int8(business)] = round
//todo: support round??
}
}
// todo: use cache?
return
}
func adminInfo(ctx *bm.Context) (adminID int64, adminName string) {
if IUid, ok := ctx.Get("uid"); ok {
adminID = IUid.(int64)
}
if IUName, ok := ctx.Get("username"); ok {
adminName = IUName.(string)
}
return
}