searchListLogic.go 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. District: req.District,
  73. Buyer: req.Buyer,
  74. Winner: req.Winner,
  75. Agency: req.Agency,
  76. })
  77. log.Println("请求接口耗时:", time.Since(t).Seconds())
  78. if err != nil {
  79. return &types.CommonResp{
  80. Err_code: res.ErrCode,
  81. Err_msg: res.ErrMsg,
  82. Data: nil,
  83. }, err
  84. }
  85. if req.UserId == "" {
  86. var data []map[string]interface{}
  87. detailMosaicTxt := IC.C.DetailMosaicTxt
  88. sm := common.StructToMapMore(IC.C.SearchMosaic)
  89. for _, v := range res.Data.List {
  90. d := common.StructToMapMore(v)
  91. for name, t1 := range sm {
  92. ts, _ := t1.(bool)
  93. if !ts {
  94. continue
  95. }
  96. d[name] = detailMosaicTxt
  97. //if v1, ok := d[name]; ok && v1 != "" && v1 != 0 && ts {
  98. // d[name] = detailMosaicTxt
  99. //}
  100. }
  101. data = append(data, d)
  102. }
  103. dataAll := common.StructToMapMore(res.Data)
  104. dataAll["list"] = data
  105. return &types.CommonResp{
  106. Err_code: res.ErrCode,
  107. Err_msg: res.ErrMsg,
  108. Data: dataAll,
  109. }, nil
  110. }
  111. data := map[string]interface{}{
  112. "ip": common.GetIp(l.r),
  113. "count": res.Data.Count,
  114. "s_userid": req.UserId,
  115. "platform": strings.ToLower(util.CheckPlatform(l.r)),
  116. "source": "超级搜索",
  117. "createtime": time.Now().Unix(),
  118. "userAgent": l.r.Header.Get("User-Agent"),
  119. "pagenum": req.PageNum,
  120. "pagesize": req.PageSize,
  121. "search_area": req.Province,
  122. "search_city": req.City,
  123. "search_subType": req.Subtype,
  124. "search_topType": req.TopType,
  125. "search_selectType": req.SelectType,
  126. "search_price": req.Price,
  127. "search_industry": req.Industry,
  128. "search_buyerClass": req.BuyerClass,
  129. "search_buyerTel": req.BuyerTel,
  130. "search_winnerTel": req.WinnerTel,
  131. "fileExists": req.FileExists,
  132. "searchGroup": func(searchGroup int64) string {
  133. switch searchGroup {
  134. case 1:
  135. return "招标采购公告"
  136. case 2:
  137. return "超前项目"
  138. }
  139. return ""
  140. }(req.SearchGroup), //搜索分组:默认0:全部;1:招标采购公告;2:超前项目
  141. "searchMode": common.If(req.SearchMode == 1, "模糊搜索", "精准搜索"), //搜索模式:0:精准搜索;1:模糊搜索
  142. "wordsMode": common.If(req.WordsMode == 1, "包含任意", "包含所有"), //搜索关键词模式;默认0:包含所有,1:包含任意
  143. "search_word": req.KeyWords,
  144. "additionalWords": req.AdditionalWords,
  145. "exclusionWords": req.ExclusionWords,
  146. "search_publishtime": req.PublishTime,
  147. }
  148. go IC.SearchLog.SendLogs(data)
  149. return &types.CommonResp{
  150. Err_code: res.ErrCode,
  151. Err_msg: res.ErrMsg,
  152. Data: res.Data,
  153. }, nil
  154. }