123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- package http
- import (
- "context"
- "net/url"
- "strconv"
- "go-common/app/admin/main/aegis/model/task"
- "go-common/library/log"
- "go-common/library/xstr"
- )
- const (
- _getUIDs = "/x/admin/manager/users/uids"
- _getUname = "/x/admin/manager/users/unames"
- _getUdepartment = "/x/admin/manager/users/udepts"
- _getRole = "/x/admin/manager/internal/user/role"
- _getRoles = "/x/admin/manager/internal/user/roles"
- )
- // GetRole 获取用户对应业务下的角色
- func (d *Dao) GetRole(c context.Context, bid, uid int64) (roles []*task.Role, err error) {
- roles = []*task.Role{}
- params := url.Values{}
- params.Set("bid", strconv.FormatInt(bid, 10))
- params.Set("uid", strconv.FormatInt(uid, 10))
- res := new(struct {
- Code int `json:"code"`
- Data []*task.Role `json:"data"`
- })
- if err = d.clientR.Get(c, d.c.Host.Manager+_getRole, "", params, res); err != nil {
- log.Error("GetRole error(%v) url(%s) params(%s)", err, d.c.Host.Manager+_getRole, params.Encode())
- return
- }
- if res.Code != 0 {
- log.Error("GetRole request failed res(%+v) url(%s) params(%s)", res, d.c.Host.Manager+_getRole, params.Encode())
- return
- }
- if len(res.Data) == 0 {
- return
- }
- roles = res.Data
- return
- }
- // GetUserRoles 获取用户在所有业务下的角色
- func (d *Dao) GetUserRoles(c context.Context, uid int64) (roles []*task.Role, err error) {
- roles = []*task.Role{}
- params := url.Values{}
- params.Set("uid", strconv.FormatInt(uid, 10))
- res := new(struct {
- Code int `json:"code"`
- Data []*task.Role `json:"data"`
- })
- if err = d.clientR.Get(c, d.c.Host.Manager+_getRoles, "", params, res); err != nil {
- log.Error("GetUserRoles error(%v) url(%s) params(%s)", err, d.c.Host.Manager+_getRole, params.Encode())
- return
- }
- if res.Code != 0 {
- log.Error("GetUserRoles request failed res(%+v) url(%s) params(%s)", res, d.c.Host.Manager+_getRole, params.Encode())
- return
- }
- if len(res.Data) == 0 {
- return
- }
- roles = res.Data
- return
- }
- // GetUnames .
- func (d *Dao) GetUnames(c context.Context, uids []int64) (unames map[int64]string, err error) {
- unames = map[int64]string{}
- if len(uids) == 0 {
- return
- }
- params := url.Values{}
- params.Set("uids", xstr.JoinInts(uids))
- res := new(struct {
- Code int `json:"code"`
- Data map[int64]string `json:"data"`
- })
- if err = d.clientR.Get(c, d.c.Host.Manager+_getUname, "", params, res); err != nil {
- log.Error("GetUnames error(%v) url(%s) params(%s)", err, d.c.Host.Manager+_getUname, params.Encode())
- return
- }
- if res.Code != 0 {
- log.Error("GetUnames request failed res(%+v) url(%s) params(%s)", res, d.c.Host.Manager+_getUname, params.Encode())
- return
- }
- if len(res.Data) == 0 {
- return
- }
- unames = res.Data
- return
- }
- // GetUIDs .
- func (d *Dao) GetUIDs(c context.Context, unames string) (uids map[string]int64, err error) {
- uids = map[string]int64{}
- params := url.Values{}
- params.Set("unames", unames)
- res := new(struct {
- Code int `json:"code"`
- Data map[string]int64 `json:"data"`
- })
- if err = d.clientR.Get(c, d.c.Host.Manager+_getUIDs, "", params, res); err != nil {
- log.Error("GetUIDs error(%v) url(%s) params(%s)", err, d.c.Host.Manager+_getUname, params.Encode())
- return
- }
- if res.Code != 0 {
- log.Error("GetUIDs request failed res(%+v) url(%s) params(%s)", res, d.c.Host.Manager+_getUname, params.Encode())
- return
- }
- if len(res.Data) == 0 {
- return
- }
- uids = res.Data
- return
- }
- // GetUdepartment .
- func (d *Dao) GetUdepartment(c context.Context, uids []int64) (udepartment map[int64]string, err error) {
- udepartment = map[int64]string{}
- if len(uids) == 0 {
- return
- }
- params := url.Values{}
- params.Set("uids", xstr.JoinInts(uids))
- res := new(struct {
- Code int `json:"code"`
- Data map[int64]string `json:"data"`
- })
- if err = d.clientR.Get(c, d.c.Host.Manager+_getUdepartment, "", params, res); err != nil {
- log.Error("GetUdepartment error(%v) url(%s) params(%s)", err, d.c.Host.Manager+_getUdepartment, params.Encode())
- return
- }
- if res.Code != 0 {
- log.Error("GetUdepartment request failed res(%+v) url(%s) params(%s)", res, d.c.Host.Manager+_getUname, params.Encode())
- return
- }
- if len(res.Data) == 0 {
- return
- }
- udepartment = res.Data
- return
- }
|