timedTaskAgency.go 20 KB

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