group_info.go 1.96 KB
Newer Older
hujiebin's avatar
hujiebin committed
1 2 3 4 5
package groupPower_m

import (
	"git.hilo.cn/hilo-common/domain"
	"git.hilo.cn/hilo-common/resource/mysql"
hujiebin's avatar
hujiebin committed
6
	"hilo-group/_const/enum/groupPower_e"
hujiebin's avatar
hujiebin committed
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
)

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
	}
hujiebin's avatar
hujiebin committed
31 32 33
	for i, v := range rows {
		res[v.ID] = rows[i]
	}
hujiebin's avatar
hujiebin committed
34 35
	return res, nil
}
hujiebin's avatar
hujiebin committed
36 37 38 39 40 41 42 43 44 45 46 47 48 49

// 批量获取家族成员
func MGetGroupPowerUsers(model *domain.Model, groupPowerIds []mysql.ID) (map[mysql.ID][]*GroupPowerUser, error) {
	var users []*GroupPowerUser
	res := make(map[mysql.ID][]*GroupPowerUser)
	if err := model.DB().Model(GroupPowerUser{}).Where("group_power_id in ?", groupPowerIds).Find(&users).Error; err != nil {
		model.Log.Errorf("MGetGroupPowerUsers fail:%v", err)
		return res, err
	}
	for i, v := range users {
		res[v.GroupPowerId] = append(res[v.GroupPowerId], users[i])
	}
	return res, nil
}
hujiebin's avatar
hujiebin committed
50 51 52 53 54 55 56 57 58

// 获取家族成员
func GetGroupPowerUser(model *domain.Model, groupPowerId mysql.ID) ([]*GroupPowerUser, error) {
	m, err := MGetGroupPowerUsers(model, []mysql.ID{groupPowerId})
	if err != nil {
		return nil, err
	}
	return m[groupPowerId], nil
}
hujiebin's avatar
hujiebin committed
59 60 61 62 63 64 65 66 67 68 69

// 获取所有家族的主
func GetAllGroupPowerOwners(model *domain.Model) ([]mysql.ID, error) {
	var userIds []mysql.ID
	if err := model.DB().Model(GroupPowerUser{}).Select("user_id").
		Where("role = ?", groupPower_e.GroupPowerUserRoleMgr).Find(&userIds).Error; err != nil {
		model.Log.Errorf("GetAllGroupPowerOwners fail:%v", err)
		return userIds, err
	}
	return userIds, nil
}