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
Compare Revisions
master...feature/onMic2
Source
feature/onMic2
Select Git revision
...
Target
master
Select Git revision
Compare
Commits (1)
userOnMic干掉
· 57a9ac4a
hujiebin
authored
Aug 24, 2023
57a9ac4a
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
0 additions
and
189 deletions
+0
-189
on_mic.go
cron/mic_cron/on_mic.go
+0
-7
mic.go
domain/model/mic_m/mic.go
+0
-105
inner.go
route/mic_r/inner.go
+0
-71
router.go
route/router.go
+0
-6
No files found.
cron/mic_cron/on_mic.go
View file @
57a9ac4a
...
@@ -57,13 +57,6 @@ func OnMicQueue() {
...
@@ -57,13 +57,6 @@ func OnMicQueue() {
}
else
{
}
else
{
model
.
Log
.
Infof
(
"cron micIn GroupPowerOnMicExp success, groupId:%v, userId:%v"
,
onMic
.
GroupUuid
,
onMic
.
UserId
)
model
.
Log
.
Infof
(
"cron micIn GroupPowerOnMicExp success, groupId:%v, userId:%v"
,
onMic
.
GroupUuid
,
onMic
.
UserId
)
}
}
// 用户上麦
//if err := mic_m.IncrUserOnMic(model, onMic.UserId, onMic.Timestamp); err != nil {
// model.Log.Errorf("cron micIn IncrUserOnMic err:%v", err)
//} else {
// model.Log.Infof("cron micIn IncrUserOnMic success,userId:%v", onMic.UserId)
//}
}
}
}
}
}()
}()
...
...
domain/model/mic_m/mic.go
View file @
57a9ac4a
package
mic_m
package
mic_m
import
(
"git.hilo.cn/hilo-common/_const/enum/timezone_e"
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/mysql"
"git.hilo.cn/hilo-common/utils"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"time"
)
// 用户上麦
type
UserOnMic
struct
{
Date
string
UserId
mysql
.
ID
Seconds
mysql
.
Num
LastCalTs
int64
CreatedTime
time
.
Time
`gorm:"->"`
UpdatedTime
time
.
Time
`gorm:"->"`
Tz
timezone_e
.
Timezone
}
// 获取用户当日上麦
// 允许返回gorm.ErrRecordNotFound
func
GetUserOnMic
(
model
*
domain
.
Model
,
userId
mysql
.
ID
,
tz
timezone_e
.
Timezone
)
(
*
UserOnMic
,
error
)
{
res
:=
new
(
UserOnMic
)
day
:=
time
.
Now
()
.
In
(
timezone_e
.
TimezoneLocMap
[
tz
])
.
Format
(
"2006-01-02"
)
if
err
:=
model
.
DB
()
.
Where
(
"date = ? AND user_id = ? AND tz = ?"
,
day
,
userId
,
tz
)
.
First
(
res
)
.
Error
;
err
!=
nil
{
return
nil
,
err
}
return
res
,
nil
}
// 增加用户上麦时长
// 事务操作
func
IncrUserOnMic
(
model
*
domain
.
Model
,
userId
mysql
.
ID
,
joinMicTimestamp
int64
)
error
{
return
model
.
Transaction
(
func
(
model
*
domain
.
Model
)
error
{
for
_
,
tz
:=
range
timezone_e
.
Timezones
{
omMic
,
err
:=
GetUserOnMic
(
model
,
userId
,
tz
)
if
err
!=
nil
&&
err
!=
gorm
.
ErrRecordNotFound
{
return
err
}
curTs
:=
joinMicTimestamp
nowTs
:=
time
.
Now
()
.
Unix
()
day0Ts
:=
utils
.
GetZeroTime
(
time
.
Now
()
.
In
(
timezone_e
.
TimezoneLocMap
[
tz
]))
.
Unix
()
if
omMic
!=
nil
&&
joinMicTimestamp
<
omMic
.
LastCalTs
{
// 加入的时间比上次计算时间小
curTs
=
omMic
.
LastCalTs
}
// 跨天
if
curTs
<
day0Ts
{
curTs
=
day0Ts
}
score
:=
nowTs
-
curTs
day
:=
time
.
Now
()
.
In
(
timezone_e
.
TimezoneLocMap
[
tz
])
.
Format
(
"2006-01-02"
)
onMicNew
:=
&
UserOnMic
{
Date
:
day
,
UserId
:
userId
,
Seconds
:
mysql
.
Num
(
score
),
LastCalTs
:
nowTs
,
Tz
:
tz
,
}
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 + ?"
,
onMicNew
.
Seconds
),
"last_cal_ts"
:
nowTs
,
}),
})
.
Create
(
onMicNew
)
.
Error
;
err
!=
nil
{
model
.
Log
.
Errorf
(
"IncrUserOnMic fail:%v"
,
err
)
return
err
}
}
return
nil
})
}
// 批量获取用户上麦时长
// @return userId->seconds
func
MGetUserOnMicSeconds
(
model
*
domain
.
Model
,
day
string
,
tz
timezone_e
.
Timezone
,
userIds
[]
uint64
)
(
map
[
mysql
.
ID
]
mysql
.
Num
,
error
)
{
var
rows
[]
UserOnMic
res
:=
make
(
map
[
mysql
.
ID
]
mysql
.
Num
)
if
err
:=
model
.
DB
()
.
Model
(
UserOnMic
{})
.
Where
(
"`date`= ? AND tz = ? AND user_id in ?"
,
day
,
tz
,
userIds
)
.
Find
(
&
rows
)
.
Error
;
err
!=
nil
{
model
.
Log
.
Errorf
(
"MGetUserOnMic fail:%v"
,
err
)
return
res
,
err
}
for
_
,
r
:=
range
rows
{
res
[
r
.
UserId
]
=
r
.
Seconds
}
return
res
,
nil
}
// 批量获取用户上麦时长
// @return userId->seconds
func
MGetUserOnMicSecondsRange
(
model
*
domain
.
Model
,
beginDate
,
endDate
string
,
tz
timezone_e
.
Timezone
,
userIds
[]
uint64
)
(
map
[
mysql
.
ID
]
mysql
.
Num
,
error
)
{
var
rows
[]
UserOnMic
res
:=
make
(
map
[
mysql
.
ID
]
mysql
.
Num
)
if
err
:=
model
.
DB
()
.
Model
(
UserOnMic
{})
.
Where
(
"`date` >= ? AND `date` <= ? AND tz = ? AND user_id in ?"
,
beginDate
,
endDate
,
tz
,
userIds
)
.
Find
(
&
rows
)
.
Error
;
err
!=
nil
{
model
.
Log
.
Errorf
(
"MGetUserOnMic fail:%v"
,
err
)
return
res
,
err
}
for
_
,
r
:=
range
rows
{
res
[
r
.
UserId
]
+=
r
.
Seconds
}
return
res
,
nil
}
route/mic_r/inner.go
deleted
100644 → 0
View file @
1c13f8e5
package
mic_r
import
(
"git.hilo.cn/hilo-common/_const/enum/timezone_e"
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/mycontext"
"git.hilo.cn/hilo-common/resource/mysql"
"github.com/gin-gonic/gin"
"hilo-group/domain/model/mic_m"
"hilo-group/resp"
)
type
MGetUserOnMicSecondsReq
struct
{
Day
string
`form:"day" binding:"required"`
Ids
[]
mysql
.
ID
`form:"ids" binding:"required"`
Tz
timezone_e
.
Timezone
`form:"tz"`
}
// @Tags 麦位-内部
// @Summary 批量获取用户天上麦时长
// @Param day query string true "天 格式2006-001-02"
// @Param ids query string true "用户id,如:ids=1&ids=2&ids=3"
// @Param tz query string false "时区 0:北京时间(默认) 1:沙特时间"
// @Success 200 {object} map[uint64]uint32
// @Router /inner/mic/onMicSeconds [get]
func
MGetUserOnMicSeconds
(
c
*
gin
.
Context
)
(
*
mycontext
.
MyContext
,
error
)
{
myCtx
:=
mycontext
.
CreateMyContext
(
c
.
Keys
)
var
model
=
domain
.
CreateModelContext
(
myCtx
)
var
req
MGetUserOnMicSecondsReq
if
err
:=
c
.
ShouldBindQuery
(
&
req
);
err
!=
nil
{
return
myCtx
,
err
}
onMic
,
err
:=
mic_m
.
MGetUserOnMicSeconds
(
model
,
req
.
Day
,
req
.
Tz
,
req
.
Ids
)
if
err
!=
nil
{
return
myCtx
,
err
}
response
:=
onMic
resp
.
ResponseOk
(
c
,
response
)
return
myCtx
,
nil
}
type
MGetUserOnMicSecondsRangeReq
struct
{
BeginDate
string
`form:"beginDate" binding:"required"`
EndDate
string
`form:"endDate" binding:"required"`
Ids
[]
mysql
.
ID
`form:"ids" binding:"required"`
Tz
timezone_e
.
Timezone
`form:"tz"`
}
// @Tags 麦位-内部
// @Summary 批量获取用户范围上麦时长
// @Param beginDate query string true "天 格式2006-001-02"
// @Param endDate query string true "天 格式2006-001-02"
// @Param ids query string true "用户id,如:ids=1&ids=2&ids=3"
// @Param tz query string false "时区 0:北京时间(默认) 1:沙特时间"
// @Success 200 {object} map[uint64]uint32
// @Router /inner/mic/onMicSeconds/range [get]
func
MGetUserOnMicSecondsRange
(
c
*
gin
.
Context
)
(
*
mycontext
.
MyContext
,
error
)
{
myCtx
:=
mycontext
.
CreateMyContext
(
c
.
Keys
)
var
model
=
domain
.
CreateModelContext
(
myCtx
)
var
req
MGetUserOnMicSecondsRangeReq
if
err
:=
c
.
ShouldBindQuery
(
&
req
);
err
!=
nil
{
return
myCtx
,
err
}
onMic
,
err
:=
mic_m
.
MGetUserOnMicSecondsRange
(
model
,
req
.
BeginDate
,
req
.
EndDate
,
req
.
Tz
,
req
.
Ids
)
if
err
!=
nil
{
return
myCtx
,
err
}
response
:=
onMic
resp
.
ResponseOk
(
c
,
response
)
return
myCtx
,
nil
}
route/router.go
View file @
57a9ac4a
...
@@ -12,7 +12,6 @@ import (
...
@@ -12,7 +12,6 @@ import (
"hilo-group/route/charge_r"
"hilo-group/route/charge_r"
"hilo-group/route/group_power_r"
"hilo-group/route/group_power_r"
"hilo-group/route/group_r"
"hilo-group/route/group_r"
"hilo-group/route/mic_r"
)
)
func
InitRouter
()
*
gin
.
Engine
{
func
InitRouter
()
*
gin
.
Engine
{
...
@@ -160,11 +159,6 @@ func InitRouter() *gin.Engine {
...
@@ -160,11 +159,6 @@ func InitRouter() *gin.Engine {
{
{
innerGroupPower
.
GET
(
"/infos"
,
wrapper
(
group_power_r
.
MGetGroupPowers
))
innerGroupPower
.
GET
(
"/infos"
,
wrapper
(
group_power_r
.
MGetGroupPowers
))
}
}
innerMic
:=
inner
.
Group
(
"/mic"
)
{
innerMic
.
GET
(
"/onMicSeconds"
,
wrapper
(
mic_r
.
MGetUserOnMicSeconds
))
innerMic
.
GET
(
"/onMicSeconds/range"
,
wrapper
(
mic_r
.
MGetUserOnMicSecondsRange
))
}
r
.
GET
(
"/test"
,
wrapper
(
group_power_r
.
Test
))
r
.
GET
(
"/test"
,
wrapper
(
group_power_r
.
Test
))
return
r
return
r
}
}
...
...