searchListLogic.go 4.6 KB

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