-
Notifications
You must be signed in to change notification settings - Fork 0
/
task.go
181 lines (168 loc) · 4.41 KB
/
task.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
package rpc
import (
"context"
"errors"
"go-common/app/admin/main/aegis/model"
acc "go-common/app/service/main/account/api"
relmod "go-common/app/service/main/relation/model"
uprpc "go-common/app/service/main/up/api/v1"
"go-common/library/log"
"go-common/library/net/metadata"
terrors "github.com/pkg/errors"
)
//ERROR
var (
ErrEmptyReply = errors.New("rpc empty reply")
)
// FansCount 粉丝数
func (d *Dao) FansCount(c context.Context, mids []int64) (fans map[int64]int64, err error) {
arg := &relmod.ArgMids{Mids: mids}
stats, err := d.relRPC.Stats(c, arg)
if err != nil {
log.Error("FansCount error(%v)", terrors.WithStack(err))
return
}
fans = make(map[int64]int64)
for mid, item := range stats {
fans[mid] = item.Follower
}
log.Info("FansCount fans(%+v)", fans)
return
}
// UserInfos 提供给资源列表批量查
func (d *Dao) UserInfos(c context.Context, mids []int64) (res map[int64]*model.UserInfo, err error) {
arg1 := &relmod.ArgMids{Mids: mids}
stats, err := d.relRPC.Stats(c, arg1)
if err != nil {
log.Error("Stats error(%v)", terrors.WithStack(err))
return
}
midsReq := &acc.MidsReq{
Mids: mids,
RealIp: metadata.String(c, metadata.RemoteIP),
}
cardsreply, err := d.AccountClient.Cards3(c, midsReq)
if err != nil {
log.Error("Cards3(%+v) error(%v)", mids, terrors.WithStack(err))
return
}
if cardsreply == nil {
err = ErrEmptyReply
log.Error("Cards3(%+v) error(%v)", mids, terrors.WithStack(err))
return
}
cards := cardsreply.Cards
res = make(map[int64]*model.UserInfo)
for _, mid := range mids {
userinfo := &model.UserInfo{Mid: mid}
if card, ok := cards[mid]; ok {
userinfo.Name = card.Name
userinfo.Official = card.Official
}
if stat, ok := stats[mid]; ok {
userinfo.Follower = stat.Follower
}
res[mid] = userinfo
}
return
}
// Profile get account.
func (d *Dao) Profile(c context.Context, mid int64) (userinfo *model.UserInfo, err error) {
if mid <= 0 {
return
}
midReq := &acc.MidReq{
Mid: mid,
RealIp: metadata.String(c, metadata.RemoteIP),
}
res, err := d.AccountClient.ProfileWithStat3(c, midReq)
if err != nil {
log.Error("d.acc.ProfileWithStat3() error(%v) arg(%+v)", err, midReq)
}
if res == nil {
err = ErrEmptyReply
log.Error("ProfileWithStat3(%+v) error(%v)", mid, terrors.WithStack(err))
return
}
userinfo = &model.UserInfo{
Mid: mid,
Follower: res.Follower,
}
if res.Profile != nil {
userinfo.Official = res.Profile.Official
userinfo.Name = res.Profile.Name
}
return
}
// Info3 get Name.
func (d *Dao) Info3(c context.Context, mid int64) (res *acc.Info, err error) {
midReq := &acc.MidReq{
Mid: mid,
RealIp: metadata.String(c, metadata.RemoteIP),
}
info, err := d.AccountClient.Info3(c, midReq)
if err != nil {
log.Error("query info3 failed,mid(%v), err(%v)", mid, err)
return
}
if info == nil {
err = ErrEmptyReply
log.Error("Info3(%+v) error(%v)", mid, terrors.WithStack(err))
return
}
res = info.Info
log.Info("getUserInfo userbase (%v)", res)
return
}
// UpSpecial 分组信息
func (d *Dao) UpSpecial(c context.Context, mid int64) (ups *uprpc.UpSpecial, err error) {
midReq := &uprpc.UpSpecialReq{
Mid: mid,
}
var reply *uprpc.UpSpecialReply
if reply, err = d.UpClient.UpSpecial(c, midReq); err != nil {
log.Error("UpSpecial(%d) error(%v)", mid, terrors.WithStack(err))
return
}
if reply == nil {
err = ErrEmptyReply
log.Error("UpSpecial(%+v) error(%v)", mid, terrors.WithStack(err))
return
}
ups = reply.UpSpecial
return
}
//UpsSpecial 分组信息
func (d *Dao) UpsSpecial(c context.Context, mids []int64) (ups map[int64]*uprpc.UpSpecial, err error) {
midReq := &uprpc.UpsSpecialReq{
Mids: mids,
}
var reply *uprpc.UpsSpecialReply
if reply, err = d.UpClient.UpsSpecial(c, midReq); err != nil {
log.Error("UpsSpecial(%d) error(%v)", mids, terrors.WithStack(err))
return
}
if reply == nil {
err = ErrEmptyReply
log.Error("UpsSpecial(%+v) error(%v)", mids, terrors.WithStack(err))
return
}
ups = reply.UpSpecials
return
}
//UpGroups 所有分组
func (d *Dao) UpGroups(c context.Context) (upgs map[int64]*uprpc.UpGroup, err error) {
noReq := &uprpc.NoArgReq{}
var reply *uprpc.UpGroupsReply
if reply, err = d.UpClient.UpGroups(c, noReq); err != nil {
log.Error("UpGroups error(%v)", terrors.WithStack(err))
return
}
if reply == nil {
err = ErrEmptyReply
log.Error("UpGroups error(%v)", terrors.WithStack(err))
return
}
upgs = reply.UpGroups
return
}