fengweiqiang 4 жил өмнө
parent
commit
7bc95b07b6

+ 1 - 1
standardata/src/config.json

@@ -9,7 +9,7 @@
   "mgoentsize":5,
   "mgoentdb":"mxs",
   "extractcoll":"extract",
-  "extractdb": "extract_kf",
+  "extractdb": "extract_v3xs",
   "versioncoll": "tagdetailinfo",
   "extractversion": "V3.1.2",
   "standardata":{

+ 40 - 28
standardata/src/standaragency.go

@@ -38,7 +38,7 @@ func agencyStandarData(db string, query map[string]interface{}) {
 		agencytel := qu.ObjToString(tmp["agencytel"])
 		if entid == "" { //redis 未存
 			savetoerr := true
-			if agencytel != "" {
+			if agencytel != "" || agencyperson != "" {
 				v := map[string]interface{}{
 					"contact_person": agencyperson,
 					"phone":          agencytel,
@@ -48,6 +48,28 @@ func agencyStandarData(db string, query map[string]interface{}) {
 				ps = append(ps, v)
 				data := comHisMegerNewData(agency, "agency", ps)
 				if data != nil {
+					province, city, district := "", "", ""
+					province = qu.ObjToString(data["province"])
+					if province == "" { //省份为空,buyer优先提取区域信息再company_address
+						province, city, district = GetProvinceCityDistrict([]string{agency}) //先buyer
+						if province == "" {                                                  //再address
+							if address := qu.ObjToString(data["company_address"]); address != "" {
+								province, city, district = GetProvinceCityDistrict([]string{address})
+							}
+						}
+						data["province"] = province
+						data["city"] = city
+						data["district"] = district
+					}
+					//提取固话和手机号
+					contactArr := []interface{}{}
+					contactArr = append(contactArr, v)
+					latestFixedPhone, latestMobilePhone, timesFixedPhone, timesMobilePhone := getPhone(contactArr)
+					data["latestfixedphone"] = latestFixedPhone
+					data["latestmobilephone"] = latestMobilePhone
+					data["fixedphone"] = timesFixedPhone
+					data["mobilephone"] = timesMobilePhone
+					data["institute_type"] = "企业"
 					_id := MongoTo.Save(agencyent, data)
 					redis.PutRedis("agency", agencybd, agency, _id.(primitive.ObjectID).Hex(), -1)
 					savetoerr = false
@@ -56,42 +78,32 @@ func agencyStandarData(db string, query map[string]interface{}) {
 			if savetoerr {
 				t := MongoTo.FindOne(agencyerr, map[string]interface{}{"name": agency})
 				if len(t) < 1 {
+					province, city, district := GetProvinceCityDistrict([]string{agency})
 					MongoTo.Save(agencyerr, map[string]interface{}{
 						"name":       agency,
 						"check":      comMarkdata(agency, "agency"),
 						"updatetime": time.Now().Unix(),
+						"province":   province,
+						"city":       city,
+						"district":   district,
 					})
 				}
 			}
 		} else {
-			if agencytel != "" {
-				is_exist := false //电话是否存在
-				for _, v := range ps {
-					if v["phone"] == agencytel {
-						is_exist = true
-						if agencyperson != "" && v["contact_person"] != agencyperson {
-							v["contact_person"] = agencyperson
-							v["infoid"] = infoid
-							bs, _ := json.Marshal(ps) //替换数据,更新
-							redis.PutRedis("agency", agencybd, agency, bs, -1)
-						}
-						continue
-					}
-				}
-				if !is_exist {
-					v := map[string]interface{}{
-						"contact_person": agencyperson,
-						"phone":          agencytel,
-						"topscopeclass":  comRepTopscopeclass(topscopeclass),
-						"infoid":         infoid,
-					}
-					MongoTo.UpdateById(agencyent, entid,
-						map[string]interface{}{
-							"$set":  map[string]interface{}{"updatetime": time.Now().Unix()},
-							"$push": map[string]interface{}{"contact": v},
-						},
-					)
+			if agencytel != "" && agencyperson != "" {
+				v := map[string]interface{}{
+					"contact_person": agencyperson,
+					"phone":          agencytel,
+					"topscopeclass":  comRepTopscopeclass(topscopeclass),
+					"infoid":         infoid,
 				}
+				data := winMegerIndustry(entid, v)
+				MongoTo.UpdateById(agencyent, entid,
+					map[string]interface{}{
+						"$set":  data,
+						//"$push": map[string]interface{}{"contact": v},
+					},
+				)
 			}
 		}
 		tmp = map[string]interface{}{}

+ 10 - 2
standardata/src/standarbuyer.go

@@ -92,7 +92,7 @@ func buyerStandarData(db string, query map[string]interface{}) {
 				}
 			}
 		} else {
-			if buyerperson != "" || buyertel != "" {
+			if buyerperson != "" && buyertel != "" {
 				v := map[string]interface{}{
 					"contact_person": buyerperson,
 					"phone":          buyertel,
@@ -104,7 +104,7 @@ func buyerStandarData(db string, query map[string]interface{}) {
 				MongoTo.UpdateById(buyerent, entid,
 					map[string]interface{}{
 						"$set":  data,
-						"$push": map[string]interface{}{"contact": v},
+						//"$push": map[string]interface{}{"contact": v},
 					},
 				)
 			}
@@ -262,6 +262,14 @@ func buyerMegerBuyerclass(id string, ps map[string]interface{}) map[string]inter
 	//contact
 	contact := tmp["contact"].(primitive.A)
 	contact = append(contact, ps)
+	//bid_contact
+	bid_contacts,contacts := bid_contact(contact)
+	if len(bid_contacts) > 0 {
+		data["bid_contact"] = bid_contacts
+	}
+	//sort 200
+	contact = contacts
+	data["contact"] = contact
 	//提取固话和手机号
 	latestFixedPhone, latestMobilePhone, timesFixedPhone, timesMobilePhone := getPhone(contact)
 	data["latestfixedphone"] = latestFixedPhone

+ 61 - 16
standardata/src/standarwinner.go

@@ -46,6 +46,28 @@ func winnerStandarData(db string, query map[string]interface{}) {
 				}
 				data := comHisMegerNewData(winner, "winner", []map[string]interface{}{v})
 				if data != nil {
+					province, city, district := "", "", ""
+					province = qu.ObjToString(data["province"])
+					if province == "" { //省份为空,buyer优先提取区域信息再company_address
+						province, city, district = GetProvinceCityDistrict([]string{winner}) //先buyer
+						if province == "" {                                                 //再address
+							if address := qu.ObjToString(data["company_address"]); address != "" {
+								province, city, district = GetProvinceCityDistrict([]string{address})
+							}
+						}
+						data["province"] = province
+						data["city"] = city
+						data["district"] = district
+					}
+					//提取固话和手机号
+					contactArr := []interface{}{}
+					contactArr = append(contactArr, v)
+					latestFixedPhone, latestMobilePhone, timesFixedPhone, timesMobilePhone := getPhone(contactArr)
+					data["latestfixedphone"] = latestFixedPhone
+					data["latestmobilephone"] = latestMobilePhone
+					data["fixedphone"] = timesFixedPhone
+					data["mobilephone"] = timesMobilePhone
+					data["institute_type"] = "企业"
 					_id := MongoTo.Save(winnerent, data)
 					redis.PutRedis("winner", winnerbd, winner, _id.(primitive.ObjectID).Hex(), -1)
 					savetoerr = false
@@ -54,16 +76,20 @@ func winnerStandarData(db string, query map[string]interface{}) {
 			if savetoerr {
 				t := MongoTo.FindOne(winnererr, map[string]interface{}{"name": winner})
 				if len(t) < 1 {
+					province, city, district := GetProvinceCityDistrict([]string{winner})
 					MongoTo.Save(winnererr, map[string]interface{}{
 						"name":          winner,
 						"topscopeclass": comRepTopscopeclass(topscopeclass),
 						"check":         comMarkdata(winner, "winner"),
 						"updatetime":    time.Now().Unix(),
+						"province":   province,
+						"city":       city,
+						"district":   district,
 					})
 				}
 			}
 		} else { //更新标准库
-			if winnerperson != "" || winnertel != "" {
+			if winnerperson != "" && winnertel != "" {
 				v := map[string]interface{}{
 					"contact_person": winnerperson,
 					"phone":          winnertel,
@@ -74,7 +100,7 @@ func winnerStandarData(db string, query map[string]interface{}) {
 				MongoTo.UpdateById(winnerent, entid,
 					map[string]interface{}{
 						"$set":  data,
-						"$push": map[string]interface{}{"contact": v},
+						//"$push": map[string]interface{}{"contact": v},
 					},
 				)
 			}
@@ -231,29 +257,48 @@ func winStandarHistory(db string) {
 
 //企业数据整合(已有标注信息)
 func winMegerIndustry(id string, ps map[string]interface{}) map[string]interface{} {
-	tmp := MongoEnt.FindById(winnerent, id, bson.M{"industry": 1})
+	tmp := MongoEnt.FindById(winnerent, id, bson.M{"industry": 1, "contact": 1})
 	if len(tmp) < 1 {
 		return nil
 	}
 	data := map[string]interface{}{}
-	industry := tmp["industry"].(primitive.A)
-	tmpindustry := map[string]bool{}
-	for _, v := range industry {
-		tt := qu.ObjToString(v)
-		tmpindustry[tt] = true
-	}
-	if topscopeclass, ok := ps["topscopeclass"].([]interface{}); ok {
-		for _, v := range topscopeclass {
+	industry,ok := tmp["industry"].(primitive.A)
+	if ok{
+		tmpindustry := map[string]bool{}
+		for _, v := range industry {
 			tt := qu.ObjToString(v)
 			tmpindustry[tt] = true
 		}
+		if topscopeclass, ok := ps["topscopeclass"].([]interface{}); ok {
+			for _, v := range topscopeclass {
+				tt := qu.ObjToString(v)
+				tmpindustry[tt] = true
+			}
+		}
+		newindustry := []interface{}{}
+		for k, _ := range tmpindustry {
+			newindustry = append(newindustry, k)
+		}
+		data["industry"] = newindustry
 	}
-	newindustry := []interface{}{}
-	for k, _ := range tmpindustry {
-		newindustry = append(newindustry, k)
-	}
-	data["industry"] = newindustry
 	data["updatetime"] = time.Now().Unix()
+	//contact
+	contact := tmp["contact"].(primitive.A)
+	contact = append(contact, ps)
+	//bid_contact
+	bid_contacts,contacts := bid_contact(contact)
+	if len(bid_contacts) > 0 {
+		data["bid_contact"] = bid_contacts
+	}
+	//sort 200
+	contact = contacts
+	data["contact"] = contact
+	//提取固话和手机号
+	latestFixedPhone, latestMobilePhone, timesFixedPhone, timesMobilePhone := getPhone(contact)
+	data["latestfixedphone"] = latestFixedPhone
+	data["latestmobilephone"] = latestMobilePhone
+	data["fixedphone"] = timesFixedPhone
+	data["mobilephone"] = timesMobilePhone
 	return data
 }
 

+ 73 - 1
standardata/src/util.go

@@ -2,11 +2,15 @@ package main
 
 import (
 	"fmt"
+	"go.mongodb.org/mongo-driver/bson/primitive"
 	"log"
+	"qfw/common/src/qfw/util"
 	qu "qfw/util"
 	"regexp"
+	"sort"
 	"strconv"
 	"strings"
+	"unicode/utf8"
 )
 
 var (
@@ -765,7 +769,7 @@ func NewGetDistrict(area, city, district string, finishD, tmpcity []string) (str
 					district = d
 					return city, district
 				}
-			} else { //多个city
+			} else {                         //多个city
 				for _, tc := range tmpcity { //多个city根据district最高分取
 					if tc == c.Name && len(finishD) == 1 {
 						city = c.Name
@@ -864,3 +868,71 @@ func PCDScoreByDistrictSim(stype, t string, score float64, ps, cs, ds *map[strin
 		}
 	}
 }
+
+//bid_contact
+func bid_contact(tc primitive.A) ([]contactPersonPhone, []interface{}) {
+	contact_person_phone := make(map[string]uint32)
+	contact_person_phone_time := make(map[string]int64)
+	tmps := make([]interface{}, 0)
+	for _, v := range tc {
+		if km, ok := v.(map[string]interface{}); ok {
+			contact_person := util.ObjToString(km["contact_person"])
+			phone := util.ObjToString(km["phone"])
+			if contact_person == "" || phone == "" || utf8.RuneCountInString(phone) < 5 {
+				continue
+			}
+			if contact_person_phone[contact_person+"+_+"+phone] == 0 {
+				tmps = append(tmps, v)
+				contact_person_phone[contact_person+"+_+"+phone]++
+			}
+		}
+	}
+	ttmps := make([]interface{}, 0)
+	ttnum := 0
+	for i := len(tmps) - 1; i >= 0; i-- {
+		ttnum++
+		if ttnum > 200 {
+			break
+		}
+		ttmps = append(ttmps, tmps[i])
+	}
+	//t["contact"] = ttmps
+	contact_person_phone = make(map[string]uint32)
+	for _, v := range ttmps {
+		if km, ok := v.(map[string]interface{}); ok {
+			contact_person := util.ObjToString(km["contact_person"])
+			phone := util.ObjToString(km["phone"])
+			infoid := util.ObjToString(km["infoid"])
+			contact_person_phone[contact_person+"+_+"+phone]++
+			_id, _ := primitive.ObjectIDFromHex(infoid)
+			contact_person_phone_time[contact_person+"+_+"+phone] = _id.Timestamp().Unix()
+		}
+	}
+	contactPersonPhoneSlices := make(contactPersonPhoneSlice, 0)
+	if len(contact_person_phone) > 0 {
+		for k, v := range contact_person_phone {
+			pp := strings.Split(k, "+_+")
+			contactPersonPhoneSlices = append(contactPersonPhoneSlices, contactPersonPhone{Str: k, SNum: v, ContactPerson: pp[0], Phone: pp[1], UTime: contact_person_phone_time[k]})
+		}
+		sort.Sort(contactPersonPhoneSlices)
+		//t["bid_contact"] = contactPersonPhoneSlices
+		if contactPersonPhoneSlices.Len() > 200 {
+			contactPersonPhoneSlices = contactPersonPhoneSlices[:200]
+		}
+	}
+	return contactPersonPhoneSlices, ttmps
+}
+
+type contactPersonPhone struct {
+	Str           string `json:"str" bson:"-"`
+	SNum          uint32 `json:"s_num" bson:"-"`
+	ContactPerson string `json:"contact_person"`
+	Phone         string `json:"phone"`
+	UTime         int64  `json:"u_time"`
+}
+
+type contactPersonPhoneSlice []contactPersonPhone
+
+func (p contactPersonPhoneSlice) Len() int           { return len(p) }
+func (p contactPersonPhoneSlice) Less(i, j int) bool { return p[i].UTime >= p[j].UTime }
+func (p contactPersonPhoneSlice) Swap(i, j int)      { p[i], p[j] = p[j], p[i] }