|
@@ -455,34 +455,66 @@ func GetAllGeneralPurviewVMsProcessed(module int) ([]*PurviewTreeViewModel, erro
|
455
|
455
|
return nil, getPurviewErr
|
456
|
456
|
}
|
457
|
457
|
// 加工这些规则:树形化
|
458
|
|
- purviewVMs := make([]*PurviewTreeViewModel, 0)
|
459
|
|
- pid_childs := make(map[int64][]*PurviewTreeViewModel)
|
460
|
|
- for _, purview := range originPurviews {
|
461
|
|
- // warning:下面这个算法只适用最多两层树形结构的菜单,对于两层以上的会丢失掉第三层及其以下的节点
|
462
|
|
- // 因为取出 originPurviews 的时候已经排过序了,所以顶级节点肯定最先处理,不需要担心子节点比父节点先处理
|
|
458
|
+ map1 := make(map[int64]int64)
|
|
459
|
+ map2 := make(map[int64]*PurviewTreeViewModel)
|
|
460
|
+ for _, v := range originPurviews {
|
|
461
|
+ map1[v.Id] = v.Parentid
|
463
|
462
|
pvm := &PurviewTreeViewModel{
|
464
|
|
- ID: purview.Id,
|
465
|
|
- PID: purview.Parentid,
|
466
|
|
- Name: purview.Name,
|
|
463
|
+ ID: v.Id,
|
|
464
|
+ PID: v.Parentid,
|
|
465
|
+ Name: v.Name,
|
467
|
466
|
Number: 2,
|
468
|
467
|
}
|
469
|
|
- if purview.Parentid == 0 {
|
470
|
|
- purviewVMs = append(purviewVMs, pvm)
|
471
|
|
- } else {
|
472
|
|
- childs := pid_childs[purview.Parentid]
|
473
|
|
- if childs == nil {
|
474
|
|
- childs = make([]*PurviewTreeViewModel, 0)
|
|
468
|
+ map2[v.Id] = pvm
|
|
469
|
+ }
|
|
470
|
+ //可以处理多层的菜单
|
|
471
|
+ purviewVMs := Totree(map1, map2, 0)
|
|
472
|
+ //原来的逻辑
|
|
473
|
+ //purviewVMs := make([]*PurviewTreeViewModel, 0)
|
|
474
|
+ //pid_childs := make(map[int64][]*PurviewTreeViewModel)
|
|
475
|
+ //for _, purview := range originPurviews {
|
|
476
|
+ // // warning:下面这个算法只适用最多两层树形结构的菜单,对于两层以上的会丢失掉第三层及其以下的节点
|
|
477
|
+ // // 因为取出 originPurviews 的时候已经排过序了,所以顶级节点肯定最先处理,不需要担心子节点比父节点先处理
|
|
478
|
+ // pvm := &PurviewTreeViewModel{
|
|
479
|
+ // ID: purview.Id,
|
|
480
|
+ // PID: purview.Parentid,
|
|
481
|
+ // Name: purview.Name,
|
|
482
|
+ // Number: 2,
|
|
483
|
+ // }
|
|
484
|
+ // if purview.Parentid == 0 {
|
|
485
|
+ // purviewVMs = append(purviewVMs, pvm)
|
|
486
|
+ // } else {
|
|
487
|
+ // childs := pid_childs[purview.Parentid]
|
|
488
|
+ // if childs == nil {
|
|
489
|
+ // childs = make([]*PurviewTreeViewModel, 0)
|
|
490
|
+ // }
|
|
491
|
+ // childs = append(childs, pvm)
|
|
492
|
+ // pid_childs[purview.Parentid] = childs
|
|
493
|
+ // }
|
|
494
|
+ //}
|
|
495
|
+ //
|
|
496
|
+ //for _, vm := range purviewVMs {
|
|
497
|
+ // vm.Childs = pid_childs[vm.ID]
|
|
498
|
+ //}
|
|
499
|
+
|
|
500
|
+ return purviewVMs, nil
|
|
501
|
+}
|
|
502
|
+func Totree(map1 map[int64]int64, map2 map[int64]*PurviewTreeViewModel, tmp int64) []*PurviewTreeViewModel {
|
|
503
|
+ var j int //用来计数
|
|
504
|
+ var tmp_purview []*PurviewTreeViewModel
|
|
505
|
+ for k, v := range map1 {
|
|
506
|
+ if v == tmp {
|
|
507
|
+ tmp_purview = append(tmp_purview, map2[k])
|
|
508
|
+ delete(map1, k)
|
|
509
|
+ for k1, v1 := range tmp_purview {
|
|
510
|
+ if k1 == j {
|
|
511
|
+ v1.Childs = Totree(map1, map2, k)
|
|
512
|
+ }
|
475
|
513
|
}
|
476
|
|
- childs = append(childs, pvm)
|
477
|
|
- pid_childs[purview.Parentid] = childs
|
|
514
|
+ j++
|
478
|
515
|
}
|
479
|
516
|
}
|
480
|
|
-
|
481
|
|
- for _, vm := range purviewVMs {
|
482
|
|
- vm.Childs = pid_childs[vm.ID]
|
483
|
|
- }
|
484
|
|
-
|
485
|
|
- return purviewVMs, nil
|
|
517
|
+ return tmp_purview
|
486
|
518
|
}
|
487
|
519
|
|
488
|
520
|
func GetAllGeneralFuncPurviewVMsProcessed() ([]*PurviewTreeViewModel, error) {
|