search.go 19 KB

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