|
@@ -1,7 +1,11 @@
|
1
|
1
|
package new_mobile_api_controllers
|
2
|
2
|
|
3
|
3
|
import (
|
|
4
|
+ "XT_New/enums"
|
|
5
|
+ "XT_New/models"
|
4
|
6
|
"XT_New/service"
|
|
7
|
+ "strings"
|
|
8
|
+ "time"
|
5
|
9
|
)
|
6
|
10
|
|
7
|
11
|
type NewRoleApiController struct {
|
|
@@ -17,50 +21,280 @@ func (this *NewRoleApiController) GetAllOrgUser() {
|
17
|
21
|
|
18
|
22
|
}
|
19
|
23
|
|
20
|
|
-
|
21
|
|
-
|
22
|
|
-
|
23
|
|
-
|
24
|
|
-
|
25
|
|
-
|
26
|
|
-
|
27
|
|
-
|
28
|
|
-
|
29
|
|
-
|
30
|
|
-
|
31
|
|
-
|
32
|
|
-
|
33
|
|
-
|
34
|
|
-
|
35
|
|
-
|
36
|
|
-
|
37
|
|
-
|
38
|
|
-
|
39
|
|
-
|
40
|
|
-
|
41
|
|
-
|
42
|
|
-
|
43
|
|
-
|
44
|
|
-
|
45
|
|
-
|
46
|
|
-
|
47
|
|
-
|
48
|
|
-
|
49
|
|
-
|
50
|
|
-
|
51
|
|
-
|
52
|
|
-
|
53
|
|
-
|
54
|
|
-
|
55
|
|
-
|
56
|
|
-
|
57
|
|
-
|
58
|
|
-
|
59
|
|
-
|
60
|
|
-
|
61
|
|
-
|
62
|
|
-
|
63
|
|
-
|
64
|
|
-
|
65
|
|
-
|
66
|
|
-
|
|
24
|
+func (this *NewRoleApiController) EditAdmin() {
|
|
25
|
+ adminUserInfo := this.GetMobileAdminUserInfo()
|
|
26
|
+ adminUserId, _ := this.GetInt64("uid")
|
|
27
|
+ name := this.GetString("name")
|
|
28
|
+ userTitle := this.GetString("title")
|
|
29
|
+ roleIds := this.GetString("role_ids")
|
|
30
|
+ if adminUserId <= 0 || len(name) == 0 || len(roleIds) <= 0 {
|
|
31
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
32
|
+ return
|
|
33
|
+ }
|
|
34
|
+ appRole, getAppRoleErr := service.GetAppRole(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserId)
|
|
35
|
+ if getAppRoleErr != nil {
|
|
36
|
+
|
|
37
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
|
|
38
|
+ return
|
|
39
|
+ }
|
|
40
|
+ if appRole == nil {
|
|
41
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserNotExist)
|
|
42
|
+ return
|
|
43
|
+ }
|
|
44
|
+ appRole.UserName = name
|
|
45
|
+ appRole.UserTitleName = userTitle
|
|
46
|
+ appRole.RoleIds = roleIds
|
|
47
|
+ appRole.ModifyTime = time.Now().Unix()
|
|
48
|
+ saveErr := service.SaveAppRole(appRole)
|
|
49
|
+ if saveErr != nil {
|
|
50
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
|
|
51
|
+ } else {
|
|
52
|
+ this.ServeSuccessJSON(nil)
|
|
53
|
+ }
|
|
54
|
+}
|
|
55
|
+
|
|
56
|
+func (this *NewRoleApiController) GetEditAdminInitData() {
|
|
57
|
+ adminUserInfo := this.GetMobileAdminUserInfo()
|
|
58
|
+ roles, _ := service.GetAllOrgValidRoles(adminUserInfo.Org.Id)
|
|
59
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
60
|
+ "roles": roles,
|
|
61
|
+ })
|
|
62
|
+}
|
|
63
|
+
|
|
64
|
+func (this *NewRoleApiController) GetAdminUserInfo() {
|
|
65
|
+ adminUserInfo := this.GetMobileAdminUserInfo()
|
|
66
|
+ adminUserId, _ := this.GetInt64("uid")
|
|
67
|
+ appRole, getAppRoleErr := service.GetAppRole(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserId)
|
|
68
|
+ if getAppRoleErr != nil {
|
|
69
|
+
|
|
70
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
|
|
71
|
+ return
|
|
72
|
+ }
|
|
73
|
+ if appRole == nil {
|
|
74
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserNotExist)
|
|
75
|
+ return
|
|
76
|
+ }
|
|
77
|
+
|
|
78
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
79
|
+ "user_info": appRole,
|
|
80
|
+ })
|
|
81
|
+
|
|
82
|
+}
|
|
83
|
+
|
|
84
|
+func (this *NewRoleApiController) StopAdminUser() {
|
|
85
|
+ adminUserInfo := this.GetMobileAdminUserInfo()
|
|
86
|
+ adminUserId, _ := this.GetInt64("uid")
|
|
87
|
+ appRole, getAppRoleErr := service.GetAppRole(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserId)
|
|
88
|
+ if getAppRoleErr != nil {
|
|
89
|
+
|
|
90
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
|
|
91
|
+ return
|
|
92
|
+ }
|
|
93
|
+ if appRole == nil {
|
|
94
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserNotExist)
|
|
95
|
+ return
|
|
96
|
+ }
|
|
97
|
+
|
|
98
|
+ enable, _ := this.GetBool("enable")
|
|
99
|
+
|
|
100
|
+ if enable {
|
|
101
|
+ appRole.Status = 1
|
|
102
|
+ } else {
|
|
103
|
+ appRole.Status = 0
|
|
104
|
+ }
|
|
105
|
+ appRole.ModifyTime = time.Now().Unix()
|
|
106
|
+ saveErr := service.SaveAppRole(appRole)
|
|
107
|
+ if saveErr != nil {
|
|
108
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
|
|
109
|
+ } else {
|
|
110
|
+ this.ServeSuccessJSON(nil)
|
|
111
|
+ }
|
|
112
|
+
|
|
113
|
+}
|
|
114
|
+
|
|
115
|
+func (this *NewRoleApiController) CreateAdminUser() {
|
|
116
|
+ adminUserInfo := this.GetMobileAdminUserInfo()
|
|
117
|
+ mobile := this.GetString("mobile")
|
|
118
|
+ name := this.GetString("name")
|
|
119
|
+ role_ids := this.GetString("role_ids")
|
|
120
|
+ userTitle := this.GetString("title")
|
|
121
|
+
|
|
122
|
+ if len(mobile) == 0 || len(name) == 0 || len(role_ids) <= 0 {
|
|
123
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
124
|
+ return
|
|
125
|
+ }
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+ if adminUser, err := service.GetValidAdminUserByMobileReturnErr(mobile); err != nil {
|
|
129
|
+
|
|
130
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
|
|
131
|
+ return
|
|
132
|
+ } else {
|
|
133
|
+ if adminUser == nil {
|
|
134
|
+ _, password, createErr := service.CreateGeneralAdminUser(adminUserInfo.Org.Id, adminUserInfo.App.Id, mobile, name, userTitle, role_ids)
|
|
135
|
+ if createErr != nil {
|
|
136
|
+
|
|
137
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
|
|
138
|
+ return
|
|
139
|
+
|
|
140
|
+ } else {
|
|
141
|
+ sendSMSErr := service.SMSSendInviteMobileToJoinOrgAdmin(name, mobile, password)
|
|
142
|
+ if sendSMSErr != nil {
|
|
143
|
+ }
|
|
144
|
+
|
|
145
|
+ this.ServeSuccessJSON(nil)
|
|
146
|
+ return
|
|
147
|
+ }
|
|
148
|
+ } else {
|
|
149
|
+ app_role := &models.App_Role{
|
|
150
|
+ AdminUserId: adminUser.Id,
|
|
151
|
+ OrgId: adminUserInfo.Org.Id,
|
|
152
|
+ AppId: adminUserInfo.App.Id,
|
|
153
|
+ Avatar: "",
|
|
154
|
+ UserName: name,
|
|
155
|
+ UserTitleName: userTitle,
|
|
156
|
+ Status: 1,
|
|
157
|
+ CreateTime: time.Now().Unix(),
|
|
158
|
+ ModifyTime: time.Now().Unix(),
|
|
159
|
+ RoleIds: role_ids,
|
|
160
|
+ }
|
|
161
|
+
|
|
162
|
+ err := service.CreateUserRole(app_role)
|
|
163
|
+ if err != nil {
|
|
164
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
|
|
165
|
+ return
|
|
166
|
+ }
|
|
167
|
+ this.ServeSuccessJSON(nil)
|
|
168
|
+ return
|
|
169
|
+ }
|
|
170
|
+ }
|
|
171
|
+
|
|
172
|
+}
|
|
173
|
+
|
|
174
|
+func (this *NewRoleApiController) GetAllOrgRole() {
|
|
175
|
+ adminUserInfo := this.GetMobileAdminUserInfo()
|
|
176
|
+ roles, err := service.GetAllOrgValidRoles(adminUserInfo.Org.Id)
|
|
177
|
+ if err != nil {
|
|
178
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
|
|
179
|
+ return
|
|
180
|
+ } else {
|
|
181
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
182
|
+ "roles": roles,
|
|
183
|
+ })
|
|
184
|
+ }
|
|
185
|
+
|
|
186
|
+}
|
|
187
|
+
|
|
188
|
+func (this *NewRoleApiController) EditRole() {
|
|
189
|
+
|
|
190
|
+}
|
|
191
|
+
|
|
192
|
+func (this *NewRoleApiController) GetOrgRoleInfo() {
|
|
193
|
+ role_id, _ := this.GetInt64("id", 0)
|
|
194
|
+ role, err := service.GetRoleByRoleID(role_id)
|
|
195
|
+ if err != nil {
|
|
196
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
|
|
197
|
+ return
|
|
198
|
+ } else {
|
|
199
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
200
|
+ "role": role,
|
|
201
|
+ })
|
|
202
|
+ }
|
|
203
|
+
|
|
204
|
+}
|
|
205
|
+
|
|
206
|
+func (this *NewRoleApiController) CreateRole() {
|
|
207
|
+ adminUserInfo := this.GetMobileAdminUserInfo()
|
|
208
|
+ role_name := this.GetString("name")
|
|
209
|
+ role_desc := this.GetString("desc")
|
|
210
|
+
|
|
211
|
+ role := &models.Role{
|
|
212
|
+ RoleName: role_name,
|
|
213
|
+ RoleIntro: role_desc,
|
|
214
|
+ Creator: adminUserInfo.AdminUser.Id,
|
|
215
|
+ OrgId: adminUserInfo.Org.Id,
|
|
216
|
+ AppId: adminUserInfo.App.Id,
|
|
217
|
+ Status: 1,
|
|
218
|
+ IsSuperAdmin: false,
|
|
219
|
+ CreateTime: time.Now().Unix(),
|
|
220
|
+ ModifyTime: time.Now().Unix(),
|
|
221
|
+ }
|
|
222
|
+
|
|
223
|
+ err := service.CreateOrgRole(role)
|
|
224
|
+ if err != nil {
|
|
225
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
|
|
226
|
+ return
|
|
227
|
+ } else {
|
|
228
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
229
|
+ "role": role,
|
|
230
|
+ })
|
|
231
|
+ }
|
|
232
|
+
|
|
233
|
+}
|
|
234
|
+
|
|
235
|
+func (this *NewRoleApiController) EditRolePermission() {
|
|
236
|
+ role_id, _ := this.GetInt64("id", 0)
|
|
237
|
+ purview_id := this.GetString("purview_id")
|
|
238
|
+ is_open, _ := this.GetInt64("type", 0)
|
|
239
|
+
|
|
240
|
+ permissions, err := service.GetRolePurviewIds(role_id)
|
|
241
|
+ if err != nil {
|
|
242
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
|
|
243
|
+ return
|
|
244
|
+ } else {
|
|
245
|
+
|
|
246
|
+ if is_open == 1 {
|
|
247
|
+ permission_arr := strings.Split(permissions, ",")
|
|
248
|
+ permission_arr = append(permission_arr, purview_id)
|
|
249
|
+ permissions = strings.Join(permission_arr, ",")
|
|
250
|
+
|
|
251
|
+ purview, _ := service.GetRolePurview(role_id)
|
|
252
|
+ purview.PurviewIds = permissions
|
|
253
|
+ err := service.SaveRolePurview(purview)
|
|
254
|
+ if err != nil {
|
|
255
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
|
|
256
|
+ return
|
|
257
|
+ }
|
|
258
|
+
|
|
259
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
260
|
+ "is_open": 1,
|
|
261
|
+ })
|
|
262
|
+
|
|
263
|
+ } else {
|
|
264
|
+
|
|
265
|
+ permission_arr := strings.Split(permissions, ",")
|
|
266
|
+ for index, id := range permission_arr {
|
|
267
|
+ if id == purview_id {
|
|
268
|
+ permission_arr = append(permission_arr[:index], permission_arr[index+1:]...)
|
|
269
|
+ }
|
|
270
|
+ }
|
|
271
|
+ purview, _ := service.GetRolePurview(role_id)
|
|
272
|
+ purview.PurviewIds = strings.Join(permission_arr, ",")
|
|
273
|
+
|
|
274
|
+ err := service.SaveRolePurview(purview)
|
|
275
|
+ if err != nil {
|
|
276
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
|
|
277
|
+ return
|
|
278
|
+ }
|
|
279
|
+
|
|
280
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
281
|
+ "is_open": 0,
|
|
282
|
+ })
|
|
283
|
+
|
|
284
|
+ }
|
|
285
|
+ }
|
|
286
|
+}
|
|
287
|
+
|
|
288
|
+func (this *NewRoleApiController) GetAllPermission() {
|
|
289
|
+ module, _ := this.GetInt64("module")
|
|
290
|
+ parent_id, _ := this.GetInt64("id")
|
|
291
|
+ purviews, _ := service.GetAllPurview(module, parent_id)
|
|
292
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
293
|
+ "purviews": purviews,
|
|
294
|
+ })
|
|
295
|
+}
|
|
296
|
+
|
|
297
|
+func (this *NewRoleApiController) DeleteOrgRole() {
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+}
|