industry_map.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. package services
  2. import (
  3. "fmt"
  4. "hongze/hongze_clpt/models"
  5. "math/rand"
  6. "reflect"
  7. "sort"
  8. "time"
  9. )
  10. func MakeTree(allNode []*models.CygxIndustryMapItems, node *models.CygxIndustryMapItems) {
  11. childs, _ := haveChild(allNode, node) //判断节点是否有子节点并返回
  12. if len(childs) > 0 {
  13. node.Children = append(node.Children, childs[0:]...) //添加子节点
  14. for _, v := range childs { //查询子节点的子节点,并添加到子节点
  15. _, has := haveChild(allNode, v)
  16. if has {
  17. MakeTree(allNode, v) //递归添加节点
  18. }
  19. }
  20. }
  21. }
  22. func haveChild(allNode []*models.CygxIndustryMapItems, node *models.CygxIndustryMapItems) (childs []*models.CygxIndustryMapItems, yes bool) {
  23. for _, v := range allNode {
  24. if v.ParentId == node.IndustryMapId {
  25. childs = append(childs, v)
  26. }
  27. }
  28. if len(childs) > 0 {
  29. yes = true
  30. }
  31. return
  32. }
  33. func GetIndustryMap() {
  34. list, err := models.GetCygxIndustryMapByParentId(0)
  35. if err != nil {
  36. return
  37. }
  38. rootNode := list[0]
  39. allNodes, err := models.GetCygxIndustryMapAll()
  40. if err != nil {
  41. return
  42. }
  43. MakeTree(allNodes, rootNode)
  44. }
  45. func GetIndustryTree() (rootNode *models.CygxIndustryMapItems, err error) {
  46. //fmt.Println("start")
  47. list, err := models.GetCygxIndustryMapByParentId(0)
  48. if err != nil {
  49. return
  50. }
  51. rootNode = list[0]
  52. allNodes, err := models.GetCygxIndustryMapAll()
  53. if err != nil {
  54. return
  55. }
  56. MakeTree(allNodes, rootNode)
  57. //resultJson,err:=json.Marshal(rootNode)
  58. //fmt.Println("Err:",err)
  59. //fmt.Println("allNodes:",string(resultJson))
  60. //utils.FileLog.Info("allNodes:%s",string(resultJson))
  61. //fmt.Println("end")
  62. return
  63. }
  64. //获取对应的层级map
  65. func getMap(tree *models.CygxIndustryMapItems, item *models.CygxIndustryMapItems, hasIdMap map[int]string, otherChildMapSlice map[int][]*models.CygxIndustryMapItems) {
  66. //深度
  67. depth := 1
  68. //获取下级
  69. childTree := getChildTree(tree, item)
  70. depth = childTreeToSlice(childTree, hasIdMap, depth, otherChildMapSlice)
  71. //获取上级
  72. var tmpParentSlice []*models.CygxIndustryMapItems
  73. tmpParentSlice, _ = parentTreeToSlice(tree, item, 0, tmpParentSlice, hasIdMap)
  74. //移除第一个最上级的行业(根节点)
  75. tmpParentSlice = append(tmpParentSlice[:0], tmpParentSlice[1:len(tmpParentSlice)]...)
  76. //切片反转
  77. tmpParentSlice = reverse(tmpParentSlice)
  78. for _, v := range tmpParentSlice {
  79. depth++
  80. if _, ok := hasIdMap[v.IndustryMapId]; ok == false {
  81. otherChildMapSlice[depth] = append(otherChildMapSlice[depth], v)
  82. }
  83. }
  84. //获取同级
  85. //fmt.Println("===============")
  86. depth = siblingTreeToSlice(tree, item, hasIdMap, depth, otherChildMapSlice)
  87. //上级的同级~
  88. /*for _,parentSlice := range tmpParentSlice{
  89. depth = siblingTreeToSlice(tree,parentSlice,hasIdMap,depth,otherChildMapSlice)
  90. }*/
  91. return
  92. }
  93. //获取行业图谱切片
  94. func GetIndustryMapNameSlice(industryName string) (nameSlice []string, err error) {
  95. nameSlice = append(nameSlice, industryName)
  96. tree, err := GetIndustryTree()
  97. if err != nil {
  98. return
  99. }
  100. //已经存在的行业id的map集合
  101. hasIdMap := make(map[int]string)
  102. itemList, err := models.GetFirstCygxIndustryListByName(industryName)
  103. if err != nil {
  104. return
  105. }
  106. //找不到对应的数据
  107. if len(itemList) <= 0 {
  108. return
  109. }
  110. industryMapList := make(map[int][]*models.CygxIndustryMapItems)
  111. for _, item := range itemList {
  112. industryMapList[item.Level] = append(industryMapList[item.Level], item)
  113. }
  114. //将查出来的根节点数据的key取出来,放在切片中,并对该切片做正序排列
  115. var sortIndustryList []int
  116. for k, _ := range industryMapList {
  117. sortIndustryList = append(sortIndustryList, k)
  118. }
  119. sort.Ints(sortIndustryList)
  120. //最底层节点的数据集合
  121. list := industryMapList[sortIndustryList[0]]
  122. otherChildMapSlice := map[int][]*models.CygxIndustryMapItems{}
  123. for _, item := range list {
  124. hasIdMap[item.IndustryMapId] = ""
  125. //将自己的节点给加进去
  126. otherChildMapSlice[0] = append(otherChildMapSlice[0], item)
  127. getMap(tree, item, hasIdMap, otherChildMapSlice)
  128. }
  129. var tmpSlice []*models.CygxIndustryMapItems
  130. //将其他规律数据的key取出来,放在切片中,并对该切片做正序排列
  131. var sortList []int
  132. for k, _ := range otherChildMapSlice {
  133. sortList = append(sortList, k)
  134. }
  135. sort.Ints(sortList)
  136. //遍历该切片,根据下标key获取对应的数据,并插入到主数据中
  137. for _, v := range sortList {
  138. tmpChildSlice := otherChildMapSlice[v]
  139. randSlice(tmpChildSlice)
  140. tmpSlice = append(tmpSlice, tmpChildSlice...)
  141. //fmt.Println(k,"=====")
  142. //for _,tmpV := range otherChildMapSlice[v]{
  143. // fmt.Println(tmpV.IndustryMapName)
  144. //}
  145. }
  146. //名字切片
  147. for _, v := range tmpSlice {
  148. //fmt.Println("k===",k,"=======v=======",v)
  149. nameSlice = append(nameSlice, v.IndustryMapName)
  150. }
  151. //fmt.Println(nameSlice)
  152. //fmt.Println(strings.Join(nameSlice,","))
  153. //utils.FileLog.Info("allNodes:%s",strings.Join(nameSlice,","))
  154. return
  155. }
  156. //切片反转
  157. func reverse(s []*models.CygxIndustryMapItems) []*models.CygxIndustryMapItems {
  158. for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
  159. s[i], s[j] = s[j], s[i]
  160. }
  161. return s
  162. }
  163. //获取当前节点的树
  164. func getChildTree(rootNode *models.CygxIndustryMapItems, nowNode *models.CygxIndustryMapItems) (returnNode *models.CygxIndustryMapItems) {
  165. if rootNode.IndustryMapId == nowNode.IndustryMapId {
  166. returnNode = rootNode
  167. return
  168. }
  169. if rootNode.Children != nil {
  170. for _, v := range rootNode.Children {
  171. if v.IndustryMapId == nowNode.IndustryMapId {
  172. returnNode = v
  173. } else {
  174. returnNode = getChildTree(v, nowNode)
  175. }
  176. if returnNode != nil {
  177. return
  178. }
  179. }
  180. }
  181. return
  182. }
  183. //获取子树V2,与上一个子树规律不一样,因为上级
  184. func childTreeToSlice(rootNode *models.CygxIndustryMapItems, hasIdMap map[int]string, depth int, otherChildMapSlice map[int][]*models.CygxIndustryMapItems) (maxDepth int) {
  185. if rootNode.Children != nil {
  186. depth++
  187. maxDepth = depth
  188. for _, v := range rootNode.Children {
  189. //判断是否已经录入,如果已经录入,那么不处理
  190. if _, ok := hasIdMap[v.IndustryMapId]; ok == false {
  191. otherChildMapSlice[depth] = append(otherChildMapSlice[depth], v)
  192. }
  193. }
  194. for _, v := range rootNode.Children {
  195. //判断是否已经录入,如果已经录入,那么不处理
  196. if _, ok := hasIdMap[v.IndustryMapId]; ok == false {
  197. hasIdMap[v.IndustryMapId] = ""
  198. returnDepth := childTreeToSlice(v, hasIdMap, depth, otherChildMapSlice)
  199. if returnDepth > maxDepth {
  200. maxDepth = returnDepth
  201. }
  202. }
  203. }
  204. }
  205. return maxDepth
  206. }
  207. //获取兄弟级树
  208. func siblingTreeToSlice(rootNode *models.CygxIndustryMapItems, nowNode *models.CygxIndustryMapItems, hasIdMap map[int]string, depth int, otherChildMapSlice map[int][]*models.CygxIndustryMapItems) (maxDepth int) {
  209. if rootNode.Children != nil {
  210. depth++
  211. maxDepth = depth
  212. for _, v := range rootNode.Children {
  213. //如果父级id一致的情况下,那么代表这是兄弟节点或者是自己了
  214. if v.ParentId == nowNode.ParentId {
  215. //判断是否已经录入,如果已经录入,那么不处理
  216. if _, ok := hasIdMap[v.IndustryMapId]; ok == false {
  217. otherChildMapSlice[depth] = append(otherChildMapSlice[depth], v)
  218. returnDepth := childTreeToSlice(v, hasIdMap, depth, otherChildMapSlice)
  219. if returnDepth > maxDepth {
  220. maxDepth = returnDepth
  221. }
  222. }
  223. } else {
  224. returnDepth := siblingTreeToSlice(v, nowNode, hasIdMap, depth, otherChildMapSlice)
  225. if returnDepth > maxDepth {
  226. maxDepth = returnDepth
  227. }
  228. }
  229. }
  230. for _, v := range rootNode.Children {
  231. if v.ParentId == nowNode.ParentId {
  232. if _, ok := hasIdMap[v.IndustryMapId]; ok == false {
  233. hasIdMap[v.IndustryMapId] = ""
  234. }
  235. }
  236. }
  237. }
  238. return
  239. }
  240. //获取上级树
  241. func parentTreeToSlice(rootNode *models.CygxIndustryMapItems, nowNode *models.CygxIndustryMapItems, depth int, tmpReturnSlice []*models.CygxIndustryMapItems, hasIdMap map[int]string) (returnSlice []*models.CygxIndustryMapItems, ok bool) {
  242. if depth != 0 {
  243. returnSlice = tmpReturnSlice
  244. }
  245. depth++
  246. returnSlice = append(returnSlice, rootNode)
  247. //if _,ok := hasIdMap[rootNode.IndustryMapId];ok==false{
  248. // hasIdMap[rootNode.IndustryMapId] = ""
  249. //}
  250. if rootNode.Children != nil {
  251. for _, v := range rootNode.Children {
  252. if v.ParentId == nowNode.ParentId {
  253. ok = true
  254. return
  255. }
  256. returnSlice, ok = parentTreeToSlice(v, nowNode, depth, returnSlice, hasIdMap)
  257. //如果返回的匹配完成,那么不进入下一次循环,直接返回
  258. if ok {
  259. return
  260. }
  261. //一次循环结束后,如果没有匹配上,那么移除临时切片中的数据
  262. returnSlice = append(returnSlice[:0], returnSlice[0:depth]...)
  263. }
  264. }
  265. return
  266. }
  267. //切片乱序
  268. func randSlice(slice []*models.CygxIndustryMapItems) {
  269. rv := reflect.ValueOf(slice)
  270. if rv.Type().Kind() != reflect.Slice {
  271. return
  272. }
  273. length := rv.Len()
  274. if length < 2 {
  275. return
  276. }
  277. swap := reflect.Swapper(slice)
  278. rand.Seed(time.Now().Unix())
  279. for i := length - 1; i >= 0; i-- {
  280. j := rand.Intn(length)
  281. swap(i, j)
  282. }
  283. return
  284. }
  285. //获取行业图谱切片(v2版本,调整时间:2021-03-19 18:02:07)
  286. func GetIndustryMapNameSliceV2(industryName string) (nameSlice []string, err error) {
  287. nameSlice = append(nameSlice, industryName)
  288. tree, err := GetIndustryTree()
  289. if err != nil {
  290. fmt.Println("获取树失败")
  291. return
  292. }
  293. //fmt.Println(tree)
  294. //已经存在的行业id的map集合
  295. hasIdMap := make(map[int]string)
  296. itemList, err := models.GetFirstCygxIndustryListByName(industryName)
  297. if err != nil {
  298. fmt.Println("获取数据失败,", err)
  299. return
  300. }
  301. //找不到对应的数据
  302. if len(itemList) <= 0 {
  303. return
  304. }
  305. industryMapList := make(map[int][]*models.CygxIndustryMapItems)
  306. //TODO 这里好像有问题,如果传入行业的话,上面再没有是否只是找到第一个节点判断,那么就会异常抛出
  307. for _, item := range itemList {
  308. industryMapList[item.Level] = append(industryMapList[item.Level], item)
  309. }
  310. //将查出来的根节点数据的key取出来,放在切片中,并对该切片做正序排列
  311. var sortIndustryList []int
  312. for k, _ := range industryMapList {
  313. sortIndustryList = append(sortIndustryList, k)
  314. }
  315. sort.Ints(sortIndustryList)
  316. //最底层节点的数据集合
  317. list := industryMapList[sortIndustryList[0]]
  318. //如果该数据正好是第一层节点数据,那么需要额外判断下
  319. if list[0].ParentId <= 2 {
  320. //如果存在第二级,那么就使用该层级
  321. if len(sortIndustryList) > 1 {
  322. list = industryMapList[sortIndustryList[1]]
  323. }
  324. }
  325. //fmt.Println(list)
  326. //return
  327. otherChildMapSlice := map[int][]*models.CygxIndustryMapItems{}
  328. //多个节点时,额外处理
  329. if len(list) > 1 {
  330. for _, item := range list {
  331. hasIdMap[item.IndustryMapId] = ""
  332. //将自己的节点给加进去
  333. otherChildMapSlice[0] = append(otherChildMapSlice[0], item)
  334. //获取上级
  335. var tmpParentSlice []*models.CygxIndustryMapItems
  336. tmpParentSlice, _ = parentTreeToSlice(tree, item, 0, tmpParentSlice, hasIdMap)
  337. //父节点
  338. parentItem := tmpParentSlice[len(tmpParentSlice)-1]
  339. if _, ok := hasIdMap[parentItem.IndustryMapId]; ok == false {
  340. hasIdMap[parentItem.IndustryMapId] = ""
  341. otherChildMapSlice[1] = append(otherChildMapSlice[1], parentItem)
  342. }
  343. }
  344. } else {
  345. //匹配到单个节点
  346. item := list[0]
  347. hasIdMap[item.IndustryMapId] = ""
  348. //将自己的节点给加进去
  349. otherChildMapSlice[0] = append(otherChildMapSlice[0], item)
  350. childTree := getChildTree(tree, item)
  351. //如果是命中到最后一层节点
  352. if len(childTree.Children) == 0 {
  353. //获取上级
  354. var tmpParentSlice []*models.CygxIndustryMapItems
  355. tmpParentSlice, _ = parentTreeToSlice(tree, item, 0, tmpParentSlice, hasIdMap)
  356. //父节点
  357. parentItem := tmpParentSlice[len(tmpParentSlice)-1]
  358. if _, ok := hasIdMap[parentItem.IndustryMapId]; ok == false {
  359. hasIdMap[parentItem.IndustryMapId] = ""
  360. otherChildMapSlice[1] = append(otherChildMapSlice[1], parentItem)
  361. }
  362. //兄弟节点
  363. siblingTreeToSliceV2(parentItem, item, hasIdMap, 2, otherChildMapSlice)
  364. } else {
  365. //如果不是命中到最后一层节点
  366. otherChildMapSlice[1] = append(otherChildMapSlice[1], childTree.Children...)
  367. }
  368. }
  369. //return
  370. var tmpSlice []*models.CygxIndustryMapItems
  371. //将其他规律数据的key取出来,放在切片中,并对该切片做正序排列
  372. var sortList []int
  373. for k, _ := range otherChildMapSlice {
  374. sortList = append(sortList, k)
  375. }
  376. sort.Ints(sortList)
  377. //遍历该切片,根据下标key获取对应的数据,并插入到主数据中
  378. for _, v := range sortList {
  379. tmpChildSlice := otherChildMapSlice[v]
  380. randSlice(tmpChildSlice)
  381. tmpSlice = append(tmpSlice, tmpChildSlice...)
  382. //fmt.Println(k,"=====")
  383. //for _,tmpV := range otherChildMapSlice[v]{
  384. // fmt.Println(tmpV.IndustryMapName)
  385. //}
  386. }
  387. //名字切片
  388. for _, v := range tmpSlice {
  389. //fmt.Println("k===",k,"=======v=======",v)
  390. nameSlice = append(nameSlice, v.IndustryMapName)
  391. }
  392. //fmt.Println(nameSlice)
  393. //fmt.Println(strings.Join(nameSlice,","))
  394. //utils.FileLog.Info("allNodes:%s",strings.Join(nameSlice,","))
  395. return
  396. }
  397. //获取行业图谱切片(v3版本,调整时间:2021-04-20 17:23:31,不乱序)
  398. func GetIndustryMapNameSliceV3(industryName string) (nameSlice []string, err error) {
  399. nameSlice = append(nameSlice, industryName)
  400. tree, err := GetIndustryTree()
  401. if err != nil {
  402. fmt.Println("获取树失败")
  403. return
  404. }
  405. //fmt.Println(tree)
  406. //已经存在的行业id的map集合
  407. hasIdMap := make(map[int]string)
  408. itemList, err := models.GetFirstCygxIndustryListByName(industryName)
  409. if err != nil {
  410. fmt.Println("获取数据失败,", err)
  411. return
  412. }
  413. //找不到对应的数据
  414. if len(itemList) <= 0 {
  415. return
  416. }
  417. industryMapList := make(map[int][]*models.CygxIndustryMapItems)
  418. //TODO 这里好像有问题,如果传入行业的话,上面再没有是否只是找到第一个节点判断,那么就会异常抛出
  419. for _, item := range itemList {
  420. industryMapList[item.Level] = append(industryMapList[item.Level], item)
  421. }
  422. //将查出来的根节点数据的key取出来,放在切片中,并对该切片做正序排列
  423. var sortIndustryList []int
  424. for k, _ := range industryMapList {
  425. sortIndustryList = append(sortIndustryList, k)
  426. }
  427. sort.Ints(sortIndustryList)
  428. //最底层节点的数据集合
  429. list := industryMapList[sortIndustryList[0]]
  430. //如果该数据正好是第一层节点数据,那么需要额外判断下
  431. if list[0].ParentId <= 2 {
  432. //如果存在第二级,那么就使用该层级
  433. if len(sortIndustryList) > 1 {
  434. list = industryMapList[sortIndustryList[1]]
  435. }
  436. }
  437. //fmt.Println(list)
  438. //return
  439. otherChildMapSlice := map[int][]*models.CygxIndustryMapItems{}
  440. //多个节点时,额外处理
  441. if len(list) > 1 {
  442. for _, item := range list {
  443. hasIdMap[item.IndustryMapId] = ""
  444. //将自己的节点给加进去
  445. otherChildMapSlice[0] = append(otherChildMapSlice[0], item)
  446. //获取上级
  447. var tmpParentSlice []*models.CygxIndustryMapItems
  448. tmpParentSlice, _ = parentTreeToSlice(tree, item, 0, tmpParentSlice, hasIdMap)
  449. //父节点
  450. parentItem := tmpParentSlice[len(tmpParentSlice)-1]
  451. if _, ok := hasIdMap[parentItem.IndustryMapId]; ok == false {
  452. hasIdMap[parentItem.IndustryMapId] = ""
  453. otherChildMapSlice[1] = append(otherChildMapSlice[1], parentItem)
  454. }
  455. }
  456. } else {
  457. //匹配到单个节点
  458. item := list[0]
  459. hasIdMap[item.IndustryMapId] = ""
  460. //将自己的节点给加进去
  461. otherChildMapSlice[0] = append(otherChildMapSlice[0], item)
  462. childTree := getChildTree(tree, item)
  463. //如果是命中到最后一层节点
  464. if len(childTree.Children) == 0 {
  465. //获取上级
  466. var tmpParentSlice []*models.CygxIndustryMapItems
  467. tmpParentSlice, _ = parentTreeToSlice(tree, item, 0, tmpParentSlice, hasIdMap)
  468. //父节点
  469. parentItem := tmpParentSlice[len(tmpParentSlice)-1]
  470. if _, ok := hasIdMap[parentItem.IndustryMapId]; ok == false {
  471. hasIdMap[parentItem.IndustryMapId] = ""
  472. otherChildMapSlice[1] = append(otherChildMapSlice[1], parentItem)
  473. }
  474. //兄弟节点
  475. siblingTreeToSliceV2(parentItem, item, hasIdMap, 2, otherChildMapSlice)
  476. } else {
  477. //如果不是命中到最后一层节点
  478. otherChildMapSlice[1] = append(otherChildMapSlice[1], childTree.Children...)
  479. }
  480. }
  481. //return
  482. var tmpSlice []*models.CygxIndustryMapItems
  483. //将其他规律数据的key取出来,放在切片中,并对该切片做正序排列
  484. var sortList []int
  485. for k, _ := range otherChildMapSlice {
  486. sortList = append(sortList, k)
  487. }
  488. sort.Ints(sortList)
  489. //遍历该切片,根据下标key获取对应的数据,并插入到主数据中
  490. for _, v := range sortList {
  491. tmpChildSlice := otherChildMapSlice[v]
  492. //randSlice(tmpChildSlice)
  493. tmpSlice = append(tmpSlice, tmpChildSlice...)
  494. //fmt.Println(k,"=====")
  495. //for _,tmpV := range otherChildMapSlice[v]{
  496. // fmt.Println(tmpV.IndustryMapName)
  497. //}
  498. }
  499. //名字切片
  500. for _, v := range tmpSlice {
  501. //fmt.Println("k===",k,"=======v=======",v)
  502. nameSlice = append(nameSlice, v.IndustryMapName)
  503. }
  504. //fmt.Println(nameSlice)
  505. //fmt.Println(strings.Join(nameSlice,","))
  506. //utils.FileLog.Info("allNodes:%s",strings.Join(nameSlice,","))
  507. return
  508. }
  509. //获取兄弟级树
  510. func siblingTreeToSliceV2(rootNode *models.CygxIndustryMapItems, nowNode *models.CygxIndustryMapItems, hasIdMap map[int]string, depth int, otherChildMapSlice map[int][]*models.CygxIndustryMapItems) (maxDepth int) {
  511. if rootNode.Children != nil {
  512. depth++
  513. maxDepth = depth
  514. for _, v := range rootNode.Children {
  515. //如果父级id一致的情况下,那么代表这是兄弟节点或者是自己了
  516. if v.ParentId == nowNode.ParentId {
  517. //判断是否已经录入,如果已经录入,那么不处理
  518. if _, ok := hasIdMap[v.IndustryMapId]; ok == false {
  519. otherChildMapSlice[depth] = append(otherChildMapSlice[depth], v)
  520. hasIdMap[v.IndustryMapId] = ""
  521. }
  522. } else {
  523. returnDepth := siblingTreeToSliceV2(v, nowNode, hasIdMap, depth, otherChildMapSlice)
  524. if returnDepth > maxDepth {
  525. maxDepth = returnDepth
  526. }
  527. }
  528. }
  529. }
  530. return
  531. }
  532. //region数据修复
  533. func FixData() {
  534. tree, err := GetIndustryTree()
  535. if err != nil {
  536. }
  537. models.FixLevelData(tree.IndustryMapId, 1)
  538. fixData(tree, 1)
  539. return
  540. }
  541. func fixData(item *models.CygxIndustryMapItems, depth int) {
  542. depth++
  543. if item.Children == nil {
  544. return
  545. }
  546. for _, v := range item.Children {
  547. models.FixLevelData(v.IndustryMapId, depth)
  548. fixData(v, depth)
  549. }
  550. }
  551. //endregion