search.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  1. package util
  2. import (
  3. MC "app.yhyue.com/moapp/jybase/common"
  4. ME "app.yhyue.com/moapp/jybase/encrypt"
  5. elastic "app.yhyue.com/moapp/jybase/esv1"
  6. "crypto/rand"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/zeromicro/go-zero/core/logx"
  10. "io/ioutil"
  11. IC "jyBXCore/rpc/init"
  12. "jyBXCore/rpc/type/bxcore"
  13. "log"
  14. "math/big"
  15. "net/http"
  16. "net/url"
  17. "regexp"
  18. "sort"
  19. "strconv"
  20. "strings"
  21. "time"
  22. "unicode"
  23. )
  24. var ClearHtml = regexp.MustCompile("<[^>]*>")
  25. var MatchSpace = regexp.MustCompile("\\s+")
  26. var filterReg_3 = regexp.MustCompile("(项目|公告|公示)$")
  27. var filterReg_2 = regexp.MustCompile("^[)\\)>》】\\]}}〕,,;;::'\"“”。.\\??、/+=\\_—*&……\\^%$¥@!!`~·(\\(<《【\\[{{〔]+$")
  28. var filterReg_1 = regexp.MustCompile("^([0-9]{1,3}|[零一二三四五六七八九十]{1,2}|联系人?|电话|地址|编号|采购|政府采购|成交|更正|招标|中标|变更|结果)$")
  29. var filterReg = regexp.MustCompile("^[的人号时元万公告项目地址电话邮编日期联系招标中结果成交项目项目采购采购项目政府采购公告更正公告]+$")
  30. var PhoneReg = regexp.MustCompile("^[1][3-9][0-9]{9}$")
  31. var EmailPattern = regexp.MustCompile("^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$")
  32. func SearchHistory(history, searchvalue string) (arrs []string) {
  33. if searchvalue != "" {
  34. arrs = strings.Split(history, ",")
  35. //新增历史记录
  36. if history == "" {
  37. arrs = make([]string, 0)
  38. }
  39. for k, v := range arrs {
  40. if v == strings.TrimSpace(searchvalue) {
  41. arrs = append(arrs[:k], arrs[k+1:]...)
  42. break
  43. }
  44. }
  45. arrs = append(arrs, searchvalue)
  46. if len(arrs) > 10 {
  47. arrs = arrs[1:11]
  48. }
  49. }
  50. return arrs
  51. }
  52. func FilteKey(k string) string {
  53. k = strings.TrimSpace(k)
  54. k = filterReg_3.ReplaceAllString(k, "")
  55. k = filterReg_2.ReplaceAllString(k, "")
  56. k = filterReg_1.ReplaceAllString(k, "")
  57. k = filterReg.ReplaceAllString(k, "")
  58. return k
  59. }
  60. //超过20个字,截断
  61. //返回截取后的字符串和截取掉中的前3个字
  62. func InterceptSearchKW(word string, isIntercept, isFilter bool) (b_word, a_word, s_word string) {
  63. if isFilter {
  64. word = FilteKey(word)
  65. }
  66. word = MatchSpace.ReplaceAllString(strings.TrimSpace(word), " ")
  67. words := []rune(word)
  68. if len(words) > 20 && isIntercept {
  69. b_word = string(words[:20])
  70. b_word = strings.TrimSpace(b_word)
  71. if len(words) > 23 {
  72. a_word = string(words[20:23])
  73. } else {
  74. a_word = string(words[20:])
  75. }
  76. } else {
  77. b_word = word
  78. }
  79. a_word = strings.TrimSpace(a_word)
  80. s_word = MatchSpace.ReplaceAllString(b_word, "+")
  81. return
  82. }
  83. func HttpEs(ques, analyzer, esAddress string) (res string) {
  84. var addrs []string
  85. surl := ""
  86. for _, s := range strings.Split(esAddress, ",") {
  87. addrs = append(addrs, s)
  88. }
  89. i, _ := rand.Int(rand.Reader, big.NewInt(int64(len(addrs)))) //随机
  90. surl = addrs[int(i.Int64())] + "/bidding/_analyze"
  91. URL, _ := url.Parse(surl)
  92. Q := URL.Query()
  93. Q.Add("text", ques)
  94. Q.Add("analyzer", analyzer)
  95. URL.RawQuery = Q.Encode()
  96. resp, err := http.Get(URL.String())
  97. if err != nil {
  98. log.Println("es连接失败 err1:", err)
  99. resp, err = getesResp(ques, analyzer, addrs)
  100. if err != nil {
  101. return
  102. }
  103. }
  104. result, err := ioutil.ReadAll(resp.Body)
  105. if err == nil {
  106. defer resp.Body.Close()
  107. var resmap map[string]interface{}
  108. json.Unmarshal(result, &resmap)
  109. if resmap != nil && resmap["tokens"] != nil {
  110. tokens := MC.ObjArrToMapArr(resmap["tokens"].([]interface{}))
  111. for _, v := range tokens {
  112. token := MC.ObjToString(v["token"])
  113. if len([]rune(token)) == 1 && unicode.IsLetter([]rune(token)[0]) {
  114. continue
  115. }
  116. if res != "" {
  117. res += "+"
  118. }
  119. res += token
  120. }
  121. }
  122. }
  123. return
  124. }
  125. //
  126. func getesResp(ques, analyzer string, addrs []string) (resp *http.Response, err error) {
  127. for _, v := range addrs {
  128. surl := v + "/bidding/_analyze"
  129. URL, _ := url.Parse(surl)
  130. Q := URL.Query()
  131. Q.Add("text", ques)
  132. Q.Add("analyzer", analyzer)
  133. URL.RawQuery = Q.Encode()
  134. resp, err = http.Get(URL.String())
  135. if err == nil {
  136. break
  137. }
  138. }
  139. return resp, err
  140. }
  141. //pc、微信、app 招标信息搜索
  142. const (
  143. INDEX = "bidding"
  144. TYPE = "bidding"
  145. bidSearch_sort = `{"publishtime":-1}`
  146. RedisName = "other"
  147. //招标搜索分页--每页显示数量
  148. SearchPageSize = 50
  149. //招标搜索分页--最大页数
  150. SearchMaxPageNum = 10 //免费用户500条记录
  151. SearchMaxPageNum_PAYED = 100 //付费用户5000条记录
  152. bidSearch_field_1 = `"_id","title","publishtime","toptype","subtype","type","area","city","s_subscopeclass","bidamount","budget","buyerclass","filetext","spidercode","site"`
  153. bidSearch_field = bidSearch_field_1 + `,"bidopentime","winner","buyer","projectname","projectcode","projectinfo"`
  154. )
  155. //GetBidSearchData 标信息搜索
  156. func GetBidSearchData(in *bxcore.SearchReq) (count int64, list []*bxcore.SearchList) {
  157. t := time.Now()
  158. var hightlightContent bool = false //是否高亮正文
  159. var selectTypeArr = strings.Split(in.SelectType, ",")
  160. for _, v := range selectTypeArr {
  161. if v == "detail" {
  162. hightlightContent = true
  163. break
  164. }
  165. }
  166. qstr := GetSearchQuery(in, GetBidSearchQuery(in))
  167. var start = int((in.PageNum - 1) * in.PageSize)
  168. //首页
  169. if qstr != "" && start == 0 {
  170. count = elastic.Count(INDEX, TYPE, qstr)
  171. }
  172. if count > 0 || start > 1 {
  173. field := bidSearch_field_1
  174. if start == 0 {
  175. field = bidSearch_field
  176. }
  177. var repl *[]map[string]interface{}
  178. if hightlightContent {
  179. repl = elastic.GetAllByNgram(INDEX, TYPE, qstr, `"detail"`, bidSearch_sort, field, start, int(in.PageSize), 115, true)
  180. } else {
  181. repl = elastic.GetAllByNgram(INDEX, TYPE, qstr, ``, bidSearch_sort, field, start, int(in.PageSize), 0, false)
  182. }
  183. if repl != nil && *repl != nil && len(*repl) > 0 {
  184. BidListConvert(in.Industry, repl)
  185. list = searchListFormart(repl, true)
  186. }
  187. logx.Info("关键词 -1- 查询耗时:", time.Since(t).Seconds())
  188. MakeCollection(in.UserId, list)
  189. }
  190. logx.Info("关键词 查询耗时:", time.Since(t).Seconds())
  191. return
  192. }
  193. func GetBidSearchQuery(in *bxcore.SearchReq) string {
  194. query := ``
  195. //省份
  196. area := in.Province
  197. if area != "" {
  198. query += `{"terms":{"area":[`
  199. for k, v := range strings.Split(area, ",") {
  200. if k > 0 {
  201. query += `,`
  202. }
  203. query += `"` + v + `"`
  204. }
  205. query += `]}}`
  206. }
  207. //
  208. city := in.City
  209. if city != "" {
  210. if len(query) > 0 {
  211. query += ","
  212. }
  213. query += `{"terms":{"city":[`
  214. for k, v := range strings.Split(city, ",") {
  215. if k > 0 {
  216. query += `,`
  217. }
  218. query += `"` + v + `"`
  219. }
  220. query += `]}}`
  221. }
  222. //发布时间
  223. publishtime := in.PublishTime
  224. if publishtime != "" && len(strings.Split(publishtime, "-")) > 1 {
  225. if len(query) > 0 {
  226. query += ","
  227. }
  228. starttime := strings.Split(publishtime, "-")[0]
  229. endtime := strings.Split(publishtime, "-")[1]
  230. query += `{"range":{"publishtime":{`
  231. if starttime != "" {
  232. query += `"gte":` + starttime
  233. }
  234. if starttime != "" && endtime != "" {
  235. query += `,`
  236. }
  237. if endtime != "" {
  238. query += `"lt":` + endtime
  239. }
  240. query += `}}}`
  241. }
  242. //信息类型
  243. subtype := in.Subtype
  244. if subtype != "" {
  245. if len(query) > 0 {
  246. query += ","
  247. }
  248. query += `{"terms":{"subtype":[`
  249. for k, v := range strings.Split(subtype, ",") {
  250. if k > 0 {
  251. query += `,`
  252. }
  253. query += `"` + v + `"`
  254. }
  255. query += `]}}`
  256. }
  257. //
  258. //if winner != "" {
  259. // if len(query) > 0 {
  260. // query += ","
  261. // }
  262. // query += `{"terms":{"s_winner":[`
  263. // for k, v := range strings.Split(winner, ",") {
  264. // if k > 0 {
  265. // query += `,`
  266. // }
  267. // query += `"` + v + `"`
  268. // }
  269. // query += `]}}`
  270. //}
  271. //采购单位类型
  272. buyerclass := in.BuyerClass
  273. if buyerclass != "" {
  274. if len(query) > 0 {
  275. query += ","
  276. }
  277. query += `{"terms":{"buyerclass":[`
  278. for k, v := range strings.Split(buyerclass, ",") {
  279. if k > 0 {
  280. query += `,`
  281. }
  282. query += `"` + v + `"`
  283. }
  284. query += `]}}`
  285. }
  286. return query
  287. }
  288. func GetSearchQuery(in *bxcore.SearchReq, mustquery string) (qstr string) {
  289. multi_match := `{"multi_match": {"query": "%s","type": "phrase", "fields": [%s]}}`
  290. query := `{"query":{"bool":{"must":[%s],"must_not":[%s]}}}`
  291. query_bool_should := `{"bool":{"should":[%s],"minimum_should_match": 1}}`
  292. query_bools_must := `{"bool":{"must":[{"range":{"bidamount":{%s}}}]}},{"bool":{"must":[{"range":{"budget":{%s}}}],"must_not":[{"range":{"bidamount":{"gte":-1}}}]}}`
  293. query_bool_must := `{"bool":{"must":[{"terms":{"s_subscopeclass":[%s]}}]}}`
  294. query_missing := `{"constant_score":{"filter":{"missing":{"field":"%s"}}}}`
  295. gte := `"gte": %s`
  296. lte := `"lte": %s`
  297. musts, must_not := []string{}, []string{}
  298. if mustquery != "" {
  299. musts = append(musts, mustquery)
  300. }
  301. selectTypeArr := strings.Split(in.SelectType, ",")
  302. var findfields string
  303. if selectTypeArr == nil || len(selectTypeArr) == 0 {
  304. findfields = `"title"`
  305. } else {
  306. findfields = fmt.Sprintf(`"%s"`, strings.Join(selectTypeArr, "\",\""))
  307. }
  308. var isFileSearch bool = false //搜索范围是否有附件选择
  309. //此时关键词中间有+进行隔离
  310. if in.KeyWords != "" {
  311. if strings.Contains(findfields, "filetext") { //搜索范围选择附件,是否有附件条件无效;
  312. isFileSearch = true
  313. }
  314. shoulds := []string{}
  315. var switchBool = strings.Contains(findfields, "detail") && strings.Contains(findfields, "title") && IC.C.SearchTypeSwitch
  316. for _, v := range strings.Split(in.KeyWords, "+") {
  317. //标题 全文搜索 搜索类型开关打开 默认搜索全文;(全文包含标题)(单字排除)
  318. if switchBool && len([]rune(elastic.ReplaceYH(v))) > 1 {
  319. if strings.Contains(findfields, `"title",`) {
  320. findfields = strings.Replace(findfields, `"title",`, ``, -1)
  321. } else if strings.Contains(findfields, `,"title"`) {
  322. findfields = strings.Replace(findfields, `,"title"`, ``, -1)
  323. }
  324. }
  325. keyword_multi_match := fmt.Sprintf(multi_match, "%s", findfields)
  326. shoulds = append(shoulds, fmt.Sprintf(keyword_multi_match, elastic.ReplaceYH(v)))
  327. }
  328. musts = append(musts, fmt.Sprintf(elastic.NgramMust, strings.Join(shoulds, ",")))
  329. }
  330. if in.Industry != "" {
  331. industrys := strings.Split(in.Industry, ",")
  332. musts = append(musts, fmt.Sprintf(query_bool_must, `"`+strings.Join(industrys, `","`)+`"`))
  333. }
  334. //价格
  335. if in.Price != "" && len(strings.Split(in.Price, "-")) > 1 {
  336. minprice, maxprice := strings.Split(in.Price, "-")[0], strings.Split(in.Price, "-")[1]
  337. if minprice != "" || maxprice != "" {
  338. sq := ``
  339. if minprice != "" {
  340. min, _ := strconv.ParseFloat(minprice, 64)
  341. minprice = fmt.Sprintf("%.0f", min*10000)
  342. if minprice == "0" {
  343. minprice = ""
  344. }
  345. }
  346. if maxprice != "" {
  347. max, _ := strconv.ParseFloat(maxprice, 64)
  348. maxprice = fmt.Sprintf("%.0f", max*10000)
  349. if maxprice == "0" {
  350. maxprice = ""
  351. }
  352. }
  353. if minprice != "" {
  354. sq += fmt.Sprintf(gte, minprice)
  355. }
  356. if minprice != "" && maxprice != "" {
  357. sq += `,`
  358. }
  359. if maxprice != "" {
  360. sq += fmt.Sprintf(lte, maxprice)
  361. }
  362. if minprice != "" || maxprice != "" {
  363. query_price := fmt.Sprintf(query_bool_should, fmt.Sprintf(query_bools_must, sq, sq))
  364. musts = append(musts, query_price)
  365. }
  366. }
  367. }
  368. hasBuyerTel := in.BuyerTel
  369. if hasBuyerTel != "" {
  370. if hasBuyerTel == "y" {
  371. must_not = append(must_not, fmt.Sprintf(query_missing, "buyertel"))
  372. } else {
  373. musts = append(musts, fmt.Sprintf(query_missing, "buyertel"))
  374. }
  375. }
  376. hasWinnerTel := in.WinnerTel
  377. if hasWinnerTel != "" {
  378. if hasWinnerTel == "y" {
  379. must_not = append(must_not, fmt.Sprintf(query_missing, "winnertel"))
  380. } else {
  381. musts = append(musts, fmt.Sprintf(query_missing, "winnertel"))
  382. }
  383. }
  384. //排除词
  385. notkey := in.ExclusionWords
  386. if notkey = strings.TrimSpace(notkey); notkey != "" {
  387. notkey_multi_match := fmt.Sprintf(multi_match, "%s", findfields)
  388. notkey_must_not := []string{}
  389. for _, v := range strings.Split(notkey, " ") {
  390. v = strings.TrimSpace(v)
  391. if v == "" {
  392. continue
  393. }
  394. notkey_must_not = append(notkey_must_not, fmt.Sprintf(notkey_multi_match, elastic.ReplaceYH(v)))
  395. }
  396. must_not = append(must_not, fmt.Sprintf(query_bool_should, strings.Join(notkey_must_not, ",")))
  397. }
  398. //
  399. fileExists := in.FileExists
  400. if !isFileSearch && fileExists != "" {
  401. if fileExists == "1" { //有附件
  402. must_not = append(must_not, fmt.Sprintf(query_missing, "filetext"))
  403. } else if fileExists == "-1" { //无附件
  404. musts = append(musts, fmt.Sprintf(query_missing, "filetext"))
  405. }
  406. }
  407. qstr = fmt.Sprintf(query, strings.Join(musts, ","), strings.Join(must_not, ","))
  408. logx.Info(qstr)
  409. return
  410. }
  411. /*
  412. * 结果列表转换,目前只换行行业字段
  413. * 所有的招标搜索都要调用此方法,列表中有展示行业的也可以用
  414. * industry 搜索条件中的行业,默认为空
  415. */
  416. func BidListConvert(industry string, res *[]map[string]interface{}) {
  417. if res == nil {
  418. return
  419. }
  420. commonSubstring := func(v string) (value string) {
  421. bcs := strings.Split(v, "_")
  422. if len(bcs) == 1 {
  423. value = bcs[0]
  424. } else if len(bcs) == 2 {
  425. value = bcs[0]
  426. if strings.TrimSpace(value) == "" {
  427. value = bcs[0]
  428. }
  429. }
  430. return
  431. }
  432. for _, v := range *res {
  433. v["id"] = v["_id"]
  434. delete(v, "_id")
  435. budget, _ := v["budget"].(float64)
  436. bidamount, _ := v["bidamount"].(float64)
  437. if budget == 0 || strings.TrimSpace(fmt.Sprint(v["budget"])) == "" {
  438. delete(v, "budget")
  439. }
  440. if bidamount == 0 || strings.TrimSpace(fmt.Sprint(v["bidamount"])) == "" {
  441. delete(v, "bidamount")
  442. }
  443. value := ""
  444. subscopeclass, _ := v["s_subscopeclass"].(string)
  445. subscopeclass = strings.Trim(subscopeclass, ",")
  446. bct := strings.Split(subscopeclass, ",")
  447. if bct == nil || len(bct) == 0 {
  448. continue
  449. }
  450. //搜索条件中没有行业的话,取查询结果中第一个行业
  451. if industry == "" {
  452. value = commonSubstring(bct[0])
  453. } else { //搜索条件中有行业的话,取行业中和搜索条件相对应的第一个
  454. industrys := strings.Split(industry, ",")
  455. L:
  456. for _, bc := range bct {
  457. for _, is := range industrys {
  458. if bc == is {
  459. value = commonSubstring(bc)
  460. break L
  461. }
  462. }
  463. }
  464. }
  465. if strings.TrimSpace(value) == "" {
  466. continue
  467. }
  468. v["industry"] = value
  469. }
  470. }
  471. //是否收藏
  472. func MakeCollection(userId string, list []*bxcore.SearchList) {
  473. if list == nil || len(list) == 0 {
  474. return
  475. }
  476. param := []interface{}{userId}
  477. wh := []string{}
  478. for _, v := range list {
  479. array := ME.DecodeArticleId2ByCheck(v.Id)
  480. if len(array) == 1 && array[0] != "" {
  481. param = append(param, array[0])
  482. wh = append(wh, "?")
  483. }
  484. }
  485. if len(wh) > 0 {
  486. result := IC.MainMysql.SelectBySql(`select bid from bdcollection where userid=? and bid in (`+strings.Join(wh, ",")+`)`, param...)
  487. bid_map := map[string]bool{}
  488. if result != nil {
  489. for _, v := range *result {
  490. bid_map[ME.EncodeArticleId2ByCheck(MC.ObjToString(v["bid"]))] = true
  491. }
  492. }
  493. for _, v := range list {
  494. if bid_map[v.Id] {
  495. v.IsCollected = true
  496. }
  497. }
  498. }
  499. }
  500. //默认查询缓存数据
  501. func SearchCahcheData(in *bxcore.SearchReq) (count int64, list []*bxcore.SearchList) {
  502. //最新招标信息
  503. findfields := `"title"`
  504. qstr := GetSearchQuery(in, GetBidSearchQuery(in))
  505. //首页
  506. if in.PageNum == 1 {
  507. count = elastic.Count(INDEX, TYPE, qstr)
  508. }
  509. if count > 0 || in.PageNum > 1 {
  510. repl := elastic.GetAllByNgram(INDEX, TYPE, qstr, findfields, bidSearch_sort, bidSearch_field, int(in.PageNum), int(in.PageSize), 0, false)
  511. if repl != nil && *repl != nil && len(*repl) > 0 {
  512. BidListConvert(in.Industry, repl)
  513. list = searchListFormart(repl, false)
  514. }
  515. }
  516. return
  517. }
  518. //格式化数据
  519. func searchListFormart(repl *[]map[string]interface{}, b bool) (list []*bxcore.SearchList) {
  520. for _, v := range *repl {
  521. var searchList = &bxcore.SearchList{}
  522. if b {
  523. //正文匹配检索关键词
  524. highlight, _ := v["highlight"].(map[string][]string)
  525. detail := ""
  526. for _, val := range highlight["detail"] {
  527. detail += ClearHtml.ReplaceAllString(val, "")
  528. }
  529. searchList.Detail = detail
  530. }
  531. searchList.Area = MC.ObjToString(v["area"])
  532. searchList.AreaUrl = IC.LabelMap[searchList.Area].Url
  533. searchList.BuyerClass = MC.ObjToString(v["buyerclass"])
  534. searchList.City = MC.ObjToString(v["city"])
  535. searchList.FileExists = v["filetext"] != nil
  536. searchList.Id = ME.EncodeArticleId2ByCheck(MC.ObjToString(v["id"]))
  537. searchList.Industry = MC.ObjToString(v["industry"])
  538. searchList.IndustryUrl = IC.LabelMap[searchList.Industry].Url
  539. searchList.PublishTime = MC.Int64All(v["publishtime"])
  540. searchList.Subtype = MC.ObjToString(v["subtype"])
  541. searchList.SubtypeUrl = IC.LabelMap[searchList.Subtype].Url
  542. searchList.Title = MC.ObjToString(v["title"])
  543. searchList.Budget = MC.Int64All(v["budget"])
  544. searchList.Bidamount = MC.Int64All(v["bidamount"])
  545. searchList.ProjectName = MC.ObjToString(v["projectname"])
  546. searchList.ProjectCode = MC.ObjToString(v["projectcode"])
  547. searchList.ProjectInfo = &bxcore.PInfo{}
  548. if v["projectinfo"] != nil {
  549. pinfo := MC.ObjToMap(v["projectinfo"])
  550. searchList.ProjectInfo.ApproveCode = MC.ObjToString((*pinfo)["approvecode"])
  551. searchList.ProjectInfo.ApproveContent = MC.ObjToString((*pinfo)["approvecontent"])
  552. searchList.ProjectInfo.ApproveDept = MC.ObjToString((*pinfo)["approvedept"])
  553. searchList.ProjectInfo.ApproveStatus = MC.ObjToString((*pinfo)["approvestatus"])
  554. searchList.ProjectInfo.ProjectType = MC.ObjToString((*pinfo)["projecttype"])
  555. searchList.ProjectInfo.ApproveNumber = MC.ObjToString((*pinfo)["approvenumber"])
  556. searchList.ProjectInfo.ApproveTime = MC.ObjToString((*pinfo)["approvetime"])
  557. }
  558. searchList.Winner = MC.ObjToString(v["winner"])
  559. searchList.Buyer = MC.ObjToString(v["buyer"])
  560. searchList.BidopenTime = MC.Int64All(v["bidopentime"])
  561. searchList.Site = MC.ObjToString(v["site"])
  562. searchList.SpiderCode = MC.ObjToString(v["spidercode"])
  563. list = append(list, searchList)
  564. }
  565. return
  566. }
  567. //合并map数据,去重,排序
  568. func DelRepeatSearchData(resOne, resTwo []*bxcore.SearchList) []*bxcore.SearchList {
  569. if len(resOne) > 0 && len(resTwo) > 0 {
  570. for _, v := range resOne {
  571. for n, m := range resTwo {
  572. if v.Id == m.Id {
  573. resTwo = append(resTwo[0:n], resTwo[n+1:]...)
  574. break
  575. }
  576. }
  577. }
  578. resOne = append(resOne, resTwo...)
  579. }
  580. sort.Slice(resOne, func(i, j int) bool {
  581. return resOne[i].PublishTime > resOne[j].PublishTime
  582. })
  583. return resOne
  584. }