|
@@ -4,13 +4,14 @@ import (
|
|
"encoding/json"
|
|
"encoding/json"
|
|
"fmt"
|
|
"fmt"
|
|
"github.com/garyburd/redigo/redis"
|
|
"github.com/garyburd/redigo/redis"
|
|
- "go.mongodb.org/mongo-driver/bson/primitive"
|
|
|
|
"gopkg.in/mgo.v2/bson"
|
|
"gopkg.in/mgo.v2/bson"
|
|
"log"
|
|
"log"
|
|
mu "mfw/util"
|
|
mu "mfw/util"
|
|
"net"
|
|
"net"
|
|
"qfw/util"
|
|
"qfw/util"
|
|
|
|
+ "reflect"
|
|
"sort"
|
|
"sort"
|
|
|
|
+ "strconv"
|
|
"strings"
|
|
"strings"
|
|
"time"
|
|
"time"
|
|
)
|
|
)
|
|
@@ -18,21 +19,25 @@ import (
|
|
//之前main方法,只更新
|
|
//之前main方法,只更新
|
|
func TaskBuyer(mapinfo *map[string]interface{}) {
|
|
func TaskBuyer(mapinfo *map[string]interface{}) {
|
|
defer util.Catch()
|
|
defer util.Catch()
|
|
|
|
+ //释放
|
|
|
|
+ defer func() { <-CPool }()
|
|
gtid, lteid := util.ObjToString((*mapinfo)["gtid"]), util.ObjToString((*mapinfo)["lteid"])
|
|
gtid, lteid := util.ObjToString((*mapinfo)["gtid"]), util.ObjToString((*mapinfo)["lteid"])
|
|
if gtid == "" || lteid == "" {
|
|
if gtid == "" || lteid == "" {
|
|
log.Println(gtid, lteid, "参数错误")
|
|
log.Println(gtid, lteid, "参数错误")
|
|
return
|
|
return
|
|
}
|
|
}
|
|
- GId, err := primitive.ObjectIDFromHex(gtid)
|
|
|
|
- LtId, err2 := primitive.ObjectIDFromHex(lteid)
|
|
|
|
- if err != nil || err2 != nil {
|
|
|
|
- log.Println(gtid, lteid, "转换_id错误")
|
|
|
|
|
|
+ var GId, LtId bson.ObjectId
|
|
|
|
+ if bson.IsObjectIdHex(gtid) && bson.IsObjectIdHex(lteid) {
|
|
|
|
+ GId = bson.ObjectIdHex(gtid)
|
|
|
|
+ LtId = bson.ObjectIdHex(lteid)
|
|
|
|
+ } else {
|
|
|
|
+ log.Println(gtid, lteid, "不是Objectid,转换_id错误", gtid, lteid)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
//udp的id区间查询bidding 中标人 中标联系人 中标联系电话
|
|
//udp的id区间查询bidding 中标人 中标联系人 中标联系电话
|
|
// topscopeclass项目类型-industry行业类型&&topscopeclass联系人项目类型
|
|
// topscopeclass项目类型-industry行业类型&&topscopeclass联系人项目类型
|
|
// (area地区-province省份 city城市-city城市 district区县-district区县)
|
|
// (area地区-province省份 city城市-city城市 district区县-district区县)
|
|
- // winneraddr-company_address企业地址
|
|
|
|
|
|
+ // buyeraddr-company_address企业地址
|
|
SourceClientcc := SourceClient.GetMgoConn()
|
|
SourceClientcc := SourceClient.GetMgoConn()
|
|
defer SourceClient.DestoryMongoConn(SourceClientcc)
|
|
defer SourceClient.DestoryMongoConn(SourceClientcc)
|
|
cursor := SourceClientcc.DB(Config["mgodb_bidding"]).C(Config["mgodb_mgoinit_c"]).Find(bson.M{
|
|
cursor := SourceClientcc.DB(Config["mgodb_bidding"]).C(Config["mgodb_mgoinit_c"]).Find(bson.M{
|
|
@@ -40,30 +45,45 @@ func TaskBuyer(mapinfo *map[string]interface{}) {
|
|
"$gte": GId,
|
|
"$gte": GId,
|
|
"$lte": LtId,
|
|
"$lte": LtId,
|
|
},
|
|
},
|
|
- }).Select(bson.M{"buyer": 1, "buyertel": 1, "buyerperson": 1,
|
|
|
|
- "topscopeclass": 1, "buyeraddr": 1,"buyerclass":1}).Iter()
|
|
|
|
- if cursor == nil {
|
|
|
|
- log.Println(cursor)
|
|
|
|
|
|
+ }).Select(bson.M{"buyer": 1, "buyertel": 1, "buyerperson": 1, "topscopeclass": 1,
|
|
|
|
+ "buyeraddr": 1,"buyerclass":1}).Iter()
|
|
|
|
+ if cursor.Err() != nil {
|
|
|
|
+ log.Println(cursor.Err())
|
|
return
|
|
return
|
|
}
|
|
}
|
|
//判断是否是存量,是存量走Redis遍历
|
|
//判断是否是存量,是存量走Redis遍历
|
|
if v, ok := (*mapinfo)["data_info"].(string); ok && v == "save" {
|
|
if v, ok := (*mapinfo)["data_info"].(string); ok && v == "save" {
|
|
//存量处理
|
|
//存量处理
|
|
- tmp := map[string]interface{}{}
|
|
|
|
conn := HisRedisPool.Conn()
|
|
conn := HisRedisPool.Conn()
|
|
defer conn.Close()
|
|
defer conn.Close()
|
|
//选择redis db
|
|
//选择redis db
|
|
- conn.Select(1)
|
|
|
|
|
|
+ redis_buyer_db, _ := strconv.Atoi(Config["redis_buyer_db"])
|
|
|
|
+ conn.Select(redis_buyer_db)
|
|
//遍历bidding表保存到redis
|
|
//遍历bidding表保存到redis
|
|
- // key:_id value:json结构体
|
|
|
|
|
|
+ //key:企业名 value:json结构体{"buyer": 1, "buyertel": 1, "buyerperson": 1,"topscopeclass": 1, "buyeraddr": 1,"_id":1}
|
|
|
|
+ tmp := make(map[string]interface{})
|
|
for cursor.Next(&tmp) {
|
|
for cursor.Next(&tmp) {
|
|
- if tmp["buyer"] == nil || tmp["buyer"] == "" {
|
|
|
|
|
|
+ buyer, ok := tmp["buyer"].(string)
|
|
|
|
+ if !ok || buyer == "" {
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
- mgoId:=tmp["_id"].(primitive.ObjectID).Hex()
|
|
|
|
- delete(tmp,"_id")
|
|
|
|
- bytes, _ := json.Marshal(tmp)
|
|
|
|
- if err := conn.Set(mgoId, string(bytes), 0).Err(); err != nil {
|
|
|
|
|
|
+ //判断redis key是否存在
|
|
|
|
+ e_num := conn.Exists(buyer).Val()
|
|
|
|
+ //获取字符串_id
|
|
|
|
+ mgoId := tmp["_id"].(bson.ObjectId).Hex()
|
|
|
|
+ //替换_id
|
|
|
|
+ tmp["_id"] = mgoId
|
|
|
|
+ //创建value数组
|
|
|
|
+ tmps := make([]map[string]interface{}, 0)
|
|
|
|
+ if e_num > 0 {
|
|
|
|
+ //存量redis的key存在,累加更新
|
|
|
|
+ bytes, _ := conn.Get(buyer).Bytes()
|
|
|
|
+ json.Unmarshal(bytes, &tmps)
|
|
|
|
+ }
|
|
|
|
+ tmps = append(tmps, tmp)
|
|
|
|
+ bytes, _ := json.Marshal(tmps)
|
|
|
|
+ //存量redis的key不存在,新增 key :企业名 val :[]map
|
|
|
|
+ if err := conn.Set(buyer, string(bytes), 0).Err(); err != nil {
|
|
log.Println(err)
|
|
log.Println(err)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -74,172 +94,133 @@ func TaskBuyer(mapinfo *map[string]interface{}) {
|
|
} else {
|
|
} else {
|
|
iterator := scan.Iterator()
|
|
iterator := scan.Iterator()
|
|
for iterator.Next() {
|
|
for iterator.Next() {
|
|
- redisId := iterator.Val() //redis key
|
|
|
|
- redisvalue := conn.Get(iterator.Val()).Val() //redis val
|
|
|
|
- tmp := make(map[string]interface{})
|
|
|
|
- json.Unmarshal([]byte(redisvalue),&tmp)
|
|
|
|
- //重复增量操作
|
|
|
|
|
|
+ redisCName := iterator.Val() //redis key 企业名
|
|
|
|
+ redisvalueBytes, _ := conn.Get(redisCName).Bytes() //redis val []数组
|
|
|
|
+ rValuesMaps := make([]map[string]interface{}, 0)
|
|
|
|
+ json.Unmarshal(redisvalueBytes, &rValuesMaps)
|
|
//redis查询是否存在
|
|
//redis查询是否存在
|
|
rdb := RedisPool.Get()
|
|
rdb := RedisPool.Get()
|
|
- rdb.Do("SELECT","2")
|
|
|
|
- if reply, err := redis.String(rdb.Do("GET", tmp["buyer"])); err != nil {
|
|
|
|
|
|
+ rdb.Do("SELECT", Config["redis_buyer_db"])
|
|
|
|
+ if reply, err := redis.String(rdb.Do("GET", redisCName)); err != nil {
|
|
//redis不存在,存到临时表,定时任务处理
|
|
//redis不存在,存到临时表,定时任务处理
|
|
- FClient.DbName = Config["mgodb_extract_kf"]
|
|
|
|
- if tmpid := FClient.Save("buyer_new", tmp); tmpid == nil {
|
|
|
|
- log.Println("存量 FClient.Save err", tmpid)
|
|
|
|
|
|
+ //FClient.DbName = Config["mgodb_extract_kf"]
|
|
|
|
+ //if tmpid := FClient.Save("buyer_new", tmps); tmpid == nil {
|
|
|
|
+ // log.Println("存量 FClient.Save err", tmpid)
|
|
|
|
+ //}
|
|
|
|
+ fsavec := FClient.GetMgoConn().DB(Config["mgodb_extract_kf"]).C("buyer_new")
|
|
|
|
+ for _, vmap := range rValuesMaps {
|
|
|
|
+ vmap["_id"] = bson.ObjectIdHex(vmap["_id"].(string))
|
|
|
|
+ if err = fsavec.Insert(vmap); err != nil{
|
|
|
|
+ log.Println("存量 FClient.Save err", err)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
//log.Println("get redis id err:定时任务处理", err, tmp)
|
|
//log.Println("get redis id err:定时任务处理", err, tmp)
|
|
if err := rdb.Close(); err != nil {
|
|
if err := rdb.Close(); err != nil {
|
|
- log.Println("存量",err)
|
|
|
|
|
|
+ log.Println("存量", err)
|
|
}
|
|
}
|
|
- //删除存量redis
|
|
|
|
- conn.Del(redisId)
|
|
|
|
continue
|
|
continue
|
|
} else {
|
|
} else {
|
|
|
|
+ //redis存在更新合并
|
|
if err := rdb.Close(); err != nil {
|
|
if err := rdb.Close(); err != nil {
|
|
log.Println(err)
|
|
log.Println(err)
|
|
}
|
|
}
|
|
//拿到合并后的qyk
|
|
//拿到合并后的qyk
|
|
FClient.DbName = Config["mgodb_extract_kf"]
|
|
FClient.DbName = Config["mgodb_extract_kf"]
|
|
- oldTmp := FClient.FindById(Config["mgo_qyk_buyer"], reply)
|
|
|
|
- if oldTmp == nil {
|
|
|
|
- log.Println("存量 redis id 不存在",reply,tmp["buyer"])
|
|
|
|
|
|
+ oldTmp, b := FClient.FindById(Config["mgo_qyk_buyer"], reply, nil)
|
|
|
|
+ if !b || oldTmp == nil {
|
|
|
|
+ log.Println(redisCName, "存量 redis id 不存在", reply)
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
tmpTopscopeclass := []string{}
|
|
tmpTopscopeclass := []string{}
|
|
tmpTopscopeclassMap := make(map[string]bool)
|
|
tmpTopscopeclassMap := make(map[string]bool)
|
|
|
|
|
|
- if v, ok := tmp["topscopeclass"].(primitive.A); ok {
|
|
|
|
- for _, vv := range v {
|
|
|
|
- if vvv, ok := vv.(string); ok && len(vvv) > 1 {
|
|
|
|
- tmpTopscopeclassMap[vvv[:len(vvv)-1]] = true
|
|
|
|
|
|
+ for _, rvaluemaps := range rValuesMaps {
|
|
|
|
+ if tclasss, ok := rvaluemaps["topscopeclass"].([]string); ok {
|
|
|
|
+ for _, vv := range tclasss {
|
|
|
|
+ if len(vv) > 1 {
|
|
|
|
+ tmpTopscopeclassMap[vv[:len(vv)-1]] = true
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- for k := range tmpTopscopeclassMap {
|
|
|
|
- tmpTopscopeclass = append(tmpTopscopeclass, k)
|
|
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
+ for k := range tmpTopscopeclassMap {
|
|
|
|
+ tmpTopscopeclass = append(tmpTopscopeclass, k)
|
|
}
|
|
}
|
|
sort.Strings(tmpTopscopeclass)
|
|
sort.Strings(tmpTopscopeclass)
|
|
|
|
+ esId := (*oldTmp)["_id"].(bson.ObjectId).Hex()
|
|
|
|
|
|
- //更新buyerclass
|
|
|
|
- esId := oldTmp["_id"].(primitive.ObjectID).Hex()
|
|
|
|
- //更新行业类型
|
|
|
|
- if tmp["buyerperson"] == nil || tmp["buyerperson"] == "" || Reg_xing.MatchString(util.ObjToString(tmp["buyerperson"])) {
|
|
|
|
- //更新buyerclass合并
|
|
|
|
- if tmp["buyerclass"] == nil || tmp["buyerclass"] == "" {
|
|
|
|
- //无值,不更新
|
|
|
|
|
|
+
|
|
|
|
+ //更新buyerclass合并
|
|
|
|
+ if tmp["buyerclass"] == nil || tmp["buyerclass"] == "" {
|
|
|
|
+ //无值,不更新
|
|
|
|
+ }else {
|
|
|
|
+ var buyerclass_new,buyerclass_old string
|
|
|
|
+ buyerclass_new = tmp["buyerclass"].(string)
|
|
|
|
+ buyerclass_old = (*oldTmp)["buyerclass"].(string)
|
|
|
|
+ if buyerclass_old=="" {
|
|
|
|
+ (*oldTmp)["buyerclass"] = buyerclass_new
|
|
}else {
|
|
}else {
|
|
- var buyerclass_new,buyerclass_old string
|
|
|
|
- buyerclass_new = tmp["buyerclass"].(string)
|
|
|
|
- buyerclass_old = oldTmp["buyerclass"].(string)
|
|
|
|
- if buyerclass_old=="" {
|
|
|
|
- oldTmp["buyerclass"] = buyerclass_new
|
|
|
|
- }else {
|
|
|
|
- if buyerclass_new!=buyerclass_old {
|
|
|
|
- if !strings.Contains(buyerclass_old, buyerclass_new) {
|
|
|
|
- oldTmp["buyerclass"] = buyerclass_old + ","+buyerclass_new //采购单位类型
|
|
|
|
- }
|
|
|
|
|
|
+ if buyerclass_new!=buyerclass_old {
|
|
|
|
+ if !strings.Contains(buyerclass_old, buyerclass_new) {
|
|
|
|
+ (*oldTmp)["buyerclass"] = buyerclass_old + ","+buyerclass_new //采购单位类型
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
|
|
- oldTmp["updatatime"] = time.Now().Unix()
|
|
|
|
- //mongo更新
|
|
|
|
- FClient.DbName = Config["mgodb_extract_kf"]
|
|
|
|
- if !FClient.UpdateById(Config["mgo_qyk_buyer"], esId, bson.M{"$set": oldTmp}) {
|
|
|
|
- log.Println("mongo更新err", esId)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //es更新
|
|
|
|
- delete(oldTmp, "_id")
|
|
|
|
- if _, err := EsConn.Update().Index(Config["elasticsearch_buyer_index"]).Type(Config["elasticsearch_buyer_type"]).Id(esId).Doc(oldTmp).Refresh(true).Do(); err != nil {
|
|
|
|
- log.Println("update es err:", err)
|
|
|
|
|
|
+ //联系方式合并
|
|
|
|
+ contactMaps := make([]interface{}, 0)
|
|
|
|
+ if (*oldTmp)["contact"] != nil {
|
|
|
|
+ //直接添加联系人,不再判断
|
|
|
|
+ if v, ok := (*oldTmp)["contact"].([]interface{}); ok {
|
|
|
|
+ contactMaps = append(contactMaps, v...)
|
|
}
|
|
}
|
|
- //删除存量redis
|
|
|
|
- conn.Del(redisId)
|
|
|
|
- continue
|
|
|
|
}
|
|
}
|
|
- //联系方式合并
|
|
|
|
- var tmpperson, buyertel string
|
|
|
|
- tmpperson = tmp["buyerperson"].(string)
|
|
|
|
- if tmp["buyertel"] == nil || tmp["buyertel"] == "" {
|
|
|
|
- buyertel = ""
|
|
|
|
- } else {
|
|
|
|
- if Reg_xing.MatchString(util.ObjToString(tmp["buyertel"])) || !Reg_tel.MatchString(util.ObjToString(tmp["buyertel"])) {
|
|
|
|
- buyertel = ""
|
|
|
|
|
|
+ //遍历redis value联系人
|
|
|
|
+ for _, rvmap := range rValuesMaps {
|
|
|
|
+ var tmpperson, buyertel string
|
|
|
|
+ if rvmapperson, ok := rvmap["buyerperson"].(string); ok && rvmapperson != "" {
|
|
|
|
+ tmpperson = rvmapperson
|
|
} else {
|
|
} else {
|
|
- buyertel = util.ObjToString(tmp["buyertel"])
|
|
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ if rvmapwintel, ok := rvmap["buyertel"].(string); ok {
|
|
|
|
+ buyertel = rvmapwintel
|
|
|
|
+ } else {
|
|
|
|
+ buyertel = ""
|
|
|
|
+ }
|
|
|
|
+ if Reg_xing.MatchString(buyertel) || !Reg_tel.MatchString(buyertel) {
|
|
|
|
+ buyertel = ""
|
|
}
|
|
}
|
|
- }
|
|
|
|
- contactMaps := make([]interface{}, 0)
|
|
|
|
- if oldTmp["contact"] == nil {
|
|
|
|
tmpContact := make(map[string]interface{})
|
|
tmpContact := make(map[string]interface{})
|
|
- tmpContact["infoid"] = redisId
|
|
|
|
|
|
+ tmpContact["infoid"] = rvmap["_id"]
|
|
tmpContact["contact_person"] = tmpperson
|
|
tmpContact["contact_person"] = tmpperson
|
|
tmpContact["contact_type"] = "项目联系人"
|
|
tmpContact["contact_type"] = "项目联系人"
|
|
tmpContact["phone"] = buyertel
|
|
tmpContact["phone"] = buyertel
|
|
- tmpContact["topscopeclass"] = strings.Join(tmpTopscopeclass, ";")
|
|
|
|
- tmpContact["updatetime"] = time.Now().Unix()
|
|
|
|
- contactMaps = append(contactMaps, tmpContact)
|
|
|
|
- } else {
|
|
|
|
- //对比前四项,相等丢弃
|
|
|
|
- if v, ok := oldTmp["contact"].(primitive.A); ok {
|
|
|
|
- var isNotUpdate bool
|
|
|
|
- for _, vv := range v {
|
|
|
|
- if vvv, ok := vv.(map[string]interface{}); ok {
|
|
|
|
- if vvv["contact_person"] == tmpperson && vvv["contact_type"] == "项目联系人" &&
|
|
|
|
- vvv["phone"] == buyertel && vvv["topscopeclass"] == strings.Join(tmpTopscopeclass, ";") {
|
|
|
|
- isNotUpdate = true
|
|
|
|
- vvv["updatetime"] = time.Now().Unix()
|
|
|
|
- }
|
|
|
|
- contactMaps = append(contactMaps, vvv)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if !isNotUpdate {
|
|
|
|
- vvv := make(map[string]interface{})
|
|
|
|
- vvv["infoid"] = redisId
|
|
|
|
- vvv["contact_person"] = tmp["buyerperson"]
|
|
|
|
- vvv["contact_type"] = "项目联系人"
|
|
|
|
- vvv["phone"] = buyertel
|
|
|
|
- vvv["topscopeclass"] = strings.Join(tmpTopscopeclass, ";")
|
|
|
|
- vvv["updatetime"] = time.Now().Unix()
|
|
|
|
- contactMaps = append(contactMaps, vvv)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- oldTmp["contact"] = contactMaps
|
|
|
|
-
|
|
|
|
- //更新buyerclass合并
|
|
|
|
- if tmp["buyerclass"] == nil || tmp["buyerclass"] == "" {
|
|
|
|
- //无值,不更新
|
|
|
|
- }else {
|
|
|
|
- var buyerclass_new,buyerclass_old string
|
|
|
|
- buyerclass_new = tmp["buyerclass"].(string)
|
|
|
|
- buyerclass_old = oldTmp["buyerclass"].(string)
|
|
|
|
- if buyerclass_old=="" {
|
|
|
|
- oldTmp["buyerclass"] = buyerclass_new
|
|
|
|
- }else {
|
|
|
|
- if buyerclass_new!=buyerclass_old {
|
|
|
|
- if !strings.Contains(buyerclass_old, buyerclass_new) {
|
|
|
|
- oldTmp["buyerclass"] = buyerclass_old + ","+buyerclass_new //采购单位类型
|
|
|
|
|
|
+ tmpclass := make([]string, 0)
|
|
|
|
+ if tclasss, ok := rvmap["topscopeclass"].([]string); ok {
|
|
|
|
+ for _, vv := range tclasss {
|
|
|
|
+ if len(vv) > 1 {
|
|
|
|
+ tmpclass = append(tmpclass, vv[:len(vv)-1])
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ tmpContact["topscopeclass"] = strings.Join(tmpclass, ";")
|
|
|
|
+ tmpContact["updatetime"] = time.Now().Unix()
|
|
|
|
+ contactMaps = append(contactMaps, tmpContact)
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ (*oldTmp)["contact"] = contactMaps
|
|
//mongo更新
|
|
//mongo更新
|
|
- oldTmp["updatatime"] = time.Now().Unix()
|
|
|
|
|
|
+ (*oldTmp)["updatatime"] = time.Now().Unix()
|
|
FClient.DbName = Config["mgodb_extract_kf"]
|
|
FClient.DbName = Config["mgodb_extract_kf"]
|
|
if !FClient.UpdateById(Config["mgo_qyk_buyer"], esId, bson.M{"$set": oldTmp}) {
|
|
if !FClient.UpdateById(Config["mgo_qyk_buyer"], esId, bson.M{"$set": oldTmp}) {
|
|
log.Println("存量 mongo更新 err", esId, oldTmp)
|
|
log.Println("存量 mongo更新 err", esId, oldTmp)
|
|
}
|
|
}
|
|
//es更新
|
|
//es更新
|
|
- delete(oldTmp, "_id")
|
|
|
|
|
|
+ delete((*oldTmp), "_id")
|
|
if _, err := EsConn.Update().Index(Config["elasticsearch_buyer_index"]).Type(Config["elasticsearch_buyer_type"]).Id(esId).Doc(oldTmp).Refresh(true).Do(); err != nil {
|
|
if _, err := EsConn.Update().Index(Config["elasticsearch_buyer_index"]).Type(Config["elasticsearch_buyer_type"]).Id(esId).Doc(oldTmp).Refresh(true).Do(); err != nil {
|
|
log.Println("存量 EsConn err :", err)
|
|
log.Println("存量 EsConn err :", err)
|
|
}
|
|
}
|
|
- //最后删除redis
|
|
|
|
- conn.Del(redisId)
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -250,18 +231,18 @@ func TaskBuyer(mapinfo *map[string]interface{}) {
|
|
overid := gtid
|
|
overid := gtid
|
|
tmp := map[string]interface{}{}
|
|
tmp := map[string]interface{}{}
|
|
for cursor.Next(&tmp) {
|
|
for cursor.Next(&tmp) {
|
|
- overid = tmp["_id"].(primitive.ObjectID).Hex()
|
|
|
|
|
|
+ overid = tmp["_id"].(bson.ObjectId).Hex()
|
|
//log.Println(tmp["_id"])
|
|
//log.Println(tmp["_id"])
|
|
if tmp["buyer"] == nil || tmp["buyer"] == "" {
|
|
if tmp["buyer"] == nil || tmp["buyer"] == "" {
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
//redis查询是否存在
|
|
//redis查询是否存在
|
|
rdb := RedisPool.Get()
|
|
rdb := RedisPool.Get()
|
|
- rdb.Do("SELECT","2")
|
|
|
|
|
|
+ rdb.Do("SELECT", Config["redis_buyer_db"])
|
|
if reply, err := redis.String(rdb.Do("GET", tmp["buyer"])); err != nil {
|
|
if reply, err := redis.String(rdb.Do("GET", tmp["buyer"])); err != nil {
|
|
//redis不存在存到临时表,定时任务处理
|
|
//redis不存在存到临时表,定时任务处理
|
|
FClient.DbName = Config["mgodb_extract_kf"]
|
|
FClient.DbName = Config["mgodb_extract_kf"]
|
|
- if tmpid := FClient.Save("buyer_new", tmp); tmpid == nil {
|
|
|
|
|
|
+ if tmpid := FClient.Save("buyer_new", tmp); tmpid == "" {
|
|
log.Println("FClient.Save err", tmpid)
|
|
log.Println("FClient.Save err", tmpid)
|
|
}
|
|
}
|
|
//log.Println("get redis id err:定时任务处理", err, tmp)
|
|
//log.Println("get redis id err:定时任务处理", err, tmp)
|
|
@@ -275,53 +256,54 @@ func TaskBuyer(mapinfo *map[string]interface{}) {
|
|
}
|
|
}
|
|
//拿到合并后的qyk
|
|
//拿到合并后的qyk
|
|
FClient.DbName = Config["mgodb_extract_kf"]
|
|
FClient.DbName = Config["mgodb_extract_kf"]
|
|
- oldTmp := FClient.FindById(Config["mgo_qyk_buyer"], reply)
|
|
|
|
- if oldTmp == nil {
|
|
|
|
|
|
+ oldTmp, b := FClient.FindById(Config["mgo_qyk_buyer"], reply, bson.M{})
|
|
|
|
+ if !b || oldTmp == nil {
|
|
log.Println("redis id 不存在")
|
|
log.Println("redis id 不存在")
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
//比较合并
|
|
//比较合并
|
|
//行业类型
|
|
//行业类型
|
|
tmpTopscopeclass := []string{}
|
|
tmpTopscopeclass := []string{}
|
|
|
|
+ tmpConTopscopeclass := []string{}
|
|
tmpTopscopeclassMap := make(map[string]bool)
|
|
tmpTopscopeclassMap := make(map[string]bool)
|
|
|
|
|
|
-
|
|
|
|
- if v, ok := tmp["topscopeclass"].(primitive.A); ok {
|
|
|
|
|
|
+ if v, ok := tmp["topscopeclass"].([]interface{}); ok {
|
|
for _, vv := range v {
|
|
for _, vv := range v {
|
|
if vvv, ok := vv.(string); ok && len(vvv) > 1 {
|
|
if vvv, ok := vv.(string); ok && len(vvv) > 1 {
|
|
tmpTopscopeclassMap[vvv[:len(vvv)-1]] = true
|
|
tmpTopscopeclassMap[vvv[:len(vvv)-1]] = true
|
|
|
|
+ tmpConTopscopeclass = append(tmpConTopscopeclass, vvv[:len(vvv)-1])
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- for k := range tmpTopscopeclassMap {
|
|
|
|
- tmpTopscopeclass = append(tmpTopscopeclass, k)
|
|
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
|
+ for k := range tmpTopscopeclassMap {
|
|
|
|
+ tmpTopscopeclass = append(tmpTopscopeclass, k)
|
|
}
|
|
}
|
|
sort.Strings(tmpTopscopeclass)
|
|
sort.Strings(tmpTopscopeclass)
|
|
|
|
+ esId := (*oldTmp)["_id"].(bson.ObjectId).Hex()
|
|
|
|
|
|
- esId := oldTmp["_id"].(primitive.ObjectID).Hex()
|
|
|
|
-
|
|
|
|
- //更新行业类型 buyerclass合并
|
|
|
|
- if tmp["buyerperson"] == nil || tmp["buyerperson"] == "" || Reg_xing.MatchString(util.ObjToString(tmp["buyerperson"])) {
|
|
|
|
|
|
|
|
- //更新buyerclass合并
|
|
|
|
- if tmp["buyerclass"] == nil || tmp["buyerclass"] == "" {
|
|
|
|
- //无值,不更新
|
|
|
|
|
|
+ //更新buyerclass合并
|
|
|
|
+ if tmp["buyerclass"] == nil || tmp["buyerclass"] == "" {
|
|
|
|
+ //无值,不更新
|
|
|
|
+ }else {
|
|
|
|
+ var buyerclass_new,buyerclass_old string
|
|
|
|
+ buyerclass_new = tmp["buyerclass"].(string)
|
|
|
|
+ buyerclass_old = (*oldTmp)["buyerclass"].(string)
|
|
|
|
+ if buyerclass_old=="" {
|
|
|
|
+ (*oldTmp)["buyerclass"] = buyerclass_new
|
|
}else {
|
|
}else {
|
|
- var buyerclass_new,buyerclass_old string
|
|
|
|
- buyerclass_new = tmp["buyerclass"].(string)
|
|
|
|
- buyerclass_old = oldTmp["buyerclass"].(string)
|
|
|
|
- if buyerclass_old=="" {
|
|
|
|
- oldTmp["buyerclass"] = buyerclass_new
|
|
|
|
- }else {
|
|
|
|
- if buyerclass_new!=buyerclass_old {
|
|
|
|
- if !strings.Contains(buyerclass_old, buyerclass_new) {
|
|
|
|
- oldTmp["buyerclass"] = buyerclass_old + ","+buyerclass_new //采购单位类型
|
|
|
|
- }
|
|
|
|
|
|
+ if buyerclass_new!=buyerclass_old {
|
|
|
|
+ if !strings.Contains(buyerclass_old, buyerclass_new) {
|
|
|
|
+ (*oldTmp)["buyerclass"] = buyerclass_old + ","+buyerclass_new //采购单位类型
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
|
|
- oldTmp["updatatime"] = time.Now().Unix()
|
|
|
|
|
|
+ //更新行业类型
|
|
|
|
+ if tmp["buyerperson"] == nil || tmp["buyerperson"] == "" || Reg_xing.MatchString(util.ObjToString(tmp["buyerperson"])) {
|
|
|
|
+
|
|
|
|
+ (*oldTmp)["updatatime"] = time.Now().Unix()
|
|
//mongo更新
|
|
//mongo更新
|
|
FClient.DbName = Config["mgodb_extract_kf"]
|
|
FClient.DbName = Config["mgodb_extract_kf"]
|
|
if !FClient.UpdateById(Config["mgo_qyk_buyer"], esId, bson.M{"$set": oldTmp}) {
|
|
if !FClient.UpdateById(Config["mgo_qyk_buyer"], esId, bson.M{"$set": oldTmp}) {
|
|
@@ -329,7 +311,7 @@ func TaskBuyer(mapinfo *map[string]interface{}) {
|
|
}
|
|
}
|
|
|
|
|
|
//es更新
|
|
//es更新
|
|
- delete(oldTmp, "_id")
|
|
|
|
|
|
+ delete((*oldTmp), "_id")
|
|
if _, err := EsConn.Update().Index(Config["elasticsearch_buyer_index"]).Type(Config["elasticsearch_buyer_type"]).Id(esId).Doc(oldTmp).Refresh(true).Do(); err != nil {
|
|
if _, err := EsConn.Update().Index(Config["elasticsearch_buyer_index"]).Type(Config["elasticsearch_buyer_type"]).Id(esId).Doc(oldTmp).Refresh(true).Do(); err != nil {
|
|
log.Println("update es err:", err)
|
|
log.Println("update es err:", err)
|
|
}
|
|
}
|
|
@@ -337,80 +319,41 @@ func TaskBuyer(mapinfo *map[string]interface{}) {
|
|
}
|
|
}
|
|
//联系方式合并
|
|
//联系方式合并
|
|
var tmpperson, buyertel string
|
|
var tmpperson, buyertel string
|
|
- tmpperson = tmp["buyerperson"].(string)
|
|
|
|
- if tmp["buyertel"] == nil || tmp["buyertel"] == "" {
|
|
|
|
|
|
+ if tmppersona, ok := tmp["buyerperson"].(string); ok {
|
|
|
|
+ tmpperson = tmppersona
|
|
|
|
+ }
|
|
|
|
+ if buyerteltmp, ok := tmp["buyertel"].(string); ok {
|
|
|
|
+ buyertel = buyerteltmp
|
|
|
|
+ }
|
|
|
|
+ if Reg_xing.MatchString(buyertel) || !Reg_tel.MatchString(buyertel) {
|
|
buyertel = ""
|
|
buyertel = ""
|
|
} else {
|
|
} else {
|
|
- if Reg_xing.MatchString(util.ObjToString(tmp["buyertel"])) || !Reg_tel.MatchString(util.ObjToString(tmp["buyertel"])) {
|
|
|
|
- buyertel = ""
|
|
|
|
- } else {
|
|
|
|
- buyertel = util.ObjToString(tmp["buyertel"])
|
|
|
|
- }
|
|
|
|
|
|
+ buyertel = buyertel
|
|
}
|
|
}
|
|
contactMaps := make([]interface{}, 0)
|
|
contactMaps := make([]interface{}, 0)
|
|
- if oldTmp["contact"] == nil {
|
|
|
|
- tmpContact := make(map[string]interface{})
|
|
|
|
- tmpContact["infoid"] = overid
|
|
|
|
- tmpContact["contact_person"] = tmpperson
|
|
|
|
- tmpContact["contact_type"] = "项目联系人"
|
|
|
|
- tmpContact["phone"] = buyertel
|
|
|
|
- tmpContact["topscopeclass"] = strings.Join(tmpTopscopeclass, ";")
|
|
|
|
- tmpContact["updatetime"] = time.Now().Unix()
|
|
|
|
- contactMaps = append(contactMaps, tmpContact)
|
|
|
|
- } else {
|
|
|
|
- //对比前四项,相等丢弃
|
|
|
|
- if v, ok := oldTmp["contact"].(primitive.A); ok {
|
|
|
|
- var isNotUpdate bool
|
|
|
|
- for _, vv := range v {
|
|
|
|
- if vvv, ok := vv.(map[string]interface{}); ok {
|
|
|
|
- if vvv["contact_person"] == tmpperson && vvv["contact_type"] == "项目联系人" &&
|
|
|
|
- vvv["phone"] == buyertel && vvv["topscopeclass"] == strings.Join(tmpTopscopeclass, ";") {
|
|
|
|
- isNotUpdate = true
|
|
|
|
- vvv["updatetime"] = time.Now().Unix()
|
|
|
|
- }
|
|
|
|
- contactMaps = append(contactMaps, vvv)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if !isNotUpdate {
|
|
|
|
- vvv := make(map[string]interface{})
|
|
|
|
- vvv["infoid"] = overid
|
|
|
|
- vvv["contact_person"] = tmp["buyerperson"]
|
|
|
|
- vvv["contact_type"] = "项目联系人"
|
|
|
|
- vvv["phone"] = buyertel
|
|
|
|
- vvv["topscopeclass"] = strings.Join(tmpTopscopeclass, ";")
|
|
|
|
- vvv["updatetime"] = time.Now().Unix()
|
|
|
|
- contactMaps = append(contactMaps, vvv)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- oldTmp["contact"] = contactMaps
|
|
|
|
-
|
|
|
|
- //更新buyerclass合并
|
|
|
|
- if tmp["buyerclass"] == nil || tmp["buyerclass"] == "" {
|
|
|
|
- //无值,不更新
|
|
|
|
- }else {
|
|
|
|
- var buyerclass_new,buyerclass_old string
|
|
|
|
- buyerclass_new = tmp["buyerclass"].(string)
|
|
|
|
- buyerclass_old = oldTmp["buyerclass"].(string)
|
|
|
|
- if buyerclass_old=="" {
|
|
|
|
- oldTmp["buyerclass"] = buyerclass_new
|
|
|
|
- }else {
|
|
|
|
- if buyerclass_new!=buyerclass_old {
|
|
|
|
- if !strings.Contains(buyerclass_old, buyerclass_new) {
|
|
|
|
- oldTmp["buyerclass"] = buyerclass_old + ","+buyerclass_new //采购单位类型
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ if (*oldTmp)["contact"] != nil {
|
|
|
|
+ //直接添加联系人,不再判断
|
|
|
|
+ if v, ok := (*oldTmp)["contact"].([]interface{}); ok {
|
|
|
|
+ contactMaps = append(contactMaps, v...)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ vvv := make(map[string]interface{})
|
|
|
|
+ vvv["infoid"] = overid
|
|
|
|
+ vvv["contact_person"] = tmpperson
|
|
|
|
+ vvv["contact_type"] = "项目联系人"
|
|
|
|
+ vvv["phone"] = buyertel
|
|
|
|
+ vvv["topscopeclass"] = strings.Join(tmpConTopscopeclass, ";")
|
|
|
|
+ vvv["updatetime"] = time.Now().Unix()
|
|
|
|
+ contactMaps = append(contactMaps, vvv)
|
|
|
|
+ (*oldTmp)["contact"] = contactMaps
|
|
//mongo更新
|
|
//mongo更新
|
|
- oldTmp["updatatime"] = time.Now().Unix()
|
|
|
|
|
|
+ (*oldTmp)["updatatime"] = time.Now().Unix()
|
|
FClient.DbName = Config["mgodb_extract_kf"]
|
|
FClient.DbName = Config["mgodb_extract_kf"]
|
|
if !FClient.UpdateById(Config["mgo_qyk_buyer"], esId, bson.M{"$set": oldTmp}) {
|
|
if !FClient.UpdateById(Config["mgo_qyk_buyer"], esId, bson.M{"$set": oldTmp}) {
|
|
log.Println("mongo更新 err", esId, oldTmp)
|
|
log.Println("mongo更新 err", esId, oldTmp)
|
|
}
|
|
}
|
|
//es更新
|
|
//es更新
|
|
- delete(oldTmp, "_id")
|
|
|
|
|
|
+ delete((*oldTmp), "_id")
|
|
if _, err := EsConn.Update().Index(Config["elasticsearch_buyer_index"]).Type(Config["elasticsearch_buyer_type"]).Id(esId).Doc(oldTmp).Refresh(true).Do(); err != nil {
|
|
if _, err := EsConn.Update().Index(Config["elasticsearch_buyer_index"]).Type(Config["elasticsearch_buyer_type"]).Id(esId).Doc(oldTmp).Refresh(true).Do(); err != nil {
|
|
log.Println("EsConn err :", err)
|
|
log.Println("EsConn err :", err)
|
|
}
|
|
}
|
|
@@ -421,9 +364,7 @@ func TaskBuyer(mapinfo *map[string]interface{}) {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-//定时任务
|
|
|
|
|
|
+//定时任务 新增
|
|
//1.存异常表
|
|
//1.存异常表
|
|
//2.合并原始库新增
|
|
//2.合并原始库新增
|
|
func TimedTaskBuyer() {
|
|
func TimedTaskBuyer() {
|
|
@@ -437,8 +378,7 @@ func TimedTaskBuyer() {
|
|
if !iter.Next(&tmpLast) {
|
|
if !iter.Next(&tmpLast) {
|
|
//临时表无数据
|
|
//临时表无数据
|
|
log.Println("临时表无数据:")
|
|
log.Println("临时表无数据:")
|
|
- //t2.Reset(time.Second * 10) //增量
|
|
|
|
- t2.Reset(time.Minute * 5) //存量
|
|
|
|
|
|
+ t2.Reset(time.Second * 15)
|
|
continue
|
|
continue
|
|
} else {
|
|
} else {
|
|
log.Println("临时表有数据:", tmpLast)
|
|
log.Println("临时表有数据:", tmpLast)
|
|
@@ -457,17 +397,18 @@ func TimedTaskBuyer() {
|
|
//遍历临时表数据,匹配不到原始库存入异常表
|
|
//遍历临时表数据,匹配不到原始库存入异常表
|
|
tmp := make(map[string]interface{})
|
|
tmp := make(map[string]interface{})
|
|
for cursor.Next(&tmp) {
|
|
for cursor.Next(&tmp) {
|
|
- tmpId := tmp["_id"].(primitive.ObjectID).Hex()
|
|
|
|
|
|
+ tmpId := tmp["_id"].(bson.ObjectId).Hex()
|
|
//再重新查找redis,存在发udp处理,不存在走新增合并
|
|
//再重新查找redis,存在发udp处理,不存在走新增合并
|
|
rdb := RedisPool.Get()
|
|
rdb := RedisPool.Get()
|
|
- rdb.Do("SELECT","2")
|
|
|
|
|
|
+ rdb.Do("SELECT", Config["redis_buyer_db"])
|
|
if _, err := redis.String(rdb.Do("GET", tmp["buyer"])); err == nil {
|
|
if _, err := redis.String(rdb.Do("GET", tmp["buyer"])); err == nil {
|
|
- //{"gtid":"57d7ad2f61a0721f152d2ad5","lteid":"5e20968d85a9271abf0ad6c2","stype":""}
|
|
|
|
//redis存在发送udp进行处理
|
|
//redis存在发送udp进行处理
|
|
by, _ := json.Marshal(map[string]interface{}{
|
|
by, _ := json.Marshal(map[string]interface{}{
|
|
- "gtid": tmpId,
|
|
|
|
- "lteid": tmpId,
|
|
|
|
- "stype": "",
|
|
|
|
|
|
+ "gtid": tmpId,
|
|
|
|
+ "lteid": tmpId,
|
|
|
|
+ "stype": "",
|
|
|
|
+ "data_type": "buyer",
|
|
|
|
+ "data_info": "add",
|
|
})
|
|
})
|
|
if e := udpclient.WriteUdp(by, mu.OP_TYPE_DATA, &net.UDPAddr{
|
|
if e := udpclient.WriteUdp(by, mu.OP_TYPE_DATA, &net.UDPAddr{
|
|
IP: net.ParseIP("127.0.0.1"),
|
|
IP: net.ParseIP("127.0.0.1"),
|
|
@@ -477,7 +418,7 @@ func TimedTaskBuyer() {
|
|
}
|
|
}
|
|
//存在的话删除tmp mongo表
|
|
//存在的话删除tmp mongo表
|
|
FClient.DbName = Config["mgodb_extract_kf"]
|
|
FClient.DbName = Config["mgodb_extract_kf"]
|
|
- if DeletedCount := FClient.DeleteById("buyer_new", tmpId); DeletedCount == 0 {
|
|
|
|
|
|
+ if DeletedCount := FClient.Del("buyer_new", bson.M{"_id": bson.ObjectIdHex(tmpId)}); !DeletedCount {
|
|
log.Println("删除临时表err:", DeletedCount)
|
|
log.Println("删除临时表err:", DeletedCount)
|
|
}
|
|
}
|
|
if err := rdb.Close(); err != nil {
|
|
if err := rdb.Close(); err != nil {
|
|
@@ -491,34 +432,34 @@ func TimedTaskBuyer() {
|
|
}
|
|
}
|
|
//查询redis不存在新增
|
|
//查询redis不存在新增
|
|
FClient.DbName = Config["mgodb_enterprise"]
|
|
FClient.DbName = Config["mgodb_enterprise"]
|
|
- //qyxy 企业库 两亿条
|
|
|
|
- resulttmp := FClient.FindOne(Config["mgodb_enterprise_c"], bson.M{"company_name": tmp["buyer"]})
|
|
|
|
- if resulttmp["_id"] == nil {
|
|
|
|
|
|
+
|
|
|
|
+ resulttmp, b := FClient.FindOne(Config["mgodb_enterprise_c"], bson.M{"company_name": tmp["buyer"]})
|
|
|
|
+ if !b || (*resulttmp)["_id"] == nil {
|
|
//log.Println(r)
|
|
//log.Println(r)
|
|
//匹配不到原始库,存入异常表删除临时表
|
|
//匹配不到原始库,存入异常表删除临时表
|
|
- FClient.DbName = Config["mgodb_extract_kf"]
|
|
|
|
- if saveid := FClient.Save("buyer_err", tmp); saveid == nil {
|
|
|
|
- log.Println("存入异常表错误", tmp)
|
|
|
|
|
|
+ log.Println(len(tmp),reflect.TypeOf(tmp))
|
|
|
|
+ fdmongo := FClient.GetMgoConn().DB(Config["mgodb_extract_kf"])
|
|
|
|
+ if err := fdmongo.C("buyer_err").Insert(tmp); err != nil {
|
|
|
|
+ log.Println("存入异常表错误", err, tmp)
|
|
}
|
|
}
|
|
- FClient.DbName = Config["mgodb_extract_kf"]
|
|
|
|
- if deleteNum := FClient.DeleteById("buyer_new", tmpId); deleteNum == 0 {
|
|
|
|
|
|
+ if deleteNum := fdmongo.C("buyer_new").RemoveId(bson.ObjectIdHex(tmpId)); !b {
|
|
log.Println("删除临时表错误", deleteNum)
|
|
log.Println("删除临时表错误", deleteNum)
|
|
}
|
|
}
|
|
continue
|
|
continue
|
|
} else {
|
|
} else {
|
|
//log.Println(123)
|
|
//log.Println(123)
|
|
//匹配到原始库,新增 resulttmp
|
|
//匹配到原始库,新增 resulttmp
|
|
- if resulttmp["credit_no"] != nil {
|
|
|
|
- if credit_no, ok := resulttmp["credit_no"].(string); ok && strings.TrimSpace(credit_no) != "" &&
|
|
|
|
|
|
+ if (*resulttmp)["credit_no"] != nil {
|
|
|
|
+ if credit_no, ok := (*resulttmp)["credit_no"].(string); ok && strings.TrimSpace(credit_no) != "" &&
|
|
len(strings.TrimSpace(credit_no)) > 8 {
|
|
len(strings.TrimSpace(credit_no)) > 8 {
|
|
dataNo := strings.TrimSpace(credit_no)[2:8]
|
|
dataNo := strings.TrimSpace(credit_no)[2:8]
|
|
if Addrs[dataNo] != nil {
|
|
if Addrs[dataNo] != nil {
|
|
if v, ok := Addrs[dataNo].(map[string]interface{}); ok {
|
|
if v, ok := Addrs[dataNo].(map[string]interface{}); ok {
|
|
- if resulttmp["province"] == nil || resulttmp["province"] == "" {
|
|
|
|
- resulttmp["province"] = v["province"]
|
|
|
|
|
|
+ if (*resulttmp)["province"] == nil || (*resulttmp)["province"] == "" {
|
|
|
|
+ (*resulttmp)["province"] = v["province"]
|
|
}
|
|
}
|
|
- resulttmp["city"] = v["city"]
|
|
|
|
- resulttmp["district"] = v["district"]
|
|
|
|
|
|
+ (*resulttmp)["city"] = v["city"]
|
|
|
|
+ (*resulttmp)["district"] = v["district"]
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -526,15 +467,15 @@ func TimedTaskBuyer() {
|
|
}
|
|
}
|
|
contacts := make([]map[string]interface{}, 0)
|
|
contacts := make([]map[string]interface{}, 0)
|
|
contact := make(map[string]interface{}, 0)
|
|
contact := make(map[string]interface{}, 0)
|
|
- if resulttmp["legal_person"] != nil {
|
|
|
|
- contact["contact_person"] = resulttmp["legal_person"] //联系人
|
|
|
|
|
|
+ if (*resulttmp)["legal_person"] != nil {
|
|
|
|
+ contact["contact_person"] = (*resulttmp)["legal_person"] //联系人
|
|
} else {
|
|
} else {
|
|
contact["contact_person"] = "" //联系人
|
|
contact["contact_person"] = "" //联系人
|
|
}
|
|
}
|
|
contact["contact_type"] = "法定代表人" //法定代表人
|
|
contact["contact_type"] = "法定代表人" //法定代表人
|
|
//log.Println(1)
|
|
//log.Println(1)
|
|
- if resulttmp["annual_reports"] != nil {
|
|
|
|
- bytes, err := json.Marshal(resulttmp["annual_reports"])
|
|
|
|
|
|
+ if (*resulttmp)["annual_reports"] != nil {
|
|
|
|
+ bytes, err := json.Marshal((*resulttmp)["annual_reports"])
|
|
if err != nil {
|
|
if err != nil {
|
|
log.Println("annual_reports err:", err)
|
|
log.Println("annual_reports err:", err)
|
|
}
|
|
}
|
|
@@ -566,24 +507,50 @@ func TimedTaskBuyer() {
|
|
contact["updatetime"] = time.Now().Unix() //更新时间
|
|
contact["updatetime"] = time.Now().Unix() //更新时间
|
|
contact["infoid"] = "" //招标信息id
|
|
contact["infoid"] = "" //招标信息id
|
|
contacts = append(contacts, contact)
|
|
contacts = append(contacts, contact)
|
|
- resulttmp["contact"] = contacts
|
|
|
|
|
|
+ //添加临时表匹配到的联系人
|
|
|
|
+ vvv := make(map[string]interface{})
|
|
|
|
+ vvv["infoid"] = tmp["_id"].(bson.ObjectId).Hex()
|
|
|
|
+ if tmp["buyerperson"] != nil {
|
|
|
|
+ vvv["contact_person"] = tmp["buyerperson"]
|
|
|
|
+ } else {
|
|
|
|
+ vvv["contact_person"] = ""
|
|
|
|
+ }
|
|
|
|
+ vvv["contact_type"] = "项目联系人"
|
|
|
|
+ // "buyer": 1, "buyertel": 1, "buyerperson": 1, "topscopeclass": 1 buyerclass : 1
|
|
|
|
+ if tmp["buyertel"] != nil {
|
|
|
|
+ vvv["phone"] = tmp["buyertel"]
|
|
|
|
+ } else {
|
|
|
|
+ vvv["phone"] = ""
|
|
|
|
+ }
|
|
|
|
+ tmpclass := make([]string, 0)
|
|
|
|
+ if tclasss, ok := tmp["topscopeclass"].([]string); ok {
|
|
|
|
+ for _, vv := range tclasss {
|
|
|
|
+ if len(vv) > 1 {
|
|
|
|
+ tmpclass = append(tmpclass, vv[:len(vv)-1])
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ vvv["topscopeclass"] = strings.Join(tmpclass, ";")
|
|
|
|
+ vvv["updatetime"] = time.Now().Unix()
|
|
|
|
+ contacts = append(contacts, vvv)
|
|
|
|
+ (*resulttmp)["contact"] = contacts
|
|
|
|
|
|
savetmp := make(map[string]interface{}, 0)
|
|
savetmp := make(map[string]interface{}, 0)
|
|
for _, sk := range BuyerFields {
|
|
for _, sk := range BuyerFields {
|
|
if sk == "_id" {
|
|
if sk == "_id" {
|
|
- savetmp["tmp"+sk] = resulttmp[sk]
|
|
|
|
|
|
+ savetmp["tmp"+sk] = (*resulttmp)[sk]
|
|
continue
|
|
continue
|
|
} else if sk == "area_code" {
|
|
} else if sk == "area_code" {
|
|
//行政区划代码
|
|
//行政区划代码
|
|
- savetmp[sk] = fmt.Sprint(resulttmp[sk])
|
|
|
|
|
|
+ savetmp[sk] = fmt.Sprint((*resulttmp)[sk])
|
|
continue
|
|
continue
|
|
} else if sk == "report_websites" {
|
|
} else if sk == "report_websites" {
|
|
//网址
|
|
//网址
|
|
- if resulttmp["report_websites"] == nil {
|
|
|
|
|
|
+ if (*resulttmp)["report_websites"] == nil {
|
|
savetmp["website"] = ""
|
|
savetmp["website"] = ""
|
|
} else {
|
|
} else {
|
|
report_websitesArr := []string{}
|
|
report_websitesArr := []string{}
|
|
- if ppms, ok := resulttmp[sk].(primitive.A); ok {
|
|
|
|
|
|
+ if ppms, ok := (*resulttmp)[sk].([]interface{}); ok {
|
|
for _, v := range ppms {
|
|
for _, v := range ppms {
|
|
if vvv, ok := v.(map[string]interface{}); ok {
|
|
if vvv, ok := v.(map[string]interface{}); ok {
|
|
if rv, ok := vvv["website_url"].(string); ok {
|
|
if rv, ok := vvv["website_url"].(string); ok {
|
|
@@ -599,46 +566,45 @@ func TimedTaskBuyer() {
|
|
} else if sk == "wechat_accounts" {
|
|
} else if sk == "wechat_accounts" {
|
|
savetmp[sk] = []interface{}{}
|
|
savetmp[sk] = []interface{}{}
|
|
continue
|
|
continue
|
|
- }else if sk=="buyer_name" {
|
|
|
|
- if resulttmp["company_name"] == nil {
|
|
|
|
|
|
+ } else if sk == "buyer_name" {
|
|
|
|
+ if (*resulttmp)["company_name"] == nil {
|
|
savetmp[sk] = ""
|
|
savetmp[sk] = ""
|
|
- }else {
|
|
|
|
- savetmp[sk] = resulttmp["company_name"]
|
|
|
|
|
|
+ } else {
|
|
|
|
+ savetmp[sk] = (*resulttmp)["company_name"]
|
|
}
|
|
}
|
|
continue
|
|
continue
|
|
- }else if sk=="address"{
|
|
|
|
- if resulttmp["company_address"] == nil {
|
|
|
|
|
|
+ } else if sk == "address" {
|
|
|
|
+ if (*resulttmp)["company_address"] == nil {
|
|
savetmp[sk] = ""
|
|
savetmp[sk] = ""
|
|
- }else {
|
|
|
|
- savetmp[sk] = resulttmp["company_address"]
|
|
|
|
|
|
+ } else {
|
|
|
|
+ savetmp[sk] = (*resulttmp)["company_address"]
|
|
}
|
|
}
|
|
continue
|
|
continue
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- if resulttmp[sk] == nil && sk != "history_name" && sk != "wechat_accounts" &&
|
|
|
|
|
|
+ if (*resulttmp)[sk] == nil && sk != "history_name" && sk != "wechat_accounts" &&
|
|
sk != "buyer_name" && sk != "address" &&
|
|
sk != "buyer_name" && sk != "address" &&
|
|
sk != "contact" && sk != "report_websites" {
|
|
sk != "contact" && sk != "report_websites" {
|
|
savetmp[sk] = ""
|
|
savetmp[sk] = ""
|
|
} else {
|
|
} else {
|
|
- savetmp[sk] = resulttmp[sk]
|
|
|
|
|
|
+ savetmp[sk] = (*resulttmp)[sk]
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//tmps = append(tmps, savetmp)
|
|
//tmps = append(tmps, savetmp)
|
|
savetmp["updatatime"] = time.Now().Unix()
|
|
savetmp["updatatime"] = time.Now().Unix()
|
|
//保存mongo
|
|
//保存mongo
|
|
FClient.DbName = Config["mgodb_extract_kf"]
|
|
FClient.DbName = Config["mgodb_extract_kf"]
|
|
|
|
+
|
|
saveid := FClient.Save(Config["mgo_qyk_buyer"], savetmp)
|
|
saveid := FClient.Save(Config["mgo_qyk_buyer"], savetmp)
|
|
- if saveid != nil {
|
|
|
|
|
|
+ if saveid != "" {
|
|
//保存redis
|
|
//保存redis
|
|
rc := RedisPool.Get()
|
|
rc := RedisPool.Get()
|
|
- rc.Do("SELECT","2")
|
|
|
|
- var _id string
|
|
|
|
- if v, ok := saveid.(primitive.ObjectID); ok {
|
|
|
|
- _id = v.Hex()
|
|
|
|
- }
|
|
|
|
- if _, err := rc.Do("SET", savetmp["buyer_name"], _id); err != nil {
|
|
|
|
|
|
+ rc.Do("SELECT", Config["redis_buyer_db"])
|
|
|
|
+ //var _id string
|
|
|
|
+ //if v, ok := saveid.(primitive.ObjectID); ok {
|
|
|
|
+ // _id = v.Hex()
|
|
|
|
+ //}
|
|
|
|
+ if _, err := rc.Do("SET", savetmp["buyer_name"], saveid); err != nil {
|
|
log.Println("save redis err:", tmp["_id"], savetmp["_id"], savetmp["buyer_name"], err)
|
|
log.Println("save redis err:", tmp["_id"], savetmp["_id"], savetmp["buyer_name"], err)
|
|
if err := rc.Close(); err != nil {
|
|
if err := rc.Close(); err != nil {
|
|
log.Println(err)
|
|
log.Println(err)
|
|
@@ -652,12 +618,12 @@ func TimedTaskBuyer() {
|
|
|
|
|
|
//esConn := elastic.GetEsConn()
|
|
//esConn := elastic.GetEsConn()
|
|
//defer elastic.DestoryEsConn(esConn)
|
|
//defer elastic.DestoryEsConn(esConn)
|
|
- if _, err := EsConn.Index().Index(Config["elasticsearch_buyer_index"]).Type(Config["elasticsearch_buyer_type"]).Id(_id).BodyJson(savetmp).Refresh(true).Do(); err != nil {
|
|
|
|
|
|
+ if _, err := EsConn.Index().Index(Config["elasticsearch_buyer_index"]).Type(Config["elasticsearch_buyer_type"]).Id(saveid).BodyJson(savetmp).Refresh(true).Do(); err != nil {
|
|
log.Println("save es err :", tmp["_id"], savetmp["_id"], err)
|
|
log.Println("save es err :", tmp["_id"], savetmp["_id"], err)
|
|
} else {
|
|
} else {
|
|
//删除临时表
|
|
//删除临时表
|
|
FClient.DbName = Config["mgodb_extract_kf"]
|
|
FClient.DbName = Config["mgodb_extract_kf"]
|
|
- if deleteNum := FClient.DeleteById("buyer_new", tmpId); deleteNum == 0 {
|
|
|
|
|
|
+ if deleteNum := FClient.Del("buyer_new", bson.M{"_id": bson.ObjectIdHex(tmpId)}); !deleteNum {
|
|
log.Println("删除临时表失败", deleteNum)
|
|
log.Println("删除临时表失败", deleteNum)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -666,9 +632,11 @@ func TimedTaskBuyer() {
|
|
log.Println("save mongo err:", saveid, tmp["_id"])
|
|
log.Println("save mongo err:", saveid, tmp["_id"])
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|
|
t2.Reset(time.Minute)
|
|
t2.Reset(time.Minute)
|
|
}
|
|
}
|
|
-}
|
|
|
|
|
|
+}
|