|
@@ -9,10 +9,11 @@ import ( |
|
@@ -9,10 +9,11 @@ import ( |
9
|
)
|
9
|
)
|
10
|
|
10
|
|
11
|
func RoleAdd(param protocol.RequestRoleAdd) (*protocol.ResponseRoleInfo, error) {
|
11
|
func RoleAdd(param protocol.RequestRoleAdd) (*protocol.ResponseRoleInfo, error) {
|
|
|
12
|
+ nowTime := time.Now()
|
12
|
role := models.Role{
|
13
|
role := models.Role{
|
13
|
CompanyId: param.CompanyID,
|
14
|
CompanyId: param.CompanyID,
|
14
|
Name: param.Name,
|
15
|
Name: param.Name,
|
15
|
- CreateAt: time.Now(),
|
16
|
+ CreateAt: nowTime,
|
16
|
Pid: param.Pid,
|
17
|
Pid: param.Pid,
|
17
|
Types: param.Types,
|
18
|
Types: param.Types,
|
18
|
Descript: param.Descript,
|
19
|
Descript: param.Descript,
|
|
@@ -22,21 +23,30 @@ func RoleAdd(param protocol.RequestRoleAdd) (*protocol.ResponseRoleInfo, error) |
|
@@ -22,21 +23,30 @@ func RoleAdd(param protocol.RequestRoleAdd) (*protocol.ResponseRoleInfo, error) |
22
|
log.Error(e.Error())
|
23
|
log.Error(e.Error())
|
23
|
return nil, protocol.NewErrWithMessage("1", e)
|
24
|
return nil, protocol.NewErrWithMessage("1", e)
|
24
|
}
|
25
|
}
|
25
|
- err := role.ValidatePid()
|
26
|
+ var (
|
|
|
27
|
+ parentRole *models.Role
|
|
|
28
|
+ err error
|
|
|
29
|
+ roleid int64
|
|
|
30
|
+ )
|
|
|
31
|
+ parentRole, err = role.ValidatePid()
|
26
|
if err != nil {
|
32
|
if err != nil {
|
27
|
e := fmt.Errorf("ValidatePid err:%s", err)
|
33
|
e := fmt.Errorf("ValidatePid err:%s", err)
|
28
|
log.Error(e.Error())
|
34
|
log.Error(e.Error())
|
29
|
return nil, protocol.NewErrWithMessage("1", e)
|
35
|
return nil, protocol.NewErrWithMessage("1", e)
|
30
|
}
|
36
|
}
|
31
|
- roleid, err := models.AddRole(&role)
|
37
|
+ roleid, err = models.AddRole(&role)
|
32
|
if err != nil {
|
38
|
if err != nil {
|
33
|
log.Error("AddRole err:%s", err)
|
39
|
log.Error("AddRole err:%s", err)
|
34
|
return nil, protocol.NewErrWithMessage("1", err)
|
40
|
return nil, protocol.NewErrWithMessage("1", err)
|
35
|
}
|
41
|
}
|
36
|
r := &protocol.ResponseRoleInfo{
|
42
|
r := &protocol.ResponseRoleInfo{
|
37
|
- ID: int(roleid),
|
|
|
38
|
- Name: role.Name,
|
|
|
39
|
- Descript: role.Descript,
|
43
|
+ ID: int(roleid),
|
|
|
44
|
+ Name: role.Name,
|
|
|
45
|
+ Descript: role.Descript,
|
|
|
46
|
+ Pid: role.Pid,
|
|
|
47
|
+ ParentName: parentRole.Name,
|
|
|
48
|
+ Types: role.Types,
|
|
|
49
|
+ CreateTime: role.CreateAt.Unix(), //Format("2006-01-02 15:04:05")
|
40
|
}
|
50
|
}
|
41
|
return r, nil
|
51
|
return r, nil
|
42
|
}
|
52
|
}
|
|
@@ -53,11 +63,15 @@ func RoleDelete(param protocol.RequestRoleDelete) error { |
|
@@ -53,11 +63,15 @@ func RoleDelete(param protocol.RequestRoleDelete) error { |
53
|
log.Error(e.Error())
|
63
|
log.Error(e.Error())
|
54
|
return protocol.NewErrWithMessage("1", e)
|
64
|
return protocol.NewErrWithMessage("1", e)
|
55
|
}
|
65
|
}
|
56
|
- //TODO
|
66
|
+ //
|
57
|
if role.Types == models.ROLETYPES_GROUP {
|
67
|
if role.Types == models.ROLETYPES_GROUP {
|
58
|
-
|
68
|
+ if err := models.DeleteRoleByPid(param.RoleID); err != nil {
|
|
|
69
|
+ e := fmt.Errorf("DeleteRoleByPid err:%s", err)
|
|
|
70
|
+ log.Error(e.Error())
|
|
|
71
|
+ return protocol.NewErrWithMessage("1", e)
|
|
|
72
|
+ }
|
59
|
}
|
73
|
}
|
60
|
- if err := models.DeleteRole(param.RoleID); err != nil {
|
74
|
+ if err := models.DeleteRoleByID(param.RoleID); err != nil {
|
61
|
e := fmt.Errorf("DeleteRole err:%s", err)
|
75
|
e := fmt.Errorf("DeleteRole err:%s", err)
|
62
|
log.Error(e.Error())
|
76
|
log.Error(e.Error())
|
63
|
return protocol.NewErrWithMessage("1", e)
|
77
|
return protocol.NewErrWithMessage("1", e)
|
|
@@ -67,8 +81,9 @@ func RoleDelete(param protocol.RequestRoleDelete) error { |
|
@@ -67,8 +81,9 @@ func RoleDelete(param protocol.RequestRoleDelete) error { |
67
|
|
81
|
|
68
|
func RoleEdit(param protocol.RequestRoleEdit) (*protocol.ResponseRoleInfo, error) {
|
82
|
func RoleEdit(param protocol.RequestRoleEdit) (*protocol.ResponseRoleInfo, error) {
|
69
|
var (
|
83
|
var (
|
70
|
- role *models.Role
|
|
|
71
|
- err error
|
84
|
+ parentRole *models.Role
|
|
|
85
|
+ role *models.Role
|
|
|
86
|
+ err error
|
72
|
)
|
87
|
)
|
73
|
role, err = models.GetRoleById(param.ID)
|
88
|
role, err = models.GetRoleById(param.ID)
|
74
|
if err != nil {
|
89
|
if err != nil {
|
|
@@ -84,7 +99,7 @@ func RoleEdit(param protocol.RequestRoleEdit) (*protocol.ResponseRoleInfo, error |
|
@@ -84,7 +99,7 @@ func RoleEdit(param protocol.RequestRoleEdit) (*protocol.ResponseRoleInfo, error |
84
|
role.Pid = param.Pid
|
99
|
role.Pid = param.Pid
|
85
|
role.Descript = param.Descript
|
100
|
role.Descript = param.Descript
|
86
|
role.Name = param.Name
|
101
|
role.Name = param.Name
|
87
|
- if err = role.ValidatePid(); err != nil {
|
102
|
+ if parentRole, err = role.ValidatePid(); err != nil {
|
88
|
e := fmt.Errorf("ValidatePid err:%s", err)
|
103
|
e := fmt.Errorf("ValidatePid err:%s", err)
|
89
|
log.Error(e.Error())
|
104
|
log.Error(e.Error())
|
90
|
return nil, protocol.NewErrWithMessage("1", e)
|
105
|
return nil, protocol.NewErrWithMessage("1", e)
|
|
@@ -95,15 +110,19 @@ func RoleEdit(param protocol.RequestRoleEdit) (*protocol.ResponseRoleInfo, error |
|
@@ -95,15 +110,19 @@ func RoleEdit(param protocol.RequestRoleEdit) (*protocol.ResponseRoleInfo, error |
95
|
return nil, protocol.NewErrWithMessage("1", e)
|
110
|
return nil, protocol.NewErrWithMessage("1", e)
|
96
|
}
|
111
|
}
|
97
|
r := &protocol.ResponseRoleInfo{
|
112
|
r := &protocol.ResponseRoleInfo{
|
98
|
- ID: param.ID,
|
|
|
99
|
- Name: param.Name,
|
|
|
100
|
- Descript: param.Descript,
|
113
|
+ ID: role.Id,
|
|
|
114
|
+ Name: role.Name,
|
|
|
115
|
+ Descript: role.Descript,
|
|
|
116
|
+ Pid: role.Pid,
|
|
|
117
|
+ ParentName: parentRole.Name,
|
|
|
118
|
+ Types: role.Types,
|
|
|
119
|
+ CreateTime: role.CreateAt.Unix(),
|
101
|
}
|
120
|
}
|
102
|
return r, nil
|
121
|
return r, nil
|
103
|
}
|
122
|
}
|
104
|
|
123
|
|
105
|
func RoleGetOne(param protocol.RequestRoleOne) (*protocol.ResponseRoleInfo, error) {
|
124
|
func RoleGetOne(param protocol.RequestRoleOne) (*protocol.ResponseRoleInfo, error) {
|
106
|
-
|
125
|
+ // roledata, err := models.GetRoleById(param.RoleID)
|
107
|
return nil, nil
|
126
|
return nil, nil
|
108
|
}
|
127
|
}
|
109
|
|
128
|
|