bidding_es.go 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823
  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. )
  21. var (
  22. TimeV1 = regexp.MustCompile("(\\d{4})[年.]?$")
  23. TimeV2 = regexp.MustCompile("(\\d{4}[年.\\-/]?)(\\d{1,2}[月.\\-/]?$)")
  24. TimeClear = regexp.MustCompile("[年|月|/|.|-]")
  25. filterSpace = regexp.MustCompile("<[^>]*?>|[\\s\u3000\u2003\u00a0]")
  26. date1 = regexp.MustCompile("20[0-2][0-9][年|\\-/.][0-9]{1,2}[月|\\-/.][0-9]{1,2}[日]?")
  27. HtmlReg = regexp.MustCompile("<[^>]+>")
  28. )
  29. func biddingTask(mapInfo map[string]interface{}) {
  30. defer util.Catch()
  31. stype := util.ObjToString(mapInfo["stype"])
  32. if stype == "bidding" {
  33. uq := bson.M{"gtid": bson.M{"$gte": util.ObjToString(mapInfo["gtid"])},
  34. "lteid": bson.M{"$lte": util.ObjToString(mapInfo["lteid"])}}
  35. MgoB.Update("bidding_processing_ids", uq, bson.M{"$set": bson.M{"dataprocess": 8, "updatetime": time.Now().Unix()}}, false, true)
  36. }
  37. q, _ := mapInfo["query"].(map[string]interface{})
  38. if q == nil {
  39. q = map[string]interface{}{
  40. "_id": map[string]interface{}{
  41. "$gt": mongodb.StringTOBsonId(mapInfo["gtid"].(string)),
  42. "$lte": mongodb.StringTOBsonId(mapInfo["lteid"].(string)),
  43. },
  44. }
  45. } else {
  46. //针对gte/lte,单独转换
  47. q = convertToMongoID(q)
  48. }
  49. ch := make(chan bool, 10)
  50. wg := &sync.WaitGroup{}
  51. //bidding库
  52. biddingConn := MgoB.GetMgoConn()
  53. count, _ := biddingConn.DB(MgoB.DbName).C(config.Conf.DB.MongoB.Coll).Find(&q).Count()
  54. log.Info("bidding表", zap.Int64("同步总数:", count))
  55. it := biddingConn.DB(config.Conf.DB.MongoB.Dbname).C(config.Conf.DB.MongoB.Coll).Find(&q).Select(map[string]interface{}{
  56. "contenthtml": 0,
  57. }).Iter()
  58. c1, index := 0, 0
  59. var indexLock sync.Mutex
  60. for tmp := make(map[string]interface{}); it.Next(tmp); c1++ {
  61. if c1%1000 == 0 {
  62. log.Info("biddingTask", zap.Int("current:", c1))
  63. log.Info("biddingTask", zap.Any("current:_id =>", tmp["_id"]))
  64. }
  65. ch <- true
  66. wg.Add(1)
  67. go func(tmp map[string]interface{}) {
  68. defer func() {
  69. <-ch
  70. wg.Done()
  71. }()
  72. if sensitive := util.ObjToString(tmp["sensitive"]); sensitive == "测试" { //bidding中有敏感词,不生索引
  73. tmp = make(map[string]interface{})
  74. return
  75. }
  76. //只针对增量数据处理;全量数据 需要用extracttype字段判断
  77. //7: 重复数据
  78. //8: 不重复
  79. if util.IntAll(tmp["dataprocess"]) != 8 {
  80. return
  81. }
  82. //// 增量数据使用上面判断;全量数据使用下面配置
  83. //-1:重复 ,1:不重复 ,0:入库 9:分类
  84. //if util.IntAll(tmp["extracttype"]) != 1 {
  85. // return
  86. //}
  87. //针对产权数据,暂时不入es 索引库
  88. if util.IntAll(tmp["infoformat"]) == 3 {
  89. return
  90. }
  91. /**
  92. 数据抽取时,有的数据的发布时间是之前的,属于增量历史数据,在判重和同步到bidding表是,会添加history_updatetime
  93. 字段,所以下面判断才会处理
  94. */
  95. if stype == "bidding_history" && tmp["history_updatetime"] == nil {
  96. return
  97. }
  98. indexLock.Lock()
  99. index++
  100. indexLock.Unlock()
  101. newTmp, update := GetEsField(tmp, stype)
  102. newTmp["dataweight"] = 0 //索引数据新增 jy置顶字段
  103. //针对中国政府采购网,单独处理
  104. if util.ObjToString(tmp["site"]) == "中国政府采购网" {
  105. objectType := MatchService(tmp)
  106. if objectType != "" {
  107. newTmp["object_type"] = objectType
  108. }
  109. }
  110. if len(update) > 0 {
  111. updateBiddingPool <- []map[string]interface{}{{
  112. "_id": tmp["_id"],
  113. },
  114. {"$set": update},
  115. }
  116. }
  117. if util.ObjToString(newTmp["spidercode"]) == "a_jyxxfbpt_gg" {
  118. // 剑鱼信息发布数据 通过udp通知信息发布程序
  119. go UdpMethod(mongodb.BsonIdToSId(newTmp["_id"]))
  120. }
  121. saveEsPool <- newTmp
  122. }(tmp)
  123. tmp = map[string]interface{}{}
  124. }
  125. wg.Wait()
  126. log.Info("biddingTask over", zap.Int("count", c1), zap.Int("index", index))
  127. // 重采平台需要
  128. //mapInfo["stype"] = ""
  129. //datas, _ := json.Marshal(mapInfo)
  130. //var next = &net.UDPAddr{
  131. // IP: net.ParseIP("127.0.0.1"),
  132. // Port: 1910,
  133. //}
  134. //log.Info("bidding index es over", zap.Any("es", next), zap.String("mapinfo", string(datas)))
  135. }
  136. //biddingAllTask 补充存量数据
  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. log.Info("biddingTaskById over", zap.Any("mapInfo", mapInfo))
  330. }
  331. // GetEsField @Description ES字段
  332. // @Author J 2022/6/7 11:34 AM
  333. func GetEsField(tmp map[string]interface{}, stype string) (map[string]interface{}, map[string]interface{}) {
  334. newTmp := make(map[string]interface{})
  335. update := make(map[string]interface{}) // bidding 修改字段
  336. saveErr := make(map[string]interface{})
  337. //for field, ftype := range config.Conf.DB.Es.FieldEs {
  338. for field, ftype := range BiddingField {
  339. if tmp[field] != nil { //
  340. if field == "purchasinglist" { //标的物处理
  341. purchasinglist_new := []map[string]interface{}{}
  342. if pcl, _ := tmp[field].([]interface{}); len(pcl) > 0 {
  343. for _, ls := range pcl {
  344. lsm_new := make(map[string]interface{})
  345. lsm := ls.(map[string]interface{})
  346. for pf, pftype := range BiddingLevelField[field] {
  347. lsmv := lsm[pf]
  348. if lsmv != nil && reflect.TypeOf(lsmv).String() == pftype {
  349. lsm_new[pf] = lsm[pf]
  350. }
  351. }
  352. if lsm_new != nil && len(lsm_new) > 0 {
  353. purchasinglist_new = append(purchasinglist_new, lsm_new)
  354. }
  355. }
  356. }
  357. if len(purchasinglist_new) > 0 {
  358. newTmp[field] = purchasinglist_new
  359. }
  360. } else if field == "procurementlist" {
  361. if tmp["procurementlist"] != nil {
  362. var arr []interface{}
  363. plist := tmp["procurementlist"].([]interface{})
  364. for _, p := range plist {
  365. p1 := p.(map[string]interface{})
  366. p2 := make(map[string]interface{})
  367. for k, v := range BiddingLevelField[field] {
  368. if k == "projectname" && util.ObjToString(p1[k]) == "" {
  369. p2[k] = util.ObjToString(tmp["projectname"])
  370. } else if k == "buyer" && util.ObjToString(p1[k]) == "" && util.ObjToString(tmp["buyer"]) != "" {
  371. p2[k] = util.ObjToString(tmp["buyer"])
  372. } else if k == "expurasingtime" && util.ObjToString(p1[k]) != "" {
  373. res := getMethod(util.ObjToString(p1[k]))
  374. if res != 0 {
  375. p2[k] = res
  376. }
  377. } else if p1[k] != nil && reflect.TypeOf(p1[k]).String() == v {
  378. p2[k] = p1[k]
  379. }
  380. }
  381. arr = append(arr, p2)
  382. }
  383. if len(arr) > 0 {
  384. newTmp[field] = arr
  385. }
  386. }
  387. } else if field == "projectscope" {
  388. ps, _ := tmp["projectscope"].(string)
  389. newTmp["projectscope"] = ps
  390. //新版本已无需记录长度
  391. //if len(ps) > pscopeLength {
  392. // saveErr["projectscope"] = ps
  393. // saveErr["projectscope_length"] = len(ps)
  394. //}
  395. } else if field == "winnerorder" { //中标候选
  396. winnerorder_new := []map[string]interface{}{}
  397. if winnerorder, _ := tmp[field].([]interface{}); len(winnerorder) > 0 {
  398. for _, win := range winnerorder {
  399. winMap_new := make(map[string]interface{})
  400. winMap := win.(map[string]interface{})
  401. for wf, wftype := range BiddingLevelField[field] {
  402. wfv := winMap[wf]
  403. if wfv != nil && reflect.TypeOf(wfv).String() == wftype {
  404. if wf == "sort" && util.Int64All(wfv) > 100 {
  405. continue
  406. }
  407. winMap_new[wf] = winMap[wf]
  408. }
  409. }
  410. if winMap_new != nil && len(winMap_new) > 0 {
  411. winnerorder_new = append(winnerorder_new, winMap_new)
  412. }
  413. }
  414. }
  415. if len(winnerorder_new) > 0 {
  416. newTmp[field] = winnerorder_new
  417. }
  418. } else if field == "qualifies" {
  419. //项目资质
  420. qs := []string{}
  421. if q, _ := tmp[field].([]interface{}); len(q) > 0 {
  422. for _, v := range q {
  423. v1 := v.(map[string]interface{})
  424. qs = append(qs, util.ObjToString(v1["key"]))
  425. }
  426. }
  427. if len(qs) > 0 {
  428. newTmp[field] = strings.Join(qs, ",")
  429. }
  430. } else if field == "bidopentime" {
  431. if tmp[field] != nil && tmp["bidendtime"] == nil {
  432. newTmp["bidendtime"] = tmp[field]
  433. newTmp[field] = tmp[field]
  434. } else if tmp[field] == nil && tmp["bidendtime"] != nil {
  435. newTmp["bidendtime"] = tmp[field]
  436. newTmp[field] = tmp["bidendtime"]
  437. } else {
  438. if tmp["bidopentime"] != nil {
  439. newTmp[field] = tmp["bidopentime"]
  440. }
  441. }
  442. } else if field == "detail" { //过滤
  443. detail, _ := tmp[field].(string)
  444. detail = filterSpace.ReplaceAllString(detail, "")
  445. // 不需要再保存记录长度
  446. //if len(detail) > pscopeLength {
  447. // saveErr["detail"] = detail
  448. // saveErr["detail_length"] = len(detail)
  449. //}
  450. if tmp["cleartag"] != nil {
  451. if tmp["cleartag"].(bool) {
  452. text, _ := FilterDetail(detail)
  453. newTmp[field] = util.ObjToString(tmp["title"]) + " " + text
  454. } else {
  455. newTmp[field] = util.ObjToString(tmp["title"]) + " " + detail
  456. }
  457. } else {
  458. text, b := FilterDetail(detail)
  459. newTmp[field] = util.ObjToString(tmp["title"]) + " " + text
  460. update["cleartag"] = b
  461. }
  462. } else if field == "topscopeclass" || field == "entidlist" {
  463. newTmp[field] = tmp[field]
  464. } else if field == "_id" {
  465. newTmp["_id"] = mongodb.BsonIdToSId(tmp["_id"])
  466. newTmp["id"] = mongodb.BsonIdToSId(tmp["_id"])
  467. } else if field == "publishtime" || field == "comeintime" {
  468. //字段类型不正确,特别处理
  469. if tmp[field] != nil && util.Int64All(tmp[field]) > 0 {
  470. newTmp[field] = util.Int64All(tmp[field])
  471. }
  472. } else if field == "package" {
  473. //分包信息处理
  474. packages := dealPackage(tmp)
  475. if len(packages) > 0 {
  476. newTmp["package"] = packages
  477. newTmp["subpackage"] = 1
  478. }
  479. } else { //其它字段判断数据类型,不正确舍弃
  480. if fieldval := tmp[field]; reflect.TypeOf(fieldval).String() != ftype {
  481. continue
  482. } else {
  483. if fieldval != "" {
  484. newTmp[field] = fieldval
  485. }
  486. }
  487. }
  488. }
  489. }
  490. // 附件内容长度不做限制,大于20万字符,只做记录
  491. filetext := getFileText(tmp)
  492. if len([]rune(filetext)) > 10 {
  493. newTmp["filetext"] = filetext
  494. if len([]rune(filetext)) > fileLength {
  495. saveErr["filetext"] = filetext
  496. saveErr["filetext_length"] = len([]rune(filetext))
  497. }
  498. }
  499. YuceEndtime(newTmp) // 预测结果时间
  500. if stype == "bidding" || stype == "bidding_history" || stype == "index-by-id" {
  501. newTmp["createtime"] = time.Now().Unix() // es库数据创建时间,只有增量数据有
  502. newTmp["pici"] = time.Now().Unix() //createtime跟pici一样,为了剑鱼功能需要,并行存在一段时间,之后可以删掉createtime
  503. update["pici"] = time.Now().Unix()
  504. }
  505. if len(saveErr) > 0 {
  506. saveErr["infoid"] = mongodb.BsonIdToSId(tmp["_id"])
  507. saveErr["time"] = time.Now().Unix()
  508. saveErrBidPool <- saveErr
  509. }
  510. return newTmp, update
  511. }
  512. // @Description 采购意向 预计采购时间处理
  513. // @Author J 2022/6/7 8:04 PM
  514. func getMethod(str string) int64 {
  515. if TimeV1.MatchString(str) {
  516. arr := TimeV1.FindStringSubmatch(str)
  517. st := arr[1] + "0000"
  518. parseInt, err := strconv.ParseInt(st, 10, 64)
  519. if err == nil {
  520. return parseInt
  521. }
  522. } else if TimeV2.MatchString(str) {
  523. arr := TimeV2.FindStringSubmatch(str)
  524. str1 := arr[2]
  525. if len(str1) == 1 {
  526. str1 = "0" + str1
  527. }
  528. str2 := TimeClear.ReplaceAllString(arr[1], "") + TimeClear.ReplaceAllString(str1, "") + "00"
  529. parseInt, err := strconv.ParseInt(str2, 10, 64)
  530. if err == nil {
  531. return parseInt
  532. }
  533. }
  534. return 0
  535. }
  536. func FilterDetail(text string) (string, bool) {
  537. b := false // 清理标记
  538. for _, s := range config.Conf.DB.Es.DetailFilter {
  539. reg := regexp.MustCompile(s)
  540. if reg.MatchString(text) {
  541. text = reg.ReplaceAllString(text, "")
  542. if !b {
  543. b = true
  544. }
  545. }
  546. }
  547. return text, b
  548. }
  549. // @Description 附件内容
  550. // @Author J 2022/6/7 1:54 PM
  551. func getFileText(tmp map[string]interface{}) (filetext string) {
  552. if attchMap, ok := tmp["attach_text"].(map[string]interface{}); attchMap != nil && ok {
  553. for _, tmpData1 := range attchMap {
  554. if tmpData2, ok := tmpData1.(map[string]interface{}); tmpData2 != nil && ok {
  555. for _, result := range tmpData2 {
  556. if resultMap, ok := result.(map[string]interface{}); resultMap != nil && ok {
  557. if attach_url := util.ObjToString(resultMap["attach_url"]); attach_url != "" {
  558. bs := oss.OssGetObject(attach_url, mongodb.BsonIdToSId(tmp["_id"])) //oss读数据
  559. if len(bs) > 0 {
  560. filetext += bs + "\n"
  561. }
  562. //正式环境
  563. //if utf8.RuneCountInString(filetext+bs) < fileLength {
  564. // filetext += bs + "\n"
  565. //} else {
  566. // if utf8.RuneCountInString(bs) > fileLength {
  567. // filetext = bs[0:fileLength]
  568. // } else {
  569. // filetext = bs
  570. // }
  571. // break
  572. //}
  573. }
  574. }
  575. }
  576. }
  577. }
  578. }
  579. return
  580. }
  581. // 预测结果时间
  582. func YuceEndtime(tmp map[string]interface{}) {
  583. flag := false
  584. flag2 := false
  585. scope := []string{"信息技术_运维服务", "信息技术_软件开发", "信息技术_系统集成及安全", "信息技术_其他"}
  586. titles := []string{"短信服务", "短信发送服务"}
  587. details := []string{"短信发送服务", "短信服务平台", "短信服务项目"}
  588. subscopeclass := util.ObjToString(tmp["s_subscopeclass"])
  589. //先判断满足 s_subscopeclass 条件
  590. for _, v := range scope {
  591. if strings.Contains(subscopeclass, v) {
  592. flag = true
  593. break
  594. }
  595. }
  596. //满足 s_subscopeclass ,再去判断title detail
  597. if flag {
  598. title := util.ObjToString(tmp["title"])
  599. for _, v := range titles {
  600. if strings.Contains(title, v) {
  601. flag2 = true
  602. }
  603. }
  604. if !flag2 {
  605. detail := util.ObjToString(tmp["detail"])
  606. for _, v := range details {
  607. if strings.Contains(detail, v) {
  608. flag2 = true
  609. }
  610. }
  611. }
  612. }
  613. if !flag2 {
  614. return
  615. }
  616. subtype := util.ObjToString(tmp["subtype"])
  617. if subtype == "成交" || subtype == "合同" {
  618. // yucestarttime、yuceendtime
  619. yucestarttime, yuceendtime := int64(0), int64(0)
  620. // 项目周期中
  621. if util.ObjToString(tmp["projectperiod"]) != "" {
  622. dateStr := date1.FindStringSubmatch(util.ObjToString(tmp["projectperiod"]))
  623. if len(dateStr) == 2 {
  624. sdate := FormatDateStr(dateStr[0])
  625. edate := FormatDateStr(dateStr[1])
  626. if sdate < edate && sdate != 0 && edate != 0 {
  627. yucestarttime = sdate
  628. yuceendtime = edate
  629. }
  630. }
  631. }
  632. if yucestarttime > 0 && yuceendtime > yucestarttime {
  633. tmp["yuceendtime"] = yuceendtime
  634. return
  635. }
  636. // 预测开始时间 合同签订日期
  637. if yucestarttime == 0 {
  638. if util.IntAll(tmp["signaturedate"]) <= 0 {
  639. if util.IntAll(tmp["publishtime"]) <= 0 {
  640. return
  641. } else {
  642. yucestarttime = util.Int64All(tmp["publishtime"])
  643. }
  644. } else {
  645. yucestarttime = util.Int64All(tmp["signaturedate"])
  646. }
  647. }
  648. // 预测结束时间
  649. if yucestarttime > 0 && yuceendtime == 0 {
  650. if util.IntAll(tmp["project_duration"]) > 0 && util.ObjToString(tmp["project_timeunit"]) != "" {
  651. yuceendtime = YcEndTime(yucestarttime, util.IntAll(tmp["project_duration"]), util.ObjToString(tmp["project_timeunit"]))
  652. tmp["yuceendtime"] = yuceendtime
  653. }
  654. }
  655. }
  656. }
  657. func FormatDateStr(ds string) int64 {
  658. ds = strings.Replace(ds, "年", "-", -1)
  659. ds = strings.Replace(ds, "月", "-", -1)
  660. ds = strings.Replace(ds, "日", "", -1)
  661. ds = strings.Replace(ds, "/", "-", -1)
  662. ds = strings.Replace(ds, ".", "-", -1)
  663. location, err := time.ParseInLocation(util.Date_Short_Layout, ds, time.Local)
  664. if err != nil {
  665. log.Error("FormatDateStr", zap.Error(err))
  666. return 0
  667. } else {
  668. return location.Unix()
  669. }
  670. }
  671. func YcEndTime(starttime int64, num int, unit string) int64 {
  672. yuceendtime := int64(0)
  673. if unit == "日历天" || unit == "天" || unit == "日" {
  674. yuceendtime = starttime + int64(num*86400)
  675. } else if unit == "周" {
  676. yuceendtime = time.Unix(starttime, 0).AddDate(0, 0, num*7).Unix()
  677. } else if unit == "月" {
  678. yuceendtime = time.Unix(starttime, 0).AddDate(0, num, 0).Unix()
  679. } else if unit == "年" {
  680. yuceendtime = time.Unix(starttime, 0).AddDate(num, 0, 0).Unix()
  681. } else if unit == "工作日" {
  682. n := num / 7 * 2
  683. yuceendtime = time.Unix(starttime, 0).AddDate(0, 0, num+n).Unix()
  684. }
  685. return yuceendtime
  686. }
  687. // UdpMethod @Description rpc调用信息发布程序接口
  688. // @Author J 2022/4/13 9:13 AM
  689. func UdpMethod(id string) {
  690. mapinfo := map[string]interface{}{
  691. "infoid": id,
  692. "stype": "jyfb_data_over",
  693. }
  694. datas, _ := json.Marshal(mapinfo)
  695. log.Info("UdpMethod", zap.Any("JyUdpAddr", JyUdpAddr), zap.String("mapinfo", string(datas)))
  696. _ = UdpClient.WriteUdp(datas, udp.OP_TYPE_DATA, JyUdpAddr)
  697. }
  698. //MatchService 针对中国招标网,匹配关键词打标签,object_type,货物、服务、工程,jsondata.item
  699. func MatchService(tmp map[string]interface{}) (res string) {
  700. if jsondata, ok := tmp["jsondata"]; ok {
  701. if da, ok := jsondata.(map[string]interface{}); ok {
  702. if item, ok := da["item"]; ok {
  703. services := []string{"货物", "服务", "工程"}
  704. for _, v := range services {
  705. if strings.Contains(util.ObjToString(item), v) {
  706. return v
  707. }
  708. }
  709. }
  710. }
  711. }
  712. return
  713. }
  714. //dealPackage 处理package 字段
  715. func dealPackage(tmp map[string]interface{}) (newpackages []map[string]interface{}) {
  716. package1, ok1 := tmp["package"]
  717. s_winner, ok2 := tmp["s_winner"]
  718. bidamount, ok3 := tmp["bidamount"]
  719. var innerWinners = make([]string, 0)
  720. var biaoAmounts = make([]float64, 0)
  721. // 三个字段都存在
  722. if ok3 && ok2 && ok1 {
  723. packageMap, ok := package1.(map[string]interface{})
  724. if ok {
  725. if len(packageMap) >= 2 {
  726. var packages = make([]map[string]interface{}, 0)
  727. //var newTmp = make(map[string]interface{})
  728. winner_amount_count := 0
  729. for _, pack := range packageMap {
  730. var newPackage = make(map[string]interface{})
  731. pac, okk := pack.(map[string]interface{})
  732. if okk {
  733. _, okk1 := pac["winner"]
  734. _, okk2 := pac["bidamount"]
  735. _, okk3 := pac["name"]
  736. if okk1 {
  737. innerWinners = append(innerWinners, util.ObjToString(pac["winner"]))
  738. }
  739. if okk2 {
  740. biaoAmounts = append(biaoAmounts, util.Float64All(pac["bidamount"]))
  741. }
  742. //winner bidamount 二个字段都存在
  743. if okk1 && okk2 {
  744. winner_amount_count++
  745. newPackage["winner"] = pac["winner"]
  746. newPackage["bidamount"] = pac["bidamount"]
  747. if okk3 {
  748. newPackage["name"] = pac["name"]
  749. }
  750. packages = append(packages, newPackage)
  751. }
  752. }
  753. }
  754. //出现次数大于1
  755. if winner_amount_count > 1 {
  756. swinner := util.ObjToString(s_winner)
  757. swinners := strings.Split(swinner, ",")
  758. //判断里外 winner 是否相等
  759. eq := StringSliceValuesEqual(swinners, innerWinners)
  760. if eq {
  761. //判断金额相等
  762. if Float64Equal1Precision(Float64SliceSum(biaoAmounts), util.Float64All(bidamount)) {
  763. newpackages = packages
  764. }
  765. }
  766. }
  767. }
  768. }
  769. }
  770. return
  771. }