getsearchlistlogic.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. package logic
  2. import (
  3. MC "app.yhyue.com/moapp/jybase/common"
  4. "context"
  5. "jyBXCore/rpc/entity"
  6. IC "jyBXCore/rpc/init"
  7. "jyBXCore/rpc/util"
  8. "strings"
  9. "time"
  10. "jyBXCore/rpc/internal/svc"
  11. "jyBXCore/rpc/type/bxcore"
  12. "github.com/zeromicro/go-zero/core/logx"
  13. )
  14. type GetSearchListLogic struct {
  15. ctx context.Context
  16. svcCtx *svc.ServiceContext
  17. logx.Logger
  18. }
  19. func NewGetSearchListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetSearchListLogic {
  20. return &GetSearchListLogic{
  21. ctx: ctx,
  22. svcCtx: svcCtx,
  23. Logger: logx.WithContext(ctx),
  24. }
  25. }
  26. // GetSearchList 标讯搜索结果列表数据
  27. func (l *GetSearchListLogic) GetSearchList(in *bxcore.SearchReq) (*bxcore.SearchResp, error) {
  28. defer MC.Catch()
  29. //用户身份 是否登录
  30. if in.UserId == "" {
  31. return &bxcore.SearchResp{
  32. ErrCode: -1,
  33. ErrMsg: "用户信息异常",
  34. }, nil
  35. }
  36. res := &bxcore.SearchData{
  37. Count: 0,
  38. List: []*bxcore.SearchList{},
  39. InterceptLimit: int64(MC.IntAllDef(IC.C.KeywordsLimit, 35)),
  40. Total: MC.Int64All(IC.C.DefaultBidInfo.Total),
  41. }
  42. logx.Info(in.SearchGroup, "-----------------:", IC.C.DefaultBidInfo.Total)
  43. //初始化搜索对象
  44. ks := entity.NewKeyWordsSearch()
  45. //处理搜索条件
  46. heightWords := ks.SearchParamsHandle(in)
  47. //判断是否是空搜索,如果是空搜索,查缓存数据
  48. if ks.IsEmptySearch(in) {
  49. res.List, res.Count = ks.GetBidSearchListByCache(in)
  50. logx.Info(len(res.List), "+++++++++++++++++++++++++", res.Count)
  51. return &bxcore.SearchResp{
  52. Data: res,
  53. ErrMsg: "",
  54. ErrCode: 0,
  55. }, nil
  56. }
  57. //异常付费用户 参数不是免费fType,但是又不是付费用户;还有一种是未登录用户 稍后处理
  58. if in.UserType != "fType" && !in.IsPay {
  59. return &bxcore.SearchResp{
  60. ErrCode: -1,
  61. ErrMsg: "无权限",
  62. }, nil
  63. }
  64. t := time.Now()
  65. //招标信息有效查询
  66. res.IsLimit = 1
  67. //查询数据
  68. searchLimit := util.IsSearchLimit(strings.Split(in.SelectType, ","))
  69. //全文检索限制
  70. if searchLimit {
  71. res.IsLimit = util.IsLimited(in.UserId, in.UserType != "fType")
  72. if res.IsLimit == 1 { //没有被限制
  73. defer util.Limit()
  74. }
  75. }
  76. //无限制
  77. if res.IsLimit == 1 {
  78. //付费用户搜索优化--默认搜索5年数据,数据量太多,接口反应太慢,前两页数据 时间范围根据配置缩小查询以达到快速查询的目的。
  79. publishTime := in.PublishTime
  80. if b := util.IsOptimize(IC.C, in); b {
  81. t1 := time.Now()
  82. res.Count, res.Total, res.List = ks.GetBidSearchList(in) // util.GetBidSearchData(in)
  83. logx.Info("1查询耗时:", time.Since(t1))
  84. }
  85. //如果优化查询数据量太少,和配置数据量作比较,不够的话走原始查询
  86. if res.Count < IC.C.PaySearchLimit.PageSize {
  87. t2 := time.Now()
  88. in.PublishTime = publishTime
  89. res.Count, res.Total, res.List = ks.GetBidSearchList(in) //util.GetBidSearchData(in)
  90. logx.Info("2查询耗时:", time.Since(t2))
  91. }
  92. res.KeyWords = strings.Join(heightWords, " ")
  93. res.InterceptOtherWords = in.InterceptOtherWords
  94. res.InterceptKeyWords = in.InterceptKeyWords
  95. }
  96. logx.Info("关键词 -全部- 查询耗时:", time.Since(t).Seconds())
  97. return &bxcore.SearchResp{
  98. Data: res,
  99. ErrMsg: "",
  100. ErrCode: 0,
  101. }, nil
  102. }