searchListLogic.go 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. package logic
  2. import (
  3. "context"
  4. "github.com/zeromicro/go-zero/core/logx"
  5. IC "jyBXCore/api/init"
  6. "jyBXCore/api/internal/svc"
  7. "jyBXCore/api/internal/types"
  8. "jyBXCore/api/internal/util"
  9. "jyBXCore/rpc/type/bxcore"
  10. "log"
  11. "net/http"
  12. "strings"
  13. "time"
  14. "app.yhyue.com/moapp/jybase/common"
  15. )
  16. type SearchListLogic struct {
  17. logx.Logger
  18. ctx context.Context
  19. svcCtx *svc.ServiceContext
  20. r *http.Request
  21. w http.ResponseWriter
  22. }
  23. func NewSearchListLogic(ctx context.Context, svcCtx *svc.ServiceContext, r *http.Request, w http.ResponseWriter) *SearchListLogic {
  24. return &SearchListLogic{
  25. Logger: logx.WithContext(ctx),
  26. ctx: ctx,
  27. svcCtx: svcCtx,
  28. r: r,
  29. w: w,
  30. }
  31. }
  32. func (l *SearchListLogic) SearchList(req *types.SearchReq) (resp *types.CommonResp, err error) {
  33. defer common.Catch()
  34. t := time.Now()
  35. limitFlag, isNew := util.GetFlag(l.r, l.w, req.UserId)
  36. res, err := l.svcCtx.BxCore.GetSearchList(l.ctx, &bxcore.SearchReq{
  37. AppId: req.AppId,
  38. UserId: req.UserId,
  39. Phone: req.Phone,
  40. NewUserId: req.NewUserId,
  41. EntId: req.EntId,
  42. EntUserId: req.EntUserId,
  43. PageNum: req.PageNum,
  44. PageSize: req.PageSize,
  45. Province: req.Province,
  46. City: req.City,
  47. Subtype: req.Subtype,
  48. TopType: req.TopType,
  49. PublishTime: req.PublishTime,
  50. SelectType: req.SelectType,
  51. Price: req.Price,
  52. Industry: req.Industry,
  53. BuyerClass: req.BuyerClass,
  54. BuyerTel: req.BuyerTel,
  55. WinnerTel: req.WinnerTel,
  56. FileExists: req.FileExists,
  57. SearchGroup: req.SearchGroup,
  58. SearchMode: req.SearchMode,
  59. WordsMode: req.WordsMode,
  60. KeyWords: req.KeyWords,
  61. AdditionalWords: req.AdditionalWords,
  62. ExclusionWords: req.ExclusionWords,
  63. UserType: req.UserType,
  64. Platform: util.CheckPlatform(l.r),
  65. BidField: req.BidField,
  66. PositionType: req.PositionType,
  67. PositionId: req.PositionId,
  68. AccountId: req.AccountId,
  69. MgoUserId: req.MgoUserId,
  70. LimitFlag: limitFlag,
  71. IsNew: isNew,
  72. })
  73. log.Println("请求接口耗时:", time.Since(t).Seconds())
  74. if err != nil {
  75. return &types.CommonResp{
  76. Err_code: res.ErrCode,
  77. Err_msg: res.ErrMsg,
  78. Data: nil,
  79. }, err
  80. }
  81. if req.UserId == "" {
  82. var data []map[string]interface{}
  83. detailMosaicTxt := IC.C.DetailMosaicTxt
  84. sm := common.StructToMapMore(IC.C.SearchMosaic)
  85. for _, v := range res.Data.List {
  86. d := common.StructToMapMore(v)
  87. for name, t1 := range sm {
  88. ts, _ := t1.(bool)
  89. if !ts {
  90. continue
  91. }
  92. d[name] = detailMosaicTxt
  93. //if v1, ok := d[name]; ok && v1 != "" && v1 != 0 && ts {
  94. // d[name] = detailMosaicTxt
  95. //}
  96. }
  97. data = append(data, d)
  98. }
  99. dataAll := common.StructToMapMore(res.Data)
  100. dataAll["list"] = data
  101. return &types.CommonResp{
  102. Err_code: res.ErrCode,
  103. Err_msg: res.ErrMsg,
  104. Data: dataAll,
  105. }, nil
  106. }
  107. data := map[string]interface{}{
  108. "ip": common.GetIp(l.r),
  109. "count": res.Data.Count,
  110. "s_userid": req.UserId,
  111. "platform": strings.ToLower(util.CheckPlatform(l.r)),
  112. "source": "超级搜索",
  113. "createtime": time.Now().Unix(),
  114. "userAgent": l.r.Header.Get("User-Agent"),
  115. "pagenum": req.PageNum,
  116. "pagesize": req.PageSize,
  117. "search_area": req.Province,
  118. "search_city": req.City,
  119. "search_subType": req.Subtype,
  120. "search_topType": req.TopType,
  121. "search_selectType": req.SelectType,
  122. "search_price": req.Price,
  123. "search_industry": req.Industry,
  124. "search_buyerClass": req.BuyerClass,
  125. "search_buyerTel": req.BuyerTel,
  126. "search_winnerTel": req.WinnerTel,
  127. "fileExists": req.FileExists,
  128. "searchGroup": func(searchGroup int64) string {
  129. switch searchGroup {
  130. case 1:
  131. return "招标采购公告"
  132. case 2:
  133. return "超前项目"
  134. }
  135. return ""
  136. }(req.SearchGroup), //搜索分组:默认0:全部;1:招标采购公告;2:超前项目
  137. "searchMode": common.If(req.SearchMode == 1, "模糊搜索", "精准搜索"), //搜索模式:0:精准搜索;1:模糊搜索
  138. "wordsMode": common.If(req.WordsMode == 1, "包含任意", "包含所有"), //搜索关键词模式;默认0:包含所有,1:包含任意
  139. "search_word": req.KeyWords,
  140. "additionalWords": req.AdditionalWords,
  141. "exclusionWords": req.ExclusionWords,
  142. "search_publishtime": req.PublishTime,
  143. }
  144. go IC.SearchLog.SendLogs(data)
  145. return &types.CommonResp{
  146. Err_code: res.ErrCode,
  147. Err_msg: res.ErrMsg,
  148. Data: res.Data,
  149. }, nil
  150. }