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...fix/group_support_old_data
Source
fix/group_support_old_data
Select Git revision
...
Target
master
Select Git revision
Compare
Commits (1)
group support
· 58041891
chenweijian
authored
Aug 25, 2023
58041891
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
82 additions
and
75 deletions
+82
-75
cron.go
cron/cron.go
+3
-2
group_support.go
cron/group_cron/group_support.go
+79
-73
No files found.
cron/cron.go
View file @
58041891
...
@@ -21,4 +21,5 @@ func Init() {
...
@@ -21,4 +21,5 @@ func Init() {
//group_cron.GroupInEventInit() // 进房事件
//group_cron.GroupInEventInit() // 进房事件
group_cron
.
CreateGroup
()
//
group_cron
.
CreateGroup
()
//
group_cron
.
CalcGroupSupport
()
// 群组扶持计算
group_cron
.
CalcGroupSupport
()
// 群组扶持计算
group_cron
.
CalcGroupSupport_OldData
()
}
}
cron/group_cron/group_support.go
View file @
58041891
package
group_cron
package
group_cron
import
(
import
(
"context"
"encoding/json"
"encoding/json"
"git.hilo.cn/hilo-common/_const/rediskey"
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/config"
"git.hilo.cn/hilo-common/resource/config"
"git.hilo.cn/hilo-common/resource/redisCli"
"git.hilo.cn/hilo-common/sdk/tencentyun"
"git.hilo.cn/hilo-common/sdk/tencentyun"
"git.hilo.cn/hilo-common/utils"
"git.hilo.cn/hilo-common/utils"
"github.com/robfig/cron"
"github.com/robfig/cron"
"hilo-group/_const/enum/gift_e"
"hilo-group/_const/enum/group_e"
"hilo-group/_const/enum/group_e"
"hilo-group/domain/model/gift_m"
"hilo-group/domain/model/group_m"
"hilo-group/domain/model/group_m"
"hilo-group/domain/service/group_s"
"hilo-group/domain/service/group_s"
"time"
"time"
...
@@ -86,76 +91,77 @@ func sendGroupSupportH5(model *domain.Model) error {
...
@@ -86,76 +91,77 @@ func sendGroupSupportH5(model *domain.Model) error {
return
nil
return
nil
}
}
// 群组扶持计算-本周旧数据
// 群组扶持计算-旧数据
//func CalcGroupSupport_OldData() {
func
CalcGroupSupport_OldData
()
{
// if !config.IsMaster() {
if
!
config
.
IsMaster
()
{
// return
return
// }
}
// c := cron.New()
c
:=
cron
.
New
()
// spec := "0 30 10 24 8 ?"
spec
:=
"0 20 11 25 8 ?"
// _ = c.AddFunc(spec, func() {
_
=
c
.
AddFunc
(
spec
,
func
()
{
// defer utils.CheckGoPanic()
defer
utils
.
CheckGoPanic
()
// var model = domain.CreateModelNil()
var
model
=
domain
.
CreateModelNil
()
// //开始
//开始
// model.Log.Infof("CalcGroupSupport_OldData start")
model
.
Log
.
Infof
(
"CalcGroupSupport_OldData start"
)
//
// beginTime, _, period := group_m.GetSupportLevelTime(time.Now())
beginTime
,
endTime
,
period
:=
group_m
.
GetSupportLevelTime
(
time
.
Now
()
.
AddDate
(
0
,
0
,
-
group_e
.
SUPPORT_LEVEL_PERIOD_DAY
))
// endTime := time.Unix(1692843600, 0)
//beginTime, _, period := group_m.GetSupportLevelTime(time.Now())
//
//endTime := time.Unix(1692843600, 0)
// g := gift_m.GiftOperate{SceneType: gift_e.GroupSceneType, Model: model}
// records, err := g.BatchGetConsumeByRange(beginTime, endTime)
g
:=
gift_m
.
GiftOperate
{
SceneType
:
gift_e
.
GroupSceneType
,
Model
:
model
}
// if err != nil {
records
,
err
:=
g
.
BatchGetConsumeByRange
(
beginTime
,
endTime
)
// model.Log.Errorf("CalcGroupSupport_OldData beginTime:%v, endTime:%v, err:%v", beginTime, endTime, err)
if
err
!=
nil
{
// return
model
.
Log
.
Errorf
(
"CalcGroupSupport_OldData beginTime:%v, endTime:%v, err:%v"
,
beginTime
,
endTime
,
err
)
// }
return
// // 流水写入redis
}
// keyDiamond := rediskey.GetGroupSupportConsumeSummary(period)
// 流水写入redis
// for _, r := range records {
keyDiamond
:=
rediskey
.
GetGroupSupportConsumeSummary
(
period
)
// if r.SceneUid == "" || r.Consume <= 0 {
for
_
,
r
:=
range
records
{
// continue
if
r
.
SceneUid
==
""
||
r
.
Consume
<=
0
{
// }
continue
// _, err = model.RedisCluster.ZIncrBy(context.Background(), keyDiamond, float64(r.Consume), r.SceneUid).Result()
}
// if err != nil {
_
,
err
=
model
.
RedisCluster
.
ZIncrBy
(
context
.
Background
(),
keyDiamond
,
float64
(
r
.
Consume
),
r
.
SceneUid
)
.
Result
()
// model.Log.Errorf("CalcGroupSupport_OldData groupSupport key:%s, val:%d, member:%s, err:%v",
if
err
!=
nil
{
// keyDiamond, r.Consume, r.SceneUid, err)
model
.
Log
.
Errorf
(
"CalcGroupSupport_OldData groupSupport key:%s, val:%d, member:%s, err:%v"
,
// }
keyDiamond
,
r
.
Consume
,
r
.
SceneUid
,
err
)
// }
}
// err = redisCli.SetExpire(model.RedisCluster, keyDiamond, time.Hour*24*14) // 保留两周
}
// if err != nil {
err
=
redisCli
.
SetExpire
(
model
.
RedisCluster
,
keyDiamond
,
time
.
Hour
*
24
*
14
)
// 保留两周
// model.Log.Errorf("CalcGroupSupport_OldData groupSupport key:%s, err:%v", keyDiamond, err)
if
err
!=
nil
{
// return
model
.
Log
.
Errorf
(
"CalcGroupSupport_OldData groupSupport key:%s, err:%v"
,
keyDiamond
,
err
)
// }
return
// // 支持者写入redis
}
// for _, r := range records {
// 支持者写入redis
// if r.SceneUid == "" || r.C <= 0 {
for
_
,
r
:=
range
records
{
// continue
if
r
.
SceneUid
==
""
||
r
.
C
<=
0
{
// }
continue
// // 支持者列表
}
// support := gift_m.GiftOperate{SceneType: gift_e.GroupSceneType, SceneUid: r.SceneUid, Model: model}
// 支持者列表
// uids, err := support.BatchGetSupportList(beginTime, endTime)
support
:=
gift_m
.
GiftOperate
{
SceneType
:
gift_e
.
GroupSceneType
,
SceneUid
:
r
.
SceneUid
,
Model
:
model
}
// if err != nil {
uids
,
err
:=
support
.
BatchGetSupportList
(
beginTime
,
endTime
)
// model.Log.Errorf("CalcGroupSupport_OldData beginTime:%v, endTime:%v, imGroupId:%v, err:%v", beginTime, endTime, r.SceneUid, err)
if
err
!=
nil
{
// continue
model
.
Log
.
Errorf
(
"CalcGroupSupport_OldData beginTime:%v, endTime:%v, imGroupId:%v, err:%v"
,
beginTime
,
endTime
,
r
.
SceneUid
,
err
)
// }
continue
// if len(uids) <= 0 {
}
// continue
if
len
(
uids
)
<=
0
{
// }
continue
// // 支持者数量
}
// keySupportNum := rediskey.GetGroupSupportCountSupporter(period, r.SceneUid)
// 支持者数量
// for _, uid := range uids {
keySupportNum
:=
rediskey
.
GetGroupSupportCountSupporter
(
period
,
r
.
SceneUid
)
// err = model.RedisCluster.SAdd(context.Background(), keySupportNum, uid).Err()
for
_
,
uid
:=
range
uids
{
// if err != nil {
err
=
model
.
RedisCluster
.
SAdd
(
context
.
Background
(),
keySupportNum
,
uid
)
.
Err
()
// model.Log.Errorf("CalcGroupSupport_OldData groupSupport key:%s, UserId:%d, err:%v", keySupportNum, uid, err)
if
err
!=
nil
{
// }
model
.
Log
.
Errorf
(
"CalcGroupSupport_OldData groupSupport key:%s, UserId:%d, err:%v"
,
keySupportNum
,
uid
,
err
)
// }
}
// err = redisCli.SetExpire(model.RedisCluster, keySupportNum, time.Hour*24*14) // 保留两周
}
// if err != nil {
err
=
redisCli
.
SetExpire
(
model
.
RedisCluster
,
keySupportNum
,
time
.
Hour
*
24
*
14
)
// 保留两周
// model.Log.Errorf("AddSendGiftEventAsync groupSupport key:%s, err:%v", keySupportNum, err)
if
err
!=
nil
{
// }
model
.
Log
.
Errorf
(
"AddSendGiftEventAsync groupSupport key:%s, err:%v"
,
keySupportNum
,
err
)
// }
}
//
}
// model.Log.Infof("CalcGroupSupport_OldData end")
// })
model
.
Log
.
Infof
(
"CalcGroupSupport_OldData end"
)
//
})
// c.Start()
//}
c
.
Start
()
}