diff --git a/cv/group_cv/group.go b/cv/group_cv/group.go index b5b2035463e85c532d0336e5bea86124bc83c2bd..635c901a3476cdce6bb1190966c4bbfc0e9d3498 100644 --- a/cv/group_cv/group.go +++ b/cv/group_cv/group.go @@ -64,10 +64,11 @@ type GroupInfo struct { GroupBasicInfo // hilo业务 - EntryLevel uint32 `json:"entryLevel"` // obsolete - HasOnMic bool `json:"hasOnMic"` // 房间麦上是否有人 - GroupPowerId uint64 `json:"groupPowerId"` // 群主所在的势力ID - GroupPowerName string `json:"groupPowerName"` // 群主所在的势力的名称 + EntryLevel uint32 `json:"entryLevel"` // obsolete + HasOnMic bool `json:"hasOnMic"` // 房间麦上是否有人 + GroupPowerId uint64 `json:"groupPowerId"` // 群主所在的势力ID + GroupPowerName string `json:"groupPowerName"` // 群主所在的势力的名称 + GroupPowerNameplate string `json:"groupPowerNameplate"` // 势力铭牌 // "AppDefinedData": 群组维度的自定义字段 【暂时不用】 MemberList []MemberListInfo @@ -312,7 +313,7 @@ func BuildJoinedGroupInfo(myService *domain.Service, myUserId uint64, groupIds [ for _, i := range groupIds { owners = append(owners, groupInfo[i].Owner) } - powerIds, powerNames, err := group_power_cv.BatchGetGroupPower(model.Db, owners) + powerIds, powerNames, powerNameplates, err := group_power_cv.BatchGetGroupPower(model.Db, owners) if err != nil { return nil, 0, err } @@ -388,9 +389,10 @@ func BuildJoinedGroupInfo(myService *domain.Service, myUserId uint64, groupIds [ MicNumType: int(g.MicNumType), GroupMedals: medals, }, - HasOnMic: len(micUsers) > 0, - GroupPowerId: powerIds[g.Owner], - GroupPowerName: powerNames[g.Owner], + HasOnMic: len(micUsers) > 0, + GroupPowerId: powerIds[g.Owner], + GroupPowerName: powerNames[g.Owner], + GroupPowerNameplate: powerNameplates[g.Owner], }, MicUsers: micUsers, RoomUserCount: uint(roomCount[i]), diff --git a/cv/group_power_cv/groupPower.go b/cv/group_power_cv/groupPower.go index 6953f6384c5bb230d4b74a74adab382d02995b11..dfb1607e0e396a356b06e6d9cd44815d3ba10f63 100644 --- a/cv/group_power_cv/groupPower.go +++ b/cv/group_power_cv/groupPower.go @@ -232,28 +232,31 @@ func GetCvGroupPowerUsers(groupPowerId uint64) ([]mysql.ID, error) { return usreIds, nil } -func BatchGetGroupPower(db *gorm.DB, userIds []uint64) (map[uint64]uint64, map[uint64]string, error) { +// return userId->powerId userId->powerName userId->powerNameplate +func BatchGetGroupPower(db *gorm.DB, userIds []uint64) (map[uint64]uint64, map[uint64]string, map[uint64]string, error) { if len(userIds) <= 0 { - return nil, nil, nil + return nil, nil, nil, nil } groupPowers, err := groupPower_m.GetGroupPowerMap(db, userIds) if err != nil { - return nil, nil, err + return nil, nil, nil, err } gpIds := make([]uint64, 0) for _, i := range groupPowers { gpIds = append(gpIds, i) } - powerNames, err := groupPower_m.GetGroupPowerNames(db, gpIds) + powerNames, powerNameplates, err := groupPower_m.GetGroupPowerNames(db, gpIds) if err != nil { - return nil, nil, err + return nil, nil, nil, err } groupPowerNames := make(map[mysql.ID]string, 0) + groupPowerNameplates := make(map[mysql.ID]string, 0) for i, g := range groupPowers { groupPowerNames[i] = powerNames[g] + groupPowerNameplates[i] = powerNameplates[g] } - return groupPowers, groupPowerNames, nil + return groupPowers, groupPowerNames, groupPowerNameplates, nil } //获取国家势力的所有用户数量 diff --git a/cv/user_cv/user.go b/cv/user_cv/user.go index 89d2c24c57f96d710b52e0b5b59b09568995ddc2..d8d698d0fb68586835fcc46c71ef320af4c6a3eb 100644 --- a/cv/user_cv/user.go +++ b/cv/user_cv/user.go @@ -299,7 +299,7 @@ func getUserDetails(model *domain.Model, users []*user_m.User, myUserId mysql.ID for _, i := range groupPowers { gpIds = append(gpIds, i) } - powerNames, err := groupPower_m.GetGroupPowerNames(mysql.Db, gpIds) + powerNames, _, err := groupPower_m.GetGroupPowerNames(mysql.Db, gpIds) if err != nil { return nil, err } diff --git a/domain/model/groupPower_m/groupPower.go b/domain/model/groupPower_m/groupPower.go index f25d9ed3d585b6b1a10b8db370ab949891fbf52e..e1cd5ac1356152b4c5f1f8b0fc6a4a58038f33be 100644 --- a/domain/model/groupPower_m/groupPower.go +++ b/domain/model/groupPower_m/groupPower.go @@ -348,24 +348,28 @@ func GetGroupPowerMap(db *gorm.DB, userIds []mysql.ID) (map[mysql.ID]uint64, err return result, nil } -func GetGroupPowerNames(db *gorm.DB, ids []mysql.ID) (map[mysql.ID]string, error) { +// return +func GetGroupPowerNames(db *gorm.DB, ids []mysql.ID) (map[mysql.ID]string, map[mysql.ID]string, error) { type record struct { - Id mysql.ID - Name string + Id mysql.ID + Name string + Nameplate string } rows := make([]record, 0) + result := make(map[mysql.ID]string, 0) + result2 := make(map[mysql.ID]string, 0) if len(ids) > 0 { - if err := db.Model(&GroupPower{}).Select("p.id, i.name"). + if err := db.Model(&GroupPower{}).Select("p.id, i.name,i.nameplate"). Joins("AS p INNER JOIN group_info AS i ON p.group_uid = i.im_group_id"). Where("p.id IN ?", ids).Find(&rows).Error; err != nil { - return nil, err + return result, result2, err } } - result := make(map[mysql.ID]string, 0) for _, i := range rows { result[i.Id] = i.Name + result[i.Id] = i.Nameplate } - return result, nil + return result, result2, nil } func GetGroupPower(model *domain.Model, id mysql.ID) (*GroupPower, error) { diff --git a/route/group_power_r/group_power.go b/route/group_power_r/group_power.go index f3e1cc442cdbcf6fb4a14eda979a31722fdb148f..467360a31d19c80c798b087dade31894f426f022 100644 --- a/route/group_power_r/group_power.go +++ b/route/group_power_r/group_power.go @@ -375,7 +375,7 @@ func GetGroupPowerGroups(c *gin.Context) (*mycontext.MyContext, error) { groupIds = append(groupIds, i.ImGroupId) owners = append(owners, i.Owner) } - powerIds, powerNames, err := group_power_cv.BatchGetGroupPower(model.Db, owners) + powerIds, powerNames, powerNameplates, err := group_power_cv.BatchGetGroupPower(model.Db, owners) if err != nil { return myContext, err } @@ -487,9 +487,10 @@ func GetGroupPowerGroups(c *gin.Context) (*mycontext.MyContext, error) { MicNumType: int(i.MicNumType), GroupMedals: medals, }, - HasOnMic: len(roomMicUserMap[i.ImGroupId]) > 0, - GroupPowerId: powerIds[i.Owner], - GroupPowerName: powerNames[i.Owner], + HasOnMic: len(roomMicUserMap[i.ImGroupId]) > 0, + GroupPowerId: powerIds[i.Owner], + GroupPowerName: powerNames[i.Owner], + GroupPowerNameplate: powerNameplates[i.Owner], }, MicUsers: micUsers, RoomUserCount: uint(roomCount[i.ImGroupId]), diff --git a/route/group_r/group_info.go b/route/group_r/group_info.go index 5633090ecbe990f80319e7939b4190e80c0c5e88..091219508e696551fc0ca3b93109a25470587cc6 100644 --- a/route/group_r/group_info.go +++ b/route/group_r/group_info.go @@ -133,7 +133,7 @@ func GetTheirGroups(c *gin.Context) (*mycontext.MyContext, error) { } model.Log.Info("GetTheirGroups: theirRoles - ", theirRoles) - powerIds, powerNames, err := group_power_cv.BatchGetGroupPower(model.Db, owners) + powerIds, powerNames, powerNameplates, err := group_power_cv.BatchGetGroupPower(model.Db, owners) if err != nil { return myContext, err } @@ -273,8 +273,9 @@ func GetTheirGroups(c *gin.Context) (*mycontext.MyContext, error) { GroupMedals: medals, }, //HasOnMic: onMicScore[i.GroupId] != 0, - GroupPowerId: powerIds[gi.Owner], - GroupPowerName: powerNames[gi.Owner], + GroupPowerId: powerIds[gi.Owner], + GroupPowerName: powerNames[gi.Owner], + GroupPowerNameplate: powerNameplates[gi.Owner], }, MicUsers: micUsers, RoomUserCount: uint(roomCount[i.GroupId]), diff --git a/route/group_r/group_list.go b/route/group_r/group_list.go index e6aee0aeb702cc7997fc95c67f66eba80d84c813..8745e81f030661a18aa560b92360fc1e33e069ef 100644 --- a/route/group_r/group_list.go +++ b/route/group_r/group_list.go @@ -246,7 +246,7 @@ func GetPopularGroups(c *gin.Context) (*mycontext.MyContext, error) { groupIds = append(groupIds, i.ImGroupId) owners = append(owners, i.Owner) } - powerIds, powerNames, err := group_power_cv.BatchGetGroupPower(model.Db, owners) + powerIds, powerNames, powerNameplates, err := group_power_cv.BatchGetGroupPower(model.Db, owners) if err != nil { return myContext, err } @@ -338,9 +338,10 @@ func GetPopularGroups(c *gin.Context) (*mycontext.MyContext, error) { MicNumType: int(i.MicNumType), GroupMedals: medals, }, - HasOnMic: true, - GroupPowerId: powerIds[i.Owner], - GroupPowerName: powerNames[i.Owner], + HasOnMic: true, + GroupPowerId: powerIds[i.Owner], + GroupPowerName: powerNames[i.Owner], + GroupPowerNameplate: powerNameplates[i.Owner], }, MicUsers: micUsers, RoomUserCount: uint(roomCount[i.ImGroupId]), @@ -468,7 +469,7 @@ func GetLatestGroups(c *gin.Context) (*mycontext.MyContext, error) { for _, group := range groupInfos { owners = append(owners, group.Owner) } - powerIds, powerNames, err := group_power_cv.BatchGetGroupPower(model.Db, owners) + powerIds, powerNames, powerNameplates, err := group_power_cv.BatchGetGroupPower(model.Db, owners) if err != nil { return myContext, err } @@ -555,9 +556,10 @@ func GetLatestGroups(c *gin.Context) (*mycontext.MyContext, error) { MicNumType: int(group.MicNumType), GroupMedals: medals, }, - HasOnMic: true, - GroupPowerId: powerIds[group.Owner], - GroupPowerName: powerNames[group.Owner], + HasOnMic: true, + GroupPowerId: powerIds[group.Owner], + GroupPowerName: powerNames[group.Owner], + GroupPowerNameplate: powerNameplates[group.Owner], }, MicUsers: micUsers, RoomUserCount: uint(roomCount[group.ImGroupId]), @@ -1289,7 +1291,7 @@ func GetGroupByCountry(c *gin.Context) (*mycontext.MyContext, error) { groupIds = append(groupIds, i.ImGroupId) owners = append(owners, i.Owner) } - powerIds, powerNames, err := group_power_cv.BatchGetGroupPower(model.Db, owners) + powerIds, powerNames, powerNameplates, err := group_power_cv.BatchGetGroupPower(model.Db, owners) if err != nil { return myContext, err } @@ -1369,9 +1371,10 @@ func GetGroupByCountry(c *gin.Context) (*mycontext.MyContext, error) { MicNumType: int(i.MicNumType), GroupMedals: medals, }, - HasOnMic: micGroupNum[i.ImGroupId] > 0, - GroupPowerId: powerIds[i.Owner], - GroupPowerName: powerNames[i.Owner], + HasOnMic: micGroupNum[i.ImGroupId] > 0, + GroupPowerId: powerIds[i.Owner], + GroupPowerName: powerNames[i.Owner], + GroupPowerNameplate: powerNameplates[i.Owner], }, MicUsers: []user_cv.CvUserTiny{}, RoomUserCount: uint(roomCount[i.ImGroupId]),