group_power_grade.go 1.45 KB
Newer Older
hujiebin's avatar
hujiebin committed
1 2 3 4 5 6
package groupPower_c

import (
	"encoding/json"
	"git.hilo.cn/hilo-common/domain"
	"git.hilo.cn/hilo-common/resource/mysql"
hujiebin's avatar
hujiebin committed
7
	"github.com/go-redis/redis/v8"
hujiebin's avatar
hujiebin committed
8 9 10 11 12 13 14 15 16
	"hilo-group/_const/redis_key/groupPower_k"
	"time"
)

type GroupPowerGradeExp struct {
	GroupPowerId mysql.ID
	Exp          mysql.Num
	UserId       mysql.ID
	Remark       string
17
	Ts           int64
hujiebin's avatar
hujiebin committed
18 19 20 21 22 23 24 25 26 27
}

// redis队列缓冲GroupPowerGradeExp升级内容
func QueueGroupPowerGradeExp(model *domain.Model, groupPowerId mysql.ID, exp mysql.Num, userId mysql.ID, remark string) error {
	queue := groupPower_k.GetGroupPowerGradeExpQueue()
	data := GroupPowerGradeExp{
		GroupPowerId: groupPowerId,
		Exp:          exp,
		UserId:       userId,
		Remark:       remark,
28
		Ts:           time.Now().Unix(),
hujiebin's avatar
hujiebin committed
29 30 31 32 33 34 35 36 37 38 39
	}
	body, _ := json.Marshal(data)
	return model.Redis.RPush(model, queue, string(body)).Err()
}

// redis弹出GroupPowerGradeExp升级内容
func BLPopGroupPowerGradeExp(model *domain.Model) *GroupPowerGradeExp {
	var res *GroupPowerGradeExp
	queue := groupPower_k.GetGroupPowerGradeExpQueue()
	strs, err := model.Redis.BLPop(model, time.Second, queue).Result()
	if err != nil {
hujiebin's avatar
hujiebin committed
40 41 42
		if err != redis.Nil {
			model.Log.Errorf("BLPopGroupPowerGradeExp fail:%v", err)
		}
hujiebin's avatar
hujiebin committed
43 44 45 46 47 48 49 50 51 52 53 54 55
		return nil
	}
	if len(strs) >= 2 {
		content := strs[1]
		res = new(GroupPowerGradeExp)
		if err := json.Unmarshal([]byte(content), res); err != nil {
			model.Log.Errorf("BLPopGroupPowerGradeExp json fail:%v", err)
			return nil
		}
		return res
	}
	return nil
}