UserRecallRequest.java 3.22 KB
package com.yoho.search.models.recall;

import com.alibaba.fastjson.JSON;
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
import com.yoho.search.base.utils.MD5Util;
import com.yoho.search.cache.CacheTimeConstants;
import com.yoho.search.cache.model.ICacheRequest;
import org.apache.commons.lang.StringUtils;

import java.util.List;

public class UserRecallRequest implements ICacheRequest {

    private final ParamQueryFilter paramQueryFilter;
    private final int pageSize;
    private final List<Integer> firstProductSkns;
    private final int uid;
    private final String udid;
    private int pageId;
    private RedisKeyBuilder redisKeyBuilder;
    private boolean defaultOrder;
    private boolean aUser;

    public UserRecallRequest(ParamQueryFilter paramQueryFilter, int pageSize, List<Integer> firstProductSkns, int uid, String udid, int pageId, boolean defaultOrder,boolean aUser) {
        this.paramQueryFilter = paramQueryFilter;
        this.firstProductSkns = firstProductSkns;
        this.pageSize = pageSize;
        this.uid = uid;
        this.udid = udid;
        this.pageId = pageId;
        this.defaultOrder = defaultOrder;
        this.redisKeyBuilder = genRedisKeyBuilder();
        this.aUser = aUser;
    }

    public boolean hasUidOrUdid() {
        return uid > 0 || StringUtils.isNotBlank(udid);
    }

    public boolean openDetailLog() {
        if (this.uid == 9963947) {
            return true;
        }
        if ("f6ec847d5ac7ce275992db526666e997eb39425a".equalsIgnoreCase(this.udid)) {
            return true;
        }
        return false;
    }

    @Override
    public RedisKeyBuilder redisKeyBuilder() {
        return this.redisKeyBuilder;
    }

    private RedisKeyBuilder genRedisKeyBuilder() {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(paramQueryFilter == null ? "" : paramQueryFilter.getParamMd5Key());
        stringBuilder.append(pageSize);
        stringBuilder.append(firstProductSkns == null ? "" : JSON.toJSON(firstProductSkns));
        stringBuilder.append(uid);
        stringBuilder.append(udid == null ? "" : udid);
        stringBuilder.append(pageId);
        stringBuilder.append(defaultOrder);
        stringBuilder.append(aUser);
        String value = MD5Util.string2MD5(stringBuilder.toString());
        return RedisKeyBuilder.newInstance().appendFixed("YOHOSEARCH:").appendFixed("USER_RECALL_SKN_LIST:").appendVar(cacheTimeInMinute()).appendFixed(":").appendVar(value);
    }

    @Override
    public int cacheTimeInMinute() {
        return CacheTimeConstants.USER_RECALL_SKN_LIST;
    }

    public ParamQueryFilter getParamQueryFilter() {
        return paramQueryFilter;
    }

    public int getPageSize() {
        return pageSize;
    }

    public int getUid() {
        return uid;
    }

    public String getUdid() {
        return udid;
    }

    public List<Integer> getFirstProductSkns() {
        return firstProductSkns;
    }

    public int getPageId() {
        return pageId;
    }

    public boolean isDefaultOrder() {
        return defaultOrder;
    }

    public boolean isAUser() {
        return aUser;
    }
}