|
@@ -1060,17 +1060,34 @@ RETURN p LIMIT 1
|
|
|
return false, nil, nil
|
|
|
}
|
|
|
|
|
|
-// CheckLegalRelationships 判断提供的企业名单,是否存在投资关系
|
|
|
-func (c *NebulaClient) CheckLegalRelationships(names []string, deep, stype int) (bool, []string, error) {
|
|
|
+type GraphNode struct {
|
|
|
+ Name string `json:"name"`
|
|
|
+}
|
|
|
+
|
|
|
+type GraphLink struct {
|
|
|
+ Source string `json:"source"`
|
|
|
+ Target string `json:"target"`
|
|
|
+ Type string `json:"type"` // 可选字段,比如 "投资"
|
|
|
+}
|
|
|
+
|
|
|
+type GraphResult struct {
|
|
|
+ Nodes []GraphNode `json:"nodes"`
|
|
|
+ Links []GraphLink `json:"links"`
|
|
|
+}
|
|
|
+
|
|
|
+func (c *NebulaClient) CheckLegalRelationships(names []string, deep, stype int) (bool, []string, *GraphResult, error) {
|
|
|
if len(names) < 2 {
|
|
|
- return false, nil, fmt.Errorf("企业数量不足,至少需要两个")
|
|
|
+ return false, nil, nil, fmt.Errorf("企业数量不足,至少需要两个")
|
|
|
}
|
|
|
|
|
|
if deep == 0 {
|
|
|
deep = 1
|
|
|
}
|
|
|
+
|
|
|
var rawPaths []string
|
|
|
var rawNodeLists [][]string
|
|
|
+ nodeSet := make(map[string]struct{})
|
|
|
+ graph := &GraphResult{}
|
|
|
|
|
|
for i := 0; i < len(names); i++ {
|
|
|
start := names[i]
|
|
@@ -1083,23 +1100,17 @@ func (c *NebulaClient) CheckLegalRelationships(names []string, deep, stype int)
|
|
|
}
|
|
|
targetList := strings.Join(targets, ", ")
|
|
|
|
|
|
- query := fmt.Sprintf(`
|
|
|
-USE %s;
|
|
|
-MATCH p=(a:Legal{name:"%s"})-[*1..%d]-(b:Legal)
|
|
|
-WHERE b.Legal.name IN [%s]
|
|
|
-RETURN p LIMIT 1
|
|
|
-`, Table_Space, start, deep, targetList)
|
|
|
+ query := fmt.Sprintf(`USE %s; MATCH p=(a:Legal{name:"%s"})-[*1..%d]-(b:Legal) WHERE b.Legal.name IN [%s] RETURN p LIMIT 1`, Table_Space, start, deep, targetList)
|
|
|
|
|
|
resp, err := c.ExecuteWithReconnect(query)
|
|
|
if err != nil {
|
|
|
- return false, nil, fmt.Errorf("查询失败: %w", err)
|
|
|
+ return false, nil, nil, fmt.Errorf("查询失败: %w", err)
|
|
|
}
|
|
|
-
|
|
|
if resp == nil {
|
|
|
- return false, nil, fmt.Errorf("查询失败,response is nil")
|
|
|
+ return false, nil, nil, fmt.Errorf("查询失败,response is nil")
|
|
|
}
|
|
|
if !resp.IsSucceed() {
|
|
|
- return false, nil, fmt.Errorf("执行失败: %s", resp.GetErrorMsg())
|
|
|
+ return false, nil, nil, fmt.Errorf("执行失败: %s", resp.GetErrorMsg())
|
|
|
}
|
|
|
|
|
|
if resp.GetRowSize() > 0 {
|
|
@@ -1127,6 +1138,14 @@ RETURN p LIMIT 1
|
|
|
builder.WriteString(curName)
|
|
|
nodeNames = append(nodeNames, curName)
|
|
|
|
|
|
+ // 图谱节点添加
|
|
|
+ if curName != "" {
|
|
|
+ if _, ok := nodeSet[curName]; !ok {
|
|
|
+ nodeSet[curName] = struct{}{}
|
|
|
+ graph.Nodes = append(graph.Nodes, GraphNode{Name: curName})
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// 步长处理
|
|
|
for _, step := range path.Steps {
|
|
|
dstName := ""
|
|
@@ -1149,13 +1168,31 @@ RETURN p LIMIT 1
|
|
|
}
|
|
|
builder.WriteString(dstName)
|
|
|
nodeNames = append(nodeNames, dstName)
|
|
|
+
|
|
|
+ // 图谱节点添加
|
|
|
+ if dstName != "" {
|
|
|
+ if _, ok := nodeSet[dstName]; !ok {
|
|
|
+ nodeSet[dstName] = struct{}{}
|
|
|
+ graph.Nodes = append(graph.Nodes, GraphNode{Name: dstName})
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 图谱边添加
|
|
|
+ if curName != "" && dstName != "" {
|
|
|
+ graph.Links = append(graph.Links, GraphLink{
|
|
|
+ Source: curName,
|
|
|
+ Target: dstName,
|
|
|
+ Type: "投资",
|
|
|
+ })
|
|
|
+ }
|
|
|
+ curName = dstName
|
|
|
}
|
|
|
|
|
|
rawPaths = append(rawPaths, builder.String())
|
|
|
rawNodeLists = append(rawNodeLists, nodeNames)
|
|
|
|
|
|
if stype == 0 {
|
|
|
- return true, []string{builder.String()}, nil
|
|
|
+ return true, []string{builder.String()}, graph, nil
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -1190,7 +1227,7 @@ RETURN p LIMIT 1
|
|
|
}
|
|
|
|
|
|
if len(finalPaths) > 0 {
|
|
|
- return true, finalPaths, nil
|
|
|
+ return true, finalPaths, graph, nil
|
|
|
}
|
|
|
- return false, nil, nil
|
|
|
+ return false, nil, nil, nil
|
|
|
}
|