Commit 3717f457 authored by chenweijian's avatar chenweijian

Merge remote-tracking branch 'origin/master' into fix/group_country

parents 72b685e0 3f4af9eb
...@@ -75,9 +75,6 @@ func groupPowerStar(model *domain.Model, sendGiftEvent *gift_ev.SendGiftEvent) { ...@@ -75,9 +75,6 @@ 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 {
model.Log.Errorf("IncrGroupPowerMonthStarScore famous fail:%v", err)
}
if err := groupPower_c.IncrGroupPowerDayStarScore(model, data.GroupPowerId, data.UserId, if err := groupPower_c.IncrGroupPowerDayStarScore(model, data.GroupPowerId, data.UserId,
groupPower_e.GroupPowerStarTypeFamous, diamonds); err != nil { groupPower_e.GroupPowerStarTypeFamous, diamonds); err != nil {
model.Log.Errorf("IncrGroupPowerDayStarScore famous fail:%v", err) model.Log.Errorf("IncrGroupPowerDayStarScore famous fail:%v", err)
...@@ -87,9 +84,6 @@ func groupPowerStar(model *domain.Model, sendGiftEvent *gift_ev.SendGiftEvent) { ...@@ -87,9 +84,6 @@ 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 {
model.Log.Errorf("IncrGroupPowerMonthStarScore charm fail:%v", err)
}
if err := groupPower_c.IncrGroupPowerDayStarScore(model, data.GroupPowerId, data.UserId, if err := groupPower_c.IncrGroupPowerDayStarScore(model, data.GroupPowerId, data.UserId,
groupPower_e.GroupPowerStarTypeCharm, diamonds); err != nil { groupPower_e.GroupPowerStarTypeCharm, diamonds); err != nil {
model.Log.Errorf("IncrGroupPowerDayStarScore charm fail:%v", err) model.Log.Errorf("IncrGroupPowerDayStarScore charm fail:%v", err)
......
...@@ -251,7 +251,7 @@ type CvCountry struct { ...@@ -251,7 +251,7 @@ type CvCountry struct {
AreaCodeName *string `json:"areaShortName"` AreaCodeName *string `json:"areaShortName"`
} }
func BuildJoinedGroupInfo(myService *domain.Service, myUserId uint64, originGroupIds []string, pageSize, pageIndex int) ([]JoinedGroupInfo, int, error) { func BuildJoinedGroupInfo(myService *domain.Service, myUserId uint64, originGroupIds []string, pageSize, pageIndex int, _roomEnterTime ...map[string]int64) ([]JoinedGroupInfo, int, error) {
model := domain.CreateModel(myService.CtxAndDb) model := domain.CreateModel(myService.CtxAndDb)
groupInfo, err := group_m.BatchGetGroupInfo(model, originGroupIds) groupInfo, err := group_m.BatchGetGroupInfo(model, originGroupIds)
...@@ -321,6 +321,9 @@ func BuildJoinedGroupInfo(myService *domain.Service, myUserId uint64, originGrou ...@@ -321,6 +321,9 @@ func BuildJoinedGroupInfo(myService *domain.Service, myUserId uint64, originGrou
if err != nil { if err != nil {
return nil, 0, err return nil, 0, err
} }
if len(_roomEnterTime) > 0 {
roomEnterTime = _roomEnterTime[0]
}
//model.Log.Infof("BuildJoinedGroupInfo, roomEnterTime: %v", roomEnterTime) //model.Log.Infof("BuildJoinedGroupInfo, roomEnterTime: %v", roomEnterTime)
// 排序优先级V8.0版本 // 排序优先级V8.0版本
......
...@@ -47,7 +47,8 @@ func IncrGroupPowerDayStarScore(model *domain.Model, groupPowerId, userId mysql. ...@@ -47,7 +47,8 @@ func IncrGroupPowerDayStarScore(model *domain.Model, groupPowerId, userId mysql.
} }
// 获取家族之星排行 // 获取家族之星排行
func GetGroupPowerStarRankPeriod(model *domain.Model, period string, groupPowerId mysql.ID, _type groupPower_e.GroupPowerStarType, offset, limit int) ([]*GroupPowerStarRank, error) { // 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 var res []*GroupPowerStarRank
date := "" date := ""
switch period { switch period {
...@@ -61,6 +62,9 @@ func GetGroupPowerStarRankPeriod(model *domain.Model, period string, groupPowerI ...@@ -61,6 +62,9 @@ func GetGroupPowerStarRankPeriod(model *domain.Model, period string, groupPowerI
if len(date) <= 0 { if len(date) <= 0 {
return res, errors.New("illegal date") return res, errors.New("illegal date")
} }
if len(targetDate) > 0 {
date = targetDate[0]
}
key := groupPower_k.GetGroupPowerStarRankKey(_type, period, groupPowerId, date) key := groupPower_k.GetGroupPowerStarRankKey(_type, period, groupPowerId, date)
rows, err := model.RedisCluster.ZRevRangeByScoreWithScores(model, key, &redis.ZRangeBy{ rows, err := model.RedisCluster.ZRevRangeByScoreWithScores(model, key, &redis.ZRangeBy{
Min: "-inf", Min: "-inf",
......
...@@ -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,21 @@ func GetLastRoomVisitors(model *domain.Model, imGroupId string) (userIds []uint6 ...@@ -49,16 +50,21 @@ 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) (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.ZRangeByScoreWithScores(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",
}).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
} }
......
...@@ -59,7 +59,10 @@ func ProcessUserRoomVisit(userId uint64, groupId string) error { ...@@ -59,7 +59,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 +70,6 @@ func GetUserRoomVisit(userId uint64) (map[string]int64, error) { ...@@ -67,7 +70,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)
} }
......
...@@ -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
......
...@@ -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{
...@@ -83,6 +84,7 @@ func IncrGroupPowerDayStarScore(model *domain.Model, groupPowerId, userId mysql. ...@@ -83,6 +84,7 @@ func IncrGroupPowerDayStarScore(model *domain.Model, groupPowerId, userId mysql.
} }
// 获取家族之星排行 // 获取家族之星排行
// 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")
......
...@@ -319,8 +319,6 @@ func SendGroupInvitationShare(model *domain.Model, fromAccount string, toAccount ...@@ -319,8 +319,6 @@ func SendGroupInvitationShare(model *domain.Model, fromAccount string, toAccount
func GetOnlineStatus(model *domain.Model, extIds []string) (map[string]uint, error) { func GetOnlineStatus(model *domain.Model, extIds []string) (map[string]uint, error) {
left := make([]string, 0) left := make([]string, 0)
result := make(map[string]uint, 0) result := make(map[string]uint, 0)
// todo
return result, nil
r, err := getOnlineStatus(extIds) r, err := getOnlineStatus(extIds)
if err != nil { if err != nil {
......
...@@ -322,11 +322,7 @@ func (s *GroupMicService) IncrGroupPowerOnMicExpAndTime(groupId string, userId u ...@@ -322,11 +322,7 @@ 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 {
model.Log.Errorf("IncrGroupPowerStarOnMicMonth fail:%v", err)
}
// 增加势力上麦时长-天
//if err := groupPower_m.IncrGroupPowerStarOnMicDay(model, groupPowerId, userId, joinMicTimestamp); err != nil { //if err := groupPower_m.IncrGroupPowerStarOnMicDay(model, groupPowerId, userId, joinMicTimestamp); err != nil {
if err := groupPower_c.IncrGroupPowerDayStarScore(model, groupPowerId, userId, if err := groupPower_c.IncrGroupPowerDayStarScore(model, groupPowerId, userId,
groupPower_e.GroupPowerStarTypeActive, 60); err != nil { groupPower_e.GroupPowerStarTypeActive, 60); err != 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
} }
......
...@@ -720,7 +720,7 @@ func GetRecentGroup(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -720,7 +720,7 @@ func GetRecentGroup(c *gin.Context) (*mycontext.MyContext, error) {
//if err != nil { //if err != nil {
// return myContext, err // return myContext, err
//} //}
rec := group_c.GetUserRecentRooms(model, userId) rec, roomEnterTime := group_c.GetUserRecentRooms(model, userId)
myGroups, err := group_m.FindGroupMapByOwner(model, userId) myGroups, err := group_m.FindGroupMapByOwner(model, userId)
if err != nil { if err != nil {
...@@ -736,7 +736,7 @@ func GetRecentGroup(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -736,7 +736,7 @@ func GetRecentGroup(c *gin.Context) (*mycontext.MyContext, error) {
} }
myService := domain.CreateService(myContext) myService := domain.CreateService(myContext)
result, _, err := group_cv.BuildJoinedGroupInfo(myService, userId, groupIds, 30, 1) result, _, err := group_cv.BuildJoinedGroupInfo(myService, userId, groupIds, 30, 1,roomEnterTime)
if err != nil { if err != nil {
return myContext, err return myContext, err
} }
......
...@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment