searchListLogic.go 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. var mobileTag []string
  37. //工作台内
  38. if strings.Contains(l.r.Referer(), "/page_workDesktop/work-bench") {
  39. mobileTag = req.MobileTag
  40. }
  41. res, err := l.svcCtx.BxCore.GetSearchList(l.ctx, &bxcore.SearchReq{
  42. AppId: req.AppId,
  43. UserId: req.UserId,
  44. Phone: req.Phone,
  45. NewUserId: req.NewUserId,
  46. EntId: req.EntId,
  47. EntUserId: req.EntUserId,
  48. PageNum: req.PageNum,
  49. PageSize: req.PageSize,
  50. Province: req.Province,
  51. City: req.City,
  52. Subtype: req.Subtype,
  53. TopType: req.TopType,
  54. PublishTime: req.PublishTime,
  55. SelectType: req.SelectType,
  56. Price: req.Price,
  57. Industry: req.Industry,
  58. BuyerClass: req.BuyerClass,
  59. BuyerTel: req.BuyerTel,
  60. WinnerTel: req.WinnerTel,
  61. FileExists: req.FileExists,
  62. SearchGroup: req.SearchGroup,
  63. SearchMode: req.SearchMode,
  64. WordsMode: req.WordsMode,
  65. KeyWords: req.KeyWords,
  66. AdditionalWords: req.AdditionalWords,
  67. ExclusionWords: req.ExclusionWords,
  68. UserType: req.UserType,
  69. Platform: util.CheckPlatform(l.r),
  70. BidField: req.BidField,
  71. PositionType: req.PositionType,
  72. PositionId: req.PositionId,
  73. AccountId: req.AccountId,
  74. MgoUserId: req.MgoUserId,
  75. LimitFlag: limitFlag,
  76. IsNew: isNew,
  77. District: req.District,
  78. Buyer: req.Buyer,
  79. Winner: req.Winner,
  80. Agency: req.Agency,
  81. PropertyForm: req.PropertyForm,
  82. ExpireTime: req.ExpireTime,
  83. SubInformation: req.SubInformation,
  84. Period: req.Period,
  85. ChangeHand: int64(req.ChangeHand),
  86. Scale: req.Scale,
  87. MobileTag: mobileTag,
  88. UserAgent: l.r.UserAgent(),
  89. })
  90. log.Println("请求接口耗时:", time.Since(t).Seconds())
  91. if err != nil {
  92. return &types.CommonResp{
  93. Err_code: res.ErrCode,
  94. Err_msg: res.ErrMsg,
  95. Data: nil,
  96. }, err
  97. }
  98. if req.UserId == "" {
  99. var data []map[string]interface{}
  100. detailMosaicTxt := IC.C.DetailMosaicTxt
  101. sm := common.StructToMapMore(IC.C.SearchMosaic)
  102. for _, v := range res.Data.List {
  103. d := common.StructToMapMore(v)
  104. for name, t1 := range sm {
  105. ts, _ := t1.(bool)
  106. if !ts {
  107. continue
  108. }
  109. d[name] = detailMosaicTxt
  110. //if v1, ok := d[name]; ok && v1 != "" && v1 != 0 && ts {
  111. // d[name] = detailMosaicTxt
  112. //}
  113. }
  114. data = append(data, d)
  115. }
  116. dataAll := common.StructToMapMore(res.Data)
  117. dataAll["list"] = data
  118. return &types.CommonResp{
  119. Err_code: res.ErrCode,
  120. Err_msg: res.ErrMsg,
  121. Data: dataAll,
  122. }, nil
  123. }
  124. data := map[string]interface{}{
  125. "ip": common.GetIp(l.r),
  126. "count": res.Data.Count,
  127. "s_userid": req.UserId,
  128. "platform": strings.ToLower(util.CheckPlatform(l.r)),
  129. "source": "超级搜索",
  130. "createtime": time.Now().Unix(),
  131. "userAgent": l.r.Header.Get("User-Agent"),
  132. "pagenum": req.PageNum,
  133. "pagesize": req.PageSize,
  134. "search_area": req.Province,
  135. "search_city": req.City,
  136. "search_subType": req.Subtype,
  137. "search_topType": req.TopType,
  138. "search_selectType": req.SelectType,
  139. "search_price": req.Price,
  140. "search_industry": req.Industry,
  141. "search_buyerClass": req.BuyerClass,
  142. "search_buyerTel": req.BuyerTel,
  143. "search_winnerTel": req.WinnerTel,
  144. "fileExists": req.FileExists,
  145. "searchGroup": func(searchGroup int64) string {
  146. switch searchGroup {
  147. case 1:
  148. return "招标采购公告"
  149. case 2:
  150. return "超前项目"
  151. }
  152. return ""
  153. }(req.SearchGroup), //搜索分组:默认0:全部;1:招标采购公告;2:超前项目
  154. "searchMode": common.If(req.SearchMode == 1, "模糊搜索", "精准搜索"), //搜索模式:0:精准搜索;1:模糊搜索
  155. "wordsMode": common.If(req.WordsMode == 1, "包含任意", "包含所有"), //搜索关键词模式;默认0:包含所有,1:包含任意
  156. "search_word": req.KeyWords,
  157. "additionalWords": req.AdditionalWords,
  158. "exclusionWords": req.ExclusionWords,
  159. "search_publishtime": req.PublishTime,
  160. }
  161. go IC.SearchLog.SendLogs(data)
  162. return &types.CommonResp{
  163. Err_code: res.ErrCode,
  164. Err_msg: res.ErrMsg,
  165. Data: res.Data,
  166. }, nil
  167. }