task.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  1. package main
  2. import (
  3. "encoding/json"
  4. "field_sync/config"
  5. "field_sync/oss"
  6. "fmt"
  7. "go.uber.org/zap"
  8. util "jygit.jydev.jianyu360.cn/data_processing/common_utils"
  9. "jygit.jydev.jianyu360.cn/data_processing/common_utils/log"
  10. "jygit.jydev.jianyu360.cn/data_processing/common_utils/mongodb"
  11. "jygit.jydev.jianyu360.cn/data_processing/common_utils/redis"
  12. "jygit.jydev.jianyu360.cn/data_processing/common_utils/udp"
  13. "net"
  14. "reflect"
  15. "regexp"
  16. "sort"
  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, del)
  159. }
  160. }
  161. if util.IntAll(compare["repeat"]) == 1 {
  162. update["extracttype"] = -1
  163. update["dataprocess"] = 7
  164. update["repeat_id"] = compare["repeat_id"]
  165. } else {
  166. update["extracttype"] = 1
  167. update["dataprocess"] = 8
  168. }
  169. break
  170. } else {
  171. if cid < tid {
  172. compare = nil
  173. continue
  174. } else {
  175. break
  176. }
  177. }
  178. } else {
  179. break
  180. }
  181. }
  182. //------------------对比结束
  183. //处理分类
  184. if compare != nil { //extract
  185. fieldFun(compare, update)
  186. compare = nil
  187. }
  188. // entidlist
  189. extractMap := make(map[string]interface{})
  190. if update["s_winner"] != "" {
  191. cid := companyFun(update)
  192. if len(cid) > 0 {
  193. update["entidlist"] = cid
  194. extractMap["entidlist"] = cid
  195. }
  196. }
  197. if len(extractMap) > 0 {
  198. updateExtPool <- []map[string]interface{}{
  199. {"_id": tmp["_id"]},
  200. {"$set": extractMap},
  201. }
  202. }
  203. // 附件有效字段
  204. if i := validFile(tmp); i != 0 {
  205. if i == -1 {
  206. update["isValidFile"] = false
  207. } else {
  208. update["isValidFile"] = true
  209. }
  210. }
  211. if len(update) > 0 {
  212. if len(del) > 0 { //删除的字段
  213. updateBidPool <- []map[string]interface{}{{
  214. "_id": tmp["_id"],
  215. },
  216. {"$set": update, "$unset": del},
  217. }
  218. } else {
  219. updateBidPool <- []map[string]interface{}{{
  220. "_id": tmp["_id"],
  221. },
  222. {"$set": update},
  223. }
  224. }
  225. }
  226. if count%50000 == 0 {
  227. log.Info("biddingTask", zap.Int("current", count))
  228. }
  229. tmp = make(map[string]interface{})
  230. }
  231. log.Info("biddingAll sync...over", zap.Int("all", count))
  232. }
  233. func doIndex(infos []map[string]interface{}, eMap map[string]map[string]interface{}, bkey, stype string) int {
  234. syncNo := 0 //抽取表数据同步数量
  235. //对比两张表数据,减少查询次数
  236. var compare map[string]interface{}
  237. var bidUpdate [][]map[string]interface{}
  238. var extUpdate [][]map[string]interface{}
  239. //SaveEsLock := &sync.Mutex{}
  240. log.Info("start ...")
  241. for n, tmp := range infos {
  242. tid := mongodb.BsonIdToSId(tmp["_id"])
  243. update := map[string]interface{}{} //要更新的mongo数据
  244. del := map[string]interface{}{}
  245. //对比方法----------------
  246. if eMap[tid] != nil {
  247. compare = eMap[tid]
  248. if stype == "bidding" {
  249. // 增量id段 正常数据
  250. if dg := util.IntAll(compare["dataging"]); dg == 1 { //extract中dataging=1跳过
  251. tmp = make(map[string]interface{})
  252. compare = nil
  253. continue
  254. }
  255. delete(eMap, tid)
  256. }
  257. if stype == "bidding_history" {
  258. //增量id段 历史数据
  259. if compare["history_updatetime"] == nil { //extract中history_updatetime不存在跳过
  260. tmp = make(map[string]interface{})
  261. compare = nil
  262. continue
  263. }
  264. delete(eMap, tid)
  265. }
  266. syncNo++
  267. for _, k := range config.Conf.Serve.FieldS {
  268. v1 := compare[k] //extract
  269. v2 := tmp[k] //bidding
  270. if v2 == nil && v1 != nil {
  271. update[k] = v1
  272. } else if v2 != nil && v1 != nil {
  273. update[k] = v1
  274. } else if v2 != nil && v1 == nil {
  275. if k == "s_subscopeclass" && del["subscopeclass"] == nil {
  276. continue
  277. } else if k == "s_topscopeclass" && del["topscopeclass"] == nil {
  278. continue
  279. } else if k == "city" || k == "district" {
  280. update[k] = ""
  281. } else {
  282. del[k] = 1
  283. }
  284. }
  285. }
  286. if util.IntAll(compare["repeat"]) == 1 {
  287. update["extracttype"] = -1
  288. update["dataprocess"] = 7
  289. update["repeat_id"] = compare["repeat_id"]
  290. } else {
  291. update["extracttype"] = 1
  292. update["dataprocess"] = 8
  293. }
  294. } else {
  295. compare = nil
  296. if util.IntAll(tmp["dataging"]) == 1 { //修改未抽取的bidding数据的dataging
  297. update["dataging"] = 0
  298. }
  299. update["dataprocess"] = 8
  300. }
  301. //下面可以多线程跑的--->
  302. //处理分类
  303. if compare != nil { //extract
  304. fieldFun(compare, update)
  305. // publishtime 20230523
  306. if util.IntAll(tmp["publishtime"]) == -1 {
  307. if pb := methodPb(compare); pb > 0 {
  308. update["publishtime"] = pb
  309. }
  310. }
  311. compare = nil
  312. }
  313. //------------------对比结束
  314. //处理key descript
  315. if bkey == "" {
  316. DealInfo(&tmp, &update)
  317. }
  318. // entidlist
  319. extractMap := make(map[string]interface{})
  320. if update["s_winner"] != "" {
  321. cid := companyFun(update)
  322. if len(cid) > 0 {
  323. tmp["entidlist"] = cid
  324. update["entidlist"] = cid
  325. extractMap["entidlist"] = cid
  326. }
  327. }
  328. // 6.10 剑鱼发布信息分类处理, 写在这里是为了修改抽取表
  329. typeFunc(tmp, update, extractMap)
  330. if len(extractMap) > 0 {
  331. if extractMap["toptype"] != nil && extractMap["subtype"] == nil {
  332. extUpdate = append(extUpdate, []map[string]interface{}{
  333. {"_id": tmp["_id"]},
  334. {"$set": extractMap, "$unset": map[string]interface{}{"subtype": ""}},
  335. })
  336. } else {
  337. extUpdate = append(extUpdate, []map[string]interface{}{
  338. {"_id": tmp["_id"]},
  339. {"$set": extractMap},
  340. })
  341. }
  342. if len(extUpdate) >= MgoBulkSize {
  343. tmps := extUpdate
  344. MgoE.UpdateBulk(config.Conf.DB.MongoE.Coll, tmps...)
  345. extUpdate = [][]map[string]interface{}{}
  346. }
  347. }
  348. // 附件有效字段
  349. if i := validFile(tmp); i != 0 {
  350. if i == -1 {
  351. tmp["isValidFile"] = false
  352. update["isValidFile"] = false
  353. } else {
  354. tmp["isValidFile"] = true
  355. update["isValidFile"] = true
  356. }
  357. }
  358. if len(update) > 0 {
  359. if len(del) > 0 {
  360. bidUpdate = append(bidUpdate, []map[string]interface{}{{
  361. "_id": tmp["_id"],
  362. },
  363. {"$set": update, "$unset": del},
  364. })
  365. } else {
  366. bidUpdate = append(bidUpdate, []map[string]interface{}{{
  367. "_id": tmp["_id"],
  368. },
  369. {"$set": update},
  370. })
  371. }
  372. if len(bidUpdate) >= MgoBulkSize {
  373. tmps := bidUpdate
  374. MgoB.UpdateBulk(config.Conf.DB.MongoB.Coll, tmps...)
  375. bidUpdate = [][]map[string]interface{}{}
  376. }
  377. }
  378. if n%500 == 0 {
  379. log.Info("biddingTask", zap.Int("current", n))
  380. }
  381. tmp = make(map[string]interface{})
  382. }
  383. //SaveEsLock.Lock()
  384. if len(bidUpdate) > 0 {
  385. tmps := bidUpdate
  386. MgoB.UpdateBulk(config.Conf.DB.MongoB.Coll, tmps...)
  387. bidUpdate = [][]map[string]interface{}{}
  388. }
  389. if len(extUpdate) > 0 {
  390. tmps := extUpdate
  391. MgoE.UpdateBulk(config.Conf.DB.MongoE.Coll, tmps...)
  392. extUpdate = [][]map[string]interface{}{}
  393. }
  394. //SaveEsLock.Unlock()
  395. return syncNo
  396. }
  397. // @Description subscopeclass、topscopeclass、package
  398. // 20230523 多包处理 subpackage = 1
  399. // @Author J 2022/6/7 5:54 PM
  400. func fieldFun(compare, update map[string]interface{}) {
  401. subscopeclass, _ := compare["subscopeclass"].([]interface{}) //subscopeclass
  402. if subscopeclass != nil {
  403. m1 := map[string]bool{}
  404. newclass := []string{}
  405. for _, sc := range subscopeclass {
  406. sclass, _ := sc.(string)
  407. if !m1[sclass] {
  408. m1[sclass] = true
  409. newclass = append(newclass, sclass)
  410. }
  411. }
  412. update["s_subscopeclass"] = strings.Join(newclass, ",")
  413. update["subscopeclass"] = newclass
  414. }
  415. topscopeclass, _ := compare["topscopeclass"].([]interface{}) //topscopeclass
  416. if topscopeclass != nil {
  417. m2 := map[string]bool{}
  418. newclass := []string{}
  419. for _, tc := range topscopeclass {
  420. tclass, _ := tc.(string)
  421. tclass = regLetter.ReplaceAllString(tclass, "") // 去除字母
  422. if !m2[tclass] {
  423. m2[tclass] = true
  424. newclass = append(newclass, tclass)
  425. }
  426. }
  427. update["topscopeclass"] = topscopeclass
  428. update["s_topscopeclass"] = strings.Join(newclass, ",")
  429. }
  430. if package1 := compare["package"]; package1 != nil {
  431. packageM, _ := package1.(map[string]interface{})
  432. update["package"] = packageM
  433. for _, p := range packageM {
  434. pm, _ := p.(map[string]interface{})
  435. if util.ObjToString(pm["winner"]) != "" || util.Float64All(pm["budget"]) > 0 ||
  436. util.Float64All(pm["bidamount"]) > 0 {
  437. update["multipackage"] = 1
  438. break
  439. }
  440. }
  441. } else {
  442. update["multipackage"] = 0
  443. }
  444. // subpackage
  445. if compare["package"] != nil && compare["s_winner"] != nil && compare["bidamount"] != nil {
  446. pg := compare["package"].(map[string]interface{})
  447. if len(pg) > 1 {
  448. var bmt []float64
  449. var swn []string
  450. for _, p := range pg {
  451. p1 := p.(map[string]interface{})
  452. if p1["bidamount"] != nil {
  453. bmt = append(bmt, util.Float64All(p1["bidamount"]))
  454. }
  455. if w := util.ObjToString(p1["winner"]); w != "" {
  456. swn = append(swn)
  457. }
  458. }
  459. if len(bmt) > 1 && len(swn) > 1 {
  460. sn := strings.Split(util.ObjToString(compare["s_winner"]), ",")
  461. sort.Strings(sn)
  462. sort.Strings(swn)
  463. swn1 := util.ObjArrToStringArr(Duplicate(swn)) // 去重
  464. if strings.Join(swn1, ",") == strings.Join(sn, ",") {
  465. bidamount := 0.0
  466. for _, f := range bmt {
  467. bidamount += f
  468. }
  469. if bidamount == util.Float64All(compare["bidamount"]) {
  470. update["subpackage"] = 1
  471. }
  472. }
  473. }
  474. }
  475. }
  476. }
  477. // @Description entidlist
  478. // @Author J 2022/6/7 2:36 PM
  479. func companyFun(tmp map[string]interface{}) (cid []string) {
  480. sWinnerarr := strings.Split(util.ObjToString(tmp["s_winner"]), ",")
  481. for _, w := range sWinnerarr {
  482. if w != "" {
  483. id := redis.GetStr("qyxy_id", w)
  484. if id == "" {
  485. 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)
  486. if len(*ents) > 0 {
  487. id = util.ObjToString((*ents)[0]["_id"])
  488. redis.PutCKV("qyxy_id", w, id)
  489. } else {
  490. ent, _ := MgoP.FindOne(config.Conf.DB.MongoP.Coll, map[string]interface{}{"history_name": w})
  491. if len(*ent) > 0 {
  492. id = util.ObjToString((*ent)["company_id"])
  493. redis.PutCKV("qyxy_id", w, id)
  494. }
  495. }
  496. }
  497. if id == "" {
  498. id = "-"
  499. }
  500. cid = append(cid, id)
  501. }
  502. }
  503. return cid
  504. }
  505. // @Description update 修改bidding表,extractM修改抽取表
  506. // @Author J 2022/6/10 10:29 AM
  507. func typeFunc(tmp, update, extractM map[string]interface{}) {
  508. if jyData, ok := tmp["jyfb_data"].(map[string]interface{}); ok {
  509. if t := util.ObjToString(jyData["type"]); t != "" {
  510. switch t {
  511. //case "采购信息":
  512. case "招标公告":
  513. if util.ObjToString(tmp["toptype"]) != "招标" {
  514. update["toptype"] = "招标"
  515. extractM["toptype"] = "招标"
  516. delete(update, "subtype")
  517. }
  518. case "采购意向":
  519. if util.ObjToString(tmp["toptype"]) != "采购意向" {
  520. update["toptype"] = "采购意向"
  521. update["subtype"] = "采购意向"
  522. extractM["toptype"] = "采购意向"
  523. extractM["subtype"] = "采购意向"
  524. }
  525. case "招标预告":
  526. if util.ObjToString(tmp["toptype"]) != "预告" {
  527. update["toptype"] = "预告"
  528. extractM["toptype"] = "预告"
  529. delete(update, "subtype")
  530. }
  531. case "招标结果":
  532. if util.ObjToString(tmp["toptype"]) != "结果" {
  533. update["toptype"] = "结果"
  534. extractM["toptype"] = "结果"
  535. delete(update, "subtype")
  536. }
  537. }
  538. }
  539. }
  540. }
  541. // @Description 附件有效字段(isValidFile)
  542. // @Author J 2022/7/8 14:41
  543. func validFile(tmp map[string]interface{}) int {
  544. isContinue := false
  545. if pinfo, o := tmp["projectinfo"].(map[string]interface{}); o {
  546. if atts, o1 := pinfo["attachments"].(map[string]interface{}); o1 {
  547. for _, att := range atts {
  548. if att == nil {
  549. continue
  550. }
  551. if reflect.TypeOf(att).String() == "string" {
  552. continue
  553. }
  554. att1 := att.(map[string]interface{})
  555. if fid := util.ObjToString(att1["fid"]); fid != "" {
  556. isContinue = true
  557. break
  558. }
  559. }
  560. if isContinue {
  561. if attachTxt, o := tmp["attach_text"].(map[string]interface{}); o {
  562. if len(attachTxt) > 0 {
  563. for _, at := range attachTxt {
  564. at1 := at.(map[string]interface{})
  565. if len(at1) > 0 {
  566. for k, _ := range at1 {
  567. if reflect.TypeOf(at1[k]).String() == "string" {
  568. continue
  569. }
  570. at2 := at1[k].(map[string]interface{})
  571. s := strings.ToLower(util.ObjToString(at2["file_name"]))
  572. if !strings.Contains(s, "jpg") || !strings.Contains(s, "jpeg") != strings.Contains(s, "png") ||
  573. strings.Contains(s, "pdf") {
  574. if strings.Contains(s, "swf") || strings.Contains(s, "html") {
  575. return -1
  576. } else if AnalysisFile(oss.OssGetObject(util.ObjToString(at2["attach_url"]))) {
  577. return 1
  578. }
  579. }
  580. }
  581. break
  582. } else {
  583. break
  584. }
  585. }
  586. }
  587. }
  588. flag := false
  589. for _, att := range atts {
  590. if att == nil {
  591. continue
  592. }
  593. if reflect.TypeOf(att).String() == "string" {
  594. continue
  595. }
  596. att1 := att.(map[string]interface{})
  597. if fid := util.ObjToString(att1["fid"]); fid != "" {
  598. ftype := strings.ToLower(util.ObjToString(tmp["ftype"]))
  599. if ftype != "swf" && ftype != "html" && oss.OssObjExists("jy-datafile", fid) {
  600. return 1
  601. } else {
  602. flag = true
  603. }
  604. }
  605. }
  606. if flag {
  607. return -1
  608. }
  609. }
  610. }
  611. }
  612. return 0
  613. }
  614. // @Description id不变,内容变化 重新索引数据
  615. // @Author J 2022/8/10 13:29
  616. func taskinfo(id string) {
  617. tmp, _ := MgoB.FindById("bidding", id, nil)
  618. if tmp == nil || len(*tmp) == 0 {
  619. log.Info(fmt.Sprintf("taskinfo bidding id=%s 未查询到数据", id))
  620. return
  621. }
  622. extractM, _ := MgoE.FindById(config.Conf.DB.MongoE.Coll, id, nil)
  623. if extractM == nil || len(*extractM) == 0 {
  624. extractM, _ = MgoE.FindById(config.Conf.DB.MongoE.Coll1, id, nil)
  625. if extractM == nil || len(*extractM) == 0 {
  626. log.Info(fmt.Sprintf("taskinfo extract id=%s 未查询到数据", id))
  627. return
  628. }
  629. }
  630. update := map[string]interface{}{} //要更新的mongo数据
  631. //更新bidding表字段
  632. for _, k := range config.Conf.Serve.FieldS {
  633. v1 := (*extractM)[k] //extract
  634. v2 := (*tmp)[k] //bidding
  635. if v2 == nil && v1 != nil {
  636. update[k] = v1
  637. } else if v2 != nil && v1 != nil {
  638. update[k] = v1
  639. } else if v2 != nil && v1 == nil {
  640. if k == "city" || k == "district" {
  641. update[k] = ""
  642. }
  643. }
  644. }
  645. if util.IntAll((*extractM)["repeat"]) == 1 {
  646. update["extracttype"] = -1
  647. update["dataprocess"] = 7
  648. update["repeat_id"] = (*extractM)["repeat_id"]
  649. } else {
  650. update["extracttype"] = 1
  651. update["dataprocess"] = 8
  652. }
  653. //处理分类
  654. fieldFun(*extractM, update)
  655. extractMap := make(map[string]interface{})
  656. if util.ObjToString((*tmp)["s_winner"]) != "" {
  657. cid := companyFun(*tmp)
  658. if len(cid) > 0 {
  659. update["entidlist"] = cid
  660. extractMap["entidlist"] = cid
  661. }
  662. MgoE.UpdateById(config.Conf.DB.MongoE.Coll, id, map[string]interface{}{"$set": extractMap})
  663. }
  664. // 附件有效字段
  665. if i := validFile(*tmp); i != 0 {
  666. if i == -1 {
  667. update["isValidFile"] = false
  668. } else {
  669. update["isValidFile"] = true
  670. }
  671. }
  672. if len(update) > 0 {
  673. MgoB.UpdateById(config.Conf.DB.MongoB.Coll, id, map[string]interface{}{"$set": update})
  674. }
  675. mapinfo := map[string]interface{}{
  676. "infoid": id,
  677. "stype": "index-by-id",
  678. }
  679. datas, _ := json.Marshal(mapinfo)
  680. var next = &net.UDPAddr{
  681. IP: net.ParseIP(config.Conf.Udp.Next.Addr),
  682. Port: util.IntAll(config.Conf.Udp.Next.Port),
  683. }
  684. log.Info("nsq data over", zap.Any("es", next), zap.String("mapinfo", string(datas)))
  685. _ = UdpClient.WriteUdp(datas, udp.OP_TYPE_DATA, next)
  686. }
  687. var DateTimeSelect = []string{"bidopentime", "bidendtime", "signaturedate", "comeintime"}
  688. // @Description 发布时间处理
  689. // @Author J 2023/5/23 14:32
  690. func methodPb(tmp map[string]interface{}) int64 {
  691. if tmp["ext_publishtime"] != nil {
  692. if newPb := util.Int64All(tmp["ext_publishtime"]); newPb < time.Now().Unix() && newPb > 1420041600 {
  693. return newPb
  694. }
  695. }
  696. for _, d := range DateTimeSelect {
  697. if tmp[d] != nil && util.Int64All(tmp[d]) < time.Now().Unix() {
  698. return util.Int64All(tmp[d])
  699. }
  700. }
  701. return 0
  702. }
  703. // Duplicate
  704. // @Description 去重
  705. // @Author J 2023/5/24 09:53
  706. func Duplicate(a interface{}) (ret []interface{}) {
  707. va := reflect.ValueOf(a)
  708. for i := 0; i < va.Len(); i++ {
  709. if i > 0 && reflect.DeepEqual(va.Index(i-1).Interface(), va.Index(i).Interface()) {
  710. continue
  711. }
  712. ret = append(ret, va.Index(i).Interface())
  713. }
  714. return ret
  715. }