Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
hilo-common
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hujiebin
hilo-common
Commits
d30b4869
Commit
d30b4869
authored
Mar 16, 2023
by
hujiebin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
批量获取用户上麦时长
parent
885148b8
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
1 deletion
+41
-1
group.go
rpc/group.go
+36
-1
rpc_test.go
test/rpc_test.go
+5
-0
No files found.
rpc/group.go
View file @
d30b4869
...
@@ -30,7 +30,7 @@ func init() {
...
@@ -30,7 +30,7 @@ func init() {
mylogrus
.
MyLog
.
Infof
(
"consul service update state:%v-%v"
,
defaultGroupConsulName
,
healthAddrs
)
mylogrus
.
MyLog
.
Infof
(
"consul service update state:%v-%v"
,
defaultGroupConsulName
,
healthAddrs
)
groupServerHost
=
healthAddrs
groupServerHost
=
healthAddrs
}
else
{
}
else
{
mylogrus
.
MyLog
.
Warnf
(
"consul service update local state:%v-%v"
,
default
FinanceConsulName
,
defaultFinanceServerAddr
)
mylogrus
.
MyLog
.
Warnf
(
"consul service update local state:%v-%v"
,
default
GroupConsulName
,
defaultGroupServerScheme
)
groupServerHost
=
[]
string
{
defaultGroupServerAddr
}
// 有其他问题都用默认的
groupServerHost
=
[]
string
{
defaultGroupServerAddr
}
// 有其他问题都用默认的
}
}
for
status
:=
range
statusAddrs
{
for
status
:=
range
statusAddrs
{
...
@@ -117,6 +117,41 @@ func MGetGroupPower(model *domain.Model, groupPowerIds []mysql.ID) (map[mysql.ID
...
@@ -117,6 +117,41 @@ func MGetGroupPower(model *domain.Model, groupPowerIds []mysql.ID) (map[mysql.ID
return
res
,
nil
return
res
,
nil
}
}
// 批量获取用户上麦时长
// param day 获取的天,格式 2006-01-02
// return userId->seconds
func
MGetUserOnMic
(
model
*
domain
.
Model
,
day
string
,
userIds
[]
mysql
.
ID
)
(
map
[
mysql
.
ID
]
mysql
.
Num
,
error
)
{
type
Response
struct
{
Code
int
`json:"code"`
Message
string
`json:"message"`
Data
map
[
mysql
.
ID
]
mysql
.
Num
}
var
res
=
make
(
map
[
mysql
.
ID
]
mysql
.
Num
)
if
len
(
userIds
)
<=
0
{
return
res
,
nil
}
var
userIdsStr
[]
string
for
_
,
userId
:=
range
userIds
{
userIdsStr
=
append
(
userIdsStr
,
fmt
.
Sprintf
(
"%d"
,
userId
))
}
_url
:=
fmt
.
Sprintf
(
"%v://%v/inner/mic/onMicSeconds"
,
defaultGroupServerScheme
,
getGroupHost
())
resp
,
err
:=
HttpGet
(
model
,
_url
,
nil
,
map
[
string
][]
string
{
"ids"
:
userIdsStr
,
"day"
:
{
day
},
})
if
err
!=
nil
{
model
.
Log
.
Errorf
(
"MGetUserOnMic fail:%v"
,
err
)
return
res
,
err
}
response
:=
new
(
Response
)
if
err
=
json
.
Unmarshal
(
resp
,
response
);
err
!=
nil
{
model
.
Log
.
Errorf
(
"MGetUserOnMic json fail:%v"
,
err
)
return
res
,
err
}
res
=
response
.
Data
return
res
,
nil
}
func
getGroupHost
()
string
{
func
getGroupHost
()
string
{
l
:=
len
(
groupServerHost
)
l
:=
len
(
groupServerHost
)
r
:=
rand
.
Intn
(
l
)
// 随机一个
r
:=
rand
.
Intn
(
l
)
// 随机一个
...
...
test/rpc_test.go
View file @
d30b4869
...
@@ -11,3 +11,8 @@ func TestMGetGroupPower(t *testing.T) {
...
@@ -11,3 +11,8 @@ func TestMGetGroupPower(t *testing.T) {
res
,
err
:=
rpc
.
MGetGroupPower
(
domain
.
CreateModelNil
(),
[]
mysql
.
ID
{
250
,
251
})
res
,
err
:=
rpc
.
MGetGroupPower
(
domain
.
CreateModelNil
(),
[]
mysql
.
ID
{
250
,
251
})
println
(
res
,
err
)
println
(
res
,
err
)
}
}
func
TestMGetUserOnMic
(
t
*
testing
.
T
)
{
res
,
err
:=
rpc
.
MGetUserOnMic
(
domain
.
CreateModelNil
(),
"2023-03-16"
,
[]
mysql
.
ID
{
2781
,
4549
,
4556
,
4559
})
println
(
res
,
err
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment