-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathentity.go
113 lines (106 loc) · 2.51 KB
/
entity.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
package yingyan
import (
"encoding/json"
"strconv"
"strings"
)
func (c *Client) EntityAdd(entityName, entityDesc string) (r *CommonResp, err error) {
param := map[string]string{
"entity_name": entityName,
"entity_desc": entityDesc,
}
respByte, err := c.Post(entityAddPath, param)
if err != nil {
return nil, err
}
r = &CommonResp{}
err = json.Unmarshal(respByte, r)
if err != nil {
return nil, err
}
return r, nil
}
func (c *Client) EntityUpdate(entityName, entityDesc string) (r *CommonResp, err error) {
param := map[string]string{
"entity_name": entityName,
"entity_desc": entityDesc,
}
respByte, err := c.Post(entityUpdatePath, param)
if err != nil {
return nil, err
}
r = &CommonResp{}
err = json.Unmarshal(respByte, r)
if err != nil {
return nil, err
}
return r, nil
}
func (c *Client) EntityDelete(entityName string) (r *CommonResp, err error) {
param := map[string]string{
"entity_name": entityName,
}
respByte, err := c.Post(entityDeletePath, param)
if err != nil {
return nil, err
}
r = &CommonResp{}
err = json.Unmarshal(respByte, r)
if err != nil {
return nil, err
}
return r, nil
}
type EntityListFilter struct {
EntityNames []string
ActiveTime int64 //该时间之后活跃的用户
InactiveTime int64 //该时间之后不活跃的用户
}
func (f *EntityListFilter) ToData() string {
param := map[string]string{}
names := strings.Join(f.EntityNames, ",")
if names != "" {
param["entity_names"] = names
}
//有且只有一个Time
if f.ActiveTime != 0 {
param["active_time"] = strconv.FormatInt(f.ActiveTime, 10)
} else if f.InactiveTime != 0 {
param["inactive_time"] = strconv.FormatInt(f.InactiveTime, 10)
}
var params []string
for k, v := range param {
params = append(params, k+"="+v)
}
return strings.Join(params, "|")
}
func (c *Client) EntityList(filter *EntityListFilter, coordType CoordType, pageIndex, pageSize int) (r *EntitiesListResp, err error) {
if coordType == "" {
coordType = BaiDuCoordType
}
if pageIndex <= 0 {
pageIndex = 1
}
if pageSize <= 0 || pageSize > 1000 {
pageSize = 100
}
param := map[string]string{
"coord_type_output": string(coordType),
"page_index": strconv.Itoa(pageIndex),
"page_size": strconv.Itoa(pageSize),
}
filterString := filter.ToData()
if filterString != "" {
param["filter"] = filterString
}
respByte, err := c.Get(entityList, param)
if err != nil {
return nil, err
}
r = &EntitiesListResp{}
err = json.Unmarshal(respByte, r)
if err != nil {
return nil, err
}
return r, nil
}