searchListLogic.go 5.5 KB

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