fengweiqiang 4 years ago
parent
commit
8c8690ab10
4 changed files with 90 additions and 92 deletions
  1. 18 19
      standardata/src/standaragency.go
  2. 38 34
      standardata/src/standarbuyer.go
  3. 31 36
      standardata/src/standarwinner.go
  4. 3 3
      udps/main.go

+ 18 - 19
standardata/src/standaragency.go

@@ -100,7 +100,7 @@ func agencyStandarData(db string, query map[string]interface{}) {
 				data := winMegerIndustry(entid, v)
 				MongoTo.UpdateById(agencyent, entid,
 					map[string]interface{}{
-						"$set":  data,
+						"$set": data,
 						//"$push": map[string]interface{}{"contact": v},
 					},
 				)
@@ -170,28 +170,27 @@ func historyagency(db, fromcoll string) {
 								bs, _ := json.Marshal(ps)
 								redis.PutRedis("agency", agencybd, agency, bs, -1)
 							}
-						} else {
-							log.Println("jsonErr", err)
 						}
 					}
-				} else {
-					val := []map[string]interface{}{}
-					if agencytel != "" {
-						tmp := map[string]interface{}{
-							"contact_person": agencyperson,
-							"phone":          agencytel,
-							"topscopeclass":  comRepTopscopeclass(topscopeclass),
-							"infoid":         _id,
-						}
-						val = append(val, tmp)
+					return
+				}
+				val := []map[string]interface{}{}
+				if agencytel != "" {
+					tmp := map[string]interface{}{
+						"contact_person": agencyperson,
+						"phone":          agencytel,
+						"topscopeclass":  comRepTopscopeclass(topscopeclass),
+						"infoid":         _id,
 					}
-					bs, _ := json.Marshal(val)
-					redis.PutRedis("agency", agencybd, agency, bs, -1)
-					MongoTo.Save(agencyerr, map[string]interface{}{
-						"name":       agency,
-						"updatetime": time.Now().Unix(),
-					})
+					val = append(val, tmp)
 				}
+				bs, _ := json.Marshal(val)
+				redis.PutRedis("agency", agencybd, agency, bs, -1)
+				MongoTo.Save(agencyerr, map[string]interface{}{
+					"name":       agency,
+					"updatetime": time.Now().Unix(),
+				})
+
 			}
 		}(tmp)
 		tmp = map[string]interface{}{}

+ 38 - 34
standardata/src/standarbuyer.go

@@ -103,7 +103,7 @@ func buyerStandarData(db string, query map[string]interface{}) {
 				data := buyerMegerBuyerclass(entid, v)
 				MongoTo.UpdateById(buyerent, entid,
 					map[string]interface{}{
-						"$set":  data,
+						"$set": data,
 						//"$push": map[string]interface{}{"contact": v},
 					},
 				)
@@ -136,7 +136,16 @@ func historybuyer(db, fromcoll string) {
 				<-buyerchanbool
 			}()
 			buyer := qu.ObjToString(tmp["buyer"])
-			buyerclass := qu.ObjToString(tmp["buyerclass"])
+			buyerclass :=""
+			if tb ,ok := tmp["buyerclass"].(primitive.A);ok{
+				tbn := len(tb)
+				if tbn>0{
+					buyerclass = qu.ObjToString(tb[tbn-1])
+				}
+			}else if tbs ,ok :=tmp["buyerclass"].(string);ok{
+				buyerclass = tbs
+
+			}
 			topscopeclass, _ := tmp["topscopeclass"].(primitive.A)
 			if buyer != "" && utf8.RuneCountInString(buyer) > 4 {
 				buyerperson := qu.ObjToString(tmp["buyerperson"])
@@ -158,30 +167,29 @@ func historybuyer(db, fromcoll string) {
 							ps = append(ps, v)
 							bs, _ := json.Marshal(ps)
 							redis.PutRedis("buyer", buyerbd, buyer, bs, -1)
-						} else {
-							log.Println("jsonErr", err)
 						}
 					}
-				} else {
-					val := []map[string]interface{}{}
-					if buyerperson != "" || buyertel != "" {
-						tmp := map[string]interface{}{
-							"contact_person": buyerperson,
-							"phone":          buyertel,
-							"buyerclass":     buyerclass,
-							"topscopeclass":  comRepTopscopeclass(topscopeclass),
-							"infoid":         _id,
-						}
-						val = append(val, tmp)
+					return
+				}
+				val := []map[string]interface{}{}
+				if buyerperson != "" || buyertel != "" {
+					tmp := map[string]interface{}{
+						"contact_person": buyerperson,
+						"phone":          buyertel,
+						"buyerclass":     buyerclass,
+						"topscopeclass":  comRepTopscopeclass(topscopeclass),
+						"infoid":         _id,
 					}
-					bs, _ := json.Marshal(val)
-					redis.PutRedis("buyer", buyerbd, buyer, bs, -1)
-					MongoTo.Save(buyererr, map[string]interface{}{
-						"name":       buyer,
-						"buyerclass": buyerclass,
-						"updatetime": time.Now().Unix(),
-					})
+					val = append(val, tmp)
 				}
+				bs, _ := json.Marshal(val)
+				redis.PutRedis("buyer", buyerbd, buyer, bs, -1)
+				MongoTo.Save(buyererr, map[string]interface{}{
+					"name":       buyer,
+					"buyerclass": buyerclass,
+					"updatetime": time.Now().Unix(),
+				})
+
 			}
 		}(tmp)
 		tmp = map[string]interface{}{}
@@ -246,24 +254,20 @@ func buyerMegerBuyerclass(id string, ps map[string]interface{}) map[string]inter
 		return nil
 	}
 	data := map[string]interface{}{}
-	buyerclass := tmp["buyerclass"].(primitive.A)
-	tmpbuyerclass := map[string]bool{}
-	for _, v := range buyerclass {
-		tt := qu.ObjToString(v)
-		tmpbuyerclass[tt] = true
-	}
-	tmpbuyerclass[qu.ObjToString(ps["buyerclass"])] = true
-	newbuyerclass := []interface{}{}
-	for k, _ := range tmpbuyerclass {
-		newbuyerclass = append(newbuyerclass, k)
+	if buyerclass, ok := tmp["buyerclass"].(primitive.A); ok {
+		bn := len(buyerclass)
+		if bn > 0 {
+			data["buyerclass"] = qu.ObjToString(buyerclass[bn-1])
+		}
+	} else if sb, ok := tmp["buyerclass"].(string); ok {
+		data["buyerclass"] = sb
 	}
-	data["buyerclass"] = newbuyerclass
 	data["updatetime"] = time.Now().Unix()
 	//contact
 	contact := tmp["contact"].(primitive.A)
 	contact = append(contact, ps)
 	//bid_contact
-	bid_contacts,contacts := bid_contact(contact)
+	bid_contacts, contacts := bid_contact(contact)
 	if len(bid_contacts) > 0 {
 		data["bid_contact"] = bid_contacts
 	}

+ 31 - 36
standardata/src/standarwinner.go

@@ -50,7 +50,7 @@ func winnerStandarData(db string, query map[string]interface{}) {
 					province = qu.ObjToString(data["province"])
 					if province == "" { //省份为空,buyer优先提取区域信息再company_address
 						province, city, district = GetProvinceCityDistrict([]string{winner}) //先buyer
-						if province == "" {                                                 //再address
+						if province == "" {                                                  //再address
 							if address := qu.ObjToString(data["company_address"]); address != "" {
 								province, city, district = GetProvinceCityDistrict([]string{address})
 							}
@@ -82,9 +82,9 @@ func winnerStandarData(db string, query map[string]interface{}) {
 						"topscopeclass": comRepTopscopeclass(topscopeclass),
 						"check":         comMarkdata(winner, "winner"),
 						"updatetime":    time.Now().Unix(),
-						"province":   province,
-						"city":       city,
-						"district":   district,
+						"province":      province,
+						"city":          city,
+						"district":      district,
 					})
 				}
 			}
@@ -99,7 +99,7 @@ func winnerStandarData(db string, query map[string]interface{}) {
 				data := winMegerIndustry(entid, v)
 				MongoTo.UpdateById(winnerent, entid,
 					map[string]interface{}{
-						"$set":  data,
+						"$set": data,
 						//"$push": map[string]interface{}{"contact": v},
 					},
 				)
@@ -141,7 +141,8 @@ func historywinner(db, fromcoll string) {
 	log.Println("history  start")
 	sess := MongoFrom.GetMgoConn()
 	defer MongoFrom.Close()
-	it := sess.DB(db).C(fromcoll).Find(map[string]interface{}{}).Select(bson.M{"repeat": 1, "winner": 1, "winnertel": 1, "winnerperson": 1, "topscopeclass": 1}).Sort("_id").Iter()
+	it := sess.DB(db).C(fromcoll).Find(map[string]interface{}{}).Select(bson.M{
+		"repeat": 1, "winner": 1, "winnertel": 1, "winnerperson": 1, "topscopeclass": 1}).Sort("_id").Iter()
 	index := 0
 	for tmp := make(map[string]interface{}); it.Next(&tmp); index++ {
 		if qu.IntAll(tmp["repeat"]) > 0 { //重复数据跳过
@@ -175,29 +176,28 @@ func historywinner(db, fromcoll string) {
 							bs, _ := json.Marshal(ps)
 							redis.PutRedis("winner", winnerbd, winner, bs, -1)
 							//log.Println(_id, index, winner)
-						} else {
-							log.Println("jsonErr", err)
 						}
 					}
-				} else {
-					val := []map[string]interface{}{}
-					if winnerperson != "" || winnertel != "" {
-						tmp := map[string]interface{}{
-							"contact_person": winnerperson,
-							"phone":          winnertel,
-							"topscopeclass":  comRepTopscopeclass(topscopeclass),
-							"infoid":         _id,
-						}
-						val = append(val, tmp)
+					return
+				}
+				val := []map[string]interface{}{}
+				if winnerperson != "" || winnertel != "" {
+					tmp := map[string]interface{}{
+						"contact_person": winnerperson,
+						"phone":          winnertel,
+						"topscopeclass":  comRepTopscopeclass(topscopeclass),
+						"infoid":         _id,
 					}
-					bs, _ := json.Marshal(val)
-					redis.PutRedis("winner", winnerbd, winner, bs, -1)
-					MongoTo.Save(winnererr, map[string]interface{}{
-						"name":          winner,
-						"topscopeclass": comRepTopscopeclass(topscopeclass),
-						"updatetime":    time.Now().Unix(),
-					})
+					val = append(val, tmp)
 				}
+				bs, _ := json.Marshal(val)
+				redis.PutRedis("winner", winnerbd, winner, bs, -1)
+				MongoTo.Save(winnererr, map[string]interface{}{
+					"name":          winner,
+					"topscopeclass": comRepTopscopeclass(topscopeclass),
+					"updatetime":    time.Now().Unix(),
+				})
+
 			}
 		}(tmp)
 		tmp = map[string]interface{}{}
@@ -262,8 +262,8 @@ func winMegerIndustry(id string, ps map[string]interface{}) map[string]interface
 		return nil
 	}
 	data := map[string]interface{}{}
-	industry,ok := tmp["industry"].(primitive.A)
-	if ok{
+	industry, ok := tmp["industry"].(primitive.A)
+	if ok {
 		tmpindustry := map[string]bool{}
 		for _, v := range industry {
 			tt := qu.ObjToString(v)
@@ -286,7 +286,7 @@ func winMegerIndustry(id string, ps map[string]interface{}) map[string]interface
 	contact := tmp["contact"].(primitive.A)
 	contact = append(contact, ps)
 	//bid_contact
-	bid_contacts,contacts := bid_contact(contact)
+	bid_contacts, contacts := bid_contact(contact)
 	if len(bid_contacts) > 0 {
 		data["bid_contact"] = bid_contacts
 	}
@@ -437,15 +437,10 @@ func comHisMegerNewData(name, datatype string, ps []map[string]interface{}) map[
 		data["industry"] = industry
 	} else if datatype == "buyer" {
 		data["buyer_name"] = name
-		tmpbuyerclass := map[string]bool{}
-		for _, p := range ps {
-			tmpbuyerclass[qu.ObjToString(p["buyerclass"])] = true
-		}
-		buyerclass := []interface{}{}
-		for k, _ := range tmpbuyerclass {
-			buyerclass = append(buyerclass, k)
+		lennum := len(ps)
+		if lennum > 1 {
+			data["buyerclass"] = qu.ObjToString(ps[lennum-1]["buyerclass"])
 		}
-		data["buyerclass"] = buyerclass
 		data["ranks"] = ""
 		data["type"] = ""
 		data["address"] = ""

+ 3 - 3
udps/main.go

@@ -18,12 +18,12 @@ func main() {
 	ip, p, tmptime, tmpkey, id1, id2, stype, q, bkey, param, ids := "", 0, 0, "", "", "", "", "", "", "", ""
 	flag.StringVar(&startDate, "start", "", "开始日期2006-01-02")
 	flag.StringVar(&endDate, "end", "", "结束日期2006-01-02")
-	flag.StringVar(&ip, "ip", "192.168.3.205", "ip")
+	flag.StringVar(&ip, "ip", "127.0.0.1", "ip")
 	flag.IntVar(&p, "p", 1484, "端口")
 	flag.IntVar(&tmptime, "tmptime", 0, "时间查询")
 	flag.StringVar(&tmpkey, "tmpkey", "", "时间字段")
-	flag.StringVar(&id1, "gtid", "5a86328a40d2d9bbe88e4138", "gtid")
-	flag.StringVar(&id2, "lteid", "5a8f8cd340d2d9bbe8a21400", "lteid")
+	flag.StringVar(&id1, "gtid", "5e8fae3485a9271abf2b8330", "gtid")
+	flag.StringVar(&id2, "lteid", "5fe50860f0f9d716c17d1b99", "lteid")
 	flag.StringVar(&ids, "ids", "", "id1,id2")
 	flag.StringVar(&stype, "stype", "biddingall", "stype,传递类型")
 	flag.StringVar(&bkey, "bkey", "", "bkey,加上此参数表示不生关键词和摘要")