Commit 983add29 authored by hujiebin's avatar hujiebin

批量获取家族信息

parent f7d159d0
......@@ -14,13 +14,12 @@ type CvGroupPowerRank struct {
type CvGroupPowerRankData struct {
GroupPowerId mysql.ID `json:"groupPowerId"` // 家族id
GroupPic string `json:"groupPic"` // 家族图片
Icon string `json:"icon"` // 家族图片
Name string `json:"name"` // 家族名
Nameplate string `json:"nameplate"` // 铭牌
Grade groupPower_e.GroupPowerGrade `json:"grade"` // 等级 0:无 1:青铜 2:白银 3:黄金 4:黑金
Exp mysql.Num `json:"exp"` // 经验值
Rank int `json:"rank"` // 排名
// todo 铭牌,图片等字段, 等伟健哥哥的结构体
}
// 家族之星
......
......@@ -368,29 +368,6 @@ func GetGroupPowerNames(db *gorm.DB, ids []mysql.ID) (map[mysql.ID]string, error
return result, nil
}
type GroupPowerInfo struct {
PowerId mysql.ID
Owner mysql.ID
Name string
}
func BatchGetGroupPower(db *gorm.DB, ids []mysql.ID) (map[mysql.ID]GroupPowerInfo, error) {
rows := make([]GroupPowerInfo, 0)
if len(ids) > 0 {
if err := db.Model(&GroupPower{}).Select("p.id AS power_id, u.user_id AS owner, p.name").
Joins("AS p INNER JOIN group_power_user AS u ON p.id = u.group_power_id").
Where("p.id IN ? AND p.status = ? AND role = ?", ids, groupPower_e.GroupPowerUserHas, groupPower_e.GroupPowerUserRoleMgr).
Find(&rows).Error; err != nil {
return nil, err
}
}
result := make(map[mysql.ID]GroupPowerInfo, 0)
for _, i := range rows {
result[i.PowerId] = i
}
return result, nil
}
func GetGroupPower(model *domain.Model, id mysql.ID) (*GroupPower, error) {
groupPower := GroupPower{}
if err := model.Db.Model(&GroupPower{}).First(&groupPower, id).Error; err != nil {
......
package groupPower_m
import (
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/mysql"
)
type GroupPowerInfo struct {
mysql.Entity
GroupUid string
Name string
Nameplate string
Declaration string
Icon string
Status int
}
func (GroupPowerInfo) TableName() string {
return "group_power"
}
// 批量获取家族信息
func MGetGroupPowerInfoMap(model *domain.Model, groupPowerIds []mysql.ID) (map[mysql.ID]GroupPowerInfo, error) {
var rows []GroupPowerInfo
res := make(map[mysql.ID]GroupPowerInfo)
if err := model.DB().Model(GroupPowerInfo{}).Where("id in ?", groupPowerIds).Find(&rows).Error; err != nil {
model.Log.Errorf("MGetGroupPowerInfo fail:%v", err)
return res, err
}
return res, nil
}
......@@ -65,6 +65,10 @@ func GroupPowerRank(c *gin.Context) (*mycontext.MyContext, error) {
if err != nil {
return myContext, err
}
groupPowers, err := groupPower_m.MGetGroupPowerInfoMap(model, ids)
if err != nil {
return myContext, err
}
if myGroupPower != nil && myGroupPower.Role == groupPower_e.GroupPowerUserRoleMgr {
myGroupPowerRank, err := groupPower_m.GetGroupPowerExpMyRank(model, beginDate, endDate, myGroupPower.GroupPowerId)
if err != nil {
......@@ -72,9 +76,9 @@ func GroupPowerRank(c *gin.Context) (*mycontext.MyContext, error) {
}
response.MyGroupPower = group_power_cv.CvGroupPowerRankData{
GroupPowerId: myGroupPower.GroupPowerId,
GroupPic: "todo",
Name: "todo",
Nameplate: "todo",
Icon: groupPowers[myGroupPower.ID].Icon,
Name: groupPowers[myGroupPower.ID].Name,
Nameplate: groupPowers[myGroupPower.ID].Nameplate,
Grade: grades[myGroupPower.GroupPowerId].Grade,
Exp: myGroupPowerRank.Exp,
Rank: myGroupPowerRank.Rank,
......@@ -83,9 +87,9 @@ func GroupPowerRank(c *gin.Context) (*mycontext.MyContext, error) {
for r, v := range rank {
response.Items = append(response.Items, group_power_cv.CvGroupPowerRankData{
GroupPowerId: v.GroupPowerId,
GroupPic: "todo", // todo
Name: "todo",
Nameplate: "todo",
Icon: groupPowers[v.GroupPowerId].Icon,
Name: groupPowers[v.GroupPowerId].Name,
Nameplate: groupPowers[v.GroupPowerId].Nameplate,
Grade: grades[v.GroupPowerId].Grade,
Exp: v.Exp,
Rank: r + 1, // 查询已做排序
......
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