|
@@ -4,6 +4,7 @@ import (
|
4
|
4
|
"XT_New/enums"
|
5
|
5
|
"XT_New/models"
|
6
|
6
|
"XT_New/service"
|
|
7
|
+ "strconv"
|
7
|
8
|
"strings"
|
8
|
9
|
"time"
|
9
|
10
|
)
|
|
@@ -13,12 +14,12 @@ type NewRoleApiController struct {
|
13
|
14
|
}
|
14
|
15
|
|
15
|
16
|
func (this *NewRoleApiController) GetAllOrgUser() {
|
|
17
|
+
|
16
|
18
|
adminUserInfo := this.GetMobileAdminUserInfo()
|
17
|
|
- viewModels, _, _ := service.GetAdminUsersAndLoginInfo(adminUserInfo.Org.Id, adminUserInfo.App.Id, 1, 10)
|
|
19
|
+ viewModels, _, _ := service.GetAllAdminUsersAndRole(adminUserInfo.Org.Id, adminUserInfo.App.Id, 1, 10)
|
18
|
20
|
this.ServeSuccessJSON(map[string]interface{}{
|
19
|
21
|
"admins": viewModels,
|
20
|
22
|
})
|
21
|
|
-
|
22
|
23
|
}
|
23
|
24
|
|
24
|
25
|
func (this *NewRoleApiController) EditAdmin() {
|
|
@@ -145,26 +146,35 @@ func (this *NewRoleApiController) CreateAdminUser() {
|
145
|
146
|
this.ServeSuccessJSON(nil)
|
146
|
147
|
return
|
147
|
148
|
}
|
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)
|
|
149
|
+ } else {
|
|
150
|
+
|
|
151
|
+ total, _ := service.FindAdminUserByID(adminUser.Id, adminUserInfo.Org.Id)
|
|
152
|
+
|
|
153
|
+ if total <= 0 {
|
|
154
|
+ //新增用户
|
|
155
|
+ app_role := &models.App_Role{
|
|
156
|
+ AdminUserId: adminUser.Id,
|
|
157
|
+ OrgId: adminUserInfo.Org.Id,
|
|
158
|
+ AppId: adminUserInfo.App.Id,
|
|
159
|
+ Avatar: "",
|
|
160
|
+ UserName: name,
|
|
161
|
+ UserTitleName: userTitle,
|
|
162
|
+ Status: 1,
|
|
163
|
+ CreateTime: time.Now().Unix(),
|
|
164
|
+ ModifyTime: time.Now().Unix(),
|
|
165
|
+ RoleIds: role_ids,
|
|
166
|
+ }
|
|
167
|
+ err := service.CreateUserRole(app_role)
|
|
168
|
+ if err != nil {
|
|
169
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
|
|
170
|
+ return
|
|
171
|
+ }
|
|
172
|
+ this.ServeSuccessJSON(nil)
|
|
173
|
+ } else {
|
|
174
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRepeatCreateStaffException)
|
165
|
175
|
return
|
166
|
176
|
}
|
167
|
|
- this.ServeSuccessJSON(nil)
|
|
177
|
+
|
168
|
178
|
return
|
169
|
179
|
}
|
170
|
180
|
}
|
|
@@ -186,7 +196,22 @@ func (this *NewRoleApiController) GetAllOrgRole() {
|
186
|
196
|
}
|
187
|
197
|
|
188
|
198
|
func (this *NewRoleApiController) EditRole() {
|
|
199
|
+ role_id, _ := this.GetInt64("id", 0)
|
|
200
|
+ desc := this.GetString("desc")
|
|
201
|
+
|
|
202
|
+ role, _ := service.GetRoleByRoleID(role_id)
|
|
203
|
+
|
|
204
|
+ role.RoleIntro = desc
|
|
205
|
+ role.ModifyTime = time.Now().Unix()
|
189
|
206
|
|
|
207
|
+ err := service.SaveRole(role)
|
|
208
|
+ if err != nil {
|
|
209
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
|
|
210
|
+ }
|
|
211
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
212
|
+ "role": role,
|
|
213
|
+ })
|
|
214
|
+ return
|
190
|
215
|
}
|
191
|
216
|
|
192
|
217
|
func (this *NewRoleApiController) GetOrgRoleInfo() {
|
|
@@ -295,6 +320,70 @@ func (this *NewRoleApiController) GetAllPermission() {
|
295
|
320
|
}
|
296
|
321
|
|
297
|
322
|
func (this *NewRoleApiController) DeleteOrgRole() {
|
298
|
|
- //role_id, _ := this.GetInt64("id", 0)
|
|
323
|
+ roleID, _ := this.GetInt64("role_id")
|
|
324
|
+ enable, _ := this.GetBool("enable")
|
|
325
|
+ if roleID <= 0 {
|
|
326
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
|
|
327
|
+ return
|
|
328
|
+ }
|
|
329
|
+
|
|
330
|
+ adminUserInfo := this.GetMobileAdminUserInfo()
|
|
331
|
+
|
|
332
|
+ role, getRoleErr := service.GetRoleByRoleID(roleID)
|
|
333
|
+ if getRoleErr != nil {
|
|
334
|
+ //beego.Error("获取角色失败:", getRoleErr)
|
|
335
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
|
|
336
|
+ return
|
|
337
|
+ } else if role == nil {
|
|
338
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRoleNotExist)
|
|
339
|
+ return
|
|
340
|
+ }
|
|
341
|
+
|
|
342
|
+ if enable == false {
|
|
343
|
+ if count, _ := service.RoleAdminUserCountTwo(adminUserInfo.Org.Id, adminUserInfo.App.Id, roleID); count != 0 {
|
|
344
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCannotRemoveRole)
|
|
345
|
+ return
|
|
346
|
+ }
|
|
347
|
+ }
|
|
348
|
+
|
|
349
|
+ if enable {
|
|
350
|
+ role.Status = 1
|
|
351
|
+ } else {
|
|
352
|
+ role.Status = 2
|
|
353
|
+ }
|
|
354
|
+ role.ModifyTime = time.Now().Unix()
|
|
355
|
+ saveErr := service.ModifyRole(role)
|
|
356
|
+ if saveErr != nil {
|
|
357
|
+ //beego.Error("修改角色失败:", role.Id, saveErr)
|
|
358
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
|
|
359
|
+ } else {
|
|
360
|
+ this.ServeSuccessJSON(nil)
|
|
361
|
+ }
|
|
362
|
+
|
|
363
|
+}
|
|
364
|
+
|
|
365
|
+func (this *NewRoleApiController) GetRolePurviews() {
|
|
366
|
+ adminUserInfo := this.GetMobileAdminUserInfo()
|
|
367
|
+ role_id, _ := this.GetInt64("id", 0)
|
|
368
|
+ rolePurview, _ := service.GetRoleAndPurviewById(role_id, adminUserInfo.Org.Id, adminUserInfo.App.Id)
|
|
369
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
370
|
+ "role_purview": rolePurview,
|
|
371
|
+ })
|
|
372
|
+}
|
|
373
|
+
|
|
374
|
+func (this *NewRoleApiController) AddRoleStaff() {
|
|
375
|
+ //adminUserInfo := this.GetMobileAdminUserInfo()
|
|
376
|
+ role_id, _ := this.GetInt64("id", 0)
|
|
377
|
+ staff_ids := this.GetString("ids")
|
|
378
|
+ ids := strings.Split(staff_ids, ",")
|
|
379
|
+ for _, item := range ids {
|
|
380
|
+ id, _ := strconv.ParseInt(item, 10, 64)
|
|
381
|
+ role, _ := service.FindAdminUserID(id)
|
|
382
|
+ role.RoleIds = role.RoleIds + "," + strconv.FormatInt(role_id, 10)
|
|
383
|
+ service.SaveAdminUser(&role)
|
|
384
|
+ }
|
|
385
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
386
|
+ "msg": "添加成功",
|
|
387
|
+ })
|
299
|
388
|
|
300
|
389
|
}
|