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
04b986e8
Commit
04b986e8
authored
Aug 26, 2023
by
JiebinHu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:1分钟统一60秒
parent
d41ec14f
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
33 deletions
+61
-33
on_mic.go
cron/mic_cron/on_mic.go
+2
-1
group_grade.go
domain/model/groupPower_m/group_grade.go
+36
-32
mic.go
domain/model/mic_m/mic.go
+23
-0
No files found.
cron/mic_cron/on_mic.go
View file @
04b986e8
...
@@ -63,7 +63,8 @@ func OnMicQueue() {
...
@@ -63,7 +63,8 @@ func OnMicQueue() {
}
}
// 用户上麦
// 用户上麦
if
err
:=
mic_m
.
IncrUserOnMic
(
model
,
onMic
.
UserId
,
onMic
.
Timestamp
);
err
!=
nil
{
//if err := mic_m.IncrUserOnMic(model, onMic.UserId, onMic.Timestamp); err != nil {
if
err
:=
mic_m
.
IncrUserOnMicV2
(
model
,
onMic
.
UserId
);
err
!=
nil
{
model
.
Log
.
Errorf
(
"cron micIn IncrUserOnMic err:%v"
,
err
)
model
.
Log
.
Errorf
(
"cron micIn IncrUserOnMic err:%v"
,
err
)
}
else
{
}
else
{
model
.
Log
.
Infof
(
"cron micIn IncrUserOnMic success,userId:%v,cost:%vs"
,
onMic
.
UserId
,
time
.
Now
()
.
Sub
(
start
)
.
Seconds
())
model
.
Log
.
Infof
(
"cron micIn IncrUserOnMic success,userId:%v,cost:%vs"
,
onMic
.
UserId
,
time
.
Now
()
.
Sub
(
start
)
.
Seconds
())
...
...
domain/model/groupPower_m/group_grade.go
View file @
04b986e8
...
@@ -158,22 +158,24 @@ func IncrGroupPowerExpOnMic(model *domain.Model, groupPowerId, userId mysql.ID)
...
@@ -158,22 +158,24 @@ func IncrGroupPowerExpOnMic(model *domain.Model, groupPowerId, userId mysql.ID)
// 事务操作
// 事务操作
func
IncrGroupPowerStarOnMicMonth
(
model
*
domain
.
Model
,
groupPowerId
,
userId
mysql
.
ID
,
joinMicTimestamp
int64
)
error
{
func
IncrGroupPowerStarOnMicMonth
(
model
*
domain
.
Model
,
groupPowerId
,
userId
mysql
.
ID
,
joinMicTimestamp
int64
)
error
{
// 月统计
// 月统计
star
,
err
:=
GetGroupPowerMonthStar
(
model
,
groupPowerId
,
userId
,
groupPower_e
.
GroupPowerStarTypeActive
)
//star, err := GetGroupPowerMonthStar(model, groupPowerId, userId, groupPower_e.GroupPowerStarTypeActive)
curTs
:=
joinMicTimestamp
//curTs := joinMicTimestamp
nowTs
:=
time
.
Now
()
.
Unix
()
//nowTs := time.Now().Unix()
month0Ts
:=
now
.
BeginningOfMonth
()
.
Unix
()
//month0Ts := now.BeginningOfMonth().Unix()
if
err
!=
nil
&&
err
!=
gorm
.
ErrRecordNotFound
{
//if err != nil && err != gorm.ErrRecordNotFound {
return
err
// return err
}
//}
if
star
!=
nil
&&
joinMicTimestamp
<
star
.
LastCalTs
{
// 加入的时间比上次计算时间小
//if star != nil && joinMicTimestamp < star.LastCalTs { // 加入的时间比上次计算时间小
curTs
=
star
.
LastCalTs
// curTs = star.LastCalTs
}
//}
// 跨月
//// 跨月
if
curTs
<
month0Ts
{
//if curTs < month0Ts {
curTs
=
month0Ts
// curTs = month0Ts
}
//}
score
:=
nowTs
-
curTs
//score := nowTs - curTs
err
=
IncrGroupPowerMonthStarScore
(
model
,
groupPowerId
,
userId
,
groupPower_e
.
GroupPowerStarTypeActive
,
mysql
.
Num
(
score
),
nowTs
)
score
:=
60
err
:=
IncrGroupPowerMonthStarScore
(
model
,
groupPowerId
,
userId
,
groupPower_e
.
GroupPowerStarTypeActive
,
mysql
.
Num
(
score
),
0
)
return
err
return
err
}
}
...
@@ -181,22 +183,24 @@ func IncrGroupPowerStarOnMicMonth(model *domain.Model, groupPowerId, userId mysq
...
@@ -181,22 +183,24 @@ func IncrGroupPowerStarOnMicMonth(model *domain.Model, groupPowerId, userId mysq
// 事务操作
// 事务操作
func
IncrGroupPowerStarOnMicDay
(
model
*
domain
.
Model
,
groupPowerId
,
userId
mysql
.
ID
,
joinMicTimestamp
int64
)
error
{
func
IncrGroupPowerStarOnMicDay
(
model
*
domain
.
Model
,
groupPowerId
,
userId
mysql
.
ID
,
joinMicTimestamp
int64
)
error
{
// 日统计
// 日统计
star
,
err
:=
GetGroupPowerDayStar
(
model
,
groupPowerId
,
userId
,
groupPower_e
.
GroupPowerStarTypeActive
)
//star, err := GetGroupPowerDayStar(model, groupPowerId, userId, groupPower_e.GroupPowerStarTypeActive)
curTs
:=
joinMicTimestamp
//curTs := joinMicTimestamp
nowTs
:=
time
.
Now
()
.
Unix
()
//nowTs := time.Now().Unix()
day0Ts
:=
now
.
BeginningOfDay
()
.
Unix
()
//day0Ts := now.BeginningOfDay().Unix()
if
err
!=
nil
&&
err
!=
gorm
.
ErrRecordNotFound
{
//if err != nil && err != gorm.ErrRecordNotFound {
return
err
// return err
}
//}
if
star
!=
nil
&&
joinMicTimestamp
<
star
.
LastCalTs
{
// 加入的时间比上次计算时间小
//if star != nil && joinMicTimestamp < star.LastCalTs { // 加入的时间比上次计算时间小
curTs
=
star
.
LastCalTs
// curTs = star.LastCalTs
}
//}
// 跨天
//// 跨天
if
curTs
<
day0Ts
{
//if curTs < day0Ts {
curTs
=
day0Ts
// curTs = day0Ts
}
//}
score
:=
nowTs
-
curTs
//score := nowTs - curTs
err
=
IncrGroupPowerDayStarScore
(
model
,
groupPowerId
,
userId
,
groupPower_e
.
GroupPowerStarTypeActive
,
mysql
.
Num
(
score
),
nowTs
)
score
:=
60
err
:=
IncrGroupPowerDayStarScore
(
model
,
groupPowerId
,
userId
,
groupPower_e
.
GroupPowerStarTypeActive
,
mysql
.
Num
(
score
),
0
)
return
err
return
err
}
}
...
...
domain/model/mic_m/mic.go
View file @
04b986e8
...
@@ -75,6 +75,29 @@ func IncrUserOnMic(model *domain.Model, userId mysql.ID, joinMicTimestamp int64)
...
@@ -75,6 +75,29 @@ func IncrUserOnMic(model *domain.Model, userId mysql.ID, joinMicTimestamp int64)
})
})
}
}
// 增加用户上麦时长
// 事务操作
func
IncrUserOnMicV2
(
model
*
domain
.
Model
,
userId
mysql
.
ID
)
error
{
for
_
,
tz
:=
range
timezone_e
.
Timezones
{
day
:=
time
.
Now
()
.
In
(
timezone_e
.
TimezoneLocMap
[
tz
])
.
Format
(
"2006-01-02"
)
if
err
:=
model
.
DB
()
.
Model
(
UserOnMic
{})
.
Clauses
(
clause
.
OnConflict
{
Columns
:
[]
clause
.
Column
{{
Name
:
"date"
},
{
Name
:
"user_id"
},
{
Name
:
"tz"
}},
DoUpdates
:
clause
.
Assignments
(
map
[
string
]
interface
{}{
"seconds"
:
gorm
.
Expr
(
"seconds + ?"
,
60
),
}),
})
.
Create
(
&
UserOnMic
{
Date
:
day
,
UserId
:
userId
,
Seconds
:
60
,
Tz
:
tz
,
})
.
Error
;
err
!=
nil
{
model
.
Log
.
Errorf
(
"IncrUserOnMic fail:%v"
,
err
)
return
err
}
}
return
nil
}
// 批量获取用户上麦时长
// 批量获取用户上麦时长
// @return userId->seconds
// @return userId->seconds
func
MGetUserOnMicSeconds
(
model
*
domain
.
Model
,
day
string
,
tz
timezone_e
.
Timezone
,
userIds
[]
uint64
)
(
map
[
mysql
.
ID
]
mysql
.
Num
,
error
)
{
func
MGetUserOnMicSeconds
(
model
*
domain
.
Model
,
day
string
,
tz
timezone_e
.
Timezone
,
userIds
[]
uint64
)
(
map
[
mysql
.
ID
]
mysql
.
Num
,
error
)
{
...
...
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