task.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. package main
  2. import (
  3. util "app.yhyue.com/data_processing/common_utils"
  4. "app.yhyue.com/data_processing/common_utils/log"
  5. "app.yhyue.com/data_processing/common_utils/mongodb"
  6. "app.yhyue.com/data_processing/common_utils/redis"
  7. "app.yhyue.com/data_processing/common_utils/udp"
  8. "encoding/json"
  9. "field_sync/config"
  10. "field_sync/oss"
  11. "fmt"
  12. "go.mongodb.org/mongo-driver/bson"
  13. "go.uber.org/zap"
  14. "net"
  15. "reflect"
  16. "regexp"
  17. "strings"
  18. "time"
  19. )
  20. var (
  21. regLetter = regexp.MustCompile("[a-z]*")
  22. cityEndReg = regexp.MustCompile("(区|县|市)$")
  23. )
  24. func biddingTask(data []byte, mapInfo map[string]interface{}) {
  25. defer util.Catch()
  26. stype := util.ObjToString(mapInfo["stype"])
  27. if stype == "bidding" {
  28. uq := bson.M{"gtid": bson.M{"$gte": util.ObjToString(mapInfo["gtid"])},
  29. "lteid": bson.M{"$lte": util.ObjToString(mapInfo["lteid"])}}
  30. MgoB.Update("bidding_processing_ids", uq, bson.M{"$set": bson.M{"dataprocess": 7, "updatetime": time.Now().Unix()}}, false, true)
  31. }
  32. // 领域标签处理的数据 id段
  33. if stype == "bidding_history" {
  34. MgoB.Save("field_data_record", map[string]interface{}{"gtid": mapInfo["gtid"], "lteid": mapInfo["lteid"], "status": 0})
  35. }
  36. q, _ := mapInfo["query"].(map[string]interface{})
  37. bkey, _ := mapInfo["bkey"].(string)
  38. if q == nil {
  39. q = map[string]interface{}{
  40. "_id": map[string]interface{}{
  41. "$gt": mongodb.StringTOBsonId(mapInfo["gtid"].(string)),
  42. "$lte": mongodb.StringTOBsonId(mapInfo["lteid"].(string)),
  43. },
  44. }
  45. }
  46. //extract库
  47. extractConn := MgoE.GetMgoConn()
  48. defer MgoE.DestoryMongoConn(extractConn)
  49. extractResult := extractConn.DB(MgoE.DbName).C(config.Conf.DB.MongoE.Coll).Find(q).Select(map[string]interface{}{
  50. "field_source": 0,
  51. "kvtext": 0,
  52. }).Sort("_id").Iter()
  53. eMap := map[string]map[string]interface{}{}
  54. extCount, repeatCount := 0, 0
  55. for tmp := make(map[string]interface{}); extractResult.Next(tmp); extCount++ {
  56. if util.IntAll(tmp["repeat"]) == 1 {
  57. repeatCount++
  58. }
  59. tid := mongodb.BsonIdToSId(tmp["_id"])
  60. eMap[tid] = tmp
  61. tmp = make(map[string]interface{})
  62. }
  63. log.Info("抽取表", zap.Int("数据量", extCount), zap.Int("重复数据量", repeatCount))
  64. //bidding库
  65. biddingConn := MgoB.GetMgoConn()
  66. count, _ := biddingConn.DB(MgoB.DbName).C(config.Conf.DB.MongoB.Coll).Find(&q).Count()
  67. log.Info("bidding表", zap.Int64("同步总数:", count))
  68. c := 0
  69. if count < 500000 {
  70. var res []map[string]interface{}
  71. result := biddingConn.DB(MgoB.DbName).C(config.Conf.DB.MongoB.Coll).Find(q).Select(map[string]interface{}{
  72. "contenthtml": 0,
  73. }).Iter()
  74. for tmp := make(map[string]interface{}); result.Next(tmp); {
  75. res = append(res, tmp)
  76. tmp = make(map[string]interface{})
  77. }
  78. MgoB.DestoryMongoConn(biddingConn)
  79. log.Info("查询结果", zap.Int64("bidding", count), zap.Int("抽取:", extCount))
  80. c = doIndex(res, eMap, bkey, stype)
  81. } else {
  82. log.Info("查询结果", zap.Int64("数据量太大,放弃", count))
  83. MgoB.DestoryMongoConn(biddingConn)
  84. }
  85. log.Info("bidding sync...over", zap.Int64("all", count), zap.Int("extract sync", c))
  86. NextNode(mapInfo, stype)
  87. NextNodePro(mapInfo, stype)
  88. NextNodeTidb(mapInfo, stype)
  89. if stype == "bidding_history" {
  90. NextNodeBidData(mapInfo) // bidding-data数据
  91. NextNodeTidbQyxy(mapInfo) // tidb-企业数据
  92. NextNodeHn(mapInfo)
  93. }
  94. }
  95. func biddingAllTask(data []byte, mapInfo map[string]interface{}) {
  96. defer util.Catch()
  97. q, _ := mapInfo["query"].(map[string]interface{})
  98. if q == nil {
  99. q = map[string]interface{}{
  100. "_id": map[string]interface{}{
  101. "$gt": mongodb.StringTOBsonId(mapInfo["gtid"].(string)),
  102. "$lte": mongodb.StringTOBsonId(mapInfo["lteid"].(string)),
  103. },
  104. }
  105. }
  106. //extract库
  107. extractConn := MgoE.GetMgoConn()
  108. defer MgoE.DestoryMongoConn(extractConn)
  109. extractResult := extractConn.DB(MgoE.DbName).C(config.Conf.DB.MongoE.Coll).Find(q).Select(map[string]interface{}{
  110. "field_source": 0,
  111. "kvtext": 0,
  112. }).Sort("-_id").Iter()
  113. //bidding库
  114. biddingConn := MgoB.GetMgoConn()
  115. defer MgoB.DestoryMongoConn(biddingConn)
  116. count := 0
  117. var compare map[string]interface{}
  118. result := biddingConn.DB(MgoB.DbName).C(config.Conf.DB.MongoB.Coll).Find(q).Select(map[string]interface{}{
  119. "contenthtml": 0,
  120. "field_source": 0,
  121. }).Sort("-_id").Iter()
  122. for tmp := make(map[string]interface{}); result.Next(tmp); count++ {
  123. update := map[string]interface{}{}
  124. del := map[string]interface{}{} //记录extract没有值而bidding中有值的字段
  125. //对比方法----------------
  126. for {
  127. if compare == nil {
  128. compare = make(map[string]interface{})
  129. if !extractResult.Next(compare) {
  130. break
  131. }
  132. }
  133. if compare != nil {
  134. cid := mongodb.BsonIdToSId(compare["_id"])
  135. tid := mongodb.BsonIdToSId(tmp["_id"])
  136. if cid == tid {
  137. //更新bidding表;bidding表modifyinfo中的字段不更新
  138. modifyinfo := make(map[string]bool)
  139. if tmpmodifyinfo, ok := tmp["modifyinfo"].(map[string]interface{}); ok && tmpmodifyinfo != nil {
  140. for k := range tmpmodifyinfo {
  141. modifyinfo[k] = true
  142. }
  143. }
  144. for _, k := range config.Conf.Serve.FieldS {
  145. v1 := compare[k] //extract
  146. v2 := tmp[k] //bidding
  147. if v2 == nil && v1 != nil {
  148. update[k] = v1
  149. } else if v2 != nil && v1 != nil && !modifyinfo[k] {
  150. update[k] = v1
  151. } else if v2 != nil && v1 == nil && !modifyinfo[k] {
  152. if k == "s_subscopeclass" && del["subscopeclass"] == nil {
  153. continue
  154. } else if k == "s_topscopeclass" && del["topscopeclass"] == nil {
  155. continue
  156. }
  157. del[k] = 1
  158. //util.Debug("抽取结果没有值,bidding有值:field--", k, "val--", v2)
  159. }
  160. }
  161. //if util.IntAll(compare["repeat"]) == 1 {
  162. // update["extracttype"] = -1
  163. // update["dataprocess"] = 7
  164. //} else {
  165. // update["extracttype"] = 1
  166. // update["dataprocess"] = 8
  167. //}
  168. break
  169. } else {
  170. if cid < tid {
  171. compare = nil
  172. continue
  173. } else {
  174. break
  175. }
  176. }
  177. } else {
  178. break
  179. }
  180. }
  181. //------------------对比结束
  182. //处理分类
  183. if compare != nil { //extract
  184. fieldFun(compare, update)
  185. compare = nil
  186. }
  187. // entidlist
  188. extractMap := make(map[string]interface{})
  189. if update["s_winner"] != "" {
  190. cid := companyFun(update)
  191. if len(cid) > 0 {
  192. update["entidlist"] = cid
  193. extractMap["entidlist"] = cid
  194. }
  195. }
  196. if len(extractMap) > 0 {
  197. updateExtPool <- []map[string]interface{}{
  198. {"_id": tmp["_id"]},
  199. {"$set": extractMap},
  200. }
  201. }
  202. // 附件有效字段
  203. if i := validFile(tmp); i != 0 {
  204. if i == -1 {
  205. update["isValidFile"] = false
  206. } else {
  207. update["isValidFile"] = true
  208. }
  209. }
  210. if len(update) > 0 {
  211. if len(del) > 0 { //删除的字段
  212. updateBidPool <- []map[string]interface{}{{
  213. "_id": tmp["_id"],
  214. },
  215. {"$set": update, "$unset": del},
  216. }
  217. } else {
  218. updateBidPool <- []map[string]interface{}{{
  219. "_id": tmp["_id"],
  220. },
  221. {"$set": update},
  222. }
  223. }
  224. }
  225. if count%50000 == 0 {
  226. log.Info("biddingTask", zap.Int("current", count))
  227. }
  228. tmp = make(map[string]interface{})
  229. }
  230. log.Info("biddingAll sync...over", zap.Int("all", count))
  231. }
  232. func doIndex(infos []map[string]interface{}, eMap map[string]map[string]interface{}, bkey, stype string) int {
  233. syncNo := 0 //抽取表数据同步数量
  234. //对比两张表数据,减少查询次数
  235. var compare map[string]interface{}
  236. var bidUpdate [][]map[string]interface{}
  237. var extUpdate [][]map[string]interface{}
  238. //SaveEsLock := &sync.Mutex{}
  239. log.Info("start ...")
  240. for n, tmp := range infos {
  241. tid := mongodb.BsonIdToSId(tmp["_id"])
  242. update := map[string]interface{}{} //要更新的mongo数据
  243. //对比方法----------------
  244. if eMap[tid] != nil {
  245. compare = eMap[tid]
  246. if stype == "bidding" {
  247. // 增量id段 正常数据
  248. if dg := util.IntAll(compare["dataging"]); dg == 1 { //extract中dataging=1跳过
  249. tmp = make(map[string]interface{})
  250. compare = nil
  251. continue
  252. }
  253. delete(eMap, tid)
  254. }
  255. if stype == "bidding_history" {
  256. //增量id段 历史数据
  257. if compare["history_updatetime"] == nil { //extract中history_updatetime不存在跳过
  258. tmp = make(map[string]interface{})
  259. compare = nil
  260. continue
  261. }
  262. delete(eMap, tid)
  263. }
  264. syncNo++
  265. for _, k := range config.Conf.Serve.FieldS {
  266. v1 := compare[k] //extract
  267. v2 := tmp[k] //bidding
  268. if v2 == nil && v1 != nil {
  269. update[k] = v1
  270. } else if v2 != nil && v1 != nil {
  271. update[k] = v1
  272. } else if v2 != nil && v1 == nil {
  273. if k == "city" || k == "district" {
  274. update[k] = ""
  275. }
  276. }
  277. }
  278. if util.IntAll(compare["repeat"]) == 1 {
  279. update["extracttype"] = -1
  280. update["dataprocess"] = 7
  281. } else {
  282. update["extracttype"] = 1
  283. update["dataprocess"] = 8
  284. }
  285. } else {
  286. compare = nil
  287. if util.IntAll(tmp["dataging"]) == 1 { //修改未抽取的bidding数据的dataging
  288. update["dataging"] = 0
  289. }
  290. update["dataprocess"] = 8
  291. }
  292. //下面可以多线程跑的--->
  293. //处理分类
  294. if compare != nil { //extract
  295. fieldFun(compare, update)
  296. compare = nil
  297. }
  298. //------------------对比结束
  299. //处理key descript
  300. if bkey == "" {
  301. DealInfo(&tmp, &update)
  302. }
  303. // entidlist
  304. extractMap := make(map[string]interface{})
  305. if update["s_winner"] != "" {
  306. cid := companyFun(update)
  307. if len(cid) > 0 {
  308. tmp["entidlist"] = cid
  309. update["entidlist"] = cid
  310. extractMap["entidlist"] = cid
  311. }
  312. }
  313. // 6.10 剑鱼发布信息分类处理, 写在这里是为了修改抽取表
  314. typeFunc(tmp, update, extractMap)
  315. if len(extractMap) > 0 {
  316. if extractMap["toptype"] != nil && extractMap["subtype"] == nil {
  317. extUpdate = append(extUpdate, []map[string]interface{}{
  318. {"_id": tmp["_id"]},
  319. {"$set": extractMap, "$unset": map[string]interface{}{"subtype": ""}},
  320. })
  321. } else {
  322. extUpdate = append(extUpdate, []map[string]interface{}{
  323. {"_id": tmp["_id"]},
  324. {"$set": extractMap},
  325. })
  326. }
  327. if len(extUpdate) >= MgoBulkSize {
  328. tmps := extUpdate
  329. MgoE.UpdateBulk(config.Conf.DB.MongoE.Coll, tmps...)
  330. extUpdate = [][]map[string]interface{}{}
  331. }
  332. }
  333. // 附件有效字段
  334. if i := validFile(tmp); i != 0 {
  335. if i == -1 {
  336. tmp["isValidFile"] = false
  337. update["isValidFile"] = false
  338. } else {
  339. tmp["isValidFile"] = true
  340. update["isValidFile"] = true
  341. }
  342. }
  343. if len(update) > 0 {
  344. bidUpdate = append(bidUpdate, []map[string]interface{}{{
  345. "_id": tmp["_id"],
  346. },
  347. {"$set": update},
  348. })
  349. if len(bidUpdate) >= MgoBulkSize {
  350. tmps := bidUpdate
  351. MgoB.UpdateBulk(config.Conf.DB.MongoB.Coll, tmps...)
  352. bidUpdate = [][]map[string]interface{}{}
  353. }
  354. }
  355. if n%500 == 0 {
  356. log.Info("biddingTask", zap.Int("current", n))
  357. }
  358. tmp = make(map[string]interface{})
  359. }
  360. //SaveEsLock.Lock()
  361. if len(bidUpdate) > 0 {
  362. tmps := bidUpdate
  363. MgoB.UpdateBulk(config.Conf.DB.MongoB.Coll, tmps...)
  364. bidUpdate = [][]map[string]interface{}{}
  365. }
  366. if len(extUpdate) > 0 {
  367. tmps := extUpdate
  368. MgoE.UpdateBulk(config.Conf.DB.MongoE.Coll, tmps...)
  369. extUpdate = [][]map[string]interface{}{}
  370. }
  371. //SaveEsLock.Unlock()
  372. return syncNo
  373. }
  374. // @Description subscopeclass、topscopeclass、package
  375. // @Author J 2022/6/7 5:54 PM
  376. func fieldFun(compare, update map[string]interface{}) {
  377. subscopeclass, _ := compare["subscopeclass"].([]interface{}) //subscopeclass
  378. if subscopeclass != nil {
  379. m1 := map[string]bool{}
  380. newclass := []string{}
  381. for _, sc := range subscopeclass {
  382. sclass, _ := sc.(string)
  383. if !m1[sclass] {
  384. m1[sclass] = true
  385. newclass = append(newclass, sclass)
  386. }
  387. }
  388. update["s_subscopeclass"] = strings.Join(newclass, ",")
  389. update["subscopeclass"] = newclass
  390. }
  391. topscopeclass, _ := compare["topscopeclass"].([]interface{}) //topscopeclass
  392. if topscopeclass != nil {
  393. m2 := map[string]bool{}
  394. newclass := []string{}
  395. for _, tc := range topscopeclass {
  396. tclass, _ := tc.(string)
  397. tclass = regLetter.ReplaceAllString(tclass, "") // 去除字母
  398. if !m2[tclass] {
  399. m2[tclass] = true
  400. newclass = append(newclass, tclass)
  401. }
  402. }
  403. update["topscopeclass"] = topscopeclass
  404. update["s_topscopeclass"] = strings.Join(newclass, ",")
  405. }
  406. if package1 := compare["package"]; package1 != nil {
  407. packageM, _ := package1.(map[string]interface{})
  408. update["package"] = packageM
  409. for _, p := range packageM {
  410. pm, _ := p.(map[string]interface{})
  411. if util.ObjToString(pm["winner"]) != "" || util.Float64All(pm["budget"]) > 0 ||
  412. util.Float64All(pm["bidamount"]) > 0 {
  413. update["multipackage"] = 1
  414. break
  415. }
  416. }
  417. } else {
  418. update["multipackage"] = 0
  419. }
  420. }
  421. // @Description entidlist
  422. // @Author J 2022/6/7 2:36 PM
  423. func companyFun(tmp map[string]interface{}) (cid []string) {
  424. sWinnerarr := strings.Split(util.ObjToString(tmp["s_winner"]), ",")
  425. for _, w := range sWinnerarr {
  426. if w != "" {
  427. id := redis.GetStr("qyxy_id", w)
  428. if id == "" {
  429. ents, _ := MgoQ.Find(config.Conf.DB.MongoQ.Coll, map[string]interface{}{"company_name": w}, map[string]interface{}{"updatetime": -1}, map[string]interface{}{"company_name": 1}, false, -1, -1)
  430. if len(*ents) > 0 {
  431. id = util.ObjToString((*ents)[0]["_id"])
  432. redis.PutCKV("qyxy_id", w, id)
  433. } else {
  434. ent, _ := MgoP.FindOne(config.Conf.DB.MongoP.Coll, map[string]interface{}{"history_name": w})
  435. if len(*ent) > 0 {
  436. id = util.ObjToString((*ent)["company_id"])
  437. redis.PutCKV("qyxy_id", w, id)
  438. }
  439. }
  440. }
  441. if id == "" {
  442. id = "-"
  443. }
  444. cid = append(cid, id)
  445. }
  446. }
  447. return cid
  448. }
  449. // @Description update 修改bidding表,extractM修改抽取表
  450. // @Author J 2022/6/10 10:29 AM
  451. func typeFunc(tmp, update, extractM map[string]interface{}) {
  452. if jyData, ok := tmp["jyfb_data"].(map[string]interface{}); ok {
  453. if t := util.ObjToString(jyData["type"]); t != "" {
  454. switch t {
  455. //case "采购信息":
  456. case "招标公告":
  457. if util.ObjToString(tmp["toptype"]) != "招标" {
  458. update["toptype"] = "招标"
  459. extractM["toptype"] = "招标"
  460. delete(update, "subtype")
  461. }
  462. case "采购意向":
  463. if util.ObjToString(tmp["toptype"]) != "采购意向" {
  464. update["toptype"] = "采购意向"
  465. update["subtype"] = "采购意向"
  466. extractM["toptype"] = "采购意向"
  467. extractM["subtype"] = "采购意向"
  468. }
  469. case "招标预告":
  470. if util.ObjToString(tmp["toptype"]) != "预告" {
  471. update["toptype"] = "预告"
  472. extractM["toptype"] = "预告"
  473. delete(update, "subtype")
  474. }
  475. case "招标结果":
  476. if util.ObjToString(tmp["toptype"]) != "结果" {
  477. update["toptype"] = "结果"
  478. extractM["toptype"] = "结果"
  479. delete(update, "subtype")
  480. }
  481. }
  482. }
  483. }
  484. }
  485. // @Description 附件有效字段(isValidFile)
  486. // @Author J 2022/7/8 14:41
  487. func validFile(tmp map[string]interface{}) int {
  488. isContinue := false
  489. if pinfo, o := tmp["projectinfo"].(map[string]interface{}); o {
  490. if atts, o1 := pinfo["attachments"].(map[string]interface{}); o1 {
  491. for _, att := range atts {
  492. if att == nil {
  493. continue
  494. }
  495. if reflect.TypeOf(att).String() == "string" {
  496. continue
  497. }
  498. att1 := att.(map[string]interface{})
  499. if fid := util.ObjToString(att1["fid"]); fid != "" {
  500. isContinue = true
  501. break
  502. }
  503. }
  504. if isContinue {
  505. if attachTxt, o := tmp["attach_text"].(map[string]interface{}); o {
  506. if len(attachTxt) > 0 {
  507. for _, at := range attachTxt {
  508. at1 := at.(map[string]interface{})
  509. if len(at1) > 0 {
  510. for k, _ := range at1 {
  511. if reflect.TypeOf(at1[k]).String() == "string" {
  512. continue
  513. }
  514. at2 := at1[k].(map[string]interface{})
  515. s := strings.ToLower(util.ObjToString(at2["file_name"]))
  516. if !strings.Contains(s, "jpg") || !strings.Contains(s, "jpeg") != strings.Contains(s, "png") ||
  517. strings.Contains(s, "pdf") {
  518. if strings.Contains(s, "swf") || strings.Contains(s, "html") {
  519. return -1
  520. } else if AnalysisFile(oss.OssGetObject(util.ObjToString(at2["attach_url"]))) {
  521. return 1
  522. }
  523. }
  524. }
  525. break
  526. } else {
  527. break
  528. }
  529. }
  530. }
  531. }
  532. flag := false
  533. for _, att := range atts {
  534. if att == nil {
  535. continue
  536. }
  537. if reflect.TypeOf(att).String() == "string" {
  538. continue
  539. }
  540. att1 := att.(map[string]interface{})
  541. if fid := util.ObjToString(att1["fid"]); fid != "" {
  542. ftype := strings.ToLower(util.ObjToString(tmp["ftype"]))
  543. if ftype != "swf" && ftype != "html" && oss.OssObjExists("jy-datafile", fid) {
  544. return 1
  545. } else {
  546. flag = true
  547. }
  548. }
  549. }
  550. if flag {
  551. return -1
  552. }
  553. }
  554. }
  555. }
  556. return 0
  557. }
  558. // @Description id不变,内容变化 重新索引数据
  559. // @Author J 2022/8/10 13:29
  560. func taskinfo(id string) {
  561. tmp, _ := MgoB.FindById("bidding", id, nil)
  562. if tmp == nil || len(*tmp) == 0 {
  563. log.Info(fmt.Sprintf("taskinfo bidding id=%s 未查询到数据", id))
  564. return
  565. }
  566. extractM, _ := MgoE.FindById(config.Conf.DB.MongoE.Coll, id, nil)
  567. if extractM == nil || len(*extractM) == 0 {
  568. extractM, _ = MgoE.FindById(config.Conf.DB.MongoE.Coll1, id, nil)
  569. if extractM == nil || len(*extractM) == 0 {
  570. log.Info(fmt.Sprintf("taskinfo extract id=%s 未查询到数据", id))
  571. return
  572. }
  573. }
  574. update := map[string]interface{}{} //要更新的mongo数据
  575. //更新bidding表字段
  576. for _, k := range config.Conf.Serve.FieldS {
  577. v1 := (*extractM)[k] //extract
  578. v2 := (*tmp)[k] //bidding
  579. if v2 == nil && v1 != nil {
  580. update[k] = v1
  581. } else if v2 != nil && v1 != nil {
  582. update[k] = v1
  583. } else if v2 != nil && v1 == nil {
  584. if k == "city" || k == "district" {
  585. update[k] = ""
  586. }
  587. }
  588. }
  589. if util.IntAll((*extractM)["repeat"]) == 1 {
  590. update["extracttype"] = -1
  591. update["dataprocess"] = 7
  592. } else {
  593. update["extracttype"] = 1
  594. update["dataprocess"] = 8
  595. }
  596. //处理分类
  597. fieldFun(*extractM, update)
  598. extractMap := make(map[string]interface{})
  599. if util.ObjToString((*tmp)["s_winner"]) != "" {
  600. cid := companyFun(*tmp)
  601. if len(cid) > 0 {
  602. update["entidlist"] = cid
  603. extractMap["entidlist"] = cid
  604. }
  605. MgoE.UpdateById(config.Conf.DB.MongoE.Coll, id, map[string]interface{}{"$set": extractMap})
  606. }
  607. // 附件有效字段
  608. if i := validFile(*tmp); i != 0 {
  609. if i == -1 {
  610. update["isValidFile"] = false
  611. } else {
  612. update["isValidFile"] = true
  613. }
  614. }
  615. if len(update) > 0 {
  616. MgoB.UpdateById(config.Conf.DB.MongoB.Coll, id, map[string]interface{}{"$set": update})
  617. }
  618. mapinfo := map[string]interface{}{
  619. "infoid": id,
  620. "stype": "index-by-id",
  621. }
  622. datas, _ := json.Marshal(mapinfo)
  623. var next = &net.UDPAddr{
  624. IP: net.ParseIP(config.Conf.Udp.Next.Addr),
  625. Port: util.IntAll(config.Conf.Udp.Next.Port),
  626. }
  627. log.Info("nsq data over", zap.Any("es", next), zap.String("mapinfo", string(datas)))
  628. _ = UdpClient.WriteUdp(datas, udp.OP_TYPE_DATA, next)
  629. }