Browse Source

feat(图谱算法,修改新的算法):碰到大行业时,自动匹配第二层级的行业,如果没有第二层级的行业,那么返回大行业本身

Roc 4 years ago
parent
commit
37e7338c70
1 changed files with 20 additions and 4 deletions
  1. 20 4
      services/industry_map.go

+ 20 - 4
services/industry_map.go

@@ -358,7 +358,9 @@ func GetIndustryMapNameSliceV2(industryName string)(nameSlice []string,err error
 	if len(itemList) <= 0{
 		return
 	}
+
 	industryMapList := make(map[int][]*models.CygxIndustryMapItems)
+	//TODO  这里好像有问题,如果传入行业的话,上面再没有是否只是找到第一个节点判断,那么就会异常抛出
 	for _,item := range itemList{
 		industryMapList[item.Level] = append(industryMapList[item.Level],item)
 	}
@@ -370,8 +372,17 @@ func GetIndustryMapNameSliceV2(industryName string)(nameSlice []string,err error
 	}
 	sort.Ints(sortIndustryList)
 
+
 	//最底层节点的数据集合
 	list := industryMapList[sortIndustryList[0]]
+
+	//如果该数据正好是第一层节点数据,那么需要额外判断下
+	if list[0].ParentId <= 2 {
+		//如果存在第二级,那么就使用该层级
+		if len(sortIndustryList) > 1{
+			list = industryMapList[sortIndustryList[1]]
+		}
+	}
 	//fmt.Println(list)
 	//return
 
@@ -389,8 +400,10 @@ func GetIndustryMapNameSliceV2(industryName string)(nameSlice []string,err error
 			tmpParentSlice,_ = parentTreeToSlice(tree,item,0,tmpParentSlice,hasIdMap)
 			//父节点
 			parentItem := tmpParentSlice[len(tmpParentSlice)-1]
-			hasIdMap[parentItem.IndustryMapId]=""
-			otherChildMapSlice[1] = append(otherChildMapSlice[1],parentItem)
+			if _,ok := hasIdMap[parentItem.IndustryMapId];ok==false{
+				hasIdMap[parentItem.IndustryMapId] = ""
+				otherChildMapSlice[1] = append(otherChildMapSlice[1],parentItem)
+			}
 		}
 	}else{
 		//匹配到单个节点
@@ -407,8 +420,11 @@ func GetIndustryMapNameSliceV2(industryName string)(nameSlice []string,err error
 			tmpParentSlice,_ = parentTreeToSlice(tree,item,0,tmpParentSlice,hasIdMap)
 			//父节点
 			parentItem := tmpParentSlice[len(tmpParentSlice)-1]
-			hasIdMap[parentItem.IndustryMapId]=""
-			otherChildMapSlice[1] = append(otherChildMapSlice[1],parentItem)
+
+			if _,ok := hasIdMap[parentItem.IndustryMapId];ok==false{
+				hasIdMap[parentItem.IndustryMapId] = ""
+				otherChildMapSlice[1] = append(otherChildMapSlice[1],parentItem)
+			}
 
 			//兄弟节点
 			siblingTreeToSliceV2(parentItem,item,hasIdMap,2,otherChildMapSlice)