wcc 3 mēneši atpakaļ
vecāks
revīzija
2855692d9f
4 mainītis faili ar 231 papildinājumiem un 53 dzēšanām
  1. 15 0
      graph/graph_test.go
  2. 63 19
      graph/main.go
  3. 116 0
      graph/yisi.go
  4. 37 34
      updateBidding/main.go

+ 15 - 0
graph/graph_test.go

@@ -63,3 +63,18 @@ func TestFetchLegalByVid(t *testing.T) {
 	res, err := getLegalByVid(session, vid)
 	log.Println(res, err)
 }
+
+// TestFindSuspectInvestRelationsByNames 测试 疑似关系的判断
+func TestFindSuspectInvestRelationsByNames(t *testing.T) {
+	client, err := NewNebulaClient(HostList, UserName, PassWord)
+	if err != nil {
+		log.Fatal("连接失败:", err)
+	}
+	defer client.Close()
+	names := []string{"南雄市宝虹农业开发有限公司", "南雄市龙旭园林景观设计有限公司", "香港豪华国际酒店有限公司", "香港豪华酒店(中国)国际管理有限公司"}
+
+	res, err := client.FindSuspectInvestRelationsByNames(names)
+
+	log.Println(res, err)
+
+}

+ 63 - 19
graph/main.go

@@ -124,15 +124,25 @@ type CheckResponse struct {
 	Msg  string   `json:"msg"`
 }
 
+// SuspectInvestResponse 意思关系返回结果
+type SuspectInvestResponse struct {
+	Code int           `json:"code"`
+	Data []interface{} `json:"data"`
+	Msg  string        `json:"msg"`
+}
+
 func main() {
 
+	handHttp()
+
+	return
 	//dealYS()
 	//dealTsDongShi() //董事高管
 	//log.Println("处理完毕")
 	//return
-	InitMgo() //初始化 MongoDB
+	//InitMgo() //初始化 MongoDB
 	//dealTsGraph() //处理疑似关系图谱
-	dealDsGraph() //处理高管  关系到 图形数据库
+	//dealDsGraph() //处理高管  关系到 图形数据库
 	//---------------//
 	//dda()
 	//dealCompanyBase22()
@@ -140,19 +150,23 @@ func main() {
 	//batchDealGraph() // 迭代es 处理企业数据;
 	//
 
-	log.Println("数据处理完毕!!!!!!!")
-	return
+	//log.Println("数据处理完毕!!!!!!!")
+	//return
 	//-----------------------------------------//
-	//2、封装对外提供的HTTP
-	//session, pool, err := ConnectToNebula(HostList, UserName, PassWord)
+	//3、改造方法,使用连接池,避免session过去//
+	// 初始化 Gin 路由
+	//r := gin.Default()
+	//
+	//client, err := NewNebulaClient(HostList, UserName, PassWord)
 	//if err != nil {
-	//	log.Fatalf("Failed to connect to Nebula Graph: %v", err)
+	//	log.Fatal("连接失败:", err)
 	//}
-	//defer pool.Close()
-	//defer session.Release()
-	//// 初始化 Gin 路由
-	//r := gin.Default()
+	//defer client.Close()
 	//// 注册 POST 接口
+	//// 提供 HTML 页面
+	////r.GET("/legal/graph", func(c *gin.Context) {
+	////	c.HTML(http.StatusOK, "graph.html", nil)
+	////})
 	//r.POST("/check-relations", func(c *gin.Context) {
 	//	var req CheckRequest
 	//	if err := c.ShouldBindJSON(&req); err != nil {
@@ -160,12 +174,12 @@ func main() {
 	//		return
 	//	}
 	//
-	//	has, results, err := CheckLegalRelationships4(session, req.Names, req.Deep, req.Stype)
+	//	has, results, err := client.CheckLegalRelationships(req.Names, req.Deep, req.Stype)
 	//	if err != nil {
 	//		res := CheckResponse{
 	//			Code: -1,
 	//			Data: results,
-	//			Msg:  "请求失败",
+	//			Msg:  "请求失败;" + err.Error(),
 	//		}
 	//		c.JSON(http.StatusInternalServerError, res)
 	//		return
@@ -183,8 +197,12 @@ func main() {
 	//
 	//	c.JSON(http.StatusOK, res)
 	//})
+	//// 启动服务
+	//r.Run(":8080")
+}
 
-	//3、改造方法,使用连接池,避免session过去//
+// handHttp  对外提供 HTTP接口
+func handHttp() {
 	// 初始化 Gin 路由
 	r := gin.Default()
 
@@ -193,11 +211,8 @@ func main() {
 		log.Fatal("连接失败:", err)
 	}
 	defer client.Close()
-	// 注册 POST 接口
-	// 提供 HTML 页面
-	//r.GET("/legal/graph", func(c *gin.Context) {
-	//	c.HTML(http.StatusOK, "graph.html", nil)
-	//})
+
+	//1、投资关系查询
 	r.POST("/check-relations", func(c *gin.Context) {
 		var req CheckRequest
 		if err := c.ShouldBindJSON(&req); err != nil {
@@ -228,6 +243,35 @@ func main() {
 
 		c.JSON(http.StatusOK, res)
 	})
+
+	//2、疑似关系  查询
+	r.POST("/yisi-relations", func(c *gin.Context) {
+		var req CheckRequest
+		if err := c.ShouldBindJSON(&req); err != nil {
+			c.JSON(http.StatusBadRequest, gin.H{"error": "请求参数无效"})
+			return
+		}
+
+		results, err := client.FindSuspectInvestRelationsByNames(req.Names)
+		if err != nil {
+			res := map[string]interface{}{
+				"code": 200,
+				"msg":  "请求失败",
+				"data": err.Error(),
+			}
+			c.JSON(http.StatusInternalServerError, res)
+			return
+		} else {
+			res := map[string]interface{}{
+				"code": 200,
+				"msg":  "请求成功",
+				"data": results,
+			}
+			c.JSON(http.StatusOK, res)
+		}
+
+	})
+	//--------------------------//
 	// 启动服务
 	r.Run(":8080")
 }

+ 116 - 0
graph/yisi.go

@@ -453,3 +453,119 @@ func concatMatchPairs(tmp map[string]interface{}) (string, error) {
 
 	return builder.String(), nil
 }
+
+//-------------------------------------------//
+
+type SuspectInvestRelation struct {
+	FromName string
+	ToName   string
+	Reason   string
+}
+
+func (c *NebulaClient) FindSuspectInvestRelationsByNames(names []string) ([]SuspectInvestRelation, error) {
+	if len(names) == 0 {
+		return nil, nil
+	}
+
+	// 1. 企业名称 -> vid 列表(注意同名问题)
+	var nameList strings.Builder
+	for i, name := range names {
+		nameList.WriteString(fmt.Sprintf("\"%s\"", name))
+		if i < len(names)-1 {
+			nameList.WriteString(", ")
+		}
+	}
+
+	vidQuery := fmt.Sprintf(`
+		USE %s;
+		LOOKUP ON Legal WHERE Legal.name IN [%s] YIELD id(vertex) AS vid, Legal.name AS name
+	`, Table_Space, nameList.String())
+
+	resp, err := c.ExecuteWithReconnect(vidQuery)
+	if err != nil {
+		return nil, err
+	}
+	if !resp.IsSucceed() {
+		return nil, fmt.Errorf("vid lookup failed: %s", resp.GetErrorMsg())
+	}
+
+	nameToVids := make(map[string][]string) // 改成切片
+	vidToName := make(map[string]string)
+	rows := resp.GetRows()
+	for _, row := range rows {
+		vid := row.Values[0].GetSVal()
+		name := row.Values[1].GetSVal()
+		nameToVids[string(name)] = append(nameToVids[string(name)], string(vid))
+		vidToName[string(vid)] = string(name)
+	}
+
+	if len(nameToVids) == 0 {
+		return nil, nil
+	}
+
+	// 2. 用 vid 查询 SuspectInvest 边
+	var vidList strings.Builder
+	i := 0
+	for _, vids := range nameToVids {
+		for _, vid := range vids {
+			vidList.WriteString(fmt.Sprintf("\"%s\"", vid))
+			vidList.WriteString(", ")
+			i++
+		}
+	}
+	vidListStr := strings.TrimSuffix(vidList.String(), ", ") // 去掉最后的逗号
+
+	edgeQuery := fmt.Sprintf(`
+		USE %s;
+		GO FROM %s OVER SuspectInvest
+		YIELD 
+			SuspectInvest._src AS from_id,
+			SuspectInvest._dst AS to_id,
+			SuspectInvest.reason AS reason
+	`, Table_Space, vidListStr)
+
+	resp2, err := c.ExecuteWithReconnect(edgeQuery)
+	if err != nil {
+		return nil, err
+	}
+	if !resp2.IsSucceed() {
+		return nil, fmt.Errorf("edge query failed: %s", resp2.GetErrorMsg())
+	}
+
+	// 3. 解析查询结果,筛选起点和终点都在输入列表里的边
+	vidSet := make(map[string]struct{})
+	for _, vids := range nameToVids {
+		for _, vid := range vids {
+			vidSet[vid] = struct{}{}
+		}
+	}
+
+	existingRelations := make(map[string]struct{}) // 加一层去重
+	var relations []SuspectInvestRelation
+	rows2 := resp2.GetRows()
+	for _, row := range rows2 {
+		fromVid := row.Values[0].GetSVal()
+		toVid := row.Values[1].GetSVal()
+		reason := row.Values[2].GetSVal()
+
+		if _, ok1 := vidSet[string(fromVid)]; ok1 {
+			if _, ok2 := vidSet[string(toVid)]; ok2 {
+				fromName := vidToName[string(fromVid)]
+				toName := vidToName[string(toVid)]
+				key := fromName + "->" + toName
+				if _, exists := existingRelations[key]; exists {
+					continue // 已存在,不要重复加
+				}
+				existingRelations[key] = struct{}{}
+
+				relations = append(relations, SuspectInvestRelation{
+					FromName: fromName,
+					ToName:   toName,
+					Reason:   string(reason),
+				})
+			}
+		}
+	}
+
+	return relations, nil
+}

+ 37 - 34
updateBidding/main.go

@@ -41,13 +41,13 @@ var (
 
 func Init() {
 	MgoB = &mongodb.MongodbSim{
-		MongodbAddr: "172.31.31.202:27081,172.20.45.128:27080",
-		//MongodbAddr: "127.0.0.1:27083",
-		DbName:   "qfw",
-		Size:     10,
-		UserName: "SJZY_RWbid_ES",
-		Password: "SJZY@B4i4D5e6S",
-		//Direct:      true,
+		//MongodbAddr: "172.31.31.202:27081,172.20.45.128:27080",
+		MongodbAddr: "127.0.0.1:27083",
+		DbName:      "qfw",
+		Size:        10,
+		UserName:    "SJZY_RWbid_ES",
+		Password:    "SJZY@B4i4D5e6S",
+		Direct:      true,
 	}
 	MgoB.InitPool()
 
@@ -108,8 +108,8 @@ func Init() {
 
 	//es
 	Es = &elastic.Elastic{
-		//S_esurl: "http://127.0.0.1:19908",
-		S_esurl:  "http://172.17.4.184:19908",
+		S_esurl: "http://127.0.0.1:19908",
+		//S_esurl:  "http://172.17.4.184:19908",
 		I_size:   5,
 		Username: "jybid",
 		Password: "Top2023_JEB01i@31",
@@ -118,8 +118,8 @@ func Init() {
 
 	//es 新集群
 	EsNew = &elastic.Elastic{
-		//S_esurl: "http://127.0.0.1:19905",
-		S_esurl:  "http://172.17.4.184:19905",
+		S_esurl: "http://127.0.0.1:19905",
+		//S_esurl:  "http://172.17.4.184:19905",
 		I_size:   5,
 		Username: "jybid",
 		Password: "Top2023_JEB01i@31",
@@ -197,7 +197,7 @@ func taskRunBidding() {
 	//}
 
 	//selected := map[string]interface{}{"contenthtml": 0, "detail": 0}
-	it := sess.DB("qfw").C("zktest_0401").Find(nil).Select(nil).Iter()
+	it := sess.DB("qfw").C("zktest_0428").Find(nil).Select(nil).Iter()
 
 	fmt.Println("taskRun 开始")
 	count := 0
@@ -222,34 +222,37 @@ func taskRunBidding() {
 		//	update["city"] = ""
 		//}
 		//
-		if district, ok := tmp["district"]; ok && district != nil {
-			if district == "乌拉盖管委会" {
-				update["district"] = "乌拉盖管理区管委会"
-			} else if district == "错那县" {
-				update["district"] = "错那市"
-			} else if district == "河南周口经济开发区" {
-				update["district"] = "周口临港开发区"
-			} else if district == "米林县" {
-				update["district"] = "米林市"
-			}
-
-		}
-
+		//if district, ok := tmp["district"]; ok && district != nil {
+		//	if district == "乌拉盖管委会" {
+		//		update["district"] = "乌拉盖管理区管委会"
+		//	} else if district == "错那县" {
+		//		update["district"] = "错那市"
+		//	} else if district == "河南周口经济开发区" {
+		//		update["district"] = "周口临港开发区"
+		//	} else if district == "米林县" {
+		//		update["district"] = "米林市"
+		//	}
+		//
+		//}
+		//-------------------------------------------//
 		// 2.更新中标单位
-
-		biddingID := util.ObjToString(tmp["id"])
+		//biddingID := util.ObjToString(tmp["id"])
 		////biddingID := mongodb.BsonIdToSId(tmp["_id"])
 		//update["winner"] = ""
 		//update["s_winner"] = ""
-		//
+		//-------------------------------------------//
+		//3. 更新中标金额
+		biddingID := util.ObjToString(tmp["tmpid"])
+		update["bidamount"] = tmp["bidamount"]
+		// 更新 MongoDB + ES
 		if len(update) > 0 {
-			//Mgo.UpdateById("bidding", biddingID, map[string]interface{}{"$set": update})
+			MgoB.UpdateById("bidding", biddingID, map[string]interface{}{"$set": update})
 			//2.es 项目 更新字段
-			err := Es.UpdateDocument("bidding", biddingID, update)
-			err = EsNew.UpdateDocument("bidding", biddingID, update)
-			if err != nil && err.Error() != "Document not updated: noop" {
-				log.Info("bidding es update err", err, biddingID)
-			}
+			//err := Es.UpdateDocument("bidding", biddingID, update)
+			//err = EsNew.UpdateDocument("bidding", biddingID, update)
+			//if err != nil && err.Error() != "Document not updated: noop" {
+			//	log.Info("bidding es update err", err, biddingID)
+			//}
 		}
 
 	}