package logic import ( MC "app.yhyue.com/moapp/jybase/common" "app.yhyue.com/moapp/jybase/redis" "context" "fmt" "github.com/zeromicro/go-zero/core/logx" IC "jyBXCore/api/init" "jyBXCore/api/internal/svc" "jyBXCore/api/internal/types" "jyBXCore/api/internal/util" ) type MobileHotWordLogic struct { logx.Logger ctx context.Context svcCtx *svc.ServiceContext } func NewMobileHotWordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MobileHotWordLogic { return &MobileHotWordLogic{ Logger: logx.WithContext(ctx), ctx: ctx, svcCtx: svcCtx, } } func (l *MobileHotWordLogic) MobileHotWord(req *types.MobileHotWordReq) (resp *types.CommonResp, err error) { var rsData []string if req.Refresh == 0 { //非刷新动作 自动获取默认缓存热词 5分钟更新一次 rsData = MC.If(req.UserId == "", IC.HotKeyArrUnLogin, IC.HotKeyArrLoginEd).([]string) } else { // 刷新热词 需过滤已经看过的热词 redisKey := MC.If(req.UserId == "", "mobileHotWordUnLogin", fmt.Sprintf("mobileHotWordLogin_%s", req.UserId)).(string) rData, _ := redis.Get("newother", redisKey).([]interface{}) defaultWord := MC.If(req.UserId == "", IC.HotKeyArrUnLogin, IC.HotKeyArrLoginEd).([]string) //排除默认词 redisWord := MC.ObjArrToStringArr(rData) aData := MC.If(req.UserId == "", IC.C.MobileIndexHotKeyUnLogin, IC.C.MobileIndexHotKey).([]string) if len(defaultWord)+len(redisWord) >= len(aData)-int(IC.C.MobileIndexHotKeyLimit) { //剩余热词已经不足 重新获取 rsData = util.FilterWord(aData, append(defaultWord, redisWord...), int(IC.C.MobileIndexHotKeyLimit)) redis.Put("newother", redisKey, rsData, 60*60) } else { rsData = util.FilterWord(aData, append(defaultWord, redisWord...), int(IC.C.MobileIndexHotKeyLimit)) redisWord = append(redisWord, rsData...) redis.Put("newother", redisKey, redisWord, 60*60) } } return &types.CommonResp{ Data: rsData, }, nil }