|
@@ -443,6 +443,135 @@ func GetIndustryMapNameSliceV2(industryName string) (nameSlice []string, err err
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+func GetIndustryMapNameSliceV3(industryName string) (nameSlice []string, err error) {
|
|
|
+ nameSlice = append(nameSlice, industryName)
|
|
|
+ tree, err := GetIndustryTree()
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("获取树失败")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ hasIdMap := make(map[int]string)
|
|
|
+ itemList, err := models.GetFirstCygxIndustryListByName(industryName)
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("获取数据失败,", err)
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if len(itemList) <= 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ industryMapList := make(map[int][]*models.CygxIndustryMapItems)
|
|
|
+
|
|
|
+ for _, item := range itemList {
|
|
|
+ industryMapList[item.Level] = append(industryMapList[item.Level], item)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ var sortIndustryList []int
|
|
|
+ for k, _ := range industryMapList {
|
|
|
+ sortIndustryList = append(sortIndustryList, k)
|
|
|
+ }
|
|
|
+ sort.Ints(sortIndustryList)
|
|
|
+
|
|
|
+
|
|
|
+ list := industryMapList[sortIndustryList[0]]
|
|
|
+
|
|
|
+
|
|
|
+ if list[0].ParentId <= 2 {
|
|
|
+
|
|
|
+ if len(sortIndustryList) > 1 {
|
|
|
+ list = industryMapList[sortIndustryList[1]]
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ otherChildMapSlice := map[int][]*models.CygxIndustryMapItems{}
|
|
|
+
|
|
|
+
|
|
|
+ if len(list) > 1 {
|
|
|
+ for _, item := range list {
|
|
|
+ hasIdMap[item.IndustryMapId] = ""
|
|
|
+
|
|
|
+ otherChildMapSlice[0] = append(otherChildMapSlice[0], item)
|
|
|
+
|
|
|
+
|
|
|
+ var tmpParentSlice []*models.CygxIndustryMapItems
|
|
|
+ tmpParentSlice, _ = parentTreeToSlice(tree, item, 0, tmpParentSlice, hasIdMap)
|
|
|
+
|
|
|
+ parentItem := tmpParentSlice[len(tmpParentSlice)-1]
|
|
|
+ if _, ok := hasIdMap[parentItem.IndustryMapId]; ok == false {
|
|
|
+ hasIdMap[parentItem.IndustryMapId] = ""
|
|
|
+ otherChildMapSlice[1] = append(otherChildMapSlice[1], parentItem)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+
|
|
|
+ item := list[0]
|
|
|
+ hasIdMap[item.IndustryMapId] = ""
|
|
|
+
|
|
|
+ otherChildMapSlice[0] = append(otherChildMapSlice[0], item)
|
|
|
+ childTree := getChildTree(tree, item)
|
|
|
+
|
|
|
+
|
|
|
+ if len(childTree.Children) == 0 {
|
|
|
+
|
|
|
+ var tmpParentSlice []*models.CygxIndustryMapItems
|
|
|
+ tmpParentSlice, _ = parentTreeToSlice(tree, item, 0, tmpParentSlice, hasIdMap)
|
|
|
+
|
|
|
+ parentItem := tmpParentSlice[len(tmpParentSlice)-1]
|
|
|
+
|
|
|
+ if _, ok := hasIdMap[parentItem.IndustryMapId]; ok == false {
|
|
|
+ hasIdMap[parentItem.IndustryMapId] = ""
|
|
|
+ otherChildMapSlice[1] = append(otherChildMapSlice[1], parentItem)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ siblingTreeToSliceV2(parentItem, item, hasIdMap, 2, otherChildMapSlice)
|
|
|
+ } else {
|
|
|
+
|
|
|
+ otherChildMapSlice[1] = append(otherChildMapSlice[1], childTree.Children...)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ var tmpSlice []*models.CygxIndustryMapItems
|
|
|
+
|
|
|
+
|
|
|
+ var sortList []int
|
|
|
+ for k, _ := range otherChildMapSlice {
|
|
|
+ sortList = append(sortList, k)
|
|
|
+ }
|
|
|
+ sort.Ints(sortList)
|
|
|
+
|
|
|
+
|
|
|
+ for _, v := range sortList {
|
|
|
+ tmpChildSlice := otherChildMapSlice[v]
|
|
|
+
|
|
|
+ tmpSlice = append(tmpSlice, tmpChildSlice...)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, v := range tmpSlice {
|
|
|
+
|
|
|
+ nameSlice = append(nameSlice, v.IndustryMapName)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
func siblingTreeToSliceV2(rootNode *models.CygxIndustryMapItems, nowNode *models.CygxIndustryMapItems, hasIdMap map[int]string, depth int, otherChildMapSlice map[int][]*models.CygxIndustryMapItems) (maxDepth int) {
|
|
|
if rootNode.Children != nil {
|