Commit 9068f714 authored by JiebinHu's avatar JiebinHu

todo 一次性脚本

parent 1ccc8c2f
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,60 @@ func Test(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -93,3 +98,60 @@ func Test(c *gin.Context) (*mycontext.MyContext, error) {
//} //}
return nil, nil return nil, nil
} }
type GroupPowerDayStar struct {
Date string
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)
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,
}
for _, star := range stars {
date, err := time.Parse("2006-01-02", star.Date)
if err != nil {
model.Log.Errorf("SyncStar date fail:%v", err)
continue
}
for _, period := range []string{"day", "week", "month"} {
var dateStr string
switch period {
case "day":
dateStr = date.Format("2006-01-02")
case "week":
dateStr = now.With(date).BeginningOfWeek().Format("2006-01-02")
case "month":
dateStr = now.With(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])
}
}
return myCtx, nil
}
...@@ -159,6 +159,7 @@ func InitRouter() *gin.Engine { ...@@ -159,6 +159,7 @@ func InitRouter() *gin.Engine {
innerGroupPower := inner.Group("/groupPower") innerGroupPower := inner.Group("/groupPower")
{ {
innerGroupPower.GET("/infos", wrapper(group_power_r.MGetGroupPowers)) innerGroupPower.GET("/infos", wrapper(group_power_r.MGetGroupPowers))
innerGroupPower.GET("/sync/star", wrapper(group_power_r.SyncStar)) // todo 一次性脚本
} }
innerMic := inner.Group("/mic") innerMic := inner.Group("/mic")
{ {
......
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