From 993eff94a9627cf72de365fccd19b3bd4dc0e4d8 Mon Sep 17 00:00:00 2001 From: NorthLan <6995syu@163.com> Date: Mon, 16 May 2022 13:45:27 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=8E=92=E8=A1=8C?= =?UTF-8?q?=E6=A6=9C=EF=BC=8C=E4=BF=AE=E5=A4=8D=E7=94=A8=E6=88=B7=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E9=80=BB=E8=BE=91=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/user_center/model/statistics_pvp_model.go | 4 +- app/user_center/rpc/etc/user_center-dev.yaml | 12 +- app/user_center/rpc/etc/user_center.yaml | 32 ++++- .../retrieve_platform_user_logic.go | 13 ++ .../rpc/internal/logic/rank/rank_job.go | 124 ++++++------------ .../rpc/internal/svc/service_context.go | 2 +- 6 files changed, 90 insertions(+), 97 deletions(-) diff --git a/app/user_center/model/statistics_pvp_model.go b/app/user_center/model/statistics_pvp_model.go index 1b40c78..1728abe 100644 --- a/app/user_center/model/statistics_pvp_model.go +++ b/app/user_center/model/statistics_pvp_model.go @@ -42,8 +42,8 @@ type ( } UserAndScore struct { - UserId int64 - Score int64 + UserId int64 `gorm:"user_id"` + Score int64 `gorm:"score"` } UpdateRecordProps struct { diff --git a/app/user_center/rpc/etc/user_center-dev.yaml b/app/user_center/rpc/etc/user_center-dev.yaml index cf39b2b..374a503 100644 --- a/app/user_center/rpc/etc/user_center-dev.yaml +++ b/app/user_center/rpc/etc/user_center-dev.yaml @@ -1,10 +1,10 @@ Name: usercenter.rpc -ListenOn: 127.0.0.1:30001 +ListenOn: 127.0.0.1:40001 Timeout: 5000 Etcd: Hosts: - 127.0.0.1:2379 - Key: usercenter.rpc.dev + Key: usercenter.rpc.v2.dev Timeout: 5000 # default is 2000 NonBlock: true Log: @@ -27,12 +27,12 @@ UserRetriever: RoomShortInfoApi: https://api.live.bilibili.com/room/v1/Room/room_init TopListApi: https://api.live.bilibili.com/guard/topList Rank: - Enabled: false + Enabled: true Cron: - Update: "0/10 * * * * ?" # 10s一次 - Persistence: "0 0/10 * * * ?" # 10min一次 + Update: "@every 10s" # 10s一次 + Persistence: "@every 10m" # 10min一次 GiftCollector: - Enabled: true + Enabled: false Platforms: [ "bilibili" ] Cron: CollectGift: "0 0 0/6 * * ?" # 每隔6小时执行一次 diff --git a/app/user_center/rpc/etc/user_center.yaml b/app/user_center/rpc/etc/user_center.yaml index 7b68896..abe990d 100644 --- a/app/user_center/rpc/etc/user_center.yaml +++ b/app/user_center/rpc/etc/user_center.yaml @@ -4,18 +4,44 @@ Timeout: 5000 Etcd: Hosts: - 127.0.0.1:2379 - Key: usercenter.rpc + Key: usercenter.rpc.v2 Timeout: 5000 # default is 2000 NonBlock: true Log: Mode: file KeepDays: 7 - Level: error + Level: info DB: #DataSource: root:root@tcp(192.168.1.100:3306)/dmgame?charset=utf8mb4&loc=Asia%2FShanghai&parseTime=true DataSource: root:root@tcp(127.0.0.1:3306)/dmgame?charset=utf8mb4&loc=Asia%2FShanghai&parseTime=true UserRetriever: Enabled: true UpdateDuration: 720 # 720 hours = 30 Day = 1 Month + Cron: + PlatformUser: "0 0/5 * * * ?" # 每隔5分钟执行一次 + Nobility: "0 0/10 * * * ?" # 每隔10分钟执行一次 + NobilityPlatforms: [ "bilibili" ] # 需要获取贵族的平台列表 + Bilibili: + RoomId: 8722013 + Mid: 6704420 + RoomShortInfoApi: https://api.live.bilibili.com/room/v1/Room/room_init + TopListApi: https://api.live.bilibili.com/guard/topList Rank: - Enabled: true \ No newline at end of file + Enabled: true + Cron: + Update: "@every 10s" # 10s一次 + Persistence: "@every 10m" # 10min一次 +GiftCollector: + Enabled: true + Platforms: [ "bilibili" ] + Cron: + CollectGift: "0 0 0/6 * * ?" # 每隔6小时执行一次 +Integral: + # RMB到积分的转换 + RMBToIntegral: 1000 + # 平台礼物到RMB的转换 + GiftToRMB: + bilibili: 0.001 + # 平台免费礼物到积分的转换 + FreeToIntegral: + bilibili: 0.0001 \ No newline at end of file diff --git a/app/user_center/rpc/internal/logic/platform_user/retrieve_platform_user_logic.go b/app/user_center/rpc/internal/logic/platform_user/retrieve_platform_user_logic.go index 48f7c85..3b04269 100644 --- a/app/user_center/rpc/internal/logic/platform_user/retrieve_platform_user_logic.go +++ b/app/user_center/rpc/internal/logic/platform_user/retrieve_platform_user_logic.go @@ -46,6 +46,8 @@ func (l *RetrievePlatformUserLogic) RetrievePlatformUser(in *pb.PlatformUserReq) } return nil } + // : not found + // insert newId := uuid.NextId() if err := l.svcCtx.UserModel.InsertTx(l.ctx, tx, &model.User{Id: newId}); err != nil { @@ -61,6 +63,17 @@ func (l *RetrievePlatformUserLogic) RetrievePlatformUser(in *pb.PlatformUserReq) if err := l.svcCtx.UserPlatformModel.InsertTx(l.ctx, tx, dbPlatformUser); err != nil { return errors.Wrap(nerr.NewWithCode(nerr.DBError), "插入平台用户数据失败") } + dbFullUser = &model.FullUser{ + UserPlatform: *dbPlatformUser, + UserNobility: model.UserNobility{ + UserId: newId, + NobilityLevel: 0, + }, + UserIntegral: model.UserIntegral{ + UserId: newId, + Integral: 0, + }, + } return nil }); err != nil { return nil, errors.Wrapf(nerr.NewWithCode(nerr.DBError), "查询或创建用户-事务执行失败, err:%+v", err) diff --git a/app/user_center/rpc/internal/logic/rank/rank_job.go b/app/user_center/rpc/internal/logic/rank/rank_job.go index 1b8b479..5e95549 100644 --- a/app/user_center/rpc/internal/logic/rank/rank_job.go +++ b/app/user_center/rpc/internal/logic/rank/rank_job.go @@ -80,95 +80,51 @@ func InitRankJob(svcCtx *svc.ServiceContext) { // 3. 开启任务 定时落库 func (j *Job) initJob() { logx.Info("开启排行榜服务...") - j.initByType(model.RankTypeDamage) - j.initByType(model.RankTypeDeDamage) - j.initByType(model.RankTypeGeneral) - j.initByType(model.RankTypeDeGeneral) - j.initByType(model.RankTypeKillUnit) - j.initByType(model.RankTypeDeKillUnit) - j.initByType(model.RankTypeKillPlayer) - j.initByType(model.RankTypeDeKillPlayer) - j.initByType(model.RankTypeWin) - j.initByType(model.RankTypeLost) - j.initByType(model.RankTypeFirstBlood) - j.initByType(model.RankTypeDeFirstBlood) + // TODO 读取历史数据功能暂时移除 + //j.initByType(model.RankTypeDamage) + //j.initByType(model.RankTypeDeDamage) + //j.initByType(model.RankTypeGeneral) + //j.initByType(model.RankTypeDeGeneral) + //j.initByType(model.RankTypeKillUnit) + //j.initByType(model.RankTypeDeKillUnit) + //j.initByType(model.RankTypeKillPlayer) + //j.initByType(model.RankTypeDeKillPlayer) + //j.initByType(model.RankTypeWin) + //j.initByType(model.RankTypeLost) + //j.initByType(model.RankTypeFirstBlood) + //j.initByType(model.RankTypeDeFirstBlood) cfg := j.svcCtx.Config.Rank // job read and update c := cron.New() _, _ = c.AddFunc(cfg.Cron.Update, func() { - j.readAndUpdate(model.RankTypeDamage) + go j.readAndUpdate(model.RankTypeDamage) + go j.readAndUpdate(model.RankTypeDeDamage) + go j.readAndUpdate(model.RankTypeGeneral) + go j.readAndUpdate(model.RankTypeDeGeneral) + go j.readAndUpdate(model.RankTypeKillUnit) + go j.readAndUpdate(model.RankTypeDeKillUnit) + go j.readAndUpdate(model.RankTypeKillPlayer) + go j.readAndUpdate(model.RankTypeDeKillPlayer) + go j.readAndUpdate(model.RankTypeWin) + go j.readAndUpdate(model.RankTypeLost) + go j.readAndUpdate(model.RankTypeFirstBlood) + go j.readAndUpdate(model.RankTypeDeFirstBlood) }) - _, _ = c.AddFunc(cfg.Cron.Update, func() { - j.readAndUpdate(model.RankTypeDeDamage) - }) - _, _ = c.AddFunc(cfg.Cron.Update, func() { - j.readAndUpdate(model.RankTypeGeneral) - }) - _, _ = c.AddFunc(cfg.Cron.Update, func() { - j.readAndUpdate(model.RankTypeDeGeneral) - }) - _, _ = c.AddFunc(cfg.Cron.Update, func() { - j.readAndUpdate(model.RankTypeKillUnit) - }) - _, _ = c.AddFunc(cfg.Cron.Update, func() { - j.readAndUpdate(model.RankTypeDeKillUnit) - }) - _, _ = c.AddFunc(cfg.Cron.Update, func() { - j.readAndUpdate(model.RankTypeKillPlayer) - }) - _, _ = c.AddFunc(cfg.Cron.Update, func() { - j.readAndUpdate(model.RankTypeDeKillPlayer) - }) - _, _ = c.AddFunc(cfg.Cron.Update, func() { - j.readAndUpdate(model.RankTypeWin) - }) - _, _ = c.AddFunc(cfg.Cron.Update, func() { - j.readAndUpdate(model.RankTypeLost) - }) - _, _ = c.AddFunc(cfg.Cron.Update, func() { - j.readAndUpdate(model.RankTypeFirstBlood) - }) - _, _ = c.AddFunc(cfg.Cron.Update, func() { - j.readAndUpdate(model.RankTypeDeFirstBlood) - }) - // persistence _, _ = c.AddFunc(cfg.Cron.Persistence, func() { - j.persistence(model.RankTypeDamage) - }) - _, _ = c.AddFunc(cfg.Cron.Persistence, func() { - j.persistence(model.RankTypeDeDamage) - }) - _, _ = c.AddFunc(cfg.Cron.Persistence, func() { - j.persistence(model.RankTypeGeneral) - }) - _, _ = c.AddFunc(cfg.Cron.Persistence, func() { - j.persistence(model.RankTypeDeGeneral) - }) - _, _ = c.AddFunc(cfg.Cron.Persistence, func() { - j.persistence(model.RankTypeKillUnit) - }) - _, _ = c.AddFunc(cfg.Cron.Persistence, func() { - j.persistence(model.RankTypeDeKillUnit) - }) - _, _ = c.AddFunc(cfg.Cron.Persistence, func() { - j.persistence(model.RankTypeKillPlayer) - }) - _, _ = c.AddFunc(cfg.Cron.Persistence, func() { - j.persistence(model.RankTypeDeKillPlayer) - }) - _, _ = c.AddFunc(cfg.Cron.Persistence, func() { - j.persistence(model.RankTypeWin) - }) - _, _ = c.AddFunc(cfg.Cron.Persistence, func() { - j.persistence(model.RankTypeLost) - }) - _, _ = c.AddFunc(cfg.Cron.Persistence, func() { - j.persistence(model.RankTypeFirstBlood) - }) - _, _ = c.AddFunc(cfg.Cron.Persistence, func() { - j.persistence(model.RankTypeDeFirstBlood) + go j.persistence(model.RankTypeDamage) + go j.persistence(model.RankTypeDeDamage) + go j.persistence(model.RankTypeGeneral) + go j.persistence(model.RankTypeDeGeneral) + go j.persistence(model.RankTypeKillUnit) + go j.persistence(model.RankTypeDeKillUnit) + go j.persistence(model.RankTypeKillPlayer) + go j.persistence(model.RankTypeDeKillPlayer) + go j.persistence(model.RankTypeWin) + go j.persistence(model.RankTypeLost) + go j.persistence(model.RankTypeFirstBlood) + go j.persistence(model.RankTypeDeFirstBlood) }) c.Start() } @@ -251,16 +207,14 @@ func (j *Job) readAndUpdate(rankType int32) { rankLen := len(rank) var score int64 - if rankLen == 0 { - score = 0 - } else { + if rankLen > 0 { // 取当前榜最后一名分数 score = rank[rankLen-1][1] } // 若榜内数量不够,则直接取 max - len 数量的人 score排序一下 limit := model.MaxRankN if rankLen < model.MaxRankN { - limit = model.MaxRankN - rankLen + 1 // +1是避免取到自己后少取一位 + limit = model.MaxRankN - rankLen + 1 // +1是避免取到自己 少取一位 } // 末位 score diff --git a/app/user_center/rpc/internal/svc/service_context.go b/app/user_center/rpc/internal/svc/service_context.go index 49cad73..b49bf43 100644 --- a/app/user_center/rpc/internal/svc/service_context.go +++ b/app/user_center/rpc/internal/svc/service_context.go @@ -32,7 +32,7 @@ func NewServiceContext(c config.Config) *ServiceContext { log.New(os.Stdout, "\r\n", log.LstdFlags), logger.Config{ SlowThreshold: 5 * time.Second, - LogLevel: logger.Info, + LogLevel: logger.Warn, IgnoreRecordNotFoundError: true, Colorful: true, },