ABUserPartitionUtils.java
2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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);
}
}