searchListLogic.go 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. package logic
  2. import (
  3. "app.yhyue.com/moapp/jypkg/public"
  4. "context"
  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. "github.com/zeromicro/go-zero/core/logx"
  16. )
  17. type SearchListLogic struct {
  18. logx.Logger
  19. ctx context.Context
  20. svcCtx *svc.ServiceContext
  21. r *http.Request
  22. w http.ResponseWriter
  23. }
  24. func NewSearchListLogic(ctx context.Context, svcCtx *svc.ServiceContext, r *http.Request, w http.ResponseWriter) *SearchListLogic {
  25. return &SearchListLogic{
  26. Logger: logx.WithContext(ctx),
  27. ctx: ctx,
  28. svcCtx: svcCtx,
  29. r: r,
  30. w: w,
  31. }
  32. }
  33. func (l *SearchListLogic) SearchList(req *types.SearchReq) (resp *types.CommonResp, err error) {
  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 v1, ok := d[name]; ok && v1 != "" && v1 != 0 && ts {
  90. d[name] = detailMosaicTxt
  91. }
  92. }
  93. data = append(data, d)
  94. }
  95. dataAll := common.StructToMapMore(res.Data)
  96. dataAll["list"] = data
  97. return &types.CommonResp{
  98. Err_code: res.ErrCode,
  99. Err_msg: res.ErrMsg,
  100. Data: dataAll,
  101. }, nil
  102. }
  103. go func() {
  104. public.SaveUserSearchLog(l.r, req.UserId, res.Data.Count, strings.ToLower(util.CheckPlatform(l.r)), "超级搜索", map[string]interface{}{
  105. "pagenum": req.PageNum,
  106. "pagesize": req.PageSize,
  107. "search_area": req.Province,
  108. "search_city": req.City,
  109. "search_subType": req.Subtype,
  110. "search_topType": req.TopType,
  111. "search_selectType": req.SelectType,
  112. "search_price": req.Price,
  113. "search_industry": req.Industry,
  114. "search_buyerClass": req.BuyerClass,
  115. "search_buyerTel": req.BuyerTel,
  116. "search_winnerTel": req.WinnerTel,
  117. "fileExists": req.FileExists,
  118. "searchGroup": func(searchGroup int64) string {
  119. switch searchGroup {
  120. case 1:
  121. return "招标采购公告"
  122. case 2:
  123. return "超前项目"
  124. }
  125. return ""
  126. }(req.SearchGroup), //搜索分组:默认0:全部;1:招标采购公告;2:超前项目
  127. "searchMode": common.If(req.SearchMode == 1, "模糊搜索", "精准搜索"), //搜索模式:0:精准搜索;1:模糊搜索
  128. "wordsMode": common.If(req.WordsMode == 1, "包含任意", "包含所有"), //搜索关键词模式;默认0:包含所有,1:包含任意
  129. "search_word": req.KeyWords,
  130. "additionalWords": req.AdditionalWords,
  131. "exclusionWords": req.ExclusionWords,
  132. "search_publishtime": req.PublishTime,
  133. })
  134. }()
  135. return &types.CommonResp{
  136. Err_code: res.ErrCode,
  137. Err_msg: res.ErrMsg,
  138. Data: res.Data,
  139. }, nil
  140. }