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
8b63b8f3
Commit
8b63b8f3
authored
Jun 09, 2023
by
hujiebin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:试下
parent
ef4b6018
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
28 deletions
+60
-28
mic.go
domain/model/group_m/mic.go
+12
-26
micData.go
domain/model/group_m/micData.go
+7
-0
group_mic.go
domain/service/group_mic_s/group_mic.go
+41
-2
No files found.
domain/model/group_m/mic.go
View file @
8b63b8f3
...
...
@@ -124,8 +124,10 @@ type MicUser struct {
I
int
//麦中的人
ExternalId
string
//
//
用户id
UserId
uint64
//用户cpId
CpUserId
uint64
//静音 true:静音,false:没有静音
Forbid
bool
//上麦的的时间戳
...
...
@@ -189,7 +191,8 @@ const micInScript = "local flag = redis.call('EXISTS', '{prefixGroupUserMic}') i
//上麦(自己),
//规则:1:加锁了不能上麦 2:麦上有人,不能上麦
func
(
mic
*
Mic
)
In
(
userId
uint64
,
externalId
string
)
error
{
//cpUserId如果有
func
(
mic
*
Mic
)
In
(
userId
uint64
,
externalId
string
,
cpUserId
uint64
)
error
{
// 群是否被封禁, 呃,,,呃,,,呃,,,
banned
:=
GroupBanned
{
ImGroupId
:
mic
.
GroupUuid
}
if
err
:=
banned
.
Get
(
mic
.
model
);
err
!=
gorm
.
ErrRecordNotFound
{
...
...
@@ -214,33 +217,13 @@ func (mic *Mic) In(userId uint64, externalId string) error {
I
:
mic
.
I
,
ExternalId
:
externalId
,
UserId
:
userId
,
CpUserId
:
cpUserId
,
Forbid
:
false
,
Timestamp
:
time
.
Now
()
.
Unix
(),
})
if
err
!=
nil
{
return
err
}
//让自己踢出去。
/* if str, err := redisCli.GetRedis().Get(context.Background(), redis_key.GetPrefixGroupUserInMic(externalId)).Result(); err != nil {
if err != redis2.Nil {
return myerr.WrapErr(err)
}
} else {
if userInMic, err := strToUserInMic(str); err != nil {
return err
} else {
if micUser, err := GetMicUser(mic.model, userInMic.GroupUuid, userInMic.I); err != nil {
return err
} else {
if micUser != nil {
if err := micUser.LeaveByUser(userId, externalId); err != nil {
return err
}
}
}
}
}*/
//加入到麦上可能有人的集合中。
groupMicHasIn
(
mic
.
model
,
mic
.
GroupUuid
,
userId
)
...
...
@@ -250,12 +233,15 @@ func (mic *Mic) In(userId uint64, externalId string) error {
if
err
!=
nil
{
return
err
}
//r, err := redis2.NewScript(micInScript).Run(context.Background(), redisCli.GetRedis(), []string{redis.GetPrefixGroupMicUser(mic.groupUuid), strconv.Itoa(mic.i), redis.GetPrefixGroupUserMic(), externalId}, micUserStr, groupUserStr).Result()
script
:=
strings
.
Replace
(
strings
.
Replace
(
strings
.
Replace
(
strings
.
Replace
(
strings
.
Replace
(
micInScript
,
"{micExpire}"
,
strconv
.
Itoa
(
expireMinute
),
-
1
),
"{prefixGroupMicUser}"
,
redis_key
.
GetPrefixGroupMicUser
(
mic
.
GroupUuid
,
mic
.
I
),
-
1
),
"{micUserStr}"
,
micUserStr
,
-
1
),
"{prefixGroupUserMic}"
,
redis_key
.
GetPrefixGroupUserInMic
(
externalId
),
-
1
),
"{groupUserStr}"
,
groupUserStr
,
-
1
)
//redisCli.GetRedis().ScriptFlush(context.Background())
strings
.
Replace
(
micInScript
,
"{micExpire}"
,
strconv
.
Itoa
(
expireMinute
),
-
1
),
"{prefixGroupMicUser}"
,
redis_key
.
GetPrefixGroupMicUser
(
mic
.
GroupUuid
,
mic
.
I
),
-
1
),
"{micUserStr}"
,
micUserStr
,
-
1
),
"{prefixGroupUserMic}"
,
redis_key
.
GetPrefixGroupUserInMic
(
externalId
),
-
1
),
"{groupUserStr}"
,
groupUserStr
,
-
1
)
r
,
err
:=
redis2
.
NewScript
(
script
)
.
Run
(
context
.
Background
(),
redisCli
.
GetRedis
(),
[]
string
{})
.
Result
()
mic
.
model
.
Log
.
Infof
(
"micUser In micInScript:%v, result:%v"
,
script
,
r
)
d
:=
r
.
(
int64
)
...
...
domain/model/group_m/micData.go
View file @
8b63b8f3
...
...
@@ -42,6 +42,13 @@ type MicContent struct {
Timestamp
int64
`json:"timestamp"`
//用户
User
*
MicUserData
`json:"user"`
//cp特效
CpEffect
*
CpEffect
`json:"cpEffect"`
}
type
CpEffect
struct
{
Svga
string
`json:"svga"`
CpAvatar
string
`json:"cpAvatar"`
}
type
MicUserData
struct
{
...
...
domain/service/group_mic_s/group_mic.go
View file @
8b63b8f3
...
...
@@ -6,12 +6,14 @@ import (
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/mycontext"
"git.hilo.cn/hilo-common/resource/redisCli"
"git.hilo.cn/hilo-common/rpc"
uuid
"github.com/satori/go.uuid"
"hilo-group/_const/enum/group_e"
"hilo-group/_const/redis_key"
"hilo-group/domain/event/group_ev"
"hilo-group/domain/model/groupPower_m"
"hilo-group/domain/model/group_m"
"hilo-group/domain/model/user_m"
"hilo-group/domain/service/signal_s"
"hilo-group/myerr"
"hilo-group/myerr/bizerr"
...
...
@@ -124,14 +126,51 @@ func redisLock(key string, sign string, expiration time.Duration, callBack func(
//加入麦位,锁两秒
func
(
s
*
GroupMicService
)
GroupMicIn
(
groupUuid
string
,
i
int
,
userId
uint64
,
externalId
string
)
error
{
return
redisLock
(
redis_key
.
GetPrefixGroupMicUserInLock
(
userId
),
uuid
.
NewV4
()
.
String
(),
time
.
Second
*
2
,
func
()
error
{
model
:=
domain
.
CreateModelContext
(
s
.
svc
.
MyContext
)
// 填充cp麦位
var
cpUserId
uint64
var
cpI
int
if
cpRelation
,
_
:=
rpc
.
GetUserCpRelation
(
model
,
userId
);
cpRelation
!=
nil
{
micNumType
,
err
:=
group_m
.
GetMicNumType
(
model
,
groupUuid
)
if
err
!=
nil
{
return
err
}
_
,
micUsers
,
err
:=
group_m
.
GetAllMic
(
groupUuid
,
micNumType
)
if
err
!=
nil
{
return
err
}
for
_
,
u
:=
range
micUsers
{
if
u
.
UserId
==
cpRelation
.
CpUserId
{
cpUserId
=
u
.
UserId
cpI
=
u
.
I
break
}
}
}
err
:=
redisLock
(
redis_key
.
GetPrefixGroupMicUserInLock
(
userId
),
uuid
.
NewV4
()
.
String
(),
time
.
Second
*
2
,
func
()
error
{
model
:=
domain
.
CreateModel
(
s
.
svc
.
CtxAndDb
)
mic
,
err
:=
group_m
.
GetMic
(
model
,
groupUuid
,
i
)
if
err
!=
nil
{
return
err
}
return
mic
.
In
(
userId
,
externalId
)
return
mic
.
In
(
userId
,
externalId
,
cpUserId
)
})
if
err
!=
nil
{
return
err
}
// 更新麦上cp的信息
if
cpUserId
>
0
{
user
,
_
:=
user_m
.
GetUser
(
model
,
cpUserId
)
return
redisLock
(
redis_key
.
GetPrefixGroupMicUserInLock
(
cpUserId
),
uuid
.
NewV4
()
.
String
(),
time
.
Second
*
2
,
func
()
error
{
model
:=
domain
.
CreateModel
(
s
.
svc
.
CtxAndDb
)
mic
,
err
:=
group_m
.
GetMic
(
model
,
groupUuid
,
cpI
)
if
err
!=
nil
{
return
err
}
return
mic
.
In
(
cpUserId
,
user
.
ExternalId
,
userId
)
})
}
return
nil
}
//离开麦位
...
...
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