作者 唐旭辉

“用户角色权限设置”进行中

@@ -5,7 +5,6 @@ import ( @@ -5,7 +5,6 @@ import (
5 "oppmg/common/log" 5 "oppmg/common/log"
6 "oppmg/protocol" 6 "oppmg/protocol"
7 servecompany "oppmg/services/company" 7 servecompany "oppmg/services/company"
8 - "oppmg/storage/redisdata"  
9 "oppmg/utils" 8 "oppmg/utils"
10 "strings" 9 "strings"
11 ) 10 )
@@ -302,7 +301,7 @@ func (c *CompanyController) UserDelete() { @@ -302,7 +301,7 @@ func (c *CompanyController) UserDelete() {
302 c.ResposeJson(msg) 301 c.ResposeJson(msg)
303 }() 302 }()
304 type Parameter struct { 303 type Parameter struct {
305 - Userid int64 `json:"user_id"` 304 + UserCompanyId []int64 `json:"ids"`
306 } 305 }
307 var param Parameter 306 var param Parameter
308 if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil { 307 if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
@@ -311,20 +310,15 @@ func (c *CompanyController) UserDelete() { @@ -311,20 +310,15 @@ func (c *CompanyController) UserDelete() {
311 return 310 return
312 } 311 }
313 companyId := c.GetCompanyId() 312 companyId := c.GetCompanyId()
314 - err := servecompany.UserDelete(param.Userid, companyId)  
315 - if err == nil {  
316 - e := redisdata.DeleteLoginToken(param.Userid)  
317 - if e != nil {  
318 - log.Error(e.Error())  
319 - }  
320 - } 313 + err := servecompany.UserDelete(param.UserCompanyId, companyId)
  314 +
321 msg = protocol.NewReturnResponse(nil, err) 315 msg = protocol.NewReturnResponse(nil, err)
322 return 316 return
323 } 317 }
324 318
325 //UserEdit 禁用、启用用户 TODO 319 //UserEdit 禁用、启用用户 TODO
326 -//@Router /user/forbid [post]  
327 -func (c *CompanyController) UserForbid() { 320 +//@Router /user/allow_forbid [post]
  321 +func (c *CompanyController) UserAllowForbid() {
328 var msg *protocol.ResponseMessage 322 var msg *protocol.ResponseMessage
329 defer func() { 323 defer func() {
330 c.ResposeJson(msg) 324 c.ResposeJson(msg)
@@ -333,14 +327,27 @@ func (c *CompanyController) UserForbid() { @@ -333,14 +327,27 @@ func (c *CompanyController) UserForbid() {
333 UserCompanyIds []int64 `json:"ids"` 327 UserCompanyIds []int64 `json:"ids"`
334 Status int `json:"status"` // [1:执行禁用操作][2:执行启用操作] 328 Status int `json:"status"` // [1:执行禁用操作][2:执行启用操作]
335 } 329 }
336 - var param protocol.RequestUserEdit 330 + var param Parameter
337 if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil { 331 if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
338 log.Error("json 解析失败 err:%s", err) 332 log.Error("json 解析失败 err:%s", err)
339 msg = protocol.BadRequestParam("1") 333 msg = protocol.BadRequestParam("1")
340 return 334 return
341 } 335 }
  336 + var (
  337 + err error
  338 + )
  339 + companyid := c.GetCompanyId()
  340 + switch param.Status {
  341 + case 1:
  342 + err = servecompany.UserForbid(param.UserCompanyIds, companyid)
  343 + case 2:
  344 + err = servecompany.UserAllow(param.UserCompanyIds, companyid)
  345 + default:
  346 + msg = protocol.BadRequestParam("1")
  347 + return
  348 + }
342 349
343 - msg = protocol.NewReturnResponse(nil, nil) 350 + msg = protocol.NewReturnResponse(nil, err)
344 return 351 return
345 } 352 }
346 353
@@ -406,3 +413,45 @@ func (c *CompanyController) DepartmentUser() { @@ -406,3 +413,45 @@ func (c *CompanyController) DepartmentUser() {
406 msg = protocol.NewReturnResponse(resultdata, err) 413 msg = protocol.NewReturnResponse(resultdata, err)
407 return 414 return
408 } 415 }
  416 +
  417 +//CurrentCompanyEdit 编辑当前公司
  418 +func (c *CompanyController) CurrentCompanyEdit() {
  419 + var msg *protocol.ResponseMessage
  420 + defer func() {
  421 + c.ResposeJson(msg)
  422 + }()
  423 + type Parameter struct {
  424 + Logo string `json:"string"`
  425 + }
  426 + var param Parameter
  427 + if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
  428 + log.Error("json 解析失败 err:%s", err)
  429 + msg = protocol.BadRequestParam("1")
  430 + return
  431 + }
  432 + companyid := c.GetCompanyId()
  433 + err := servecompany.CompanyInfoEdit(companyid, param.Logo)
  434 + msg = protocol.NewReturnResponse(nil, err)
  435 + return
  436 +}
  437 +
  438 +//CurrentCompanyInfo 获取当前公司数据
  439 +func (c *CompanyController) CurrentCompanyInfo() {
  440 + var msg *protocol.ResponseMessage
  441 + defer func() {
  442 + c.ResposeJson(msg)
  443 + }()
  444 + // type Parameter struct {
  445 + // Logo string `json:"string"`
  446 + // }
  447 + // var param Parameter
  448 + // if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
  449 + // log.Error("json 解析失败 err:%s", err)
  450 + // msg = protocol.BadRequestParam("1")
  451 + // return
  452 + // }
  453 + companyid := c.GetCompanyId()
  454 + companybase, err := servecompany.CompanyBaseInfo(companyid)
  455 + msg = protocol.NewReturnResponse(companybase, err)
  456 + return
  457 +}
@@ -188,3 +188,41 @@ func (c *RbacController) RoleList() { @@ -188,3 +188,41 @@ func (c *RbacController) RoleList() {
188 msg = protocol.NewReturnResponse(rolelist, err) 188 msg = protocol.NewReturnResponse(rolelist, err)
189 return 189 return
190 } 190 }
  191 +
  192 +//PermissionList
  193 +//@router /menu/list [post]
  194 +func (c *RbacController) MenuList() {
  195 + var msg *protocol.ResponseMessage
  196 + defer func() {
  197 + c.ResposeJson(msg)
  198 + }()
  199 + list, err := serverbac.GetMenuAll()
  200 + msg = protocol.NewReturnResponse(list, err)
  201 + return
  202 +}
  203 +
  204 +//GetRoleHasMenu 获取角色下的菜单
  205 +//@router /role/menu
  206 +func (c *RbacController) RoleHasMenu() {
  207 + var msg *protocol.ResponseMessage
  208 + defer func() {
  209 + c.ResposeJson(msg)
  210 + }()
  211 + type Parameter struct {
  212 + RoleId int64 `json:"role_id"`
  213 + }
  214 + var param Parameter
  215 + if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
  216 + log.Error("json 解析失败 err:%s", err)
  217 + msg = protocol.BadRequestParam("1")
  218 + return
  219 + }
  220 + companyid := c.GetCompanyId()
  221 + list, err := serverbac.GetRoleHasMenu(param.RoleId, companyid)
  222 + msg = protocol.NewReturnResponse(list, err)
  223 + return
  224 +}
  225 +
  226 +func (c *RbacController) RoleMenuEdit() {
  227 + return
  228 +}
@@ -82,13 +82,14 @@ func GetCompanyById(id int64) (v *Company, err error) { @@ -82,13 +82,14 @@ func GetCompanyById(id int64) (v *Company, err error) {
82 82
83 // UpdateCompany updates Company by Id and returns error if 83 // UpdateCompany updates Company by Id and returns error if
84 // the record to be updated doesn't exist 84 // the record to be updated doesn't exist
85 -func UpdateCompanyById(m *Company) (err error) { 85 +func UpdateCompanyById(m *Company, col []string) (err error) {
86 o := orm.NewOrm() 86 o := orm.NewOrm()
87 v := Company{Id: m.Id} 87 v := Company{Id: m.Id}
88 // ascertain id exists in the database 88 // ascertain id exists in the database
89 if err = o.Read(&v); err == nil { 89 if err = o.Read(&v); err == nil {
90 var num int64 90 var num int64
91 - if num, err = o.Update(m); err == nil { 91 + m.UpdateAt = time.Now()
  92 + if num, err = o.Update(m, col...); err == nil {
92 fmt.Println("Number of records updated in database:", num) 93 fmt.Println("Number of records updated in database:", num)
93 } 94 }
94 } 95 }
  1 +package models
  2 +
  3 +import (
  4 + "time"
  5 +
  6 + "github.com/astaxie/beego/orm"
  7 +)
  8 +
  9 +type Menu struct {
  10 + Id int `orm:"column(id);auto" description:"主键"`
  11 + Name string `orm:"column(name);size(10)" description:"菜单名称"`
  12 + Icon string `orm:"column(icon);size(128)" description:"菜单图标地址"`
  13 + ParentId int `orm:"column(parent_id)" description:"上一级菜单 id"`
  14 + Type int `orm:"column(type)" description:"类型:1为 pc 2为app"`
  15 + Url string `orm:"column(url);size(128)" description:"菜单地址"`
  16 + SeniorStatus int `orm:"column(senior_status)" description:"类型:是否有高级设置 1是 0 否"`
  17 + Code string `orm:"column(code);size(128)" description:"菜单编码"`
  18 + Sort int `orm:"column(sort)" description:"同级菜单序号 "`
  19 + CreateTime time.Time `orm:"column(create_time);type(timestamp);null" description:"创建时间"`
  20 + Enabled int8 `orm:"column(enabled)" description:"是否有效"`
  21 +}
  22 +
  23 +func (t *Menu) TableName() string {
  24 + return "menu"
  25 +}
  26 +
  27 +func init() {
  28 + orm.RegisterModel(new(Menu))
  29 +}
  30 +
  31 +// GetMenuById retrieves Menu by Id. Returns error if
  32 +// Id doesn't exist
  33 +func GetMenuById(id int) (v *Menu, err error) {
  34 + o := orm.NewOrm()
  35 + v = &Menu{Id: id}
  36 + if err = o.Read(v); err == nil {
  37 + return v, nil
  38 + }
  39 + return nil, err
  40 +}
  1 +package models
  2 +
  3 +import (
  4 + "github.com/astaxie/beego/orm"
  5 +)
  6 +
  7 +type RoleMenu struct {
  8 + Id int64 `orm:"column(id);auto" description:"主键"`
  9 + RoleId int64 `orm:"column(role_id);null" description:"role.id"`
  10 + MenuId int64 `orm:"column(menu_id);null" description:"menu.id"`
  11 + Opption string `orm:"column(opption);size(500);null" description:"配置"`
  12 +}
  13 +
  14 +func (t *RoleMenu) TableName() string {
  15 + return "role_menu"
  16 +}
  17 +
  18 +func init() {
  19 + orm.RegisterModel(new(RoleMenu))
  20 +}
  21 +
  22 +// AddRoleMenu insert a new RoleMenu into database and returns
  23 +// last inserted Id on success.
  24 +func AddRoleMenu(m *RoleMenu) (id int64, err error) {
  25 + o := orm.NewOrm()
  26 + id, err = o.Insert(m)
  27 + return
  28 +}
  29 +
  30 +func GetRoleMenuByRole(roleid int64) ([]RoleMenu, error) {
  31 + var (
  32 + list []RoleMenu
  33 + err error
  34 + )
  35 + o := orm.NewOrm()
  36 + _, err = o.QueryTable(&RoleMenu{}).
  37 + Filter("role_id", roleid).
  38 + All(&list)
  39 + if err == orm.ErrNoRows {
  40 + return list, nil
  41 + }
  42 + return list, err
  43 +}
@@ -114,3 +114,9 @@ type UserListItem struct { @@ -114,3 +114,9 @@ type UserListItem struct {
114 Departments string `json:"departments" orm:"-"` 114 Departments string `json:"departments" orm:"-"`
115 Enable int8 `json:"enable" orm:"column(enable)"` 115 Enable int8 `json:"enable" orm:"column(enable)"`
116 } 116 }
  117 +
  118 +type ResponseCompanyBase struct {
  119 + CompanyId int64 `json:"id"`
  120 + Name string `json:"name"`
  121 + Logo string `json:"logo"`
  122 +}
@@ -3,7 +3,7 @@ package protocol @@ -3,7 +3,7 @@ package protocol
3 var errmessge ErrorMap = map[string]string{ 3 var errmessge ErrorMap = map[string]string{
4 //操作 4 //操作
5 "0": "成功", 5 "0": "成功",
6 - "1": "无效请求", 6 + "1": "网络连接无响应",
7 //角色相关 7 //角色相关
8 "10001": "请先删除该分组下的其他角色", 8 "10001": "请先删除该分组下的其他角色",
9 "10002": "请先删除该角色下的人员", 9 "10002": "请先删除该角色下的人员",
@@ -57,3 +57,24 @@ type RequestRolePermission struct { @@ -57,3 +57,24 @@ type RequestRolePermission struct {
57 RoleID int `json:"role_id"` 57 RoleID int `json:"role_id"`
58 PermissionID []int `json:"permission_id"` 58 PermissionID []int `json:"permission_id"`
59 } 59 }
  60 +
  61 +type PermissionItem struct {
  62 + Id int64 `json:"id"`
  63 + Name string `json:"name"`
  64 + Icon string `json:"icon"`
  65 + ParentId int64 `json:"parent_id"`
  66 + SeniorStatus int8 `json:"senior_status"`
  67 + Sort int `json:"sort"`
  68 +}
  69 +
  70 +//TODO PermissionItem 实现排序接口
  71 +
  72 +//
  73 +type ResponseRoleMenus struct {
  74 + RoleId int64 `json:"role_id"`
  75 + RoleName string `json:"role_name"`
  76 + MenuId []int64 `json:"menu_ids"`
  77 +}
  78 +
  79 +type ResponseRolePermission struct {
  80 +}
  1 +package routers
  2 +
  3 +// type PermissionBase struct {
  4 +// Check int8 `json:"check"`
  5 +// }
  6 +
  7 +//职位管理相关
  8 +type PermissionWithPosition struct {
  9 + Check int8 `json:"check"`
  10 +}
  11 +
  12 +func (c PermissionWithPosition) Code() string {
  13 + return "OPPMG_POSITION"
  14 +}
  15 +
  16 +//部门管理相关
  17 +type PermissionWithDepart struct {
  18 + Check int8 `json:"check"`
  19 +}
@@ -9,7 +9,7 @@ import ( @@ -9,7 +9,7 @@ import (
9 ) 9 )
10 10
11 func init() { 11 func init() {
12 - nsV1 := beego.NewNamespace("v1", 12 + nsV1 := beego.NewNamespace("/v1",
13 beego.NSBefore(middleware.AllowOption), 13 beego.NSBefore(middleware.AllowOption),
14 beego.NSBefore(middleware.LogRequestData), 14 beego.NSBefore(middleware.LogRequestData),
15 //beego.NSBefore(middleware.AuthToken), 15 //beego.NSBefore(middleware.AuthToken),
@@ -34,12 +34,15 @@ func init() { @@ -34,12 +34,15 @@ func init() {
34 beego.NSRouter("/role_group/edit", &controllers.RbacController{}, "post:RoleGroupUpdate"), 34 beego.NSRouter("/role_group/edit", &controllers.RbacController{}, "post:RoleGroupUpdate"),
35 beego.NSRouter("/role_group/delete", &controllers.RbacController{}, "post:RoleGroupDelete"), 35 beego.NSRouter("/role_group/delete", &controllers.RbacController{}, "post:RoleGroupDelete"),
36 beego.NSRouter("/role/list", &controllers.RbacController{}, "post:RoleList"), 36 beego.NSRouter("/role/list", &controllers.RbacController{}, "post:RoleList"),
  37 + beego.NSRouter("/menu/list", &controllers.RbacController{}, "post:MenuList"),
  38 + beego.NSRouter("/role/menu", &controllers.RbacController{}, "post:RoleHasMenu"),
37 ), 39 ),
38 beego.NSNamespace("/user", 40 beego.NSNamespace("/user",
39 beego.NSRouter("/list", &controllers.CompanyController{}, "post:UserList"), 41 beego.NSRouter("/list", &controllers.CompanyController{}, "post:UserList"),
40 beego.NSRouter("/add", &controllers.CompanyController{}, "post:UserAdd"), 42 beego.NSRouter("/add", &controllers.CompanyController{}, "post:UserAdd"),
41 beego.NSRouter("/edit", &controllers.CompanyController{}, "post:UserEdit"), 43 beego.NSRouter("/edit", &controllers.CompanyController{}, "post:UserEdit"),
42 beego.NSRouter("/delete", &controllers.CompanyController{}, "post:UserDelete"), 44 beego.NSRouter("/delete", &controllers.CompanyController{}, "post:UserDelete"),
  45 + beego.NSRouter("/allow_forbid", &controllers.CompanyController{}, "post:UserAllowForbid"),
43 ), 46 ),
44 beego.NSNamespace("/auth", 47 beego.NSNamespace("/auth",
45 beego.NSRouter("/change_company", &controllers.AuthController{}, "post:ChangeCompany"), 48 beego.NSRouter("/change_company", &controllers.AuthController{}, "post:ChangeCompany"),
@@ -406,3 +406,34 @@ func initUserRole(newUserCompany *models.UserCompany, newRole *models.Role, o or @@ -406,3 +406,34 @@ func initUserRole(newUserCompany *models.UserCompany, newRole *models.Role, o or
406 406
407 return newUserRole, nil 407 return newUserRole, nil
408 } 408 }
  409 +
  410 +func CompanyInfoEdit(companyid int64, logo string) error {
  411 + data := models.Company{
  412 + Id: companyid,
  413 + Logo: logo,
  414 + }
  415 + err := models.UpdateCompanyById(&data, []string{"Logo"})
  416 + if err != nil {
  417 + log.Info("更新公司数据失败:%s", err)
  418 + return protocol.NewErrWithMessage("1")
  419 + }
  420 +
  421 + return nil
  422 +}
  423 +func CompanyBaseInfo(companyid int64) (*protocol.ResponseCompanyBase, error) {
  424 + var (
  425 + err error
  426 + mcompany *models.Company
  427 + )
  428 + mcompany, err = models.GetCompanyById(companyid)
  429 + if err != nil {
  430 + log.Error("获取公司基础数据失败:%s", err)
  431 + return nil, protocol.NewErrWithMessage("1")
  432 + }
  433 + companyinfo := &protocol.ResponseCompanyBase{
  434 + CompanyId: mcompany.Id,
  435 + Name: mcompany.Name,
  436 + Logo: mcompany.Logo,
  437 + }
  438 + return companyinfo, nil
  439 +}
@@ -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/storage/redisdata"
8 "oppmg/utils" 9 "oppmg/utils"
9 "strings" 10 "strings"
10 "time" 11 "time"
@@ -375,17 +376,31 @@ func UserEdit(param protocol.RequestUserEdit) error { @@ -375,17 +376,31 @@ func UserEdit(param protocol.RequestUserEdit) error {
375 return nil 376 return nil
376 } 377 }
377 378
378 -func UserDelete(userid, companyid int64) error {  
379 - ok := models.ExistUserCompany(userid, companyid)  
380 - if !ok {  
381 - e := fmt.Errorf("ExistUserCompany(userid, companyid) [%d,%d] ==false ", userid, companyid)  
382 - log.Error(e.Error())  
383 - return protocol.NewErrWithMessage("1") 379 +func UserDelete(userCompanyids []int64, companyid int64) error {
  380 + if len(userCompanyids) == 0 {
  381 + return nil
384 } 382 }
  383 + var (
  384 + updateIds []models.UserCompany
  385 + err error
  386 + )
385 o := orm.NewOrm() 387 o := orm.NewOrm()
386 - _, err := o.QueryTable(&models.UserCompany{}).  
387 - Filter("user_id", userid).  
388 - Filter("company_id"). 388 + _, err = o.QueryTable(&models.UserCompany{}).
  389 + Filter("id__in", userCompanyids).
  390 + Filter("company_id", companyid).
  391 + All(&updateIds, "Id", "UserId")
  392 + if err != nil {
  393 + log.Error("获取用户数据失败:%s", err)
  394 + return protocol.NewErrWithMessage("1")
  395 + }
  396 + var (
  397 + ids []int64
  398 + )
  399 + for _, v := range updateIds {
  400 + ids = append(ids, v.Id)
  401 + }
  402 + _, err = o.QueryTable(&models.UserCompany{}).
  403 + Filter("id__in", ids).
389 Update(orm.Params{ 404 Update(orm.Params{
390 "delete_at": time.Now().String(), 405 "delete_at": time.Now().String(),
391 }) 406 })
@@ -394,6 +409,13 @@ func UserDelete(userid, companyid int64) error { @@ -394,6 +409,13 @@ func UserDelete(userid, companyid int64) error {
394 log.Error(e.Error()) 409 log.Error(e.Error())
395 return protocol.NewErrWithMessage("1") 410 return protocol.NewErrWithMessage("1")
396 } 411 }
  412 + for _, v := range updateIds {
  413 + e := redisdata.DeleteLoginToken(v.UserId)
  414 + if e != nil {
  415 + log.Error(e.Error())
  416 + }
  417 + }
  418 +
397 return nil 419 return nil
398 } 420 }
399 421
@@ -510,22 +532,64 @@ func GetUserRole(usercompanyid int64) []protocol.RoleBase { @@ -510,22 +532,64 @@ func GetUserRole(usercompanyid int64) []protocol.RoleBase {
510 return data 532 return data
511 } 533 }
512 534
513 -//启用、禁用用户  
514 -func UserForbid(userCompanyIds []int64, companyid int64, enable int8) error {  
515 - if len(userCompanyIds) == 0 { 535 +//禁用用户
  536 +func UserForbid(userCompanyids []int64, companyid int64) error {
  537 + if len(userCompanyids) == 0 {
516 return nil 538 return nil
517 } 539 }
518 - if !(enable == models.USERCOMPANY_ENABLE_NO || enable == models.USERCOMPANY_ENABLE_YES) {  
519 - log.Error("enable err") 540 + var (
  541 + updateIds []models.UserCompany
  542 + err error
  543 + )
  544 + o := orm.NewOrm()
  545 + _, err = o.QueryTable(&models.UserCompany{}).
  546 + Filter("id__in", userCompanyids).
  547 + Filter("company_id", companyid).
  548 + All(&updateIds, "Id", "UserId")
  549 + if err != nil {
  550 + log.Error("获取用户数据失败:%s", err)
520 return protocol.NewErrWithMessage("1") 551 return protocol.NewErrWithMessage("1")
521 } 552 }
  553 + var (
  554 + ids []int64
  555 + )
  556 + for _, v := range updateIds {
  557 + ids = append(ids, v.Id)
  558 + }
  559 + num, err := o.QueryTable(&models.UserCompany{}).
  560 + Filter("delete_at", 0).
  561 + Filter("company_id", companyid).
  562 + Filter("id__in", ids).
  563 + Update(orm.Params{
  564 + "enable": models.USERCOMPANY_ENABLE_NO,
  565 + "update_at": time.Now(),
  566 + })
  567 + if err != nil {
  568 + log.Error("更新user_company失败:%s", err)
  569 + protocol.NewErrWithMessage("1")
  570 + }
  571 + log.Info("更新记录数:%d", num)
  572 + for _, v := range updateIds {
  573 + e := redisdata.DeleteLoginToken(v.UserId)
  574 + if e != nil {
  575 + log.Error(e.Error())
  576 + }
  577 + }
  578 + return nil
  579 +}
  580 +
  581 +//启用用户
  582 +func UserAllow(userCompanyIds []int64, companyid int64) error {
  583 + if len(userCompanyIds) == 0 {
  584 + return nil
  585 + }
522 o := orm.NewOrm() 586 o := orm.NewOrm()
523 num, err := o.QueryTable(&models.UserCompany{}). 587 num, err := o.QueryTable(&models.UserCompany{}).
524 Filter("delete_at", 0). 588 Filter("delete_at", 0).
525 Filter("company_id", companyid). 589 Filter("company_id", companyid).
526 Filter("id__in", userCompanyIds). 590 Filter("id__in", userCompanyIds).
527 Update(orm.Params{ 591 Update(orm.Params{
528 - "enable": enable, 592 + "enable": models.USERCOMPANY_ENABLE_YES,
529 "update_at": time.Now(), 593 "update_at": time.Now(),
530 }) 594 })
531 if err != nil { 595 if err != nil {
1 package rbac 1 package rbac
  2 +
  3 +import (
  4 + "oppmg/common/log"
  5 + "oppmg/models"
  6 + "oppmg/protocol"
  7 + "oppmg/utils"
  8 +)
  9 +
  10 +//获取全部的权限菜单
  11 +func GetMenuAll() ([]protocol.PermissionItem, error) {
  12 + const datasql string = `SELECT id,name,icon,parent_id,senior_status,sort
  13 + FROM menu WHERE enabled=1 ORDER BY sort `
  14 + var (
  15 + list []protocol.PermissionItem
  16 + err error
  17 + )
  18 + err = utils.ExecuteQueryAll(&list, datasql)
  19 + if err != nil {
  20 + log.Error("EXECUTE SQL err:%s", err)
  21 + return nil, protocol.NewErrWithMessage("1")
  22 + }
  23 + return list, nil
  24 +}
  25 +
  26 +//
  27 +func GetRoleHasMenu(roleid int64, companyid int64) (*protocol.ResponseRoleMenus, error) {
  28 + var (
  29 + roleData *models.Role
  30 + err error
  31 + )
  32 + roleData, err = models.GetRoleById(roleid)
  33 + if err != nil {
  34 + log.Error("获取角色数据失败:%s", err)
  35 + return nil, err
  36 + }
  37 + if roleData.Types != models.ROLETYPES_ROLE {
  38 + log.Error("角色类型错误")
  39 + return nil, protocol.NewErrWithMessage("1")
  40 + }
  41 + if roleData.CompanyId != companyid {
  42 + log.Error("角色的公司id不匹配")
  43 + return nil, protocol.NewErrWithMessage("1")
  44 + }
  45 + var (
  46 + rolemenu []models.RoleMenu
  47 + ids []int64
  48 + )
  49 + rolemenu, err = models.GetRoleMenuByRole(roleid)
  50 + if err != nil {
  51 + log.Error("获取角色下的菜单数据失败:%s", err)
  52 + return nil, protocol.NewErrWithMessage("1")
  53 + }
  54 + for _, v := range rolemenu {
  55 + ids = append(ids, v.MenuId)
  56 + }
  57 + data := &protocol.ResponseRoleMenus{
  58 + RoleId: roleData.Id,
  59 + RoleName: roleData.Name,
  60 + MenuId: ids,
  61 + }
  62 + return data, nil
  63 +}
  64 +
  65 +func RoleMenuEdit(companyid int64, roleid int64, menuids []int64) {
  66 +
  67 +}