作者 唐旭辉

添加

  1 +### 接口完成进度
  2 +
  3 +| 功能 | 完成状态 | 时间 | 接口路径 | 请求方式 |
  4 +| ---------- | -------- | ---------- | ---------------------- | -------- |
  5 +| 登录 | 进行中 | | |
  6 +| 短信验证码 | 未开始 | | |
  7 +| 获取 token | 未开始 | | |
  8 +| 刷新 token | 未开始 | | |
  9 +| 添加角色 | 完成 | 2019.11.26 | /v1/rbac/role | post |
  10 +| 编辑角色 | 完成 | 2019.11.26 | /v1/rbac/role | put |
  11 +| 删除角色 | 完成 | 2019.11.26 | /v1/rbac/role | delete |
  12 +| 添加部门 | 完成 | 2019.11.28 | /v1/company/department | post |
  13 +| 编辑部门 | 完成 | 2019.11.29 | /v1/company/department | put |
  14 +| 删除部门 | 完成 | 2019.11.29 | /v1/company/department | delete |
  15 +| 添加职位 | 进行中 | | /v1/company/position | post |
  16 +| 编辑职位 | 进行中 | | /v1/company/position | put |
  17 +| 删除职位 | 进行中 | | /v1/company/position | delete |
1 package controllers 1 package controllers
2 2
  3 +import (
  4 + "encoding/json"
  5 + "oppmg/common/log"
  6 + "oppmg/protocol"
  7 + serverbac "oppmg/services/rbac"
  8 +)
  9 +
3 type RbacController struct { 10 type RbacController struct {
4 BaseController 11 BaseController
5 } 12 }
@@ -8,3 +15,74 @@ type RbacController struct { @@ -8,3 +15,74 @@ type RbacController struct {
8 func (c *RbacController) URLMapping() { 15 func (c *RbacController) URLMapping() {
9 //c.Mapping("AccessToken", c.AccessToken) 16 //c.Mapping("AccessToken", c.AccessToken)
10 } 17 }
  18 +
  19 +// RoleAdd 添加部门
  20 +// @router /department [post]
  21 +func (c *RbacController) RoleAdd() {
  22 + var msg *protocol.ResponseMessage
  23 + defer func() {
  24 + c.ResposeJson(msg)
  25 + }()
  26 + var param protocol.RequestRoleAdd
  27 + if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
  28 + log.Error("json 解析失败 err:%s", err)
  29 + msg = protocol.BadRequestParam("1")
  30 + return
  31 + }
  32 + if param.CompanyID <= 0 {
  33 + log.Error("param.CompanyID <= 0")
  34 + msg = protocol.BadRequestParam("1")
  35 + return
  36 + }
  37 + err := serverbac.RoleAdd(param)
  38 + msg = protocol.NewReturnResponse(nil, err)
  39 + return
  40 +}
  41 +
  42 +// RoleUpdate 编辑部门
  43 +// @router /department [put]
  44 +func (c *RbacController) RoleUpdate() {
  45 + var msg *protocol.ResponseMessage
  46 + defer func() {
  47 + c.ResposeJson(msg)
  48 + }()
  49 + var param protocol.RequestRoleEdit
  50 + if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
  51 + log.Error("json 解析失败 err:%s", err)
  52 + msg = protocol.BadRequestParam("1")
  53 + return
  54 + }
  55 + if param.CompanyID <= 0 {
  56 + log.Error("param.CompanyID <= 0")
  57 + msg = protocol.BadRequestParam("1")
  58 + return
  59 + }
  60 +
  61 + err := serverbac.RoleEdit(param)
  62 + msg = protocol.NewReturnResponse(nil, err)
  63 + return
  64 +}
  65 +
  66 +// RoleDelete 删除角色
  67 +// @router /department [delete]
  68 +func (c *RbacController) RoleDelete() {
  69 + var msg *protocol.ResponseMessage
  70 + defer func() {
  71 + c.ResposeJson(msg)
  72 + }()
  73 + var param protocol.RequestRoleDelete
  74 + if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
  75 + log.Error("json 解析失败 err:%s", err)
  76 + msg = protocol.BadRequestParam("1")
  77 + return
  78 + }
  79 + if param.CompanyID <= 0 {
  80 + log.Error("param.CompanyID <= 0")
  81 + msg = protocol.BadRequestParam("1")
  82 + return
  83 + }
  84 +
  85 + err := serverbac.RoleDelete(param)
  86 + msg = protocol.NewReturnResponse(nil, err)
  87 + return
  88 +}
@@ -16,6 +16,11 @@ func init() { @@ -16,6 +16,11 @@ func init() {
16 beego.NSRouter("/department", &controllers.CompanyController{}, "put:DepartmentUpdate"), 16 beego.NSRouter("/department", &controllers.CompanyController{}, "put:DepartmentUpdate"),
17 beego.NSRouter("/department", &controllers.CompanyController{}, "delete:DepartmentDelete"), 17 beego.NSRouter("/department", &controllers.CompanyController{}, "delete:DepartmentDelete"),
18 ), 18 ),
  19 + beego.NSNamespace("/rbac",
  20 + beego.NSRouter("/role", &controllers.CompanyController{}, "post:RoleAdd"),
  21 + beego.NSRouter("/role", &controllers.CompanyController{}, "put:RoleUpdate"),
  22 + beego.NSRouter("/role", &controllers.CompanyController{}, "delete:RoleDelete"),
  23 + ),
19 ) 24 )
20 25
21 nsAuth := beego.NewNamespace("/auth", 26 nsAuth := beego.NewNamespace("/auth",