search.go 18 KB

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