package sandbox import ( "eta/eta_hub/models/sandbox" ) // ContentStruct 沙盘内容结构体 type ContentStruct struct { Cells []struct { Attrs struct { Line struct { SourceMarker bool `json:"sourceMarker"` Stroke string `json:"stroke"` StrokeDasharray string `json:"strokeDasharray"` } `json:"line"` Rect struct { Fill string `json:"fill"` Stroke string `json:"stroke"` StrokeDasharray interface{} `json:"strokeDasharray"` StrokeWidth int64 `json:"strokeWidth"` } `json:"rect"` Text struct { Fill string `json:"fill"` FontSize float64 `json:"fontSize"` FontWeight string `json:"fontWeight"` LineHeight float64 `json:"lineHeight"` Text string `json:"text"` TextWrap struct { Text string `json:"text"` Width int64 `json:"width"` } `json:"textWrap"` } `json:"text"` } `json:"attrs"` Data struct { Key string `json:"key"` } `json:"data"` ID string `json:"id"` Ports struct { Groups struct { Port_bottom struct { Attrs struct { Circle struct { Fill string `json:"fill"` Magnet bool `json:"magnet"` R int64 `json:"r"` Stroke string `json:"stroke"` StrokeWidth int64 `json:"strokeWidth"` } `json:"circle"` } `json:"attrs"` Position string `json:"position"` ZIndex int64 `json:"zIndex"` } `json:"port-bottom"` Port_left struct { Attrs struct { Circle struct { Fill string `json:"fill"` Magnet bool `json:"magnet"` R int64 `json:"r"` Stroke string `json:"stroke"` StrokeWidth int64 `json:"strokeWidth"` } `json:"circle"` } `json:"attrs"` Position string `json:"position"` ZIndex int64 `json:"zIndex"` } `json:"port-left"` Port_right struct { Attrs struct { Circle struct { Fill string `json:"fill"` Magnet bool `json:"magnet"` R int64 `json:"r"` Stroke string `json:"stroke"` StrokeWidth int64 `json:"strokeWidth"` } `json:"circle"` } `json:"attrs"` Position string `json:"position"` ZIndex int64 `json:"zIndex"` } `json:"port-right"` Port_top struct { Attrs struct { Circle struct { Fill string `json:"fill"` Magnet bool `json:"magnet"` R int64 `json:"r"` Stroke string `json:"stroke"` StrokeWidth int64 `json:"strokeWidth"` } `json:"circle"` } `json:"attrs"` Position string `json:"position"` ZIndex int64 `json:"zIndex"` } `json:"port-top"` } `json:"groups"` Items []struct { Group string `json:"group"` ID string `json:"id"` } `json:"items"` } `json:"ports"` Position struct { X float64 `json:"x"` Y float64 `json:"y"` } `json:"position"` Shape string `json:"shape"` Size struct { Height float64 `json:"height"` Width float64 `json:"width"` } `json:"size"` Source struct { Cell string `json:"cell"` Port string `json:"port"` } `json:"source"` Target struct { Cell string `json:"cell"` Port string `json:"port"` } `json:"target"` ZIndex int64 `json:"zIndex"` } `json:"cells"` } type SendBoxNodeData struct { linkData []SandBoxLinkData `json:"linkData"` linkFold bool `json:"linkFold"` } type SandBoxLinkData struct { RId string `json:"RId"` Id int `json:"Id"` Name string `json:"Name"` Type int `json:"Type"` Editing bool `json:"editing"` DatabaseType int `json:"databaseType"` DetailParams SandBoxDetailParams `json:"detailParams"` } type SandBoxDetailParams struct { Code string `json:"code"` Id int `json:"id"` ClassifyId int `json:"classifyId"` } func sandboxClassifyHaveChild(allNode []*sandbox.SandboxClassifyItems, node *sandbox.SandboxClassifyItems) (childs []*sandbox.SandboxClassifyItems, yes bool) { for _, v := range allNode { if v.ParentId == node.SandboxClassifyId { childs = append(childs, v) } } if len(childs) > 0 { yes = true } return } func SandboxClassifyItemsMakeTree(allNode []*sandbox.SandboxClassifyItems, node *sandbox.SandboxClassifyItems) { childs, _ := sandboxClassifyHaveChild(allNode, node) //判断节点是否有子节点并返回 if len(childs) > 0 { node.Children = append(node.Children, childs[0:]...) //添加子节点 for _, v := range childs { //查询子节点的子节点,并添加到子节点 _, has := sandboxClassifyHaveChild(allNode, v) if has { SandboxClassifyItemsMakeTree(allNode, v) //递归添加节点 } else { childrenArr := make([]*sandbox.SandboxClassifyItems, 0) v.Children = childrenArr } } } else { childrenArr := make([]*sandbox.SandboxClassifyItems, 0) node.Children = childrenArr } } func SandboxClassifyItemsMakeTreeV2(allNode []*sandbox.SandboxClassifyItems, node *sandbox.SandboxClassifyItems) { childs, _ := sandboxClassifyHaveChildV2(allNode, node) //判断节点是否有子节点并返回 if len(childs) > 0 { node.Children = append(node.Children, childs[0:]...) //添加子节点 for _, v := range childs { //查询子节点的子节点,并添加到子节点 _, has := sandboxClassifyHaveChildV2(allNode, v) if has { SandboxClassifyItemsMakeTreeV2(allNode, v) //递归添加节点 } } } } func sandboxClassifyHaveChildV2(allNode []*sandbox.SandboxClassifyItems, node *sandbox.SandboxClassifyItems) (childs []*sandbox.SandboxClassifyItems, yes bool) { for _, v := range allNode { if v.ParentId == node.SandboxClassifyId && node.SandboxId == 0 { childs = append(childs, v) } } if len(childs) > 0 { yes = true } return }