正在显示
8 个修改的文件
包含
137 行增加
和
44 行删除
| @@ -6,6 +6,7 @@ import ( | @@ -6,6 +6,7 @@ import ( | ||
| 6 | "oppmg/models" | 6 | "oppmg/models" |
| 7 | "oppmg/protocol" | 7 | "oppmg/protocol" |
| 8 | serverbac "oppmg/services/rbac" | 8 | serverbac "oppmg/services/rbac" |
| 9 | + "strconv" | ||
| 9 | ) | 10 | ) |
| 10 | 11 | ||
| 11 | type RbacController struct { | 12 | type RbacController struct { |
| @@ -35,8 +36,9 @@ func (c *RbacController) RoleAdd() { | @@ -35,8 +36,9 @@ func (c *RbacController) RoleAdd() { | ||
| 35 | msg = protocol.BadRequestParam("1") | 36 | msg = protocol.BadRequestParam("1") |
| 36 | return | 37 | return |
| 37 | } | 38 | } |
| 38 | - _, err := serverbac.RoleAdd(param) | ||
| 39 | - msg = protocol.NewReturnResponse(nil, err) | 39 | + param.Types = models.ROLETYPES_ROLE |
| 40 | + r, err := serverbac.RoleAdd(param) | ||
| 41 | + msg = protocol.NewReturnResponse(r, err) | ||
| 40 | return | 42 | return |
| 41 | } | 43 | } |
| 42 | 44 | ||
| @@ -58,9 +60,9 @@ func (c *RbacController) RoleUpdate() { | @@ -58,9 +60,9 @@ func (c *RbacController) RoleUpdate() { | ||
| 58 | msg = protocol.BadRequestParam("1") | 60 | msg = protocol.BadRequestParam("1") |
| 59 | return | 61 | return |
| 60 | } | 62 | } |
| 61 | - | ||
| 62 | - _, err := serverbac.RoleEdit(param) | ||
| 63 | - msg = protocol.NewReturnResponse(nil, err) | 63 | + param.Types = models.ROLETYPES_ROLE |
| 64 | + r, err := serverbac.RoleEdit(param) | ||
| 65 | + msg = protocol.NewReturnResponse(r, err) | ||
| 64 | return | 66 | return |
| 65 | } | 67 | } |
| 66 | 68 | ||
| @@ -168,8 +170,14 @@ func (c *RbacController) RoleList() { | @@ -168,8 +170,14 @@ func (c *RbacController) RoleList() { | ||
| 168 | defer func() { | 170 | defer func() { |
| 169 | c.ResposeJson(msg) | 171 | c.ResposeJson(msg) |
| 170 | }() | 172 | }() |
| 171 | - | ||
| 172 | - var err error | ||
| 173 | - msg = protocol.NewReturnResponse(nil, err) | 173 | + var companyid int64 |
| 174 | + param := c.Ctx.Input.Param(":companyid") | ||
| 175 | + companyid, _ = strconv.ParseInt(param, 10, 64) | ||
| 176 | + if companyid <= 0 { | ||
| 177 | + msg = protocol.BadRequestParam("1") | ||
| 178 | + return | ||
| 179 | + } | ||
| 180 | + rolelist, err := serverbac.GetRoleList(companyid) | ||
| 181 | + msg = protocol.NewReturnResponse(rolelist, err) | ||
| 174 | return | 182 | return |
| 175 | } | 183 | } |
| @@ -66,7 +66,7 @@ func (t *Department) GetManages() []protocol.DepartmentManager { | @@ -66,7 +66,7 @@ func (t *Department) GetManages() []protocol.DepartmentManager { | ||
| 66 | log.Error("GetUserNameByIds err :%s", err) | 66 | log.Error("GetUserNameByIds err :%s", err) |
| 67 | return nil | 67 | return nil |
| 68 | } | 68 | } |
| 69 | - var managesdata []protocol.DepartmentManager | 69 | + managesdata := []protocol.DepartmentManager{} |
| 70 | for _, v := range users { | 70 | for _, v := range users { |
| 71 | m := protocol.DepartmentManager{ | 71 | m := protocol.DepartmentManager{ |
| 72 | Id: v.Id, Name: v.NickName, | 72 | Id: v.Id, Name: v.NickName, |
| @@ -52,6 +52,7 @@ func AddPosition(m *Position, om ...orm.Ormer) (id int64, err error) { | @@ -52,6 +52,7 @@ func AddPosition(m *Position, om ...orm.Ormer) (id int64, err error) { | ||
| 52 | } | 52 | } |
| 53 | m.CreateAt = time.Now() | 53 | m.CreateAt = time.Now() |
| 54 | m.UpdateAt = time.Now() | 54 | m.UpdateAt = time.Now() |
| 55 | + m.DeleteAt = time.Unix(0, 0) | ||
| 55 | id, err = o.Insert(m) | 56 | id, err = o.Insert(m) |
| 56 | return | 57 | return |
| 57 | } | 58 | } |
| @@ -16,6 +16,7 @@ type Role struct { | @@ -16,6 +16,7 @@ type Role struct { | ||
| 16 | CompanyId int64 `orm:"column(company_id)"` | 16 | CompanyId int64 `orm:"column(company_id)"` |
| 17 | Descript string `orm:"column(descript)"` | 17 | Descript string `orm:"column(descript)"` |
| 18 | CreateAt time.Time `orm:"column(create_at);type(timestamp)"` | 18 | CreateAt time.Time `orm:"column(create_at);type(timestamp)"` |
| 19 | + UpdateAt time.Time `orm:"column(update_at);type(timestamp)"` | ||
| 19 | DeleteAt time.Time `orm:"column(delete_at);type(timestamp)"` | 20 | DeleteAt time.Time `orm:"column(delete_at);type(timestamp)"` |
| 20 | IsDefault int8 `orm:"column(is_default)"` | 21 | IsDefault int8 `orm:"column(is_default)"` |
| 21 | } | 22 | } |
| @@ -30,8 +31,9 @@ func init() { | @@ -30,8 +31,9 @@ func init() { | ||
| 30 | 31 | ||
| 31 | //角色类型 | 32 | //角色类型 |
| 32 | const ( | 33 | const ( |
| 33 | - ROLETYPES_GROUP int8 = 1 //角色组 | ||
| 34 | - ROLETYPES_ROLE int8 = 2 //角色 | 34 | + ROLETYPES_ROLE int8 = 1 //角色 |
| 35 | + ROLETYPES_GROUP int8 = 2 //角色组 | ||
| 36 | + | ||
| 35 | ) | 37 | ) |
| 36 | 38 | ||
| 37 | //默认角色 | 39 | //默认角色 |
| @@ -58,8 +60,10 @@ func (t *Role) ValidatePid() (*Role, error) { | @@ -58,8 +60,10 @@ func (t *Role) ValidatePid() (*Role, error) { | ||
| 58 | if err != nil { | 60 | if err != nil { |
| 59 | return nil, err | 61 | return nil, err |
| 60 | } | 62 | } |
| 61 | - if roledata.DeleteAt.Unix() != 0 { | ||
| 62 | - return nil, errors.New("roledata.DeleteAt !=0") | 63 | + |
| 64 | + if roledata.DeleteAt.Unix() > 0 { | ||
| 65 | + | ||
| 66 | + return nil, errors.New("roledata Delete") | ||
| 63 | } | 67 | } |
| 64 | if roledata.Types != ROLETYPES_GROUP { | 68 | if roledata.Types != ROLETYPES_GROUP { |
| 65 | return nil, errors.New("roledata.Types != ROLETYPES_GROUP") | 69 | return nil, errors.New("roledata.Types != ROLETYPES_GROUP") |
| @@ -75,6 +79,8 @@ func (t *Role) ValidatePid() (*Role, error) { | @@ -75,6 +79,8 @@ func (t *Role) ValidatePid() (*Role, error) { | ||
| 75 | func AddRole(m *Role) (id int64, err error) { | 79 | func AddRole(m *Role) (id int64, err error) { |
| 76 | o := orm.NewOrm() | 80 | o := orm.NewOrm() |
| 77 | m.CreateAt = time.Now() | 81 | m.CreateAt = time.Now() |
| 82 | + m.DeleteAt = time.Unix(0, 0) | ||
| 83 | + m.UpdateAt = time.Now() | ||
| 78 | id, err = o.Insert(m) | 84 | id, err = o.Insert(m) |
| 79 | return | 85 | return |
| 80 | } | 86 | } |
| @@ -143,3 +149,36 @@ func CountRoleByPid(pid int64) (int64, error) { | @@ -143,3 +149,36 @@ func CountRoleByPid(pid int64) (int64, error) { | ||
| 143 | Filter("pid", pid).Count() | 149 | Filter("pid", pid).Count() |
| 144 | return cnt, err | 150 | return cnt, err |
| 145 | } | 151 | } |
| 152 | + | ||
| 153 | +func GetRoleGroupsByCompany(companyid int64) ([]Role, error) { | ||
| 154 | + var ( | ||
| 155 | + err error | ||
| 156 | + roles []Role | ||
| 157 | + ) | ||
| 158 | + o := orm.NewOrm() | ||
| 159 | + _, err = o.QueryTable(&Role{}). | ||
| 160 | + Filter("company_id", companyid). | ||
| 161 | + Filter("types", ROLETYPES_GROUP). | ||
| 162 | + Filter("delete_at", 0). | ||
| 163 | + All(&roles) | ||
| 164 | + if err == orm.ErrNoRows { | ||
| 165 | + return roles, nil | ||
| 166 | + } | ||
| 167 | + return roles, err | ||
| 168 | +} | ||
| 169 | + | ||
| 170 | +func GetRoleByPid(pid int64) ([]Role, error) { | ||
| 171 | + var ( | ||
| 172 | + err error | ||
| 173 | + roles []Role | ||
| 174 | + ) | ||
| 175 | + o := orm.NewOrm() | ||
| 176 | + _, err = o.QueryTable(&Role{}). | ||
| 177 | + Filter("pid", pid). | ||
| 178 | + Filter("delete_at", 0). | ||
| 179 | + All(&roles) | ||
| 180 | + if err == orm.ErrNoRows { | ||
| 181 | + return roles, nil | ||
| 182 | + } | ||
| 183 | + return roles, err | ||
| 184 | +} |
| @@ -2,7 +2,6 @@ package models | @@ -2,7 +2,6 @@ package models | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "fmt" | 4 | "fmt" |
| 5 | - "strings" | ||
| 6 | "time" | 5 | "time" |
| 7 | 6 | ||
| 8 | "github.com/astaxie/beego/orm" | 7 | "github.com/astaxie/beego/orm" |
| @@ -20,7 +19,7 @@ type User struct { | @@ -20,7 +19,7 @@ type User struct { | ||
| 20 | LastLoginTime time.Time `orm:"column(last_login_time);type(timestamp)" description:"最后一次登录时间"` | 19 | LastLoginTime time.Time `orm:"column(last_login_time);type(timestamp)" description:"最后一次登录时间"` |
| 21 | CreateAt time.Time `orm:"column(create_at);type(timestamp);auto_now_add" description:"创建时间"` | 20 | CreateAt time.Time `orm:"column(create_at);type(timestamp);auto_now_add" description:"创建时间"` |
| 22 | EnableStatus int8 `orm:"column(enable_status)" description:"是否有效"` | 21 | EnableStatus int8 `orm:"column(enable_status)" description:"是否有效"` |
| 23 | - DeleteAt time.Time `orm:"column(delete_time);type(timestamp)"` | 22 | + DeleteAt time.Time `orm:"column(delete_at);type(timestamp)"` |
| 24 | } | 23 | } |
| 25 | 24 | ||
| 26 | func (t *User) TableName() string { | 25 | func (t *User) TableName() string { |
| @@ -103,17 +102,13 @@ func getUserNameByIds(ids []int64) ([]User, error) { | @@ -103,17 +102,13 @@ func getUserNameByIds(ids []int64) ([]User, error) { | ||
| 103 | if len(ids) == 0 { | 102 | if len(ids) == 0 { |
| 104 | return users, nil | 103 | return users, nil |
| 105 | } | 104 | } |
| 106 | - const ( | ||
| 107 | - dataSql string = `SELECT id,nick_name FROM user WHERE id IN (?) AND delete_at =0` | ||
| 108 | - ) | ||
| 109 | - var s []string | ||
| 110 | - for _, v := range ids { | ||
| 111 | - s = append(s, fmt.Sprint(v)) | ||
| 112 | - } | ||
| 113 | o := orm.NewOrm() | 105 | o := orm.NewOrm() |
| 114 | - _, err = o.Raw(dataSql, strings.Join(s, ",")).QueryRows(&users) | ||
| 115 | - if err != nil { | ||
| 116 | - return nil, err | ||
| 117 | - } | 106 | + _, err = o.QueryTable(&User{}). |
| 107 | + Filter("id__in", ids). | ||
| 108 | + Filter("delete_at", time.Unix(0, 0)).All(&users) | ||
| 109 | + | ||
| 110 | + if err == orm.ErrNoRows { | ||
| 118 | return users, nil | 111 | return users, nil |
| 112 | + } | ||
| 113 | + return users, err | ||
| 119 | } | 114 | } |
| @@ -2,7 +2,7 @@ package protocol | @@ -2,7 +2,7 @@ package protocol | ||
| 2 | 2 | ||
| 3 | //RequestRoleAdd 添加角色信息 | 3 | //RequestRoleAdd 添加角色信息 |
| 4 | type RequestRoleAdd struct { | 4 | type RequestRoleAdd struct { |
| 5 | - CompanyID int64 `json:"company"` | 5 | + CompanyID int64 `json:"company_id"` |
| 6 | Pid int64 `json:"pid"` | 6 | Pid int64 `json:"pid"` |
| 7 | Name string `json:"name"` | 7 | Name string `json:"name"` |
| 8 | Types int8 `json:"types"` | 8 | Types int8 `json:"types"` |
| @@ -12,7 +12,7 @@ type RequestRoleAdd struct { | @@ -12,7 +12,7 @@ type RequestRoleAdd struct { | ||
| 12 | //RequestRoleDelete 删除一个角色数据 | 12 | //RequestRoleDelete 删除一个角色数据 |
| 13 | type RequestRoleDelete struct { | 13 | type RequestRoleDelete struct { |
| 14 | CompanyID int64 `json:"company_id"` | 14 | CompanyID int64 `json:"company_id"` |
| 15 | - RoleID int64 `json:"role_id"` | 15 | + RoleID int64 `json:"id"` |
| 16 | } | 16 | } |
| 17 | 17 | ||
| 18 | //RequestRoleEdit 编辑角色信息入参 | 18 | //RequestRoleEdit 编辑角色信息入参 |
| @@ -30,12 +30,9 @@ type RequestRoleOne struct { | @@ -30,12 +30,9 @@ type RequestRoleOne struct { | ||
| 30 | //ResponseRoleInfo 响应数据 | 30 | //ResponseRoleInfo 响应数据 |
| 31 | type ResponseRoleInfo struct { | 31 | type ResponseRoleInfo struct { |
| 32 | ID int64 `json:"id"` | 32 | ID int64 `json:"id"` |
| 33 | - Pid int64 `json:"pid"` | ||
| 34 | - ParentName string `json:"parent_name"` | ||
| 35 | Name string `json:"name"` | 33 | Name string `json:"name"` |
| 36 | Descript string `json:"descript"` | 34 | Descript string `json:"descript"` |
| 37 | Types int8 `json:"types"` | 35 | Types int8 `json:"types"` |
| 38 | - CreateTime int64 `json:"create_time` | ||
| 39 | } | 36 | } |
| 40 | 37 | ||
| 41 | //RequestRoleList 分页获取角色列表 | 38 | //RequestRoleList 分页获取角色列表 |
| @@ -45,9 +42,15 @@ type RequestRoleList struct { | @@ -45,9 +42,15 @@ type RequestRoleList struct { | ||
| 45 | Keyword string `json:"keyword"` // 搜索关键字 | 42 | Keyword string `json:"keyword"` // 搜索关键字 |
| 46 | } | 43 | } |
| 47 | 44 | ||
| 48 | -type ResponseRoleList struct { | ||
| 49 | - ResponsePageInfo | ||
| 50 | - Data []ResponseRoleInfo `json:"data` | 45 | +type RoleInfo struct { |
| 46 | + Id int64 `json:"id"` | ||
| 47 | + Name string `json:"name"` | ||
| 48 | + IsDefault int8 `json:"is_default"` | ||
| 49 | +} | ||
| 50 | + | ||
| 51 | +type RoleGroup struct { | ||
| 52 | + RoleInfo | ||
| 53 | + Roles []RoleInfo `json:"roles"` | ||
| 51 | } | 54 | } |
| 52 | 55 | ||
| 53 | type RequestRolePermission struct { | 56 | type RequestRolePermission struct { |
| @@ -13,12 +13,12 @@ func init() { | @@ -13,12 +13,12 @@ func init() { | ||
| 13 | beego.NSBefore(middleware.AllowOption), | 13 | beego.NSBefore(middleware.AllowOption), |
| 14 | beego.NSBefore(middleware.LogRequestData, middleware.AuthToken), | 14 | beego.NSBefore(middleware.LogRequestData, middleware.AuthToken), |
| 15 | beego.NSNamespace("/company", | 15 | beego.NSNamespace("/company", |
| 16 | - beego.NSRouter("/:companyid/department", &controllers.CompanyController{}, "get:DepartmentList"), | ||
| 17 | - beego.NSRouter("/department/:id", &controllers.CompanyController{}, "get:DepartmentOne"), | 16 | + beego.NSRouter("/:companyid([0-9]+)/department", &controllers.CompanyController{}, "get:DepartmentList"), |
| 17 | + beego.NSRouter("/department/:id([0-9]+)", &controllers.CompanyController{}, "get:DepartmentOne"), | ||
| 18 | beego.NSRouter("/department", &controllers.CompanyController{}, "post:DepartmentAdd"), | 18 | beego.NSRouter("/department", &controllers.CompanyController{}, "post:DepartmentAdd"), |
| 19 | beego.NSRouter("/department", &controllers.CompanyController{}, "put:DepartmentUpdate"), | 19 | beego.NSRouter("/department", &controllers.CompanyController{}, "put:DepartmentUpdate"), |
| 20 | beego.NSRouter("/department", &controllers.CompanyController{}, "delete:DepartmentDelete"), | 20 | beego.NSRouter("/department", &controllers.CompanyController{}, "delete:DepartmentDelete"), |
| 21 | - beego.NSRouter("/:companyid/position", &controllers.CompanyController{}, "get:PositionList"), | 21 | + beego.NSRouter("/:companyid([0-9]+)/position", &controllers.CompanyController{}, "get:PositionList"), |
| 22 | beego.NSRouter("/position", &controllers.CompanyController{}, "post:PositionAdd"), | 22 | beego.NSRouter("/position", &controllers.CompanyController{}, "post:PositionAdd"), |
| 23 | beego.NSRouter("/position", &controllers.CompanyController{}, "put:PositionEdit"), | 23 | beego.NSRouter("/position", &controllers.CompanyController{}, "put:PositionEdit"), |
| 24 | beego.NSRouter("/position", &controllers.CompanyController{}, "delete:PositionDelete"), | 24 | beego.NSRouter("/position", &controllers.CompanyController{}, "delete:PositionDelete"), |
| @@ -30,7 +30,7 @@ func init() { | @@ -30,7 +30,7 @@ func init() { | ||
| 30 | beego.NSRouter("/role_group", &controllers.RbacController{}, "post:RoleGroupAdd"), | 30 | beego.NSRouter("/role_group", &controllers.RbacController{}, "post:RoleGroupAdd"), |
| 31 | beego.NSRouter("/role_group", &controllers.RbacController{}, "put:RoleGroupUpdate"), | 31 | beego.NSRouter("/role_group", &controllers.RbacController{}, "put:RoleGroupUpdate"), |
| 32 | beego.NSRouter("/role_group", &controllers.RbacController{}, "delete:RoleGroupDelete"), | 32 | beego.NSRouter("/role_group", &controllers.RbacController{}, "delete:RoleGroupDelete"), |
| 33 | - beego.NSRouter("/:companyid/role", &controllers.RbacController{}, "get:RoleList"), | 33 | + beego.NSRouter("/:companyid([0-9]+)/role", &controllers.RbacController{}, "get:RoleList"), |
| 34 | ), | 34 | ), |
| 35 | ) | 35 | ) |
| 36 | 36 |
| @@ -5,6 +5,7 @@ import ( | @@ -5,6 +5,7 @@ import ( | ||
| 5 | "oppmg/common/log" | 5 | "oppmg/common/log" |
| 6 | "oppmg/models" | 6 | "oppmg/models" |
| 7 | "oppmg/protocol" | 7 | "oppmg/protocol" |
| 8 | + "oppmg/utils" | ||
| 8 | "time" | 9 | "time" |
| 9 | ) | 10 | ) |
| 10 | 11 | ||
| @@ -43,9 +44,7 @@ func RoleAdd(param protocol.RequestRoleAdd) (*protocol.ResponseRoleInfo, error) | @@ -43,9 +44,7 @@ func RoleAdd(param protocol.RequestRoleAdd) (*protocol.ResponseRoleInfo, error) | ||
| 43 | ID: roleid, | 44 | ID: roleid, |
| 44 | Name: role.Name, | 45 | Name: role.Name, |
| 45 | Descript: role.Descript, | 46 | Descript: role.Descript, |
| 46 | - Pid: role.Pid, | ||
| 47 | Types: role.Types, | 47 | Types: role.Types, |
| 48 | - CreateTime: role.CreateAt.Unix(), //Format("2006-01-02 15:04:05") | ||
| 49 | } | 48 | } |
| 50 | return r, nil | 49 | return r, nil |
| 51 | } | 50 | } |
| @@ -53,7 +52,7 @@ func RoleAdd(param protocol.RequestRoleAdd) (*protocol.ResponseRoleInfo, error) | @@ -53,7 +52,7 @@ func RoleAdd(param protocol.RequestRoleAdd) (*protocol.ResponseRoleInfo, error) | ||
| 53 | func RoleDelete(param protocol.RequestRoleDelete) error { | 52 | func RoleDelete(param protocol.RequestRoleDelete) error { |
| 54 | role, err := models.GetRoleById(param.RoleID) | 53 | role, err := models.GetRoleById(param.RoleID) |
| 55 | if err != nil { | 54 | if err != nil { |
| 56 | - e := fmt.Errorf("GetRoleById err:%s", err) | 55 | + e := fmt.Errorf("GetRoleById(%d) err:%s", param.RoleID, err) |
| 57 | log.Error(e.Error()) | 56 | log.Error(e.Error()) |
| 58 | return protocol.NewErrWithMessage("1", e) | 57 | return protocol.NewErrWithMessage("1", e) |
| 59 | } | 58 | } |
| @@ -86,7 +85,6 @@ func RoleDelete(param protocol.RequestRoleDelete) error { | @@ -86,7 +85,6 @@ func RoleDelete(param protocol.RequestRoleDelete) error { | ||
| 86 | 85 | ||
| 87 | func RoleEdit(param protocol.RequestRoleEdit) (*protocol.ResponseRoleInfo, error) { | 86 | func RoleEdit(param protocol.RequestRoleEdit) (*protocol.ResponseRoleInfo, error) { |
| 88 | var ( | 87 | var ( |
| 89 | - //parentRole *models.Role | ||
| 90 | role *models.Role | 88 | role *models.Role |
| 91 | err error | 89 | err error |
| 92 | ) | 90 | ) |
| @@ -118,9 +116,7 @@ func RoleEdit(param protocol.RequestRoleEdit) (*protocol.ResponseRoleInfo, error | @@ -118,9 +116,7 @@ func RoleEdit(param protocol.RequestRoleEdit) (*protocol.ResponseRoleInfo, error | ||
| 118 | ID: role.Id, | 116 | ID: role.Id, |
| 119 | Name: role.Name, | 117 | Name: role.Name, |
| 120 | Descript: role.Descript, | 118 | Descript: role.Descript, |
| 121 | - Pid: role.Pid, | ||
| 122 | Types: role.Types, | 119 | Types: role.Types, |
| 123 | - CreateTime: role.CreateAt.Unix(), | ||
| 124 | } | 120 | } |
| 125 | return r, nil | 121 | return r, nil |
| 126 | } | 122 | } |
| @@ -169,6 +165,57 @@ func CanSetRole(adminId int64, groupId int64) bool { | @@ -169,6 +165,57 @@ func CanSetRole(adminId int64, groupId int64) bool { | ||
| 169 | return false | 165 | return false |
| 170 | } | 166 | } |
| 171 | 167 | ||
| 168 | +func GetRoleList(companyId int64) ([]protocol.RoleGroup, error) { | ||
| 169 | + var ( | ||
| 170 | + roleGroups []protocol.RoleGroup | ||
| 171 | + err error | ||
| 172 | + groups []protocol.RoleInfo | ||
| 173 | + ) | ||
| 174 | + groups, err = getRoleGroupByCompany(companyId) | ||
| 175 | + if err != nil { | ||
| 176 | + log.Error("getRoleGroupByCompany err:%s", err) | ||
| 177 | + return roleGroups, protocol.NewErrWithMessage("1") | ||
| 178 | + } | ||
| 179 | + for k, v := range groups { | ||
| 180 | + var roles []protocol.RoleInfo | ||
| 181 | + roles, err = getRoleInfoByPid(companyId, v.Id) | ||
| 182 | + if err != nil { | ||
| 183 | + log.Error("getRoleInfoByPid err:%s", err) | ||
| 184 | + return roleGroups, protocol.NewErrWithMessage("1") | ||
| 185 | + } | ||
| 186 | + rolegroup := protocol.RoleGroup{ | ||
| 187 | + RoleInfo: groups[k], | ||
| 188 | + Roles: roles, | ||
| 189 | + } | ||
| 190 | + roleGroups = append(roleGroups, rolegroup) | ||
| 191 | + } | ||
| 192 | + return roleGroups, nil | ||
| 193 | +} | ||
| 194 | + | ||
| 195 | +func getRoleInfoByPid(companyid int64, pid int64) ([]protocol.RoleInfo, error) { | ||
| 196 | + const ( | ||
| 197 | + dataSql string = `SELECT id,name,is_default FROM role WHERE company_id=? AND pid=? and delete_at=0 ` | ||
| 198 | + ) | ||
| 199 | + var ( | ||
| 200 | + err error | ||
| 201 | + roles []protocol.RoleInfo | ||
| 202 | + ) | ||
| 203 | + err = utils.ExecuteQueryAll(&roles, dataSql, companyid, pid) | ||
| 204 | + return roles, err | ||
| 205 | +} | ||
| 206 | + | ||
| 207 | +func getRoleGroupByCompany(companyid int64) ([]protocol.RoleInfo, error) { | ||
| 208 | + const ( | ||
| 209 | + datasql string = `SELECT id,name,is_default FROM role WHERE company_id=? AND types=? AND delete_at=0 ` | ||
| 210 | + ) | ||
| 211 | + var ( | ||
| 212 | + err error | ||
| 213 | + roles []protocol.RoleInfo | ||
| 214 | + ) | ||
| 215 | + err = utils.ExecuteQueryAll(&roles, datasql, companyid, models.ROLETYPES_GROUP) | ||
| 216 | + return roles, err | ||
| 217 | +} | ||
| 218 | + | ||
| 172 | func RoleGetOne(param protocol.RequestRoleOne) (*protocol.ResponseRoleInfo, error) { | 219 | func RoleGetOne(param protocol.RequestRoleOne) (*protocol.ResponseRoleInfo, error) { |
| 173 | // roledata, err := models.GetRoleById(param.RoleID) | 220 | // roledata, err := models.GetRoleById(param.RoleID) |
| 174 | return nil, nil | 221 | return nil, nil |
-
请 注册 或 登录 后发表评论