Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
hilo-group
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-group
Commits
6a817fba
Commit
6a817fba
authored
Mar 23, 2023
by
hujiebin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
分批获取所有家族成员
parent
16b757e5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
24 deletions
+42
-24
group_info.go
domain/model/groupPower_m/group_info.go
+13
-8
event_init.go
domain/service/event_s/event_init.go
+28
-15
group_power_test.go
test/group_power_test.go
+1
-1
No files found.
domain/model/groupPower_m/group_info.go
View file @
6a817fba
...
...
@@ -4,7 +4,6 @@ import (
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/mysql"
"git.hilo.cn/hilo-common/utils"
"hilo-group/_const/enum/groupPower_e"
)
type
GroupPowerInfo
struct
{
...
...
@@ -59,13 +58,19 @@ func GetGroupPowerUser(model *domain.Model, groupPowerId mysql.ID) ([]*GroupPowe
return
m
[
groupPowerId
],
nil
}
// 获取所有家族的主
func
GetAllGroupPowerOwners
(
model
*
domain
.
Model
)
([]
mysql
.
ID
,
error
)
{
// 分批获取所有家族成员
func
BatchGetAllGroupPowerUsers
(
model
*
domain
.
Model
,
lastId
mysql
.
ID
,
limit
int
)
([]
mysql
.
ID
,
mysql
.
ID
,
error
)
{
var
res
[]
GroupPowerUser
var
userIds
[]
mysql
.
ID
if
err
:=
model
.
DB
()
.
Model
(
GroupPowerUser
{})
.
Select
(
"user_id"
)
.
Where
(
"role = ?"
,
groupPower_e
.
GroupPowerUserRoleMgr
)
.
Find
(
&
userIds
)
.
Error
;
err
!=
nil
{
model
.
Log
.
Errorf
(
"GetAllGroupPowerOwners fail:%v"
,
err
)
return
userIds
,
err
var
nextLastId
mysql
.
ID
if
err
:=
model
.
DB
()
.
Model
(
GroupPowerUser
{})
.
Where
(
"id > ?"
,
lastId
)
.
Order
(
"id asc"
)
.
Limit
(
limit
)
.
Find
(
&
res
)
.
Error
;
err
!=
nil
{
model
.
Log
.
Errorf
(
"BatchGetAllGroupPowerUsers fail:%v"
,
err
)
return
userIds
,
0
,
err
}
return
userIds
,
nil
for
_
,
v
:=
range
res
{
userIds
=
append
(
userIds
,
v
.
UserId
)
nextLastId
=
v
.
ID
}
return
userIds
,
nextLastId
,
nil
}
domain/service/event_s/event_init.go
View file @
6a817fba
...
...
@@ -195,23 +195,36 @@ func GroupPowerEvents() {
// 势力等级即将过期
group_power_ev
.
AddGroupPowerExpireNoticeAsync
(
func
(
model
*
domain
.
Model
,
e
interface
{})
error
{
model
.
Log
.
Infof
(
"msg AddGroupPowerExpireNoticeAsync"
)
powerOwners
,
err
:=
groupPower_m
.
GetAllGroupPowerOwners
(
model
)
if
err
!=
nil
{
model
.
Log
.
Errorf
(
"AddGroupPowerExpireNoticeAsync fail:%v"
,
err
)
return
err
}
userMaps
,
err
:=
user_m
.
GetUserMapByIds
(
model
,
powerOwners
)
if
err
!=
nil
{
return
err
}
for
uid
,
u
:=
range
userMaps
{
if
err
:=
msg_m
.
NewUserRecord
(
model
,
uid
,
msg_e
.
GroupPowerExpireNotice
,
""
,
0
,
""
,
""
,
""
,
""
,
""
)
.
Persistent
();
err
!=
nil
{
model
.
Log
.
Errorf
(
"msg AddGroupPowerExpireNoticeAsync NewUserRecord err:%v"
,
err
)
return
nil
start
:=
time
.
Now
()
model
.
Log
.
Infof
(
"msg AddGroupPowerExpireNoticeAsync,start:%v"
,
start
)
lastId
:=
mysql
.
ID
(
0
)
for
{
powerUsers
,
nextLastId
,
err
:=
groupPower_m
.
BatchGetAllGroupPowerUsers
(
model
,
lastId
,
500
)
if
err
!=
nil
{
model
.
Log
.
Errorf
(
"AddGroupPowerExpireNoticeAsync fail:%v"
,
err
)
return
err
}
msg_m
.
SendEmasMsgAssistant
(
model
,
u
.
ExternalId
,
u
.
DeviceType
)
if
len
(
powerUsers
)
<=
0
{
break
}
userMaps
,
err
:=
user_m
.
GetUserMapByIds
(
model
,
powerUsers
)
if
err
!=
nil
{
return
err
}
for
uid
,
u
:=
range
userMaps
{
if
err
:=
msg_m
.
NewUserRecord
(
model
,
uid
,
msg_e
.
GroupPowerExpireNotice
,
""
,
0
,
""
,
""
,
""
,
""
,
""
)
.
Persistent
();
err
!=
nil
{
model
.
Log
.
Errorf
(
"msg AddGroupPowerExpireNoticeAsync NewUserRecord err:%v"
,
err
)
return
nil
}
_
=
msg_m
.
SendEmasMsgAssistant
(
model
,
u
.
ExternalId
,
u
.
DeviceType
)
}
if
nextLastId
<=
0
{
break
}
lastId
=
nextLastId
time
.
Sleep
(
time
.
Second
)
// 停顿一秒
}
model
.
Log
.
Infof
(
"msg AddGroupPowerExpireNoticeAsync,end:%v"
,
time
.
Now
()
.
Sub
(
start
)
.
Seconds
())
return
nil
})
}
...
...
test/group_power_test.go
View file @
6a817fba
...
...
@@ -7,7 +7,7 @@ import (
)
func
TestGetAllGroupPowerOwner
(
t
*
testing
.
T
)
{
owners
,
err
:=
groupPower_m
.
GetAllGroupPowerOwn
ers
(
domain
.
CreateModelNil
())
owners
,
err
:=
groupPower_m
.
BatchGetAllGroupPowerUs
ers
(
domain
.
CreateModelNil
())
println
(
owners
,
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