searchListLogic.go 5.4 KB

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