timedTaskAgency.go 20 KB

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