searchListLogic.go 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. package logic
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/zeromicro/go-zero/core/logx"
  6. IC "jyBXCore/api/init"
  7. "jyBXCore/api/internal/svc"
  8. "jyBXCore/api/internal/types"
  9. "jyBXCore/api/internal/util"
  10. "jyBXCore/rpc/type/bxcore"
  11. "log"
  12. "net/http"
  13. "strings"
  14. "time"
  15. "app.yhyue.com/moapp/jybase/common"
  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. data := map[string]interface{}{
  104. "ip": common.GetIp(l.r),
  105. "count": res.Data.Count,
  106. "s_userid": req.UserId,
  107. "platform": strings.ToLower(util.CheckPlatform(l.r)),
  108. "source": "超级搜索",
  109. "createtime": time.Now().Unix(),
  110. "userAgent": l.r.Header.Get("User-Agent"),
  111. "pagenum": req.PageNum,
  112. "pagesize": req.PageSize,
  113. "search_area": req.Province,
  114. "search_city": req.City,
  115. "search_subType": req.Subtype,
  116. "search_topType": req.TopType,
  117. "search_selectType": req.SelectType,
  118. "search_price": req.Price,
  119. "search_industry": req.Industry,
  120. "search_buyerClass": req.BuyerClass,
  121. "search_buyerTel": req.BuyerTel,
  122. "search_winnerTel": req.WinnerTel,
  123. "fileExists": req.FileExists,
  124. "searchGroup": func(searchGroup int64) string {
  125. switch searchGroup {
  126. case 1:
  127. return "招标采购公告"
  128. case 2:
  129. return "超前项目"
  130. }
  131. return ""
  132. }(req.SearchGroup), //搜索分组:默认0:全部;1:招标采购公告;2:超前项目
  133. "searchMode": common.If(req.SearchMode == 1, "模糊搜索", "精准搜索"), //搜索模式:0:精准搜索;1:模糊搜索
  134. "wordsMode": common.If(req.WordsMode == 1, "包含任意", "包含所有"), //搜索关键词模式;默认0:包含所有,1:包含任意
  135. "search_word": req.KeyWords,
  136. "additionalWords": req.AdditionalWords,
  137. "exclusionWords": req.ExclusionWords,
  138. "search_publishtime": req.PublishTime,
  139. }
  140. if logId := IC.MgoLog.Save("jy_search_log", data); logId == "" {
  141. log.Println(fmt.Sprintf("保存搜索日志异常 %s", req.UserId))
  142. }
  143. return &types.CommonResp{
  144. Err_code: res.ErrCode,
  145. Err_msg: res.ErrMsg,
  146. Data: res.Data,
  147. }, nil
  148. }