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
e8e15102
Commit
e8e15102
authored
Aug 27, 2023
by
JiebinHu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:redis版本家族榜单
关键还是脚本同步逻辑!
parent
8a88c123
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
114 additions
and
27 deletions
+114
-27
group_power_star.go
_const/redis_key/groupPower_k/group_power_star.go
+16
-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
+83
-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
No files found.
_const/redis_key/groupPower_k/group_power_star.go
0 → 100644
View file @
e8e15102
package
groupPower_k
import
(
"fmt"
"hilo-group/_const/enum/groupPower_e"
"hilo-group/_const/redis_key"
)
// 家族之星榜单
// type: 1:送礼 2:活跃 3:收礼
const
GroupPowerStarPrefix
=
"groupPowerStar:${type}:${period}:${groupPowerId}"
// zset member:userId score:分数
func
GetGroupPowerStarRankKey
(
_type
groupPower_e
.
GroupPowerStarType
,
period
string
,
groupPowerId
uint64
)
string
{
return
redis_key
.
ReplaceKey
(
GroupPowerStarPrefix
,
fmt
.
Sprintf
(
"%d"
,
_type
),
period
,
fmt
.
Sprintf
(
"%d"
,
groupPowerId
))
}
cron/gift_cron/send_gift_redis.go
View file @
e8e15102
...
...
@@ -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 @
e8e15102
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/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"
}
{
key
:=
groupPower_k
.
GetGroupPowerStarRankKey
(
_type
,
period
,
groupPowerId
)
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
key
:=
groupPower_k
.
GetGroupPowerStarRankKey
(
_type
,
period
,
groupPowerId
)
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 @
e8e15102
...
...
@@ -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 @
e8e15102
...
...
@@ -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 @
e8e15102
...
...
@@ -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 @
e8e15102
...
...
@@ -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
}
...
...
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