package logic import ( MC "app.yhyue.com/moapp/jybase/common" "context" "jyBXCore/rpc/entity" IC "jyBXCore/rpc/init" "jyBXCore/rpc/util" "strings" "time" "jyBXCore/rpc/internal/svc" "jyBXCore/rpc/type/bxcore" "github.com/zeromicro/go-zero/core/logx" ) type GetSearchListLogic struct { ctx context.Context svcCtx *svc.ServiceContext logx.Logger } func NewGetSearchListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetSearchListLogic { return &GetSearchListLogic{ ctx: ctx, svcCtx: svcCtx, Logger: logx.WithContext(ctx), } } // 标讯搜索结果列表数据 func (l *GetSearchListLogic) GetSearchList(in *bxcore.SearchReq) (*bxcore.SearchResp, error) { defer MC.Catch() //用户身份 是否登录 if in.UserId == "" { return &bxcore.SearchResp{ ErrCode: -1, ErrMsg: "用户信息异常", }, nil } res := &bxcore.SearchData{ Count: 0, List: []*bxcore.SearchList{}, InterceptLimit: int64(MC.IntAllDef(IC.C.KeywordsLimit, 35)), NumberMsg: IC.C.DefaultBidInfo.NumMsg, } //初始化搜索对象 ks := entity.NewKeyWordsSearch() //处理搜索条件 ks.SearchParamsHandle(in) //判断是否是空搜索,如果是空搜索,查缓存数据 if ks.IsEmptySearch(in) { res.List, res.Count = ks.GetBidListByCache(in) return &bxcore.SearchResp{ Data: res, ErrMsg: "", ErrCode: 0, }, nil } //异常付费用户 if in.UserType != "fType" && !in.IsFree { return &bxcore.SearchResp{ ErrCode: -1, ErrMsg: "无权限", }, nil } //招标信息有效查询 t := time.Now() res.IsLimit = 1 //查询数据 searchLimit := util.IsSearchLimit(strings.Split(in.SelectType, ",")) //全文检索限制 if searchLimit { res.IsLimit = util.IsLimited(in.UserId, in.UserType != "fType") if res.IsLimit == 1 { //没有被限制 defer util.Limit() } } //无限制 if res.IsLimit == 1 { //付费用户搜索优化 publishTime := in.PublishTime t1 := time.Now() if b := util.IsOptimize(IC.C, in); b { res.Count, res.List = util.GetBidSearchData(in) res.Count += 1 //避免刚好50条 无法加载下一页数据 } logx.Info("1查询耗时", time.Since(t1)) t2 := time.Now() //不够配置条 走原始查询 if res.Count < IC.C.PaySearchLimit.PageSize { in.PublishTime = publishTime res.Count, res.List = util.GetBidSearchData(in) } logx.Info("2查询耗时:", time.Since(t2)) limitCount := MC.If(in.UserType != "fType", int64(util.SearchPageSize*util.SearchMaxPageNum_PAYED), int64(util.SearchPageSize*util.SearchMaxPageNum)).(int64) if res.Count > limitCount { res.Count = limitCount } res.KeyWords = in.KeyWords res.InterceptOtherWords = in.InterceptOtherWords //是否收藏 //util.MakeCollection(in.UserId, list) //res.TotalPage = MC.If(in.PageNum == 1, (count+int64(util.SearchPageSize)-1)/int64(util.SearchPageSize), res.TotalPage).(int64) //res.Count = count //res.List = list } logx.Info("关键词 -全部- 查询耗时:", time.Since(t).Seconds()) return &bxcore.SearchResp{ Data: res, ErrMsg: "", ErrCode: 0, }, nil }