ABUserPartitionUtils.java 2.12 KB
package com.yoho.search.common.utils;

import com.yoho.search.common.SearchDynamicConfigService;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Component
public class ABUserPartitionUtils {

    private static final Logger logger = LoggerFactory.getLogger(ABUserPartitionUtils.class);

    @Autowired
    private SearchDynamicConfigService searchDynamicConfigService;

    public boolean isAUserComplete(int uid, String udid) {
        try {
            List<Integer> aStrategyUIds = searchDynamicConfigService.aStrategyUIds();
            if (aStrategyUIds.contains(uid)) {
                return true;
            }
            if (StringUtils.isBlank(udid)) {
                return false;
            }
            List<String> aStrategyUdIds = searchDynamicConfigService.aStrategyUdIds();
            if (aStrategyUdIds.contains(udid)) {
                return true;
            }
            int tail = Math.abs(udid.hashCode() % 1024);
            int aUserPercent = searchDynamicConfigService.partAUserPercent();
            int aUserFloor = 1024 * aUserPercent / 100;
            return tail < aUserFloor ? true : false;
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            return true;
        }
    }

    public boolean isAUserComplete(Map<String, String> paramMap) {
        int uid = MapUtils.getIntValue(paramMap, "uid", 0);
        String udid = MapUtils.getString(paramMap, "udid", "");
        return isAUserComplete(uid, udid);
    }

    public static void main(String[] args) {
//        System.out.println(isAUserComplete(13420925, "f6ec847d5ac7ce275992db526666e997eb39425a"));//A版本
//        System.out.println(isAUserComplete(13420925, "00bcfa1e5d7745ad8c4188929134da18f8485dbd"));//B版本
        int aUserFloor = 1024 * 49 / 100;
        System.out.println(aUserFloor);
    }

}