search.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  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. query_bool_should = `{"bool":{"should":[%s],"minimum_should_match": 1}}`
  155. )
  156. //GetBidSearchData 标信息搜索
  157. func GetBidSearchData(in *bxcore.SearchReq) (count int64, list []*bxcore.SearchList) {
  158. t := time.Now()
  159. var hightlightContent bool = false //是否高亮正文
  160. var selectTypeArr = strings.Split(in.SelectType, ",")
  161. for _, v := range selectTypeArr {
  162. if v == "detail" {
  163. hightlightContent = true
  164. break
  165. }
  166. }
  167. qstr := GetSearchQuery(in, GetBidSearchQuery(in))
  168. var start = int((in.PageNum - 1) * in.PageSize)
  169. //首页
  170. if qstr != "" && start == 0 {
  171. count = elastic.Count(INDEX, TYPE, qstr)
  172. }
  173. if count > 0 || start > 1 {
  174. field := bidSearch_field_1
  175. if start == 0 {
  176. field = bidSearch_field
  177. }
  178. var repl *[]map[string]interface{}
  179. if hightlightContent {
  180. repl = elastic.GetAllByNgram(INDEX, TYPE, qstr, `"detail"`, bidSearch_sort, field, start, int(in.PageSize), 115, true)
  181. } else {
  182. repl = elastic.GetAllByNgram(INDEX, TYPE, qstr, ``, bidSearch_sort, field, start, int(in.PageSize), 0, false)
  183. }
  184. if repl != nil && *repl != nil && len(*repl) > 0 {
  185. BidListConvert(in.Industry, repl)
  186. list = searchListFormart(repl, true)
  187. }
  188. logx.Info("关键词 -1- 查询耗时:", time.Since(t).Seconds())
  189. MakeCollection(in.UserId, list)
  190. }
  191. logx.Info("关键词 查询耗时:", time.Since(t).Seconds())
  192. return
  193. }
  194. func GetBidSearchQuery(in *bxcore.SearchReq) string {
  195. query := ``
  196. //省份
  197. area := in.Province
  198. if area != "" {
  199. query += `{"terms":{"area":[`
  200. for k, v := range strings.Split(area, ",") {
  201. if k > 0 {
  202. query += `,`
  203. }
  204. query += `"` + v + `"`
  205. }
  206. query += `]}}`
  207. }
  208. //
  209. city := in.City
  210. if city != "" {
  211. if len(query) > 0 {
  212. query += ","
  213. }
  214. query += `{"terms":{"city":[`
  215. for k, v := range strings.Split(city, ",") {
  216. if k > 0 {
  217. query += `,`
  218. }
  219. query += `"` + v + `"`
  220. }
  221. query += `]}}`
  222. }
  223. if query != "" {
  224. query = fmt.Sprintf(query_bool_should, query)
  225. }
  226. //发布时间
  227. publishtime := in.PublishTime
  228. if publishtime != "" && len(strings.Split(publishtime, "-")) > 1 {
  229. if len(query) > 0 {
  230. query += ","
  231. }
  232. starttime := strings.Split(publishtime, "-")[0]
  233. endtime := strings.Split(publishtime, "-")[1]
  234. query += `{"range":{"publishtime":{`
  235. if starttime != "" {
  236. query += `"gte":` + starttime
  237. }
  238. if starttime != "" && endtime != "" {
  239. query += `,`
  240. }
  241. if endtime != "" {
  242. query += `"lt":` + endtime
  243. }
  244. query += `}}}`
  245. }
  246. //信息类型
  247. subtype := in.Subtype
  248. if subtype != "" {
  249. if len(query) > 0 {
  250. query += ","
  251. }
  252. query += `{"terms":{"subtype":[`
  253. for k, v := range strings.Split(subtype, ",") {
  254. if k > 0 {
  255. query += `,`
  256. }
  257. query += `"` + v + `"`
  258. }
  259. query += `]}}`
  260. }
  261. //
  262. //if winner != "" {
  263. // if len(query) > 0 {
  264. // query += ","
  265. // }
  266. // query += `{"terms":{"s_winner":[`
  267. // for k, v := range strings.Split(winner, ",") {
  268. // if k > 0 {
  269. // query += `,`
  270. // }
  271. // query += `"` + v + `"`
  272. // }
  273. // query += `]}}`
  274. //}
  275. //采购单位类型
  276. buyerclass := in.BuyerClass
  277. if buyerclass != "" {
  278. if len(query) > 0 {
  279. query += ","
  280. }
  281. query += `{"terms":{"buyerclass":[`
  282. for k, v := range strings.Split(buyerclass, ",") {
  283. if k > 0 {
  284. query += `,`
  285. }
  286. query += `"` + v + `"`
  287. }
  288. query += `]}}`
  289. }
  290. return query
  291. }
  292. func GetSearchQuery(in *bxcore.SearchReq, mustquery string) (qstr string) {
  293. multi_match := `{"multi_match": {"query": "%s","type": "phrase", "fields": [%s]}}`
  294. query := `{"query":{"bool":{"must":[%s],"must_not":[%s]}}}`
  295. query_bool_should := `{"bool":{"should":[%s],"minimum_should_match": 1}}`
  296. query_bools_must := `{"bool":{"must":[{"range":{"bidamount":{%s}}}]}},{"bool":{"must":[{"range":{"budget":{%s}}}],"must_not":[{"range":{"bidamount":{"gte":-1}}}]}}`
  297. query_bool_must := `{"bool":{"must":[{"terms":{"s_subscopeclass":[%s]}}]}}`
  298. query_missing := `{"constant_score":{"filter":{"missing":{"field":"%s"}}}}`
  299. gte := `"gte": %s`
  300. lte := `"lte": %s`
  301. musts, must_not := []string{}, []string{}
  302. if mustquery != "" {
  303. musts = append(musts, mustquery)
  304. }
  305. selectTypeArr := strings.Split(in.SelectType, ",")
  306. var findfields string
  307. if selectTypeArr == nil || len(selectTypeArr) == 0 {
  308. findfields = `"title"`
  309. } else {
  310. findfields = fmt.Sprintf(`"%s"`, strings.Join(selectTypeArr, "\",\""))
  311. }
  312. var isFileSearch bool = false //搜索范围是否有附件选择
  313. //此时关键词中间有+进行隔离
  314. if in.KeyWords != "" {
  315. if strings.Contains(findfields, "filetext") { //搜索范围选择附件,是否有附件条件无效;
  316. isFileSearch = true
  317. }
  318. shoulds := []string{}
  319. var switchBool = strings.Contains(findfields, "detail") && strings.Contains(findfields, "title") && IC.C.SearchTypeSwitch
  320. for _, v := range strings.Split(in.KeyWords, "+") {
  321. //标题 全文搜索 搜索类型开关打开 默认搜索全文;(全文包含标题)(单字排除)
  322. if switchBool && len([]rune(elastic.ReplaceYH(v))) > 1 {
  323. if strings.Contains(findfields, `"title",`) {
  324. findfields = strings.Replace(findfields, `"title",`, ``, -1)
  325. } else if strings.Contains(findfields, `,"title"`) {
  326. findfields = strings.Replace(findfields, `,"title"`, ``, -1)
  327. }
  328. }
  329. keyword_multi_match := fmt.Sprintf(multi_match, "%s", findfields)
  330. shoulds = append(shoulds, fmt.Sprintf(keyword_multi_match, elastic.ReplaceYH(v)))
  331. }
  332. musts = append(musts, fmt.Sprintf(elastic.NgramMust, strings.Join(shoulds, ",")))
  333. }
  334. if in.Industry != "" {
  335. industrys := strings.Split(in.Industry, ",")
  336. musts = append(musts, fmt.Sprintf(query_bool_must, `"`+strings.Join(industrys, `","`)+`"`))
  337. }
  338. //价格
  339. if in.Price != "" && len(strings.Split(in.Price, "-")) > 1 {
  340. minprice, maxprice := strings.Split(in.Price, "-")[0], strings.Split(in.Price, "-")[1]
  341. if minprice != "" || maxprice != "" {
  342. sq := ``
  343. if minprice != "" {
  344. min, _ := strconv.ParseFloat(minprice, 64)
  345. minprice = fmt.Sprintf("%.0f", min*10000)
  346. if minprice == "0" {
  347. minprice = ""
  348. }
  349. }
  350. if maxprice != "" {
  351. max, _ := strconv.ParseFloat(maxprice, 64)
  352. maxprice = fmt.Sprintf("%.0f", max*10000)
  353. if maxprice == "0" {
  354. maxprice = ""
  355. }
  356. }
  357. if minprice != "" {
  358. sq += fmt.Sprintf(gte, minprice)
  359. }
  360. if minprice != "" && maxprice != "" {
  361. sq += `,`
  362. }
  363. if maxprice != "" {
  364. sq += fmt.Sprintf(lte, maxprice)
  365. }
  366. if minprice != "" || maxprice != "" {
  367. query_price := fmt.Sprintf(query_bool_should, fmt.Sprintf(query_bools_must, sq, sq))
  368. musts = append(musts, query_price)
  369. }
  370. }
  371. }
  372. hasBuyerTel := in.BuyerTel
  373. if hasBuyerTel != "" {
  374. if hasBuyerTel == "y" {
  375. must_not = append(must_not, fmt.Sprintf(query_missing, "buyertel"))
  376. } else {
  377. musts = append(musts, fmt.Sprintf(query_missing, "buyertel"))
  378. }
  379. }
  380. hasWinnerTel := in.WinnerTel
  381. if hasWinnerTel != "" {
  382. if hasWinnerTel == "y" {
  383. must_not = append(must_not, fmt.Sprintf(query_missing, "winnertel"))
  384. } else {
  385. musts = append(musts, fmt.Sprintf(query_missing, "winnertel"))
  386. }
  387. }
  388. //排除词
  389. notkey := in.ExclusionWords
  390. if notkey = strings.TrimSpace(notkey); notkey != "" {
  391. notkey_multi_match := fmt.Sprintf(multi_match, "%s", findfields)
  392. notkey_must_not := []string{}
  393. for _, v := range strings.Split(notkey, " ") {
  394. v = strings.TrimSpace(v)
  395. if v == "" {
  396. continue
  397. }
  398. notkey_must_not = append(notkey_must_not, fmt.Sprintf(notkey_multi_match, elastic.ReplaceYH(v)))
  399. }
  400. must_not = append(must_not, fmt.Sprintf(query_bool_should, strings.Join(notkey_must_not, ",")))
  401. }
  402. //
  403. fileExists := in.FileExists
  404. if !isFileSearch && fileExists != "" {
  405. if fileExists == "1" { //有附件
  406. must_not = append(must_not, fmt.Sprintf(query_missing, "filetext"))
  407. } else if fileExists == "-1" { //无附件
  408. musts = append(musts, fmt.Sprintf(query_missing, "filetext"))
  409. }
  410. }
  411. qstr = fmt.Sprintf(query, strings.Join(musts, ","), strings.Join(must_not, ","))
  412. logx.Info(qstr)
  413. return
  414. }
  415. /*
  416. * 结果列表转换,目前只换行行业字段
  417. * 所有的招标搜索都要调用此方法,列表中有展示行业的也可以用
  418. * industry 搜索条件中的行业,默认为空
  419. */
  420. func BidListConvert(industry string, res *[]map[string]interface{}) {
  421. if res == nil {
  422. return
  423. }
  424. commonSubstring := func(v string) (value string) {
  425. bcs := strings.Split(v, "_")
  426. if len(bcs) == 1 {
  427. value = bcs[0]
  428. } else if len(bcs) == 2 {
  429. value = bcs[0]
  430. if strings.TrimSpace(value) == "" {
  431. value = bcs[0]
  432. }
  433. }
  434. return
  435. }
  436. for _, v := range *res {
  437. v["id"] = v["_id"]
  438. delete(v, "_id")
  439. budget, _ := v["budget"].(float64)
  440. bidamount, _ := v["bidamount"].(float64)
  441. if budget == 0 || strings.TrimSpace(fmt.Sprint(v["budget"])) == "" {
  442. delete(v, "budget")
  443. }
  444. if bidamount == 0 || strings.TrimSpace(fmt.Sprint(v["bidamount"])) == "" {
  445. delete(v, "bidamount")
  446. }
  447. value := ""
  448. subscopeclass, _ := v["s_subscopeclass"].(string)
  449. subscopeclass = strings.Trim(subscopeclass, ",")
  450. bct := strings.Split(subscopeclass, ",")
  451. if bct == nil || len(bct) == 0 {
  452. continue
  453. }
  454. //搜索条件中没有行业的话,取查询结果中第一个行业
  455. if industry == "" {
  456. value = commonSubstring(bct[0])
  457. } else { //搜索条件中有行业的话,取行业中和搜索条件相对应的第一个
  458. industrys := strings.Split(industry, ",")
  459. L:
  460. for _, bc := range bct {
  461. for _, is := range industrys {
  462. if bc == is {
  463. value = commonSubstring(bc)
  464. break L
  465. }
  466. }
  467. }
  468. }
  469. if strings.TrimSpace(value) == "" {
  470. continue
  471. }
  472. v["industry"] = value
  473. }
  474. }
  475. //是否收藏
  476. func MakeCollection(userId string, list []*bxcore.SearchList) {
  477. if list == nil || len(list) == 0 {
  478. return
  479. }
  480. param := []interface{}{userId}
  481. wh := []string{}
  482. for _, v := range list {
  483. array := ME.DecodeArticleId2ByCheck(v.Id)
  484. if len(array) == 1 && array[0] != "" {
  485. param = append(param, array[0])
  486. wh = append(wh, "?")
  487. }
  488. }
  489. if len(wh) > 0 {
  490. result := IC.MainMysql.SelectBySql(`select bid from bdcollection where userid=? and bid in (`+strings.Join(wh, ",")+`)`, param...)
  491. bid_map := map[string]bool{}
  492. if result != nil {
  493. for _, v := range *result {
  494. bid_map[ME.EncodeArticleId2ByCheck(MC.ObjToString(v["bid"]))] = true
  495. }
  496. }
  497. for _, v := range list {
  498. if bid_map[v.Id] {
  499. v.IsCollected = true
  500. }
  501. }
  502. }
  503. }
  504. //默认查询缓存数据
  505. func SearchCahcheData(in *bxcore.SearchReq) (count int64, list []*bxcore.SearchList) {
  506. //最新招标信息
  507. findfields := `"title"`
  508. qstr := GetSearchQuery(in, GetBidSearchQuery(in))
  509. //首页
  510. if in.PageNum == 1 {
  511. count = elastic.Count(INDEX, TYPE, qstr)
  512. }
  513. if count > 0 || in.PageNum > 1 {
  514. repl := elastic.GetAllByNgram(INDEX, TYPE, qstr, findfields, bidSearch_sort, bidSearch_field, int(in.PageNum), int(in.PageSize), 0, false)
  515. if repl != nil && *repl != nil && len(*repl) > 0 {
  516. BidListConvert(in.Industry, repl)
  517. list = searchListFormart(repl, false)
  518. }
  519. }
  520. return
  521. }
  522. //格式化数据
  523. func searchListFormart(repl *[]map[string]interface{}, b bool) (list []*bxcore.SearchList) {
  524. for _, v := range *repl {
  525. var searchList = &bxcore.SearchList{}
  526. if b {
  527. //正文匹配检索关键词
  528. highlight, _ := v["highlight"].(map[string][]string)
  529. detail := ""
  530. for _, val := range highlight["detail"] {
  531. detail += ClearHtml.ReplaceAllString(val, "")
  532. }
  533. searchList.Detail = detail
  534. }
  535. searchList.Area = MC.ObjToString(v["area"])
  536. searchList.AreaUrl = IC.LabelMap[searchList.Area].Url
  537. searchList.BuyerClass = MC.ObjToString(v["buyerclass"])
  538. searchList.City = MC.ObjToString(v["city"])
  539. searchList.FileExists = v["filetext"] != nil
  540. searchList.Id = ME.EncodeArticleId2ByCheck(MC.ObjToString(v["id"]))
  541. searchList.Industry = MC.ObjToString(v["industry"])
  542. searchList.IndustryUrl = IC.LabelMap[searchList.Industry].Url
  543. searchList.PublishTime = MC.Int64All(v["publishtime"])
  544. searchList.Subtype = MC.ObjToString(v["subtype"])
  545. searchList.SubtypeUrl = IC.LabelMap[searchList.Subtype].Url
  546. searchList.Title = MC.ObjToString(v["title"])
  547. searchList.Budget = MC.Int64All(v["budget"])
  548. searchList.Bidamount = MC.Int64All(v["bidamount"])
  549. searchList.ProjectName = MC.ObjToString(v["projectname"])
  550. searchList.ProjectCode = MC.ObjToString(v["projectcode"])
  551. searchList.ProjectInfo = &bxcore.PInfo{}
  552. if v["projectinfo"] != nil {
  553. pinfo := MC.ObjToMap(v["projectinfo"])
  554. searchList.ProjectInfo.ApproveCode = MC.ObjToString((*pinfo)["approvecode"])
  555. searchList.ProjectInfo.ApproveContent = MC.ObjToString((*pinfo)["approvecontent"])
  556. searchList.ProjectInfo.ApproveDept = MC.ObjToString((*pinfo)["approvedept"])
  557. searchList.ProjectInfo.ApproveStatus = MC.ObjToString((*pinfo)["approvestatus"])
  558. searchList.ProjectInfo.ProjectType = MC.ObjToString((*pinfo)["projecttype"])
  559. searchList.ProjectInfo.ApproveNumber = MC.ObjToString((*pinfo)["approvenumber"])
  560. searchList.ProjectInfo.ApproveTime = MC.ObjToString((*pinfo)["approvetime"])
  561. }
  562. searchList.Winner = MC.ObjToString(v["winner"])
  563. searchList.Buyer = MC.ObjToString(v["buyer"])
  564. searchList.BidopenTime = MC.Int64All(v["bidopentime"])
  565. searchList.Site = MC.ObjToString(v["site"])
  566. searchList.SpiderCode = MC.ObjToString(v["spidercode"])
  567. list = append(list, searchList)
  568. }
  569. return
  570. }
  571. //合并map数据,去重,排序
  572. func DelRepeatSearchData(resOne, resTwo []*bxcore.SearchList) []*bxcore.SearchList {
  573. if len(resOne) > 0 && len(resTwo) > 0 {
  574. for _, v := range resOne {
  575. for n, m := range resTwo {
  576. if v.Id == m.Id {
  577. resTwo = append(resTwo[0:n], resTwo[n+1:]...)
  578. break
  579. }
  580. }
  581. }
  582. resOne = append(resOne, resTwo...)
  583. }
  584. sort.Slice(resOne, func(i, j int) bool {
  585. return resOne[i].PublishTime > resOne[j].PublishTime
  586. })
  587. return resOne
  588. }