apple 5 years ago
parent
commit
6c201b376e
2 changed files with 53 additions and 27 deletions
  1. 51 27
      src/service/repair_rule.go
  2. 2 0
      src/util/config.go

+ 51 - 27
src/service/repair_rule.go

@@ -5,6 +5,7 @@ import (
 	"gopkg.in/mgo.v2/bson"
 	"log"
 	qu "qfw/util"
+	"qfw/util/elastic"
 	. "util"
 )
 
@@ -36,6 +37,8 @@ func (jy *RepairRule) RepairEdit() {
 	//contenthtml detail 单独拿出来
 	detail:= qu.ObjToString((*data)["detail"])
 	contenthtml:= qu.ObjToString((*data)["contenthtml"])
+
+
 	jy.T["detail"] = map[string]string{"detail":detail}
 	jy.T["contenthtml"] = map[string]string{"contenthtml":contenthtml}
 	delete(*data,"detail")
@@ -51,6 +54,8 @@ func (jy *RepairRule) RepairDelete() {
 	defer qu.Catch()
 	id := jy.GetString("_id")
 	coll := jy.GetString("coll")
+	souredata, _ := JYMgo.FindById(coll,id,"")//记录当前表的源数据
+
 	log.Println(id,coll)
 	set := bson.M{"_id":qu.StringTOBsonId(id)}
 	b :=JYMgo.Del(coll,set)
@@ -60,17 +65,30 @@ func (jy *RepairRule) RepairDelete() {
 			"rep": b,
 		})
 	}else {
-		//修改es
-		//client := elastic.GetEsConn()
-		//defer elastic.DestoryEsConn(client)
-		//_, err := client.Delete().Index(EsIndex).Type(EsType).Id(id).Refresh(true).Do()
-		//if err != nil {
-		//	log.Println("delete es err:", err)
-		//}
-
-
-		//新增记录
+		//删除es
+		client := elastic.GetEsConn()
+		defer elastic.DestoryEsConn(client)
+		_, err := client.Delete().Index(EsIndex).Type(EsType).Id(id).Refresh(true).Do()
+		if err != nil {
+			log.Println("delete es err:", err)
+		}
 
+		//新增mongo记录
+		count := JYMgo.Count(JyRecord,bson.M{"_id": qu.StringTOBsonId(id)})
+		if count<=0 {
+			log.Println("删除-无记录-新增源数据")
+			(*souredata)["is_exist_type"] = "0"
+			(*souredata)["is_exist_coll"] = coll
+			JYMgo.Update(JyRecord, "", bson.M{"$set": souredata}, true, true)
+		}else {
+			log.Println("删除-有记录-更新数据:",id)
+			set := bson.M{
+				"$set": bson.M{
+					"is_exist_type": "0",
+				},
+			}
+			JYMgo.UpdateById(JyRecord, id, set)
+		}
 
 		jy.ServeJson(map[string]interface{}{
 			"rep": b,
@@ -85,8 +103,10 @@ func (jy *RepairRule) RepairSave() {
 		data := GetPostForm(jy.Request)
 		updata:=qu.ObjToMap(data["data"])
 		coll:=qu.ObjToString(data["coll"])
-		log.Println("当前更新的表:",coll)
 		id := qu.ObjToString((*updata)["_id"])
+		souredata, _ := JYMgo.FindById(coll,id,"")//记录当前表的源数据
+
+
 		query := bson.M{
 			"_id": qu.StringTOBsonId(id),
 		}
@@ -94,24 +114,32 @@ func (jy *RepairRule) RepairSave() {
 
 		//修改mongo
 		rep := JYMgo.Update(coll, query, bson.M{"$set": *updata}, false, true)
-
 		if !rep {
 			jy.ServeJson(map[string]interface{}{
 				"rep": rep,
 			})
 		}else {
-			//修改es
-			//client := elastic.GetEsConn()
-			//defer elastic.DestoryEsConn(client)
-			//_, err := client.Update().Index(EsIndex).Type(EsType).Id(id).Doc(*updata).Refresh(true).Do()
+			//修改es - 更新已存在id
+			client := elastic.GetEsConn()
+			defer elastic.DestoryEsConn(client)
+			_, err := client.Update().Index(EsIndex).Type(EsType).Id(id).Doc(*updata).Refresh(true).Do()
+			if err != nil {
+				log.Println("update es err:", err)
+			}
+
+			//_, err := client.Index().Index(EsIndex).Type(EsType).Id(id).BodyJson(util.ObjToMap(*updata)).Do()
 			//if err != nil {
-			//	log.Println("update es err:", err)
+			//	log.Println("保存到ES出错", err)
 			//}
-
-
-			//新增记录
-
-
+			count := JYMgo.Count(JyRecord,bson.M{"_id": qu.StringTOBsonId(id)})
+			if count<=0 {
+				(*souredata)["is_exist_type"] = "1"
+				(*souredata)["is_exist_coll"] = coll
+				log.Println("更新,无数据,记录源数据")
+				JYMgo.Update(JyRecord, "", bson.M{"$set": souredata}, true, true)
+			}else {
+				log.Println("更新,有数据,已记录")
+			}
 			jy.ServeJson(map[string]interface{}{
 				"rep": rep,
 			})
@@ -126,9 +154,7 @@ func (jy *RepairRule) SearchID() {
 	defer qu.Catch()
 	if jy.Method() == "POST" {
 		id := jy.GetString("_id")
-
-		//先查one 没有在查two 5da3f2c5a5cb26b9b79847fc 5ea7d06c519cb1801b15385b
-		id = "5da3f2c5a5cb26b9b79847fc"
+		//先查one 没有在查two
 		if !bson.IsObjectIdHex(id){
 			jy.ServeJson(map[string]interface{}{
 				"rep":false,
@@ -165,8 +191,6 @@ func (jy *RepairRule) SearchHref() {
 	defer qu.Catch()
 	if jy.Method() == "POST" {
 		href := jy.GetString("href")
-		href = "http://www.chinabidding.com/bidDetail/244286088.html"
-		//href = "http://rfq.ouyeelbuy.com/rfqNotice/bidListInfo?id=3d3e2154-c7a5-11e9-8d47-005056b17e0e"
 		data_one, rep_one := JYMgo.Find(JyCollNameOne, bson.M{"href": href}, nil, nil, false, -1, -1)
 		if !rep_one ||len(*data_one)<=0 {
 			data_two, rep_two := JYMgo.Find(JyCollNameTwo, bson.M{"href": href}, nil, nil, false, -1, -1)

+ 2 - 0
src/util/config.go

@@ -17,6 +17,7 @@ var (
 	PreviewHref     string //数据预览地址
 	JyCollNameOne   string
 	JyCollNameTwo   string
+	JyRecord		string
 )
 
 var (
@@ -63,6 +64,7 @@ func initJYMgo()  {
 	}
 	JyCollNameOne = qu.ObjToString(Sysconfig["jycollname1"])
 	JyCollNameTwo = qu.ObjToString(Sysconfig["jycollname2"])
+	JyRecord = qu.ObjToString(Sysconfig["jyrecord"])
 	JYMgo.InitPool()
 
 }