RecallConfigService.java
6.48 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package com.yoho.search.recall.config;
import com.alibaba.fastjson.JSON;
import com.yoho.search.base.utils.CollectionUtils;
import com.yoho.search.core.personalized.models.SortBrand;
import com.yoho.search.recall.beans.strategy.SortBrandType;
import com.yoho.search.recall.beans.strategy.StrategyEnum;
import com.yoho.search.recall.models.personal.PagePersonalFactor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
@Service
public class RecallConfigService {
private static final Logger RECALL_LOGGE = LoggerFactory.getLogger("RECALL");
@Autowired
private RecallConfigProductService recallConfigProductService;
@Autowired
private RecallConfigCommonService recallConfigCommonService;
@Autowired
private RecallConfigSortBrandService recallConfigSortBrandService;
private static int legallValue(int value, int min, int max) {
value = Math.min(value, max);
value = Math.max(value, min);
return value;
}
/**
* 获取某些策略的召回数量
*
* @param pageId
* @param strategyEnum
* @return
*/
public int queryStrategyConfigSize(int pageId, StrategyEnum strategyEnum) {
String configKey = getStrategyConfigKey(strategyEnum);
int size = recallConfigCommonService.queryConfigSize(pageId, configKey, 0);
size = this.legallValue(size, 0, 100);
RECALL_LOGGE.info("queryStrategyConfigSize,pageId is [{}],strategyEnum is [{}],size is[{}]", pageId, strategyEnum.name(), size);
return size;
}
/**
* 获取某些策略的间隔
*
* @param pageId
* @param strategyEnum
* @return
*/
public int queryStrategyConfigInterval(int pageId, StrategyEnum strategyEnum) {
String configKey = getStrategyConfigKey(strategyEnum);
int interval = recallConfigCommonService.queryConfigInterval(pageId, configKey, 10);
interval = this.legallValue(interval, 2, 40);
RECALL_LOGGE.info("queryStrategyConfigInterval,pageId is [{}],strategyEnum is [{}],interval is[{}]", pageId, strategyEnum.name(), interval);
return interval;
}
private String getStrategyConfigKey(StrategyEnum strategyEnum) {
if (strategyEnum.equals(StrategyEnum.REC_SKN)) {
return RecallConfigConstants.REC_SKN;
}
if (strategyEnum.equals(StrategyEnum.RT_SIM_SKN)) {
return RecallConfigConstants.RT_SIM_SKN;
}
if (strategyEnum.equals(StrategyEnum.DIRECT_TRAIN)) {
return RecallConfigConstants.DIRECT_TRAIN;
}
if (strategyEnum.equals(StrategyEnum.NEW_SHOP)) {
return RecallConfigConstants.NEW_SHOP;
}
if (strategyEnum.equals(StrategyEnum.ADD_FLOW)) {
return RecallConfigConstants.ADD_FLOW;
}
return null;
}
/**
* 获取推荐的【品类*品牌】的数量
*
* @param pageId
* @return
*/
public int querySortBrandConfigCount(int pageId, SortBrandType sortBrandType, int defaultSize) {
String sortBrandConfigKey = this.getSortBrandConfigKey(sortBrandType);
int size = recallConfigCommonService.queryConfigSize(pageId, sortBrandConfigKey, defaultSize);
size = this.legallValue(size, 0, 30);
RECALL_LOGGE.info("querySortBrandConfigCount,pageId is [{}],sortBrandType is [{}],size is[{}]", pageId, sortBrandType.name(), size);
return size;
}
/**
* 获取【品类*品牌】下的的商品的召回数量
*
* @param pageId
* @param sortBrand
* @return
*/
public RecallSknCount queryRecallSknCount(int pageId, SortBrandType sortBrandType, SortBrand sortBrand) {
String sortBrandConfigKey = this.getSortBrandConfigKey(sortBrandType);
RecallSknCount recallSknCount = recallConfigProductService.queryRecallSknCount(pageId, sortBrandConfigKey, sortBrand);
if (recallSknCount == null) {
RECALL_LOGGE.info("queryRecallSknCount,pageId is [{}],sortBrandType is [{}],RecallSknCount is[{}]", pageId, sortBrandType.name(), "null");
return null;
}
recallSknCount.setNewShelve(this.legallValue(recallSknCount.getNewShelve(), 0, 20));
recallSknCount.setPromotion(this.legallValue(recallSknCount.getPromotion(), 0, 20));
recallSknCount.setCtrValue(this.legallValue(recallSknCount.getCtrValue(), 0, 20));
recallSknCount.setHeatValue(this.legallValue(recallSknCount.getHeatValue(), 0, 20));
recallSknCount.setReducePrice(this.legallValue(recallSknCount.getReducePrice(), 0, 20));
recallSknCount.setRandom(this.legallValue(recallSknCount.getRandom(), 0, 20));
RECALL_LOGGE.info("queryRecallSknCount,pageId is [{}],sortBrandType is [{}],RecallSknCount is[{}]", pageId, sortBrandType.name(), JSON.toJSONString(recallSknCount));
return recallSknCount;
}
private String getSortBrandConfigKey(SortBrandType sortBrandType) {
if (sortBrandType.equals(SortBrandType.REC_SORT_BRAND)) {
return RecallConfigConstants.REC_SORT_BRAND;
}
if (sortBrandType.equals(SortBrandType.VEC_RNN_SORT_BRAND)) {
return RecallConfigConstants.VEC_RNN_SORT_BRAND;
}
if (sortBrandType.equals(SortBrandType.VEC_W2V_SORT_BRAND)) {
return RecallConfigConstants.VEC_W2V_SORT_BRAND;
}
if (sortBrandType.equals(SortBrandType.CONFIG_SORT_BRAND)) {
return RecallConfigConstants.CONFIG_SORT_BRAND;
}
return null;
}
/**
* 随机获取configSortBrandCount数量
*
* @param pageFactor
* @param filterSortBrandKeys
* @param configSortBrandCount
* @return
*/
public List<SortBrand> queryConfigSortBrandList(PagePersonalFactor pageFactor, Set<String> filterSortBrandKeys, int configSortBrandCount) {
List<SortBrand> pageConfigSortBrands = recallConfigSortBrandService.queryConfigSortBrand(pageFactor, filterSortBrandKeys);
Collections.shuffle(pageConfigSortBrands);
return CollectionUtils.safeSubList(pageConfigSortBrands, 0, configSortBrandCount);
}
public static void main(String[] args) {
System.out.println(legallValue(-1, 0, 30));
}
}