getsearchlistlogic.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. // GetSearchList 标讯搜索结果列表数据
  28. func (l *GetSearchListLogic) GetSearchList(in *bxcore.SearchReq) (*bxcore.SearchResp, error) {
  29. defer MC.Catch()
  30. res := &bxcore.SearchData{
  31. Count: 0,
  32. List: []*bxcore.SearchList{},
  33. InterceptLimit: int64(MC.IntAllDef(IC.C.KeywordsLimit, 35)),
  34. }
  35. //初始化搜索对象
  36. ks := entity.NewKeyWordsSearch()
  37. //处理搜索条件
  38. heightWords := ks.SearchParamsHandle(in)
  39. //判断是否是空搜索,如果是空搜索,查缓存数据
  40. if ks.IsEmptySearch(in) {
  41. res.List, res.Count, res.Total = ks.GetBidSearchListByCache(in)
  42. return &bxcore.SearchResp{
  43. Data: res,
  44. ErrMsg: "",
  45. ErrCode: 0,
  46. }, nil
  47. }
  48. //异常付费用户 参数不是免费fType,但是又不是付费用户;还有一种是未登录用户 稍后处理
  49. if in.UserType != "fType" && !in.IsPay {
  50. return &bxcore.SearchResp{
  51. ErrCode: -1,
  52. ErrMsg: "无权限",
  53. }, nil
  54. }
  55. //未登录用户访问全部信息类型 需要过滤掉 拟建和采购意向
  56. if in.UserId == "" && in.Subtype == "" {
  57. in.Subtype = "招标预告,招标公告,招标结果,招标信用信息"
  58. }
  59. t := time.Now()
  60. //招标信息有效查询
  61. res.IsLimit = 1
  62. //查询数据
  63. searchLimit := util.IsSearchLimit(strings.Split(in.SelectType, ","))
  64. //全文检索限制
  65. if searchLimit {
  66. res.IsLimit = util.IsLimited(in.LimitFlag, in.UserId, in.UserType != "fType", in.IsNew)
  67. if res.IsLimit == 1 { //没有被限制
  68. defer util.Limit()
  69. }
  70. }
  71. //无限制
  72. if res.IsLimit == 1 {
  73. //付费用户搜索优化--默认搜索5年数据,数据量太多,接口反应太慢,前两页数据 时间范围根据配置缩小查询以达到快速查询的目的。
  74. publishTime := in.PublishTime
  75. if b := util.IsOptimize(IC.C, in); b {
  76. t1 := time.Now()
  77. res.Count, res.Total, res.List = ks.GetBidSearchList(in) // util.GetBidSearchData(in)
  78. logx.Info("1查询耗时:", time.Since(t1))
  79. }
  80. //如果优化查询数据量太少,和配置数据量作比较,不够的话走原始查询
  81. if res.Count < IC.C.PaySearchLimit.PageSize {
  82. t2 := time.Now()
  83. in.PublishTime = publishTime
  84. res.Count, res.Total, res.List = ks.GetBidSearchList(in) //util.GetBidSearchData(in)
  85. logx.Info("2查询耗时:", time.Since(t2))
  86. }
  87. res.KeyWords = strings.Join(heightWords, " ")
  88. res.InterceptOtherWords = in.InterceptOtherWords
  89. res.InterceptKeyWords = in.InterceptKeyWords
  90. }
  91. logx.Info("关键词 -全部- 查询耗时:", time.Since(t).Seconds())
  92. return &bxcore.SearchResp{
  93. Data: res,
  94. ErrMsg: "",
  95. ErrCode: 0,
  96. }, nil
  97. }