Commit c3dceed8 authored by hujiebin's avatar hujiebin

feat:群组信息加上铭牌

parent 7bb301e5
......@@ -68,6 +68,7 @@ type GroupInfo struct {
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
}
......@@ -391,6 +392,7 @@ func BuildJoinedGroupInfo(myService *domain.Service, myUserId uint64, groupIds [
HasOnMic: len(micUsers) > 0,
GroupPowerId: powerIds[g.Owner],
GroupPowerName: powerNames[g.Owner],
GroupPowerNameplate: powerNameplates[g.Owner],
},
MicUsers: micUsers,
RoomUserCount: uint(roomCount[i]),
......
......@@ -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
}
//获取国家势力的所有用户数量
......
......@@ -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
}
......
......@@ -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
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) {
......
......@@ -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
}
......@@ -490,6 +490,7 @@ func GetGroupPowerGroups(c *gin.Context) (*mycontext.MyContext, error) {
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]),
......
......@@ -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
}
......@@ -275,6 +275,7 @@ func GetTheirGroups(c *gin.Context) (*mycontext.MyContext, error) {
//HasOnMic: onMicScore[i.GroupId] != 0,
GroupPowerId: powerIds[gi.Owner],
GroupPowerName: powerNames[gi.Owner],
GroupPowerNameplate: powerNameplates[gi.Owner],
},
MicUsers: micUsers,
RoomUserCount: uint(roomCount[i.GroupId]),
......
......@@ -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
}
......@@ -341,6 +341,7 @@ func GetPopularGroups(c *gin.Context) (*mycontext.MyContext, error) {
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
}
......@@ -558,6 +559,7 @@ func GetLatestGroups(c *gin.Context) (*mycontext.MyContext, error) {
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
}
......@@ -1372,6 +1374,7 @@ func GetGroupByCountry(c *gin.Context) (*mycontext.MyContext, error) {
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]),
......
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