|
|
package com.yoho.search.service.scene.common;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.TypeReference;
|
|
|
import com.yoho.search.core.personalized.models.SortBrand;
|
|
|
import com.yoho.search.core.personalized.models.UserPersonalFactorRspNew;
|
|
|
import com.yoho.search.service.base.SearchRequestParams;
|
|
|
import org.apache.commons.collections.MapUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import com.yoho.search.recall.scene.beans.persional.UserPersionalFactorComponent;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
import java.util.List;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
public class SceneRecommendBrandsService {
|
|
|
|
|
|
@Autowired
|
|
|
private UserPersionalFactorComponent userPersionalFactorComponent;
|
|
|
|
|
|
public JSONArray getRecommendBrands(Map<String, String> paramMap, JSONArray brandList) {
|
|
|
List<HashMap<String, String>> brandListTemp = JSON.parseObject(brandList.toJSONString(), new TypeReference<List<HashMap<String, String>>>() {});
|
|
|
Map<String, HashMap<String, String>> brandIdMap = brandListTemp.stream().collect(Collectors.toMap(e -> e.get("id"), Function.identity(), (m1, m2) -> m2));
|
|
|
|
|
|
int uid = MapUtils.getIntValue(paramMap, "uid", 0);
|
|
|
String udid = MapUtils.getString(paramMap, "udid", "");
|
|
|
int recommendBrandCount = Integer.parseInt(paramMap.getOrDefault(SearchRequestParams.PARAM_SEARCH_VIEWNUM, "8"));
|
|
|
UserPersonalFactorRspNew userFactor = userPersionalFactorComponent.queryUserPersionalFactor(uid, udid);
|
|
|
JSONArray recBrands = new JSONArray(recommendBrandCount);
|
|
|
List<SortBrand> sortBrandList = new ArrayList<>(userFactor.getRealTimeSortBrandList());
|
|
|
sortBrandList.addAll(userFactor.getSortBrandList());
|
|
|
for (SortBrand sortBrand : sortBrandList) {
|
|
|
if (recBrands.size() >= recommendBrandCount) {
|
|
|
break;
|
|
|
}
|
|
|
Map<String, String> brand = brandIdMap.get(String.valueOf(sortBrand.getBrandId()));
|
|
|
if (brand != null) {
|
|
|
recBrands.add(brand);
|
|
|
}
|
|
|
}
|
|
|
return recBrands;
|
|
|
}
|
|
|
} |
...
|
...
|
|