getsearchlistlogic.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. // 标讯搜索结果列表数据
  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. NumberMsg: IC.C.DefaultBidInfo.NumMsg,
  41. }
  42. //初始化搜索对象
  43. ks := entity.NewKeyWordsSearch()
  44. //处理搜索条件
  45. ks.SearchParamsHandle(in)
  46. //判断是否是空搜索,如果是空搜索,查缓存数据
  47. if ks.IsEmptySearch(in) {
  48. res.List, res.Count = ks.GetBidListByCache(in)
  49. return &bxcore.SearchResp{
  50. Data: res,
  51. ErrMsg: "",
  52. ErrCode: 0,
  53. }, nil
  54. }
  55. //异常付费用户
  56. if in.UserType != "fType" && !in.IsFree {
  57. return &bxcore.SearchResp{
  58. ErrCode: -1,
  59. ErrMsg: "无权限",
  60. }, nil
  61. }
  62. //招标信息有效查询
  63. t := time.Now()
  64. res.IsLimit = 1
  65. //查询数据
  66. searchLimit := util.IsSearchLimit(strings.Split(in.SelectType, ","))
  67. //全文检索限制
  68. if searchLimit {
  69. res.IsLimit = util.IsLimited(in.UserId, in.UserType != "fType")
  70. if res.IsLimit == 1 { //没有被限制
  71. defer util.Limit()
  72. }
  73. }
  74. //无限制
  75. if res.IsLimit == 1 {
  76. //付费用户搜索优化
  77. publishTime := in.PublishTime
  78. t1 := time.Now()
  79. if b := util.IsOptimize(IC.C, in); b {
  80. res.Count, res.List = util.GetBidSearchData(in)
  81. res.Count += 1 //避免刚好50条 无法加载下一页数据
  82. }
  83. logx.Info("1查询耗时", time.Since(t1))
  84. t2 := time.Now()
  85. //不够配置条 走原始查询
  86. if res.Count < IC.C.PaySearchLimit.PageSize {
  87. in.PublishTime = publishTime
  88. res.Count, res.List = util.GetBidSearchData(in)
  89. }
  90. logx.Info("2查询耗时:", time.Since(t2))
  91. limitCount := MC.If(in.UserType != "fType", int64(util.SearchPageSize*util.SearchMaxPageNum_PAYED), int64(util.SearchPageSize*util.SearchMaxPageNum)).(int64)
  92. if res.Count > limitCount {
  93. res.Count = limitCount
  94. }
  95. res.KeyWords = in.KeyWords
  96. res.InterceptOtherWords = in.InterceptOtherWords
  97. //是否收藏
  98. //util.MakeCollection(in.UserId, list)
  99. //res.TotalPage = MC.If(in.PageNum == 1, (count+int64(util.SearchPageSize)-1)/int64(util.SearchPageSize), res.TotalPage).(int64)
  100. //res.Count = count
  101. //res.List = list
  102. }
  103. logx.Info("关键词 -全部- 查询耗时:", time.Since(t).Seconds())
  104. return &bxcore.SearchResp{
  105. Data: res,
  106. ErrMsg: "",
  107. ErrCode: 0,
  108. }, nil
  109. }