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, ¶m); 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, ¶m); 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, ¶m); 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
|
+} |