|
@@ -6,8 +6,6 @@ import (
|
|
|
"github.com/garyburd/redigo/redis"
|
|
|
"gopkg.in/mgo.v2/bson"
|
|
|
"log"
|
|
|
- mu "mfw/util"
|
|
|
- "net"
|
|
|
"qfw/util"
|
|
|
"sort"
|
|
|
"strings"
|
|
@@ -102,7 +100,6 @@ func TaskBuyer(mapinfo *map[string]interface{}) {
|
|
|
rdb.Do("SELECT", redis_buyer_db)
|
|
|
if reply, err := redis.String(rdb.Do("GET", redisCName)); err != nil {
|
|
|
//redis不存在,存到临时表,定时任务处理
|
|
|
- FClient.DbName = Config["mgodb_extract_kf"]
|
|
|
for _, vmap := range rValuesMaps {
|
|
|
vmap["_id"] = bson.ObjectIdHex(vmap["_id"].(string))
|
|
|
if err = FClient.SaveForOld("buyer_new", vmap); err != nil {
|
|
@@ -206,15 +203,11 @@ func TaskBuyer(mapinfo *map[string]interface{}) {
|
|
|
(*oldTmp)["contact"] = contactMaps
|
|
|
//mongo更新
|
|
|
(*oldTmp)["updatatime"] = time.Now().Unix()
|
|
|
- FClient.DbName = Config["mgodb_extract_kf"]
|
|
|
if !FClient.UpdateById(Config["mgo_qyk_buyer"], esId, bson.M{"$set": oldTmp}) {
|
|
|
log.Println("存量 mongo更新 err", esId, oldTmp)
|
|
|
}
|
|
|
//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("存量 EsConn err :", err)
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -225,139 +218,142 @@ func TaskBuyer(mapinfo *map[string]interface{}) {
|
|
|
overid := gtid
|
|
|
tmp := map[string]interface{}{}
|
|
|
for cursor.Next(&tmp) {
|
|
|
- overid = tmp["_id"].(bson.ObjectId).Hex()
|
|
|
- //log.Println(tmp["_id"])
|
|
|
- buyer, ok := tmp["buyer"].(string)
|
|
|
- if !ok || utf8.RuneCountInString(buyer) < 4 {
|
|
|
- continue
|
|
|
- }
|
|
|
- //redis查询是否存在
|
|
|
- rdb := RedisPool.Get()
|
|
|
- rdb.Do("SELECT", redis_buyer_db)
|
|
|
- if reply, err := redis.String(rdb.Do("GET", buyer)); err != nil {
|
|
|
- //redis不存在存到临时表,定时任务处理
|
|
|
- FClient.DbName = Config["mgodb_extract_kf"]
|
|
|
- if err := FClient.SaveForOld("buyer_new", tmp); err != nil {
|
|
|
- log.Println("FClient.Save err", err, tmp)
|
|
|
- }
|
|
|
- //log.Println("get redis id err:定时任务处理", err, tmp)
|
|
|
- if err := rdb.Close(); err != nil {
|
|
|
- log.Println(err)
|
|
|
- }
|
|
|
- continue
|
|
|
- } else {
|
|
|
- if err := rdb.Close(); err != nil {
|
|
|
- log.Println(err)
|
|
|
- }
|
|
|
- //拿到合并后的qyk
|
|
|
- FClient.DbName = Config["mgodb_extract_kf"]
|
|
|
- oldTmp, b := FClient.FindById(Config["mgo_qyk_buyer"], reply, bson.M{})
|
|
|
- if !b || (*oldTmp) == nil|| reply==""||(*oldTmp)["_id"]==nil{
|
|
|
- log.Println("redis id 不存在")
|
|
|
- continue
|
|
|
- }
|
|
|
- //比较合并
|
|
|
- //行业类型
|
|
|
- tmpTopscopeclass := []string{}
|
|
|
- tmpConTopscopeclass := []string{}
|
|
|
- tmpTopscopeclassMap := make(map[string]bool)
|
|
|
-
|
|
|
- if v, ok := tmp["topscopeclass"].([]interface{}); ok {
|
|
|
- for _, vv := range v {
|
|
|
- if vvv, ok := vv.(string); ok && len(vvv) > 1 {
|
|
|
- tmpTopscopeclassMap[vvv[:len(vvv)-1]] = true
|
|
|
- tmpConTopscopeclass = append(tmpConTopscopeclass, vvv[:len(vvv)-1])
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- for k := range tmpTopscopeclassMap {
|
|
|
- tmpTopscopeclass = append(tmpTopscopeclass, k)
|
|
|
- }
|
|
|
- sort.Strings(tmpTopscopeclass)
|
|
|
- esId := (*oldTmp)["_id"].(bson.ObjectId).Hex()
|
|
|
+ overid = AddBuyer(overid, tmp)
|
|
|
+ }
|
|
|
+ SourceClient.DestoryMongoConn(SourceClientcc)
|
|
|
+ log.Println("增量合并执行完成 ok", gtid, lteid, overid)
|
|
|
+ //发送udp 更新es段
|
|
|
+ }
|
|
|
|
|
|
- //更新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 tmp["buyerperson"] == nil || tmp["buyerperson"] == "" || Reg_xing.MatchString(util.ObjToString(tmp["buyerperson"])) {
|
|
|
|
|
|
- (*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)
|
|
|
- }
|
|
|
+//增量
|
|
|
+func AddBuyer(overid string, tmp map[string]interface{}) string {
|
|
|
+ overid = tmp["_id"].(bson.ObjectId).Hex()
|
|
|
+ buyer, ok := tmp["buyer"].(string)
|
|
|
+ if !ok || utf8.RuneCountInString(buyer) < 4 {
|
|
|
+ return overid
|
|
|
+ }
|
|
|
+ //redis查询是否存在
|
|
|
+ rdb := RedisPool.Get()
|
|
|
+ rdb.Do("SELECT", redis_buyer_db)
|
|
|
+ if reply, err := redis.String(rdb.Do("GET", buyer)); err != nil {
|
|
|
+ //redis不存在存到临时表,定时任务处理
|
|
|
+ if err := FClient.SaveForOld("buyer_new", tmp); err != nil {
|
|
|
+ log.Println("FClient.Save err", err, tmp)
|
|
|
+ }
|
|
|
+ //log.Println("get redis id err:定时任务处理", err, tmp)
|
|
|
+ if err := rdb.Close(); err != nil {
|
|
|
+ log.Println(err)
|
|
|
+ }
|
|
|
+ return overid
|
|
|
+ } else {
|
|
|
+ if err := rdb.Close(); err != nil {
|
|
|
+ log.Println(err)
|
|
|
+ }
|
|
|
+ //拿到合并后的qyk
|
|
|
+ oldTmp, b := FClient.FindById(Config["mgo_qyk_buyer"], reply, bson.M{})
|
|
|
+ if !b || (*oldTmp) == nil || reply == "" || (*oldTmp)["_id"] == nil {
|
|
|
+ log.Println("redis id 不存在", reply)
|
|
|
+ return overid
|
|
|
+ }
|
|
|
+ //比较合并 行业类型
|
|
|
+ tmpTopscopeclass := []string{}
|
|
|
+ tmpConTopscopeclass := []string{}
|
|
|
+ tmpTopscopeclassMap := make(map[string]bool)
|
|
|
|
|
|
- //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)
|
|
|
- }
|
|
|
- continue
|
|
|
- }
|
|
|
- //联系方式合并
|
|
|
- var tmpperson, buyertel string
|
|
|
- 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 = ""
|
|
|
- } else {
|
|
|
- buyertel = buyertel
|
|
|
+ if v, ok := tmp["topscopeclass"].([]interface{}); ok {
|
|
|
+ for _, vv := range v {
|
|
|
+ if vvv, ok := vv.(string); ok && len(vvv) > 1 {
|
|
|
+ tmpTopscopeclassMap[vvv[:len(vvv)-1]] = true
|
|
|
+ tmpConTopscopeclass = append(tmpConTopscopeclass, vvv[:len(vvv)-1])
|
|
|
}
|
|
|
- contactMaps := make([]interface{}, 0)
|
|
|
- if (*oldTmp)["contact"] != nil {
|
|
|
- //直接添加联系人,不再判断
|
|
|
- if v, ok := (*oldTmp)["contact"].([]interface{}); ok {
|
|
|
- contactMaps = append(contactMaps, v...)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for k := range tmpTopscopeclassMap {
|
|
|
+ tmpTopscopeclass = append(tmpTopscopeclass, k)
|
|
|
+ }
|
|
|
+ sort.Strings(tmpTopscopeclass)
|
|
|
+ esId := (*oldTmp)["_id"].(bson.ObjectId).Hex()
|
|
|
+
|
|
|
+ //更新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 //采购单位类型
|
|
|
}
|
|
|
}
|
|
|
- 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更新
|
|
|
- (*oldTmp)["updatatime"] = time.Now().Unix()
|
|
|
- FClient.DbName = Config["mgodb_extract_kf"]
|
|
|
- if !FClient.UpdateById(Config["mgo_qyk_buyer"], esId, bson.M{"$set": oldTmp}) {
|
|
|
- log.Println("mongo更新 err", esId, oldTmp)
|
|
|
- }
|
|
|
- //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("EsConn err :", err)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //更新行业类型
|
|
|
+ if tmp["buyerperson"] == nil || tmp["buyerperson"] == "" || Reg_xing.MatchString(util.ObjToString(tmp["buyerperson"])) {
|
|
|
+ (*oldTmp)["updatatime"] = time.Now().Unix()
|
|
|
+ //mongo更新
|
|
|
+ if !FClient.UpdateById(Config["mgo_qyk_buyer"], esId, bson.M{"$set": oldTmp}) {
|
|
|
+ log.Println("mongo更新err", esId)
|
|
|
+ }
|
|
|
+
|
|
|
+ //es更新
|
|
|
+ delete((*oldTmp), "_id")
|
|
|
+ return overid
|
|
|
+ }
|
|
|
+ //联系方式合并
|
|
|
+ contactMaps := make([]map[string]interface{}, 0)
|
|
|
+ if (*oldTmp)["contact"] != nil {
|
|
|
+ //直接添加联系人,不再判断
|
|
|
+ if v, ok := (*oldTmp)["contact"].([]interface{}); ok {
|
|
|
+ for _, vv := range v {
|
|
|
+ contactMaps = append(contactMaps, vv.(map[string]interface{}))
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- SourceClient.DestoryMongoConn(SourceClientcc)
|
|
|
+ var tmpperson, buyertel string
|
|
|
+ if tmppersona, ok := tmp["buyerperson"].(string); ok && tmpperson != "" && Reg_person.MatchString(tmpperson) && !Reg_xing.MatchString(tmpperson) {
|
|
|
+ tmpperson = tmppersona
|
|
|
+ }
|
|
|
+ if tmpperson != "" {
|
|
|
+ if buyerteltmp, ok := tmp["buyertel"].(string); ok {
|
|
|
+ buyertel = buyerteltmp
|
|
|
+ }
|
|
|
+ if Reg_xing.MatchString(buyertel) || !Reg_tel.MatchString(buyertel) {
|
|
|
+ buyertel = ""
|
|
|
+ } else {
|
|
|
+ buyertel = buyertel
|
|
|
+ }
|
|
|
|
|
|
- log.Println("增量合并执行完成 ok", gtid, lteid, overid)
|
|
|
+ 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)
|
|
|
+ }
|
|
|
+ //分包处理
|
|
|
+ if tmp["package"] != nil {
|
|
|
+ PackageDealWithBuyer(oldTmp, tmp, buyer)
|
|
|
+ }
|
|
|
+ (*oldTmp)["contact"] = contactMaps
|
|
|
+ //mongo更新
|
|
|
+ (*oldTmp)["updatatime"] = time.Now().Unix()
|
|
|
+ if !FClient.UpdateById(Config["mgo_qyk_buyer"], esId, bson.M{"$set": oldTmp}) {
|
|
|
+ log.Println("mongo更新 err", esId, oldTmp)
|
|
|
+ }
|
|
|
+ //es更新
|
|
|
+ delete((*oldTmp), "_id")
|
|
|
}
|
|
|
-
|
|
|
+ return overid
|
|
|
}
|
|
|
|
|
|
//定时任务 新增
|
|
@@ -373,11 +369,11 @@ func TimedTaskBuyer() {
|
|
|
if !iter.Next(&tmpLast) {
|
|
|
//临时表无数据
|
|
|
log.Println("临时表无数据:")
|
|
|
- t2.Reset(time.Minute * 5)
|
|
|
+ t2.Reset(time.Minute * 1)
|
|
|
FClient.DestoryMongoConn(Fcconn)
|
|
|
continue
|
|
|
} else {
|
|
|
- log.Println("临时表有数据:", tmpLast)
|
|
|
+ log.Println("临时表有数据:", tmpLast["_id"])
|
|
|
fconn := FClient.GetMgoConn(86400)
|
|
|
cursor := fconn.DB(Config["mgodb_extract_kf"]).C("buyer_new").Find(bson.M{
|
|
|
"_id": bson.M{
|
|
@@ -402,22 +398,9 @@ func TimedTaskBuyer() {
|
|
|
rdb := RedisPool.Get()
|
|
|
rdb.Do("SELECT", redis_buyer_db)
|
|
|
if _, err := redis.String(rdb.Do("GET", errbuyer)); err == nil {
|
|
|
- //redis存在发送udp进行处理
|
|
|
- by, _ := json.Marshal(map[string]interface{}{
|
|
|
- "gtid": tmpId,
|
|
|
- "lteid": tmpId,
|
|
|
- "stype": "",
|
|
|
- "data_type": "buyer",
|
|
|
- "data_info": "add",
|
|
|
- })
|
|
|
- if e := udpclient.WriteUdp(by, mu.OP_TYPE_DATA, &net.UDPAddr{
|
|
|
- IP: net.ParseIP("127.0.0.1"),
|
|
|
- Port: Updport,
|
|
|
- }); e != nil {
|
|
|
- log.Println(e)
|
|
|
- }
|
|
|
+ //增量合并
|
|
|
+ Add(tmpId, tmp)
|
|
|
//存在的话删除tmp mongo表
|
|
|
- FClient.DbName = Config["mgodb_extract_kf"]
|
|
|
if DeletedCount := FClient.Del("buyer_new", bson.M{"_id": bson.ObjectIdHex(tmpId)}); !DeletedCount {
|
|
|
log.Println("删除临时表err:", DeletedCount)
|
|
|
}
|
|
@@ -430,138 +413,160 @@ func TimedTaskBuyer() {
|
|
|
log.Println(err)
|
|
|
}
|
|
|
}
|
|
|
- //查询redis不存在新增
|
|
|
- FClient.DbName = Config["mgodb_enterprise"]
|
|
|
|
|
|
- resulttmp, b := FClient.FindOne(Config["mgodb_enterprise_c"], bson.M{"company_name": errbuyer})
|
|
|
- if !b || (*resulttmp)["_id"] == nil {
|
|
|
+ //查询redis不存在新增
|
|
|
+ sessionfinone := FClient.GetMgoConn()
|
|
|
+ resulttmp := make(map[string]interface{})
|
|
|
+ err := sessionfinone.DB(Config["mgodb_enterprise"]).C(Config["mgodb_enterprise_c"]).Find(bson.M{"company_name": errbuyer}).One(&resulttmp)
|
|
|
+ FClient.DestoryMongoConn(sessionfinone)
|
|
|
+ if err != nil || resulttmp["_id"] == nil {
|
|
|
//log.Println(r)
|
|
|
- //人工审核
|
|
|
+ //人工审核正则
|
|
|
var isok bool
|
|
|
- for _, v := range BuerRegOk {
|
|
|
+ //先遍历ok
|
|
|
+ for _, v := range BuyerRegOk {
|
|
|
isok = v.MatchString(errbuyer)
|
|
|
if isok {
|
|
|
- tmp["buyer_ok"] = 1
|
|
|
- break
|
|
|
+ //匹配ok完,匹配err
|
|
|
+ for _, vRegErr := range BuyerRegErr {
|
|
|
+ isok = vRegErr.MatchString(errbuyer)
|
|
|
+ //匹配到ok 也匹配到err 按err算
|
|
|
+ if isok {
|
|
|
+ tmp["buyer_err"] = 1
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //匹配ok,没匹配err 按ok算
|
|
|
+ if tmp["buyer_err"] == nil {
|
|
|
+ tmp["buyer_ok"] = 1
|
|
|
+ break
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- if tmp["buyer_ok"] == nil {
|
|
|
+ //都没匹配
|
|
|
+ if tmp["buyer_ok"] == nil && tmp["bnuyer_err"] == nil {
|
|
|
tmp["buyer_err"] = 1
|
|
|
}
|
|
|
//匹配不到原始库,存入异常表删除临时表
|
|
|
- FClient.DbName = Config["mgodb_extract_kf"]
|
|
|
if err := FClient.SaveForOld("buyer_err", tmp); err != nil {
|
|
|
log.Println("存入异常表错误", err, tmp)
|
|
|
}
|
|
|
- if deleteNum := FClient.Del("buyer_new", bson.M{"_id": bson.ObjectIdHex(tmpId)}); !b {
|
|
|
+ if deleteNum := FClient.Del("buyer_new", bson.M{"_id": bson.ObjectIdHex(tmpId)}); !deleteNum {
|
|
|
log.Println("删除临时表错误", deleteNum)
|
|
|
}
|
|
|
continue
|
|
|
} else {
|
|
|
//log.Println(123)
|
|
|
//匹配到原始库,新增 resulttmp buyer
|
|
|
- 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 {
|
|
|
dataNo := strings.TrimSpace(credit_no)[2:8]
|
|
|
if Addrs[dataNo] != nil {
|
|
|
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"]
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- contacts := make([]map[string]interface{}, 0)
|
|
|
- contact := make(map[string]interface{}, 0)
|
|
|
- if (*resulttmp)["legal_person"] != nil {
|
|
|
- contact["contact_person"] = (*resulttmp)["legal_person"] //联系人
|
|
|
- } else {
|
|
|
- contact["contact_person"] = "" //联系人
|
|
|
- }
|
|
|
- contact["contact_type"] = "法定代表人" //法定代表人
|
|
|
- //log.Println(1)
|
|
|
- if (*resulttmp)["annual_reports"] != nil {
|
|
|
- bytes, err := json.Marshal((*resulttmp)["annual_reports"])
|
|
|
- if err != nil {
|
|
|
- log.Println("annual_reports err:", err)
|
|
|
- }
|
|
|
- phonetmp := make([]map[string]interface{}, 0)
|
|
|
- err = json.Unmarshal(bytes, &phonetmp)
|
|
|
- if err != nil {
|
|
|
- log.Println("Unmarshal err:", err)
|
|
|
+
|
|
|
+ //行业类型
|
|
|
+ tmpclass := make([]string, 0)
|
|
|
+ if tclasss, ok := tmp["topscopeclass"].([]interface{}); ok {
|
|
|
+ for _, vv := range tclasss {
|
|
|
+ if vvv, ok := vv.(string); ok {
|
|
|
+ if len(vvv) > 1 {
|
|
|
+ tmpclass = append(tmpclass, vvv[:len(vvv)-1])
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- for _, vv := range phonetmp {
|
|
|
- if vv["company_phone"] != nil {
|
|
|
- if vv["company_phone"] == "" {
|
|
|
- continue
|
|
|
+ }
|
|
|
+ contacts := make([]map[string]interface{}, 0)
|
|
|
+ if legal_person, ok := resulttmp["legal_person"].(string); ok && legal_person != "" && !Reg_xing.MatchString(legal_person) && Reg_person.MatchString(legal_person) {
|
|
|
+ contact := make(map[string]interface{}, 0)
|
|
|
+ contact["contact_person"] = legal_person //联系人
|
|
|
+ contact["contact_type"] = "法定代表人" //法定代表人
|
|
|
+ if resulttmp["annual_reports"] != nil {
|
|
|
+ bytes, err := json.Marshal(resulttmp["annual_reports"])
|
|
|
+ if err != nil {
|
|
|
+ log.Println("annual_reports err:", err)
|
|
|
+ }
|
|
|
+ phonetmp := make([]map[string]interface{}, 0)
|
|
|
+ err = json.Unmarshal(bytes, &phonetmp)
|
|
|
+ if err != nil {
|
|
|
+ log.Println("Unmarshal err:", err)
|
|
|
+ }
|
|
|
+ for _, vv := range phonetmp {
|
|
|
+ if vv["company_phone"] != nil {
|
|
|
+ if vv["company_phone"] == "" {
|
|
|
+ continue
|
|
|
+ } else {
|
|
|
+ contact["phone"] = vv["company_phone"] //联系电话
|
|
|
+ break
|
|
|
+ }
|
|
|
} else {
|
|
|
- contact["phone"] = vv["company_phone"] //联系电话
|
|
|
- break
|
|
|
+ contact["phone"] = "" //联系电话
|
|
|
}
|
|
|
- } else {
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //log.Println(k, contact["phone"], resulttmp["_id"])
|
|
|
+ //time.Sleep(10 * time.Second)
|
|
|
+ if phone, ok := contact["phone"].(string); ok && phone != "" {
|
|
|
+ if Reg_xing.MatchString(phone) || !Reg_tel.MatchString(phone) {
|
|
|
contact["phone"] = "" //联系电话
|
|
|
}
|
|
|
-
|
|
|
+ } else {
|
|
|
+ contact["phone"] = "" //联系电话
|
|
|
}
|
|
|
+ contact["topscopeclass"] = "企业公示" //项目类型
|
|
|
+ contact["updatetime"] = time.Now().Unix() //更新时间
|
|
|
+ contact["infoid"] = "" //招标信息id
|
|
|
+ contacts = append(contacts, contact)
|
|
|
}
|
|
|
- //log.Println(k, contact["phone"], resulttmp["_id"])
|
|
|
- //time.Sleep(10 * time.Second)
|
|
|
- if contact["phone"] == nil {
|
|
|
- contact["phone"] = "" //联系电话
|
|
|
- }
|
|
|
- contact["topscopeclass"] = "企业公示" //项目类型
|
|
|
- contact["updatetime"] = time.Now().Unix() //更新时间
|
|
|
- contact["infoid"] = "" //招标信息id
|
|
|
- contacts = append(contacts, contact)
|
|
|
+
|
|
|
+
|
|
|
//添加临时表匹配到的联系人
|
|
|
- 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])
|
|
|
- }
|
|
|
+ if buyerperson, ok := tmp["buyerperson"].(string); ok && buyerperson != "" &&
|
|
|
+ !Reg_xing.MatchString(buyerperson) && Reg_person.MatchString(buyerperson) {
|
|
|
+ vvv := make(map[string]interface{})
|
|
|
+ vvv["infoid"] = tmp["_id"].(bson.ObjectId).Hex()
|
|
|
+ vvv["contact_person"] = buyerperson
|
|
|
+ vvv["contact_type"] = "项目联系人"
|
|
|
+ if buyertel, ok := tmp["buyertel"].(string); ok && !Reg_xing.MatchString(buyertel) && Reg_tel.MatchString(buyertel) {
|
|
|
+ vvv["phone"] = buyertel
|
|
|
+ } else {
|
|
|
+ vvv["phone"] = ""
|
|
|
}
|
|
|
+
|
|
|
+ vvv["topscopeclass"] = strings.Join(tmpclass, ";")
|
|
|
+ vvv["updatetime"] = time.Now().Unix()
|
|
|
+ contacts = append(contacts, vvv)
|
|
|
}
|
|
|
- vvv["topscopeclass"] = strings.Join(tmpclass, ";")
|
|
|
- vvv["updatetime"] = time.Now().Unix()
|
|
|
- contacts = append(contacts, vvv)
|
|
|
- (*resulttmp)["contact"] = contacts
|
|
|
+
|
|
|
+
|
|
|
|
|
|
savetmp := make(map[string]interface{}, 0)
|
|
|
for _, sk := range BuyerFields {
|
|
|
if sk == "_id" {
|
|
|
- savetmp["tmp"+sk] = (*resulttmp)[sk]
|
|
|
+ savetmp["tmp"+sk] = resulttmp[sk]
|
|
|
continue
|
|
|
} else if sk == "area_code" {
|
|
|
//行政区划代码
|
|
|
- savetmp[sk] = fmt.Sprint((*resulttmp)[sk])
|
|
|
+ savetmp[sk] = fmt.Sprint(resulttmp[sk])
|
|
|
continue
|
|
|
} else if sk == "report_websites" {
|
|
|
//网址
|
|
|
- if (*resulttmp)["report_websites"] == nil {
|
|
|
+ if resulttmp["report_websites"] == nil {
|
|
|
savetmp["website"] = ""
|
|
|
} else {
|
|
|
report_websitesArr := []string{}
|
|
|
- if ppms, ok := (*resulttmp)[sk].([]interface{}); ok {
|
|
|
+ if ppms, ok := resulttmp[sk].([]interface{}); ok {
|
|
|
for _, v := range ppms {
|
|
|
if vvv, ok := v.(map[string]interface{}); ok {
|
|
|
if rv, ok := vvv["website_url"].(string); ok {
|
|
@@ -578,17 +583,17 @@ func TimedTaskBuyer() {
|
|
|
savetmp[sk] = []interface{}{}
|
|
|
continue
|
|
|
} else if sk == "buyer_name" {
|
|
|
- if (*resulttmp)["company_name"] == nil {
|
|
|
+ if resulttmp["company_name"] == nil {
|
|
|
savetmp[sk] = ""
|
|
|
} else {
|
|
|
- savetmp[sk] = (*resulttmp)["company_name"]
|
|
|
+ savetmp[sk] = resulttmp["company_name"]
|
|
|
}
|
|
|
continue
|
|
|
} else if sk == "address" {
|
|
|
- if (*resulttmp)["company_address"] == nil {
|
|
|
+ if resulttmp["company_address"] == nil {
|
|
|
savetmp[sk] = ""
|
|
|
} else {
|
|
|
- savetmp[sk] = (*resulttmp)["company_address"]
|
|
|
+ savetmp[sk] = resulttmp["company_address"]
|
|
|
}
|
|
|
continue
|
|
|
}else if sk == "buyerclass" {
|
|
@@ -601,57 +606,45 @@ func TimedTaskBuyer() {
|
|
|
}
|
|
|
|
|
|
|
|
|
- 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 != "buyerclass"&&
|
|
|
sk != "contact" && sk != "report_websites" {
|
|
|
savetmp[sk] = ""
|
|
|
} else {
|
|
|
- savetmp[sk] = (*resulttmp)[sk]
|
|
|
+ savetmp[sk] = resulttmp[sk]
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ //判断分包
|
|
|
+ if tmp["package"] != nil {
|
|
|
+ PackageDealWithBuyer(&savetmp, tmp, errbuyer)
|
|
|
+ }
|
|
|
//tmps = append(tmps, savetmp)
|
|
|
+ savetmp["comeintime"] = time.Now().Unix()
|
|
|
savetmp["updatatime"] = time.Now().Unix()
|
|
|
//保存mongo
|
|
|
- FClient.DbName = Config["mgodb_extract_kf"]
|
|
|
-
|
|
|
saveid := FClient.Save(Config["mgo_qyk_buyer"], savetmp)
|
|
|
if saveid != "" {
|
|
|
//保存redis
|
|
|
rc := RedisPool.Get()
|
|
|
rc.Do("SELECT", 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)
|
|
|
- if err := rc.Close(); err != nil {
|
|
|
- log.Println(err)
|
|
|
- }
|
|
|
} else {
|
|
|
- //保存es
|
|
|
- delete(savetmp, "_id")
|
|
|
- if err := rc.Close(); err != nil {
|
|
|
- log.Println(err)
|
|
|
- }
|
|
|
-
|
|
|
- //esConn := elastic.GetEsConn()
|
|
|
- //defer elastic.DestoryEsConn(esConn)
|
|
|
- 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)
|
|
|
- } else {
|
|
|
- //删除临时表
|
|
|
- FClient.DbName = Config["mgodb_extract_kf"]
|
|
|
- if deleteNum := FClient.Del("buyer_new", bson.M{"_id": bson.ObjectIdHex(tmpId)}); !deleteNum {
|
|
|
- log.Println("删除临时表失败", deleteNum)
|
|
|
- }
|
|
|
+ //删除临时表
|
|
|
+ if deleteNum := FClient.Del("buyer_new", bson.M{"_id": bson.ObjectIdHex(tmpId)}); !deleteNum {
|
|
|
+ log.Println("删除临时表失败", deleteNum)
|
|
|
}
|
|
|
}
|
|
|
+ if err := rc.Close(); err != nil {
|
|
|
+ log.Println(err)
|
|
|
+ }
|
|
|
} else {
|
|
|
log.Println("save mongo err:", saveid, tmp["_id"])
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
FClient.DestoryMongoConn(fconn)
|
|
|
log.Println("buyer_new,遍历完成")
|
|
@@ -661,3 +654,14 @@ func TimedTaskBuyer() {
|
|
|
t2.Reset(time.Minute)
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+//分包处理
|
|
|
+func PackageDealWithBuyer(contactMap *map[string]interface{}, tmp map[string]interface{}, comName string) []interface{} {
|
|
|
+ util.Catch()
|
|
|
+ //if v, ok := tmp["package"].(map[string]interface{}); ok {
|
|
|
+ //for i, pv := range v {
|
|
|
+ // log.Println(i, pv)
|
|
|
+ //}
|
|
|
+ //}
|
|
|
+ return nil
|
|
|
+}
|