|
@@ -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"
|
|
)
|
|
)
|
|
@@ -56,7 +57,6 @@ func ClueImportTtSync(this *biservice.ClueImportReq) (string, int) {
|
|
<-ch
|
|
<-ch
|
|
}()
|
|
}()
|
|
v["isCompetitors"] = "否"
|
|
v["isCompetitors"] = "否"
|
|
- details := ""
|
|
|
|
id := common.ObjToString(v["id"])
|
|
id := common.ObjToString(v["id"])
|
|
href := common.ObjToString(v["href"])
|
|
href := common.ObjToString(v["href"])
|
|
for _, vv := range strings.Split(competitors, ",") {
|
|
for _, vv := range strings.Split(competitors, ",") {
|
|
@@ -64,39 +64,16 @@ func ClueImportTtSync(this *biservice.ClueImportReq) (string, int) {
|
|
v["isCompetitors"] = "是"
|
|
v["isCompetitors"] = "是"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ delete(v, "temp_id")
|
|
delete(v, "import_pc")
|
|
delete(v, "import_pc")
|
|
delete(v, "projectId")
|
|
delete(v, "projectId")
|
|
- customer_data := BiService.FindOne("customer_data_ttzl", map[string]interface{}{"id": id}, "", "")
|
|
|
|
|
|
+ id_new := common.GetMd5String(fmt.Sprintf("%s_%d", common.ObjToString(v["id"]), common.Int64All(v["multipackage_id"])))
|
|
|
|
+ v["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)
|
|
- msg_id := common.Int64All((*customer_data)["msg_id"])
|
|
|
|
- bok := BiService.Update("customer_data_ttzl", map[string]interface{}{"msg_id": msg_id}, v)
|
|
|
|
- if bok {
|
|
|
|
- //
|
|
|
|
- biddingData, ok := Bidding.FindOne("bidding", map[string]interface{}{"_id": mongodb.StringTOBsonId(id)})
|
|
|
|
- if ok && biddingData != nil && len(*biddingData) > 0 {
|
|
|
|
- details = common.ObjToString((*biddingData)["detail"])
|
|
|
|
- }
|
|
|
|
- //
|
|
|
|
- delete(v, "isCompetitors")
|
|
|
|
- delete(v, "msg_id")
|
|
|
|
- v["_id"] = v["id"]
|
|
|
|
- delete(v, "id")
|
|
|
|
- v["details"] = cleanHTML(details)
|
|
|
|
- if common.ObjToString(v["publishtime"]) != "" {
|
|
|
|
- v["publishtime2"] = common.ObjToString(v["publishtime"])
|
|
|
|
- publishtime, _ := time.ParseInLocation(date.Date_Full_Layout, common.ObjToString(v["publishtime"]), time.Local)
|
|
|
|
- v["publishtime"] = publishtime.UnixMilli()
|
|
|
|
- } else {
|
|
|
|
- delete(v, "publishtime")
|
|
|
|
- }
|
|
|
|
- for k, vv := range v {
|
|
|
|
- if vv == nil {
|
|
|
|
- delete(v, k)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- oks := Es.UpdateNewDoc("ttbid", "ttbid", v)
|
|
|
|
- if oks {
|
|
|
|
|
|
+ if BiService.Update("customer_data_ttzl", map[string]interface{}{"msg_id": common.Int64All((*customer_data)["msg_id"])}, v) {
|
|
|
|
+ if _, ok := CreateEs(v); ok {
|
|
counts++
|
|
counts++
|
|
log.Println("es更新成功", id)
|
|
log.Println("es更新成功", id)
|
|
} else {
|
|
} else {
|
|
@@ -106,34 +83,9 @@ func ClueImportTtSync(this *biservice.ClueImportReq) (string, int) {
|
|
log.Println("tidb更新失败!!", id)
|
|
log.Println("tidb更新失败!!", id)
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- dataId := BiService.Insert("customer_data_ttzl", v)
|
|
|
|
- if dataId > 0 {
|
|
|
|
- //
|
|
|
|
- biddingData, ok := Bidding.FindOne("bidding", map[string]interface{}{"_id": mongodb.StringTOBsonId(id)})
|
|
|
|
- if ok && biddingData != nil && len(*biddingData) > 0 {
|
|
|
|
- details = common.ObjToString((*biddingData)["detail"])
|
|
|
|
- }
|
|
|
|
- //
|
|
|
|
- BiService.Insert("customer_data_ttzl_gl", map[string]interface{}{"msg_id": dataId, "info_id": id, "details": details, "isHistory": "否"})
|
|
|
|
- delete(v, "isCompetitors")
|
|
|
|
- delete(v, "msg_id")
|
|
|
|
- v["_id"] = v["id"]
|
|
|
|
- delete(v, "id")
|
|
|
|
- v["details"] = cleanHTML(details)
|
|
|
|
- if common.ObjToString(v["publishtime"]) != "" {
|
|
|
|
- v["publishtime2"] = common.ObjToString(v["publishtime"])
|
|
|
|
- publishtime, _ := time.ParseInLocation(date.Date_Full_Layout, common.ObjToString(v["publishtime"]), time.Local)
|
|
|
|
- v["publishtime"] = publishtime.UnixMilli()
|
|
|
|
- } else {
|
|
|
|
- delete(v, "publishtime")
|
|
|
|
- }
|
|
|
|
- for k, vv := range v {
|
|
|
|
- if vv == nil {
|
|
|
|
- delete(v, k)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- oks := Es.Save("ttbid", "ttbid", v)
|
|
|
|
- if oks {
|
|
|
|
|
|
+ if dataId := BiService.Insert("customer_data_ttzl", v); dataId > 0 {
|
|
|
|
+ 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 {
|
|
@@ -162,6 +114,54 @@ func ClueImportTtSync(this *biservice.ClueImportReq) (string, int) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+//根据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 := ""
|
|
|
|
+ biddingData, ok := Bidding.FindOne("bidding", map[string]interface{}{"_id": mongodb.StringTOBsonId(common.ObjToString(v["id"]))})
|
|
|
|
+ if ok && biddingData != nil && len(*biddingData) > 0 {
|
|
|
|
+ details = common.ObjToString((*biddingData)["detail"])
|
|
|
|
+ }
|
|
|
|
+ delete(v, "isCompetitors")
|
|
|
|
+ delete(v, "msg_id")
|
|
|
|
+ v["details"] = cleanHTML(details)
|
|
|
|
+ if common.ObjToString(v["publishtime"]) != "" {
|
|
|
|
+ v["publishtime2"] = common.ObjToString(v["publishtime"])
|
|
|
|
+ publishtime, _ := time.ParseInLocation(date.Date_Full_Layout, common.ObjToString(v["publishtime"]), time.Local)
|
|
|
|
+ v["publishtime"] = publishtime.UnixMilli()
|
|
|
|
+ } else {
|
|
|
|
+ delete(v, "publishtime")
|
|
|
|
+ }
|
|
|
|
+ for k, vv := range v {
|
|
|
|
+ if vv == nil {
|
|
|
|
+ delete(v, k)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //
|
|
|
|
+ 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 {
|
|
// 清理HTML标签
|
|
// 清理HTML标签
|
|
htmlRegex := regexp.MustCompile("<[^>]*>")
|
|
htmlRegex := regexp.MustCompile("<[^>]*>")
|