task.go 20 KB

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