|
@@ -2,6 +2,7 @@ package service
|
|
|
|
|
|
import (
|
|
import (
|
|
"bytes"
|
|
"bytes"
|
|
|
|
+ "context"
|
|
"database/sql"
|
|
"database/sql"
|
|
"encoding/json"
|
|
"encoding/json"
|
|
"fmt"
|
|
"fmt"
|
|
@@ -17,9 +18,9 @@ import (
|
|
|
|
|
|
"app.yhyue.com/moapp/jybase/mongodb"
|
|
"app.yhyue.com/moapp/jybase/mongodb"
|
|
|
|
|
|
- "app.yhyue.com/moapp/jybase/date"
|
|
|
|
-
|
|
|
|
common "app.yhyue.com/moapp/jybase/common"
|
|
common "app.yhyue.com/moapp/jybase/common"
|
|
|
|
+ "app.yhyue.com/moapp/jybase/date"
|
|
|
|
+ "app.yhyue.com/moapp/jybase/es"
|
|
. "bp.jydev.jianyu360.cn/BaseService/biService/entity"
|
|
. "bp.jydev.jianyu360.cn/BaseService/biService/entity"
|
|
"bp.jydev.jianyu360.cn/BaseService/biService/rpc/biservice"
|
|
"bp.jydev.jianyu360.cn/BaseService/biService/rpc/biservice"
|
|
)
|
|
)
|
|
@@ -66,13 +67,13 @@ func ClueImportTtSync(this *biservice.ClueImportReq) (string, int) {
|
|
delete(v, "temp_id")
|
|
delete(v, "temp_id")
|
|
delete(v, "import_pc")
|
|
delete(v, "import_pc")
|
|
delete(v, "projectId")
|
|
delete(v, "projectId")
|
|
- id_new := common.GetMd5String(fmt.Sprintf("%s_%s", common.ObjToString(v["id"]), common.ObjToString(v["multipackage_id"])))
|
|
|
|
|
|
+ id_new := common.GetMd5String(fmt.Sprintf("%s_%d", common.ObjToString(v["id"]), common.Int64All(v["multipackage_id"])))
|
|
v["id_new"] = id_new
|
|
v["id_new"] = id_new
|
|
customer_data := BiService.FindOne("customer_data_ttzl", map[string]interface{}{"id_new": id_new}, "", "")
|
|
customer_data := BiService.FindOne("customer_data_ttzl", map[string]interface{}{"id_new": id_new}, "", "")
|
|
if customer_data != nil {
|
|
if customer_data != nil {
|
|
log.Println("数据重复", id)
|
|
log.Println("数据重复", id)
|
|
if BiService.Update("customer_data_ttzl", map[string]interface{}{"msg_id": common.Int64All((*customer_data)["msg_id"])}, v) {
|
|
if BiService.Update("customer_data_ttzl", map[string]interface{}{"msg_id": common.Int64All((*customer_data)["msg_id"])}, v) {
|
|
- if _, nv := getEsV(id, v); Es.UpdateNewDoc("ttbid", "ttbid", nv) {
|
|
|
|
|
|
+ if _, ok := CreateEs(v); ok {
|
|
counts++
|
|
counts++
|
|
log.Println("es更新成功", id)
|
|
log.Println("es更新成功", id)
|
|
} else {
|
|
} else {
|
|
@@ -83,10 +84,8 @@ func ClueImportTtSync(this *biservice.ClueImportReq) (string, int) {
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
if dataId := BiService.Insert("customer_data_ttzl", v); dataId > 0 {
|
|
if dataId := BiService.Insert("customer_data_ttzl", v); dataId > 0 {
|
|
- details, nv := getEsV(id, v)
|
|
|
|
- //
|
|
|
|
- BiService.Insert("customer_data_ttzl_gl", map[string]interface{}{"msg_id": dataId, "info_id": id, "details": details, "isHistory": "否"})
|
|
|
|
- if Es.Save("ttbid", "ttbid", nv) {
|
|
|
|
|
|
+ if details, ok := CreateEs(v); ok {
|
|
|
|
+ BiService.Insert("customer_data_ttzl_gl", map[string]interface{}{"msg_id": dataId, "info_id": id, "details": details, "isHistory": "否"})
|
|
counts++
|
|
counts++
|
|
log.Println("es存入成功", id)
|
|
log.Println("es存入成功", id)
|
|
} else {
|
|
} else {
|
|
@@ -115,16 +114,26 @@ func ClueImportTtSync(this *biservice.ClueImportReq) (string, int) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-func getEsV(id string, v map[string]interface{}) (string, map[string]interface{}) {
|
|
|
|
|
|
+//根据id重新生成es
|
|
|
|
+func CreateEsById(newId string) bool {
|
|
|
|
+ data := BiService.FindOne("customer_data_ttzl", map[string]interface{}{"id_new": newId}, "", "")
|
|
|
|
+ if data == nil || len(*data) == 0 {
|
|
|
|
+ log.Println("没有找到该数据", newId)
|
|
|
|
+ return false
|
|
|
|
+ }
|
|
|
|
+ _, ok := CreateEs(*data)
|
|
|
|
+ return ok
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+//重新生成es
|
|
|
|
+func CreateEs(v map[string]interface{}) (string, bool) {
|
|
details := ""
|
|
details := ""
|
|
- biddingData, ok := Bidding.FindOne("bidding", map[string]interface{}{"_id": mongodb.StringTOBsonId(id)})
|
|
|
|
|
|
+ biddingData, ok := Bidding.FindOne("bidding", map[string]interface{}{"_id": mongodb.StringTOBsonId(common.ObjToString(v["id"]))})
|
|
if ok && biddingData != nil && len(*biddingData) > 0 {
|
|
if ok && biddingData != nil && len(*biddingData) > 0 {
|
|
details = common.ObjToString((*biddingData)["detail"])
|
|
details = common.ObjToString((*biddingData)["detail"])
|
|
}
|
|
}
|
|
delete(v, "isCompetitors")
|
|
delete(v, "isCompetitors")
|
|
delete(v, "msg_id")
|
|
delete(v, "msg_id")
|
|
- v["_id"] = v["id"]
|
|
|
|
- delete(v, "id")
|
|
|
|
v["details"] = cleanHTML(details)
|
|
v["details"] = cleanHTML(details)
|
|
if common.ObjToString(v["publishtime"]) != "" {
|
|
if common.ObjToString(v["publishtime"]) != "" {
|
|
v["publishtime2"] = common.ObjToString(v["publishtime"])
|
|
v["publishtime2"] = common.ObjToString(v["publishtime"])
|
|
@@ -138,7 +147,19 @@ func getEsV(id string, v map[string]interface{}) (string, map[string]interface{}
|
|
delete(v, k)
|
|
delete(v, k)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- return details, v
|
|
|
|
|
|
+ //
|
|
|
|
+ esV7 := Es.(*es.EsV7)
|
|
|
|
+ client := esV7.GetEsConn()
|
|
|
|
+ defer esV7.DestoryEsConn(client)
|
|
|
|
+ newId := common.ObjToString(v["id_new"])
|
|
|
|
+ client.Delete().Index("ttbid").Id(newId).Do(context.TODO())
|
|
|
|
+ _, err := client.Index().Index("ttbid").Id(newId).BodyJson(v).Do(context.TODO())
|
|
|
|
+ if err != nil {
|
|
|
|
+ log.Println("保存到ES出错", err.Error())
|
|
|
|
+ return details, false
|
|
|
|
+ } else {
|
|
|
|
+ return details, true
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
func cleanHTML(htmlString string) string {
|
|
func cleanHTML(htmlString string) string {
|