searchListLogic.go 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. defer common.Catch()
  35. t := time.Now()
  36. limitFlag, isNew := util.GetFlag(l.r, l.w, req.UserId)
  37. res, err := l.svcCtx.BxCore.GetSearchList(l.ctx, &bxcore.SearchReq{
  38. AppId: req.AppId,
  39. UserId: req.UserId,
  40. Phone: req.Phone,
  41. NewUserId: req.NewUserId,
  42. EntId: req.EntId,
  43. EntUserId: req.EntUserId,
  44. PageNum: req.PageNum,
  45. PageSize: req.PageSize,
  46. Province: req.Province,
  47. City: req.City,
  48. Subtype: req.Subtype,
  49. TopType: req.TopType,
  50. PublishTime: req.PublishTime,
  51. SelectType: req.SelectType,
  52. Price: req.Price,
  53. Industry: req.Industry,
  54. BuyerClass: req.BuyerClass,
  55. BuyerTel: req.BuyerTel,
  56. WinnerTel: req.WinnerTel,
  57. FileExists: req.FileExists,
  58. SearchGroup: req.SearchGroup,
  59. SearchMode: req.SearchMode,
  60. WordsMode: req.WordsMode,
  61. KeyWords: req.KeyWords,
  62. AdditionalWords: req.AdditionalWords,
  63. ExclusionWords: req.ExclusionWords,
  64. UserType: req.UserType,
  65. Platform: util.CheckPlatform(l.r),
  66. BidField: req.BidField,
  67. PositionType: req.PositionType,
  68. PositionId: req.PositionId,
  69. AccountId: req.AccountId,
  70. MgoUserId: req.MgoUserId,
  71. LimitFlag: limitFlag,
  72. IsNew: isNew,
  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. if name == "winnerPerson" || name == "winnerTel" || name == "winner" {
  94. if v.WinnerInfo != nil {
  95. var winnerInfo []*bxcore.WinnerInfo
  96. for _, wv := range v.WinnerInfo {
  97. if name == "winnerPerson" {
  98. wv.WinnerPerson = detailMosaicTxt
  99. }
  100. if name == "winnerTel" {
  101. wv.WinnerTel = detailMosaicTxt
  102. }
  103. if name == "winner" {
  104. wv.Winner = detailMosaicTxt
  105. }
  106. winnerInfo = append(winnerInfo, &bxcore.WinnerInfo{
  107. Winner: wv.Winner,
  108. WinnerTel: wv.WinnerTel,
  109. WinnerPerson: wv.WinnerPerson,
  110. WinnerId: wv.WinnerId,
  111. })
  112. }
  113. d["winnerInfo"] = winnerInfo
  114. }
  115. } else {
  116. d[name] = detailMosaicTxt
  117. }
  118. //if v1, ok := d[name]; ok && v1 != "" && v1 != 0 && ts {
  119. // d[name] = detailMosaicTxt
  120. //}
  121. }
  122. data = append(data, d)
  123. }
  124. dataAll := common.StructToMapMore(res.Data)
  125. dataAll["list"] = data
  126. return &types.CommonResp{
  127. Err_code: res.ErrCode,
  128. Err_msg: res.ErrMsg,
  129. Data: dataAll,
  130. }, nil
  131. }
  132. data := map[string]interface{}{
  133. "ip": common.GetIp(l.r),
  134. "count": res.Data.Count,
  135. "s_userid": req.UserId,
  136. "platform": strings.ToLower(util.CheckPlatform(l.r)),
  137. "source": "超级搜索",
  138. "createtime": time.Now().Unix(),
  139. "userAgent": l.r.Header.Get("User-Agent"),
  140. "pagenum": req.PageNum,
  141. "pagesize": req.PageSize,
  142. "search_area": req.Province,
  143. "search_city": req.City,
  144. "search_subType": req.Subtype,
  145. "search_topType": req.TopType,
  146. "search_selectType": req.SelectType,
  147. "search_price": req.Price,
  148. "search_industry": req.Industry,
  149. "search_buyerClass": req.BuyerClass,
  150. "search_buyerTel": req.BuyerTel,
  151. "search_winnerTel": req.WinnerTel,
  152. "fileExists": req.FileExists,
  153. "searchGroup": func(searchGroup int64) string {
  154. switch searchGroup {
  155. case 1:
  156. return "招标采购公告"
  157. case 2:
  158. return "超前项目"
  159. }
  160. return ""
  161. }(req.SearchGroup), //搜索分组:默认0:全部;1:招标采购公告;2:超前项目
  162. "searchMode": common.If(req.SearchMode == 1, "模糊搜索", "精准搜索"), //搜索模式:0:精准搜索;1:模糊搜索
  163. "wordsMode": common.If(req.WordsMode == 1, "包含任意", "包含所有"), //搜索关键词模式;默认0:包含所有,1:包含任意
  164. "search_word": req.KeyWords,
  165. "additionalWords": req.AdditionalWords,
  166. "exclusionWords": req.ExclusionWords,
  167. "search_publishtime": req.PublishTime,
  168. }
  169. if logId := IC.MgoLog.Save("jy_search_log", data); logId == "" {
  170. log.Println(fmt.Sprintf("保存搜索日志异常 %s", req.UserId))
  171. }
  172. return &types.CommonResp{
  173. Err_code: res.ErrCode,
  174. Err_msg: res.ErrMsg,
  175. Data: res.Data,
  176. }, nil
  177. }