timedTaskAgency.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  1. package main
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/garyburd/redigo/redis"
  6. "gopkg.in/mgo.v2/bson"
  7. "log"
  8. "qfw/util"
  9. "sort"
  10. "strings"
  11. "time"
  12. "unicode/utf8"
  13. )
  14. //之前main方法,只更新
  15. func TaskAgency(mapinfo *map[string]interface{}) {
  16. defer util.Catch()
  17. gtid, lteid := util.ObjToString((*mapinfo)["gtid"]), util.ObjToString((*mapinfo)["lteid"])
  18. if gtid == "" || lteid == "" {
  19. log.Println(gtid, lteid, "参数错误")
  20. return
  21. }
  22. var GId, LtId bson.ObjectId
  23. if bson.IsObjectIdHex(gtid) && bson.IsObjectIdHex(lteid) {
  24. GId = bson.ObjectIdHex(gtid)
  25. LtId = bson.ObjectIdHex(lteid)
  26. } else {
  27. log.Println(gtid, lteid, "不是Objectid,转换_id错误", gtid, lteid)
  28. return
  29. }
  30. //udp的id区间查询bidding 中标人 中标联系人 中标联系电话
  31. // topscopeclass项目类型-industry行业类型&&topscopeclass联系人项目类型
  32. // (area地区-province省份 city城市-city城市 district区县-district区县)
  33. // agencyaddr-company_address企业地址
  34. SourceClientcc := SourceClient.GetMgoConn(86400)
  35. cursor := SourceClientcc.DB(Config["mgodb_bidding"]).C(Config["mgodb_mgoinit_c"]).Find(bson.M{
  36. "_id": bson.M{
  37. "$gte": GId,
  38. "$lte": LtId,
  39. },
  40. }).Select(bson.M{"agency": 1, "agencytel": 1, "agencyperson": 1, "topscopeclass": 1,
  41. "agencyaddr": 1}).Iter()
  42. if cursor.Err() != nil {
  43. SourceClient.DestoryMongoConn(SourceClientcc)
  44. log.Println(cursor.Err())
  45. return
  46. }
  47. //判断是否是存量,是存量走Redis遍历
  48. if v, ok := (*mapinfo)["data_info"].(string); ok && v == "save" {
  49. //存量处理
  50. conn := HisRedisPool.Conn()
  51. defer conn.Close()
  52. //选择redis db
  53. conn.Select(redis_agency_db)
  54. //遍历bidding表保存到redis
  55. //key:企业名 value:json结构体{"agency": 1, "agencytel": 1, "agencyperson": 1,"topscopeclass": 1, "agencyaddr": 1,"_id":1}
  56. tmp := make(map[string]interface{})
  57. for cursor.Next(&tmp) {
  58. agency, ok := tmp["agency"].(string)
  59. if !ok || utf8.RuneCountInString(agency) < 4 {
  60. continue
  61. }
  62. //判断redis key是否存在
  63. e_num := conn.Exists(agency).Val()
  64. //获取字符串_id
  65. mgoId := tmp["_id"].(bson.ObjectId).Hex()
  66. //替换_id
  67. tmp["_id"] = mgoId
  68. //创建value数组
  69. tmps := make([]map[string]interface{}, 0)
  70. if e_num > 0 {
  71. //存量redis的key存在,累加更新
  72. bytes, _ := conn.Get(agency).Bytes()
  73. json.Unmarshal(bytes, &tmps)
  74. }
  75. tmps = append(tmps, tmp)
  76. bytes, _ := json.Marshal(tmps)
  77. //存量redis的key不存在,新增 key :企业名 val :[]map
  78. if err := conn.Set(agency, string(bytes), 0).Err(); err != nil {
  79. log.Println(err)
  80. }
  81. }
  82. SourceClient.DestoryMongoConn(SourceClientcc)
  83. //遍历redis
  84. if scan := conn.Scan(0, "", 100); scan.Err() != nil {
  85. log.Println(scan.Err())
  86. return
  87. } else {
  88. iterator := scan.Iterator()
  89. for iterator.Next() {
  90. redisCName := iterator.Val() //redis key 企业名
  91. redisvalueBytes, _ := conn.Get(redisCName).Bytes() //redis val []数组
  92. rValuesMaps := make([]map[string]interface{}, 0)
  93. json.Unmarshal(redisvalueBytes, &rValuesMaps)
  94. //redis查询是否存在
  95. rdb := RedisPool.Get()
  96. rdb.Do("SELECT", redis_agency_db)
  97. if reply, err := redis.String(rdb.Do("GET", redisCName)); err != nil {
  98. //redis不存在,存到临时表,定时任务处理
  99. for _, vmap := range rValuesMaps {
  100. vmap["_id"] = bson.ObjectIdHex(vmap["_id"].(string))
  101. if err = FClient.SaveForOld("agency_new", vmap); err != nil {
  102. log.Println("存量 FClient.Save err", err, vmap)
  103. }
  104. }
  105. //log.Println("get redis id err:定时任务处理", err, tmp)
  106. if err := rdb.Close(); err != nil {
  107. log.Println("存量", err)
  108. }
  109. continue
  110. } else {
  111. //redis存在更新合并
  112. if err := rdb.Close(); err != nil {
  113. log.Println(err)
  114. }
  115. //拿到合并后的qyk
  116. FClient.DbName = Config["mgodb_extract_kf"]
  117. oldTmp, b := FClient.FindById(Config["mgo_qyk_agency"], reply, nil)
  118. if !b || (*oldTmp) == nil|| reply==""||(*oldTmp)["_id"]==nil{
  119. log.Println(redisCName, "存量 redis id 不存在", reply)
  120. continue
  121. }
  122. tmpTopscopeclass := []string{}
  123. tmpTopscopeclassMap := make(map[string]bool)
  124. for _, rvaluemaps := range rValuesMaps {
  125. if tclasss, ok := rvaluemaps["topscopeclass"].([]string); ok {
  126. for _, vv := range tclasss {
  127. if len(vv) > 1 {
  128. tmpTopscopeclassMap[vv[:len(vv)-1]] = true
  129. }
  130. }
  131. }
  132. }
  133. for k := range tmpTopscopeclassMap {
  134. tmpTopscopeclass = append(tmpTopscopeclass, k)
  135. }
  136. sort.Strings(tmpTopscopeclass)
  137. esId := (*oldTmp)["_id"].(bson.ObjectId).Hex()
  138. //联系方式合并
  139. contactMaps := make([]interface{}, 0)
  140. if (*oldTmp)["contact"] != nil {
  141. //直接添加联系人,不再判断
  142. if v, ok := (*oldTmp)["contact"].([]interface{}); ok {
  143. contactMaps = append(contactMaps, v...)
  144. }
  145. }
  146. //遍历redis value联系人
  147. for _, rvmap := range rValuesMaps {
  148. var tmpperson, agencytel string
  149. if rvmapperson, ok := rvmap["agencyperson"].(string); ok && rvmapperson != "" {
  150. tmpperson = rvmapperson
  151. } else {
  152. continue
  153. }
  154. if rvmapwintel, ok := rvmap["agencytel"].(string); ok {
  155. agencytel = rvmapwintel
  156. } else {
  157. agencytel = ""
  158. }
  159. if Reg_xing.MatchString(agencytel) || !Reg_tel.MatchString(agencytel) {
  160. agencytel = ""
  161. }
  162. tmpContact := make(map[string]interface{})
  163. tmpContact["infoid"] = rvmap["_id"]
  164. tmpContact["contact_person"] = tmpperson
  165. tmpContact["contact_type"] = "项目联系人"
  166. tmpContact["phone"] = agencytel
  167. tmpclass := make([]string, 0)
  168. if tclasss, ok := rvmap["topscopeclass"].([]string); ok {
  169. for _, vv := range tclasss {
  170. if len(vv) > 1 {
  171. tmpclass = append(tmpclass, vv[:len(vv)-1])
  172. }
  173. }
  174. }
  175. tmpContact["topscopeclass"] = strings.Join(tmpclass, ";")
  176. tmpContact["updatetime"] = time.Now().Unix()
  177. contactMaps = append(contactMaps, tmpContact)
  178. }
  179. (*oldTmp)["contact"] = contactMaps
  180. //mongo更新
  181. (*oldTmp)["updatatime"] = time.Now().Unix()
  182. if !FClient.UpdateById(Config["mgo_qyk_agency"], esId, bson.M{"$set": oldTmp}) {
  183. log.Println("存量 mongo更新 err", esId, oldTmp)
  184. }
  185. //es更新
  186. delete((*oldTmp), "_id")
  187. }
  188. }
  189. }
  190. log.Println("存量历史合并执行完成 ok", gtid, lteid)
  191. //发送udp 更新es段
  192. } else {
  193. overid := gtid
  194. tmp := map[string]interface{}{}
  195. for cursor.Next(&tmp) {
  196. overid = AddAgency(overid, tmp)
  197. }
  198. SourceClient.DestoryMongoConn(SourceClientcc)
  199. log.Println("增量合并执行完成 ok", gtid, lteid, overid)
  200. //发送udp 更新es段
  201. }
  202. }
  203. //增量
  204. func AddAgency(overid string, tmp map[string]interface{}) string {
  205. overid = tmp["_id"].(bson.ObjectId).Hex()
  206. agency, ok := tmp["agency"].(string)
  207. if !ok || utf8.RuneCountInString(agency) < 4 {
  208. return overid
  209. }
  210. //redis查询是否存在
  211. rdb := RedisPool.Get()
  212. rdb.Do("SELECT", redis_agency_db)
  213. if reply, err := redis.String(rdb.Do("GET", agency)); err != nil {
  214. //redis不存在存到临时表,定时任务处理
  215. if err := FClient.SaveForOld("agency_new", tmp); err != nil {
  216. log.Println("FClient.Save err", err, tmp)
  217. }
  218. //log.Println("get redis id err:定时任务处理", err, tmp)
  219. if err := rdb.Close(); err != nil {
  220. log.Println(err)
  221. }
  222. return overid
  223. } else {
  224. if err := rdb.Close(); err != nil {
  225. log.Println(err)
  226. }
  227. //拿到合并后的qyk
  228. oldTmp, b := FClient.FindById(Config["mgo_qyk_agency"], reply, bson.M{})
  229. if !b || (*oldTmp) == nil || reply == "" || (*oldTmp)["_id"] == nil {
  230. log.Println("redis id 不存在", reply)
  231. return overid
  232. }
  233. //比较合并 行业类型
  234. tmpTopscopeclass := []string{}
  235. tmpConTopscopeclass := []string{}
  236. tmpTopscopeclassMap := make(map[string]bool)
  237. if v, ok := tmp["topscopeclass"].([]interface{}); ok {
  238. for _, vv := range v {
  239. if vvv, ok := vv.(string); ok && len(vvv) > 1 {
  240. tmpTopscopeclassMap[vvv[:len(vvv)-1]] = true
  241. tmpConTopscopeclass = append(tmpConTopscopeclass, vvv[:len(vvv)-1])
  242. }
  243. }
  244. }
  245. for k := range tmpTopscopeclassMap {
  246. tmpTopscopeclass = append(tmpTopscopeclass, k)
  247. }
  248. sort.Strings(tmpTopscopeclass)
  249. esId := (*oldTmp)["_id"].(bson.ObjectId).Hex()
  250. //更新行业类型
  251. if tmp["agencyperson"] == nil || tmp["agencyperson"] == "" || Reg_xing.MatchString(util.ObjToString(tmp["agencyperson"])) {
  252. (*oldTmp)["updatatime"] = time.Now().Unix()
  253. //mongo更新
  254. if !FClient.UpdateById(Config["mgo_qyk_agency"], esId, bson.M{"$set": oldTmp}) {
  255. log.Println("mongo更新err", esId)
  256. }
  257. //es更新
  258. delete((*oldTmp), "_id")
  259. return overid
  260. }
  261. //联系方式合并
  262. contactMaps := make([]map[string]interface{}, 0)
  263. if (*oldTmp)["contact"] != nil {
  264. //直接添加联系人,不再判断
  265. if v, ok := (*oldTmp)["contact"].([]interface{}); ok {
  266. for _, vv := range v {
  267. contactMaps = append(contactMaps, vv.(map[string]interface{}))
  268. }
  269. }
  270. }
  271. var tmpperson, agencytel string
  272. if tmppersona, ok := tmp["agencyperson"].(string); ok && tmpperson != "" && Reg_person.MatchString(tmpperson) && !Reg_xing.MatchString(tmpperson) {
  273. tmpperson = tmppersona
  274. }
  275. if tmpperson != "" {
  276. if agencyteltmp, ok := tmp["agencytel"].(string); ok {
  277. agencytel = agencyteltmp
  278. }
  279. if Reg_xing.MatchString(agencytel) || !Reg_tel.MatchString(agencytel) {
  280. agencytel = ""
  281. } else {
  282. agencytel = agencytel
  283. }
  284. vvv := make(map[string]interface{})
  285. vvv["infoid"] = overid
  286. vvv["contact_person"] = tmpperson
  287. vvv["contact_type"] = "项目联系人"
  288. vvv["phone"] = agencytel
  289. vvv["topscopeclass"] = strings.Join(tmpConTopscopeclass, ";")
  290. vvv["updatetime"] = time.Now().Unix()
  291. contactMaps = append(contactMaps, vvv)
  292. }
  293. //分包处理
  294. if tmp["package"] != nil {
  295. PackageDealWithAgency(oldTmp, tmp, agency)
  296. }
  297. (*oldTmp)["contact"] = contactMaps
  298. //mongo更新
  299. (*oldTmp)["updatatime"] = time.Now().Unix()
  300. if !FClient.UpdateById(Config["mgo_qyk_agency"], esId, bson.M{"$set": oldTmp}) {
  301. log.Println("mongo更新 err", esId, oldTmp)
  302. }
  303. //es更新
  304. delete((*oldTmp), "_id")
  305. }
  306. return overid
  307. }
  308. //定时任务 新增
  309. //1.存异常表
  310. //2.合并原始库新增
  311. func TimedTaskAgency() {
  312. //time.Sleep(time.Hour*70)
  313. t2 := time.NewTimer(time.Second * 5)
  314. for range t2.C {
  315. Fcconn := FClient.GetMgoConn(86400)
  316. tmpLast := map[string]interface{}{}
  317. if iter := Fcconn.DB(Config["mgodb_extract_kf"]).C("agency_new").Find(bson.M{}).Sort("-_id").Limit(1).Iter(); iter != nil {
  318. if !iter.Next(&tmpLast) {
  319. //临时表无数据
  320. log.Println("临时表无数据:")
  321. t2.Reset(time.Minute * 1)
  322. FClient.DestoryMongoConn(Fcconn)
  323. continue
  324. } else {
  325. log.Println("临时表有数据:", tmpLast["_id"])
  326. fconn := FClient.GetMgoConn(86400)
  327. cursor := fconn.DB(Config["mgodb_extract_kf"]).C("agency_new").Find(bson.M{
  328. "_id": bson.M{
  329. "$lte": tmpLast["_id"],
  330. },
  331. }).Sort("_id").Iter()
  332. if cursor == nil {
  333. log.Println("查询失败")
  334. t2.Reset(time.Second * 5)
  335. FClient.DestoryMongoConn(fconn)
  336. continue
  337. }
  338. //遍历临时表数据,匹配不到原始库存入异常表
  339. tmp := make(map[string]interface{})
  340. for cursor.Next(&tmp) {
  341. tmpId := tmp["_id"].(bson.ObjectId).Hex()
  342. erragency, ok := tmp["agency"].(string)
  343. if !ok || erragency == "" {
  344. continue
  345. }
  346. //再重新查找redis,存在发udp处理,不存在走新增合并
  347. rdb := RedisPool.Get()
  348. rdb.Do("SELECT", redis_agency_db)
  349. if _, err := redis.String(rdb.Do("GET", erragency)); err == nil {
  350. //增量合并
  351. AddAgency(tmpId, tmp)
  352. //存在的话删除tmp mongo表
  353. if DeletedCount := FClient.Del("agency_new", bson.M{"_id": bson.ObjectIdHex(tmpId)}); !DeletedCount {
  354. log.Println("删除临时表err:", DeletedCount)
  355. }
  356. if err := rdb.Close(); err != nil {
  357. log.Println(err)
  358. }
  359. continue
  360. } else {
  361. if err = rdb.Close(); err != nil {
  362. log.Println(err)
  363. }
  364. }
  365. //查询redis不存在新增
  366. sessionfinone := FClient.GetMgoConn()
  367. resulttmp := make(map[string]interface{})
  368. err := sessionfinone.DB(Config["mgodb_enterprise"]).C(Config["mgodb_enterprise_c"]).Find(bson.M{"company_name": erragency}).One(&resulttmp)
  369. FClient.DestoryMongoConn(sessionfinone)
  370. if err != nil || resulttmp["_id"] == nil {
  371. //log.Println(r)
  372. //人工审核正则
  373. var isok bool
  374. //先遍历ok
  375. for _, v := range AgencyRegOk {
  376. isok = v.MatchString(erragency)
  377. if isok {
  378. //匹配ok完,匹配err
  379. for _, vRegErr := range AgencyRegErr {
  380. isok = vRegErr.MatchString(erragency)
  381. //匹配到ok 也匹配到err 按err算
  382. if isok {
  383. tmp["agency_err"] = 1
  384. break
  385. }
  386. }
  387. //匹配ok,没匹配err 按ok算
  388. if tmp["agency_err"] == nil {
  389. tmp["agency_ok"] = 1
  390. break
  391. }
  392. }
  393. }
  394. //都没匹配
  395. if tmp["agency_ok"] == nil && tmp["agency_err"] == nil {
  396. tmp["agency_err"] = 1
  397. }
  398. //匹配不到原始库,存入异常表删除临时表
  399. if err := FClient.SaveForOld("agency_err", tmp); err != nil {
  400. log.Println("存入异常表错误", err, tmp)
  401. }
  402. if deleteNum := FClient.Del("agency_new", bson.M{"_id": bson.ObjectIdHex(tmpId)}); !deleteNum {
  403. log.Println("删除临时表错误", deleteNum)
  404. }
  405. continue
  406. } else {
  407. //log.Println(123)
  408. //匹配到原始库,新增 resulttmp angency
  409. if resulttmp["credit_no"] != nil {
  410. if credit_no, ok := resulttmp["credit_no"].(string); ok && strings.TrimSpace(credit_no) != "" &&
  411. len(strings.TrimSpace(credit_no)) > 8 {
  412. dataNo := strings.TrimSpace(credit_no)[2:8]
  413. if Addrs[dataNo] != nil {
  414. if v, ok := Addrs[dataNo].(map[string]interface{}); ok {
  415. if resulttmp["province"] == nil || resulttmp["province"] == "" {
  416. resulttmp["province"] = v["province"]
  417. }
  418. resulttmp["city"] = v["city"]
  419. resulttmp["district"] = v["district"]
  420. }
  421. }
  422. }
  423. }
  424. //行业类型
  425. tmpclass := make([]string, 0)
  426. if tclasss, ok := tmp["topscopeclass"].([]interface{}); ok {
  427. for _, vv := range tclasss {
  428. if vvv, ok := vv.(string); ok {
  429. if len(vvv) > 1 {
  430. tmpclass = append(tmpclass, vvv[:len(vvv)-1])
  431. }
  432. }
  433. }
  434. }
  435. contacts := make([]map[string]interface{}, 0)
  436. if legal_person, ok := resulttmp["legal_person"].(string); ok && legal_person != "" && !Reg_xing.MatchString(legal_person) && Reg_person.MatchString(legal_person) {
  437. contact := make(map[string]interface{}, 0)
  438. contact["contact_person"] = legal_person //联系人
  439. contact["contact_type"] = "法定代表人" //法定代表人
  440. if resulttmp["annual_reports"] != nil {
  441. bytes, err := json.Marshal(resulttmp["annual_reports"])
  442. if err != nil {
  443. log.Println("annual_reports err:", err)
  444. }
  445. phonetmp := make([]map[string]interface{}, 0)
  446. err = json.Unmarshal(bytes, &phonetmp)
  447. if err != nil {
  448. log.Println("Unmarshal err:", err)
  449. }
  450. for _, vv := range phonetmp {
  451. if vv["company_phone"] != nil {
  452. if vv["company_phone"] == "" {
  453. continue
  454. } else {
  455. contact["phone"] = vv["company_phone"] //联系电话
  456. break
  457. }
  458. } else {
  459. contact["phone"] = "" //联系电话
  460. }
  461. }
  462. }
  463. //log.Println(k, contact["phone"], resulttmp["_id"])
  464. //time.Sleep(10 * time.Second)
  465. if phone, ok := contact["phone"].(string); ok && phone != "" {
  466. if Reg_xing.MatchString(phone) || !Reg_tel.MatchString(phone) {
  467. contact["phone"] = "" //联系电话
  468. }
  469. } else {
  470. contact["phone"] = "" //联系电话
  471. }
  472. contact["topscopeclass"] = "企业公示" //项目类型
  473. contact["updatetime"] = time.Now().Unix() //更新时间
  474. contact["infoid"] = "" //招标信息id
  475. contacts = append(contacts, contact)
  476. }
  477. //添加临时表匹配到的联系人
  478. if agencyperson, ok := tmp["agencyperson"].(string); ok && agencyperson != "" &&
  479. !Reg_xing.MatchString(agencyperson) && Reg_person.MatchString(agencyperson) {
  480. vvv := make(map[string]interface{})
  481. vvv["infoid"] = tmp["_id"].(bson.ObjectId).Hex()
  482. vvv["contact_person"] = agencyperson
  483. vvv["contact_type"] = "项目联系人"
  484. if agencytel, ok := tmp["agencytel"].(string); ok && !Reg_xing.MatchString(agencytel) && Reg_tel.MatchString(agencytel) {
  485. vvv["phone"] = agencytel
  486. } else {
  487. vvv["phone"] = ""
  488. }
  489. vvv["topscopeclass"] = strings.Join(tmpclass, ";")
  490. vvv["updatetime"] = time.Now().Unix()
  491. contacts = append(contacts, vvv)
  492. }
  493. savetmp := make(map[string]interface{}, 0)
  494. for _, sk := range BuyerFields {
  495. if sk == "_id" {
  496. savetmp["tmp"+sk] = resulttmp[sk]
  497. continue
  498. } else if sk == "area_code" {
  499. //行政区划代码
  500. savetmp[sk] = fmt.Sprint(resulttmp[sk])
  501. continue
  502. } else if sk == "report_websites" {
  503. //网址
  504. if resulttmp["report_websites"] == nil {
  505. savetmp["website"] = ""
  506. } else {
  507. report_websitesArr := []string{}
  508. if ppms, ok := resulttmp[sk].([]interface{}); ok {
  509. for _, v := range ppms {
  510. if vvv, ok := v.(map[string]interface{}); ok {
  511. if rv, ok := vvv["website_url"].(string); ok {
  512. report_websitesArr = append(report_websitesArr, rv)
  513. }
  514. }
  515. }
  516. }
  517. sort.Strings(report_websitesArr)
  518. savetmp["website"] = strings.Join(report_websitesArr, ";")
  519. }
  520. continue
  521. } else if sk == "wechat_accounts" {
  522. savetmp[sk] = []interface{}{}
  523. continue
  524. } else if sk == "agency_name" {
  525. if resulttmp["company_name"] == nil {
  526. savetmp[sk] = ""
  527. } else {
  528. savetmp[sk] = resulttmp["company_name"]
  529. }
  530. continue
  531. } else if sk == "address" {
  532. if resulttmp["company_address"] == nil {
  533. savetmp[sk] = ""
  534. } else {
  535. savetmp[sk] = resulttmp["company_address"]
  536. }
  537. continue
  538. }
  539. if resulttmp[sk] == nil && sk != "history_name" && sk != "wechat_accounts" &&
  540. sk != "agency_name" && sk != "address" &&
  541. sk != "contact" && sk != "report_websites" {
  542. savetmp[sk] = ""
  543. } else {
  544. savetmp[sk] = resulttmp[sk]
  545. }
  546. }
  547. //判断分包
  548. if tmp["package"] != nil {
  549. PackageDealWith(&savetmp, tmp, erragency)
  550. }
  551. //tmps = append(tmps, savetmp)
  552. savetmp["comeintime"] = time.Now().Unix()
  553. savetmp["updatatime"] = time.Now().Unix()
  554. //保存mongo
  555. saveid := FClient.Save(Config["mgo_qyk_agency"], savetmp)
  556. if saveid != "" {
  557. //保存redis
  558. rc := RedisPool.Get()
  559. rc.Do("SELECT", redis_agency_db)
  560. if _, err := rc.Do("SET", savetmp["agency_name"], saveid); err != nil {
  561. log.Println("save redis err:", tmp["_id"], savetmp["_id"], savetmp["agency_name"], err)
  562. } else {
  563. //删除临时表
  564. if deleteNum := FClient.Del("agency_new", bson.M{"_id": bson.ObjectIdHex(tmpId)}); !deleteNum {
  565. log.Println("删除临时表失败", deleteNum)
  566. }
  567. }
  568. if err := rc.Close(); err != nil {
  569. log.Println(err)
  570. }
  571. } else {
  572. log.Println("save mongo err:", saveid, tmp["_id"])
  573. }
  574. }
  575. }
  576. FClient.DestoryMongoConn(fconn)
  577. log.Println("agency_new,遍历完成")
  578. }
  579. }
  580. FClient.DestoryMongoConn(Fcconn)
  581. t2.Reset(time.Minute)
  582. }
  583. }
  584. //分包处理
  585. func PackageDealWithAgency(contactMap *map[string]interface{}, tmp map[string]interface{}, comName string) []interface{} {
  586. util.Catch()
  587. //if v, ok := tmp["package"].(map[string]interface{}); ok {
  588. //for i, pv := range v {
  589. // log.Println(i, pv)
  590. //}
  591. //}
  592. return nil
  593. }