task.go 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991
  1. package main
  2. import (
  3. "encoding/json"
  4. "field_sync/config"
  5. "field_sync/oss"
  6. "fmt"
  7. "net"
  8. "reflect"
  9. "regexp"
  10. "sort"
  11. "strconv"
  12. "strings"
  13. "time"
  14. "log"
  15. "go.mongodb.org/mongo-driver/bson"
  16. util "jygit.jydev.jianyu360.cn/data_processing/common_utils"
  17. "jygit.jydev.jianyu360.cn/data_processing/common_utils/mongodb"
  18. "jygit.jydev.jianyu360.cn/data_processing/common_utils/redis"
  19. "jygit.jydev.jianyu360.cn/data_processing/common_utils/udp"
  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. q, _ := mapInfo["query"].(map[string]interface{})
  29. bkey, _ := mapInfo["bkey"].(string)
  30. if q == nil {
  31. q = map[string]interface{}{
  32. "_id": map[string]interface{}{
  33. "$gt": mongodb.StringTOBsonId(mapInfo["gtid"].(string)),
  34. "$lte": mongodb.StringTOBsonId(mapInfo["lteid"].(string)),
  35. },
  36. }
  37. }
  38. //extract库
  39. // extractConn := MgoE.GetMgoConn()
  40. // defer MgoE.DestoryMongoConn(extractConn)
  41. // extractResult := extractConn.DB(MgoE.DbName).C(config.Conf.DB.MongoE.Coll).Find(q).Select(map[string]interface{}{
  42. // "field_source": 0,
  43. // "kvtext": 0,
  44. // }).Sort("_id").Iter()
  45. // eMap := map[string]map[string]interface{}{}
  46. // extCount, repeatCount := 0, 0
  47. // for tmp := make(map[string]interface{}); extractResult.Next(tmp); extCount++ {
  48. // if util.IntAll(tmp["repeat"]) == 1 {
  49. // repeatCount++
  50. // }
  51. // tid := mongodb.BsonIdToSId(tmp["_id"])
  52. // eMap[tid] = tmp
  53. // tmp = make(map[string]interface{})
  54. // }
  55. // log.Println("抽取表 数据量", extCount, "重复数据量", repeatCount)
  56. //bidding库
  57. biddingConn := MgoB.GetMgoConn()
  58. count, _ := biddingConn.DB(MgoB.DbName).C(config.Conf.DB.MongoB.Coll).Find(&q).Count()
  59. log.Println("bidding表 同步总数:", count)
  60. c := 0
  61. // if count < 500000 {
  62. var res []map[string]interface{}
  63. result := biddingConn.DB(MgoB.DbName).C(config.Conf.DB.MongoB.Coll).Find(q).Select(map[string]interface{}{
  64. "contenthtml": 0,
  65. }).Iter()
  66. for tmp := make(map[string]interface{}); result.Next(tmp); {
  67. res = append(res, tmp)
  68. tmp = make(map[string]interface{})
  69. }
  70. MgoB.DestoryMongoConn(biddingConn)
  71. // log.Println("查询结果 bidding", count, "抽取:", extCount)
  72. c = doIndex(res, bkey, stype)
  73. // } else {
  74. // log.Println("查询结果 数据量太大,放弃", count)
  75. // MgoB.DestoryMongoConn(biddingConn)
  76. // }
  77. log.Println("bidding sync...over all", count, "extract sync ", c)
  78. NextNode(mapInfo, stype)
  79. NextNodePro(mapInfo, stype)
  80. // NextNodeTidb(mapInfo, stype)
  81. if stype == "bidding_history" {
  82. NextNodeBidData(mapInfo) // bidding-data数据
  83. // NextNodeTidbQyxy(mapInfo) // tidb-企业数据
  84. // NextNodeHn(mapInfo)
  85. }
  86. if stype == "bidding" {
  87. uq := map[string]interface{}{
  88. "gtid": map[string]interface{}{
  89. "$gte": util.ObjToString(mapInfo["gtid"]),
  90. },
  91. "lteid": map[string]interface{}{
  92. "$lte": util.ObjToString(mapInfo["lteid"]),
  93. },
  94. }
  95. MgoBP.Update("bidding_processing_ids", uq, bson.M{"$set": bson.M{"dataprocess_ai": 6, "updatetime": time.Now().Unix()}}, false, true)
  96. }
  97. //领域标签处理的数据 id段
  98. // if stype == "bidding_history" {
  99. // MgoB.Save("field_data_record", map[string]interface{}{"gtid": mapInfo["gtid"], "lteid": mapInfo["lteid"], "status": 0})
  100. // }
  101. }
  102. func biddingAllTask(data []byte, mapInfo map[string]interface{}) {
  103. defer util.Catch()
  104. q, _ := mapInfo["query"].(map[string]interface{})
  105. if q == nil {
  106. q = map[string]interface{}{
  107. "_id": map[string]interface{}{
  108. "$gt": mongodb.StringTOBsonId(mapInfo["gtid"].(string)),
  109. "$lte": mongodb.StringTOBsonId(mapInfo["lteid"].(string)),
  110. },
  111. }
  112. }
  113. //extract库
  114. extractConn := MgoE.GetMgoConn()
  115. defer MgoE.DestoryMongoConn(extractConn)
  116. extractResult := extractConn.DB(MgoE.DbName).C(config.Conf.DB.MongoE.Coll).Find(q).Select(map[string]interface{}{
  117. "field_source": 0,
  118. "kvtext": 0,
  119. }).Sort("-_id").Iter()
  120. //bidding库
  121. biddingConn := MgoB.GetMgoConn()
  122. defer MgoB.DestoryMongoConn(biddingConn)
  123. count := 0
  124. var compare map[string]interface{}
  125. result := biddingConn.DB(MgoB.DbName).C(config.Conf.DB.MongoB.Coll).Find(q).Select(map[string]interface{}{
  126. "contenthtml": 0,
  127. "field_source": 0,
  128. }).Sort("-_id").Iter()
  129. for tmp := make(map[string]interface{}); result.Next(tmp); count++ {
  130. update := map[string]interface{}{}
  131. del := map[string]interface{}{} //记录extract没有值而bidding中有值的字段
  132. //对比方法----------------
  133. for {
  134. if compare == nil {
  135. compare = make(map[string]interface{})
  136. if !extractResult.Next(compare) {
  137. break
  138. }
  139. }
  140. if compare != nil {
  141. cid := mongodb.BsonIdToSId(compare["_id"])
  142. tid := mongodb.BsonIdToSId(tmp["_id"])
  143. if cid == tid {
  144. //更新bidding表;bidding表modifyinfo中的字段不更新
  145. modifyinfo := make(map[string]bool)
  146. if tmpmodifyinfo, ok := tmp["modifyinfo"].(map[string]interface{}); ok && tmpmodifyinfo != nil {
  147. for k := range tmpmodifyinfo {
  148. modifyinfo[k] = true
  149. }
  150. }
  151. for _, k := range config.Conf.Serve.FieldS {
  152. v1 := compare[k] //extract
  153. v2 := tmp[k] //bidding
  154. if v2 == nil && v1 != nil {
  155. update[k] = v1
  156. } else if v2 != nil && v1 != nil && !modifyinfo[k] {
  157. update[k] = v1
  158. } else if v2 != nil && v1 == nil && !modifyinfo[k] {
  159. if k == "s_subscopeclass" && del["subscopeclass"] == nil {
  160. continue
  161. } else if k == "s_topscopeclass" && del["topscopeclass"] == nil {
  162. continue
  163. }
  164. del[k] = 1
  165. //util.Debug("抽取结果没有值,bidding有值:field--", k, del)
  166. }
  167. }
  168. if util.IntAll(compare["repeat"]) == 1 {
  169. update["extracttype"] = -1
  170. update["dataprocess"] = 7
  171. if compare["repeat_id"] != nil {
  172. update["repeat_id"] = compare["repeat_id"]
  173. }
  174. } else {
  175. update["extracttype"] = 1
  176. update["dataprocess"] = 8
  177. }
  178. break
  179. } else {
  180. if cid < tid {
  181. compare = nil
  182. continue
  183. } else {
  184. break
  185. }
  186. }
  187. } else {
  188. break
  189. }
  190. }
  191. //------------------对比结束
  192. //处理分类
  193. if compare != nil { //extract
  194. fieldFun(compare, update)
  195. compare = nil
  196. }
  197. // entidlist
  198. extractMap := make(map[string]interface{})
  199. if update["s_winner"] != "" {
  200. cid := companyFun(update)
  201. if len(cid) > 0 {
  202. update["entidlist"] = cid
  203. extractMap["entidlist"] = cid
  204. }
  205. }
  206. if len(extractMap) > 0 {
  207. updateExtPool <- []map[string]interface{}{
  208. {"_id": tmp["_id"]},
  209. {"$set": extractMap},
  210. }
  211. }
  212. // 附件有效字段
  213. if i := validFile(tmp); i != 0 {
  214. if i == -1 {
  215. update["isValidFile"] = false
  216. } else {
  217. update["isValidFile"] = true
  218. }
  219. }
  220. if len(update) > 0 {
  221. if len(del) > 0 { //删除的字段
  222. updateBidPool <- []map[string]interface{}{{
  223. "_id": tmp["_id"],
  224. },
  225. {"$set": update, "$unset": del},
  226. }
  227. } else {
  228. updateBidPool <- []map[string]interface{}{{
  229. "_id": tmp["_id"],
  230. },
  231. {"$set": update},
  232. }
  233. }
  234. }
  235. if count%50000 == 0 {
  236. log.Println("biddingTask current", count)
  237. }
  238. tmp = make(map[string]interface{})
  239. }
  240. log.Println("biddingAll sync...over all", count)
  241. }
  242. func doIndex(infos []map[string]interface{}, bkey, stype string) int {
  243. syncNo := 0 //抽取表数据同步数量
  244. //对比两张表数据,减少查询次数
  245. var compare map[string]interface{}
  246. var bidUpdate [][]map[string]interface{}
  247. var extUpdate [][]map[string]interface{}
  248. //SaveEsLock := &sync.Mutex{}
  249. log.Println("start ...")
  250. for n, tmp := range infos {
  251. tid := mongodb.BsonIdToSId(tmp["_id"])
  252. update := map[string]interface{}{} //要更新的mongo数据
  253. del := map[string]interface{}{}
  254. edata, _ := MgoE.FindById(config.Conf.DB.MongoE.Coll, tid, nil)
  255. //对比方法----------------
  256. if edata != nil && len(*edata) > 0 {
  257. compare = *edata
  258. if stype == "bidding" {
  259. // 增量id段 正常数据
  260. if dg := util.IntAll(compare["dataging"]); dg == 1 { //extract中dataging=1跳过
  261. tmp = make(map[string]interface{})
  262. compare = nil
  263. continue
  264. }
  265. // delete(eMap, tid)
  266. }
  267. if stype == "bidding_history" {
  268. //增量id段 历史数据
  269. if compare["history_updatetime"] == nil { //extract中history_updatetime不存在跳过
  270. tmp = make(map[string]interface{})
  271. compare = nil
  272. continue
  273. }
  274. // delete(eMap, tid)
  275. }
  276. syncNo++
  277. log.Println("抽取区域 省", compare["area"], " 市 ", compare["city"], " 区 ", compare["district"], " id ", tid)
  278. modifyinfo := make(map[string]bool)
  279. if tmp["modifyinfo"] != nil {
  280. if tmpmodifyinfo, ok := tmp["modifyinfo"].(map[string]interface{}); ok {
  281. for k := range tmpmodifyinfo {
  282. modifyinfo[k] = true
  283. }
  284. }
  285. }
  286. for _, k := range config.Conf.Serve.FieldS {
  287. v1 := compare[k] //extract
  288. v2 := tmp[k] //bidding
  289. if v2 == nil && v1 != nil {
  290. update[k] = v1
  291. } else if v2 != nil && v1 != nil && !modifyinfo[k] {
  292. update[k] = v1
  293. } else if v2 != nil && v1 == nil && !modifyinfo[k] {
  294. if k == "s_subscopeclass" && del["subscopeclass"] == nil {
  295. continue
  296. } else if k == "s_topscopeclass" && del["topscopeclass"] == nil {
  297. continue
  298. } else if k == "city" || k == "district" {
  299. update[k] = ""
  300. } else {
  301. del[k] = 1
  302. }
  303. }
  304. }
  305. // 附件重采,数据同步时不更新判重标识
  306. if util.IntAll(compare["repeat"]) == 1 {
  307. update["extracttype"] = -1
  308. update["dataprocess"] = 7
  309. if compare["repeat_id"] != nil {
  310. update["repeat_id"] = compare["repeat_id"]
  311. }
  312. } else {
  313. update["extracttype"] = 1
  314. update["dataprocess"] = 8
  315. }
  316. } else {
  317. compare = nil
  318. if util.IntAll(tmp["dataging"]) == 1 { //修改未抽取的bidding数据的dataging
  319. update["dataging"] = 0
  320. }
  321. update["dataprocess"] = 8
  322. }
  323. //下面可以多线程跑的--->
  324. //处理分类
  325. if compare != nil { //extract
  326. fieldFun(compare, update)
  327. // publishtime 20230523
  328. if util.IntAll(tmp["publishtime"]) == -1 {
  329. if pb := methodPb(compare); pb > 0 {
  330. update["publishtime"] = pb
  331. }
  332. }
  333. compare = nil
  334. }
  335. //------------------对比结束
  336. //处理key descript
  337. if bkey == "" {
  338. DealInfo(&tmp, &update)
  339. }
  340. // entidlist
  341. extractMap := make(map[string]interface{})
  342. if update["s_winner"] != "" {
  343. cid := companyFun(update)
  344. if len(cid) > 0 {
  345. tmp["entidlist"] = cid
  346. update["entidlist"] = cid
  347. extractMap["entidlist"] = cid
  348. }
  349. }
  350. // 6.10 剑鱼发布信息分类处理, 写在这里是为了修改抽取表
  351. typeFunc(tmp, update, extractMap)
  352. if len(extractMap) > 0 {
  353. if extractMap["toptype"] != nil && extractMap["subtype"] == nil {
  354. extUpdate = append(extUpdate, []map[string]interface{}{
  355. {"_id": tmp["_id"]},
  356. {"$set": extractMap, "$unset": map[string]interface{}{"subtype": ""}},
  357. })
  358. } else {
  359. extUpdate = append(extUpdate, []map[string]interface{}{
  360. {"_id": tmp["_id"]},
  361. {"$set": extractMap},
  362. })
  363. }
  364. if len(extUpdate) >= MgoBulkSize {
  365. tmps := extUpdate
  366. MgoE.UpdateBulk(config.Conf.DB.MongoE.Coll, tmps...)
  367. extUpdate = [][]map[string]interface{}{}
  368. }
  369. }
  370. // 附件有效字段
  371. if i := validFile(tmp); i != 0 {
  372. if i == -1 {
  373. tmp["isValidFile"] = false
  374. update["isValidFile"] = false
  375. } else {
  376. tmp["isValidFile"] = true
  377. update["isValidFile"] = true
  378. }
  379. }
  380. // 2024-02-21 徐志恒 情报标签字段
  381. toptype := util.ObjToString(tmp["toptype"])
  382. subtype := util.ObjToString(tmp["subtype"])
  383. buyerclass := util.ObjToString(update["buyerclass"])
  384. if buyerclass != "" {
  385. update["buyer_type"] = getStr(buyerclass)
  386. }
  387. s_topscopeclass := util.ObjToString(update["s_topscopeclass"])
  388. if (tmp["tag_topinformation"] != nil && (subtype == "合同" || subtype == "中标" || subtype == "成交" || subtype == "采购意向" || toptype == "招标")) || (tmp["tag_topinformation"] == nil && toptype == "拟建" && strings.Contains(s_topscopeclass, "建筑工程")) {
  389. update["tag_set"] = getTagSet(tmp, compare)
  390. }
  391. if len(update) > 0 {
  392. log.Println("保存bidding区域 省", update["area"], " 市 ", update["city"], " 区 ", update["district"], update["buyerclass"], update["buyer_type"], " id ", tid)
  393. if len(del) > 0 {
  394. bidUpdate = append(bidUpdate, []map[string]interface{}{{
  395. "_id": tmp["_id"],
  396. },
  397. {"$set": update, "$unset": del},
  398. })
  399. } else {
  400. bidUpdate = append(bidUpdate, []map[string]interface{}{{
  401. "_id": tmp["_id"],
  402. },
  403. {"$set": update},
  404. })
  405. }
  406. if len(bidUpdate) >= MgoBulkSize {
  407. tmps := bidUpdate
  408. MgoB.UpdateBulk(config.Conf.DB.MongoB.Coll, tmps...)
  409. bidUpdate = [][]map[string]interface{}{}
  410. }
  411. }
  412. if n%500 == 0 {
  413. log.Println("biddingTask current ", n)
  414. }
  415. tmp = make(map[string]interface{})
  416. }
  417. //SaveEsLock.Lock()
  418. if len(bidUpdate) > 0 {
  419. tmps := bidUpdate
  420. MgoB.UpdateBulk(config.Conf.DB.MongoB.Coll, tmps...)
  421. bidUpdate = [][]map[string]interface{}{}
  422. }
  423. if len(extUpdate) > 0 {
  424. tmps := extUpdate
  425. MgoE.UpdateBulk(config.Conf.DB.MongoE.Coll, tmps...)
  426. extUpdate = [][]map[string]interface{}{}
  427. }
  428. //SaveEsLock.Unlock()
  429. return syncNo
  430. }
  431. // @Description subscopeclass、topscopeclass、package
  432. // 20230523 多包处理 subpackage = 1
  433. // @Author J 2022/6/7 5:54 PM
  434. func fieldFun(compare, update map[string]interface{}) {
  435. subscopeclass, _ := compare["subscopeclass"].([]interface{}) //subscopeclass
  436. if subscopeclass != nil {
  437. m1 := map[string]bool{}
  438. newclass := []string{}
  439. for _, sc := range subscopeclass {
  440. sclass, _ := sc.(string)
  441. if !m1[sclass] {
  442. m1[sclass] = true
  443. newclass = append(newclass, sclass)
  444. }
  445. }
  446. update["s_subscopeclass"] = strings.Join(newclass, ",")
  447. update["subscopeclass"] = newclass
  448. }
  449. topscopeclass, _ := compare["topscopeclass"].([]interface{}) //topscopeclass
  450. if topscopeclass != nil {
  451. m2 := map[string]bool{}
  452. newclass := []string{}
  453. for _, tc := range topscopeclass {
  454. tclass, _ := tc.(string)
  455. tclass = regLetter.ReplaceAllString(tclass, "") // 去除字母
  456. if !m2[tclass] {
  457. m2[tclass] = true
  458. newclass = append(newclass, tclass)
  459. }
  460. }
  461. update["topscopeclass"] = topscopeclass
  462. update["s_topscopeclass"] = strings.Join(newclass, ",")
  463. }
  464. if package1 := compare["package"]; package1 != nil {
  465. packageM, _ := package1.(map[string]interface{})
  466. update["package"] = packageM
  467. for _, p := range packageM {
  468. pm, _ := p.(map[string]interface{})
  469. if util.ObjToString(pm["winner"]) != "" || util.Float64All(pm["budget"]) > 0 ||
  470. util.Float64All(pm["bidamount"]) > 0 {
  471. update["multipackage"] = 1
  472. break
  473. }
  474. }
  475. } else {
  476. update["multipackage"] = 0
  477. }
  478. // subpackage
  479. if compare["package"] != nil && compare["s_winner"] != nil && compare["bidamount"] != nil {
  480. pg := compare["package"].(map[string]interface{})
  481. if len(pg) > 1 {
  482. var bmt []float64
  483. var swn []string
  484. for _, p := range pg {
  485. p1 := p.(map[string]interface{})
  486. if p1["bidamount"] != nil {
  487. bmt = append(bmt, util.Float64All(p1["bidamount"]))
  488. }
  489. if w := util.ObjToString(p1["winner"]); w != "" {
  490. swn = append(swn)
  491. }
  492. }
  493. if len(bmt) > 1 && len(swn) > 1 {
  494. sn := strings.Split(util.ObjToString(compare["s_winner"]), ",")
  495. sort.Strings(sn)
  496. sort.Strings(swn)
  497. swn1 := util.ObjArrToStringArr(Duplicate(swn)) // 去重
  498. if strings.Join(swn1, ",") == strings.Join(sn, ",") {
  499. bidamount := 0.0
  500. for _, f := range bmt {
  501. bidamount += f
  502. }
  503. if bidamount == util.Float64All(compare["bidamount"]) {
  504. update["subpackage"] = 1
  505. }
  506. }
  507. }
  508. }
  509. }
  510. }
  511. // @Description entidlist
  512. // @Author J 2022/6/7 2:36 PM
  513. func companyFun(tmp map[string]interface{}) (cid []string) {
  514. sWinnerarr := strings.Split(util.ObjToString(tmp["s_winner"]), ",")
  515. for _, w := range sWinnerarr {
  516. if w != "" {
  517. id := redis.GetStr("qyxy_id", w)
  518. if id == "" {
  519. 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)
  520. if len(*ents) > 0 {
  521. id = util.ObjToString((*ents)[0]["_id"])
  522. redis.PutCKV("qyxy_id", w, id)
  523. } else {
  524. ent, _ := MgoP.FindOne(config.Conf.DB.MongoP.Coll, map[string]interface{}{"history_name": w})
  525. if len(*ent) > 0 {
  526. id = util.ObjToString((*ent)["company_id"])
  527. redis.PutCKV("qyxy_id", w, id)
  528. }
  529. }
  530. }
  531. if id == "" {
  532. id = "-"
  533. }
  534. cid = append(cid, id)
  535. }
  536. }
  537. return cid
  538. }
  539. // @Description update 修改bidding表,extractM修改抽取表
  540. // @Author J 2022/6/10 10:29 AM
  541. func typeFunc(tmp, update, extractM map[string]interface{}) {
  542. if jyData, ok := tmp["jyfb_data"].(map[string]interface{}); ok {
  543. if t := util.ObjToString(jyData["type"]); t != "" {
  544. switch t {
  545. //case "采购信息":
  546. case "招标公告":
  547. if util.ObjToString(tmp["toptype"]) != "招标" {
  548. update["toptype"] = "招标"
  549. extractM["toptype"] = "招标"
  550. delete(update, "subtype")
  551. }
  552. case "采购意向":
  553. if util.ObjToString(tmp["toptype"]) != "采购意向" {
  554. update["toptype"] = "采购意向"
  555. update["subtype"] = "采购意向"
  556. extractM["toptype"] = "采购意向"
  557. extractM["subtype"] = "采购意向"
  558. }
  559. case "招标预告":
  560. if util.ObjToString(tmp["toptype"]) != "预告" {
  561. update["toptype"] = "预告"
  562. extractM["toptype"] = "预告"
  563. delete(update, "subtype")
  564. }
  565. case "招标结果":
  566. if util.ObjToString(tmp["toptype"]) != "结果" {
  567. update["toptype"] = "结果"
  568. extractM["toptype"] = "结果"
  569. delete(update, "subtype")
  570. }
  571. }
  572. }
  573. }
  574. }
  575. // @Description 附件有效字段(isValidFile)
  576. // @Author J 2022/7/8 14:41
  577. func validFile(tmp map[string]interface{}) int {
  578. isContinue := false
  579. if pinfo, o := tmp["projectinfo"].(map[string]interface{}); o {
  580. if atts, o1 := pinfo["attachments"].(map[string]interface{}); o1 {
  581. for _, att := range atts {
  582. if att == nil {
  583. continue
  584. }
  585. if reflect.TypeOf(att).String() == "string" {
  586. continue
  587. }
  588. att1 := att.(map[string]interface{})
  589. if fid := util.ObjToString(att1["fid"]); fid != "" {
  590. isContinue = true
  591. break
  592. }
  593. }
  594. if isContinue {
  595. if attachTxt, o := tmp["attach_text"].(map[string]interface{}); o {
  596. if len(attachTxt) > 0 {
  597. for _, at := range attachTxt {
  598. at1 := at.(map[string]interface{})
  599. if len(at1) > 0 {
  600. for k, _ := range at1 {
  601. if reflect.TypeOf(at1[k]).String() == "string" {
  602. continue
  603. }
  604. at2 := at1[k].(map[string]interface{})
  605. s := strings.ToLower(util.ObjToString(at2["file_name"]))
  606. if !strings.Contains(s, "jpg") || !strings.Contains(s, "jpeg") != strings.Contains(s, "png") ||
  607. strings.Contains(s, "pdf") {
  608. if strings.Contains(s, "swf") || strings.Contains(s, "html") {
  609. return -1
  610. } else if AnalysisFile(oss.OssGetObject(util.ObjToString(at2["attach_url"]))) {
  611. return 1
  612. }
  613. }
  614. }
  615. break
  616. } else {
  617. break
  618. }
  619. }
  620. }
  621. }
  622. flag := false
  623. for _, att := range atts {
  624. if att == nil {
  625. continue
  626. }
  627. if reflect.TypeOf(att).String() == "string" {
  628. continue
  629. }
  630. att1 := att.(map[string]interface{})
  631. if fid := util.ObjToString(att1["fid"]); fid != "" {
  632. ftype := strings.ToLower(util.ObjToString(tmp["ftype"]))
  633. if ftype != "swf" && ftype != "html" && oss.OssObjExists("jy-datafile", fid) {
  634. return 1
  635. } else {
  636. flag = true
  637. }
  638. }
  639. }
  640. if flag {
  641. return -1
  642. }
  643. }
  644. }
  645. }
  646. return 0
  647. }
  648. // @Description id不变,内容变化 重新索引数据
  649. // @Author J 2022/8/10 13:29
  650. func taskinfo(id string) {
  651. tmp, _ := MgoB.FindById("bidding", id, nil)
  652. if tmp == nil || len(*tmp) == 0 {
  653. log.Println(fmt.Sprintf("taskinfo bidding id=%s 未查询到数据", id))
  654. return
  655. }
  656. extractM, _ := MgoE.FindById(config.Conf.DB.MongoE.Coll, id, nil)
  657. if extractM == nil || len(*extractM) == 0 {
  658. extractM, _ = MgoE.FindById(config.Conf.DB.MongoE.Coll1, id, nil)
  659. if extractM == nil || len(*extractM) == 0 {
  660. log.Println(fmt.Sprintf("taskinfo extract id=%s 未查询到数据", id))
  661. return
  662. }
  663. }
  664. update := map[string]interface{}{} //要更新的mongo数据
  665. //更新bidding表字段
  666. for _, k := range config.Conf.Serve.FieldS {
  667. v1 := (*extractM)[k] //extract
  668. v2 := (*tmp)[k] //bidding
  669. if v2 == nil && v1 != nil {
  670. update[k] = v1
  671. } else if v2 != nil && v1 != nil {
  672. update[k] = v1
  673. } else if v2 != nil && v1 == nil {
  674. if k == "city" || k == "district" {
  675. update[k] = ""
  676. }
  677. }
  678. }
  679. if util.IntAll((*extractM)["repeat"]) == 1 {
  680. update["extracttype"] = -1
  681. update["dataprocess"] = 7
  682. if (*extractM)["repeat_id"] != nil {
  683. update["repeat_id"] = (*extractM)["repeat_id"]
  684. }
  685. } else {
  686. update["extracttype"] = 1
  687. update["dataprocess"] = 8
  688. }
  689. //处理分类
  690. fieldFun(*extractM, update)
  691. extractMap := make(map[string]interface{})
  692. if util.ObjToString((*tmp)["s_winner"]) != "" {
  693. cid := companyFun(*tmp)
  694. if len(cid) > 0 {
  695. update["entidlist"] = cid
  696. extractMap["entidlist"] = cid
  697. }
  698. MgoE.UpdateById(config.Conf.DB.MongoE.Coll, id, map[string]interface{}{"$set": extractMap})
  699. }
  700. // 附件有效字段
  701. if i := validFile(*tmp); i != 0 {
  702. if i == -1 {
  703. update["isValidFile"] = false
  704. } else {
  705. update["isValidFile"] = true
  706. }
  707. }
  708. if len(update) > 0 {
  709. MgoB.UpdateById(config.Conf.DB.MongoB.Coll, id, map[string]interface{}{"$set": update})
  710. }
  711. mapinfo := map[string]interface{}{
  712. "infoid": id,
  713. "stype": "index-by-id",
  714. }
  715. datas, _ := json.Marshal(mapinfo)
  716. var next = &net.UDPAddr{
  717. IP: net.ParseIP(config.Conf.Udp.Next.Addr),
  718. Port: util.IntAll(config.Conf.Udp.Next.Port),
  719. }
  720. log.Println("nsq data over es ", next, " mapinfo ", string(datas))
  721. _ = UdpClient.WriteUdp(datas, udp.OP_TYPE_DATA, next)
  722. }
  723. var DateTimeSelect = []string{"bidopentime", "bidendtime", "signaturedate", "comeintime"}
  724. // @Description 发布时间处理
  725. // @Author J 2023/5/23 14:32
  726. func methodPb(tmp map[string]interface{}) int64 {
  727. if tmp["ext_publishtime"] != nil {
  728. if newPb := util.Int64All(tmp["ext_publishtime"]); newPb < time.Now().Unix() && newPb > 1420041600 {
  729. return newPb
  730. }
  731. }
  732. for _, d := range DateTimeSelect {
  733. if tmp[d] != nil && util.Int64All(tmp[d]) < time.Now().Unix() {
  734. return util.Int64All(tmp[d])
  735. }
  736. }
  737. return 0
  738. }
  739. // Duplicate
  740. // @Description 去重
  741. // @Author J 2023/5/24 09:53
  742. func Duplicate(a interface{}) (ret []interface{}) {
  743. va := reflect.ValueOf(a)
  744. for i := 0; i < va.Len(); i++ {
  745. if i > 0 && reflect.DeepEqual(va.Index(i-1).Interface(), va.Index(i).Interface()) {
  746. continue
  747. }
  748. ret = append(ret, va.Index(i).Interface())
  749. }
  750. return ret
  751. }
  752. // @Description 获取情报标签
  753. // @Author 徐志恒 2024/2/21 09:53
  754. func getTagSet(tmp, compare map[string]interface{}) map[string]map[string]interface{} {
  755. tagSet := map[string]map[string]interface{}{}
  756. wuye := map[string]interface{}{}
  757. buyer := util.ObjToString(compare["buyer"])
  758. publishtime := util.Int64All(tmp["publishtime"])
  759. bidamount := util.Float64All(compare["bidamount"])
  760. toptype := util.ObjToString(tmp["toptype"])
  761. subtype := util.ObjToString(tmp["subtype"])
  762. if subtype == "合同" {
  763. wuye["isfirsthand"] = 62
  764. if buyer != "" {
  765. sql := `{
  766. "query": {
  767. "bool": {
  768. "must": [
  769. {
  770. "term": {
  771. "buyer": "` + buyer + `"
  772. }
  773. },
  774. {
  775. "term": {
  776. "tag_topinformation": "情报_物业"
  777. }
  778. },
  779. {
  780. "term": {
  781. "subtype": "合同"
  782. }
  783. },
  784. {
  785. "range": {
  786. "publishtime": {
  787. "lte": ` + fmt.Sprint(publishtime) + `
  788. }
  789. }
  790. }
  791. ]
  792. }
  793. },
  794. "sort": {
  795. "publishtime": "asc"
  796. },
  797. "_source": [
  798. "s_winner"
  799. ],
  800. "size": 10000
  801. }`
  802. data := Es.Get("bidding", "bidding", sql)
  803. if data != nil && len(*data) > 0 {
  804. count := 0
  805. first := util.ObjToString((*data)[0]["s_winner"])
  806. for k, v := range *data {
  807. winner := util.ObjToString(v["s_winner"])
  808. if k > 0 && first != winner {
  809. first = winner
  810. count++
  811. }
  812. }
  813. changehand := fmt.Sprintf("%.2f", float64(count)/float64(len(*data)))
  814. changehands, _ := strconv.ParseFloat(changehand, 64)
  815. wuye["changehand"] = changehands
  816. if changehands > 0.3 {
  817. wuye["changehandindex"] = 61
  818. }
  819. if len(*data) > 1 {
  820. wuye["isfirsthand"] = 0
  821. }
  822. }
  823. }
  824. wuye["period"] = getperiod(compare)
  825. } else if toptype == "招标" || toptype == "采购意向" {
  826. bidamount = util.Float64All(compare["budget"])
  827. }
  828. if tmp["projectinfo"] != nil {
  829. projectInfo := util.ObjToMap(tmp["projectinfo"])
  830. if projectInfo != nil && len(*projectInfo) > 0 {
  831. if (*projectInfo)["attachments"] != nil {
  832. wuye["isfile"] = 63
  833. }
  834. }
  835. }
  836. wuye["scale"] = getBidamountRange(bidamount)
  837. if tmp["property_form"] != nil {
  838. property_form := util.ObjArrToStringArr(tmp["property_form"].([]interface{}))
  839. wuye["property_form"] = getpropertyform(property_form)
  840. }
  841. tagSet["wuye"] = wuye
  842. return tagSet
  843. }
  844. func getBidamountRange(value float64) int {
  845. switch {
  846. case value < 500000:
  847. return 1
  848. case value >= 500000 && value < 1000000:
  849. return 2
  850. case value >= 1000000 && value < 2000000:
  851. return 3
  852. case value >= 2000000 && value < 5000000:
  853. return 4
  854. default:
  855. return 5
  856. }
  857. }
  858. func getpropertyform(value []string) string {
  859. arr := []string{}
  860. categories := map[string]string{
  861. "住宅": "21",
  862. "政府办公楼": "22",
  863. "学校": "23",
  864. "医院": "24",
  865. "产业园区": "25",
  866. "旅游景区": "26",
  867. "交通运输": "27",
  868. "商务办公楼": "28",
  869. "酒店": "29",
  870. }
  871. for _, v := range value {
  872. if categories[v] != "" {
  873. arr = append(arr, categories[v])
  874. }
  875. }
  876. return strings.Join(arr, ",")
  877. }
  878. func getperiod(data map[string]interface{}) int {
  879. res := 16
  880. signaturedate := util.Int64All(data["signaturedate"]) //合同签订日期
  881. expiredate := util.Int64All(data["expiredate"]) //合同截止日期
  882. // contractperiod := util.ObjToString(data["contractperiod"]) //合同期限
  883. project_duration := util.IntAll(data["project_duration"]) //工期时长
  884. project_timeunit := util.ObjToString(data["project_timeunit"]) //工期单位
  885. result := float64(0)
  886. if expiredate > 0 && signaturedate > 0 {
  887. result = calculateYearDifference(signaturedate, expiredate)
  888. } else if project_duration > 0 && project_timeunit != "" {
  889. if strings.Contains(project_timeunit, "年") {
  890. if project_duration == 1 {
  891. res = 12
  892. } else if project_duration == 2 {
  893. res = 13
  894. } else if project_duration == 3 {
  895. res = 14
  896. } else if project_duration == 5 {
  897. res = 15
  898. }
  899. return res
  900. } else if strings.Contains(project_timeunit, "月") {
  901. result = float64(project_duration) / 12
  902. } else if strings.Contains(project_timeunit, "周") {
  903. result = float64(project_duration) * 7 / 365
  904. } else if strings.Contains(project_timeunit, "日") || strings.Contains(project_timeunit, "天") {
  905. result = float64(project_duration) / 365
  906. }
  907. }
  908. if result == 0 {
  909. res = 16
  910. } else if result < 1 {
  911. res = 11
  912. } else if result >= 1 && result < 2 {
  913. res = 12
  914. } else if result >= 2 && result < 3 {
  915. res = 13
  916. } else if result >= 3 && result < 4 {
  917. res = 14
  918. } else if result >= 5 {
  919. res = 15
  920. }
  921. return res
  922. }
  923. func calculateYearDifference(startTime int64, endTime int64) float64 {
  924. start := time.Unix(startTime, 0)
  925. end := time.Unix(endTime, 0)
  926. duration := end.Sub(start)
  927. years := duration.Hours() / 24 / 365
  928. return years
  929. }
  930. func getStr(b string) string {
  931. if b == "" {
  932. return "其它"
  933. }
  934. a1 := "(交通|运输物流|工信|农业|住建|城管|市政|出版广电|检察院|科技|民政|生态环境|市场监管|水利|应急管理|自然资源|财政|档案|党委办|组织|发改|宣传|政府办|政务中心|人大|政协|法院|公安|国资委|海关|机关事务|纪委|军队|人社|商务|审计税务|司法|体育|统计|统战|文旅|民宗|银保监|证监|气象|社会团体|公共资源交易)"
  935. a2 := "(卫健委|医疗)"
  936. a3 := "(教育|学校)"
  937. a4 := "(人行|金融业)"
  938. a5 := "(信息技术|电信行业|农林牧渔|建筑业|传媒|制造业|住宿餐饮|采矿业|能源化工|批发零售)"
  939. if strings.Contains(a1, b) {
  940. return "政府机构"
  941. } else if strings.Contains(a2, b) {
  942. return "医疗单位"
  943. } else if strings.Contains(a3, b) {
  944. return "教育单位"
  945. } else if strings.Contains(a4, b) {
  946. return "金融企业"
  947. } else if strings.Contains(a5, b) {
  948. return "商业公司"
  949. } else {
  950. return "其它"
  951. }
  952. return "其它"
  953. }