...
 
Commits (82)
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)
}
...@@ -13,6 +13,8 @@ const ( ...@@ -13,6 +13,8 @@ const (
MicGroupPowerOnMic = MicPrefix + "groupPower:${userId}:${date}" // 家族内群上麦分钟数 MicGroupPowerOnMic = MicPrefix + "groupPower:${userId}:${date}" // 家族内群上麦分钟数
MicUserOnMic = MicPrefix + "user:onMic:${tz}:${userId}:${date}" MicUserOnMic = MicPrefix + "user:onMic:${tz}:${userId}:${date}"
MicGroupOnMic = MicPrefix + "group:onMic:${groupId}" // 在群组麦位上的人 hset field:micIndex member:userId
) )
func GetUserMicDayInvite(userId mysql.ID) string { func GetUserMicDayInvite(userId mysql.ID) string {
...@@ -31,3 +33,10 @@ func GetMicGroupPowerOnMic(userId uint64) string { ...@@ -31,3 +33,10 @@ func GetMicGroupPowerOnMic(userId uint64) string {
func GetUserOnMicKey(userId uint64, tz, date string) string { func GetUserOnMicKey(userId uint64, tz, date string) string {
return redis_key.ReplaceKey(MicUserOnMic, tz, fmt.Sprintf("%d", userId), date) return redis_key.ReplaceKey(MicUserOnMic, tz, fmt.Sprintf("%d", userId), date)
} }
// 获取群组麦位上的人
// 可能会有数据不一致,已原来麦位的key为准
// 这里用户快速获取群上麦位的人用,代替大量mget命令慢查询
func GetGroupOnMicUser(groupId string) string {
return redis_key.ReplaceKey(MicGroupOnMic, groupId)
}
...@@ -249,6 +249,9 @@ const groupInUserDuration = "group_in_user_duration_{groupUuid}" ...@@ -249,6 +249,9 @@ const groupInUserDuration = "group_in_user_duration_{groupUuid}"
// 15天内进入房间的人数 // 15天内进入房间的人数
const roomVisitCount = "room_visit_count" const roomVisitCount = "room_visit_count"
// 15天内进入房间的人数 member groupId score 麦位有人的数量
const roomVisitCountZSet = "room_visit_count_zset"
// 用户进入过的房间及时间 // 用户进入过的房间及时间
const userEnterRoom = "enter_room_{userId}" const userEnterRoom = "enter_room_{userId}"
...@@ -757,18 +760,27 @@ func GetPrefixGroupMicNumType(groupUuid string) string { ...@@ -757,18 +760,27 @@ func GetPrefixGroupMicNumType(groupUuid string) string {
return strings.Replace(groupMicNumType, "{groupUuid}", groupUuid, -1) return strings.Replace(groupMicNumType, "{groupUuid}", groupUuid, -1)
} }
// Deprecated: 用户进房时间
// 用 uer:g:${group_id}代替
func GetPrefixGroupInUserDuration(groupUuid string) string { func GetPrefixGroupInUserDuration(groupUuid string) string {
return strings.Replace(groupInUserDuration, "{groupUuid}", groupUuid, -1) return strings.Replace(groupInUserDuration, "{groupUuid}", groupUuid, -1)
} }
// Deprecated: 用户进房时间
// 可用 uer:u:${user_id}代替
func GetUserEnterRoomKey(userId uint64) string { func GetUserEnterRoomKey(userId uint64) string {
return strings.Replace(userEnterRoom, "{userId}", strconv.FormatUint(userId, 10), -1) return strings.Replace(userEnterRoom, "{userId}", strconv.FormatUint(userId, 10), -1)
} }
// Deprecated: 用redis集群中的zset代替
func GetPrefixRoomVisitCount() string { func GetPrefixRoomVisitCount() string {
return roomVisitCount return roomVisitCount
} }
func GetPrefixRoomVisitCountZset() string {
return roomVisitCountZSet
}
func GetPrefixSupportLevel(date string) string { func GetPrefixSupportLevel(date string) string {
return strings.Replace(supportLevel, "{date}", date, -1) return strings.Replace(supportLevel, "{date}", date, -1)
} }
......
...@@ -5,9 +5,11 @@ import ( ...@@ -5,9 +5,11 @@ import (
"hilo-group/cron/gift_cron" "hilo-group/cron/gift_cron"
"hilo-group/cron/group_cron" "hilo-group/cron/group_cron"
"hilo-group/cron/mic_cron" "hilo-group/cron/mic_cron"
"hilo-group/cron/user_cron"
) )
func Init() { func Init() {
user_cron.LoadSvipVipNoble() // 加载用户特权
if !config.IsMaster() { if !config.IsMaster() {
return return
} }
...@@ -19,7 +21,8 @@ func Init() { ...@@ -19,7 +21,8 @@ func Init() {
group_cron.GroupPowerExpClear() // 清理家族经验/等级 group_cron.GroupPowerExpClear() // 清理家族经验/等级
group_cron.GroupPowerMonthRankAct() group_cron.GroupPowerMonthRankAct()
//group_cron.GroupInEventInit() // 进房事件 //group_cron.GroupInEventInit() // 进房事件
group_cron.CreateGroup() // //group_cron.CreateGroup() //
group_cron.CalcGroupSupport() // 群组扶持计算 group_cron.CalcGroupSupport() // 群组扶持计算
//group_cron.CalcGroupSupport_OldData() //group_cron.CalcGroupSupport_OldData()
group_cron.GroupCountryListSort()
} }
...@@ -9,6 +9,7 @@ import ( ...@@ -9,6 +9,7 @@ import (
"hilo-group/_const/enum/gift_e" "hilo-group/_const/enum/gift_e"
"hilo-group/_const/enum/groupPower_e" "hilo-group/_const/enum/groupPower_e"
"hilo-group/domain/cache/gift_c" "hilo-group/domain/cache/gift_c"
"hilo-group/domain/cache/groupPower_c"
"hilo-group/domain/event/gift_ev" "hilo-group/domain/event/gift_ev"
"hilo-group/domain/model/groupPower_m" "hilo-group/domain/model/groupPower_m"
"hilo-group/domain/model/group_m" "hilo-group/domain/model/group_m"
...@@ -74,10 +75,8 @@ func groupPowerStar(model *domain.Model, sendGiftEvent *gift_ev.SendGiftEvent) { ...@@ -74,10 +75,8 @@ func groupPowerStar(model *domain.Model, sendGiftEvent *gift_ev.SendGiftEvent) {
// 送礼加分 // 送礼加分
if data, ok := groupPowers[sendGiftEvent.SendUserId]; ok { if data, ok := groupPowers[sendGiftEvent.SendUserId]; ok {
diamonds := sendGiftEvent.GiftN * sendGiftEvent.ResGift.DiamondNum * mysql.Num(len(sendGiftEvent.ReceiveUserIds)) diamonds := sendGiftEvent.GiftN * sendGiftEvent.ResGift.DiamondNum * mysql.Num(len(sendGiftEvent.ReceiveUserIds))
if err := groupPower_m.IncrGroupPowerMonthStarScore(model, data.GroupPowerId, data.UserId, groupPower_e.GroupPowerStarTypeFamous, diamonds, 0); err != nil { if err := groupPower_c.IncrGroupPowerDayStarScore(model, data.GroupPowerId, data.UserId,
model.Log.Errorf("IncrGroupPowerMonthStarScore famous fail:%v", err) groupPower_e.GroupPowerStarTypeFamous, diamonds); err != nil {
}
if err := groupPower_m.IncrGroupPowerDayStarScore(model, data.GroupPowerId, data.UserId, groupPower_e.GroupPowerStarTypeFamous, diamonds, 0); err != nil {
model.Log.Errorf("IncrGroupPowerDayStarScore famous fail:%v", err) model.Log.Errorf("IncrGroupPowerDayStarScore famous fail:%v", err)
} }
} }
...@@ -85,10 +84,8 @@ func groupPowerStar(model *domain.Model, sendGiftEvent *gift_ev.SendGiftEvent) { ...@@ -85,10 +84,8 @@ func groupPowerStar(model *domain.Model, sendGiftEvent *gift_ev.SendGiftEvent) {
for _, userId := range sendGiftEvent.ReceiveUserIds { for _, userId := range sendGiftEvent.ReceiveUserIds {
if data, ok := groupPowers[userId]; ok { if data, ok := groupPowers[userId]; ok {
diamonds := sendGiftEvent.GiftN * sendGiftEvent.ResGift.DiamondNum diamonds := sendGiftEvent.GiftN * sendGiftEvent.ResGift.DiamondNum
if err := groupPower_m.IncrGroupPowerMonthStarScore(model, data.GroupPowerId, data.UserId, groupPower_e.GroupPowerStarTypeCharm, diamonds, 0); err != nil { if err := groupPower_c.IncrGroupPowerDayStarScore(model, data.GroupPowerId, data.UserId,
model.Log.Errorf("IncrGroupPowerMonthStarScore charm fail:%v", err) groupPower_e.GroupPowerStarTypeCharm, diamonds); err != nil {
}
if err := groupPower_m.IncrGroupPowerDayStarScore(model, data.GroupPowerId, data.UserId, groupPower_e.GroupPowerStarTypeCharm, diamonds, 0); err != nil {
model.Log.Errorf("IncrGroupPowerDayStarScore charm fail:%v", err) model.Log.Errorf("IncrGroupPowerDayStarScore charm fail:%v", err)
} }
} }
...@@ -98,7 +95,7 @@ func groupPowerStar(model *domain.Model, sendGiftEvent *gift_ev.SendGiftEvent) { ...@@ -98,7 +95,7 @@ func groupPowerStar(model *domain.Model, sendGiftEvent *gift_ev.SendGiftEvent) {
// 群组扶持增加流水数据 // 群组扶持增加流水数据
func groupSupportAddConsume(model *domain.Model, sendGiftEvent *gift_ev.SendGiftEvent) { func groupSupportAddConsume(model *domain.Model, sendGiftEvent *gift_ev.SendGiftEvent) {
if time.Now().Unix() <= 1692843600 { if time.Now().Unix() <= 1693275900 {
return return
} }
model.Log.Infof("groupSupportAddConsume UserId:%d, sendGiftEvent:%+v", sendGiftEvent.SendUserId, sendGiftEvent) model.Log.Infof("groupSupportAddConsume UserId:%d, sendGiftEvent:%+v", sendGiftEvent.SendUserId, sendGiftEvent)
...@@ -108,7 +105,7 @@ func groupSupportAddConsume(model *domain.Model, sendGiftEvent *gift_ev.SendGift ...@@ -108,7 +105,7 @@ func groupSupportAddConsume(model *domain.Model, sendGiftEvent *gift_ev.SendGift
} }
_, _, period := group_m.GetSupportLevelTime(time.Now()) _, _, period := group_m.GetSupportLevelTime(time.Now())
// 钻石数 // 钻石数
diamond := sendGiftEvent.GiftN * sendGiftEvent.ResGift.DiamondNum diamond := sendGiftEvent.GiftN * sendGiftEvent.ResGift.DiamondNum * mysql.Num(len(sendGiftEvent.ReceiveUserIds))
keyDiamond := rediskey.GetGroupSupportConsumeSummary(period) keyDiamond := rediskey.GetGroupSupportConsumeSummary(period)
_, err := model.RedisCluster.ZIncrBy(context.Background(), keyDiamond, float64(diamond), sendGiftEvent.SceneUid).Result() _, err := model.RedisCluster.ZIncrBy(context.Background(), keyDiamond, float64(diamond), sendGiftEvent.SceneUid).Result()
if err != nil { if err != nil {
......
package group_cron
import (
"git.hilo.cn/hilo-common/domain"
"github.com/robfig/cron"
"hilo-group/domain/service/group_s"
)
// 清理家族经验和等级
func GroupCountryListSort() {
// 常用国家-每15分钟计算国家房间列表排序 /v1/imGroup/country [get] 接口
spec := "0 */15 * * * ?"
c := cron.New()
_ = c.AddFunc(spec, func() {
var model = domain.CreateModelNil()
model.Log.Infof("GroupCountryListSort Common start")
group_s.SortGroupCommonCountryList(model)
model.Log.Infof("GroupCountryListSort Common end")
})
// 非常用国家-每60分钟计算国家房间列表排序 /v1/imGroup/country [get] 接口
spec2 := "0 59 * * * ?"
_ = c.AddFunc(spec2, func() {
var model = domain.CreateModelNil()
model.Log.Infof("GroupCountryListSort not Common start")
group_s.SortGroupNotCommonCountryList(model)
model.Log.Infof("GroupCountryListSort not Common end")
})
c.Start()
}
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"
...@@ -87,76 +92,76 @@ func sendGroupSupportH5(model *domain.Model) error { ...@@ -87,76 +92,76 @@ func sendGroupSupportH5(model *domain.Model) error {
} }
// 群组扶持计算-旧数据 // 群组扶持计算-旧数据
//func CalcGroupSupport_OldData() { func CalcGroupSupport_OldData() {
// if !config.IsMaster() { if !config.IsMaster() {
// return return
// } }
// c := cron.New() c := cron.New()
// spec := "0 20 11 25 8 ?" spec := "0 27 10 29 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, endTime, period := group_m.GetSupportLevelTime(time.Now().AddDate(0, 0, -group_e.SUPPORT_LEVEL_PERIOD_DAY)) //beginTime, endTime, period := group_m.GetSupportLevelTime(time.Now().AddDate(0, 0, -group_e.SUPPORT_LEVEL_PERIOD_DAY))
// //beginTime, _, period := group_m.GetSupportLevelTime(time.Now()) beginTime, _, period := group_m.GetSupportLevelTime(time.Now())
// //endTime := time.Unix(1692843600, 0) endTime := time.Unix(1693275900, 0)
//
// g := gift_m.GiftOperate{SceneType: gift_e.GroupSceneType, Model: model} g := gift_m.GiftOperate{SceneType: gift_e.GroupSceneType, Model: model}
// records, err := g.BatchGetConsumeByRange(beginTime, endTime) records, err := g.BatchGetConsumeByRange(beginTime, endTime)
// if err != nil { if err != nil {
// model.Log.Errorf("CalcGroupSupport_OldData beginTime:%v, endTime:%v, err:%v", beginTime, endTime, err) model.Log.Errorf("CalcGroupSupport_OldData beginTime:%v, endTime:%v, err:%v", beginTime, endTime, err)
// return return
// } }
// // 流水写入redis // 流水写入redis
// keyDiamond := rediskey.GetGroupSupportConsumeSummary(period) keyDiamond := rediskey.GetGroupSupportConsumeSummary(period)
// for _, r := range records { for _, r := range records {
// if r.SceneUid == "" || r.Consume <= 0 { if r.SceneUid == "" || r.Consume <= 0 {
// continue continue
// } }
// _, err = model.RedisCluster.ZIncrBy(context.Background(), keyDiamond, float64(r.Consume), r.SceneUid).Result() _, err = model.RedisCluster.ZIncrBy(context.Background(), keyDiamond, float64(r.Consume), r.SceneUid).Result()
// if err != nil { if err != nil {
// model.Log.Errorf("CalcGroupSupport_OldData groupSupport key:%s, val:%d, member:%s, err:%v", model.Log.Errorf("CalcGroupSupport_OldData groupSupport key:%s, val:%d, member:%s, err:%v",
// keyDiamond, r.Consume, r.SceneUid, err) keyDiamond, r.Consume, r.SceneUid, err)
// } }
// } }
// err = redisCli.SetExpire(model.RedisCluster, keyDiamond, time.Hour*24*14) // 保留两周 err = redisCli.SetExpire(model.RedisCluster, keyDiamond, time.Hour*24*14) // 保留两周
// if err != nil { if err != nil {
// model.Log.Errorf("CalcGroupSupport_OldData groupSupport key:%s, err:%v", keyDiamond, err) model.Log.Errorf("CalcGroupSupport_OldData groupSupport key:%s, err:%v", keyDiamond, err)
// return return
// } }
// // 支持者写入redis // 支持者写入redis
// for _, r := range records { for _, r := range records {
// if r.SceneUid == "" || r.C <= 0 { if r.SceneUid == "" || r.C <= 0 {
// continue continue
// } }
// // 支持者列表 // 支持者列表
// support := gift_m.GiftOperate{SceneType: gift_e.GroupSceneType, SceneUid: r.SceneUid, Model: model} support := gift_m.GiftOperate{SceneType: gift_e.GroupSceneType, SceneUid: r.SceneUid, Model: model}
// uids, err := support.BatchGetSupportList(beginTime, endTime) uids, err := support.BatchGetSupportList(model, beginTime, endTime)
// if err != nil { if err != nil {
// model.Log.Errorf("CalcGroupSupport_OldData beginTime:%v, endTime:%v, imGroupId:%v, err:%v", beginTime, endTime, r.SceneUid, err) model.Log.Errorf("CalcGroupSupport_OldData beginTime:%v, endTime:%v, imGroupId:%v, err:%v", beginTime, endTime, r.SceneUid, err)
// continue continue
// } }
// if len(uids) <= 0 { if len(uids) <= 0 {
// continue continue
// } }
// // 支持者数量 // 支持者数量
// keySupportNum := rediskey.GetGroupSupportCountSupporter(period, r.SceneUid) keySupportNum := rediskey.GetGroupSupportCountSupporter(period, r.SceneUid)
// for _, uid := range uids { for _, uid := range uids {
// err = model.RedisCluster.SAdd(context.Background(), keySupportNum, uid).Err() err = model.RedisCluster.SAdd(context.Background(), keySupportNum, uid).Err()
// if err != nil { if err != nil {
// model.Log.Errorf("CalcGroupSupport_OldData groupSupport key:%s, UserId:%d, err:%v", keySupportNum, uid, err) 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) // 保留两周 err = redisCli.SetExpire(model.RedisCluster, keySupportNum, time.Hour*24*14) // 保留两周
// if err != nil { if err != nil {
// model.Log.Errorf("AddSendGiftEventAsync groupSupport key:%s, err:%v", keySupportNum, err) 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()
//} }
package mic_cron package mic_cron
import ( import (
"fmt"
"git.hilo.cn/hilo-common/domain" "git.hilo.cn/hilo-common/domain"
"github.com/robfig/cron" "github.com/robfig/cron"
"hilo-group/_const/redis_key/mic_k"
"hilo-group/domain/cache/mic_c" "hilo-group/domain/cache/mic_c"
"hilo-group/domain/event/mic_ev" "hilo-group/domain/event/mic_ev"
"hilo-group/domain/model/group_m" "hilo-group/domain/model/group_m"
...@@ -24,6 +26,7 @@ func OnMicCheck() { ...@@ -24,6 +26,7 @@ func OnMicCheck() {
return return
} }
for _, groupId := range groupIds { for _, groupId := range groupIds {
onGroupMicKey := mic_k.GetGroupOnMicUser(groupId) // 同步在mic上的人
//遍历每个麦位 //遍历每个麦位
for i := 1; i <= group_m.MaxMicNum; i++ { for i := 1; i <= group_m.MaxMicNum; i++ {
micUser, err := group_m.GetMicUser(model, groupId, i) micUser, err := group_m.GetMicUser(model, groupId, i)
...@@ -41,6 +44,11 @@ func OnMicCheck() { ...@@ -41,6 +44,11 @@ func OnMicCheck() {
}); err != nil { }); err != nil {
model.Log.Errorf("QueueOnMic fail:%v", err) model.Log.Errorf("QueueOnMic fail:%v", err)
} }
// 设置mic上的人
model.Redis.HSet(model, onGroupMicKey, i, micUser.UserId)
} else {
// 删除mic上的人
model.Redis.HDel(model, onGroupMicKey, fmt.Sprintf("%d", i))
} }
} }
} }
......
package user_cron
import (
"git.hilo.cn/hilo-common/domain"
"github.com/robfig/cron"
"hilo-group/domain/cache/user_c"
)
// 加载数据到lru
func LoadSvipVipNoble() {
go user_c.LoadAllSvipVipNoble(domain.CreateModelNil()) // 启动先执行一次
c := cron.New()
spec := "0 */30 * * * ?"
_ = c.AddFunc(spec, func() {
model := domain.CreateModelNil()
user_c.LoadAllSvipVipNoble(model)
})
c.Start()
}
...@@ -445,40 +445,220 @@ func BuildJoinedGroupInfo(myService *domain.Service, myUserId uint64, originGrou ...@@ -445,40 +445,220 @@ func BuildJoinedGroupInfo(myService *domain.Service, myUserId uint64, originGrou
return result, len(groupInfo), nil return result, len(groupInfo), nil
} }
func BuildPopularGroupInfo(model *domain.Model, myUserId uint64, groupInfo []*group_m.GroupInfo) ([]*PopularGroupInfo, error) { // 填充用户最近进房
groupIds := make([]string, 0, len(groupInfo)) func BuildRecentGroupInfo(myService *domain.Service, myUserId uint64, originGroupIds []string, roomEnterTime map[string]int64) ([]JoinedGroupInfo, int, error) {
for _, v := range groupInfo { model := domain.CreateModel(myService.CtxAndDb)
groupIds = append(groupIds, v.ImGroupId)
groupInfo, err := group_m.BatchGetGroupInfo(model, originGroupIds)
if err != nil {
return nil, 0, err
}
var groupIds []string
for _, groupId := range originGroupIds {
if group, ok := groupInfo[groupId]; ok {
if group.IsGameRoom == 0 {
groupIds = append(groupIds, groupId)
}
}
}
if len(groupIds) <= 0 {
return nil, 0, nil
} }
// roomMicUserMap不影响排序 // 获取群组中上麦用户
roomMicUserMap, err := group_m.BatchGetAllMicUser(model, groupIds) roomMicUserMap, err := group_m.BatchGetAllMicUser(model, groupIds)
if err != nil { if err != nil {
return nil, err return nil, 0, err
} }
uids := make([]uint64, 0) uids := make([]uint64, 0)
micUsersMap := make(map[string][]uint64, 0) micUsersMap := make(map[string][]uint64, 0)
for _, v := range groupInfo { for _, i := range groupInfo {
micUsersMap[v.ImGroupId] = make([]uint64, 0) micUsersMap[i.ImGroupId] = make([]uint64, 0)
if len(v.Password) <= 0 { if len(i.Password) <= 0 {
// 密码群不显示麦上头像 // 密码群不显示麦上头像
u := roomMicUserMap[v.ImGroupId] u := roomMicUserMap[i.ImGroupId]
if len(u) >= 4 { if len(u) >= 4 {
micUsersMap[v.ImGroupId] = u[0:4] micUsersMap[i.ImGroupId] = u[0:4]
} else if len(u) > 0 { } else if len(u) > 0 {
micUsersMap[v.ImGroupId] = u micUsersMap[i.ImGroupId] = u
} }
uids = append(uids, micUsersMap[v.ImGroupId]...) uids = append(uids, micUsersMap[i.ImGroupId]...)
} }
} }
uids = utils.UniqueSliceUInt64(uids) uids = utils.UniqueSliceUInt64(uids)
userTiny, err := user_cv.GetUserTinyMap(uids) userTiny, err := user_cv.GetUserTinyMap(uids)
if err != nil { if err != nil {
return nil, err return nil, 0, err
} }
roomCount, err := group_m.BatchGetRoomCount(model, groupIds) roomCount, err := group_m.BatchGetRoomCount(model, groupIds)
if err != nil {
return nil, 0, err
}
countryInfo, err := res_c.GetCountryIconMap(model)
if err != nil {
return nil, 0, err
}
supportLevels, err := group_s.NewGroupService(model.MyContext).GetWeekMaxSupportLevelMap()
if err != nil {
return nil, 0, err
}
visitCount, err := group_m.BatchGetRoomVisitCount(model.Log, groupIds)
if err != nil {
return nil, 0, err
}
// 排序优先级V8.0版本
sort.Slice(groupIds, func(i, j int) bool {
gi := groupIds[i]
gj := groupIds[j]
return roomEnterTime[gi] > roomEnterTime[gj] ||
roomEnterTime[gi] == roomEnterTime[gj] && visitCount[gj] > visitCount[gj] ||
roomEnterTime[gi] == roomEnterTime[gj] && visitCount[gj] == visitCount[gj] && i >= j
})
result := make([]JoinedGroupInfo, 0)
owners := make([]uint64, 0)
for _, i := range groupIds {
owners = append(owners, groupInfo[i].Owner)
}
powerIds, powerNames, powerNameplates, powerGrades, err := group_power_cv.BatchGetGroupPower(model.Db, owners)
if err != nil {
return nil, 0, err
}
groupMedals, err := group_m.BatchGetMedals(model.Db, groupIds)
if err != nil {
return nil, 0, err
}
resMedal, err := res_m.MedalGetAllMap(model.Db)
if err != nil {
return nil, 0, err
}
rr := rocket_m.RocketResult{}
maxStageMap, err := rr.GetMaxStage(model.Db, groupIds)
if err != nil {
return nil, 0, err
}
// 正在进行的游戏
games := game_m.GetNotEndGamesMap(model)
for _, i := range groupIds {
g := groupInfo[i]
micUsers := make([]user_cv.CvUserTiny, 0)
for _, j := range micUsersMap[i] {
micUsers = append(micUsers, userTiny[j])
}
var maxStage *uint16 = nil
if s, ok := maxStageMap[i]; ok {
maxStage = &s
}
medals := make([]medal_cv.PicElement, 0)
// 补上房间流水勋章
var pe *medal_cv.PicElement
_, pe, err = medal_cv.GetGroupConsumeMedal(model, i)
if err != nil {
model.Log.Infof("BuildJoinedGroupInfo: GetGroupConsumeMedal: %s", err.Error())
} else if pe != nil {
medals = append(medals, medal_cv.PicElement{PicUrl: pe.PicUrl})
}
// res_medal
if m, ok := groupMedals[i]; ok {
for _, j := range m {
mId := uint32(j)
if e, ok := resMedal[mId]; ok {
medals = append(medals, medal_cv.PicElement{
PicUrl: e.PicUrl,
})
}
}
}
var password *string = nil
if len(g.Password) > 0 && g.Owner != myUserId {
emptyStr := ""
password = &emptyStr
}
result = append(result, JoinedGroupInfo{
PopularGroupInfo: PopularGroupInfo{
GroupInfo: GroupInfo{
GroupBasicInfo: GroupBasicInfo{
GroupId: g.TxGroupId,
Name: g.Name,
Notification: g.Notification,
Introduction: g.Introduction,
FaceUrl: g.FaceUrl,
Code: g.Code,
CountryIcon: countryInfo[g.Country],
Password: password,
SupportLevel: supportLevels[i],
GroupInUserDuration: visitCount[i],
MicNumType: int(g.MicNumType),
GroupMedals: medals,
},
HasOnMic: len(micUsers) > 0,
GroupPowerId: powerIds[g.Owner],
GroupPowerName: powerNames[g.Owner],
GroupPowerNameplate: powerNameplates[g.Owner],
GroupPower: GroupPower{
Id: powerIds[g.Owner],
Name: powerNames[g.Owner],
Nameplate: powerNameplates[g.Owner],
Grade: powerGrades[g.Owner],
},
},
MicUsers: micUsers,
RoomUserCount: uint(roomCount[i]),
MaxStage: maxStage,
GameTypes: games[g.TxGroupId],
},
LastEnterTime: roomEnterTime[i],
})
}
return result, len(groupInfo), nil
}
func BuildPopularGroupInfo(model *domain.Model, myUserId uint64, groupInfo []*group_m.GroupInfo) ([]*PopularGroupInfo, error) {
groupIds := make([]string, 0, len(groupInfo))
for _, v := range groupInfo {
groupIds = append(groupIds, v.ImGroupId)
}
// roomMicUserMap不影响排序
//roomMicUserMap, err := group_m.BatchGetAllMicUser(model, groupIds)
//if err != nil {
// return nil, err
//}
//uids := make([]uint64, 0)
//micUsersMap := make(map[string][]uint64, 0)
//for _, v := range groupInfo {
// micUsersMap[v.ImGroupId] = make([]uint64, 0)
//
// if len(v.Password) <= 0 {
// // 密码群不显示麦上头像
// u := roomMicUserMap[v.ImGroupId]
// if len(u) >= 4 {
// micUsersMap[v.ImGroupId] = u[0:4]
// } else if len(u) > 0 {
// micUsersMap[v.ImGroupId] = u
// }
// uids = append(uids, micUsersMap[v.ImGroupId]...)
// }
//}
//uids = utils.UniqueSliceUInt64(uids)
//userTiny, err := user_cv.GetUserTinyMap(uids)
//if err != nil {
// return nil, err
//}
roomCount, err := group_m.BatchGetRoomCount(model, groupIds)
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -546,10 +726,10 @@ func BuildPopularGroupInfo(model *domain.Model, myUserId uint64, groupInfo []*gr ...@@ -546,10 +726,10 @@ func BuildPopularGroupInfo(model *domain.Model, myUserId uint64, groupInfo []*gr
for _, v := range groupInfo { for _, v := range groupInfo {
g := v g := v
i := v.ImGroupId i := v.ImGroupId
micUsers := make([]user_cv.CvUserTiny, 0) //micUsers := make([]user_cv.CvUserTiny, 0)
for _, j := range micUsersMap[i] { //for _, j := range micUsersMap[i] {
micUsers = append(micUsers, userTiny[j]) // micUsers = append(micUsers, userTiny[j])
} //}
var maxStage *uint16 = nil var maxStage *uint16 = nil
if s, ok := maxStageMap[i]; ok { if s, ok := maxStageMap[i]; ok {
...@@ -598,7 +778,7 @@ func BuildPopularGroupInfo(model *domain.Model, myUserId uint64, groupInfo []*gr ...@@ -598,7 +778,7 @@ func BuildPopularGroupInfo(model *domain.Model, myUserId uint64, groupInfo []*gr
MicNumType: int(g.MicNumType), MicNumType: int(g.MicNumType),
GroupMedals: medals, GroupMedals: medals,
}, },
HasOnMic: len(micUsers) > 0, //HasOnMic: len(micUsers) > 0,
GroupPowerId: powerIds[g.Owner], GroupPowerId: powerIds[g.Owner],
GroupPowerName: powerNames[g.Owner], GroupPowerName: powerNames[g.Owner],
GroupPowerNameplate: powerNameplates[g.Owner], GroupPowerNameplate: powerNameplates[g.Owner],
...@@ -609,7 +789,7 @@ func BuildPopularGroupInfo(model *domain.Model, myUserId uint64, groupInfo []*gr ...@@ -609,7 +789,7 @@ func BuildPopularGroupInfo(model *domain.Model, myUserId uint64, groupInfo []*gr
Grade: powerGrades[g.Owner], Grade: powerGrades[g.Owner],
}, },
}, },
MicUsers: micUsers, //MicUsers: micUsers,
RoomUserCount: uint(roomCount[i]), RoomUserCount: uint(roomCount[i]),
MaxStage: maxStage, MaxStage: maxStage,
GameTypes: games[g.TxGroupId], GameTypes: games[g.TxGroupId],
......
...@@ -908,16 +908,122 @@ func GetUserDetail(model *domain.Model, userId mysql.ID, myUserId mysql.ID) (*Cv ...@@ -908,16 +908,122 @@ func GetUserDetail(model *domain.Model, userId mysql.ID, myUserId mysql.ID) (*Cv
noble, superManagerMap[userId], myGroups, phoneInfo, thirdList, cvCountryManager) noble, superManagerMap[userId], myGroups, phoneInfo, thirdList, cvCountryManager)
} }
//群主信息
func GetRoomInfoOwner(model *domain.Model, userId mysql.ID, myUserId mysql.ID) (*CvUserDetail, error) {
model.Log.Infof("GetUserDetail %d begin", userId)
var user user_m.User
var err error
if err = mysql.Db.First(&user, userId).Error; err != nil {
return nil, myerr.WrapErr(err)
}
var wealthUserScore user_m.MatchWealthUserScore
if err := mysql.Db.Model(&user_m.MatchWealthUserScore{}).Where(&user_m.MatchWealthUserScore{UserId: userId}).First(&wealthUserScore).Error; err != nil {
if err != nil {
if err == gorm.ErrRecordNotFound {
wealthUserScore = user_m.MatchWealthUserScore{
UserId: userId,
Score: 0,
Grade: 0,
}
} else {
return nil, myerr.WrapErr(err)
}
}
}
var charmUserScore user_m.MatchCharmUserScore
if err := mysql.Db.Model(&user_m.MatchCharmUserScore{}).Where(&user_m.MatchCharmUserScore{
UserId: userId,
}).First(&charmUserScore).Error; err != nil {
if err != nil {
if err == gorm.ErrRecordNotFound {
charmUserScore = user_m.MatchCharmUserScore{
UserId: userId,
Score: 0,
Grade: 0,
}
} else {
return nil, myerr.WrapErr(err)
}
}
}
isVip, expireTime, err := user_m.IsVip(userId)
if err != nil {
return nil, myerr.WrapErr(err)
}
svip, err := rpc.GetUserSvip(model, userId)
if err != nil {
return nil, myerr.WrapErr(err)
}
medals := make(map[uint64][]uint32, 0)
medals[userId], err = user_m.GetUserMedalMerge(model.Log, mysql.Db, userId)
if err != nil {
return nil, err
}
medals, medalInfo, err := medal_cv.GetMedalInfoMap(mysql.Db, medals)
if err != nil {
return nil, err
}
groupPowerId, groupPowerName, err := groupPower_m.GetUserGroupPower(model, userId)
if err != nil {
return nil, err
}
powers := map[mysql.ID]uint64{userId: groupPowerId}
powerNames := map[mysql.ID]string{userId: groupPowerName}
groupPowerInfos, err := groupPower_m.MGetGroupPowerInfoMap(model, []mysql.ID{groupPowerId})
groupPowerGrades, err := groupPower_m.MGetGroupPowerGrade(model, []mysql.ID{groupPowerId})
groupPowerUsers, err := groupPower_m.MGetGroupPowerUsers(model, []mysql.ID{groupPowerId})
var memberMax int
grade := groupPowerGrades[groupPowerId].Grade
if grade >= groupPower_e.GroupPowerGrade0 && grade <= groupPower_e.GroupPowerGradeMax {
if grade == groupPower_e.GroupPowerGrade0 {
memberMax = 300
}
if grade == groupPower_e.GroupPowerGrade1 {
memberMax = 500
}
if grade == groupPower_e.GroupPowerGrade2 {
memberMax = 800
}
if grade == groupPower_e.GroupPowerGrade3 {
memberMax = 1200
}
}
memberNum := len(groupPowerUsers[groupPowerId])
if memberNum > memberMax {
memberMax = memberNum
}
groupPowerMembers := [2]int{memberNum, memberMax} // 0->memberNum 1->memberLimit
noble, err := noble_m.FindActiveNoble(mysql.Db, userId)
if err != nil {
return nil, err
}
return userToDetailOne(model, &user, myUserId, nil, false, false,
map[mysql.ID]Relation{}, isVip, expireTime, svip, nil, property_cv.CvProperty{}, wealthUserScore.Grade, charmUserScore.Grade,
0, medals[userId], medalInfo[userId], "", powers[userId], powerNames[userId], groupPowerInfos[groupPowerId], groupPowerGrades[groupPowerId], groupPowerMembers,
noble, false, nil, nil, nil, nil)
}
// 单用户版,简化参数 // 单用户版,简化参数
func userToDetailOne(model *domain.Model, user *user_m.User, myUserId mysql.ID, userTradeUnion *user_m.UserTradeUnion, isLike bool, likeMe bool, hvMap map[mysql.ID]Relation, func userToDetailOne(model *domain.Model, user *user_m.User, myUserId mysql.ID, userTradeUnion *user_m.UserTradeUnion, isLike bool, likeMe bool, hvMap map[mysql.ID]Relation,
isVip bool, vipExpireTime *int64, svip rpc.CvSvip, headwear *headwear_cv.CvHeadwear, ride property_cv.CvProperty, wealthGrade uint32, charmGrade uint32, activityGrade uint32, isVip bool, vipExpireTime *int64, svip rpc.CvSvip, headwear *headwear_cv.CvHeadwear, ride property_cv.CvProperty, wealthGrade uint32, charmGrade uint32, activityGrade uint32,
medals []uint32, medalInfo []medal_cv.CvMedal, room string, power uint64, powerName string, powerInfo groupPower_m.GroupPowerInfo, grade groupPower_m.GroupPowerGrade, members [2]int, noble *noble_m.UserNoble, isOfficialStaff bool, medals []uint32, medalInfo []medal_cv.CvMedal, room string, power uint64, powerName string, powerInfo groupPower_m.GroupPowerInfo, grade groupPower_m.GroupPowerGrade, members [2]int, noble *noble_m.UserNoble, isOfficialStaff bool,
myGroups []group_m.GroupInfo, phoneInfo *user_m.UserPhoneInfo, thirdList []int8, countryManager *country_cv.CVCountryManager) (*CvUserDetail, error) { myGroups []group_m.GroupInfo, phoneInfo *user_m.UserPhoneInfo, thirdList []int8, countryManager *country_cv.CVCountryManager) (*CvUserDetail, error) {
room, err := group_m.ToTxGroupId(model, room) if len(room) > 0 {
if err != nil { var err error
model.Log.Warnf("ToTxGroupId failed for %s, err:%v", room, err) room, err = group_m.ToTxGroupId(model, room)
room = "" if err != nil {
model.Log.Warnf("ToTxGroupId failed for %s, err:%v", room, err)
room = ""
}
} }
cvUserDetail := &CvUserDetail{ cvUserDetail := &CvUserDetail{
......
...@@ -14,7 +14,7 @@ const EventSendGiftHiloGroupQueue = "send:gift:queue:hilo_group" ...@@ -14,7 +14,7 @@ const EventSendGiftHiloGroupQueue = "send:gift:queue:hilo_group"
func BLPopQueueSendGift(model *domain.Model) *gift_ev.SendGiftEvent { func BLPopQueueSendGift(model *domain.Model) *gift_ev.SendGiftEvent {
var res *gift_ev.SendGiftEvent var res *gift_ev.SendGiftEvent
queue := EventSendGiftHiloGroupQueue queue := EventSendGiftHiloGroupQueue
strs, err := model.Redis.BLPop(model, time.Second, queue).Result() strs, err := model.RedisCluster.BLPop(model, time.Second, queue).Result()
if err != nil { if err != nil {
if err != redis.Nil { if err != redis.Nil {
model.Log.Errorf("BLPopQueueSendGift fail:%v", err) model.Log.Errorf("BLPopQueueSendGift fail:%v", err)
......
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
}
// 获取家族之星排行
// param period: day|week|month
func GetGroupPowerStarRankPeriod(model *domain.Model, period string, groupPowerId mysql.ID, _type groupPower_e.GroupPowerStarType, offset, limit int, targetDate ...string) ([]*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")
}
if len(targetDate) > 0 {
date = targetDate[0]
}
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
}
...@@ -4,6 +4,7 @@ import ( ...@@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"git.hilo.cn/hilo-common/domain" "git.hilo.cn/hilo-common/domain"
"github.com/go-redis/redis/v8" "github.com/go-redis/redis/v8"
"github.com/spf13/cast"
"hilo-group/_const/redis_key/group_k" "hilo-group/_const/redis_key/group_k"
"strconv" "strconv"
"time" "time"
...@@ -49,16 +50,23 @@ func GetLastRoomVisitors(model *domain.Model, imGroupId string) (userIds []uint6 ...@@ -49,16 +50,23 @@ func GetLastRoomVisitors(model *domain.Model, imGroupId string) (userIds []uint6
// 获取最近进入的房间 // 获取最近进入的房间
// 3个月 // 3个月
func GetUserRecentRooms(model *domain.Model, userId uint64) (imGroupIds []string) { func GetUserRecentRooms(model *domain.Model, userId uint64, offset, limit int64) (imGroupIds []string, roomEnterTime map[string]int64) {
roomEnterTime = make(map[string]int64)
userKey := group_k.GetUserEnterRoomUserKey(userId) userKey := group_k.GetUserEnterRoomUserKey(userId)
var err error res, err := model.Redis.ZRevRangeByScoreWithScores(model, userKey, &redis.ZRangeBy{
imGroupIds, err = model.Redis.ZRangeByScore(model, userKey, &redis.ZRangeBy{ Min: fmt.Sprintf("%d", time.Now().AddDate(0, -3, 0).Unix()),
Min: fmt.Sprintf("%d", time.Now().AddDate(0, -3, 0).Unix()), Max: "+inf",
Max: "+inf", Offset: offset,
Count: limit,
}).Result() }).Result()
if err != nil { if err != nil {
return return
} }
for _, v := range res {
imGroupId := cast.ToString(v.Member)
imGroupIds = append(imGroupIds, imGroupId)
roomEnterTime[imGroupId] = int64(v.Score)
}
return return
} }
......
...@@ -83,17 +83,17 @@ func SetGroupMemberTTL(groupId string, ttl time.Duration) (bool, error) { ...@@ -83,17 +83,17 @@ func SetGroupMemberTTL(groupId string, ttl time.Duration) (bool, error) {
func GetGroupConsume(groupId string) (uint64, error) { func GetGroupConsume(groupId string) (uint64, error) {
key := getGroupConsumeKey(groupId) key := getGroupConsumeKey(groupId)
return redisCli.RedisClient.Get(context.Background(), key).Uint64() return redisCli.RedisClusterClient.Get(context.Background(), key).Uint64()
} }
func SetGroupConsume(groupId string, consume uint64, ttl time.Duration) error { func SetGroupConsume(groupId string, consume uint64, ttl time.Duration) error {
key := getGroupConsumeKey(groupId) key := getGroupConsumeKey(groupId)
return redisCli.RedisClient.Set(context.Background(), key, consume, ttl).Err() return redisCli.RedisClusterClient.Set(context.Background(), key, consume, ttl).Err()
} }
func ClearGroupConsume(groupId string) error { func ClearGroupConsume(groupId string) error {
key := getGroupConsumeKey(groupId) key := getGroupConsumeKey(groupId)
return redisCli.RedisClient.Del(context.Background(), key).Err() return redisCli.RedisClusterClient.Del(context.Background(), key).Err()
} }
// 增加编辑用户cd // 增加编辑用户cd
......
...@@ -14,14 +14,14 @@ func QueueOnMic(model *domain.Model, onMic *mic_ev.OnMicEvent) error { ...@@ -14,14 +14,14 @@ func QueueOnMic(model *domain.Model, onMic *mic_ev.OnMicEvent) error {
queue := mic_k.GetOnMicQueue() queue := mic_k.GetOnMicQueue()
onMic.Ts = time.Now().UnixNano() // 给一个时间戳 onMic.Ts = time.Now().UnixNano() // 给一个时间戳
body, _ := json.Marshal(onMic) body, _ := json.Marshal(onMic)
return model.Redis.RPush(model, queue, string(body)).Err() return model.RedisCluster.RPush(model, queue, string(body)).Err()
} }
// redis pop on mic // redis pop on mic
func BLPopQueueOnMic(model *domain.Model) *mic_ev.OnMicEvent { func BLPopQueueOnMic(model *domain.Model) *mic_ev.OnMicEvent {
var res *mic_ev.OnMicEvent var res *mic_ev.OnMicEvent
queue := mic_k.GetOnMicQueue() queue := mic_k.GetOnMicQueue()
strs, err := model.Redis.BLPop(model, time.Second, queue).Result() strs, err := model.RedisCluster.BLPop(model, time.Second, queue).Result()
if err != nil { if err != nil {
if err != redis.Nil { if err != redis.Nil {
model.Log.Errorf("BLPopQueueOnMic fail:%v", err) model.Log.Errorf("BLPopQueueOnMic fail:%v", err)
......
...@@ -27,17 +27,17 @@ func SetJSON(model *domain.Model, key string, obj interface{}) (err error) { ...@@ -27,17 +27,17 @@ func SetJSON(model *domain.Model, key string, obj interface{}) (err error) {
if err != nil { if err != nil {
return err return err
} }
return model.Redis.Set(model.Context, key, value, DEFAULT_TTL).Err() return model.RedisCluster.Set(model.Context, key, value, DEFAULT_TTL).Err()
} }
// 获取redis中json结构体 // 获取redis中json结构体
// return err: may redisV8.Nil // return err: may redisV8.Nil
func GetJSON(model *domain.Model, key string, obj interface{}) (err error) { func GetJSON(model *domain.Model, key string, obj interface{}) (err error) {
var value []byte var value []byte
defer func() { //defer func() {
model.Log.Infof("GetJson key:%v,value:%s,obj:%v,err:%v", key, value, obj, err) // model.Log.Infof("GetJson key:%v,value:%s,obj:%v,err:%v", key, value, obj, err)
}() //}()
value, err = model.Redis.Get(model.Context, key).Bytes() value, err = model.RedisCluster.Get(model.Context, key).Bytes()
if err != nil { if err != nil {
// may redisV2.Nil // may redisV2.Nil
return return
...@@ -59,7 +59,7 @@ func TryLock(model *domain.Model, key string, acquireTimeout, expireTimeout time ...@@ -59,7 +59,7 @@ func TryLock(model *domain.Model, key string, acquireTimeout, expireTimeout time
if time.Now().After(deadline) { if time.Now().After(deadline) {
return false return false
} }
flag, err := model.Redis.SetNX(model, key, "1", expireTimeout).Result() flag, err := model.RedisCluster.SetNX(model, key, "1", expireTimeout).Result()
if err != nil || !flag { if err != nil || !flag {
time.Sleep(time.Millisecond * 10) time.Sleep(time.Millisecond * 10)
} else { } else {
...@@ -70,5 +70,5 @@ func TryLock(model *domain.Model, key string, acquireTimeout, expireTimeout time ...@@ -70,5 +70,5 @@ func TryLock(model *domain.Model, key string, acquireTimeout, expireTimeout time
// 解锁 // 解锁
func UnLock(model *domain.Model, key string) { func UnLock(model *domain.Model, key string) {
model.Redis.Del(model, key) model.RedisCluster.Del(model, key)
} }
package res_c package res_c
import ( import (
"context"
"git.hilo.cn/hilo-common/domain" "git.hilo.cn/hilo-common/domain"
"hilo-group/_const/redis_key" "github.com/bluele/gcache"
"hilo-group/domain/model/res_m" "hilo-group/domain/model/res_m"
"time" "time"
) )
// 统一改成lru
var countryIconLru = gcache.New(1000).LRU().Build()
var countryIconKey = "country:icon"
var countryAreaLru = gcache.New(1000).LRU().Build()
var countryAreaKey = "country:area"
func GetCountryIconMap(model *domain.Model) (map[string]string, error) { func GetCountryIconMap(model *domain.Model) (map[string]string, error) {
m, err := GetAllCountryIcon(model) m, err := GetAllCountryIcon(model)
if err != nil || len(m) <= 0 { if err != nil || len(m) <= 0 {
...@@ -24,17 +30,22 @@ func GetCountryIconMap(model *domain.Model) (map[string]string, error) { ...@@ -24,17 +30,22 @@ func GetCountryIconMap(model *domain.Model) (map[string]string, error) {
} }
func GetAllCountryIcon(model *domain.Model) (map[string]string, error) { func GetAllCountryIcon(model *domain.Model) (map[string]string, error) {
key := redis_key.GetCountryIconKey() //key := redis_key.GetCountryIconKey()
return model.Redis.HGetAll(context.Background(), key).Result() if data, err := countryIconLru.Get(countryIconKey); err == nil {
return data.(map[string]string), nil
}
//return model.Redis.HGetAll(context.Background(), key).Result()
return map[string]string{}, nil
} }
func SaveAllCountryIcon(model *domain.Model, icons map[string]string) (int64, error) { func SaveAllCountryIcon(model *domain.Model, icons map[string]string) {
key := redis_key.GetCountryIconKey() //key := redis_key.GetCountryIconKey()
ret, err := model.Redis.HSet(context.Background(), key, icons).Result() //ret, err := model.Redis.HSet(context.Background(), key, icons).Result()
if err == nil { //if err == nil {
model.Redis.Expire(context.Background(), key, time.Minute*10) // model.Redis.Expire(context.Background(), key, time.Minute*10)
} //}
return ret, err //return ret, err
_ = countryIconLru.SetWithExpire(countryIconKey, icons, time.Minute*10)
} }
func GetCountryAreaMap(model *domain.Model) (map[string]string, error) { func GetCountryAreaMap(model *domain.Model) (map[string]string, error) {
...@@ -53,15 +64,20 @@ func GetCountryAreaMap(model *domain.Model) (map[string]string, error) { ...@@ -53,15 +64,20 @@ func GetCountryAreaMap(model *domain.Model) (map[string]string, error) {
} }
func GetAllCountryArea(model *domain.Model) (map[string]string, error) { func GetAllCountryArea(model *domain.Model) (map[string]string, error) {
key := redis_key.GetCountryAreaKey() //key := redis_key.GetCountryAreaKey()
return model.Redis.HGetAll(context.Background(), key).Result() //return model.Redis.HGetAll(context.Background(), key).Result()
if data, err := countryAreaLru.Get(countryAreaKey); err == nil {
return data.(map[string]string), nil
}
return map[string]string{}, nil
} }
func SaveAllCountryArea(model *domain.Model, data map[string]string) (int64, error) { func SaveAllCountryArea(model *domain.Model, data map[string]string) {
key := redis_key.GetCountryAreaKey() //key := redis_key.GetCountryAreaKey()
ret, err := model.Redis.HSet(context.Background(), key, data).Result() //ret, err := model.Redis.HSet(context.Background(), key, data).Result()
if err == nil { //if err == nil {
model.Redis.Expire(context.Background(), key, time.Minute*10) // model.Redis.Expire(context.Background(), key, time.Minute*10)
} //}
return ret, err //return ret, err
_ = countryAreaLru.SetWithExpire(countryAreaKey, data, time.Minute*10)
} }
...@@ -2,42 +2,44 @@ package room_c ...@@ -2,42 +2,44 @@ package room_c
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"git.hilo.cn/hilo-common/mylogrus" "git.hilo.cn/hilo-common/mylogrus"
"git.hilo.cn/hilo-common/resource/config"
"git.hilo.cn/hilo-common/resource/redisCli" "git.hilo.cn/hilo-common/resource/redisCli"
"github.com/bluele/gcache"
redis2 "github.com/go-redis/redis/v8" redis2 "github.com/go-redis/redis/v8"
"github.com/spf13/cast"
"hilo-group/_const/redis_key" "hilo-group/_const/redis_key"
"strconv" "hilo-group/_const/redis_key/group_k"
"time" "time"
) )
// 处理访问房间的相关缓存 // 处理访问房间的相关缓存
func ProcessRoomVisit(groupId string, userId uint64) error { func ProcessRoomVisit(groupId string, userId uint64) error {
key := redis_key.GetPrefixGroupInUserDuration(groupId) //key := redis_key.GetPrefixGroupInUserDuration(groupId)
now := time.Now() //now := time.Now()
ret, err := redisCli.GetRedis().ZAdd(context.Background(), key, &redis2.Z{ //ret, err := redisCli.GetRedis().ZAdd(context.Background(), key, &redis2.Z{
Score: float64(now.Unix()), // Score: float64(now.Unix()),
Member: userId, // Member: userId,
}).Result() //}).Result()
if err != nil { //if err != nil {
return err // return err
} //}
mylogrus.MyLog.Infof("ProcessRoomVisit, ZADD %s, return %d", key, ret) //mylogrus.MyLog.Infof("ProcessRoomVisit, ZADD %s, return %d", key, ret)
//
// 每群定时清一次数据可以了 //// 每群定时清一次数据可以了
if now.Second()%redis_key.GroupInDurationClearPeriod == 0 { //if now.Second()%redis_key.GroupInDurationClearPeriod == 0 {
rc, err := clearRoomVisit(groupId, now.AddDate(0, 0, -redis_key.GroupInDurationTTL)) // rc, err := clearRoomVisit(groupId, now.AddDate(0, 0, -redis_key.GroupInDurationTTL))
if err == nil { // if err == nil {
mylogrus.MyLog.Infof("ProcessRoomVisit, clearRoomVisit %s, return %d", key, rc) // mylogrus.MyLog.Infof("ProcessRoomVisit, clearRoomVisit %s, return %d", key, rc)
} else { // } else {
mylogrus.MyLog.Warnf("ProcessRoomVisit, clearRoomVisit %s, failed %s", key, err.Error()) // mylogrus.MyLog.Warnf("ProcessRoomVisit, clearRoomVisit %s, failed %s", key, err.Error())
} // }
} //}
// 马上更新roomVisitCount // 马上更新roomVisitCount
if _, err := GetSetRoomVisitCount(groupId); err != nil { if _, err := GetSetRoomVisitCount(groupId); err != nil {
mylogrus.MyLog.Warnf("ProcessRoomVisit, failed for key %s, err: %s", key, err.Error()) mylogrus.MyLog.Errorf("ProcessRoomVisit, failed for groupId %s, err: %s", groupId, err.Error())
} }
return nil return nil
...@@ -59,7 +61,10 @@ func ProcessUserRoomVisit(userId uint64, groupId string) error { ...@@ -59,7 +61,10 @@ func ProcessUserRoomVisit(userId uint64, groupId string) error {
} }
// 查询用户访问过的房间及其时间 // 查询用户访问过的房间及其时间
// todo 去掉查询,redis性能
func GetUserRoomVisit(userId uint64) (map[string]int64, error) { func GetUserRoomVisit(userId uint64) (map[string]int64, error) {
result := make(map[string]int64, 0)
return result, nil
key := redis_key.GetUserEnterRoomKey(userId) key := redis_key.GetUserEnterRoomKey(userId)
ret, err := redisCli.GetRedis().ZRangeWithScores(context.Background(), key, 0, -1).Result() ret, err := redisCli.GetRedis().ZRangeWithScores(context.Background(), key, 0, -1).Result()
if err != nil { if err != nil {
...@@ -67,7 +72,6 @@ func GetUserRoomVisit(userId uint64) (map[string]int64, error) { ...@@ -67,7 +72,6 @@ func GetUserRoomVisit(userId uint64) (map[string]int64, error) {
} }
//mylogrus.MyLog.Infof("GetUserRoomVisit, ZRangeWithScores %s, return %v", key, ret) //mylogrus.MyLog.Infof("GetUserRoomVisit, ZRangeWithScores %s, return %v", key, ret)
result := make(map[string]int64, 0)
for _, i := range ret { for _, i := range ret {
result[i.Member.(string)] = int64(i.Score) result[i.Member.(string)] = int64(i.Score)
} }
...@@ -75,54 +79,63 @@ func GetUserRoomVisit(userId uint64) (map[string]int64, error) { ...@@ -75,54 +79,63 @@ func GetUserRoomVisit(userId uint64) (map[string]int64, error) {
} }
// 批量获取房间访问人数 // 批量获取房间访问人数
// 带上lru
var roomVisitCountLru = gcache.New(100).LRU().Build()
func MGetRoomVisitCount(groupIds []string) (map[string]string, error) { func MGetRoomVisitCount(groupIds []string) (map[string]string, error) {
key := redis_key.GetPrefixRoomVisitCount()
visit := make(map[string]string) visit := make(map[string]string)
if len(groupIds) <= 0 { if len(groupIds) <= 0 {
return visit, nil return visit, nil
} }
res, err := redisCli.GetRedis().HMGet(context.Background(), key, groupIds...).Result() lKey := "room:visit:count"
if data, err := roomVisitCountLru.Get(lKey); err == nil {
return data.(map[string]string), nil
}
// 用redisCluster中的zset代替,只是取出大于10的
zKey := redis_key.GetPrefixRoomVisitCountZset()
cnt := 10
if !config.AppIsRelease() {
cnt = 0
}
zRes, err := redisCli.GetClusterRedis().ZRevRangeByScoreWithScores(context.Background(), zKey, &redis2.ZRangeBy{
Min: fmt.Sprintf("%d", cnt),
Max: "+inf",
}).Result()
if err != nil { if err != nil {
mylogrus.MyLog.Errorf("MGetRoomVisitCount zset fail:%v", err)
return visit, err return visit, err
} }
if len(res) != len(groupIds) { for _, v := range zRes {
return visit, errors.New(fmt.Sprintf("MGetRoomVisitCount fail,miss match len,%v-%v", len(res), len(groupIds))) visit[cast.ToString(v.Member)] = cast.ToString(v.Score)
}
for i, groupId := range groupIds {
if cnt, ok := res[i].(string); ok {
visit[groupId] = cnt
}
} }
_ = roomVisitCountLru.SetWithExpire(lKey, visit, time.Minute*15)
return visit, nil return visit, nil
} }
func GetSetRoomVisitCount(groupId string) (int64, error) { func GetSetRoomVisitCount(groupId string) (int64, error) {
key := redis_key.GetPrefixGroupInUserDuration(groupId) //key := redis_key.GetPrefixGroupInUserDuration(groupId)
key := group_k.GetUserEnterRoomGroupKey(groupId)
vc, err := redisCli.GetRedis().ZCard(context.Background(), key).Result() vc, err := redisCli.GetRedis().ZCard(context.Background(), key).Result()
// 查到合法值后,更新二级缓存 // 查到合法值后,更新二级缓存
if err == nil && vc >= 0 { if err == nil && vc >= 0 {
ret, err := saveRoomVisitCount(groupId, vc) if err := saveRoomVisitCount(groupId, vc); err != nil {
mylogrus.MyLog.Infof("saveRoomVisitCount %s, ret = %d, err: %v", groupId, ret, err) mylogrus.MyLog.Errorf("saveRoomVisitCount %s, err: %v", groupId, err)
}
} }
return vc, err return vc, err
} }
func saveRoomVisitCount(groupId string, count int64) (int64, error) { func saveRoomVisitCount(groupId string, count int64) error {
key := redis_key.GetPrefixRoomVisitCount() //key := redis_key.GetPrefixRoomVisitCount()
return redisCli.GetRedis().HSet(context.Background(), key, groupId, strconv.FormatInt(count, 10)).Result() zKey := redis_key.GetPrefixRoomVisitCountZset()
} // zset同步存一份到redis集群
if err := redisCli.GetClusterRedis().ZAdd(context.Background(), zKey, &redis2.Z{
func clearRoomVisit(groupId string, t time.Time) (int64, error) { Score: float64(count),
value := strconv.FormatInt(t.Unix(), 10) Member: groupId,
ret, err := redisCli.GetRedis().ZRemRangeByScore(context.Background(), redis_key.GetPrefixGroupInUserDuration(groupId), "0", value).Result() }).Err(); err != nil {
if err != nil { mylogrus.MyLog.Errorf("GetPrefixRoomVisitCountZset fail %s", err.Error())
return 0, err return err
} }
return ret, nil return nil
} //return redisCli.GetRedis().HSet(context.Background(), key, groupId, strconv.FormatInt(count, 10)).Result()
// Deprecated: hgetall有问题
func GetAllRoomVisitCount() (map[string]string, error) {
key := redis_key.GetPrefixRoomVisitCount()
return redisCli.GetRedis().HGetAll(context.Background(), key).Result()
} }
package user_c
import (
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/mysql"
"sync"
"time"
)
type UserLevel struct {
UserId mysql.ID
Level int
}
var svipVipNobleLock sync.RWMutex
var svipLevel = make(map[mysql.ID]int) // userId->svipLevel
var nobleLevel = make(map[mysql.ID]uint16) // userId->nobleLevel
var userVips = make(map[mysql.ID]bool) // userId->isVip
// 加载数据到lru
func LoadAllSvipVipNoble(model *domain.Model) {
start := time.Now()
var svips []UserLevel
svipMap := make(map[mysql.ID]int)
if err := model.DB().Table("user_svip").Select("user_id,level").Where("level > 0").Find(&svips).Error; err != nil {
model.Log.Errorf("LoadAllSvip fail:%v", err)
} else {
for _, v := range svips {
svipMap[v.UserId] = v.Level
}
}
var nobles []UserLevel
nobleMap := make(map[mysql.ID]uint16)
if err := model.DB().Table("user_noble").Select("user_id,MAX(level) level").
Where("level > 0 AND end_time > ?", time.Now()).Group("user_id").Find(&nobles).Error; err != nil {
model.Log.Errorf("LoadAllNoble fail:%v", err)
} else {
for _, v := range nobles {
nobleMap[v.UserId] = uint16(v.Level)
}
}
var vips []UserLevel
vipMap := make(map[mysql.ID]bool)
if err := model.DB().Table("user_vip").Select("user_id").
Where("expire_at > ?", time.Now()).Find(&vips).Error; err != nil {
model.Log.Errorf("LoadAllVip fail:%v", err)
} else {
for _, v := range vips {
vipMap[v.UserId] = true
}
}
// 上锁赋值
svipVipNobleLock.Lock()
svipLevel = svipMap
nobleLevel = nobleMap
userVips = vipMap
svipVipNobleLock.Unlock()
model.Log.Infof("LoadAllSvipVipNoble svip:%v,vip:%v,noble:%v,cost:%vs", len(svipMap), len(vipMap), len(nobleMap), time.Now().Sub(start).Seconds())
}
func BatchGetNobleLevel(model *domain.Model, userIds []uint64) map[uint64]uint16 {
res := make(map[uint64]uint16)
svipVipNobleLock.RLock()
defer svipVipNobleLock.RUnlock()
for _, userId := range userIds {
res[userId] = nobleLevel[userId]
}
return res
}
func MGetUserSvipLevel(model *domain.Model, userIds []uint64) map[uint64]int {
res := make(map[uint64]int)
svipVipNobleLock.RLock()
defer svipVipNobleLock.RUnlock()
for _, userId := range userIds {
res[userId] = svipLevel[userId]
}
return res
}
func BatchGetVips(model *domain.Model, userIds []uint64) map[uint64]*int64 {
res := make(map[uint64]*int64)
svipVipNobleLock.RLock()
defer svipVipNobleLock.RUnlock()
for _, userId := range userIds {
vip := int64(1)
if userVips[userId] {
res[userId] = &vip
}
}
return res
}
...@@ -38,6 +38,36 @@ func GetUserTinyById(model *domain.Model, userId mysql.ID) (*user_m.UserTiny, er ...@@ -38,6 +38,36 @@ func GetUserTinyById(model *domain.Model, userId mysql.ID) (*user_m.UserTiny, er
return userTiny, nil return userTiny, nil
} }
// 获取用户简要信息
// param userId 用户id
func MGetUserTinyById(model *domain.Model, userIds []mysql.ID) []*user_m.UserTiny {
var users []*user_m.UserTiny
for _, userId := range userIds {
if user, _ := GetUserTinyById(model, userId); user != nil {
users = append(users, user)
}
}
return users
}
// 获取用户externalIds
// return []externalIds map[userId]extId map[userId]code
func GetUserExternalIds(model *domain.Model, userIds []mysql.ID) ([]string, map[uint64]string, map[uint64]string) {
var res []string
var m = make(map[uint64]string)
var c = make(map[uint64]string)
if len(userIds) <= 0 {
return res, m, c
}
users := MGetUserTinyById(model, userIds)
for _, u := range users {
res = append(res, u.ExternalId)
m[u.ID] = u.ExternalId
c[u.ID] = u.Code
}
return res, m, c
}
// 获取用户简要信息By ExternalId // 获取用户简要信息By ExternalId
func GetUserByExternalId(model *domain.Model, externalId mysql.Str) (*user_m.UserTiny, error) { func GetUserByExternalId(model *domain.Model, externalId mysql.Str) (*user_m.UserTiny, error) {
userId, err := ToUserId(model, externalId) userId, err := ToUserId(model, externalId)
...@@ -52,7 +82,7 @@ func ToUserId(model *domain.Model, externalId mysql.Str) (mysql.ID, error) { ...@@ -52,7 +82,7 @@ func ToUserId(model *domain.Model, externalId mysql.Str) (mysql.ID, error) {
if externalId == "" { if externalId == "" {
return 0, myerr.NewSysError("externalId 不能为空") return 0, myerr.NewSysError("externalId 不能为空")
} }
userId, err := model.Redis.Get(model.Context, user_k.GetExternalIdToUidKey(externalId)).Int64() userId, err := model.RedisCluster.Get(model.Context, user_k.GetExternalIdToUidKey(externalId)).Int64()
if err != nil && err != redisV8.Nil { if err != nil && err != redisV8.Nil {
return 0, err return 0, err
} }
...@@ -75,7 +105,7 @@ func ToUserIdByCode(model *domain.Model, code mysql.Str) (mysql.ID, error) { ...@@ -75,7 +105,7 @@ func ToUserIdByCode(model *domain.Model, code mysql.Str) (mysql.ID, error) {
if code == "" { if code == "" {
return 0, myerr.NewSysError("code 不能为空") return 0, myerr.NewSysError("code 不能为空")
} }
userId, err := model.Redis.Get(model.Context, user_k.GetCodeToUidKey(code)).Int64() userId, err := model.RedisCluster.Get(model.Context, user_k.GetCodeToUidKey(code)).Int64()
if err != nil && err != redisV8.Nil { if err != nil && err != redisV8.Nil {
return 0, err return 0, err
} }
...@@ -104,11 +134,11 @@ func cacheUserTiny(model *domain.Model, user *user_m.User) error { ...@@ -104,11 +134,11 @@ func cacheUserTiny(model *domain.Model, user *user_m.User) error {
// return err // return err
//} //}
// cache externalId->userId // cache externalId->userId
if err := model.Redis.SetEX(model.Context, user_k.GetExternalIdToUidKey(user.ExternalId), user.ID, cache.GetDefaultTTL()).Err(); err != nil { if err := model.RedisCluster.SetEX(model.Context, user_k.GetExternalIdToUidKey(user.ExternalId), user.ID, cache.GetDefaultTTL()).Err(); err != nil {
return err return err
} }
// cache code->userId // cache code->userId
if err := model.Redis.SetEX(model.Context, user_k.GetCodeToUidKey(user.Code), user.ID, cache.GetDefaultTTL()).Err(); err != nil { if err := model.RedisCluster.SetEX(model.Context, user_k.GetCodeToUidKey(user.Code), user.ID, cache.GetDefaultTTL()).Err(); err != nil {
return err return err
} }
if err := cache.SetJSON(model, user_k.GetUserTinyKey(user.ID), userTiny); err != nil { if err := cache.SetJSON(model, user_k.GetUserTinyKey(user.ID), userTiny); err != nil {
......
package common package common
import ( import (
"context"
"encoding/json"
"git.hilo.cn/hilo-common/mylogrus"
"git.hilo.cn/hilo-common/resource/mysql" "git.hilo.cn/hilo-common/resource/mysql"
"git.hilo.cn/hilo-common/resource/redisCli"
"git.hilo.cn/hilo-common/utils" "git.hilo.cn/hilo-common/utils"
"hilo-group/_const/redis_key" "github.com/bluele/gcache"
"hilo-group/myerr"
"time" "time"
) )
func GetUserMedalMergeCache(userId mysql.ID) ([]uint32, error) { // 改成lru
bData, err := GetCache(redis_key.GetUserMedalMerge(userId)) var userMedalMergeLru = gcache.New(10000).LRU().Build()
if err != nil {
return nil, myerr.WrapErr(err)
}
res := make([]uint32, 0) func GetUserMedalMergeCache(userId mysql.ID) ([]uint32, error) {
err = json.Unmarshal(bData, &res) if data, err := userMedalMergeLru.Get(userId); err == nil {
if err != nil { return data.([]uint32), nil
return nil, myerr.WrapErr(err)
} }
return res, nil return nil, nil
} }
func SetUserMedalMergeCache(userId mysql.ID, data []uint32) error { func SetUserMedalMergeCache(userId mysql.ID, data []uint32) {
err := SetCache(redis_key.GetUserMedalMerge(userId), data, time.Hour*2) _ = userMedalMergeLru.SetWithExpire(userId, data, time.Minute*15)
if err != nil {
mylogrus.MyLog.Errorf("SetUserMedalMerge err:%s", err)
return myerr.WrapErr(err)
}
return nil
} }
// 删除勋章缓存, 延迟删除 // 删除勋章缓存, 延迟删除
...@@ -44,41 +30,6 @@ func DelUserMedalMergeCacheDelay(userId mysql.ID) { ...@@ -44,41 +30,6 @@ func DelUserMedalMergeCacheDelay(userId mysql.ID) {
}() }()
} }
func DelUserMedalMergeCache(userId mysql.ID) error { func DelUserMedalMergeCache(userId mysql.ID) {
err := DelCache(redis_key.GetUserMedalMerge(userId)) userMedalMergeLru.Remove(userId)
if err != nil {
mylogrus.MyLog.Errorf("DetUserMedalMerge err:%s, userId:%v", err, userId)
return myerr.WrapErr(err)
}
return nil
}
func DelCache(key string) error {
err := redisCli.GetRedis().Del(context.Background(), key).Err()
if err != nil {
mylogrus.MyLog.Errorf("DelCache key:%s, err:%s", key, err)
return err
}
return nil
}
func GetCache(key string) ([]byte, error) {
data, err := redisCli.GetRedis().Get(context.Background(), key).Bytes()
if err != nil {
return nil, err
}
return data, nil
}
func SetCache(key string, data interface{}, expire time.Duration) error {
jData, err := json.Marshal(data)
if err != nil {
return err
}
err = redisCli.GetRedis().Set(context.Background(), key, jData, expire).Err()
if err != nil {
mylogrus.MyLog.Errorf("SetCache key:%s, data:%v, err:%s", key, data, err)
return err
}
return nil
} }
...@@ -182,9 +182,9 @@ func (g *GiftOperate) BatchGetConsumeByRange(beginTime, endTime time.Time) ([]Sc ...@@ -182,9 +182,9 @@ func (g *GiftOperate) BatchGetConsumeByRange(beginTime, endTime time.Time) ([]Sc
return rows, nil return rows, nil
} }
func (g *GiftOperate) BatchGetSupportList(beginTime, endTime time.Time) ([]uint64, error) { func (g *GiftOperate) BatchGetSupportList(model *domain.Model, beginTime, endTime time.Time) ([]uint64, error) {
userIds := make([]uint64, 0) userIds := make([]uint64, 0)
err := g.DB().Model(g). err := model.DB().Model(g).
Select("DISTINCT(send_user_id) AS user_id"). Select("DISTINCT(send_user_id) AS user_id").
Where(g).Where("created_time BETWEEN ? AND ?", beginTime, endTime).Pluck("user_id", &userIds).Error Where(g).Where("created_time BETWEEN ? AND ?", beginTime, endTime).Pluck("user_id", &userIds).Error
if err != nil { if err != nil {
......
...@@ -154,56 +154,6 @@ func IncrGroupPowerExpOnMic(model *domain.Model, groupPowerId, userId mysql.ID) ...@@ -154,56 +154,6 @@ func IncrGroupPowerExpOnMic(model *domain.Model, groupPowerId, userId mysql.ID)
return nil return nil
} }
// 增加势力上麦时长-家族之星
// 事务操作
func IncrGroupPowerStarOnMicMonth(model *domain.Model, groupPowerId, userId mysql.ID, joinMicTimestamp int64) error {
// 月统计
//star, err := GetGroupPowerMonthStar(model, groupPowerId, userId, groupPower_e.GroupPowerStarTypeActive)
//curTs := joinMicTimestamp
//nowTs := time.Now().Unix()
//month0Ts := now.BeginningOfMonth().Unix()
//if err != nil && err != gorm.ErrRecordNotFound {
// return err
//}
//if star != nil && joinMicTimestamp < star.LastCalTs { // 加入的时间比上次计算时间小
// curTs = star.LastCalTs
//}
//// 跨月
//if curTs < month0Ts {
// curTs = month0Ts
//}
//score := nowTs - curTs
score := 60
err := IncrGroupPowerMonthStarScore(model, groupPowerId, userId,
groupPower_e.GroupPowerStarTypeActive, mysql.Num(score), 0)
return err
}
// 增加势力上麦时长-家族之星
// 事务操作
func IncrGroupPowerStarOnMicDay(model *domain.Model, groupPowerId, userId mysql.ID, joinMicTimestamp int64) error {
// 日统计
//star, err := GetGroupPowerDayStar(model, groupPowerId, userId, groupPower_e.GroupPowerStarTypeActive)
//curTs := joinMicTimestamp
//nowTs := time.Now().Unix()
//day0Ts := now.BeginningOfDay().Unix()
//if err != nil && err != gorm.ErrRecordNotFound {
// return err
//}
//if star != nil && joinMicTimestamp < star.LastCalTs { // 加入的时间比上次计算时间小
// curTs = star.LastCalTs
//}
//// 跨天
//if curTs < day0Ts {
// curTs = day0Ts
//}
//score := nowTs - curTs
score := 60
err := IncrGroupPowerDayStarScore(model, groupPowerId, userId,
groupPower_e.GroupPowerStarTypeActive, mysql.Num(score), 0)
return err
}
// 清理所有家族的经验 // 清理所有家族的经验
func ClearGroupPowerExp(model *domain.Model) error { func ClearGroupPowerExp(model *domain.Model) error {
var groupPowerGrades []*GroupPowerGrade var groupPowerGrades []*GroupPowerGrade
......
...@@ -15,12 +15,11 @@ type GroupPowerExpRank struct { ...@@ -15,12 +15,11 @@ type GroupPowerExpRank struct {
// 获取家族经验排行榜 // 获取家族经验排行榜
// param limit: 排行榜人数 // param limit: 排行榜人数
// 10166 线上员工,对应的势力不上榜,groupPowerId=8951,6171(产品要移走) // 10166 线上员工,对应的势力不上榜,groupPowerId=8951
func GetGroupPowerExpRank(model *domain.Model, beginDate, endDate string, limit int, gpStatus groupPower_e.GroupPowerStatus, area int) ([]GroupPowerExpRank, error) { func GetGroupPowerExpRank(model *domain.Model, beginDate, endDate string, limit int, gpStatus groupPower_e.GroupPowerStatus, area int) ([]GroupPowerExpRank, error) {
var res []GroupPowerExpRank var res []GroupPowerExpRank
db := model.DB().Table("group_power_day_exp gpd").Select("gpd.group_power_id,SUM(gpd.exp) as exp"). db := model.DB().Table("group_power_day_exp gpd").Select("gpd.group_power_id,SUM(gpd.exp) as exp").
Where("gpd.group_power_id <> 8951"). Where("gpd.group_power_id <> 8951").
Where("gpd.group_power_id <> 6171").
Where("gpd.date BETWEEN ? AND ?", beginDate, endDate) Where("gpd.date BETWEEN ? AND ?", beginDate, endDate)
if gpStatus > 0 { if gpStatus > 0 {
db = db.Joins("left join group_power gp on gpd.group_power_id = gp.id").Where("gp.status = ?", gpStatus) db = db.Joins("left join group_power gp on gpd.group_power_id = gp.id").Where("gp.status = ?", gpStatus)
......
...@@ -35,6 +35,7 @@ type GroupPowerDayStar struct { ...@@ -35,6 +35,7 @@ type GroupPowerDayStar struct {
} }
// 增加家族之星分数 // 增加家族之星分数
// Deprecated: 用redis
func IncrGroupPowerMonthStarScore(model *domain.Model, groupPowerId, userId mysql.ID, _type groupPower_e.GroupPowerStarType, score mysql.Num, lastCalTs int64) error { func IncrGroupPowerMonthStarScore(model *domain.Model, groupPowerId, userId mysql.ID, _type groupPower_e.GroupPowerStarType, score mysql.Num, lastCalTs int64) error {
month := time.Now().Format("200601") month := time.Now().Format("200601")
star := &GroupPowerMonthStar{ star := &GroupPowerMonthStar{
...@@ -59,6 +60,7 @@ func IncrGroupPowerMonthStarScore(model *domain.Model, groupPowerId, userId mysq ...@@ -59,6 +60,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 { func IncrGroupPowerDayStarScore(model *domain.Model, groupPowerId, userId mysql.ID, _type groupPower_e.GroupPowerStarType, score mysql.Num, lastCalTs int64) error {
star := &GroupPowerDayStar{ star := &GroupPowerDayStar{
Date: time.Now(), Date: time.Now(),
...@@ -81,29 +83,8 @@ func IncrGroupPowerDayStarScore(model *domain.Model, groupPowerId, userId mysql. ...@@ -81,29 +83,8 @@ func IncrGroupPowerDayStarScore(model *domain.Model, groupPowerId, userId mysql.
return nil 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
}
// 获取家族之星排行 // 获取家族之星排行
// Deprecated: 用redis
func GetGroupPowerMonthStarRank(model *domain.Model, groupPowerId mysql.ID, _type groupPower_e.GroupPowerStarType, offset, limit int, month string) ([]*GroupPowerMonthStar, error) { func GetGroupPowerMonthStarRank(model *domain.Model, groupPowerId mysql.ID, _type groupPower_e.GroupPowerStarType, offset, limit int, month string) ([]*GroupPowerMonthStar, error) {
var res []*GroupPowerMonthStar var res []*GroupPowerMonthStar
//month := time.Now().Format("200601") //month := time.Now().Format("200601")
......
...@@ -13,6 +13,7 @@ import ( ...@@ -13,6 +13,7 @@ import (
"gorm.io/gorm" "gorm.io/gorm"
"hilo-group/_const/enum/group_e" "hilo-group/_const/enum/group_e"
"hilo-group/_const/redis_key" "hilo-group/_const/redis_key"
"hilo-group/_const/redis_key/mic_k"
"hilo-group/myerr" "hilo-group/myerr"
"strconv" "strconv"
"strings" "strings"
...@@ -242,6 +243,20 @@ func BatchGetAllMicUser(model *domain.Model, groupIds []string) (map[string][]my ...@@ -242,6 +243,20 @@ func BatchGetAllMicUser(model *domain.Model, groupIds []string) (map[string][]my
if len(groupIds) <= 0 { if len(groupIds) <= 0 {
return result, nil return result, nil
} }
// 获取群组中上麦用户
for _, groupId := range groupIds {
groupMicUserKey := mic_k.GetGroupOnMicUser(groupId)
userIds, err := model.Redis.HVals(model, groupMicUserKey).Result()
if err != nil {
model.Log.Errorf("BatchGetAllMicUser fail:%v", err)
}
for _, userIdStr := range userIds {
if userId, _ := strconv.ParseUint(userIdStr, 10, 64); userId > 0 {
result[groupId] = append(result[groupId], userId)
}
}
}
return result, nil
keys := make([]string, 0) keys := make([]string, 0)
for _, g := range groupIds { for _, g := range groupIds {
......
...@@ -31,11 +31,10 @@ var bannedGroupCache = gcache.New(100).LRU().Build() ...@@ -31,11 +31,10 @@ var bannedGroupCache = gcache.New(100).LRU().Build()
func GetBannedGroups(model *domain.Model) ([]GroupBanned, error) { func GetBannedGroups(model *domain.Model) ([]GroupBanned, error) {
key := "banned" key := "banned"
if data, err := bannedGroupCache.Get(key); err == nil { if data, err := bannedGroupCache.Get(key); err == nil {
model.Log.Infof("GetBannedGroups cache:%v", len(data.([]GroupBanned)))
return data.([]GroupBanned), nil return data.([]GroupBanned), nil
} }
result := make([]GroupBanned, 0) result := make([]GroupBanned, 0)
err := model.Db.Find(&result).Error err := model.DB().Find(&result).Error
if err != nil { if err != nil {
return nil, err return nil, err
} }
......
...@@ -3,6 +3,7 @@ package group_m ...@@ -3,6 +3,7 @@ package group_m
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
"git.hilo.cn/hilo-common/domain" "git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/mylogrus" "git.hilo.cn/hilo-common/mylogrus"
"git.hilo.cn/hilo-common/resource/config" "git.hilo.cn/hilo-common/resource/config"
...@@ -14,6 +15,7 @@ import ( ...@@ -14,6 +15,7 @@ import (
"gorm.io/gorm" "gorm.io/gorm"
"hilo-group/_const/enum/group_e" "hilo-group/_const/enum/group_e"
"hilo-group/_const/redis_key" "hilo-group/_const/redis_key"
"hilo-group/_const/redis_key/mic_k"
"hilo-group/common" "hilo-group/common"
"hilo-group/domain/model/noble_m" "hilo-group/domain/model/noble_m"
"hilo-group/domain/model/res_m" "hilo-group/domain/model/res_m"
...@@ -255,6 +257,10 @@ func (mic *Mic) In(userId uint64, externalId string) error { ...@@ -255,6 +257,10 @@ func (mic *Mic) In(userId uint64, externalId string) error {
return bizerr.GroupMicUserHasIn return bizerr.GroupMicUserHasIn
} }
// 增加群组中上麦用户
groupMicUserKey := mic_k.GetGroupOnMicUser(mic.GroupUuid)
mic.model.Redis.HSet(mic.model, groupMicUserKey, mic.I, userId)
//离开动作已结束,增加到队列中 //离开动作已结束,增加到队列中
MicChangeRPush(mic.model, mic.GroupUuid, mic.I) MicChangeRPush(mic.model, mic.GroupUuid, mic.I)
...@@ -385,6 +391,10 @@ func (micUser *MicUser) leave(operateUserId uint64, operateExternalId string) er ...@@ -385,6 +391,10 @@ func (micUser *MicUser) leave(operateUserId uint64, operateExternalId string) er
//return bizerr.GroupMicErr //return bizerr.GroupMicErr
} }
// 减少群组中上麦用户
groupMicUserKey := mic_k.GetGroupOnMicUser(micUser.GroupUuid)
micUser.model.Redis.HDel(micUser.model, groupMicUserKey, fmt.Sprintf("%d", micUser.I))
//离开动作已结束,增加到队列中 //离开动作已结束,增加到队列中
MicChangeRPush(micUser.model, micUser.GroupUuid, micUser.I) MicChangeRPush(micUser.model, micUser.GroupUuid, micUser.I)
...@@ -916,7 +926,40 @@ func GetMicHasInGroupNum(model *domain.Model) (map[string]int64, error) { ...@@ -916,7 +926,40 @@ func GetMicHasInGroupNum(model *domain.Model) (map[string]int64, error) {
} }
// cache 1min // cache 1min
_ = micGroupNumCache.SetWithExpire(micGroupNumKey, resultGroupUuids, time.Minute*15) _ = micGroupNumCache.SetWithExpire(micGroupNumKey, resultGroupUuids, time.Minute*15)
//model.Log.Infof("GetMicHasInGroupNum cache miss:%v", resultGroupUuids) return resultGroupUuids, nil
}
// 获取麦上人数
func GetMicHasInGroupNumByList(model *domain.Model, groupIds []string) (map[string]int64, error) {
resultGroupUuids := make(map[string]int64, len(groupIds))
micHasInKey := redis_key.GetPrefixGroupMicHasIn()
for _, group := range groupIds {
isMem, err := redisCli.GetRedis().SIsMember(context.Background(), micHasInKey, group).Result()
if err != nil {
model.Log.Errorf("GetMicHasInGroupNumByList err:%v", err)
return nil, myerr.WrapErr(err)
}
if isMem {
s := strings.Replace(micHasInScript, "{key}", micHasInKey, -1)
s = strings.Replace(s, "{remKey}", group, -1)
for i := 1; i <= MaxMicNum; i++ {
s = strings.Replace(s, "{key"+strconv.Itoa(i)+"}", redis_key.GetPrefixGroupMicUser(group, i), -1)
}
//r, err := redis2.NewScript(s).Run(context.Background(), redisCli.GetRedis(), []string{}).Result()
sha1, err := model.Redis.ScriptLoad(model, s).Result()
if err != nil {
return nil, myerr.WrapErr(err)
}
micNum, err := model.Redis.EvalSha(model, sha1, nil, nil).Int64()
if err != nil {
return nil, myerr.WrapErr(err)
}
//d := r.(int64)
if micNum > 0 {
resultGroupUuids[group] = micNum
}
}
}
return resultGroupUuids, nil return resultGroupUuids, nil
} }
......
...@@ -96,7 +96,7 @@ func MicGroupKickOutRPush(model *domain.Model, groupUid string, userExternalId s ...@@ -96,7 +96,7 @@ func MicGroupKickOutRPush(model *domain.Model, groupUid string, userExternalId s
} }
// socket通知被拉黑者退房 // socket通知被拉黑者退房
rpc.SendQuitRoom(beKickuserId, 2, txGroupId) rpc.SendQuitRoom(beKickuserId, 2, txGroupId)
if n, err := redisCli.GetRedis().RPush(context.Background(), redis_key.GetMicInfoChange(), string(str)).Result(); err != nil || n == 0 { if n, err := redisCli.GetClusterRedis().RPush(context.Background(), redis_key.GetMicInfoChange(), string(str)).Result(); err != nil || n == 0 {
model.Log.Errorf("MicChangeRPush MicGroupKickOutRPush err:%+v, groupUuid:%v, micContent:%+v", err, groupUid, string(str)) model.Log.Errorf("MicChangeRPush MicGroupKickOutRPush err:%+v, groupUuid:%v, micContent:%+v", err, groupUid, string(str))
return return
} else { } else {
...@@ -130,7 +130,7 @@ func MicSocketMicOutRPush(model *domain.Model, groupUid string, userExternalId s ...@@ -130,7 +130,7 @@ func MicSocketMicOutRPush(model *domain.Model, groupUid string, userExternalId s
model.Log.Errorf("MicChangeRPush MicSocketMicOutRPush Marshal MicSystemMsg err:%+v, groupUuid:%v, micContent:%+v", err, groupUid, string(str)) model.Log.Errorf("MicChangeRPush MicSocketMicOutRPush Marshal MicSystemMsg err:%+v, groupUuid:%v, micContent:%+v", err, groupUid, string(str))
return return
} }
if n, err := redisCli.GetRedis().RPush(context.Background(), redis_key.GetMicInfoChange(), string(str)).Result(); err != nil || n == 0 { if n, err := redisCli.GetClusterRedis().RPush(context.Background(), redis_key.GetMicInfoChange(), string(str)).Result(); err != nil || n == 0 {
model.Log.Errorf("MicChangeRPush MicSocketMicOutRPush err:%+v, groupUuid:%v, micContent:%+v", err, groupUid, string(str)) model.Log.Errorf("MicChangeRPush MicSocketMicOutRPush err:%+v, groupUuid:%v, micContent:%+v", err, groupUid, string(str))
return return
} else { } else {
...@@ -165,7 +165,7 @@ func MicNumChangeRPush(model *domain.Model, groupUid string, micNumType group_e. ...@@ -165,7 +165,7 @@ func MicNumChangeRPush(model *domain.Model, groupUid string, micNumType group_e.
model.Log.Errorf("MicChangeRPush MicNumChangeRPush Marshal MicSystemMsg err:%+v, groupUuid:%v, micContent:%+v", err, groupUid, string(str)) model.Log.Errorf("MicChangeRPush MicNumChangeRPush Marshal MicSystemMsg err:%+v, groupUuid:%v, micContent:%+v", err, groupUid, string(str))
return return
} }
if n, err := redisCli.GetRedis().RPush(context.Background(), redis_key.GetMicInfoChange(), string(str)).Result(); err != nil || n == 0 { if n, err := redisCli.GetClusterRedis().RPush(context.Background(), redis_key.GetMicInfoChange(), string(str)).Result(); err != nil || n == 0 {
model.Log.Errorf("MicChangeRPush MicNumChangeRPush err:%+v, groupUuid:%v, micContent:%+v", err, groupUid, string(str)) model.Log.Errorf("MicChangeRPush MicNumChangeRPush err:%+v, groupUuid:%v, micContent:%+v", err, groupUid, string(str))
return return
} else { } else {
...@@ -206,7 +206,7 @@ func MicEmptyRPush(model *domain.Model, groupUid string, i int) { ...@@ -206,7 +206,7 @@ func MicEmptyRPush(model *domain.Model, groupUid string, i int) {
model.Log.Errorf("MicChangeRPush MicEmptyRPush Marshal MicSystemMsg err:%+v, groupUuid:%v, i:%v, micContent:%+v", err, groupUid, i, string(micContent)) model.Log.Errorf("MicChangeRPush MicEmptyRPush Marshal MicSystemMsg err:%+v, groupUuid:%v, i:%v, micContent:%+v", err, groupUid, i, string(micContent))
return return
} }
if n, err := redisCli.GetRedis().RPush(context.Background(), redis_key.GetMicInfoChange(), string(str)).Result(); err != nil || n == 0 { if n, err := redisCli.GetClusterRedis().RPush(context.Background(), redis_key.GetMicInfoChange(), string(str)).Result(); err != nil || n == 0 {
model.Log.Errorf("MicChangeRPush MicEmptyRPush err:%+v, groupUuid:%v, i:%v, micContent:%+v", err, groupUid, i, string(micContent)) model.Log.Errorf("MicChangeRPush MicEmptyRPush err:%+v, groupUuid:%v, i:%v, micContent:%+v", err, groupUid, i, string(micContent))
return return
} else { } else {
...@@ -243,7 +243,7 @@ func MicChangeRPush(model *domain.Model, groupUid string, i int) { ...@@ -243,7 +243,7 @@ func MicChangeRPush(model *domain.Model, groupUid string, i int) {
model.Log.Errorf("MicChangeRPush MicChangeRPush Marshal MicSystemMsg err:%+v, groupUuid:%v, i:%v, micContent:%+v", err, groupUid, i, string(micContentStr)) model.Log.Errorf("MicChangeRPush MicChangeRPush Marshal MicSystemMsg err:%+v, groupUuid:%v, i:%v, micContent:%+v", err, groupUid, i, string(micContentStr))
return return
} }
if n, err := redisCli.GetRedis().RPush(context.Background(), redis_key.GetMicInfoChange(), string(str)).Result(); err != nil || n == 0 { if n, err := redisCli.GetClusterRedis().RPush(context.Background(), redis_key.GetMicInfoChange(), string(str)).Result(); err != nil || n == 0 {
model.Log.Errorf("MicChangeRPush MicChangeRPush err:%+v, groupUuid:%v, i:%v, micContent:%+v", err, groupUid, i, string(micContentStr)) model.Log.Errorf("MicChangeRPush MicChangeRPush err:%+v, groupUuid:%v, i:%v, micContent:%+v", err, groupUid, i, string(micContentStr))
return return
} else { } else {
...@@ -288,7 +288,7 @@ func MicAllRPush(model *domain.Model, groupUid string, externalId string) error ...@@ -288,7 +288,7 @@ func MicAllRPush(model *domain.Model, groupUid string, externalId string) error
model.Log.Errorf("MicChangeRPush MicAllRPush Marshal MicSystemMsg err:%+v, groupUuid:%v, externalId:%v, micContent:%+v", err, groupUid, externalId, string(micContentStr)) model.Log.Errorf("MicChangeRPush MicAllRPush Marshal MicSystemMsg err:%+v, groupUuid:%v, externalId:%v, micContent:%+v", err, groupUid, externalId, string(micContentStr))
continue continue
} }
if n, err := redisCli.GetRedis().RPush(context.Background(), redis_key.GetMicInfoChange(), string(str)).Result(); err != nil || n == 0 { if n, err := redisCli.GetClusterRedis().RPush(context.Background(), redis_key.GetMicInfoChange(), string(str)).Result(); err != nil || n == 0 {
model.Log.Errorf("MicChangeRPush MicAllRPush err:%+v, groupUuid:%v, externalId:%v, micContent:%+v", err, groupUid, externalId, string(micContentStr)) model.Log.Errorf("MicChangeRPush MicAllRPush err:%+v, groupUuid:%v, externalId:%v, micContent:%+v", err, groupUid, externalId, string(micContentStr))
continue continue
} else { } else {
...@@ -312,7 +312,7 @@ func MicRPush(model *domain.Model, txGroupId string, msg GroupSystemMsg) error { ...@@ -312,7 +312,7 @@ func MicRPush(model *domain.Model, txGroupId string, msg GroupSystemMsg) error {
model.Log.Errorf("MicRPush Marshal MicSystemMsg err:%+v, txGroupId:%v, micContent:%+v", err, txGroupId, string(str)) model.Log.Errorf("MicRPush Marshal MicSystemMsg err:%+v, txGroupId:%v, micContent:%+v", err, txGroupId, string(str))
return err return err
} }
if n, err := redisCli.GetRedis().RPush(context.Background(), redis_key.GetMicInfoChange(), string(str)).Result(); err != nil || n == 0 { if n, err := redisCli.GetClusterRedis().RPush(context.Background(), redis_key.GetMicInfoChange(), string(str)).Result(); err != nil || n == 0 {
model.Log.Errorf("MicRPush err:%+v, txGroupId:%v, micContent:%+v", err, txGroupId, string(str)) model.Log.Errorf("MicRPush err:%+v, txGroupId:%v, micContent:%+v", err, txGroupId, string(str))
return err return err
} }
......
...@@ -14,6 +14,7 @@ import ( ...@@ -14,6 +14,7 @@ import (
"gorm.io/gorm/clause" "gorm.io/gorm/clause"
"hilo-group/_const/enum/group_e" "hilo-group/_const/enum/group_e"
"hilo-group/_const/redis_key" "hilo-group/_const/redis_key"
"hilo-group/_const/redis_key/group_k"
"hilo-group/domain/cache/room_c" "hilo-group/domain/cache/room_c"
"hilo-group/domain/model/user_m" "hilo-group/domain/model/user_m"
"hilo-group/myerr" "hilo-group/myerr"
...@@ -49,14 +50,14 @@ func RoomLivingExpire(model *domain.Model, groupUid string, userId uint64) { ...@@ -49,14 +50,14 @@ func RoomLivingExpire(model *domain.Model, groupUid string, userId uint64) {
model.Log.Infof("room RoomLivingExpire userId:%v, groupUid:%v", userId, groupUid) model.Log.Infof("room RoomLivingExpire userId:%v, groupUid:%v", userId, groupUid)
// //
key := redis_key.GetPrefixGroupRoomLiving() key := redis_key.GetPrefixGroupRoomLiving()
i, err := redisCli.GetRedis().ZAdd(context.Background(), key, &redis2.Z{ _, err := model.RedisCluster.ZAdd(context.Background(), key, &redis2.Z{
Score: float64(time.Now().Unix()), Score: float64(time.Now().Unix()),
Member: getMemberStr(groupUid, userId), Member: getMemberStr(groupUid, userId),
}).Result() }).Result()
if err != nil { if err != nil {
model.Log.Errorf("RoomLivingExpire ZAdd key:%v, groupUid:%v, userId:%v, err:%v", key, groupUid, userId, err) model.Log.Errorf("RoomLivingExpire ZAdd key:%v, groupUid:%v, userId:%v, err:%v", key, groupUid, userId, err)
} else { } else {
model.Log.Infof("RoomLivingExpire ZAdd key:%v, groupUid:%v, userId:%v result:%v", key, groupUid, userId, i) //model.Log.Infof("RoomLivingExpire ZAdd key:%v, groupUid:%v, userId:%v result:%v", key, groupUid, userId, i)
} }
} }
...@@ -69,14 +70,14 @@ func RoomLivingIn(model *domain.Model, groupUid string, userId uint64, externalI ...@@ -69,14 +70,14 @@ func RoomLivingIn(model *domain.Model, groupUid string, userId uint64, externalI
} }
// //
key := redis_key.GetPrefixGroupRoomLiving() key := redis_key.GetPrefixGroupRoomLiving()
i, err := redisCli.GetRedis().ZAdd(context.Background(), key, &redis2.Z{ _, err := model.RedisCluster.ZAdd(context.Background(), key, &redis2.Z{
Score: float64(time.Now().Unix()), Score: float64(time.Now().Unix()),
Member: getMemberStr(groupUid, userId), Member: getMemberStr(groupUid, userId),
}).Result() }).Result()
if err != nil { if err != nil {
model.Log.Errorf("UpdateRoomLiving ZAdd key:%v, groupUid:%v, userId:%v, err:%v", key, groupUid, userId, err) model.Log.Errorf("UpdateRoomLiving ZAdd key:%v, groupUid:%v, userId:%v, err:%v", key, groupUid, userId, err)
} else { } else {
model.Log.Infof("UpdateRoomLiving ZAdd key:%v, groupUid:%v, userId:%v result:%v", key, groupUid, userId, i) //model.Log.Infof("UpdateRoomLiving ZAdd key:%v, groupUid:%v, userId:%v result:%v", key, groupUid, userId, i)
} }
go func(myContext *mycontext.MyContext, groupId string) { go func(myContext *mycontext.MyContext, groupId string) {
...@@ -111,11 +112,11 @@ func roomLivingLeave(model *domain.Model, userId uint64, groupId string) ([]stri ...@@ -111,11 +112,11 @@ func roomLivingLeave(model *domain.Model, userId uint64, groupId string) ([]stri
key := redis_key.GetPrefixGroupRoomLiving() key := redis_key.GetPrefixGroupRoomLiving()
//if err := redisCli.ClearExpired(key, expireMinute); err != nil { //if err := redisCli.ClearExpired(key, expireMinute); err != nil {
if err := model.Redis.ZRemRangeByScore(model, key, "0", strconv.FormatInt(time.Now().Unix()-expireMinute, 10)).Err(); err != nil { if err := model.RedisCluster.ZRemRangeByScore(model, key, "0", strconv.FormatInt(time.Now().Unix()-expireMinute, 10)).Err(); err != nil {
return nil, myerr.WrapErr(err) return nil, myerr.WrapErr(err)
} }
data, err := redisCli.GetRedis().ZRange(context.Background(), key, 0, -1).Result() data, err := model.RedisCluster.ZRange(context.Background(), key, 0, -1).Result()
if err != nil { if err != nil {
return nil, myerr.WrapErr(err) return nil, myerr.WrapErr(err)
} }
...@@ -124,12 +125,12 @@ func roomLivingLeave(model *domain.Model, userId uint64, groupId string) ([]stri ...@@ -124,12 +125,12 @@ func roomLivingLeave(model *domain.Model, userId uint64, groupId string) ([]stri
for i, _ := range data { for i, _ := range data {
gid, uid := analysisMemberStr(data[i]) gid, uid := analysisMemberStr(data[i])
if uid == userId && (groupId == "" || gid == groupId) { if uid == userId && (groupId == "" || gid == groupId) {
if _, err := redisCli.GetRedis().ZRem(context.Background(), key, getMemberStr(gid, uid)).Result(); err != nil { if _, err := model.RedisCluster.ZRem(context.Background(), key, getMemberStr(gid, uid)).Result(); err != nil {
model.Log.Errorf("RoomLivingLeave ZRem key:%s, groupId:%s, userId:%d, err:%v", key, gid, uid, err) model.Log.Errorf("RoomLivingLeave ZRem key:%s, groupId:%s, userId:%d, err:%v", key, gid, uid, err)
return nil, myerr.WrapErr(err) return nil, myerr.WrapErr(err)
} else { } else {
groupIds = append(groupIds, gid) groupIds = append(groupIds, gid)
model.Log.Infof("RoomLivingLeave ZRem success key:%s, groupId:%s, userId:%d", key, gid, uid) //model.Log.Infof("RoomLivingLeave ZRem success key:%s, groupId:%s, userId:%d", key, gid, uid)
} }
// 发信令,让前端重新拉取,接受容错, // 发信令,让前端重新拉取,接受容错,
...@@ -271,11 +272,11 @@ func RoomLivingExistsUserId(groupUid string) ([]uint64, error) { ...@@ -271,11 +272,11 @@ func RoomLivingExistsUserId(groupUid string) ([]uint64, error) {
key := redis_key.GetPrefixGroupRoomLiving() key := redis_key.GetPrefixGroupRoomLiving()
//if err := redisCli.ClearExpired(key, expireMinute); err != nil { //if err := redisCli.ClearExpired(key, expireMinute); err != nil {
var model = domain.CreateModelNil() var model = domain.CreateModelNil()
if err := model.Redis.ZRemRangeByScore(model, key, "0", strconv.FormatInt(time.Now().Unix()-expireMinute, 10)).Err(); err != nil { if err := model.RedisCluster.ZRemRangeByScore(model, key, "0", strconv.FormatInt(time.Now().Unix()-expireMinute, 10)).Err(); err != nil {
return nil, myerr.WrapErr(err) return nil, myerr.WrapErr(err)
} }
groupUserIdstrs, err := redisCli.GetRedis().ZRevRange(context.Background(), key, 0, -1).Result() groupUserIdstrs, err := model.RedisCluster.ZRevRange(context.Background(), key, 0, -1).Result()
if err != nil { if err != nil {
return nil, myerr.WrapErr(err) return nil, myerr.WrapErr(err)
} }
...@@ -299,11 +300,11 @@ func RoomLivingUserIdFilter(userIds []mysql.ID) (map[mysql.ID]string, error) { ...@@ -299,11 +300,11 @@ func RoomLivingUserIdFilter(userIds []mysql.ID) (map[mysql.ID]string, error) {
key := redis_key.GetPrefixGroupRoomLiving() key := redis_key.GetPrefixGroupRoomLiving()
//if err := redisCli.ClearExpired(key, expireMinute); err != nil { //if err := redisCli.ClearExpired(key, expireMinute); err != nil {
model := domain.CreateModelNil() model := domain.CreateModelNil()
if err := model.Redis.ZRemRangeByScore(model, key, "0", strconv.FormatInt(time.Now().Unix()-expireMinute, 10)).Err(); err != nil { if err := model.RedisCluster.ZRemRangeByScore(model, key, "0", strconv.FormatInt(time.Now().Unix()-expireMinute, 10)).Err(); err != nil {
return nil, myerr.WrapErr(err) return nil, myerr.WrapErr(err)
} }
groupUserIdstrs, err := redisCli.GetRedis().ZRange(context.Background(), key, 0, -1).Result() groupUserIdstrs, err := model.RedisCluster.ZRange(context.Background(), key, 0, -1).Result()
if err != nil { if err != nil {
return nil, myerr.WrapErr(err) return nil, myerr.WrapErr(err)
} }
...@@ -324,12 +325,12 @@ func RoomLivingUserIdFilter(userIds []mysql.ID) (map[mysql.ID]string, error) { ...@@ -324,12 +325,12 @@ func RoomLivingUserIdFilter(userIds []mysql.ID) (map[mysql.ID]string, error) {
func RoomLivingExistsGroup(model *domain.Model) (map[string]map[uint64]struct{}, error) { func RoomLivingExistsGroup(model *domain.Model) (map[string]map[uint64]struct{}, error) {
key := redis_key.GetPrefixGroupRoomLiving() key := redis_key.GetPrefixGroupRoomLiving()
//if err := redisCli.ClearExpired(key, expireMinute); err != nil { //if err := redisCli.ClearExpired(key, expireMinute); err != nil {
if err := model.Redis.ZRemRangeByScore(model, key, "0", strconv.FormatInt(time.Now().Unix()-expireMinute, 10)).Err(); err != nil { if err := model.RedisCluster.ZRemRangeByScore(model, key, "0", strconv.FormatInt(time.Now().Unix()-expireMinute, 10)).Err(); err != nil {
model.Log.Infof("RoomLivingExistsGroup: err:%v", err) model.Log.Infof("RoomLivingExistsGroup: err:%v", err)
return nil, myerr.WrapErr(err) return nil, myerr.WrapErr(err)
} }
groupUserIdstrs, err := redisCli.GetRedis().ZRange(context.Background(), key, 0, -1).Result() groupUserIdstrs, err := model.RedisCluster.ZRange(context.Background(), key, 0, -1).Result()
if err != nil { if err != nil {
return nil, myerr.WrapErr(err) return nil, myerr.WrapErr(err)
} }
...@@ -343,7 +344,7 @@ func RoomLivingExistsGroup(model *domain.Model) (map[string]map[uint64]struct{}, ...@@ -343,7 +344,7 @@ func RoomLivingExistsGroup(model *domain.Model) (map[string]map[uint64]struct{},
groupGroup[tempGroupUid] = map[uint64]struct{}{userId: {}} groupGroup[tempGroupUid] = map[uint64]struct{}{userId: {}}
} }
} }
model.Log.Infof("RoomLivingExistsGroup size = %d", len(groupGroup)) //model.Log.Infof("RoomLivingExistsGroup size = %d", len(groupGroup))
return groupGroup, nil return groupGroup, nil
} }
...@@ -389,18 +390,8 @@ func GetAllGroupsSorted(model *domain.Model) ([]string, error) { ...@@ -389,18 +390,8 @@ func GetAllGroupsSorted(model *domain.Model) ([]string, error) {
// 取房间最近N天的访问人数 // 取房间最近N天的访问人数
func GetRoomVisitCount(groupId string) (int64, error) { func GetRoomVisitCount(groupId string) (int64, error) {
// 每群定时请一次数据可以了 key := group_k.GetUserEnterRoomGroupKey(groupId)
now := time.Now() visitCount, err := redisCli.GetRedis().ZCard(context.Background(), key).Result()
if now.Second()%redis_key.GroupInDurationClearPeriod == 0 {
// 先移除(N天之前的),后统计
if _, err := redisCli.GetRedis().ZRemRangeByScore(context.Background(), redis_key.GetPrefixGroupInUserDuration(groupId),
"0", strconv.FormatInt(time.Now().AddDate(0, 0, -redis_key.GroupInDurationTTL).Unix(), 10)).
Result(); err != nil {
return 0, err
}
}
visitCount, err := redisCli.GetRedis().ZCard(context.Background(), redis_key.GetPrefixGroupInUserDuration(groupId)).Result()
if err != nil { if err != nil {
return 0, err return 0, err
} }
...@@ -429,15 +420,12 @@ func BatchGetRoomVisitCount(logE *logrus.Entry, groupIds []string) (map[string]i ...@@ -429,15 +420,12 @@ func BatchGetRoomVisitCount(logE *logrus.Entry, groupIds []string) (map[string]i
if err != nil { if err != nil {
return nil, err return nil, err
} }
//logE.Infof("MGetRoomVisitCount:%v", roomVisitCount)
visitCount := make(map[string]int64) visitCount := make(map[string]int64)
for _, groupId := range groupIds { for _, groupId := range groupIds {
// 先从二级缓存中找 // 先从二级缓存中找
if c, ok := roomVisitCount[groupId]; ok { if c, ok := roomVisitCount[groupId]; ok {
if vc, err := strconv.ParseInt(c, 10, 64); err == nil && vc > 0 { if vc, err := strconv.ParseInt(c, 10, 64); err == nil && vc > 0 {
logE.Debugf("GetRoomVisitCount, from roomVisitCount %s - %d", groupId, vc)
visitCount[groupId] = vc visitCount[groupId] = vc
} }
} else { } else {
......
...@@ -57,6 +57,24 @@ func GetAllGroupSupportResult(db *gorm.DB, period string) (map[string]uint8, err ...@@ -57,6 +57,24 @@ func GetAllGroupSupportResult(db *gorm.DB, period string) (map[string]uint8, err
return result, nil return result, nil
} }
func GetGroupSupportResult(db *gorm.DB, period string, groupIds []string) (map[string]uint8, error) {
if len(period) <= 0 {
return nil, nil
}
gsr := GroupSupportResult{
Period: period,
}
rows := make([]GroupSupportResult, 0)
if err := db.Where(gsr).Where("group_uid in (?)", groupIds).Find(&rows).Error; err != nil {
return nil, err
}
result := make(map[string]uint8)
for _, i := range rows {
result[i.GroupUid] = i.Grade
}
return result, nil
}
//群组扶持奖励,利益分配者 //群组扶持奖励,利益分配者
type GroupSupportAwardAdmin struct { type GroupSupportAwardAdmin struct {
mysql.Entity mysql.Entity
......
...@@ -105,7 +105,7 @@ func (rb *RoomBanner) GetRoomBanners(db *gorm.DB, vcAllow bool) ([]RoomBanner, e ...@@ -105,7 +105,7 @@ func (rb *RoomBanner) GetRoomBanners(db *gorm.DB, vcAllow bool) ([]RoomBanner, e
for _, v := range rows { for _, v := range rows {
// 版本控制 // 版本控制
if !vcAllow && (v.ID == 241 || v.ID == 781 || v.ID == 771 || v.ID == 911 || v.ID == 841 || if !vcAllow && (v.ID == 241 || v.ID == 781 || v.ID == 771 || v.ID == 911 || v.ID == 841 ||
v.ID == 851 || v.ID == 1001 || v.ID == 981 || v.ID == 1451) { v.ID == 851 || v.ID == 1001 || v.ID == 981 || v.ID == 1451 || v.ID == 1621) {
continue continue
} }
res = append(res, v) res = append(res, v)
......
...@@ -213,3 +213,10 @@ func GetLangeByCountry(db *gorm.DB, country mysql.Str) (string, error) { ...@@ -213,3 +213,10 @@ func GetLangeByCountry(db *gorm.DB, country mysql.Str) (string, error) {
return "", myerr.WrapErr(err) return "", myerr.WrapErr(err)
} }
} }
//获取所有国家名字列表
func GetCountryNameList(model *domain.Model) ([]string, error) {
res := make([]string, 0)
err := model.DB().Table("res_country").Select("distinct(name) name").Pluck("name", &res).Error
return res, myerr.WrapErr(err)
}
...@@ -387,10 +387,10 @@ func getOnlineStatus(extIds []string) ([]interface{}, error) { ...@@ -387,10 +387,10 @@ func getOnlineStatus(extIds []string) ([]interface{}, error) {
for _, e := range extIds { for _, e := range extIds {
keys = append(keys, redis_key.GetOnLineStatusKey(e)) keys = append(keys, redis_key.GetOnLineStatusKey(e))
} }
return redisCli.RedisClient.MGet(context.Background(), keys...).Result() return redisCli.RedisClusterClient.MGet(context.Background(), keys...).Result()
} }
func setOnlineStatus(extId string, status uint, ttl time.Duration) error { func setOnlineStatus(extId string, status uint, ttl time.Duration) error {
key := redis_key.GetOnLineStatusKey(extId) key := redis_key.GetOnLineStatusKey(extId)
return redisCli.RedisClient.Set(context.Background(), key, status, ttl).Err() return redisCli.RedisClusterClient.Set(context.Background(), key, status, ttl).Err()
} }
...@@ -70,8 +70,8 @@ func GetUserMedalMerge(logger *logrus.Entry, db *gorm.DB, userId mysql.ID) ([]ui ...@@ -70,8 +70,8 @@ func GetUserMedalMerge(logger *logrus.Entry, db *gorm.DB, userId mysql.ID) ([]ui
} }
} }
} }
logger.Infof("maxGrade %+v", maxGrades) //logger.Infof("maxGrade %+v", maxGrades)
logger.Infof("maxMedalIds %+v", maxMedalIds) //logger.Infof("maxMedalIds %+v", maxMedalIds)
mIds := result mIds := result
result = make([]uint32, 0) result = make([]uint32, 0)
......
...@@ -144,3 +144,39 @@ func GetUsers(model *domain.Model, ids []mysql.ID) ([]*User, error) { ...@@ -144,3 +144,39 @@ func GetUsers(model *domain.Model, ids []mysql.ID) ([]*User, error) {
} }
return res, nil return res, nil
} }
// 获取用户externalIds
// return []externalIds map[userId]extId map[userId]code
func GetUserExternalIds(model *domain.Model, userIds []mysql.ID) ([]string, map[uint64]string, map[uint64]string) {
var res []string
var m = make(map[uint64]string)
var c = make(map[uint64]string)
if len(userIds) <= 0 {
return res, m, c
}
var users []User
total := len(userIds)
const NUM = 500
start, end := 0, NUM
for start < total {
if end > total {
end = total
}
var tmp []User
tmpUserId := userIds[start:end]
if err := model.DB().Model(User{}).Where("id in (?)", tmpUserId).Select("id,external_id,code").Find(&tmp).Error; err != nil {
model.Log.Errorf("GetUserExternalIds fail:%v", err)
} else if len(tmp) > 0 {
users = append(users, tmp...)
}
start += NUM
end += NUM
}
for _, user := range users {
res = append(res, user.ExternalId)
m[user.ID] = user.ExternalId
c[user.ID] = user.Code
}
return res, m, c
}
...@@ -8,8 +8,10 @@ import ( ...@@ -8,8 +8,10 @@ import (
"git.hilo.cn/hilo-common/resource/redisCli" "git.hilo.cn/hilo-common/resource/redisCli"
"git.hilo.cn/hilo-common/rpc" "git.hilo.cn/hilo-common/rpc"
uuid "github.com/satori/go.uuid" uuid "github.com/satori/go.uuid"
"hilo-group/_const/enum/groupPower_e"
"hilo-group/_const/enum/group_e" "hilo-group/_const/enum/group_e"
"hilo-group/_const/redis_key" "hilo-group/_const/redis_key"
"hilo-group/domain/cache/groupPower_c"
"hilo-group/domain/event/group_ev" "hilo-group/domain/event/group_ev"
"hilo-group/domain/model/groupPower_m" "hilo-group/domain/model/groupPower_m"
"hilo-group/domain/model/group_m" "hilo-group/domain/model/group_m"
...@@ -320,12 +322,10 @@ func (s *GroupMicService) IncrGroupPowerOnMicExpAndTime(groupId string, userId u ...@@ -320,12 +322,10 @@ func (s *GroupMicService) IncrGroupPowerOnMicExpAndTime(groupId string, userId u
if err := groupPower_m.IncrGroupPowerExpOnMic(model, groupPowerId, userId); err != nil { if err := groupPower_m.IncrGroupPowerExpOnMic(model, groupPowerId, userId); err != nil {
model.Log.Errorf("IncrGroupPowerExpOnMic fail:%v", err) model.Log.Errorf("IncrGroupPowerExpOnMic fail:%v", err)
} }
// 增加势力上麦时长-月 // 增加势力上麦时长-天/周/月
if err := groupPower_m.IncrGroupPowerStarOnMicMonth(model, groupPowerId, userId, joinMicTimestamp); err != nil { //if err := groupPower_m.IncrGroupPowerStarOnMicDay(model, groupPowerId, userId, joinMicTimestamp); err != nil {
model.Log.Errorf("IncrGroupPowerStarOnMicMonth fail:%v", err) if err := groupPower_c.IncrGroupPowerDayStarScore(model, groupPowerId, userId,
} groupPower_e.GroupPowerStarTypeActive, 60); err != nil {
// 增加势力上麦时长-天
if err := groupPower_m.IncrGroupPowerStarOnMicDay(model, groupPowerId, userId, joinMicTimestamp); err != nil {
model.Log.Errorf("IncrGroupPowerStarOnMicDay fail:%v", err) model.Log.Errorf("IncrGroupPowerStarOnMicDay fail:%v", err)
} }
return nil return nil
......
...@@ -13,6 +13,7 @@ import ( ...@@ -13,6 +13,7 @@ import (
"hilo-group/_const/enum/msg_e" "hilo-group/_const/enum/msg_e"
"hilo-group/cv/group_power_cv" "hilo-group/cv/group_power_cv"
"hilo-group/cv/user_cv" "hilo-group/cv/user_cv"
"hilo-group/domain/cache/groupPower_c"
"hilo-group/domain/cache/user_c" "hilo-group/domain/cache/user_c"
"hilo-group/domain/event/group_power_ev" "hilo-group/domain/event/group_power_ev"
"hilo-group/domain/model/groupPower_m" "hilo-group/domain/model/groupPower_m"
...@@ -154,7 +155,12 @@ func GetGroupPowerRankResp(model *domain.Model, beginDate, endDate string, userI ...@@ -154,7 +155,12 @@ func GetGroupPowerRankResp(model *domain.Model, beginDate, endDate string, userI
} }
func GetGroupPowerStar(model *domain.Model, groupPowerId mysql.ID, _type groupPower_e.GroupPowerStarType, offset, limit int, month string) ([]*group_power_cv.CvGroupPowerStarData, error) { func GetGroupPowerStar(model *domain.Model, groupPowerId mysql.ID, _type groupPower_e.GroupPowerStarType, offset, limit int, month string) ([]*group_power_cv.CvGroupPowerStarData, error) {
rank, err := groupPower_m.GetGroupPowerMonthStarRank(model, groupPowerId, _type, offset, limit, month) monthTime, err := time.Parse("200601", month)
if err != nil {
return nil, err
}
//rank, err := groupPower_m.GetGroupPowerMonthStarRank(model, groupPowerId, _type, offset, limit, month)
rank, err := groupPower_c.GetGroupPowerStarRankPeriod(model, "month", groupPowerId, _type, offset, limit, monthTime.Format("2006-01-02"))
if err != nil { if err != nil {
return nil, err return nil, err
} }
......
...@@ -4,8 +4,8 @@ import ( ...@@ -4,8 +4,8 @@ import (
"encoding/json" "encoding/json"
"git.hilo.cn/hilo-common/domain" "git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/mycontext" "git.hilo.cn/hilo-common/mycontext"
"git.hilo.cn/hilo-common/resource/config"
"git.hilo.cn/hilo-common/resource/mysql" "git.hilo.cn/hilo-common/resource/mysql"
"github.com/bluele/gcache"
"gorm.io/gorm" "gorm.io/gorm"
"hilo-group/_const/enum/group_e" "hilo-group/_const/enum/group_e"
"hilo-group/_const/enum/mgr_e" "hilo-group/_const/enum/mgr_e"
...@@ -18,7 +18,6 @@ import ( ...@@ -18,7 +18,6 @@ import (
"hilo-group/domain/model/user_m" "hilo-group/domain/model/user_m"
"hilo-group/domain/service/signal_s" "hilo-group/domain/service/signal_s"
"hilo-group/myerr" "hilo-group/myerr"
"strconv"
"time" "time"
) )
...@@ -31,7 +30,7 @@ func NewGroupService(myContext *mycontext.MyContext) *GroupService { ...@@ -31,7 +30,7 @@ func NewGroupService(myContext *mycontext.MyContext) *GroupService {
return &GroupService{svc} return &GroupService{svc}
} }
// 取本周最高的扶持等级 fixme:删除这个过渡函数 // 取本周最高的扶持等级
func (s *GroupService) GetWeekMaxSupportLevelMap() (map[string]uint8, error) { func (s *GroupService) GetWeekMaxSupportLevelMap() (map[string]uint8, error) {
return s.GetSupportLevelMap(time.Now().AddDate(0, 0, -group_e.SUPPORT_LEVEL_PERIOD_DAY)) return s.GetSupportLevelMap(time.Now().AddDate(0, 0, -group_e.SUPPORT_LEVEL_PERIOD_DAY))
} }
...@@ -42,56 +41,57 @@ func (s *GroupService) GetSupportLevelMap(now time.Time) (map[string]uint8, erro ...@@ -42,56 +41,57 @@ func (s *GroupService) GetSupportLevelMap(now time.Time) (map[string]uint8, erro
_, _, period := group_m.GetSupportLevelTime(now) _, _, period := group_m.GetSupportLevelTime(now)
levels, err := GetAllSupportLevel(model, period) levels, err := GetAllSupportLevel(model, period)
if err != nil { if err == nil {
return nil, err return levels, nil
} }
model.Log.Debugf("GetSupportLevelMap, GET %s: %v", period, levels) // cache miss
result := make(map[string]uint8, 0) result, err := group_m.GetAllGroupSupportResult(model.Db, period)
if len(levels) > 0 { if err == nil {
for g, l := range levels { SaveAllSupportLevel(model, period, result)
le, err := strconv.ParseUint(l, 10, 8)
if err == nil {
result[g] = uint8(le)
}
}
} else {
result, err = group_m.GetAllGroupSupportResult(model.Db, period)
if err == nil {
ret, err := SaveAllSupportLevel(model, period, result)
model.Log.Infof("GetSupportLevelMap SAVE ret = %d, err: %v", ret, err)
}
} }
return result, nil return result, nil
} }
func SaveAllSupportLevel(model *domain.Model, date string, levels map[string]uint8) (int64, error) { //// 取本周最高的扶持等级
values := make(map[string]interface{}, 0) //func (s *GroupService) GetWeekMaxSupportLevelMapByIds(groupIds []string) (map[string]uint8, error) {
for g, l := range levels { // return s.GetSupportLevelMapByIds(groupIds, time.Now().AddDate(0, 0, -group_e.SUPPORT_LEVEL_PERIOD_DAY))
if l > 0 { //}
values[g] = l //
} //func (s *GroupService) GetSupportLevelMapByIds(groupIds []string, now time.Time) (map[string]uint8, error) {
} // model := domain.CreateModel(s.svc.CtxAndDb)
if len(values) <= 0 { //
return 0, nil // _, _, period := group_m.GetSupportLevelTime(now)
} //
key := redis_key.GetPrefixSupportLevel(date) // levels, err := GetAllSupportLevel(model, period)
ret, err := model.Redis.HSet(model, key, values).Result() // if err == nil {
// return levels, nil
// }
// // cache miss
//
// result, err := group_m.GetGroupSupportResult(model.DB(), period, groupIds)
// if err == nil {
// SaveAllSupportLevel(model, period, result)
// }
// return result, nil
//}
if err == nil { // supportLevelLru Cache
// 设置一个TTL保险一些 TODO: 可以优化,保证数据总是有的 var supportLevelCache = gcache.New(100).LRU().Build()
ttl := time.Hour
if !config.AppIsRelease() { func SaveAllSupportLevel(model *domain.Model, date string, levels map[string]uint8) {
ttl = time.Minute key := redis_key.GetPrefixSupportLevel(date)
} _ = supportLevelCache.SetWithExpire(key, levels, time.Hour)
model.Redis.Expire(model, key, ttl) return
}
return ret, err
} }
func GetAllSupportLevel(model *domain.Model, date string) (map[string]string, error) { func GetAllSupportLevel(model *domain.Model, date string) (map[string]uint8, error) {
key := redis_key.GetPrefixSupportLevel(date) key := redis_key.GetPrefixSupportLevel(date)
return model.Redis.HGetAll(model, key).Result() if data, err := supportLevelCache.Get(key); err == nil {
return data.(map[string]uint8), nil
} else {
return map[string]uint8{}, err
}
} }
func (s *GroupService) GetJoinGroupLimit(userId mysql.ID) (uint, error) { func (s *GroupService) GetJoinGroupLimit(userId mysql.ID) (uint, error) {
......
package group_s
import (
"context"
"git.hilo.cn/hilo-common/_const/rediskey"
"git.hilo.cn/hilo-common/domain"
"github.com/go-redis/redis/v8"
"hilo-group/_const/enum/gift_e"
"hilo-group/cv/gift_cv"
"hilo-group/domain/cache/room_c"
"hilo-group/domain/model/group_m"
"hilo-group/domain/model/res_m"
"sort"
"strconv"
"time"
)
func SortGroupCommonCountryList(model *domain.Model) {
// 常用的国家
countryMap := map[string]struct{}{"India": {}, "Indonesia": {}, "Iraq": {}, "KSA": {}, "Kuwait": {}, "Pakistan": {}, "Turkey": {}}
for country, _ := range countryMap {
sortGroupList, err := GetGroupSortList(model, country)
if err != nil {
model.Log.Errorf("SortGroupCommonCountryList err:%v", err)
return
}
// 写入redis
err = setToRedis(model, country, sortGroupList)
if err != nil {
model.Log.Errorf("SortGroupCommonCountryList country:%v, len(sortGroupList):%v, err:%v", country, len(sortGroupList), err)
return
}
time.Sleep(time.Second * 3)
}
}
func SortGroupNotCommonCountryList(model *domain.Model) {
// 常用的国家
countryMap := map[string]struct{}{"India": {}, "Indonesia": {}, "Iraq": {}, "KSA": {}, "Kuwait": {}, "Pakistan": {}, "Turkey": {}}
// 取所有的国家名字
allCountryList, err := res_m.GetCountryNameList(model)
if err != nil {
model.Log.Errorf("SortGroupNotCommonCountryList err:%v", err)
return
}
for _, country := range allCountryList {
if _, ok := countryMap[country]; ok {
continue
}
// 计算非常用国家
sortGroupList, err := GetGroupSortList(model, country)
if err != nil {
model.Log.Errorf("SortGroupNotCommonCountryList err:%v", err)
return
}
// 写入redis
err = setToRedis(model, country, sortGroupList)
if err != nil {
model.Log.Errorf("SortGroupNotCommonCountryList country:%v, len(sortGroupList):%v, err:%v", country, len(sortGroupList), err)
return
}
time.Sleep(time.Second * 5)
}
}
func setToRedis(model *domain.Model, country string, groupList []string) error {
// 写入redis
key := rediskey.GetGroupCountrySortList(country)
for idx, group := range groupList {
err := model.RedisCluster.ZRemRangeByRank(context.Background(), key, int64(idx), int64(idx)).Err() // 先删除旧的
if err != nil {
model.Log.Errorf("setToRedis SortGroup key:%v, idx:%v, err:%v", key, idx, err)
return err
}
// 插入
err = model.RedisCluster.ZAdd(context.Background(), key, &redis.Z{Score: float64(idx), Member: group}).Err()
if err != nil {
model.Log.Errorf("setToRedis SortGroup key:%v, idx:%v, group:%s, err:%v", key, idx, group, err)
return err
}
if idx%1000 == 0 {
time.Sleep(time.Millisecond * 50)
}
}
return nil
}
// 计算国家群组列表排序
func GetGroupSortList(model *domain.Model, country string) ([]string, error) {
bannedGroups, err := group_m.GetBannedGroupsMap(model)
if err != nil {
return nil, err
}
beginTime := time.Now()
groups, banCount, visitCount, err := GetCandidatesByCountry(model, bannedGroups, country)
if err != nil {
return nil, err
}
endTime := time.Now()
model.Log.Infof("GroupCountryListSort: candidates size = %d, takes %d ms banned = %d, visitCount size = %d",
len(groups), endTime.Sub(beginTime).Milliseconds(), banCount, len(visitCount))
// 获取麦上有人的所有群组及麦上人数
micGroupNum, err := group_m.GetMicHasInGroupNum(model)
if err != nil {
return nil, err
}
model.Log.Infof("GroupCountryListSort, micGroupNum : %v", micGroupNum)
model.Log.Infof("GroupCountryListSort cost2:%v", time.Now().Sub(beginTime))
sortedGroupIds := make([]string, 0)
diamondGroupIds := make([]string, 0)
for i, _ := range groups {
// 麦上没人也放出来
sortedGroupIds = append(sortedGroupIds, i)
// 麦上有人才计算流水
if micGroupNum[i] > 0 {
diamondGroupIds = append(diamondGroupIds, i)
}
}
now := time.Now()
bTime := now.Add(-time.Minute * 30)
g := gift_cv.GiftOperate{SceneType: gift_e.GroupSceneType}
diamonds, err := g.GetRangeConsumeSummaryV2(bTime, now, diamondGroupIds)
if err != nil {
return nil, err
}
model.Log.Infof("GroupCountryListSort, diamonds in 30 mins: %v", diamonds)
model.Log.Infof("GroupCountryListSort cost3:%v", time.Now().Sub(beginTime))
//supportLevels, err := NewGroupService(model.MyContext).GetWeekMaxSupportLevelMap()
//if err != nil {
// return nil, err
//}
//model.Log.Infof("GroupCountryListSort, supportLevels : %v", supportLevels)
model.Log.Infof("GroupCountryListSort cost4:%v", time.Now().Sub(beginTime))
// 排序优先级2022-07-25
sort.Slice(sortedGroupIds, func(i, j int) bool {
gi := sortedGroupIds[i]
gj := sortedGroupIds[j]
// 1、按麦上人数多少排序
if micGroupNum[gi] > micGroupNum[gj] {
return true
} else if micGroupNum[gi] < micGroupNum[gj] {
return false
}
// 2、麦上人数相同,按30分钟内送礼钻石数排序
if diamonds[gi] > diamonds[gj] {
return true
} else if diamonds[gi] < diamonds[gj] {
return false
}
// 3. 根据热度排序groupInUserDuration
if visitCount[gi] > visitCount[gj] {
return true
} else if visitCount[gi] < visitCount[gj] {
return false
}
// * Final resort: 群组CODE,短号优先,然后按字母序
return len(groups[gi].Code) < len(groups[gj].Code) || len(groups[gi].Code) == len(groups[gj].Code) && groups[gi].Code < groups[gj].Code
})
model.Log.Infof("GroupCountryListSort cost5:%v", time.Now().Sub(beginTime))
return sortedGroupIds, nil
}
// 国家群候选:没有密码且没被封禁的群, 有国家
func GetCandidatesByCountry(model *domain.Model, bannedGroups map[string]uint64, country string) (map[string]*group_m.GroupInfo, int, map[string]int64, error) {
noPwdGroups, err := group_m.FindOwnerCountryGroups(model, country)
if err != nil {
return nil, 0, nil, err
}
var groupIds []string
for _, v := range noPwdGroups {
groupIds = append(groupIds, v.ImGroupId) // imGroupId
}
//roomVisitCount, err := room_c.GetAllRoomVisitCount()
roomVisitCount, err := room_c.MGetRoomVisitCount(groupIds)
if err != nil {
return nil, 0, nil, err
}
gameRoom := group_m.GetGameGroupsMap(model)
banCount := 0
groups := make(map[string]*group_m.GroupInfo, 0)
visitCount := make(map[string]int64)
for i, v := range noPwdGroups {
// 过滤掉被封禁的群
if bannedGroups[v.ImGroupId] != 0 {
banCount++
continue
}
// 过滤游戏房
if gameRoom[v.ImGroupId] {
continue
}
// 先从二级缓存中找
if c, ok := roomVisitCount[v.ImGroupId]; ok {
if vc, err := strconv.ParseInt(c, 10, 64); err == nil && vc > 0 {
//model.Log.Debugf("getPopularCandidates, from roomVisitCount %s(%s) - %d", v.ImGroupId, v.Code, vc)
groups[v.ImGroupId] = &noPwdGroups[i]
visitCount[v.ImGroupId] = vc
}
} else {
// 如果没有,就从roomVisit中取
if vc, err := room_c.GetSetRoomVisitCount(v.ImGroupId); err == nil && vc > 0 {
model.Log.Infof("getPopularCandidates, from roomVisit %s(%s) - %d", v.ImGroupId, v.Code, vc)
groups[v.ImGroupId] = &noPwdGroups[i]
visitCount[v.ImGroupId] = vc
}
}
}
return groups, banCount, visitCount, nil
}
func GetVisitCount(groupIds []string) (map[string]int64, error) {
roomVisitCount, err := room_c.MGetRoomVisitCount(groupIds)
if err != nil {
return nil, err
}
visitCount := make(map[string]int64)
for _, v := range groupIds {
// 先从二级缓存中找
if c, ok := roomVisitCount[v]; ok {
if vc, err := strconv.ParseInt(c, 10, 64); err == nil && vc > 0 {
visitCount[v] = vc
}
} else {
// 如果没有,就从roomVisit中取
if vc, err := room_c.GetSetRoomVisitCount(v); err == nil && vc > 0 {
visitCount[v] = vc
}
}
}
return visitCount, nil
}
...@@ -11,6 +11,8 @@ MYSQL_DB=hilo_code ...@@ -11,6 +11,8 @@ MYSQL_DB=hilo_code
[REDIS] [REDIS]
REDIS_HOST=47.244.34.27:6379 REDIS_HOST=47.244.34.27:6379
REDIS_PASSWORD=8QZ9JD1zLvPR3yHf REDIS_PASSWORD=8QZ9JD1zLvPR3yHf
REDIS_CLUSTER_HOST=47.244.34.27:6379
REDIS_CLUSTER_PASSWORD=8QZ9JD1zLvPR3yHf
[JWT] [JWT]
SECRET=hilo1632 SECRET=hilo1632
ISSUER_API=hiloApi ISSUER_API=hiloApi
......
...@@ -23,6 +23,7 @@ import ( ...@@ -23,6 +23,7 @@ import (
"hilo-group/cv/group_power_cv" "hilo-group/cv/group_power_cv"
"hilo-group/cv/medal_cv" "hilo-group/cv/medal_cv"
"hilo-group/cv/user_cv" "hilo-group/cv/user_cv"
"hilo-group/domain/cache/groupPower_c"
"hilo-group/domain/cache/res_c" "hilo-group/domain/cache/res_c"
"hilo-group/domain/cache/user_c" "hilo-group/domain/cache/user_c"
"hilo-group/domain/model/game_m" "hilo-group/domain/model/game_m"
...@@ -820,7 +821,7 @@ func GroupPowerInfo(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -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 { if err != nil {
return myContext, myerr.WrapErr(err) return myContext, myerr.WrapErr(err)
} }
......
...@@ -10,6 +10,7 @@ import ( ...@@ -10,6 +10,7 @@ import (
"hilo-group/_const/enum/groupPower_e" "hilo-group/_const/enum/groupPower_e"
"hilo-group/cv/group_power_cv" "hilo-group/cv/group_power_cv"
"hilo-group/cv/user_cv" "hilo-group/cv/user_cv"
"hilo-group/domain/cache/groupPower_c"
"hilo-group/domain/model/groupPower_m" "hilo-group/domain/model/groupPower_m"
"hilo-group/domain/model/user_m" "hilo-group/domain/model/user_m"
"hilo-group/domain/service/group_power_s" "hilo-group/domain/service/group_power_s"
...@@ -264,7 +265,7 @@ func GroupPowerStarPeriod(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -264,7 +265,7 @@ func GroupPowerStarPeriod(c *gin.Context) (*mycontext.MyContext, error) {
} }
var model = domain.CreateModelContext(myContext) var model = domain.CreateModelContext(myContext)
offset, limit := (param.PageIndex-1)*param.PageSize, param.PageSize 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 { if err != nil {
return myContext, err return myContext, err
} }
......
package group_power_r package group_power_r
import ( import (
"fmt"
"git.hilo.cn/hilo-common/domain" "git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/mycontext" "git.hilo.cn/hilo-common/mycontext"
"git.hilo.cn/hilo-common/resource/mysql" "git.hilo.cn/hilo-common/resource/mysql"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/jinzhu/now"
"hilo-group/_const/enum/groupPower_e" "hilo-group/_const/enum/groupPower_e"
"hilo-group/_const/enum/msg_e" "hilo-group/_const/enum/msg_e"
"hilo-group/_const/redis_key/groupPower_k"
"hilo-group/cv/group_power_cv" "hilo-group/cv/group_power_cv"
"hilo-group/domain/model/groupPower_m" "hilo-group/domain/model/groupPower_m"
"hilo-group/domain/model/msg_m" "hilo-group/domain/model/msg_m"
"hilo-group/domain/model/user_m" "hilo-group/domain/model/user_m"
"hilo-group/domain/service/group_power_s" "hilo-group/domain/service/group_power_s"
"hilo-group/myerr/bizerr"
"hilo-group/resp" "hilo-group/resp"
"time"
) )
type MGetGroupPowerReq struct { type MGetGroupPowerReq struct {
...@@ -93,3 +98,66 @@ func Test(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -93,3 +98,66 @@ func Test(c *gin.Context) (*mycontext.MyContext, error) {
//} //}
return nil, nil 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
}
...@@ -374,7 +374,7 @@ func PluginReady(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -374,7 +374,7 @@ func PluginReady(c *gin.Context) (*mycontext.MyContext, error) {
// @Router /v1/imGroup/roomInfo/{groupId} [get] // @Router /v1/imGroup/roomInfo/{groupId} [get]
func GetRoomInfo(c *gin.Context) (*mycontext.MyContext, error) { func GetRoomInfo(c *gin.Context) (*mycontext.MyContext, error) {
myContext := mycontext.CreateMyContext(c.Keys) myContext := mycontext.CreateMyContext(c.Keys)
start := time.Now()
groupId := c.Param("groupId") groupId := c.Param("groupId")
if len(groupId) <= 0 { if len(groupId) <= 0 {
return myContext, myerr.NewSysError("groupId 为必填项") return myContext, myerr.NewSysError("groupId 为必填项")
...@@ -407,7 +407,8 @@ func GetRoomInfo(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -407,7 +407,8 @@ func GetRoomInfo(c *gin.Context) (*mycontext.MyContext, error) {
deviceType, appVersion := cast.ToString(_deviceType), cast.ToString(_appVersion) deviceType, appVersion := cast.ToString(_deviceType), cast.ToString(_appVersion)
vc := version_m.GetVersionControlByPlatform(model, deviceType) vc := version_m.GetVersionControlByPlatform(model, deviceType)
allow, err := utils.CompareVersion(appVersion, fmt.Sprintf("<= %s", vc.AuditVersion)) allow, err := utils.CompareVersion(appVersion, fmt.Sprintf("<= %s", vc.AuditVersion))
model.Log.Infof("GetRoomInfo CompareVersion appVersion:%v,auditVersion:%v,allow:%v,err:%v", appVersion, vc.AuditVersion, allow, err)
model.Log.Infof("GetRoomInfo cost 0:%v", time.Now().Sub(start).Seconds())
themeUrl := "" themeUrl := ""
var themeId uint64 = 0 var themeId uint64 = 0
...@@ -464,7 +465,8 @@ func GetRoomInfo(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -464,7 +465,8 @@ func GetRoomInfo(c *gin.Context) (*mycontext.MyContext, error) {
}, },
} }
roles, _, err := group_m.GetRolesInGroup(model, groupInfo.ImGroupId) model.Log.Infof("GetRoomInfo cost 1:%v", time.Now().Sub(start).Seconds())
roles, orderList, err := group_m.GetRolesInGroup(model, groupId)
if err != nil { if err != nil {
return myContext, err return myContext, err
} }
...@@ -507,11 +509,7 @@ func GetRoomInfo(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -507,11 +509,7 @@ func GetRoomInfo(c *gin.Context) (*mycontext.MyContext, error) {
} }
} }
roles, orderList, err := group_m.GetRolesInGroup(model, groupId) model.Log.Infof("GetRoomInfo cost 2:%v", time.Now().Sub(start).Seconds())
if err != nil {
return myContext, err
}
users, err := user_cv.GetUserTinyMap(orderList) users, err := user_cv.GetUserTinyMap(orderList)
if err != nil { if err != nil {
return myContext, err return myContext, err
...@@ -549,6 +547,7 @@ func GetRoomInfo(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -549,6 +547,7 @@ func GetRoomInfo(c *gin.Context) (*mycontext.MyContext, error) {
} }
result.WelcomeText = strings.ReplaceAll(result.WelcomeText, "@%s", "") result.WelcomeText = strings.ReplaceAll(result.WelcomeText, "@%s", "")
model.Log.Infof("GetRoomInfo cost 3:%v", time.Now().Sub(start).Seconds())
// 补上房间流水勋章 // 补上房间流水勋章
var pe *medal_cv.PicElement var pe *medal_cv.PicElement
result.TotalConsume, pe, err = medal_cv.GetGroupConsumeMedal(model, groupId) result.TotalConsume, pe, err = medal_cv.GetGroupConsumeMedal(model, groupId)
...@@ -558,7 +557,7 @@ func GetRoomInfo(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -558,7 +557,7 @@ func GetRoomInfo(c *gin.Context) (*mycontext.MyContext, error) {
result.GroupMedals = append(result.GroupMedals, medal_cv.PicElement{PicUrl: pe.PicUrl}) result.GroupMedals = append(result.GroupMedals, medal_cv.PicElement{PicUrl: pe.PicUrl})
} }
resMedals := []res_m.ResMedal{} var resMedals []res_m.ResMedal
err = mysql.Db.Model(&res_m.ResMedal{}). err = mysql.Db.Model(&res_m.ResMedal{}).
Joins("INNER JOIN group_medal m ON m.res_medal_id = res_medal.id"). Joins("INNER JOIN group_medal m ON m.res_medal_id = res_medal.id").
Where("m.im_group_id = ?", groupId). Where("m.im_group_id = ?", groupId).
...@@ -573,8 +572,9 @@ func GetRoomInfo(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -573,8 +572,9 @@ func GetRoomInfo(c *gin.Context) (*mycontext.MyContext, error) {
}) })
} }
} else { } else {
model.Log.Infof("GetRoomInfo: group_medal: %s", err.Error()) model.Log.Errorf("GetRoomInfo: group_medal: %s", err.Error())
} }
model.Log.Infof("GetRoomInfo cost 4:%v", time.Now().Sub(start).Seconds())
// 获取国家信息 // 获取国家信息
country, area, err := user_m.GetUserCountryArea(model, userId) country, area, err := user_m.GetUserCountryArea(model, userId)
if err != nil { if err != nil {
...@@ -601,18 +601,21 @@ func GetRoomInfo(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -601,18 +601,21 @@ func GetRoomInfo(c *gin.Context) (*mycontext.MyContext, error) {
}) })
} }
} else { } else {
model.Log.Infof("GetRoomInfo: GetRoomBanners: %s", err.Error()) model.Log.Errorf("GetRoomInfo: GetRoomBanners: %s", err.Error())
} }
result.LuckyWheel, err = group_cv.GetLuckWheelState(model, groupId) model.Log.Infof("GetRoomInfo cost 5:%v", time.Now().Sub(start).Seconds())
result.LuckyWheel, err = group_cv.GetLuckWheelState(model, groupId) // todo check 耗时
if err != nil { if err != nil {
model.Log.Infof("GetRoomInfo: GetLuckWheelState: %s", err.Error()) model.Log.Errorf("GetRoomInfo: GetLuckWheelState: %s", err.Error())
} }
model.Log.Infof("GetRoomInfo cost 6:%v", time.Now().Sub(start).Seconds())
// 群主的详情 // 群主的详情
owner, err := user_cv.GetUserDetail(model, groupInfo.Owner, userId) owner, err := user_cv.GetRoomInfoOwner(model, groupInfo.Owner, userId)
result.Owner = user_cv.UserDetailToRoomInfoOwner(owner) result.Owner = user_cv.UserDetailToRoomInfoOwner(owner)
if err != nil { if err != nil {
model.Log.Errorf("GetRoomInfo: GetUserBase: %s", err.Error()) model.Log.Errorf("GetRoomInfo: GetUserBase: %s", err.Error())
} }
model.Log.Infof("GetRoomInfo cost 7:%v", time.Now().Sub(start).Seconds())
// 进场特效类型 // 进场特效类型
var entryEffectType int // 进场特效类型 1: CP 2:神秘人 3:贵族 4:vip ,顺序从小到大 var entryEffectType int // 进场特效类型 1: CP 2:神秘人 3:贵族 4:vip ,顺序从小到大
...@@ -639,6 +642,7 @@ func GetRoomInfo(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -639,6 +642,7 @@ func GetRoomInfo(c *gin.Context) (*mycontext.MyContext, error) {
entryEffectType = 1 entryEffectType = 1
} }
result.EntryEffectType = entryEffectType result.EntryEffectType = entryEffectType
model.Log.Infof("GetRoomInfo cost 8:%v", time.Now().Sub(start).Seconds())
resp.ResponseOk(c, result) resp.ResponseOk(c, result)
return myContext, nil return myContext, nil
...@@ -848,7 +852,7 @@ func GroupBannerList(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -848,7 +852,7 @@ func GroupBannerList(c *gin.Context) (*mycontext.MyContext, error) {
} }
// 版本控制 // 版本控制
if !allow && (v.ID == 2301 || v.ID == 4711 || v.ID == 2321 || v.ID == 5341 || v.ID == 5331 || v.ID == 5631 || v.ID == 5471 || if !allow && (v.ID == 2301 || v.ID == 4711 || v.ID == 2321 || v.ID == 5341 || v.ID == 5331 || v.ID == 5631 || v.ID == 5471 ||
v.ID == 5461 || v.ID == 5771 || v.ID == 5811 || v.ID == 5881 || v.ID == 8781) { v.ID == 5461 || v.ID == 5771 || v.ID == 5811 || v.ID == 5881 || v.ID == 8781 || v.ID == 10351) {
model.Log.Infof("CompareVersion appVersion:%v,auditVersion:%v,allow:%v,err:%v,skip top recharge", appVersion, vc.AuditVersion, allow, err) model.Log.Infof("CompareVersion appVersion:%v,auditVersion:%v,allow:%v,err:%v,skip top recharge", appVersion, vc.AuditVersion, allow, err)
continue continue
} }
......
This diff is collapsed.
...@@ -1871,9 +1871,9 @@ func GroupIn(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -1871,9 +1871,9 @@ func GroupIn(c *gin.Context) (*mycontext.MyContext, error) {
myContext.Log.Infof("GroupIn, ProcessRoomVisit err: %s", err.Error()) myContext.Log.Infof("GroupIn, ProcessRoomVisit err: %s", err.Error())
} }
// 更新用户进入房间缓存记录 // 更新用户进入房间缓存记录
if err = room_c.ProcessUserRoomVisit(userId, groupId); err != nil { //if err = room_c.ProcessUserRoomVisit(userId, groupId); err != nil {
myContext.Log.Infof("GroupIn, ProcessUserRoomVisit err: %s", err.Error()) // myContext.Log.Infof("GroupIn, ProcessUserRoomVisit err: %s", err.Error())
} //}
resp.ResponseOk(c, group_cv.GroupChannelId{ resp.ResponseOk(c, group_cv.GroupChannelId{
ChannelId: channelId, ChannelId: channelId,
Token: token, Token: token,
......
...@@ -42,7 +42,8 @@ func InitRouter() *gin.Engine { ...@@ -42,7 +42,8 @@ func InitRouter() *gin.Engine {
imGroup.GET("/myRecent", wrapper(group_r.GetRecentGroup)) imGroup.GET("/myRecent", wrapper(group_r.GetRecentGroup))
imGroup.GET("/myPermanent", wrapper(group_r.GetMyGroup)) imGroup.GET("/myPermanent", wrapper(group_r.GetMyGroup))
// //
imGroup.GET("/visitors/:groupId", wrapper(group_r.GetGroupVisitors)) imGroup.GET("/visitors/:groupId", wrapper(group_r.GetGroupVisitorsV2))
imGroup.GET("/visitors2/:groupId", wrapper(group_r.GetGroupVisitors)) // 自测用,跟上面的反过来
imGroup.GET("/ownPublicGroup/:userExternalId", wrapper(group_r.GetOwnPublicGroup)) imGroup.GET("/ownPublicGroup/:userExternalId", wrapper(group_r.GetOwnPublicGroup))
//// 2.19的新接口 //// 2.19的新接口
imGroup.GET("/ownGroup", wrapper(group_r.GetOwnGroup)) imGroup.GET("/ownGroup", wrapper(group_r.GetOwnGroup))
...@@ -106,7 +107,7 @@ func InitRouter() *gin.Engine { ...@@ -106,7 +107,7 @@ func InitRouter() *gin.Engine {
imGroup.POST("/mgr/clearScreen", wrapper(group_r.GroupMgrClearScreen)) imGroup.POST("/mgr/clearScreen", wrapper(group_r.GroupMgrClearScreen))
imGroup.GET("/online/users", wrapper(group_r.GroupInUsers)) imGroup.GET("/online/users", wrapper(group_r.GroupInUsers))
imGroup.GET("/online/users/new", wrapper(group_r.GroupInUserNew)) imGroup.GET("/online/users/new", wrapper(group_r.GroupInUserNew))
imGroup.GET("/country", wrapper(group_r.GetGroupByCountry)) imGroup.GET("/country", wrapper(group_r.GetGroupByCountryV2))
imGroup.GET("/country/prior", wrapper(group_r.GroupountryPrior)) imGroup.GET("/country/prior", wrapper(group_r.GroupountryPrior))
// //
imGroup.POST("/theme/custom", wrapper(group_r.GroupThemeAdd)) imGroup.POST("/theme/custom", wrapper(group_r.GroupThemeAdd))
......
...@@ -3,8 +3,10 @@ package test ...@@ -3,8 +3,10 @@ package test
import ( import (
"fmt" "fmt"
"git.hilo.cn/hilo-common/domain" "git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/redisCli"
"git.hilo.cn/hilo-common/utils" "git.hilo.cn/hilo-common/utils"
"github.com/jinzhu/now" "github.com/jinzhu/now"
"hilo-group/domain/cache/groupPower_c"
"hilo-group/domain/model/groupPower_m" "hilo-group/domain/model/groupPower_m"
"hilo-group/domain/model/group_m" "hilo-group/domain/model/group_m"
"hilo-group/domain/service/group_power_s" "hilo-group/domain/service/group_power_s"
...@@ -69,3 +71,14 @@ func TestGetRandomImProvider(t *testing.T) { ...@@ -69,3 +71,14 @@ func TestGetRandomImProvider(t *testing.T) {
fmt.Printf("true--------------times0:%v\n", times0) fmt.Printf("true--------------times0:%v\n", times0)
fmt.Printf("true--------------times1:%v\n", times1) fmt.Printf("true--------------times1:%v\n", times1)
} }
func TestMonthStar(t *testing.T) {
monthTime, err := time.Parse("200601", "202307")
if err != nil {
panic(err)
}
redisCli.InitCluster()
res, err := groupPower_c.GetGroupPowerStarRankPeriod(domain.CreateModelNil(), "month", 242, 1, 0, 10, monthTime.Format("2006-01-02"))
println(res)
println(err)
}
...@@ -11,6 +11,8 @@ MYSQL_DB=hilo_code ...@@ -11,6 +11,8 @@ MYSQL_DB=hilo_code
[REDIS] [REDIS]
REDIS_HOST=47.244.34.27:6379 REDIS_HOST=47.244.34.27:6379
REDIS_PASSWORD=8QZ9JD1zLvPR3yHf REDIS_PASSWORD=8QZ9JD1zLvPR3yHf
REDIS_CLUSTER_HOST=47.244.34.27:6379
REDIS_CLUSTER_PASSWORD=8QZ9JD1zLvPR3yHf
[JWT] [JWT]
SECRET=hilo1632 SECRET=hilo1632
ISSUER_API=hiloApi ISSUER_API=hiloApi
......