getsearchlistlogic.go 3.2 KB

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