task.go 27 KB

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