Merge branch 'recommendbrand' into udid
Showing
2 changed files
with
57 additions
and
1 deletions
service/src/main/java/com/yoho/search/recall/scene/beans/persional/UserPersionalFactorComponent.java
@@ -19,7 +19,7 @@ import java.util.Collections; | @@ -19,7 +19,7 @@ import java.util.Collections; | ||
19 | import java.util.List; | 19 | import java.util.List; |
20 | 20 | ||
21 | @Component | 21 | @Component |
22 | -class UserPersionalFactorComponent { | 22 | +public class UserPersionalFactorComponent { |
23 | 23 | ||
24 | @Autowired | 24 | @Autowired |
25 | private SearchDynamicConfigService searchDynamicConfigService; | 25 | private SearchDynamicConfigService searchDynamicConfigService; |
@@ -62,7 +62,14 @@ class UserPersionalFactorComponent { | @@ -62,7 +62,14 @@ class UserPersionalFactorComponent { | ||
62 | } | 62 | } |
63 | } | 63 | } |
64 | 64 | ||
65 | + public UserPersonalFactorRspNew queryUserPersionalFactor(int uid, String udid) { | ||
66 | + return queryUserPersionalFactor(uid, udid, null); | ||
67 | + } | ||
68 | + | ||
65 | private UserPersonalFactorRspNew getDefaultUserPersonalFactorRsp(PagePersonalFactor pageFactor) { | 69 | private UserPersonalFactorRspNew getDefaultUserPersonalFactorRsp(PagePersonalFactor pageFactor) { |
70 | + if (pageFactor == null) { | ||
71 | + return new UserPersonalFactorRspNew(new ArrayList<>(), new ArrayList<>(), ""); | ||
72 | + } | ||
66 | //1、构造sortBrandList | 73 | //1、构造sortBrandList |
67 | List<SortBrand> sortBrandList = new ArrayList<>(); | 74 | List<SortBrand> sortBrandList = new ArrayList<>(); |
68 | List<PageBrandSorts> pageBrandSortsList = pageFactor.getBrandSortsList(); | 75 | List<PageBrandSorts> pageBrandSortsList = pageFactor.getBrandSortsList(); |
service/src/main/java/com/yoho/search/service/scene/common/SceneRecommendBrandsService.java
0 → 100644
1 | +package com.yoho.search.service.scene.common; | ||
2 | + | ||
3 | +import com.alibaba.fastjson.JSON; | ||
4 | +import com.alibaba.fastjson.JSONArray; | ||
5 | +import com.alibaba.fastjson.TypeReference; | ||
6 | +import com.yoho.search.core.personalized.models.SortBrand; | ||
7 | +import com.yoho.search.core.personalized.models.UserPersonalFactorRspNew; | ||
8 | +import com.yoho.search.service.base.SearchRequestParams; | ||
9 | +import org.apache.commons.collections.MapUtils; | ||
10 | +import org.springframework.beans.factory.annotation.Autowired; | ||
11 | +import com.yoho.search.recall.scene.beans.persional.UserPersionalFactorComponent; | ||
12 | +import org.springframework.stereotype.Service; | ||
13 | + | ||
14 | +import java.util.ArrayList; | ||
15 | +import java.util.HashMap; | ||
16 | +import java.util.Map; | ||
17 | +import java.util.List; | ||
18 | +import java.util.function.Function; | ||
19 | +import java.util.stream.Collectors; | ||
20 | + | ||
21 | +@Service | ||
22 | +public class SceneRecommendBrandsService { | ||
23 | + | ||
24 | + @Autowired | ||
25 | + private UserPersionalFactorComponent userPersionalFactorComponent; | ||
26 | + | ||
27 | + public JSONArray getRecommendBrands(Map<String, String> paramMap, JSONArray brandList) { | ||
28 | + List<HashMap<String, String>> brandListTemp = JSON.parseObject(brandList.toJSONString(), new TypeReference<List<HashMap<String, String>>>() {}); | ||
29 | + Map<String, HashMap<String, String>> brandIdMap = brandListTemp.stream().collect(Collectors.toMap(e -> e.get("id"), Function.identity(), (m1, m2) -> m2)); | ||
30 | + | ||
31 | + int uid = MapUtils.getIntValue(paramMap, "uid", 0); | ||
32 | + String udid = MapUtils.getString(paramMap, "udid", ""); | ||
33 | + int recommendBrandCount = Integer.parseInt(paramMap.getOrDefault(SearchRequestParams.PARAM_SEARCH_VIEWNUM, "8")); | ||
34 | + UserPersonalFactorRspNew userFactor = userPersionalFactorComponent.queryUserPersionalFactor(uid, udid); | ||
35 | + JSONArray recBrands = new JSONArray(recommendBrandCount); | ||
36 | + List<SortBrand> sortBrandList = new ArrayList<>(userFactor.getRealTimeSortBrandList()); | ||
37 | + sortBrandList.addAll(userFactor.getSortBrandList()); | ||
38 | + for (SortBrand sortBrand : sortBrandList) { | ||
39 | + if (recBrands.size() >= recommendBrandCount) { | ||
40 | + break; | ||
41 | + } | ||
42 | + Map<String, String> brand = brandIdMap.get(String.valueOf(sortBrand.getBrandId())); | ||
43 | + if (brand != null) { | ||
44 | + recBrands.add(brand); | ||
45 | + } | ||
46 | + } | ||
47 | + return recBrands; | ||
48 | + } | ||
49 | +} |
-
Please register or login to post a comment