-
Notifications
You must be signed in to change notification settings - Fork 0
/
IMP_Set.go
102 lines (70 loc) · 1.77 KB
/
IMP_Set.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
package notice
import (
"github.com/hailongz/golang/db"
"github.com/hailongz/golang/dynamic"
"github.com/hailongz/golang/json"
"github.com/hailongz/golang/micro"
)
func (S *Service) Set(app micro.IContext, task *SetTask) (*Notice, error) {
conn, prefix, err := app.GetDB("wd")
if err != nil {
return nil, err
}
prefix = Prefix(app, prefix, task.Uid)
v := Notice{}
rs, err := db.Query(conn, &v, prefix, " WHERE id=?", task.Id)
if err != nil {
return nil, err
}
defer rs.Close()
if rs.Next() {
scaner := db.NewScaner(&v)
err = scaner.Scan(rs)
if err != nil {
return nil, err
}
} else {
return nil, micro.NewError(ERROR_NOT_FOUND, "未找到通知")
}
keys := map[string]bool{}
if task.Type != nil {
v.Type = int32(dynamic.IntValue(task.Type, int64(v.Type)))
keys["type"] = true
}
if task.Fid != nil {
v.Fid = dynamic.IntValue(task.Fid, v.Fid)
keys["fid"] = true
}
if task.Iid != nil {
v.Iid = dynamic.IntValue(task.Iid, v.Iid)
keys["iid"] = true
}
if task.Body != nil {
v.Body = dynamic.StringValue(task.Body, v.Body)
keys["body"] = true
}
if task.Options != nil {
options := map[string]interface{}{}
dynamic.Each(v.Options, func(key interface{}, value interface{}) bool {
options[dynamic.StringValue(key, "")] = value
return true
})
text := dynamic.StringValue(task.Options, "")
var data interface{} = nil
json.Unmarshal([]byte(text), &data)
dynamic.Each(data, func(key interface{}, value interface{}) bool {
options[dynamic.StringValue(key, "")] = value
return true
})
v.Options = options
keys["options"] = true
}
if len(keys) > 0 {
_, err = db.UpdateWithKeys(conn, &v, prefix, keys)
if err != nil {
return nil, err
}
app.SendMessage(task.GetName(), &v)
}
return &v, nil
}