123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746 |
- package main
- import (
- "encoding/json"
- "fmt"
- "github.com/garyburd/redigo/redis"
- "gopkg.in/mgo.v2/bson"
- "log"
- util2 "mfw/util"
- "net"
- "qfw/util"
- "sort"
- "strings"
- "time"
- "unicode/utf8"
- )
- //之前main方法,只更新
- func TaskWinner(mapinfo *map[string]interface{}) {
- defer util.Catch()
- gtid, lteid := util.ObjToString((*mapinfo)["gtid"]), util.ObjToString((*mapinfo)["lteid"])
- if gtid == "" || lteid == "" {
- log.Println(gtid, lteid, "参数错误")
- return
- }
- 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
- }
- //timenow := time.Now().Unix()
- //udp的id区间查询bidding 中标人 中标联系人 中标联系电话
- // topscopeclass项目类型-industry行业类型&&topscopeclass联系人项目类型
- // (area地区-province省份 city城市-city城市 district区县-district区县)
- // winneraddr-company_address企业地址
- SourceClientcc := SourceClient.GetMgoConn(8640000)
- cursor := SourceClientcc.DB(Config["mgodb_bidding"]).C(Config["mgodb_mgoinit_c"]).Find(bson.M{
- "_id": bson.M{
- "$gte": GId,
- "$lte": LtId,
- },
- }).Select(bson.M{"winner": 1, "winnertel": 1, "winnerperson": 1, "topscopeclass": 1, "package": 1}).Iter()
- if cursor.Err() != nil {
- SourceClient.DestoryMongoConn(SourceClientcc)
- log.Println(cursor.Err())
- return
- }
- //判断是否是存量,是存量走Redis遍历
- if v, ok := (*mapinfo)["data_info"].(string); ok && v == "save" {
- //存量处理
- conn := HisRedisPool.Conn()
- defer conn.Close()
- //选择redis db
- conn.Select(redis_winner_db)
- //遍历bidding表保存到redis
- //key:企业名 value:json结构体{"winner": 1, "winnertel": 1, "winnerperson": 1,"topscopeclass": 1, "winneraddr": 1,"_id":1}
- tmp := make(map[string]interface{})
- var num int
- var tmpRangeId string
- for cursor.Next(&tmp) {
- num++
- mgoId := tmp["_id"].(bson.ObjectId).Hex()
- tmpRangeId = mgoId
- winner, ok := tmp["winner"].(string)
- if !ok || utf8.RuneCountInString(winner) < 4 {
- continue
- }
- //判断redis key是否存在
- e_num := conn.Exists(winner).Val()
- //获取字符串_id
- //替换_id
- tmp["_id"] = mgoId
- //创建value数组
- tmps := make([]map[string]interface{}, 0)
- //存量删除分包
- if v, ok := tmp["package"].(map[string]interface{}); ok {
- for i, vv := range v {
- if vvv, ok2 := vv.(map[string]interface{}); ok2 {
- if pwinner, ok := vvv["winner"].(string); ok && pwinner != "" {
- if pwinper, ok4 := vvv["winnerperson"].(string); ok4 && pwinper != "" {
- ptmp := make(map[string]interface{})
- ptmp["p_id"] = mgoId + "_pkg_" + i
- ptmp["_id"] = bson.NewObjectId().Hex()
- ptmp["winner"] = winner
- ptmp["winnerperson"] = pwinper
- if pkgtel, ok6 := vvv["winnertel"].(string); ok6 {
- ptmp["winnertel"] = pkgtel
- }
- if tmp["topscopeclass"] != nil {
- ptmp["topscopeclass"] = tmp["topscopeclass"]
- }
- //分包里中标单位和企业名一样
- if pwinner == winner {
- tmps = append(tmps, ptmp)
- } else if conn.Exists(pwinner).Val() > 0 {
- //分包里中标单位和企业名不一样,存量里匹配上了
- bytes, _ := conn.Get(pwinner).Bytes()
- cltmps := make([]map[string]interface{}, 0)
- json.Unmarshal(bytes, &cltmps)
- cltmps = append(cltmps, ptmp)
- bytes2, _ := json.Marshal(cltmps)
- //存量redis的key存在,合并 key :企业名 val :[]map
- if err := conn.Set(pwinner, string(bytes2), 0).Err(); err != nil {
- log.Println(err)
- }
- } else {
- //分包和企业名不一样,而且存量没匹配上
- cltmps := make([]map[string]interface{}, 0)
- cltmps = append(cltmps, ptmp)
- bytes2, _ := json.Marshal(cltmps)
- //存量redis的key新增,新增 key :企业名 val :[]map
- if err := conn.Set(pwinner, string(bytes2), 0).Err(); err != nil {
- log.Println(err)
- }
- }
- }
- }
- }
- }
- delete(tmp, "package")
- }
- if e_num > 0 {
- //存量redis的key存在,累加更新
- bytes, _ := conn.Get(winner).Bytes()
- json.Unmarshal(bytes, &tmps)
- }
- tmps = append(tmps, tmp)
- bytes, _ := json.Marshal(tmps)
- //存量redis的key不存在,新增 key :企业名 val :[]map
- if err := conn.Set(winner, string(bytes), 0).Err(); err != nil {
- log.Println(err)
- }
- }
- log.Println("存量 winner mongo遍历完成:", num)
- if tmpRangeId != lteid{
- by, _ := json.Marshal(map[string]interface{}{
- "gtid": tmpRangeId,
- "lteid": lteid,
- "data_info":"save",
- "stype": "winner",
- })
- if e := udpclient.WriteUdp(by, util2.OP_TYPE_DATA, &net.UDPAddr{
- IP: net.ParseIP("127.0.0.1"),
- Port: Updport,
- }); e != nil {
- log.Println(e)
- }
- SourceClient.DestoryMongoConn(SourceClientcc)
- return
- }
- SourceClient.DestoryMongoConn(SourceClientcc)
- //遍历redis
- if scan := conn.Scan(0, "", 100); scan.Err() != nil {
- log.Println(scan.Err())
- return
- } else {
- iterator := scan.Iterator()
- for iterator.Next() {
- redisCName := iterator.Val() //redis key 企业名
- redisvalueBytes, _ := conn.Get(redisCName).Bytes() //redis val []数组
- rValuesMaps := make([]map[string]interface{}, 0)
- json.Unmarshal(redisvalueBytes, &rValuesMaps)
- //redis查询是否存在
- rdb := RedisPool.Get()
- rdb.Do("SELECT", redis_winner_db)
- if reply, err := redis.String(rdb.Do("GET", redisCName)); err != nil {
- //redis不存在,存到临时表,定时任务处理
- for _, vmap := range rValuesMaps {
- vmap["_id"] = bson.ObjectIdHex(vmap["_id"].(string))
- if errb := FClient.SaveByOriID(Config["mgo_qyk_c_w_new"], vmap); !errb {
- log.Println("存量 FClient.Save err", errb, vmap)
- }
- }
- //log.Println("get redis id err:定时任务处理", err, tmp)
- if err := rdb.Close(); err != nil {
- log.Println("存量", err)
- }
- continue
- } else {
- //redis存在更新合并
- if err := rdb.Close(); err != nil {
- log.Println(err)
- }
- //拿到合并后的qyk
- oldTmp, b := FClient.FindById(Config["mgo_qyk_c"], reply, nil)
- if !b || (*oldTmp) == nil || reply == "" || (*oldTmp)["_id"] == nil {
- log.Println(redisCName, "存量 redis id 不存在", reply)
- continue
- }
- tmpTopscopeclass := []string{}
- tmpTopscopeclassMap := make(map[string]bool)
- if (*oldTmp)["industry"] != nil {
- if v, ok := (*oldTmp)["industry"].([]interface{}); ok {
- for _, vv := range v {
- if vvv, ok := vv.(string); ok {
- tmpTopscopeclassMap[vvv] = 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)
- }
- sort.Strings(tmpTopscopeclass)
- (*oldTmp)["industry"] = tmpTopscopeclass
- esId := (*oldTmp)["_id"].(bson.ObjectId).Hex()
- //联系方式合并
- contactMaps := make([]interface{}, 0)
- if (*oldTmp)["contact"] != nil {
- //直接添加联系人,不再判断
- if v, ok := (*oldTmp)["contact"].([]interface{}); ok {
- contactMaps = append(contactMaps, v...)
- }
- }
- //遍历redis value联系人
- for _, rvmap := range rValuesMaps {
- var tmpperson, winnertel string
- if rvmapperson, ok := rvmap["winnerperson"].(string); ok && utf8.RuneCountInString(rvmapperson)>=2 && rvmapperson != "" {
- tmpperson = rvmapperson
- } else {
- continue
- }
- if rvmapwintel, ok := rvmap["winnertel"].(string); ok {
- winnertel = rvmapwintel
- } else {
- winnertel = ""
- }
- if Reg_xing.MatchString(winnertel) || !Reg_tel.MatchString(winnertel) {
- winnertel = ""
- }
- tmpContact := make(map[string]interface{})
- tmpContact["infoid"] = rvmap["_id"]
- tmpContact["contact_person"] = tmpperson
- tmpContact["contact_type"] = "项目联系人"
- tmpContact["phone"] = winnertel
- 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更新
- (*oldTmp)["updatatime"] = time.Now().Unix()
- if !FClient.UpdateById(Config["mgo_qyk_c"], esId, bson.M{"$set": oldTmp}) {
- log.Println("存量 mongo更新 err", esId, oldTmp)
- }
- //es更新
- delete((*oldTmp), "_id")
- }
- }
- }
- log.Println("存量历史合并执行完成 ok", gtid, lteid)
- //发送udp 更新es段
- } else {
- //增量处理
- overid := gtid
- tmp := map[string]interface{}{}
- for cursor.Next(&tmp) {
- overid = Add(overid, tmp)
- }
- SourceClient.DestoryMongoConn(SourceClientcc)
- log.Println("增量合并执行完成 ok", gtid, lteid, overid)
- //发送udp 更新es段
- //nextNode("winnerent", timenow)
- }
- }
- //增量
- func Add(overid string, tmp map[string]interface{}) string {
- overid = tmp["_id"].(bson.ObjectId).Hex()
- winner, ok := tmp["winner"].(string)
- if !ok || utf8.RuneCountInString(winner) < 4 {
- return overid
- }
- //redis查询是否存在
- rdb := RedisPool.Get()
- rdb.Do("SELECT", redis_winner_db)
- if reply, err := redis.String(rdb.Do("GET", winner)); err != nil {
- //redis不存在存到临时表,定时任务处理
- if errb := FClient.SaveByOriID(Config["mgo_qyk_c_w_new"], tmp); !errb {
- log.Println("FClient.Save err", errb, 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_c"], 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)
- if (*oldTmp)["industry"] != nil {
- if v, ok := (*oldTmp)["industry"].([]interface{}); ok {
- for _, vv := range v {
- if vvv, ok := vv.(string); ok {
- tmpTopscopeclassMap[vvv] = true
- }
- }
- }
- }
- 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)
- (*oldTmp)["industry"] = tmpTopscopeclass
- esId := (*oldTmp)["_id"].(bson.ObjectId).Hex()
- //更新行业类型
- if tmp["winnerperson"] == nil || tmp["winnerperson"] == "" || Reg_xing.MatchString(util.ObjToString(tmp["winnerperson"])) {
- (*oldTmp)["updatatime"] = time.Now().Unix()
- //mongo更新
- if !FClient.UpdateById(Config["mgo_qyk_c"], 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{}))
- }
- }
- }
- var tmpperson, winnertel string
- if tmppersona, ok := tmp["winnerperson"].(string); ok && utf8.RuneCountInString(tmppersona)>=2 && tmppersona != "" && Reg_person.MatchString(tmppersona) && !Reg_xing.MatchString(tmppersona) {
- tmpperson = tmppersona
- }
- if tmpperson != "" {
- if winnerteltmp, ok := tmp["winnertel"].(string); ok {
- winnertel = winnerteltmp
- }
- if Reg_xing.MatchString(winnertel) || !Reg_tel.MatchString(winnertel) {
- winnertel = ""
- } else {
- winnertel = winnertel
- }
- vvv := make(map[string]interface{})
- vvv["infoid"] = overid
- vvv["contact_person"] = tmpperson
- vvv["contact_type"] = "项目联系人"
- vvv["phone"] = winnertel
- vvv["topscopeclass"] = strings.Join(tmpConTopscopeclass, ";")
- vvv["updatetime"] = time.Now().Unix()
- contactMaps = append(contactMaps, vvv)
- }
- //分包处理
- if tmp["package"] != nil {
- PackageDealWith(tmp, tmpConTopscopeclass, overid)
- }
- (*oldTmp)["contact"] = contactMaps
- //mongo更新
- (*oldTmp)["updatatime"] = time.Now().Unix()
- if !FClient.UpdateById(Config["mgo_qyk_c"], esId, bson.M{"$set": oldTmp}) {
- log.Println("mongo更新 err", esId, oldTmp)
- }
- //es更新
- delete((*oldTmp), "_id")
- }
- return overid
- }
- //定时任务 新增
- //1.存异常表
- //2.合并原始库新增
- func TimedTaskWinner() {
- //time.Sleep(time.Hour*70)
- t2 := time.NewTimer(time.Second * 5)
- for range t2.C {
- //timenow:=time.Now().Unix()
- Fcconn := FClient.GetMgoConn(86400)
- tmpLast := map[string]interface{}{}
- if iter := Fcconn.DB(Config["mgodb_extract_kf"]).C(Config["mgo_qyk_c_w_new"]).Find(bson.M{}).Sort("-_id").Limit(1).Iter(); iter != nil {
- if !iter.Next(&tmpLast) {
- //临时表无数据
- log.Println("临时表无数据:")
- t2.Reset(time.Minute * 5)
- FClient.DestoryMongoConn(Fcconn)
- continue
- } else {
- log.Println("临时表有数据:", tmpLast["_id"])
- fconn := FClient.GetMgoConn(86400)
- cursor := fconn.DB(Config["mgodb_extract_kf"]).C(Config["mgo_qyk_c_w_new"]).Find(bson.M{
- "_id": bson.M{
- "$lte": tmpLast["_id"],
- },
- }).Sort("_id").Iter()
- if cursor == nil {
- log.Println("查询失败")
- t2.Reset(time.Second * 5)
- FClient.DestoryMongoConn(fconn)
- continue
- }
- //遍历临时表数据,匹配不到原始库存入异常表
- tmp := make(map[string]interface{})
- for cursor.Next(&tmp) {
- tmpId := tmp["_id"].(bson.ObjectId).Hex()
- errwinner, ok := tmp["winner"].(string)
- if !ok || errwinner == "" {
- continue
- }
- //再重新查找redis,存在发udp处理,不存在走新增合并
- rdb := RedisPool.Get()
- rdb.Do("SELECT", redis_winner_db)
- if _, err := redis.String(rdb.Do("GET", errwinner)); err == nil {
- //增量合并
- Add(tmpId, tmp)
- //存在的话删除tmp mongo表
- if DeletedCount := FClient.Del(Config["mgo_qyk_c_w_new"], bson.M{"_id": bson.ObjectIdHex(tmpId)}); !DeletedCount {
- log.Println("删除临时表err:", DeletedCount)
- }
- if err := rdb.Close(); err != nil {
- log.Println(err)
- }
- continue
- } else {
- if err = rdb.Close(); err != nil {
- log.Println(err)
- }
- }
- //查询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": errwinner}).One(&resulttmp)
- FClient.DestoryMongoConn(sessionfinone)
- if err != nil || resulttmp["_id"] == nil {
- //log.Println(r)
- //人工审核正则
- var isok bool
- //先遍历ok
- for _, v := range WinnerRegOk {
- isok = v.MatchString(errwinner)
- if isok {
- //匹配ok完,匹配err
- for _, vRegErr := range WinnerRegErr {
- isok = vRegErr.MatchString(errwinner)
- //匹配到ok 也匹配到err 按err算
- if isok {
- tmp["winner_err"] = 1
- break
- }
- }
- //匹配ok,没匹配err 按ok算
- if tmp["winner_err"] == nil {
- tmp["winner_ok"] = 1
- break
- }
- }
- }
- //都没匹配
- if tmp["winner_ok"] == nil && tmp["winner_err"] == nil {
- tmp["winner_err"] = 1
- }
- //匹配不到原始库,存入异常表删除临时表
- if errb := FClient.SaveByOriID(Config["mgo_qyk_c_w_err"], tmp); !errb {
- log.Println("存入异常表错误", errb, tmp)
- }
- if deleteNum := FClient.Del(Config["mgo_qyk_c_w_new"], bson.M{"_id": bson.ObjectIdHex(tmpId)}); !deleteNum {
- log.Println("删除临时表错误", deleteNum)
- }
- continue
- } else {
- //log.Println(123)
- //匹配到原始库,新增 resulttmp
- 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"]
- }
- resulttmp["city"] = v["city"]
- resulttmp["district"] = v["district"]
- }
- }
- }
- }
- //行业类型
- 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])
- }
- }
- }
- }
- contacts := make([]map[string]interface{}, 0)
- if legal_person, ok := resulttmp["legal_person"].(string); ok && utf8.RuneCountInString(legal_person)>=2 && 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"] = "" //联系电话
- }
- }
- }
- //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)
- }
- //添加临时表匹配到的联系人
- if winnerperson, ok := tmp["winnerperson"].(string); ok && utf8.RuneCountInString(winnerperson)>=2 && winnerperson != "" &&
- !Reg_xing.MatchString(winnerperson) && Reg_person.MatchString(winnerperson) {
- vvv := make(map[string]interface{})
- vvv["infoid"] = tmp["_id"].(bson.ObjectId).Hex()
- vvv["contact_person"] = winnerperson
- vvv["contact_type"] = "项目联系人"
- // "winner": 1, "winnertel": 1, "winnerperson": 1, "topscopeclass": 1
- if winnertel, ok := tmp["winnertel"].(string); ok && !Reg_xing.MatchString(winnertel) && Reg_tel.MatchString(winnertel) {
- vvv["phone"] = winnertel
- } else {
- vvv["phone"] = ""
- }
- 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 Fields {
- if sk == "establish_date" {
- if resulttmp[sk] != nil {
- savetmp[sk] = resulttmp[sk].(time.Time).UTC().Unix()
- continue
- }
- } else if sk == "capital" {
- //log.Println(sk, resulttmp[sk])
- savetmp[sk] = ObjToMoney([]interface{}{resulttmp[sk], ""})[0]
- continue
- } else if sk == "partners" {
- //log.Println(sk, resulttmp[sk], )
- if resulttmp[sk] != nil {
- if ppms, ok := resulttmp[sk].([]interface{}); ok {
- for i, _ := range ppms {
- if ppms[i].(map[string]interface{})["stock_type"] != nil {
- ppms[i].(map[string]interface{})["stock_type"] = "企业公示"
- }
- delete(ppms[i].(map[string]interface{}), "identify_type")
- }
- savetmp[sk] = ppms
- }
- } else {
- savetmp[sk] = []interface{}{}
- }
- continue
- } else if sk == "_id" {
- savetmp["tmp"+sk] = resulttmp[sk]
- continue
- } else if sk == "area_code" {
- //行政区划代码
- savetmp[sk] = fmt.Sprint(resulttmp[sk])
- continue
- } else if sk == "report_websites" {
- //网址
- if resulttmp["report_websites"] == nil {
- savetmp["website"] = ""
- } else {
- report_websitesArr := []string{}
- 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 {
- report_websitesArr = append(report_websitesArr, rv)
- }
- }
- }
- }
- sort.Strings(report_websitesArr)
- savetmp["website"] = strings.Join(report_websitesArr, ";")
- }
- continue
- } else if sk == "wechat_accounts" {
- savetmp[sk] = []interface{}{}
- continue
- } else if sk == "industry" {
- tmpTopscopeclass := make([]string, 0)
- if v, ok := tmp["topscopeclass"].([]interface{}); ok {
- for _, vv := range v {
- if vvv, ok := vv.(string); ok && len(vvv) > 1 {
- tmpTopscopeclass = append(tmpTopscopeclass, vvv[:len(vvv)-1])
- }
- }
- }
- sort.Strings(tmpTopscopeclass)
- savetmp[sk] = tmpTopscopeclass
- continue
- }
- if resulttmp[sk] == nil && sk != "history_name" && sk != "wechat_accounts" && sk != "establish_date" && sk != "capital" && sk != "partners" && sk != "contact" && sk != "report_websites" {
- savetmp[sk] = ""
- } else {
- savetmp[sk] = resulttmp[sk]
- }
- }
- //判断分包
- if tmp["package"] != nil {
- PackageDealWith(tmp,tmpclass, tmpId)
- }
- //tmps = append(tmps, savetmp)
- savetmp["comeintime"] = time.Now().Unix()
- savetmp["updatatime"] = time.Now().Unix()
- //保存mongo
- saveid := FClient.Save(Config["mgo_qyk_c"], savetmp)
- if saveid != "" {
- //保存redis
- rc := RedisPool.Get()
- rc.Do("SELECT", redis_winner_db)
- if _, err := rc.Do("SET", savetmp["company_name"], saveid); err != nil {
- log.Println("save redis err:", tmp["_id"], savetmp["_id"], savetmp["company_name"], err)
- } else {
- //删除临时表
- if deleteNum := FClient.Del(Config["mgo_qyk_c_w_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("winner_new,遍历完成")
- }
- }
- FClient.DestoryMongoConn(Fcconn)
- t2.Reset(time.Minute)
- //nextNode("winnerent", timenow)
- }
- }
- //分包处理
- func PackageDealWith(tmp map[string]interface{}, tmpclass []string,pkgid string) {
- util.Catch()
- if v, ok := tmp["package"].(map[string]interface{}); ok {
- for i, pv := range v {
- if ppv, ok2 := pv.(map[string]interface{}); ok2 {
- pkgwinner, ok3 := ppv["winner"].(string)
- if !ok3 || utf8.RuneCountInString(pkgwinner) < 4 {
- continue
- }
- //创建中标单位放入临时表
- vvv := make(map[string]interface{})
- vvv["winner"] = pkgwinner
- vvv["topscopeclass"] = tmpclass
- vvv["pkg_id"] =pkgid+"_"+i
- if winnerperson, ok := tmp["winnerperson"].(string); ok && winnerperson != "" &&
- !Reg_xing.MatchString(winnerperson) && Reg_person.MatchString(winnerperson) {
- vvv["winnerperson"] = winnerperson
- if winnertel, ok := tmp["winnertel"].(string); ok && !Reg_xing.MatchString(winnertel) && Reg_tel.MatchString(winnertel) {
- vvv["winnertel"] = winnertel
- }
- }
- FClient.Save(Config["mgo_qyk_c_w_new"],vvv)
- }
- }
- }
- }
|