123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- package logic
- import (
- MC "app.yhyue.com/moapp/jybase/common"
- IC "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXCore/rpc/init"
- "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXCore/rpc/service"
- "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXCore/rpc/util"
- "context"
- "strings"
- "time"
- "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXCore/rpc/internal/svc"
- "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXCore/rpc/type/bxcore"
- "github.com/zeromicro/go-zero/core/logx"
- "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 标讯搜索结果列表数据
- 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 := service.NewKeyWordsSearch()
- // 未登录用户只允许翻页和筛选搜索范围 其他参数无效
- if in.UserId == "" {
- in = &bxcore.SearchReq{
- AppId: in.AppId,
- PageNum: in.PageNum,
- PageSize: in.PageSize,
- SelectType: in.SelectType,
- KeyWords: in.KeyWords,
- Platform: in.Platform,
- UserType: in.UserType,
- SearchGroup: in.SearchGroup,
- Subtype: in.Subtype,
- TopType: in.TopType,
- }
- // 搜索范围只允许筛选 标题和正文 其他的过滤掉
- var selectType []string
- selectTypeSplit := strings.Split(in.SelectType, ",")
- // 未登录用户只能搜标题和正文
- for i := 0; i < len(selectTypeSplit); i++ {
- if selectTypeSplit[i] == "title" || selectTypeSplit[i] == "content" {
- selectType = append(selectType, selectTypeSplit[i])
- }
- }
- if len(selectType) == 0 {
- selectType = []string{"title", "content"}
- }
- //
- in.SelectType = strings.Join(selectType, ",")
- }
- isWhite, _ := service.IsOnTheWhitelist(in.UserId, in.MgoUserId)
- //模糊检索数重新格式化
- nin := &bxcore.SearchReq{
- AppId: in.AppId,
- UserId: in.UserId,
- Phone: in.Phone,
- NewUserId: in.NewUserId,
- EntId: in.EntId,
- EntUserId: in.EntUserId,
- PageNum: in.PageNum,
- PageSize: in.PageSize,
- Province: in.Province,
- City: in.City,
- Subtype: in.Subtype,
- TopType: in.TopType,
- PublishTime: in.PublishTime,
- SelectType: in.SelectType,
- Price: in.Price,
- Industry: in.Industry,
- BuyerClass: in.BuyerClass,
- BuyerTel: in.BuyerTel,
- WinnerTel: in.WinnerTel,
- FileExists: in.FileExists,
- SearchGroup: in.SearchGroup,
- SearchMode: 1,
- WordsMode: in.WordsMode,
- KeyWords: in.KeyWords,
- AdditionalWords: in.AdditionalWords,
- ExclusionWords: in.ExclusionWords,
- UserType: in.UserType,
- Platform: in.Platform,
- BidField: in.BidField,
- PositionType: in.PositionType,
- PositionId: in.PositionId,
- AccountId: in.AccountId,
- MgoUserId: in.MgoUserId,
- LimitFlag: in.LimitFlag,
- IsNew: in.IsNew,
- District: in.District,
- Buyer: in.Buyer,
- Winner: in.Winner,
- Agency: in.Agency,
- IsFuzzyNumber: true,
- PropertyForm: in.PropertyForm,
- ExpireTime: in.ExpireTime,
- SubInformation: in.SubInformation,
- Period: in.Period,
- ChangeHand: in.ChangeHand,
- Scale: in.Scale,
- MobileTag: in.MobileTag,
- EntAccountId: in.EntAccountId,
- UserAgent: in.UserAgent,
- }
- //处理搜索条件
- heightWords := ks.SearchParamsHandle(in, isWhite)
- if (in.PageNum < 0 && in.PageSize < 0) || ks.IsSearch == "F" { //没有权限
- return &bxcore.SearchResp{
- Data: res,
- ErrMsg: "",
- ErrCode: 0,
- }, nil
- }
- //判断是否是空搜索,如果是空搜索,查缓存数据
- if ks.IsEmptySearch(in, isWhite) {
- log.Println("空查询分组", in.SearchGroup)
- 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
- }
- t := time.Now()
- //招标信息有效查询
- res.IsLimit = 1
- //查询数据
- searchLimit := util.IsSearchLimit(strings.Split(in.SelectType, ","))
- //全文检索限制
- if searchLimit {
- var warnMsg string
- //res.IsLimit = util.IsLimited(in.LimitFlag, in.UserId, in.UserType != "fType", in.IsNew)
- res.IsLimit, warnMsg = util.CheckLimit(util.UserIdentMap[func(userId string, isPay bool) string {
- switch {
- case isPay:
- return "payer"
- case userId != "":
- return "free"
- default:
- return "noLogin"
- }
- }(in.UserId, in.IsPay)], in.LimitFlag, in.IsNew)
- if res.IsLimit == 1 { //没有被限制
- defer util.Limit()
- }
- if warnMsg != "" {
- util.SendMsgByWXURL(warnMsg)
- }
- }
- //无限制
- 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)
- log.Println("2查询耗时:", time.Since(t2))
- }
- // 精准模式不足50条的非空标讯查询 匹配模糊查询数
- if res.Count < IC.C.PaySearchLimit.PrecisionNum && in.SearchMode == 0 && in.KeyWords != "" {
- ks.SearchParamsHandle(nin, isWhite)
- res.BCount = service.GetBidSearchCount(nin)
- log.Println("精准查询数据不足 匹配模糊查询数:", res.BCount)
- }
- 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
- }
|