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/power-redis
Source
feature/power-redis
Select Git revision
...
Target
master
Select Git revision
Compare
Commits (6)
feat:redis版本家族榜单
· e8e15102
JiebinHu
authored
Aug 27, 2023
关键还是脚本同步逻辑!
e8e15102
fix:榜单漏了日期
· 1ccc8c2f
JiebinHu
authored
Aug 27, 2023
1ccc8c2f
todo 一次性脚本
· 9068f714
JiebinHu
authored
Aug 27, 2023
9068f714
Update inner.go
· cc964ebf
JiebinHu
authored
Aug 27, 2023
cc964ebf
fix:date
· cc86dcee
JiebinHu
authored
Aug 27, 2023
cc86dcee
Update inner.go
· 170de993
JiebinHu
authored
Aug 27, 2023
170de993
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
207 additions
and
27 deletions
+207
-27
group_power_star.go
_const/redis_key/groupPower_k/group_power_star.go
+17
-0
send_gift_redis.go
cron/gift_cron/send_gift_redis.go
+5
-2
group_power_star.go
domain/cache/groupPower_c/group_power_star.go
+106
-0
group_star.go
domain/model/groupPower_m/group_star.go
+1
-22
group_mic.go
domain/service/group_mic_s/group_mic.go
+5
-1
group_power.go
route/group_power_r/group_power.go
+2
-1
group_rank.go
route/group_power_r/group_rank.go
+2
-1
inner.go
route/group_power_r/inner.go
+68
-0
router.go
route/router.go
+1
-0
No files found.
_const/redis_key/groupPower_k/group_power_star.go
0 → 100644
View file @
170de993
package
groupPower_k
import
(
"fmt"
"hilo-group/_const/enum/groupPower_e"
"hilo-group/_const/redis_key"
)
// 家族之星榜单
// type: 1:送礼 2:活跃 3:收礼
// date:天/周/月的开始时间
const
GroupPowerStarPrefix
=
"groupPowerStar:${type}:${period}:${groupPowerId}:${date}"
// zset member:userId score:分数
func
GetGroupPowerStarRankKey
(
_type
groupPower_e
.
GroupPowerStarType
,
period
string
,
groupPowerId
uint64
,
date
string
)
string
{
return
redis_key
.
ReplaceKey
(
GroupPowerStarPrefix
,
fmt
.
Sprintf
(
"%d"
,
_type
),
period
,
fmt
.
Sprintf
(
"%d"
,
groupPowerId
),
date
)
}
cron/gift_cron/send_gift_redis.go
View file @
170de993
...
...
@@ -9,6 +9,7 @@ import (
"hilo-group/_const/enum/gift_e"
"hilo-group/_const/enum/groupPower_e"
"hilo-group/domain/cache/gift_c"
"hilo-group/domain/cache/groupPower_c"
"hilo-group/domain/event/gift_ev"
"hilo-group/domain/model/groupPower_m"
"hilo-group/domain/model/group_m"
...
...
@@ -77,7 +78,8 @@ func groupPowerStar(model *domain.Model, sendGiftEvent *gift_ev.SendGiftEvent) {
if
err
:=
groupPower_m
.
IncrGroupPowerMonthStarScore
(
model
,
data
.
GroupPowerId
,
data
.
UserId
,
groupPower_e
.
GroupPowerStarTypeFamous
,
diamonds
,
0
);
err
!=
nil
{
model
.
Log
.
Errorf
(
"IncrGroupPowerMonthStarScore famous fail:%v"
,
err
)
}
if
err
:=
groupPower_m
.
IncrGroupPowerDayStarScore
(
model
,
data
.
GroupPowerId
,
data
.
UserId
,
groupPower_e
.
GroupPowerStarTypeFamous
,
diamonds
,
0
);
err
!=
nil
{
if
err
:=
groupPower_c
.
IncrGroupPowerDayStarScore
(
model
,
data
.
GroupPowerId
,
data
.
UserId
,
groupPower_e
.
GroupPowerStarTypeFamous
,
diamonds
);
err
!=
nil
{
model
.
Log
.
Errorf
(
"IncrGroupPowerDayStarScore famous fail:%v"
,
err
)
}
}
...
...
@@ -88,7 +90,8 @@ func groupPowerStar(model *domain.Model, sendGiftEvent *gift_ev.SendGiftEvent) {
if
err
:=
groupPower_m
.
IncrGroupPowerMonthStarScore
(
model
,
data
.
GroupPowerId
,
data
.
UserId
,
groupPower_e
.
GroupPowerStarTypeCharm
,
diamonds
,
0
);
err
!=
nil
{
model
.
Log
.
Errorf
(
"IncrGroupPowerMonthStarScore charm fail:%v"
,
err
)
}
if
err
:=
groupPower_m
.
IncrGroupPowerDayStarScore
(
model
,
data
.
GroupPowerId
,
data
.
UserId
,
groupPower_e
.
GroupPowerStarTypeCharm
,
diamonds
,
0
);
err
!=
nil
{
if
err
:=
groupPower_c
.
IncrGroupPowerDayStarScore
(
model
,
data
.
GroupPowerId
,
data
.
UserId
,
groupPower_e
.
GroupPowerStarTypeCharm
,
diamonds
);
err
!=
nil
{
model
.
Log
.
Errorf
(
"IncrGroupPowerDayStarScore charm fail:%v"
,
err
)
}
}
...
...
domain/cache/groupPower_c/group_power_star.go
0 → 100644
View file @
170de993
package
groupPower_c
import
(
"fmt"
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/mysql"
"github.com/go-redis/redis/v8"
"github.com/jinzhu/now"
"github.com/pkg/errors"
"github.com/spf13/cast"
"hilo-group/_const/enum/groupPower_e"
"hilo-group/_const/redis_key/groupPower_k"
"time"
)
// 家族之星-排名
type
GroupPowerStarRank
struct
{
Period
string
GroupPowerId
mysql
.
ID
UserId
mysql
.
ID
Type
groupPower_e
.
GroupPowerStarType
Score
mysql
.
Num
}
// 增加家族之星分数
func
IncrGroupPowerDayStarScore
(
model
*
domain
.
Model
,
groupPowerId
,
userId
mysql
.
ID
,
_type
groupPower_e
.
GroupPowerStarType
,
score
mysql
.
Num
)
error
{
ttl
:=
map
[
string
]
time
.
Duration
{
"day"
:
time
.
Hour
*
24
*
7
,
"week"
:
time
.
Hour
*
24
*
7
*
30
,
"month"
:
time
.
Hour
*
24
*
7
*
30
*
2
,
}
for
_
,
period
:=
range
[]
string
{
"day"
,
"week"
,
"month"
}
{
date
:=
""
switch
period
{
case
"day"
:
date
=
time
.
Now
()
.
Format
(
"2006-01-02"
)
case
"week"
:
date
=
now
.
BeginningOfWeek
()
.
Format
(
"2006-01-02"
)
case
"month"
:
date
=
now
.
BeginningOfMonth
()
.
Format
(
"2006-01-02"
)
}
key
:=
groupPower_k
.
GetGroupPowerStarRankKey
(
_type
,
period
,
groupPowerId
,
date
)
model
.
RedisCluster
.
ZIncrBy
(
model
,
key
,
float64
(
score
),
fmt
.
Sprintf
(
"%d"
,
userId
))
model
.
RedisCluster
.
Expire
(
model
,
key
,
ttl
[
period
])
}
return
nil
}
// 获取家族之星排行
func
GetGroupPowerStarRankPeriod
(
model
*
domain
.
Model
,
period
string
,
groupPowerId
mysql
.
ID
,
_type
groupPower_e
.
GroupPowerStarType
,
offset
,
limit
int
)
([]
*
GroupPowerStarRank
,
error
)
{
var
res
[]
*
GroupPowerStarRank
date
:=
""
switch
period
{
case
"day"
:
date
=
time
.
Now
()
.
Format
(
"2006-01-02"
)
case
"week"
:
date
=
now
.
BeginningOfWeek
()
.
Format
(
"2006-01-02"
)
case
"month"
:
date
=
now
.
BeginningOfMonth
()
.
Format
(
"2006-01-02"
)
}
if
len
(
date
)
<=
0
{
return
res
,
errors
.
New
(
"illegal date"
)
}
key
:=
groupPower_k
.
GetGroupPowerStarRankKey
(
_type
,
period
,
groupPowerId
,
date
)
rows
,
err
:=
model
.
RedisCluster
.
ZRevRangeByScoreWithScores
(
model
,
key
,
&
redis
.
ZRangeBy
{
Min
:
"-inf"
,
Max
:
"+inf"
,
Offset
:
int64
(
offset
),
Count
:
int64
(
limit
),
})
.
Result
()
if
err
!=
nil
{
model
.
Log
.
Errorf
(
"GetGroupPowerStarRankPeriod fail:%v"
,
err
)
return
res
,
err
}
for
_
,
v
:=
range
rows
{
res
=
append
(
res
,
&
GroupPowerStarRank
{
Period
:
period
,
GroupPowerId
:
groupPowerId
,
UserId
:
cast
.
ToUint64
(
v
.
Member
),
Type
:
_type
,
Score
:
mysql
.
Num
(
v
.
Score
),
})
}
return
res
,
nil
}
// 获取家族之星三个排行榜的各自第一名
func
GetGroupPowerMonthStartTop1
(
model
*
domain
.
Model
,
groupPowerId
mysql
.
ID
)
([]
*
GroupPowerStarRank
,
error
)
{
var
res
[]
*
GroupPowerStarRank
r1
,
err
:=
GetGroupPowerStarRankPeriod
(
model
,
"month"
,
groupPowerId
,
groupPower_e
.
GroupPowerStarTypeFamous
,
0
,
1
)
if
err
!=
nil
{
return
res
,
err
}
r2
,
err
:=
GetGroupPowerStarRankPeriod
(
model
,
"month"
,
groupPowerId
,
groupPower_e
.
GroupPowerStarTypeActive
,
0
,
1
)
if
err
!=
nil
{
return
res
,
err
}
r3
,
err
:=
GetGroupPowerStarRankPeriod
(
model
,
"month"
,
groupPowerId
,
groupPower_e
.
GroupPowerStarTypeCharm
,
0
,
1
)
if
err
!=
nil
{
return
res
,
err
}
res
=
append
(
res
,
r1
...
)
res
=
append
(
res
,
r2
...
)
res
=
append
(
res
,
r3
...
)
return
res
,
nil
}
domain/model/groupPower_m/group_star.go
View file @
170de993
...
...
@@ -59,6 +59,7 @@ func IncrGroupPowerMonthStarScore(model *domain.Model, groupPowerId, userId mysq
}
// 增加家族之星分数
// Deprecated: 用redis代替
func
IncrGroupPowerDayStarScore
(
model
*
domain
.
Model
,
groupPowerId
,
userId
mysql
.
ID
,
_type
groupPower_e
.
GroupPowerStarType
,
score
mysql
.
Num
,
lastCalTs
int64
)
error
{
star
:=
&
GroupPowerDayStar
{
Date
:
time
.
Now
(),
...
...
@@ -81,28 +82,6 @@ func IncrGroupPowerDayStarScore(model *domain.Model, groupPowerId, userId mysql.
return
nil
}
// 获取家族之星分数
// 允许返回gorm.ErrRecordNotFound
func
GetGroupPowerDayStar
(
model
*
domain
.
Model
,
groupPowerId
,
userId
mysql
.
ID
,
_type
groupPower_e
.
GroupPowerStarType
)
(
*
GroupPowerDayStar
,
error
)
{
res
:=
new
(
GroupPowerDayStar
)
date
:=
time
.
Now
()
if
err
:=
model
.
DB
()
.
Where
(
"date = ? AND group_power_id = ? AND user_id = ? AND `type` = ?"
,
date
.
Format
(
"2006-01-02"
),
groupPowerId
,
userId
,
_type
)
.
First
(
res
)
.
Error
;
err
!=
nil
{
return
nil
,
err
}
return
res
,
nil
}
// 获取家族之星分数
// 允许返回gorm.ErrRecordNotFound
func
GetGroupPowerMonthStar
(
model
*
domain
.
Model
,
groupPowerId
,
userId
mysql
.
ID
,
_type
groupPower_e
.
GroupPowerStarType
)
(
*
GroupPowerMonthStar
,
error
)
{
res
:=
new
(
GroupPowerMonthStar
)
month
:=
time
.
Now
()
.
Format
(
"200601"
)
if
err
:=
model
.
DB
()
.
Where
(
"month = ? AND group_power_id = ? AND user_id = ? AND `type` = ?"
,
month
,
groupPowerId
,
userId
,
_type
)
.
First
(
res
)
.
Error
;
err
!=
nil
{
return
nil
,
err
}
return
res
,
nil
}
// 获取家族之星排行
func
GetGroupPowerMonthStarRank
(
model
*
domain
.
Model
,
groupPowerId
mysql
.
ID
,
_type
groupPower_e
.
GroupPowerStarType
,
offset
,
limit
int
,
month
string
)
([]
*
GroupPowerMonthStar
,
error
)
{
var
res
[]
*
GroupPowerMonthStar
...
...
domain/service/group_mic_s/group_mic.go
View file @
170de993
...
...
@@ -8,8 +8,10 @@ import (
"git.hilo.cn/hilo-common/resource/redisCli"
"git.hilo.cn/hilo-common/rpc"
uuid
"github.com/satori/go.uuid"
"hilo-group/_const/enum/groupPower_e"
"hilo-group/_const/enum/group_e"
"hilo-group/_const/redis_key"
"hilo-group/domain/cache/groupPower_c"
"hilo-group/domain/event/group_ev"
"hilo-group/domain/model/groupPower_m"
"hilo-group/domain/model/group_m"
...
...
@@ -325,7 +327,9 @@ func (s *GroupMicService) IncrGroupPowerOnMicExpAndTime(groupId string, userId u
model
.
Log
.
Errorf
(
"IncrGroupPowerStarOnMicMonth fail:%v"
,
err
)
}
// 增加势力上麦时长-天
if
err
:=
groupPower_m
.
IncrGroupPowerStarOnMicDay
(
model
,
groupPowerId
,
userId
,
joinMicTimestamp
);
err
!=
nil
{
//if err := groupPower_m.IncrGroupPowerStarOnMicDay(model, groupPowerId, userId, joinMicTimestamp); err != nil {
if
err
:=
groupPower_c
.
IncrGroupPowerDayStarScore
(
model
,
groupPowerId
,
userId
,
groupPower_e
.
GroupPowerStarTypeActive
,
60
);
err
!=
nil
{
model
.
Log
.
Errorf
(
"IncrGroupPowerStarOnMicDay fail:%v"
,
err
)
}
return
nil
...
...
route/group_power_r/group_power.go
View file @
170de993
...
...
@@ -23,6 +23,7 @@ import (
"hilo-group/cv/group_power_cv"
"hilo-group/cv/medal_cv"
"hilo-group/cv/user_cv"
"hilo-group/domain/cache/groupPower_c"
"hilo-group/domain/cache/res_c"
"hilo-group/domain/cache/user_c"
"hilo-group/domain/model/game_m"
...
...
@@ -820,7 +821,7 @@ func GroupPowerInfo(c *gin.Context) (*mycontext.MyContext, error) {
}
}
// 补上家族之星三个榜一
stars
,
err
:=
groupPower_
m
.
GetGroupPowerMonthStartTop1
(
model
,
gp
.
ID
)
stars
,
err
:=
groupPower_
c
.
GetGroupPowerMonthStartTop1
(
model
,
gp
.
ID
)
if
err
!=
nil
{
return
myContext
,
myerr
.
WrapErr
(
err
)
}
...
...
route/group_power_r/group_rank.go
View file @
170de993
...
...
@@ -10,6 +10,7 @@ import (
"hilo-group/_const/enum/groupPower_e"
"hilo-group/cv/group_power_cv"
"hilo-group/cv/user_cv"
"hilo-group/domain/cache/groupPower_c"
"hilo-group/domain/model/groupPower_m"
"hilo-group/domain/model/user_m"
"hilo-group/domain/service/group_power_s"
...
...
@@ -264,7 +265,7 @@ func GroupPowerStarPeriod(c *gin.Context) (*mycontext.MyContext, error) {
}
var
model
=
domain
.
CreateModelContext
(
myContext
)
offset
,
limit
:=
(
param
.
PageIndex
-
1
)
*
param
.
PageSize
,
param
.
PageSize
rank
,
err
:=
groupPower_
m
.
GetGroupPowerStarRankPeriod
(
model
,
period
,
param
.
GroupPowerId
,
param
.
Type
,
offset
,
limit
)
rank
,
err
:=
groupPower_
c
.
GetGroupPowerStarRankPeriod
(
model
,
period
,
param
.
GroupPowerId
,
param
.
Type
,
offset
,
limit
)
if
err
!=
nil
{
return
myContext
,
err
}
...
...
route/group_power_r/inner.go
View file @
170de993
package
group_power_r
import
(
"fmt"
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/mycontext"
"git.hilo.cn/hilo-common/resource/mysql"
"github.com/gin-gonic/gin"
"github.com/jinzhu/now"
"hilo-group/_const/enum/groupPower_e"
"hilo-group/_const/enum/msg_e"
"hilo-group/_const/redis_key/groupPower_k"
"hilo-group/cv/group_power_cv"
"hilo-group/domain/model/groupPower_m"
"hilo-group/domain/model/msg_m"
"hilo-group/domain/model/user_m"
"hilo-group/domain/service/group_power_s"
"hilo-group/myerr/bizerr"
"hilo-group/resp"
"time"
)
type
MGetGroupPowerReq
struct
{
...
...
@@ -93,3 +98,66 @@ func Test(c *gin.Context) (*mycontext.MyContext, error) {
//}
return
nil
,
nil
}
type
GroupPowerDayStar
struct
{
Date
time
.
Time
GroupPowerId
uint64
Type
groupPower_e
.
GroupPowerStarType
UserId
uint64
Score
uint64
}
// @Tags 国家势力-内部
// @Summary 同步家族之星到redis
// @Success 200
// @Router /inner/groupPower/sync/star [get]
func
SyncStar
(
c
*
gin
.
Context
)
(
*
mycontext
.
MyContext
,
error
)
{
myCtx
:=
mycontext
.
CreateMyContext
(
c
.
Keys
)
t
:=
time
.
Now
()
start
:=
c
.
Query
(
"start"
)
end
:=
c
.
Query
(
"end"
)
if
len
(
start
)
<=
0
||
len
(
end
)
<=
0
{
return
myCtx
,
bizerr
.
InvalidParameter
}
var
model
=
domain
.
CreateModelContext
(
myCtx
)
var
stars
[]
GroupPowerDayStar
if
err
:=
model
.
DB
()
.
Table
(
"group_power_day_star"
)
.
Select
(
"`date`,group_power_id,type,user_id,SUM(score) score"
)
.
Where
(
"`date` BETWEEN ? AND ?"
,
start
,
end
)
.
Group
(
"`date`,group_power_id,type,user_id"
)
.
Find
(
&
stars
)
.
Error
;
err
!=
nil
{
model
.
Log
.
Errorf
(
"SyncStar fail:%v"
,
err
)
return
myCtx
,
err
}
ttl
:=
map
[
string
]
time
.
Duration
{
"day"
:
time
.
Hour
*
24
*
7
,
"week"
:
time
.
Hour
*
24
*
7
*
30
,
"month"
:
time
.
Hour
*
24
*
7
*
30
*
2
,
}
num
:=
len
(
stars
)
for
i
,
star
:=
range
stars
{
for
_
,
period
:=
range
[]
string
{
"day"
,
"week"
,
"month"
}
{
var
dateStr
string
switch
period
{
case
"day"
:
dateStr
=
star
.
Date
.
Format
(
"2006-01-02"
)
case
"week"
:
dateStr
=
now
.
With
(
star
.
Date
)
.
BeginningOfWeek
()
.
Format
(
"2006-01-02"
)
case
"month"
:
dateStr
=
now
.
With
(
star
.
Date
)
.
BeginningOfMonth
()
.
Format
(
"2006-01-02"
)
}
key
:=
groupPower_k
.
GetGroupPowerStarRankKey
(
star
.
Type
,
period
,
star
.
GroupPowerId
,
dateStr
)
model
.
RedisCluster
.
ZIncrBy
(
model
,
key
,
float64
(
star
.
Score
),
fmt
.
Sprintf
(
"%d"
,
star
.
UserId
))
model
.
RedisCluster
.
Expire
(
model
,
key
,
ttl
[
period
])
model
.
Log
.
Infof
(
"SyncStar i:%v,star:%v"
,
i
,
star
)
}
}
type
res
struct
{
Num
int
Cost
float64
}
resp
.
ResponseOk
(
c
,
res
{
Num
:
num
,
Cost
:
time
.
Now
()
.
Sub
(
t
)
.
Seconds
(),
})
return
myCtx
,
nil
}
route/router.go
View file @
170de993
...
...
@@ -159,6 +159,7 @@ func InitRouter() *gin.Engine {
innerGroupPower
:=
inner
.
Group
(
"/groupPower"
)
{
innerGroupPower
.
GET
(
"/infos"
,
wrapper
(
group_power_r
.
MGetGroupPowers
))
innerGroupPower
.
GET
(
"/sync/star"
,
wrapper
(
group_power_r
.
SyncStar
))
// todo 一次性脚本
}
innerMic
:=
inner
.
Group
(
"/mic"
)
{
...
...