|
@@ -480,15 +480,15 @@ FETCH PROP ON Legal "%s" YIELD Legal.name;
|
|
|
//2222222222222222//
|
|
|
|
|
|
// CheckLegalRelationships 检查给定企业之间是否存在关系
|
|
|
-func CheckLegalRelationships(session *nebula.Session, names []string, deep int) (bool, string, error) {
|
|
|
+func CheckLegalRelationships(session *nebula.Session, names []string, deep, stype int) (bool, string, error) {
|
|
|
if len(names) < 2 {
|
|
|
return false, "", fmt.Errorf("企业数量不足,至少需要两个")
|
|
|
}
|
|
|
|
|
|
- // 遍历所有企业组合,只要发现有一组之间有关系就返回
|
|
|
+ found := false // 是否找到任意关系
|
|
|
+
|
|
|
for i := 0; i < len(names); i++ {
|
|
|
start := names[i]
|
|
|
-
|
|
|
// 构造剩下的企业列表作为目标
|
|
|
targets := []string{}
|
|
|
for j := 0; j < len(names); j++ {
|
|
@@ -500,11 +500,12 @@ func CheckLegalRelationships(session *nebula.Session, names []string, deep int)
|
|
|
|
|
|
// 构造 nGQL 查询
|
|
|
query := fmt.Sprintf(`
|
|
|
-USE `+Table_Space+`;
|
|
|
- MATCH p=(a:Legal{name:"%s"})-[*1..%d]-(b:Legal)
|
|
|
- WHERE b.Legal.name IN [%s]
|
|
|
- RETURN p LIMIT 1
|
|
|
-`, start, deep, targetList)
|
|
|
+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 := session.Execute(query)
|
|
|
if err != nil {
|
|
@@ -514,14 +515,19 @@ USE `+Table_Space+`;
|
|
|
return false, "", fmt.Errorf("查询执行失败: %s", resp.GetErrorMsg())
|
|
|
}
|
|
|
|
|
|
- //ss := resp.GetRows()
|
|
|
- //log.Println(ss)
|
|
|
- // 有结果表示找到关系
|
|
|
if resp.GetRowSize() > 0 {
|
|
|
- return true, fmt.Sprintf("企业【%s】与其他企业存在关系", start), nil
|
|
|
+ found = true
|
|
|
+ // stype == 0:只要找到一个关系就返回
|
|
|
+ if stype == 0 {
|
|
|
+ return true, "企业之间存在关系", nil
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 所有组合都查完了,没有找到关系
|
|
|
+ // 所有组合查完,判断是否找到关系
|
|
|
+ if found {
|
|
|
+ return true, "企业之间存在关系", nil
|
|
|
+ }
|
|
|
+
|
|
|
return false, "企业之间无关联", nil
|
|
|
}
|