From 04b986e8d03d9e5b9af0528c623c163d4c2bca9c Mon Sep 17 00:00:00 2001 From: JiebinHu <458249864@qq.com> Date: Sat, 26 Aug 2023 21:56:02 +0800 Subject: [PATCH] =?UTF-8?q?feat:1=E5=88=86=E9=92=9F=E7=BB=9F=E4=B8=8060?= =?UTF-8?q?=E7=A7=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cron/mic_cron/on_mic.go | 3 +- domain/model/groupPower_m/group_grade.go | 68 +++++++++++++----------- domain/model/mic_m/mic.go | 23 ++++++++ 3 files changed, 61 insertions(+), 33 deletions(-) diff --git a/cron/mic_cron/on_mic.go b/cron/mic_cron/on_mic.go index cbba7ce..e160da6 100644 --- a/cron/mic_cron/on_mic.go +++ b/cron/mic_cron/on_mic.go @@ -63,7 +63,8 @@ func OnMicQueue() { } // 用户上麦 - if err := mic_m.IncrUserOnMic(model, onMic.UserId, onMic.Timestamp); err != nil { + //if err := mic_m.IncrUserOnMic(model, onMic.UserId, onMic.Timestamp); err != nil { + if err := mic_m.IncrUserOnMicV2(model, onMic.UserId); err != nil { model.Log.Errorf("cron micIn IncrUserOnMic err:%v", err) } else { model.Log.Infof("cron micIn IncrUserOnMic success,userId:%v,cost:%vs", onMic.UserId, time.Now().Sub(start).Seconds()) diff --git a/domain/model/groupPower_m/group_grade.go b/domain/model/groupPower_m/group_grade.go index 92706e5..f925b67 100644 --- a/domain/model/groupPower_m/group_grade.go +++ b/domain/model/groupPower_m/group_grade.go @@ -158,22 +158,24 @@ func IncrGroupPowerExpOnMic(model *domain.Model, groupPowerId, userId mysql.ID) // 事务操作 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 - err = IncrGroupPowerMonthStarScore(model, groupPowerId, userId, groupPower_e.GroupPowerStarTypeActive, mysql.Num(score), nowTs) + //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 } @@ -181,22 +183,24 @@ func IncrGroupPowerStarOnMicMonth(model *domain.Model, groupPowerId, userId mysq // 事务操作 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 - err = IncrGroupPowerDayStarScore(model, groupPowerId, userId, groupPower_e.GroupPowerStarTypeActive, mysql.Num(score), nowTs) + //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 } diff --git a/domain/model/mic_m/mic.go b/domain/model/mic_m/mic.go index 60723e5..a91dff6 100644 --- a/domain/model/mic_m/mic.go +++ b/domain/model/mic_m/mic.go @@ -75,6 +75,29 @@ func IncrUserOnMic(model *domain.Model, userId mysql.ID, joinMicTimestamp int64) }) } +// 增加用户上麦时长 +// 事务操作 +func IncrUserOnMicV2(model *domain.Model, userId mysql.ID) error { + for _, tz := range timezone_e.Timezones { + day := time.Now().In(timezone_e.TimezoneLocMap[tz]).Format("2006-01-02") + if err := model.DB().Model(UserOnMic{}).Clauses(clause.OnConflict{ + Columns: []clause.Column{{Name: "date"}, {Name: "user_id"}, {Name: "tz"}}, + DoUpdates: clause.Assignments(map[string]interface{}{ + "seconds": gorm.Expr("seconds + ?", 60), + }), + }).Create(&UserOnMic{ + Date: day, + UserId: userId, + Seconds: 60, + Tz: tz, + }).Error; err != nil { + model.Log.Errorf("IncrUserOnMic fail:%v", err) + return err + } + } + return nil +} + // 批量获取用户上麦时长 // @return userId->seconds func MGetUserOnMicSeconds(model *domain.Model, day string, tz timezone_e.Timezone, userIds []uint64) (map[mysql.ID]mysql.Num, error) { -- 2.22.0