|
@@ -4,6 +4,7 @@ import (
|
4
|
4
|
"XT_New/enums"
|
5
|
5
|
"XT_New/models"
|
6
|
6
|
"XT_New/service"
|
|
7
|
+ "fmt"
|
7
|
8
|
"strconv"
|
8
|
9
|
"strings"
|
9
|
10
|
"time"
|
|
@@ -257,59 +258,6 @@ func (this *NewRoleApiController) CreateRole() {
|
257
|
258
|
|
258
|
259
|
}
|
259
|
260
|
|
260
|
|
-func (this *NewRoleApiController) EditRolePermission() {
|
261
|
|
- role_id, _ := this.GetInt64("id", 0)
|
262
|
|
- purview_id := this.GetString("purview_id")
|
263
|
|
- is_open, _ := this.GetInt64("type", 0)
|
264
|
|
-
|
265
|
|
- permissions, err := service.GetRolePurviewIds(role_id)
|
266
|
|
- if err != nil {
|
267
|
|
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
|
268
|
|
- return
|
269
|
|
- } else {
|
270
|
|
-
|
271
|
|
- if is_open == 1 { //打开
|
272
|
|
- permission_arr := strings.Split(permissions, ",")
|
273
|
|
- permission_arr = append(permission_arr, purview_id)
|
274
|
|
- permissions = strings.Join(permission_arr, ",")
|
275
|
|
- //插入数据库
|
276
|
|
- purview, _ := service.GetRolePurview(role_id)
|
277
|
|
- purview.PurviewIds = permissions
|
278
|
|
- err := service.SaveRolePurview(purview)
|
279
|
|
- if err != nil {
|
280
|
|
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
|
281
|
|
- return
|
282
|
|
- }
|
283
|
|
-
|
284
|
|
- this.ServeSuccessJSON(map[string]interface{}{
|
285
|
|
- "is_open": 1,
|
286
|
|
- })
|
287
|
|
-
|
288
|
|
- } else { //关闭
|
289
|
|
-
|
290
|
|
- permission_arr := strings.Split(permissions, ",")
|
291
|
|
- for index, id := range permission_arr {
|
292
|
|
- if id == purview_id {
|
293
|
|
- permission_arr = append(permission_arr[:index], permission_arr[index+1:]...)
|
294
|
|
- }
|
295
|
|
- }
|
296
|
|
- purview, _ := service.GetRolePurview(role_id)
|
297
|
|
- purview.PurviewIds = strings.Join(permission_arr, ",")
|
298
|
|
-
|
299
|
|
- err := service.SaveRolePurview(purview)
|
300
|
|
- if err != nil {
|
301
|
|
- this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
|
302
|
|
- return
|
303
|
|
- }
|
304
|
|
-
|
305
|
|
- this.ServeSuccessJSON(map[string]interface{}{
|
306
|
|
- "is_open": 0,
|
307
|
|
- })
|
308
|
|
-
|
309
|
|
- }
|
310
|
|
- }
|
311
|
|
-}
|
312
|
|
-
|
313
|
261
|
func (this *NewRoleApiController) GetAllPermission() {
|
314
|
262
|
module, _ := this.GetInt64("module")
|
315
|
263
|
parent_id, _ := this.GetInt64("id")
|
|
@@ -396,3 +344,207 @@ func (this *NewRoleApiController) GetFuntionPurviews() {
|
396
|
344
|
"funtion_purview": functionPurview,
|
397
|
345
|
})
|
398
|
346
|
}
|
|
347
|
+
|
|
348
|
+func RemoveRepeatedIDSElement(arr []string) (newArr []string) {
|
|
349
|
+ newArr = make([]string, 0)
|
|
350
|
+ for i := 0; i < len(arr); i++ {
|
|
351
|
+ repeat := false
|
|
352
|
+ for j := i + 1; j < len(arr); j++ {
|
|
353
|
+ if arr[i] == arr[j] {
|
|
354
|
+ repeat = true
|
|
355
|
+ break
|
|
356
|
+ }
|
|
357
|
+ }
|
|
358
|
+ if !repeat {
|
|
359
|
+ newArr = append(newArr, arr[i])
|
|
360
|
+ }
|
|
361
|
+ }
|
|
362
|
+ return
|
|
363
|
+}
|
|
364
|
+
|
|
365
|
+func (this *NewRoleApiController) EditRolePermission() {
|
|
366
|
+ adminUser := this.GetMobileAdminUserInfo()
|
|
367
|
+ role_id, _ := this.GetInt64("id", 0)
|
|
368
|
+ purview_id := this.GetString("purview_id")
|
|
369
|
+ is_open, _ := this.GetInt64("type", 0)
|
|
370
|
+
|
|
371
|
+ permissions, err := service.GetRolePurviewIds(role_id)
|
|
372
|
+ if err != nil {
|
|
373
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
|
|
374
|
+ return
|
|
375
|
+ } else {
|
|
376
|
+
|
|
377
|
+ if is_open == 1 { //打开
|
|
378
|
+ purview, _ := service.GetRolePurview(role_id)
|
|
379
|
+ if purview.Id == 0 { // 新建
|
|
380
|
+
|
|
381
|
+ purview.PurviewIds = purview_id
|
|
382
|
+ purview.CreateTime = time.Now().Unix()
|
|
383
|
+ purview.ModifyTime = time.Now().Unix()
|
|
384
|
+ purview.Status = 1
|
|
385
|
+ purview.RoleId = role_id
|
|
386
|
+ purview.OrgId = adminUser.Org.Id
|
|
387
|
+ purview.AppId = adminUser.App.Id
|
|
388
|
+ err := service.CreateRolePurview(&purview)
|
|
389
|
+ if err != nil {
|
|
390
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
|
|
391
|
+ return
|
|
392
|
+ }
|
|
393
|
+
|
|
394
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
395
|
+ "is_open": 1,
|
|
396
|
+ })
|
|
397
|
+
|
|
398
|
+ } else { //修改
|
|
399
|
+ var permission_arr []string
|
|
400
|
+ purview, _ := service.GetRolePurview(role_id)
|
|
401
|
+ if len(permissions) > 0 {
|
|
402
|
+ permission_arr = strings.Split(permissions, ",")
|
|
403
|
+ if len(purview_id) > 0 {
|
|
404
|
+ permission_arr = append(permission_arr, strings.Split(purview_id, ",")...)
|
|
405
|
+ }
|
|
406
|
+ } else {
|
|
407
|
+ if len(purview_id) > 0 {
|
|
408
|
+ permission_arr = strings.Split(purview_id, ",")
|
|
409
|
+ }
|
|
410
|
+ }
|
|
411
|
+
|
|
412
|
+ permission_arr = RemoveRepeatedIDSElement(permission_arr)
|
|
413
|
+ permissions = strings.Join(permission_arr, ",")
|
|
414
|
+ purview.PurviewIds = permissions
|
|
415
|
+ err := service.SaveRolePurview(&purview)
|
|
416
|
+ if err != nil {
|
|
417
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
|
|
418
|
+ return
|
|
419
|
+ }
|
|
420
|
+
|
|
421
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
422
|
+ "is_open": 1,
|
|
423
|
+ })
|
|
424
|
+
|
|
425
|
+ }
|
|
426
|
+
|
|
427
|
+ } else { //关闭
|
|
428
|
+ permission_arr := strings.Split(permissions, ",")
|
|
429
|
+ purview_arr := strings.Split(purview_id, ",")
|
|
430
|
+
|
|
431
|
+ for _, pur_id := range purview_arr {
|
|
432
|
+ for index, id := range permission_arr {
|
|
433
|
+ if id == pur_id {
|
|
434
|
+ permission_arr = append(permission_arr[:index], permission_arr[index+1:]...)
|
|
435
|
+ }
|
|
436
|
+ }
|
|
437
|
+ }
|
|
438
|
+ purview, _ := service.GetRolePurview(role_id)
|
|
439
|
+ fmt.Println(purview.CreateTime)
|
|
440
|
+ purview.PurviewIds = strings.Join(permission_arr, ",")
|
|
441
|
+
|
|
442
|
+ err := service.SaveRolePurview(&purview)
|
|
443
|
+ if err != nil {
|
|
444
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
|
|
445
|
+ return
|
|
446
|
+ }
|
|
447
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
448
|
+ "is_open": 0,
|
|
449
|
+ })
|
|
450
|
+
|
|
451
|
+ }
|
|
452
|
+ }
|
|
453
|
+
|
|
454
|
+}
|
|
455
|
+
|
|
456
|
+func (this *NewRoleApiController) EditFunctionPermission() {
|
|
457
|
+ adminUser := this.GetMobileAdminUserInfo()
|
|
458
|
+ role_id, _ := this.GetInt64("id", 0)
|
|
459
|
+ purview_id := this.GetString("purview_id")
|
|
460
|
+ is_open, _ := this.GetInt64("type", 0)
|
|
461
|
+
|
|
462
|
+ permissions, err := service.GetRoleFuncPurviewIds(role_id)
|
|
463
|
+
|
|
464
|
+ if err != nil {
|
|
465
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
|
|
466
|
+ return
|
|
467
|
+ } else {
|
|
468
|
+
|
|
469
|
+ if is_open == 1 { //打开
|
|
470
|
+ purview, _ := service.GetFuncRolePurview(role_id)
|
|
471
|
+ if purview.ID == 0 { // 新建
|
|
472
|
+
|
|
473
|
+ purview.PurviewIds = purview_id
|
|
474
|
+ purview.Ctime = time.Now().Unix()
|
|
475
|
+ purview.Mtime = time.Now().Unix()
|
|
476
|
+ purview.Status = 1
|
|
477
|
+ purview.RoleId = role_id
|
|
478
|
+ purview.OrgId = adminUser.Org.Id
|
|
479
|
+ purview.AppId = adminUser.App.Id
|
|
480
|
+ err := service.CreateFuncRolePurview(&purview)
|
|
481
|
+ if err != nil {
|
|
482
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
|
|
483
|
+ return
|
|
484
|
+ }
|
|
485
|
+
|
|
486
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
487
|
+ "is_open": 1,
|
|
488
|
+ })
|
|
489
|
+ } else { //修改
|
|
490
|
+ var permission_arr []string
|
|
491
|
+ purview, _ := service.GetRoleFuncPurview(role_id)
|
|
492
|
+ if len(permissions) > 0 {
|
|
493
|
+ permission_arr = strings.Split(permissions, ",")
|
|
494
|
+ if len(purview_id) > 0 {
|
|
495
|
+ permission_arr = append(permission_arr, strings.Split(purview_id, ",")...)
|
|
496
|
+ }
|
|
497
|
+ } else {
|
|
498
|
+ if len(purview_id) > 0 {
|
|
499
|
+ permission_arr = strings.Split(purview_id, ",")
|
|
500
|
+ }
|
|
501
|
+ }
|
|
502
|
+ permission_arr = RemoveRepeatedIDSElement(permission_arr)
|
|
503
|
+ permissions = strings.Join(permission_arr, ",")
|
|
504
|
+ purview.PurviewIds = permissions
|
|
505
|
+
|
|
506
|
+ err := service.SaveRoleFuncPurview(&purview)
|
|
507
|
+ if err != nil {
|
|
508
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
|
|
509
|
+ return
|
|
510
|
+ }
|
|
511
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
512
|
+ "is_open": 1,
|
|
513
|
+ })
|
|
514
|
+ }
|
|
515
|
+ } else { //关闭
|
|
516
|
+ permission_arr := strings.Split(permissions, ",")
|
|
517
|
+ purview_arr := strings.Split(purview_id, ",")
|
|
518
|
+
|
|
519
|
+ for index, id := range permission_arr {
|
|
520
|
+ for _, pur_id := range purview_arr {
|
|
521
|
+ if id == pur_id {
|
|
522
|
+ permission_arr = append(permission_arr[:index], permission_arr[index+1:]...)
|
|
523
|
+ }
|
|
524
|
+ }
|
|
525
|
+ }
|
|
526
|
+ purview, _ := service.GetRoleFuncPurview(role_id)
|
|
527
|
+ purview.PurviewIds = strings.Join(permission_arr, ",")
|
|
528
|
+
|
|
529
|
+ err := service.SaveRoleFuncPurview(&purview)
|
|
530
|
+ if err != nil {
|
|
531
|
+ this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
|
|
532
|
+ return
|
|
533
|
+ }
|
|
534
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
535
|
+ "is_open": 0,
|
|
536
|
+ })
|
|
537
|
+
|
|
538
|
+ }
|
|
539
|
+ }
|
|
540
|
+
|
|
541
|
+}
|
|
542
|
+
|
|
543
|
+func (this *NewRoleApiController) GetFuncRolePurviews() {
|
|
544
|
+ //adminUserInfo := this.GetMobileAdminUserInfo()
|
|
545
|
+ role_id, _ := this.GetInt64("id", 0)
|
|
546
|
+ purview, _ := service.GetRoleFuncPurview(role_id)
|
|
547
|
+ this.ServeSuccessJSON(map[string]interface{}{
|
|
548
|
+ "role_purview": purview,
|
|
549
|
+ })
|
|
550
|
+}
|