123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- package logic
- import (
- MC "app.yhyue.com/moapp/jybase/common"
- "context"
- "jyBXCore/rpc/entity"
- IC "jyBXCore/rpc/init"
- "jyBXCore/rpc/util"
- "strings"
- "time"
- "github.com/zeromicro/go-zero/core/logx"
- "jyBXCore/rpc/internal/svc"
- "jyBXCore/rpc/type/bxcore"
- "log"
- )
- 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),
- }
- }
- // GetSearchList 标讯搜索结果列表数据
- // GetSearchList 标讯搜索结果列表数据
- func (l *GetSearchListLogic) GetSearchList(in *bxcore.SearchReq) (*bxcore.SearchResp, error) {
- defer MC.Catch()
- res := &bxcore.SearchData{
- Count: 0,
- List: []*bxcore.SearchList{},
- InterceptLimit: int64(MC.IntAllDef(IC.C.KeywordsLimit, 35)),
- }
- //初始化搜索对象
- ks := entity.NewKeyWordsSearch()
- //处理搜索条件
- heightWords := ks.SearchParamsHandle(in)
- //判断是否是空搜索,如果是空搜索,查缓存数据
- if ks.IsEmptySearch(in) {
- res.List, res.Count, res.Total = ks.GetBidSearchListByCache(in)
- return &bxcore.SearchResp{
- Data: res,
- ErrMsg: "",
- ErrCode: 0,
- }, nil
- }
- //异常付费用户 参数不是免费fType,但是又不是付费用户;还有一种是未登录用户 稍后处理
- if in.UserType != "fType" && !in.IsPay {
- return &bxcore.SearchResp{
- ErrCode: -1,
- ErrMsg: "无权限",
- }, nil
- }
- //p353包含采购意向与拟建
- //未登录用户访问全部信息类型 需要过滤掉 拟建和采购意向
- if in.UserId == "" && in.Subtype == "" {
- in.Subtype = "拟建,招标预告,招标公告,招标结果,招标信用信息"
- }
- t := time.Now()
- //招标信息有效查询
- res.IsLimit = 1
- //查询数据
- searchLimit := util.IsSearchLimit(strings.Split(in.SelectType, ","))
- //全文检索限制
- if searchLimit {
- res.IsLimit = util.IsLimited(in.LimitFlag, in.UserId, in.UserType != "fType", in.IsNew)
- if res.IsLimit == 1 { //没有被限制
- defer util.Limit()
- }
- }
- //无限制
- if res.IsLimit == 1 {
- //付费用户搜索优化--默认搜索5年数据,数据量太多,接口反应太慢,前两页数据 时间范围根据配置缩小查询以达到快速查询的目的。
- publishTime := in.PublishTime
- if b := util.IsOptimize(IC.C, in); b {
- t1 := time.Now()
- res.Count, res.Total, res.List = ks.GetBidSearchList(in) // util.GetBidSearchData(in)
- log.Println("1查询耗时:", time.Since(t1))
- }
- //如果优化查询数据量太少,和配置数据量作比较,不够的话走原始查询
- if res.Count < IC.C.PaySearchLimit.PageSize {
- t2 := time.Now()
- in.PublishTime = publishTime
- res.Count, res.Total, res.List = ks.GetBidSearchList(in) //util.GetBidSearchData(in)
- log.Println("2查询耗时:", time.Since(t2))
- }
- res.KeyWords = strings.Join(heightWords, " ")
- res.InterceptOtherWords = in.InterceptOtherWords
- res.InterceptKeyWords = in.InterceptKeyWords
- }
- log.Println("关键词 -全部- 查询耗时:", time.Since(t).Seconds())
- return &bxcore.SearchResp{
- Data: res,
- ErrMsg: "",
- ErrCode: 0,
- }, nil
- }
|