diff --git a/domain/model/group_m/support.go b/domain/model/group_m/support.go index 3bfe45a83af01ba78bbcf155b6c71054a0827d1d..f8e6472afdf7a5d1c7f0b4becc5133103d7530e7 100644 --- a/domain/model/group_m/support.go +++ b/domain/model/group_m/support.go @@ -57,6 +57,24 @@ func GetAllGroupSupportResult(db *gorm.DB, period string) (map[string]uint8, err return result, nil } +func GetGroupSupportResult(db *gorm.DB, period string, groupIds []string) (map[string]uint8, error) { + if len(period) <= 0 { + return nil, nil + } + gsr := GroupSupportResult{ + Period: period, + } + rows := make([]GroupSupportResult, 0) + if err := db.Where(gsr).Where("group_uid in (?)", groupIds).Find(&rows).Error; err != nil { + return nil, err + } + result := make(map[string]uint8) + for _, i := range rows { + result[i.GroupUid] = i.Grade + } + return result, nil +} + //群组扶持奖励,利益分配者 type GroupSupportAwardAdmin struct { mysql.Entity diff --git a/domain/service/group_s/group.go b/domain/service/group_s/group.go index 25cba0317dc3ad05f5d666b291b54ba99e65180e..00d75f45565b4286b43cc4923bceed890e6b1fe9 100644 --- a/domain/service/group_s/group.go +++ b/domain/service/group_s/group.go @@ -65,6 +65,40 @@ func (s *GroupService) GetSupportLevelMap(now time.Time) (map[string]uint8, erro return result, nil } +// 取本周最高的扶持等级 +func (s *GroupService) GetWeekMaxSupportLevelMapByIds(groupIds []string) (map[string]uint8, error) { + return s.GetSupportLevelMapByIds(groupIds, time.Now().AddDate(0, 0, -group_e.SUPPORT_LEVEL_PERIOD_DAY)) +} + +func (s *GroupService) GetSupportLevelMapByIds(groupIds []string, now time.Time) (map[string]uint8, error) { + model := domain.CreateModel(s.svc.CtxAndDb) + + _, _, period := group_m.GetSupportLevelTime(now) + + levels, err := GetAllSupportLevel(model, period) + if err != nil { + return nil, err + } + model.Log.Debugf("GetSupportLevelMapByIds, GET %s: %v", period, levels) + + result := make(map[string]uint8, 0) + if len(levels) > 0 { + for g, l := range levels { + le, err := strconv.ParseUint(l, 10, 8) + if err == nil { + result[g] = uint8(le) + } + } + } else { + result, err = group_m.GetGroupSupportResult(model.DB(), period, groupIds) + if err == nil { + ret, err := SaveAllSupportLevel(model, period, result) + model.Log.Infof("GetSupportLevelMapByIds SAVE ret = %d, err: %v", ret, err) + } + } + return result, nil +} + func SaveAllSupportLevel(model *domain.Model, date string, levels map[string]uint8) (int64, error) { values := make(map[string]interface{}, 0) for g, l := range levels { diff --git a/domain/service/group_s/group_list.go b/domain/service/group_s/group_list.go index b8e1af9c61324bf35bfa5b5242b24bc322c4d519..5d6e71df92d3538bb965e8e5fd87c548ffa856e3 100644 --- a/domain/service/group_s/group_list.go +++ b/domain/service/group_s/group_list.go @@ -129,11 +129,11 @@ func GetGroupSortList(model *domain.Model, country string) ([]string, error) { model.Log.Infof("GroupCountryListSort, diamonds in 30 mins: %v", diamonds) model.Log.Infof("GroupCountryListSort cost3:%v", time.Now().Sub(beginTime)) - supportLevels, err := NewGroupService(model.MyContext).GetWeekMaxSupportLevelMap() - if err != nil { - return nil, err - } - model.Log.Infof("GroupCountryListSort, supportLevels : %v", supportLevels) + //supportLevels, err := NewGroupService(model.MyContext).GetWeekMaxSupportLevelMap() + //if err != nil { + // return nil, err + //} + //model.Log.Infof("GroupCountryListSort, supportLevels : %v", supportLevels) model.Log.Infof("GroupCountryListSort cost4:%v", time.Now().Sub(beginTime)) // 排序优先级2022-07-25 diff --git a/route/group_r/group_list.go b/route/group_r/group_list.go index 9d1dfad3e85d3e9ea3a3164ab68d5f3f6fcaee4d..657b286ec8adb20b95d540d64d6fe3c37b1222a4 100644 --- a/route/group_r/group_list.go +++ b/route/group_r/group_list.go @@ -1555,7 +1555,7 @@ func GetGroupByCountryV2(c *gin.Context) (*mycontext.MyContext, error) { // 正在进行的游戏 games := game_m.GetNotEndGamesMap(model) // 扶持等级 - supportLevels, err := group_s.NewGroupService(myContext).GetWeekMaxSupportLevelMap() + supportLevels, err := group_s.NewGroupService(myContext).GetWeekMaxSupportLevelMapByIds(groupIds) if err != nil { return myContext, err } diff --git a/route/router.go b/route/router.go index 406bf106f6b511153b5598ba5a1cf6fdb39d3398..c16fb82bd492420d6a2f3d102577e576b0a998c4 100644 --- a/route/router.go +++ b/route/router.go @@ -106,7 +106,7 @@ func InitRouter() *gin.Engine { imGroup.POST("/mgr/clearScreen", wrapper(group_r.GroupMgrClearScreen)) imGroup.GET("/online/users", wrapper(group_r.GroupInUsers)) imGroup.GET("/online/users/new", wrapper(group_r.GroupInUserNew)) - imGroup.GET("/country", wrapper(group_r.GetGroupByCountry)) + imGroup.GET("/country", wrapper(group_r.GetGroupByCountryV2)) imGroup.GET("/country/prior", wrapper(group_r.GroupountryPrior)) // imGroup.POST("/theme/custom", wrapper(group_r.GroupThemeAdd))