bidding_es.go 19 KB

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