Commit 8aed32d6 authored by chenweijian's avatar chenweijian

Merge branch 'fix/group_support_old_data' into 'master'

group support

See merge request !66
parents 43e1f9a9 d60ea0ca
......@@ -19,6 +19,7 @@ func Init() {
group_cron.GroupPowerExpClear() // 清理家族经验/等级
group_cron.GroupPowerMonthRankAct()
//group_cron.GroupInEventInit() // 进房事件
group_cron.CreateGroup() //
group_cron.CalcGroupSupport() // 群组扶持计算
group_cron.CreateGroup() //
group_cron.CalcGroupSupport() // 群组扶持计算
group_cron.CalcGroupSupport_OldData()
}
package group_cron
import (
"context"
"encoding/json"
"git.hilo.cn/hilo-common/_const/rediskey"
"git.hilo.cn/hilo-common/domain"
"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/utils"
"github.com/robfig/cron"
"hilo-group/_const/enum/gift_e"
"hilo-group/_const/enum/group_e"
"hilo-group/domain/model/gift_m"
"hilo-group/domain/model/group_m"
"hilo-group/domain/service/group_s"
"time"
......@@ -86,76 +91,77 @@ func sendGroupSupportH5(model *domain.Model) error {
return nil
}
// 群组扶持计算-本周旧数据
//func CalcGroupSupport_OldData() {
// if !config.IsMaster() {
// return
// }
// c := cron.New()
// spec := "0 30 10 24 8 ?"
// _ = c.AddFunc(spec, func() {
// defer utils.CheckGoPanic()
// var model = domain.CreateModelNil()
// //开始
// model.Log.Infof("CalcGroupSupport_OldData start")
//
// 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)
// if err != nil {
// model.Log.Errorf("CalcGroupSupport_OldData beginTime:%v, endTime:%v, err:%v", beginTime, endTime, err)
// return
// }
// // 流水写入redis
// keyDiamond := rediskey.GetGroupSupportConsumeSummary(period)
// for _, r := range records {
// if r.SceneUid == "" || r.Consume <= 0 {
// continue
// }
// _, err = model.RedisCluster.ZIncrBy(context.Background(), keyDiamond, float64(r.Consume), r.SceneUid).Result()
// if err != nil {
// 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 {
// model.Log.Errorf("CalcGroupSupport_OldData groupSupport key:%s, err:%v", keyDiamond, err)
// return
// }
// // 支持者写入redis
// for _, r := range records {
// 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)
// if err != nil {
// model.Log.Errorf("CalcGroupSupport_OldData beginTime:%v, endTime:%v, imGroupId:%v, err:%v", beginTime, endTime, r.SceneUid, err)
// continue
// }
// if len(uids) <= 0 {
// continue
// }
// // 支持者数量
// keySupportNum := rediskey.GetGroupSupportCountSupporter(period, r.SceneUid)
// for _, uid := range uids {
// err = model.RedisCluster.SAdd(context.Background(), 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 {
// model.Log.Errorf("AddSendGiftEventAsync groupSupport key:%s, err:%v", keySupportNum, err)
// }
// }
//
// model.Log.Infof("CalcGroupSupport_OldData end")
// })
//
// c.Start()
//}
// 群组扶持计算-旧数据
func CalcGroupSupport_OldData() {
if !config.IsMaster() {
return
}
c := cron.New()
spec := "0 20 11 25 8 ?"
_ = c.AddFunc(spec, func() {
defer utils.CheckGoPanic()
var model = domain.CreateModelNil()
//开始
model.Log.Infof("CalcGroupSupport_OldData start")
beginTime, endTime, period := group_m.GetSupportLevelTime(time.Now().AddDate(0, 0, -group_e.SUPPORT_LEVEL_PERIOD_DAY))
//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)
if err != nil {
model.Log.Errorf("CalcGroupSupport_OldData beginTime:%v, endTime:%v, err:%v", beginTime, endTime, err)
return
}
// 流水写入redis
keyDiamond := rediskey.GetGroupSupportConsumeSummary(period)
for _, r := range records {
if r.SceneUid == "" || r.Consume <= 0 {
continue
}
_, err = model.RedisCluster.ZIncrBy(context.Background(), keyDiamond, float64(r.Consume), r.SceneUid).Result()
if err != nil {
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 {
model.Log.Errorf("CalcGroupSupport_OldData groupSupport key:%s, err:%v", keyDiamond, err)
return
}
// 支持者写入redis
for _, r := range records {
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)
if err != nil {
model.Log.Errorf("CalcGroupSupport_OldData beginTime:%v, endTime:%v, imGroupId:%v, err:%v", beginTime, endTime, r.SceneUid, err)
continue
}
if len(uids) <= 0 {
continue
}
// 支持者数量
keySupportNum := rediskey.GetGroupSupportCountSupporter(period, r.SceneUid)
for _, uid := range uids {
err = model.RedisCluster.SAdd(context.Background(), 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 {
model.Log.Errorf("AddSendGiftEventAsync groupSupport key:%s, err:%v", keySupportNum, err)
}
}
model.Log.Infof("CalcGroupSupport_OldData end")
})
c.Start()
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment