bidding_es.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752
  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/udp"
  7. "encoding/json"
  8. "esindex/config"
  9. "esindex/oss"
  10. "fmt"
  11. "github.com/spf13/viper"
  12. "go.mongodb.org/mongo-driver/bson"
  13. "go.uber.org/zap"
  14. "reflect"
  15. "regexp"
  16. "strconv"
  17. "strings"
  18. "sync"
  19. "time"
  20. "unicode/utf8"
  21. )
  22. var (
  23. TimeV1 = regexp.MustCompile("(\\d{4})[年.]?$")
  24. TimeV2 = regexp.MustCompile("(\\d{4}[年.\\-/]?)(\\d{1,2}[月.\\-/]?$)")
  25. TimeClear = regexp.MustCompile("[年|月|/|.|-]")
  26. filterSpace = regexp.MustCompile("<[^>]*?>|[\\s\u3000\u2003\u00a0]")
  27. date1 = regexp.MustCompile("20[0-2][0-9][年|\\-/.][0-9]{1,2}[月|\\-/.][0-9]{1,2}[日]?")
  28. HtmlReg = regexp.MustCompile("<[^>]+>")
  29. )
  30. func biddingTask(mapInfo map[string]interface{}) {
  31. defer util.Catch()
  32. stype := util.ObjToString(mapInfo["stype"])
  33. if stype == "bidding" {
  34. uq := bson.M{"gtid": bson.M{"$gte": util.ObjToString(mapInfo["gtid"])},
  35. "lteid": bson.M{"$lte": util.ObjToString(mapInfo["lteid"])}}
  36. MgoB.Update("bidding_processing_ids", uq, bson.M{"$set": bson.M{"dataprocess": 8, "updatetime": time.Now().Unix()}}, false, true)
  37. }
  38. q, _ := mapInfo["query"].(map[string]interface{})
  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. } else {
  47. //针对gte/lte,单独转换
  48. q = convertToMongoID(q)
  49. }
  50. ch := make(chan bool, 10)
  51. wg := &sync.WaitGroup{}
  52. //bidding库
  53. biddingConn := MgoB.GetMgoConn()
  54. count, _ := biddingConn.DB(MgoB.DbName).C(config.Conf.DB.MongoB.Coll).Find(&q).Count()
  55. log.Info("bidding表", zap.Int64("同步总数:", count))
  56. it := biddingConn.DB(config.Conf.DB.MongoB.Dbname).C(config.Conf.DB.MongoB.Coll).Find(&q).Select(map[string]interface{}{
  57. "contenthtml": 0,
  58. }).Iter()
  59. c1, index := 0, 0
  60. var indexLock sync.Mutex
  61. for tmp := make(map[string]interface{}); it.Next(tmp); c1++ {
  62. if c1%1000 == 0 {
  63. log.Info("biddingTask", zap.Int("current:", c1))
  64. log.Info("biddingAllTask", zap.Any("current:_id =>", tmp["_id"]))
  65. }
  66. ch <- true
  67. wg.Add(1)
  68. go func(tmp map[string]interface{}) {
  69. defer func() {
  70. <-ch
  71. wg.Done()
  72. }()
  73. if sensitive := util.ObjToString(tmp["sensitive"]); sensitive == "测试" { //bidding中有敏感词,不生索引
  74. tmp = make(map[string]interface{})
  75. return
  76. }
  77. //只针对增量数据处理;全量数据 需要用extracttype字段判断
  78. //7: 重复数据
  79. //8: 不重复
  80. if util.IntAll(tmp["dataprocess"]) != 8 {
  81. return
  82. }
  83. //// 增量数据使用上面判断;全量数据使用下面配置
  84. //-1:重复 ,1:不重复 ,0:入库 9:分类
  85. //if util.IntAll(tmp["extracttype"]) != 1 {
  86. // return
  87. //}
  88. //针对产权数据,暂时不入es 索引库
  89. if util.IntAll(tmp["infoformat"]) == 3 {
  90. return
  91. }
  92. /**
  93. 数据抽取时,有的数据的发布时间是之前的,属于增量历史数据,在判重和同步到bidding表是,会添加history_updatetime
  94. 字段,所以下面判断才会处理
  95. */
  96. if stype == "bidding_history" && tmp["history_updatetime"] == nil {
  97. return
  98. }
  99. indexLock.Lock()
  100. index++
  101. indexLock.Unlock()
  102. newTmp, update := GetEsField(tmp, stype)
  103. newTmp["dataweight"] = 0 //索引数据新增 jy置顶字段
  104. //针对中国政府采购网,单独处理
  105. if util.ObjToString(tmp["site"]) == "中国政府采购网" {
  106. objectType := MatchService(tmp)
  107. if objectType != "" {
  108. newTmp["object_type"] = objectType
  109. }
  110. }
  111. if len(update) > 0 {
  112. updateBiddingPool <- []map[string]interface{}{{
  113. "_id": tmp["_id"],
  114. },
  115. {"$set": update},
  116. }
  117. }
  118. if util.ObjToString(newTmp["spidercode"]) == "a_jyxxfbpt_gg" {
  119. // 剑鱼信息发布数据 通过udp通知信息发布程序
  120. go UdpMethod(mongodb.BsonIdToSId(newTmp["_id"]))
  121. }
  122. saveEsPool <- newTmp
  123. }(tmp)
  124. tmp = map[string]interface{}{}
  125. }
  126. wg.Wait()
  127. log.Info("biddingTask over", zap.Int("count", c1), zap.Int("index", index))
  128. // 重采平台需要
  129. //mapInfo["stype"] = ""
  130. //datas, _ := json.Marshal(mapInfo)
  131. //var next = &net.UDPAddr{
  132. // IP: net.ParseIP("127.0.0.1"),
  133. // Port: 1910,
  134. //}
  135. //log.Info("bidding index es over", zap.Any("es", next), zap.String("mapinfo", string(datas)))
  136. }
  137. func biddingAllTask(mapInfo map[string]interface{}) {
  138. defer util.Catch()
  139. stype := util.ObjToString(mapInfo["stype"])
  140. q, _ := mapInfo["query"].(map[string]interface{})
  141. if q == nil {
  142. q = map[string]interface{}{
  143. "_id": map[string]interface{}{
  144. "$gt": mongodb.StringTOBsonId(mapInfo["gtid"].(string)),
  145. "$lte": mongodb.StringTOBsonId(mapInfo["lteid"].(string)),
  146. },
  147. }
  148. } else {
  149. //针对gte/lte,单独转换
  150. q = convertToMongoID(q)
  151. }
  152. ch := make(chan bool, 50)
  153. wg := &sync.WaitGroup{}
  154. //bidding库
  155. biddingConn := MgoB.GetMgoConn()
  156. it := biddingConn.DB(config.Conf.DB.MongoB.Dbname).C(config.Conf.DB.MongoB.Coll).Find(&q).Select(map[string]interface{}{
  157. "contenthtml": 0,
  158. }).Iter()
  159. c1, index := 0, 0
  160. var indexLock sync.Mutex
  161. for tmp := make(map[string]interface{}); it.Next(tmp); c1++ {
  162. if c1%20000 == 0 {
  163. log.Info("biddingAllTask", zap.Int("current:", c1))
  164. log.Info("biddingAllTask", zap.Any("current:_id =>", tmp["_id"]))
  165. }
  166. ch <- true
  167. wg.Add(1)
  168. go func(tmp map[string]interface{}) {
  169. defer func() {
  170. <-ch
  171. wg.Done()
  172. }()
  173. if sensitive := util.ObjToString(tmp["sensitive"]); sensitive == "测试" { //bidding中有敏感词,不生索引
  174. tmp = make(map[string]interface{})
  175. return
  176. }
  177. // 针对存量数据,重复数据不进索引
  178. if util.IntAll(tmp["extracttype"]) == -1 {
  179. return
  180. }
  181. //针对产权数据,暂时不入es 索引库
  182. if util.IntAll(tmp["infoformat"]) == 3 {
  183. return
  184. }
  185. indexLock.Lock()
  186. index++
  187. indexLock.Unlock()
  188. newTmp, update := GetEsField(tmp, stype)
  189. //针对中国政府采购网,单独处理
  190. if util.ObjToString(tmp["site"]) == "中国政府采购网" {
  191. objectType := MatchService(tmp)
  192. if objectType != "" {
  193. newTmp["object_type"] = objectType
  194. }
  195. }
  196. newTmp["dataweight"] = 0 //索引数据新增 jy置顶字段
  197. if len(update) > 0 {
  198. updateBiddingPool <- []map[string]interface{}{{
  199. "_id": tmp["_id"],
  200. },
  201. {"$set": update},
  202. }
  203. }
  204. saveEsPool <- newTmp
  205. }(tmp)
  206. tmp = map[string]interface{}{}
  207. }
  208. wg.Wait()
  209. log.Info("biddingAllTask over", zap.Int("count", c1), zap.Int("index", index))
  210. }
  211. //biddingAllDataTask 处理配置文件的存量数据
  212. func biddingAllDataTask() {
  213. type Biddingall struct {
  214. Coll string
  215. Gtid string
  216. Lteid string
  217. }
  218. type RoutinesConf struct {
  219. Num int
  220. }
  221. type AllConf struct {
  222. All map[string]Biddingall
  223. Routines RoutinesConf
  224. }
  225. var all AllConf
  226. viper.SetConfigFile("biddingall.toml")
  227. viper.SetConfigName("biddingall") // 配置文件名称(无扩展名)
  228. viper.SetConfigType("toml") // 如果配置文件的名称中没有扩展名,则需要配置此项
  229. viper.AddConfigPath("./")
  230. err := viper.ReadInConfig() // 查找并读取配置文件
  231. if err != nil { // 处理读取配置文件的错误
  232. fmt.Println("ReadInConfig err =>", err)
  233. return
  234. }
  235. err = viper.Unmarshal(&all)
  236. if err != nil {
  237. fmt.Println("biddingAllDataTask Unmarshal err =>", err)
  238. return
  239. }
  240. for k, conf := range all.All {
  241. go dealData(conf.Coll, conf.Gtid, conf.Lteid, k, all.Routines.Num)
  242. }
  243. }
  244. func dealData(coll, gtid, lteid, kword string, routines int) {
  245. ch := make(chan bool, routines)
  246. wg := &sync.WaitGroup{}
  247. q := map[string]interface{}{
  248. "_id": map[string]interface{}{
  249. "$gt": mongodb.StringTOBsonId(gtid),
  250. "$lte": mongodb.StringTOBsonId(lteid),
  251. },
  252. }
  253. biddingConn := MgoB.GetMgoConn()
  254. it := biddingConn.DB(config.Conf.DB.MongoB.Dbname).C(coll).Find(&q).Select(map[string]interface{}{
  255. "contenthtml": 0,
  256. }).Iter()
  257. c1, index := 0, 0
  258. var indexLock sync.Mutex
  259. for tmp := make(map[string]interface{}); it.Next(tmp); c1++ {
  260. if c1%20000 == 0 {
  261. log.Info(kword, zap.Int("current:", c1))
  262. log.Info(kword, zap.Any("current:_id =>", tmp["_id"]))
  263. }
  264. ch <- true
  265. wg.Add(1)
  266. go func(tmp map[string]interface{}) {
  267. defer func() {
  268. <-ch
  269. wg.Done()
  270. }()
  271. if sensitive := util.ObjToString(tmp["sensitive"]); sensitive == "测试" { //bidding中有敏感词,不生索引
  272. tmp = make(map[string]interface{})
  273. return
  274. }
  275. // 针对存量数据,重复数据不进索引
  276. if util.IntAll(tmp["extracttype"]) == -1 {
  277. return
  278. }
  279. //针对产权数据,暂时不入es 索引库
  280. if util.IntAll(tmp["infoformat"]) == 3 {
  281. return
  282. }
  283. indexLock.Lock()
  284. index++
  285. indexLock.Unlock()
  286. newTmp, update := GetEsField(tmp, "biddingall")
  287. //针对中国政府采购网,单独处理
  288. if util.ObjToString(tmp["site"]) == "中国政府采购网" {
  289. objectType := MatchService(tmp)
  290. if objectType != "" {
  291. newTmp["object_type"] = objectType
  292. }
  293. }
  294. newTmp["dataweight"] = 0 //索引数据新增 jy置顶字段
  295. if len(update) > 0 {
  296. updateBiddingPool <- []map[string]interface{}{{
  297. "_id": tmp["_id"],
  298. },
  299. {"$set": update},
  300. }
  301. }
  302. saveEsPool <- newTmp
  303. }(tmp)
  304. tmp = map[string]interface{}{}
  305. }
  306. wg.Wait()
  307. log.Info(fmt.Sprintf("%s over", kword), zap.Int("count", c1), zap.Int("index", index))
  308. }
  309. func biddingTaskById(mapInfo map[string]interface{}) {
  310. defer util.Catch()
  311. stype := util.ObjToString(mapInfo["stype"])
  312. infoid := util.ObjToString(mapInfo["infoid"])
  313. tmp, _ := MgoB.FindById(config.Conf.DB.MongoB.Coll, infoid, map[string]interface{}{"contenthtml": 0})
  314. if sensitive := util.ObjToString((*tmp)["sensitive"]); sensitive == "测试" { //bidding中有敏感词,不生索引
  315. return
  316. }
  317. if util.IntAll((*tmp)["extracttype"]) == 1 {
  318. newTmp, update := GetEsField(*tmp, stype)
  319. newTmp["dataweight"] = 0 //索引数据新增 jy置顶字段
  320. if len(update) > 0 {
  321. //updateBiddingPool <- []map[string]interface{}{{
  322. // "_id": mongodb.StringTOBsonId(infoid),
  323. //},
  324. // {"$set": update},
  325. //}
  326. }
  327. saveEsPool <- newTmp
  328. }
  329. }
  330. // GetEsField @Description ES字段
  331. // @Author J 2022/6/7 11:34 AM
  332. func GetEsField(tmp map[string]interface{}, stype string) (map[string]interface{}, map[string]interface{}) {
  333. newTmp := make(map[string]interface{})
  334. update := make(map[string]interface{}) // bidding 修改字段
  335. saveErr := make(map[string]interface{})
  336. for field, ftype := range config.Conf.DB.Es.FieldEs {
  337. if tmp[field] != nil { //
  338. if field == "purchasinglist" { //标的物处理
  339. purchasinglist_new := []map[string]interface{}{}
  340. if pcl, _ := tmp[field].([]interface{}); len(pcl) > 0 {
  341. for _, ls := range pcl {
  342. lsm_new := make(map[string]interface{})
  343. lsm := ls.(map[string]interface{})
  344. for pf, pftype := range config.Conf.DB.Es.FieldPurchasingList {
  345. lsmv := lsm[pf]
  346. if lsmv != nil && reflect.TypeOf(lsmv).String() == pftype {
  347. lsm_new[pf] = lsm[pf]
  348. }
  349. }
  350. if lsm_new != nil && len(lsm_new) > 0 {
  351. purchasinglist_new = append(purchasinglist_new, lsm_new)
  352. }
  353. }
  354. }
  355. if len(purchasinglist_new) > 0 {
  356. newTmp[field] = purchasinglist_new
  357. }
  358. } else if field == "procurementlist" {
  359. if tmp["procurementlist"] != nil {
  360. var arr []interface{}
  361. plist := tmp["procurementlist"].([]interface{})
  362. for _, p := range plist {
  363. p1 := p.(map[string]interface{})
  364. p2 := make(map[string]interface{})
  365. for k, v := range config.Conf.DB.Es.FieldProcurementList {
  366. if k == "projectname" && util.ObjToString(p1[k]) == "" {
  367. p2[k] = util.ObjToString(tmp["projectname"])
  368. } else if k == "buyer" && util.ObjToString(p1[k]) == "" && util.ObjToString(tmp["buyer"]) != "" {
  369. p2[k] = util.ObjToString(tmp["buyer"])
  370. } else if p1[k] != nil && reflect.TypeOf(p1[k]).String() == v {
  371. p2[k] = p1[k]
  372. }
  373. //else if k == "expurasingtime" && util.ObjToString(p1[k]) != "" {
  374. // res := getMethod(util.ObjToString(p1[k]))
  375. // if res != 0 {
  376. // p2[k] = res
  377. // }
  378. //}
  379. }
  380. arr = append(arr, p2)
  381. }
  382. if len(arr) > 0 {
  383. newTmp[field] = arr
  384. }
  385. }
  386. } else if field == "projectscope" {
  387. ps, _ := tmp["projectscope"].(string)
  388. newTmp["projectscope"] = ps
  389. //新版本已无需记录长度
  390. //if len(ps) > pscopeLength {
  391. // saveErr["projectscope"] = ps
  392. // saveErr["projectscope_length"] = len(ps)
  393. //}
  394. } else if field == "winnerorder" { //中标候选
  395. winnerorder_new := []map[string]interface{}{}
  396. if winnerorder, _ := tmp[field].([]interface{}); len(winnerorder) > 0 {
  397. for _, win := range winnerorder {
  398. winMap_new := make(map[string]interface{})
  399. winMap := win.(map[string]interface{})
  400. for wf, wftype := range config.Conf.DB.Es.FieldWinnerOrder {
  401. wfv := winMap[wf]
  402. if wfv != nil && reflect.TypeOf(wfv).String() == wftype {
  403. if wf == "sort" && util.Int64All(wfv) > 100 {
  404. continue
  405. }
  406. winMap_new[wf] = winMap[wf]
  407. }
  408. }
  409. if winMap_new != nil && len(winMap_new) > 0 {
  410. winnerorder_new = append(winnerorder_new, winMap_new)
  411. }
  412. }
  413. }
  414. if len(winnerorder_new) > 0 {
  415. newTmp[field] = winnerorder_new
  416. }
  417. } else if field == "qualifies" {
  418. //项目资质
  419. qs := []string{}
  420. if q, _ := tmp[field].([]interface{}); len(q) > 0 {
  421. for _, v := range q {
  422. v1 := v.(map[string]interface{})
  423. qs = append(qs, util.ObjToString(v1["key"]))
  424. }
  425. }
  426. if len(qs) > 0 {
  427. newTmp[field] = strings.Join(qs, ",")
  428. }
  429. } else if field == "bidopentime" {
  430. if tmp[field] != nil && tmp["bidendtime"] == nil {
  431. newTmp["bidendtime"] = tmp[field]
  432. newTmp[field] = tmp[field]
  433. } else if tmp[field] == nil && tmp["bidendtime"] != nil {
  434. newTmp["bidendtime"] = tmp[field]
  435. newTmp[field] = tmp["bidendtime"]
  436. } else {
  437. if tmp["bidopentime"] != nil {
  438. newTmp[field] = tmp["bidopentime"]
  439. }
  440. }
  441. } else if field == "detail" { //过滤
  442. detail, _ := tmp[field].(string)
  443. detail = filterSpace.ReplaceAllString(detail, "")
  444. // 不需要再保存记录长度
  445. //if len(detail) > pscopeLength {
  446. // saveErr["detail"] = detail
  447. // saveErr["detail_length"] = len(detail)
  448. //}
  449. if tmp["cleartag"] != nil {
  450. if tmp["cleartag"].(bool) {
  451. text, _ := FilterDetail(detail)
  452. newTmp[field] = util.ObjToString(tmp["title"]) + " " + text
  453. } else {
  454. newTmp[field] = util.ObjToString(tmp["title"]) + " " + detail
  455. }
  456. } else {
  457. text, b := FilterDetail(detail)
  458. newTmp[field] = util.ObjToString(tmp["title"]) + " " + text
  459. update["cleartag"] = b
  460. }
  461. } else if field == "topscopeclass" || field == "entidlist" {
  462. newTmp[field] = tmp[field]
  463. } else if field == "_id" {
  464. newTmp["_id"] = mongodb.BsonIdToSId(tmp["_id"])
  465. newTmp["id"] = mongodb.BsonIdToSId(tmp["_id"])
  466. } else if field == "publishtime" || field == "comeintime" {
  467. //字段类型不正确,特别处理
  468. if tmp[field] != nil && util.Int64All(tmp[field]) > 0 {
  469. newTmp[field] = util.Int64All(tmp[field])
  470. }
  471. } else { //其它字段判断数据类型,不正确舍弃
  472. if fieldval := tmp[field]; reflect.TypeOf(fieldval).String() != ftype {
  473. continue
  474. } else {
  475. if fieldval != "" {
  476. newTmp[field] = fieldval
  477. }
  478. }
  479. }
  480. }
  481. }
  482. filetext := getFileText(tmp)
  483. if len([]rune(filetext)) > 10 {
  484. newTmp["filetext"] = filetext
  485. // 新版不再需要记录
  486. //if len(filetext) > pscopeLength {
  487. // saveErr["filetext"] = filetext
  488. // saveErr["filetext_length"] = len(filetext)
  489. //}
  490. }
  491. YuceEndtime(newTmp) // 预测结果时间
  492. if stype == "bidding" || stype == "bidding_history" {
  493. newTmp["createtime"] = time.Now().Unix() // es库数据创建时间,只有增量数据有
  494. newTmp["pici"] = time.Now().Unix() //createtime跟pici一样,为了剑鱼功能需要,并行存在一段时间,之后可以删掉createtime
  495. update["pici"] = time.Now().Unix()
  496. }
  497. if len(saveErr) > 0 {
  498. saveErr["infoid"] = mongodb.BsonIdToSId(tmp["_id"])
  499. saveErrBidPool <- saveErr
  500. }
  501. return newTmp, update
  502. }
  503. // @Description 采购意向 预计采购时间处理
  504. // @Author J 2022/6/7 8:04 PM
  505. func getMethod(str string) int64 {
  506. if TimeV1.MatchString(str) {
  507. arr := TimeV1.FindStringSubmatch(str)
  508. st := arr[1] + "0000"
  509. parseInt, err := strconv.ParseInt(st, 10, 64)
  510. if err == nil {
  511. return parseInt
  512. }
  513. } else if TimeV2.MatchString(str) {
  514. arr := TimeV2.FindStringSubmatch(str)
  515. str1 := arr[2]
  516. if len(str1) == 1 {
  517. str1 = "0" + str1
  518. }
  519. str2 := TimeClear.ReplaceAllString(arr[1], "") + TimeClear.ReplaceAllString(str1, "") + "00"
  520. parseInt, err := strconv.ParseInt(str2, 10, 64)
  521. if err == nil {
  522. return parseInt
  523. }
  524. }
  525. return 0
  526. }
  527. func FilterDetail(text string) (string, bool) {
  528. b := false // 清理标记
  529. for _, s := range config.Conf.DB.Es.DetailFilter {
  530. reg := regexp.MustCompile(s)
  531. if reg.MatchString(text) {
  532. text = reg.ReplaceAllString(text, "")
  533. if !b {
  534. b = true
  535. }
  536. }
  537. }
  538. return text, b
  539. }
  540. // @Description 附件内容
  541. // @Author J 2022/6/7 1:54 PM
  542. func getFileText(tmp map[string]interface{}) (filetext string) {
  543. if attchMap, ok := tmp["attach_text"].(map[string]interface{}); attchMap != nil && ok {
  544. for _, tmpData1 := range attchMap {
  545. if tmpData2, ok := tmpData1.(map[string]interface{}); tmpData2 != nil && ok {
  546. for _, result := range tmpData2 {
  547. if resultMap, ok := result.(map[string]interface{}); resultMap != nil && ok {
  548. if attach_url := util.ObjToString(resultMap["attach_url"]); attach_url != "" {
  549. bs := oss.OssGetObject(attach_url, mongodb.BsonIdToSId(tmp["_id"])) //oss读数据
  550. //正式环境
  551. if utf8.RuneCountInString(filetext+bs) < fileLength {
  552. filetext += bs + "\n"
  553. } else {
  554. if utf8.RuneCountInString(bs) > fileLength {
  555. filetext = bs[0:fileLength]
  556. } else {
  557. filetext = bs
  558. }
  559. break
  560. }
  561. //测试环境
  562. //if len(filetext) > 500000 {
  563. // filetext = filetext[0:500000]
  564. // break
  565. //} else {
  566. // if len(bs) <= 500000 {
  567. // filetext += bs + "\n"
  568. // }
  569. //}
  570. }
  571. }
  572. }
  573. }
  574. }
  575. }
  576. return
  577. }
  578. // 预测结果时间
  579. func YuceEndtime(tmp map[string]interface{}) {
  580. flag := false
  581. flag2 := false
  582. scope := []string{"信息技术_运维服务", "信息技术_软件开发", "信息技术_系统集成及安全", "信息技术_其他"}
  583. titles := []string{"短信服务", "短信发送服务"}
  584. details := []string{"短信发送服务", "短信服务平台", "短信服务项目"}
  585. subscopeclass := util.ObjToString(tmp["s_subscopeclass"])
  586. //先判断满足 s_subscopeclass 条件
  587. for _, v := range scope {
  588. if strings.Contains(subscopeclass, v) {
  589. flag = true
  590. break
  591. }
  592. }
  593. //满足 s_subscopeclass ,再去判断title detail
  594. if flag {
  595. title := util.ObjToString(tmp["title"])
  596. for _, v := range titles {
  597. if strings.Contains(title, v) {
  598. flag2 = true
  599. }
  600. }
  601. if !flag2 {
  602. detail := util.ObjToString(tmp["detail"])
  603. for _, v := range details {
  604. if strings.Contains(detail, v) {
  605. flag2 = true
  606. }
  607. }
  608. }
  609. }
  610. if !flag2 {
  611. return
  612. }
  613. subtype := util.ObjToString(tmp["subtype"])
  614. if subtype == "成交" || subtype == "合同" {
  615. // yucestarttime、yuceendtime
  616. yucestarttime, yuceendtime := int64(0), int64(0)
  617. // 项目周期中
  618. if util.ObjToString(tmp["projectperiod"]) != "" {
  619. dateStr := date1.FindStringSubmatch(util.ObjToString(tmp["projectperiod"]))
  620. if len(dateStr) == 2 {
  621. sdate := FormatDateStr(dateStr[0])
  622. edate := FormatDateStr(dateStr[1])
  623. if sdate < edate && sdate != 0 && edate != 0 {
  624. yucestarttime = sdate
  625. yuceendtime = edate
  626. }
  627. }
  628. }
  629. if yucestarttime > 0 && yuceendtime > yucestarttime {
  630. tmp["yuceendtime"] = yuceendtime
  631. return
  632. }
  633. // 预测开始时间 合同签订日期
  634. if yucestarttime == 0 {
  635. if util.IntAll(tmp["signaturedate"]) <= 0 {
  636. if util.IntAll(tmp["publishtime"]) <= 0 {
  637. return
  638. } else {
  639. yucestarttime = util.Int64All(tmp["publishtime"])
  640. }
  641. } else {
  642. yucestarttime = util.Int64All(tmp["signaturedate"])
  643. }
  644. }
  645. // 预测结束时间
  646. if yucestarttime > 0 && yuceendtime == 0 {
  647. if util.IntAll(tmp["project_duration"]) > 0 && util.ObjToString(tmp["project_timeunit"]) != "" {
  648. yuceendtime = YcEndTime(yucestarttime, util.IntAll(tmp["project_duration"]), util.ObjToString(tmp["project_timeunit"]))
  649. tmp["yuceendtime"] = yuceendtime
  650. }
  651. }
  652. }
  653. }
  654. func FormatDateStr(ds string) int64 {
  655. ds = strings.Replace(ds, "年", "-", -1)
  656. ds = strings.Replace(ds, "月", "-", -1)
  657. ds = strings.Replace(ds, "日", "", -1)
  658. ds = strings.Replace(ds, "/", "-", -1)
  659. ds = strings.Replace(ds, ".", "-", -1)
  660. location, err := time.ParseInLocation(util.Date_Short_Layout, ds, time.Local)
  661. if err != nil {
  662. log.Error("FormatDateStr", zap.Error(err))
  663. return 0
  664. } else {
  665. return location.Unix()
  666. }
  667. }
  668. func YcEndTime(starttime int64, num int, unit string) int64 {
  669. yuceendtime := int64(0)
  670. if unit == "日历天" || unit == "天" || unit == "日" {
  671. yuceendtime = starttime + int64(num*86400)
  672. } else if unit == "周" {
  673. yuceendtime = time.Unix(starttime, 0).AddDate(0, 0, num*7).Unix()
  674. } else if unit == "月" {
  675. yuceendtime = time.Unix(starttime, 0).AddDate(0, num, 0).Unix()
  676. } else if unit == "年" {
  677. yuceendtime = time.Unix(starttime, 0).AddDate(num, 0, 0).Unix()
  678. } else if unit == "工作日" {
  679. n := num / 7 * 2
  680. yuceendtime = time.Unix(starttime, 0).AddDate(0, 0, num+n).Unix()
  681. }
  682. return yuceendtime
  683. }
  684. // UdpMethod @Description rpc调用信息发布程序接口
  685. // @Author J 2022/4/13 9:13 AM
  686. func UdpMethod(id string) {
  687. mapinfo := map[string]interface{}{
  688. "infoid": id,
  689. "stype": "jyfb_data_over",
  690. }
  691. datas, _ := json.Marshal(mapinfo)
  692. log.Info("UdpMethod", zap.Any("JyUdpAddr", JyUdpAddr), zap.String("mapinfo", string(datas)))
  693. _ = UdpClient.WriteUdp(datas, udp.OP_TYPE_DATA, JyUdpAddr)
  694. }
  695. //MatchService 针对中国招标网,匹配关键词打标签,object_type,货物、服务、工程,jsondata.item
  696. func MatchService(tmp map[string]interface{}) (res string) {
  697. if jsondata, ok := tmp["jsondata"]; ok {
  698. if da, ok := jsondata.(map[string]interface{}); ok {
  699. if item, ok := da["item"]; ok {
  700. services := []string{"货物", "服务", "工程"}
  701. for _, v := range services {
  702. if strings.Contains(util.ObjToString(item), v) {
  703. return v
  704. }
  705. }
  706. }
  707. }
  708. }
  709. return
  710. }