Преглед на файлове

add:逻辑图只看我显示有效目录

zqbao преди 5 месеца
родител
ревизия
2eb2e6344d
променени са 3 файла, в които са добавени 65 реда и са изтрити 2 реда
  1. 10 1
      controllers/sandbox/sandbox.go
  2. 9 1
      models/sandbox/sandbox_classify.go
  3. 46 0
      services/sandbox/sandbox.go

+ 10 - 1
controllers/sandbox/sandbox.go

@@ -12,8 +12,9 @@ import (
 	sandboxService "eta/eta_api/services/sandbox"
 	"eta/eta_api/utils"
 	"fmt"
-	"github.com/rdlucklib/rdluck_tools/paging"
 	"time"
+
+	"github.com/rdlucklib/rdluck_tools/paging"
 )
 
 // versionSize 版本列表第一页数据约定是:3条
@@ -847,6 +848,14 @@ func (this *SandboxController) SandboxClassifyItems() {
 		//allNodes := sandboxService.HandleNoPermissionSandbox(resp.AllNodes, nil)
 		//resp.AllNodes = allNodes
 
+		nodeAll, err := sandboxService.GetSandboxClassifyByIsShowMe(resp.AllNodes, sandboxClassifyId, this.SysUser.AdminId)
+		if err != nil {
+			br.Msg = "获取失败"
+			br.ErrMsg = "获取数据失败,Err:" + err.Error()
+			return
+		}
+		resp.AllNodes = nodeAll
+
 		br.Ret = 200
 		br.Success = true
 		br.Msg = "获取成功"

+ 9 - 1
models/sandbox/sandbox_classify.go

@@ -2,8 +2,9 @@ package sandbox
 
 import (
 	"fmt"
-	"github.com/beego/beego/v2/client/orm"
 	"time"
+
+	"github.com/beego/beego/v2/client/orm"
 )
 
 type SandboxClassify struct {
@@ -43,6 +44,13 @@ func GetSandboxClassifyAll() (items []*SandboxClassifyItems, err error) {
 	return
 }
 
+func GetSandboxClassifyAllIncludeParent() (items []*SandboxClassifyItems, err error) {
+	o := orm.NewOrmUsingDB("data")
+	sql := ` SELECT * FROM sandbox_classify order by sort asc,sandbox_classify_id asc`
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}
+
 type SandboxClassifyItems struct {
 	SandboxClassifyId   int       `orm:"column(sandbox_classify_id);pk"`
 	SandboxClassifyName string    `description:"分类名称"`

+ 46 - 0
services/sandbox/sandbox.go

@@ -958,3 +958,49 @@ func ReplaceEdbInSandbox(oldEdbInfoId, newEdbInfoId int) (err error) {
 
 	return
 }
+
+func GetSandboxClassifyByIsShowMe(classifyList []*sandbox.SandboxClassifyItems, classifyId, adminId int) (list []*sandbox.SandboxClassifyItems, err error) {
+	sanboxList, err := sandbox.GetSandboxInfoByAdminId(adminId)
+	if err != nil {
+		return
+	}
+	existClassify := make(map[int]struct{})
+	for _, v := range sanboxList {
+		existClassify[v.SandboxClassifyId] = struct{}{}
+	}
+	classifyAll, err := sandbox.GetSandboxClassifyAllIncludeParent()
+	if err != nil {
+		return
+	}
+	classifyTree := sandbodClassifyTree(classifyAll, classifyId)
+	list = GetClassifyListRemoveNoSandbox(classifyTree, existClassify)
+	return
+}
+
+func sandbodClassifyTree(classifyList []*sandbox.SandboxClassifyItems, classifyId int) (list []*sandbox.SandboxClassifyItems) {
+	for _, v := range classifyList {
+		if v.ParentId == classifyId {
+			list = append(list, v)
+			v.Children = sandbodClassifyTree(classifyList, v.SandboxClassifyId)
+		}
+	}
+	return
+}
+
+// GetClassifyListRemoveNoSandbox 去除没有表格的分类
+func GetClassifyListRemoveNoSandbox(classifyList []*sandbox.SandboxClassifyItems, sanboxExistClassifyId map[int]struct{}) []*sandbox.SandboxClassifyItems {
+	res := make([]*sandbox.SandboxClassifyItems, 0)
+	for _, classify := range classifyList {
+		if _, ok := sanboxExistClassifyId[classify.SandboxClassifyId]; ok {
+			classify.Children = []*sandbox.SandboxClassifyItems{}
+			res = append(res, classify)
+			continue
+		}
+		classify.Children = append([]*sandbox.SandboxClassifyItems{}, GetClassifyListRemoveNoSandbox(classify.Children, sanboxExistClassifyId)...)
+		if len(classify.Children) > 0 {
+			classify.Children = []*sandbox.SandboxClassifyItems{}
+			res = append(res, classify)
+		}
+	}
+	return res
+}