sandbox.go 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. package sandbox
  2. import (
  3. "eta/eta_hub/models/sandbox"
  4. )
  5. // ContentStruct 沙盘内容结构体
  6. type ContentStruct struct {
  7. Cells []struct {
  8. Attrs struct {
  9. Line struct {
  10. SourceMarker bool `json:"sourceMarker"`
  11. Stroke string `json:"stroke"`
  12. StrokeDasharray string `json:"strokeDasharray"`
  13. } `json:"line"`
  14. Rect struct {
  15. Fill string `json:"fill"`
  16. Stroke string `json:"stroke"`
  17. StrokeDasharray interface{} `json:"strokeDasharray"`
  18. StrokeWidth int64 `json:"strokeWidth"`
  19. } `json:"rect"`
  20. Text struct {
  21. Fill string `json:"fill"`
  22. FontSize float64 `json:"fontSize"`
  23. FontWeight string `json:"fontWeight"`
  24. LineHeight float64 `json:"lineHeight"`
  25. Text string `json:"text"`
  26. TextWrap struct {
  27. Text string `json:"text"`
  28. Width int64 `json:"width"`
  29. } `json:"textWrap"`
  30. } `json:"text"`
  31. } `json:"attrs"`
  32. Data struct {
  33. Key string `json:"key"`
  34. } `json:"data"`
  35. ID string `json:"id"`
  36. Ports struct {
  37. Groups struct {
  38. Port_bottom struct {
  39. Attrs struct {
  40. Circle struct {
  41. Fill string `json:"fill"`
  42. Magnet bool `json:"magnet"`
  43. R int64 `json:"r"`
  44. Stroke string `json:"stroke"`
  45. StrokeWidth int64 `json:"strokeWidth"`
  46. } `json:"circle"`
  47. } `json:"attrs"`
  48. Position string `json:"position"`
  49. ZIndex int64 `json:"zIndex"`
  50. } `json:"port-bottom"`
  51. Port_left struct {
  52. Attrs struct {
  53. Circle struct {
  54. Fill string `json:"fill"`
  55. Magnet bool `json:"magnet"`
  56. R int64 `json:"r"`
  57. Stroke string `json:"stroke"`
  58. StrokeWidth int64 `json:"strokeWidth"`
  59. } `json:"circle"`
  60. } `json:"attrs"`
  61. Position string `json:"position"`
  62. ZIndex int64 `json:"zIndex"`
  63. } `json:"port-left"`
  64. Port_right struct {
  65. Attrs struct {
  66. Circle struct {
  67. Fill string `json:"fill"`
  68. Magnet bool `json:"magnet"`
  69. R int64 `json:"r"`
  70. Stroke string `json:"stroke"`
  71. StrokeWidth int64 `json:"strokeWidth"`
  72. } `json:"circle"`
  73. } `json:"attrs"`
  74. Position string `json:"position"`
  75. ZIndex int64 `json:"zIndex"`
  76. } `json:"port-right"`
  77. Port_top struct {
  78. Attrs struct {
  79. Circle struct {
  80. Fill string `json:"fill"`
  81. Magnet bool `json:"magnet"`
  82. R int64 `json:"r"`
  83. Stroke string `json:"stroke"`
  84. StrokeWidth int64 `json:"strokeWidth"`
  85. } `json:"circle"`
  86. } `json:"attrs"`
  87. Position string `json:"position"`
  88. ZIndex int64 `json:"zIndex"`
  89. } `json:"port-top"`
  90. } `json:"groups"`
  91. Items []struct {
  92. Group string `json:"group"`
  93. ID string `json:"id"`
  94. } `json:"items"`
  95. } `json:"ports"`
  96. Position struct {
  97. X float64 `json:"x"`
  98. Y float64 `json:"y"`
  99. } `json:"position"`
  100. Shape string `json:"shape"`
  101. Size struct {
  102. Height float64 `json:"height"`
  103. Width float64 `json:"width"`
  104. } `json:"size"`
  105. Source struct {
  106. Cell string `json:"cell"`
  107. Port string `json:"port"`
  108. } `json:"source"`
  109. Target struct {
  110. Cell string `json:"cell"`
  111. Port string `json:"port"`
  112. } `json:"target"`
  113. ZIndex int64 `json:"zIndex"`
  114. } `json:"cells"`
  115. }
  116. type SendBoxNodeData struct {
  117. linkData []SandBoxLinkData `json:"linkData"`
  118. linkFold bool `json:"linkFold"`
  119. }
  120. type SandBoxLinkData struct {
  121. RId string `json:"RId"`
  122. Id int `json:"Id"`
  123. Name string `json:"Name"`
  124. Type int `json:"Type"`
  125. Editing bool `json:"editing"`
  126. DatabaseType int `json:"databaseType"`
  127. DetailParams SandBoxDetailParams `json:"detailParams"`
  128. }
  129. type SandBoxDetailParams struct {
  130. Code string `json:"code"`
  131. Id int `json:"id"`
  132. ClassifyId int `json:"classifyId"`
  133. }
  134. func sandboxClassifyHaveChild(allNode []*sandbox.SandboxClassifyItems, node *sandbox.SandboxClassifyItems) (childs []*sandbox.SandboxClassifyItems, yes bool) {
  135. for _, v := range allNode {
  136. if v.ParentId == node.SandboxClassifyId {
  137. childs = append(childs, v)
  138. }
  139. }
  140. if len(childs) > 0 {
  141. yes = true
  142. }
  143. return
  144. }
  145. func SandboxClassifyItemsMakeTree(allNode []*sandbox.SandboxClassifyItems, node *sandbox.SandboxClassifyItems) {
  146. childs, _ := sandboxClassifyHaveChild(allNode, node) //判断节点是否有子节点并返回
  147. if len(childs) > 0 {
  148. node.Children = append(node.Children, childs[0:]...) //添加子节点
  149. for _, v := range childs { //查询子节点的子节点,并添加到子节点
  150. _, has := sandboxClassifyHaveChild(allNode, v)
  151. if has {
  152. SandboxClassifyItemsMakeTree(allNode, v) //递归添加节点
  153. } else {
  154. childrenArr := make([]*sandbox.SandboxClassifyItems, 0)
  155. v.Children = childrenArr
  156. }
  157. }
  158. } else {
  159. childrenArr := make([]*sandbox.SandboxClassifyItems, 0)
  160. node.Children = childrenArr
  161. }
  162. }
  163. func SandboxClassifyItemsMakeTreeV2(allNode []*sandbox.SandboxClassifyItems, node *sandbox.SandboxClassifyItems) {
  164. childs, _ := sandboxClassifyHaveChildV2(allNode, node) //判断节点是否有子节点并返回
  165. if len(childs) > 0 {
  166. node.Children = append(node.Children, childs[0:]...) //添加子节点
  167. for _, v := range childs { //查询子节点的子节点,并添加到子节点
  168. _, has := sandboxClassifyHaveChildV2(allNode, v)
  169. if has {
  170. SandboxClassifyItemsMakeTreeV2(allNode, v) //递归添加节点
  171. }
  172. }
  173. }
  174. }
  175. func sandboxClassifyHaveChildV2(allNode []*sandbox.SandboxClassifyItems, node *sandbox.SandboxClassifyItems) (childs []*sandbox.SandboxClassifyItems, yes bool) {
  176. for _, v := range allNode {
  177. if v.ParentId == node.SandboxClassifyId && node.SandboxId == 0 {
  178. childs = append(childs, v)
  179. }
  180. }
  181. if len(childs) > 0 {
  182. yes = true
  183. }
  184. return
  185. }