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(86400)
  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. Fcconn := FClient.GetMgoConn(86400)
  318. tmpLast := map[string]interface{}{}
  319. 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 {
  320. if !iter.Next(&tmpLast) {
  321. //临时表无数据
  322. log.Println("临时表无数据:")
  323. t2.Reset(time.Minute * 1)
  324. FClient.DestoryMongoConn(Fcconn)
  325. continue
  326. } else {
  327. log.Println("临时表有数据:", tmpLast["_id"])
  328. fconn := FClient.GetMgoConn(86400)
  329. cursor := fconn.DB(Config["mgodb_extract_kf"]).C(Config["mgo_qyk_c_a_new"]).Find(bson.M{
  330. "_id": bson.M{
  331. "$lte": tmpLast["_id"],
  332. },
  333. }).Sort("_id").Iter()
  334. if cursor == nil {
  335. log.Println("查询失败")
  336. t2.Reset(time.Second * 5)
  337. FClient.DestoryMongoConn(fconn)
  338. continue
  339. }
  340. //遍历临时表数据,匹配不到原始库存入异常表
  341. tmp := make(map[string]interface{})
  342. for cursor.Next(&tmp) {
  343. tmpId := tmp["_id"].(bson.ObjectId).Hex()
  344. erragency, ok := tmp["agency"].(string)
  345. if !ok || erragency == "" {
  346. continue
  347. }
  348. //再重新查找redis,存在发udp处理,不存在走新增合并
  349. rdb := RedisPool.Get()
  350. rdb.Do("SELECT", redis_agency_db)
  351. if _, err := redis.String(rdb.Do("GET", erragency)); err == nil {
  352. //增量合并
  353. AddAgency(tmpId, tmp)
  354. //存在的话删除tmp mongo表
  355. if DeletedCount := FClient.Del(Config["mgo_qyk_c_a_new"], bson.M{"_id": bson.ObjectIdHex(tmpId)}); !DeletedCount {
  356. log.Println("删除临时表err:", DeletedCount)
  357. }
  358. if err := rdb.Close(); err != nil {
  359. log.Println(err)
  360. }
  361. continue
  362. } else {
  363. if err = rdb.Close(); err != nil {
  364. log.Println(err)
  365. }
  366. }
  367. //查询redis不存在新增
  368. sessionfinone := FClient.GetMgoConn()
  369. resulttmp := make(map[string]interface{})
  370. err := sessionfinone.DB(Config["mgodb_enterprise"]).C(Config["mgodb_enterprise_c"]).Find(bson.M{"company_name": erragency}).One(&resulttmp)
  371. FClient.DestoryMongoConn(sessionfinone)
  372. if err != nil || resulttmp["_id"] == nil {
  373. //log.Println(r)
  374. //人工审核正则
  375. var isok bool
  376. //先遍历ok
  377. for _, v := range AgencyRegOk {
  378. isok = v.MatchString(erragency)
  379. if isok {
  380. //匹配ok完,匹配err
  381. for _, vRegErr := range AgencyRegErr {
  382. isok = vRegErr.MatchString(erragency)
  383. //匹配到ok 也匹配到err 按err算
  384. if isok {
  385. tmp["agency_err"] = 1
  386. break
  387. }
  388. }
  389. //匹配ok,没匹配err 按ok算
  390. if tmp["agency_err"] == nil {
  391. tmp["agency_ok"] = 1
  392. break
  393. }
  394. }
  395. }
  396. //都没匹配
  397. if tmp["agency_ok"] == nil && tmp["agency_err"] == nil {
  398. tmp["agency_err"] = 1
  399. }
  400. //匹配不到原始库,存入异常表删除临时表
  401. if errb := FClient.SaveByOriID(Config["mgo_qyk_c_a_err"], tmp); !errb {
  402. log.Println("存入异常表错误", errb, tmp)
  403. }
  404. if deleteNum := FClient.Del(Config["mgo_qyk_c_a_new"], bson.M{"_id": bson.ObjectIdHex(tmpId)}); !deleteNum {
  405. log.Println("删除临时表错误", deleteNum)
  406. }
  407. continue
  408. } else {
  409. //log.Println(123)
  410. //匹配到原始库,新增 resulttmp angency
  411. if resulttmp["credit_no"] != nil {
  412. if credit_no, ok := resulttmp["credit_no"].(string); ok && strings.TrimSpace(credit_no) != "" &&
  413. len(strings.TrimSpace(credit_no)) > 8 {
  414. dataNo := strings.TrimSpace(credit_no)[2:8]
  415. if Addrs[dataNo] != nil {
  416. if v, ok := Addrs[dataNo].(map[string]interface{}); ok {
  417. if resulttmp["province"] == nil || resulttmp["province"] == "" {
  418. resulttmp["province"] = v["province"]
  419. }
  420. resulttmp["city"] = v["city"]
  421. resulttmp["district"] = v["district"]
  422. }
  423. }
  424. }
  425. }
  426. //行业类型
  427. tmpclass := make([]string, 0)
  428. if tclasss, ok := tmp["topscopeclass"].([]interface{}); ok {
  429. for _, vv := range tclasss {
  430. if vvv, ok := vv.(string); ok {
  431. if len(vvv) > 1 {
  432. tmpclass = append(tmpclass, vvv[:len(vvv)-1])
  433. }
  434. }
  435. }
  436. }
  437. contacts := make([]map[string]interface{}, 0)
  438. if legal_person, ok := resulttmp["legal_person"].(string); ok && legal_person != "" && !Reg_xing.MatchString(legal_person) && Reg_person.MatchString(legal_person) {
  439. contact := make(map[string]interface{}, 0)
  440. contact["contact_person"] = legal_person //联系人
  441. contact["contact_type"] = "法定代表人" //法定代表人
  442. if resulttmp["annual_reports"] != nil {
  443. bytes, err := json.Marshal(resulttmp["annual_reports"])
  444. if err != nil {
  445. log.Println("annual_reports err:", err)
  446. }
  447. phonetmp := make([]map[string]interface{}, 0)
  448. err = json.Unmarshal(bytes, &phonetmp)
  449. if err != nil {
  450. log.Println("Unmarshal err:", err)
  451. }
  452. for _, vv := range phonetmp {
  453. if vv["company_phone"] != nil {
  454. if vv["company_phone"] == "" {
  455. continue
  456. } else {
  457. contact["phone"] = vv["company_phone"] //联系电话
  458. break
  459. }
  460. } else {
  461. contact["phone"] = "" //联系电话
  462. }
  463. }
  464. }
  465. //log.Println(k, contact["phone"], resulttmp["_id"])
  466. //time.Sleep(10 * time.Second)
  467. if phone, ok := contact["phone"].(string); ok && phone != "" {
  468. if Reg_xing.MatchString(phone) || !Reg_tel.MatchString(phone) {
  469. contact["phone"] = "" //联系电话
  470. }
  471. } else {
  472. contact["phone"] = "" //联系电话
  473. }
  474. contact["topscopeclass"] = "企业公示" //项目类型
  475. contact["updatetime"] = time.Now().Unix() //更新时间
  476. contact["infoid"] = "" //招标信息id
  477. contacts = append(contacts, contact)
  478. }
  479. //添加临时表匹配到的联系人
  480. if agencyperson, ok := tmp["agencyperson"].(string); ok && agencyperson != "" &&
  481. !Reg_xing.MatchString(agencyperson) && Reg_person.MatchString(agencyperson) {
  482. vvv := make(map[string]interface{})
  483. vvv["infoid"] = tmp["_id"].(bson.ObjectId).Hex()
  484. vvv["contact_person"] = agencyperson
  485. vvv["contact_type"] = "项目联系人"
  486. if agencytel, ok := tmp["agencytel"].(string); ok && !Reg_xing.MatchString(agencytel) && Reg_tel.MatchString(agencytel) {
  487. vvv["phone"] = agencytel
  488. } else {
  489. vvv["phone"] = ""
  490. }
  491. vvv["topscopeclass"] = strings.Join(tmpclass, ";")
  492. vvv["updatetime"] = time.Now().Unix()
  493. contacts = append(contacts, vvv)
  494. }
  495. savetmp := make(map[string]interface{}, 0)
  496. for _, sk := range BuyerFields {
  497. if sk == "_id" {
  498. savetmp["tmp"+sk] = resulttmp[sk]
  499. continue
  500. } else if sk == "area_code" {
  501. //行政区划代码
  502. savetmp[sk] = fmt.Sprint(resulttmp[sk])
  503. continue
  504. } else if sk == "report_websites" {
  505. //网址
  506. if resulttmp["report_websites"] == nil {
  507. savetmp["website"] = ""
  508. } else {
  509. report_websitesArr := []string{}
  510. if ppms, ok := resulttmp[sk].([]interface{}); ok {
  511. for _, v := range ppms {
  512. if vvv, ok := v.(map[string]interface{}); ok {
  513. if rv, ok := vvv["website_url"].(string); ok {
  514. report_websitesArr = append(report_websitesArr, rv)
  515. }
  516. }
  517. }
  518. }
  519. sort.Strings(report_websitesArr)
  520. savetmp["website"] = strings.Join(report_websitesArr, ";")
  521. }
  522. continue
  523. } else if sk == "wechat_accounts" {
  524. savetmp[sk] = []interface{}{}
  525. continue
  526. } else if sk == "agency_name" {
  527. if resulttmp["company_name"] == nil {
  528. savetmp[sk] = ""
  529. } else {
  530. savetmp[sk] = resulttmp["company_name"]
  531. }
  532. continue
  533. } else if sk == "address" {
  534. if resulttmp["company_address"] == nil {
  535. savetmp[sk] = ""
  536. } else {
  537. savetmp[sk] = resulttmp["company_address"]
  538. }
  539. continue
  540. }
  541. if resulttmp[sk] == nil && sk != "history_name" && sk != "wechat_accounts" &&
  542. sk != "agency_name" && sk != "address" &&
  543. sk != "contact" && sk != "report_websites" {
  544. savetmp[sk] = ""
  545. } else {
  546. savetmp[sk] = resulttmp[sk]
  547. }
  548. }
  549. //判断分包
  550. if tmp["package"] != nil {
  551. PackageDealWith(&savetmp, tmp, erragency)
  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. }
  585. }
  586. //分包处理
  587. func PackageDealWithAgency(contactMap *map[string]interface{}, tmp map[string]interface{}, comName string) []interface{} {
  588. util.Catch()
  589. //if v, ok := tmp["package"].(map[string]interface{}); ok {
  590. //for i, pv := range v {
  591. // log.Println(i, pv)
  592. //}
  593. //}
  594. return nil
  595. }