Authored by iknitting

主题精选

@@ -163,6 +163,10 @@ public class CsSearchResourceIndexBaseService { @@ -163,6 +163,10 @@ public class CsSearchResourceIndexBaseService {
163 map.put("image", image); 163 map.put("image", image);
164 map.put("categoryIds", MapUtils.getString(esMap, "categoryIds", "")); 164 map.put("categoryIds", MapUtils.getString(esMap, "categoryIds", ""));
165 map.put("resourceType", MapUtils.getIntValue(esMap, "resourceType", 0)); 165 map.put("resourceType", MapUtils.getIntValue(esMap, "resourceType", 0));
  166 + // 6.9.21版本新增主题精选
  167 + map.put("banner_type", MapUtils.getIntValue(esMap, "banner_type", 1)); // 默认1-直通车;2-主题精选
  168 + map.put("theme", MapUtils.getString(esMap, "theme", ""));
  169 + map.put("skn", MapUtils.getString(esMap, "skn", ""));
166 return map; 170 return map;
167 } 171 }
168 172
1 package com.yoho.search.service.scene.general; 1 package com.yoho.search.service.scene.general;
2 2
3 import com.alibaba.fastjson.JSONObject; 3 import com.alibaba.fastjson.JSONObject;
  4 +import com.google.common.collect.Lists;
4 import com.yoho.search.base.utils.SearchConvertUtils; 5 import com.yoho.search.base.utils.SearchConvertUtils;
5 import com.yoho.search.base.utils.SearchCollectionUtils; 6 import com.yoho.search.base.utils.SearchCollectionUtils;
6 import com.yoho.search.common.SearchDynamicConfigService; 7 import com.yoho.search.common.SearchDynamicConfigService;
7 import com.yoho.search.common.SearchRequestParams; 8 import com.yoho.search.common.SearchRequestParams;
8 import com.yoho.search.common.utils.ABUserPartitionUtils; 9 import com.yoho.search.common.utils.ABUserPartitionUtils;
  10 +import com.yoho.search.service.base.SknReturnInfoBaseService;
9 import com.yoho.search.service.helper.SearchCommonHelper; 11 import com.yoho.search.service.helper.SearchCommonHelper;
10 import com.yoho.search.service.index.CsSearchResourceFuzzyIndexBaseService; 12 import com.yoho.search.service.index.CsSearchResourceFuzzyIndexBaseService;
11 import com.yoho.search.service.index.CsSearchResourceIndexBaseService; 13 import com.yoho.search.service.index.CsSearchResourceIndexBaseService;
  14 +import org.apache.commons.collections.CollectionUtils;
12 import org.apache.commons.collections.MapUtils; 15 import org.apache.commons.collections.MapUtils;
  16 +import org.apache.commons.lang3.StringUtils;
13 import org.slf4j.Logger; 17 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory; 18 import org.slf4j.LoggerFactory;
15 import org.springframework.beans.factory.annotation.Autowired; 19 import org.springframework.beans.factory.annotation.Autowired;
16 import org.springframework.stereotype.Component; 20 import org.springframework.stereotype.Component;
17 -import org.springframework.util.CollectionUtils;  
18 21
19 import java.util.ArrayList; 22 import java.util.ArrayList;
20 import java.util.HashMap; 23 import java.util.HashMap;
@@ -31,7 +34,8 @@ public class CsSearchResourceService { @@ -31,7 +34,8 @@ public class CsSearchResourceService {
31 private CsSearchResourceIndexBaseService csSearchResourceIndexBaseService; 34 private CsSearchResourceIndexBaseService csSearchResourceIndexBaseService;
32 @Autowired 35 @Autowired
33 private CsSearchResourceFuzzyIndexBaseService searchResourceFuzzyIndexBaseService; 36 private CsSearchResourceFuzzyIndexBaseService searchResourceFuzzyIndexBaseService;
34 - 37 + @Autowired
  38 + private SknReturnInfoBaseService sknReturnInfoBaseService;
35 @Autowired 39 @Autowired
36 private SearchCommonHelper searchCommonHelper; 40 private SearchCommonHelper searchCommonHelper;
37 @Autowired 41 @Autowired
@@ -65,7 +69,7 @@ public class CsSearchResourceService { @@ -65,7 +69,7 @@ public class CsSearchResourceService {
65 return resourceType == 2 || (salesCategoryId != null && categoryIdList.contains(salesCategoryId)); 69 return resourceType == 2 || (salesCategoryId != null && categoryIdList.contains(salesCategoryId));
66 }).collect(Collectors.toList()); 70 }).collect(Collectors.toList());
67 71
68 - //4、分页截取 72 + //5、分页截取
69 int page = MapUtils.getIntValue(paramMap, "page", 1); 73 int page = MapUtils.getIntValue(paramMap, "page", 1);
70 int pageSize = MapUtils.getIntValue(paramMap, "viewNum", 10); 74 int pageSize = MapUtils.getIntValue(paramMap, "viewNum", 10);
71 List productList = productListData.getJSONArray("product_list"); 75 List productList = productListData.getJSONArray("product_list");
@@ -116,7 +120,6 @@ public class CsSearchResourceService { @@ -116,7 +120,6 @@ public class CsSearchResourceService {
116 } 120 }
117 } 121 }
118 122
119 -  
120 //处理UFO首页的资源位直通车 123 //处理UFO首页的资源位直通车
121 public List<Map<String, Object>> queryUfoCsSearchResource(JSONObject productListData, int page, int viewNum) { 124 public List<Map<String, Object>> queryUfoCsSearchResource(JSONObject productListData, int page, int viewNum) {
122 try { 125 try {
@@ -143,6 +146,8 @@ public class CsSearchResourceService { @@ -143,6 +146,8 @@ public class CsSearchResourceService {
143 if (CollectionUtils.isEmpty(subResourceList)) { 146 if (CollectionUtils.isEmpty(subResourceList)) {
144 return new ArrayList<>(); 147 return new ArrayList<>();
145 } 148 }
  149 + //处理主题精选类型 6.9.21版本新增
  150 + buildThemeResourceType(subResourceList);
146 int[] index = new int[countPerSize]; 151 int[] index = new int[countPerSize];
147 index[0] = viewNum * 1 / 4; 152 index[0] = viewNum * 1 / 4;
148 index[1] = viewNum * 3 / 4; 153 index[1] = viewNum * 3 / 4;
@@ -161,4 +166,82 @@ public class CsSearchResourceService { @@ -161,4 +166,82 @@ public class CsSearchResourceService {
161 return searchResourceFuzzyIndexBaseService.queryFuzzySearchResourcesByKeyWord(keyword, contain_xixuan); 166 return searchResourceFuzzyIndexBaseService.queryFuzzySearchResourcesByKeyWord(keyword, contain_xixuan);
162 } 167 }
163 168
  169 + // 处理主题精选类型,配置的skn列表中找出一个有效的skn,取出图片,设置firstProductSkn
  170 + private void buildThemeResourceType(List<Map<String, Object>> validResources) {
  171 + // 取出配置的所有skn
  172 + List<Integer> allSknList = getAllSknList(validResources);
  173 + if (CollectionUtils.isEmpty(allSknList)) {
  174 + return;
  175 + }
  176 + // 查询商品索引信息
  177 + List<Map<String, Object>> sknReturnInfoList = sknReturnInfoBaseService.queryProductListBySkn(allSknList, allSknList.size());
  178 + if (CollectionUtils.isEmpty(sknReturnInfoList)) {
  179 + return;
  180 + }
  181 + // 构造skn map
  182 + Map<Integer, Map<String, Object>> sknReturnInfoMap = buildSknReturnInfoMap(sknReturnInfoList);
  183 + // 构建最终的主体精选resource
  184 + buildFianlThemeResource(validResources, sknReturnInfoMap);
  185 + }
  186 +
  187 + private void buildFianlThemeResource(List<Map<String, Object>> validResources, Map<Integer, Map<String, Object>> sknReturnInfoMap) {
  188 + if (CollectionUtils.isEmpty(validResources) || sknReturnInfoMap.isEmpty()) {
  189 + return;
  190 + }
  191 + for (Map<String, Object> resource : validResources) {
  192 + int bannerType = MapUtils.getIntValue(resource, "bannerType", 1); // 默认1-直通车;2-主题精选
  193 + if (bannerType == 2) {
  194 + // 取出默认图、firstProductSkn
  195 + List<Integer> sknList = SearchConvertUtils.stringToIntList(MapUtils.getString(resource, "skn", ""), ",");
  196 + Map<String, Object> product;
  197 + for (Integer productSkn : sknList) {
  198 + product = sknReturnInfoMap.get(productSkn);
  199 + if (product == null) {
  200 + continue;
  201 + }
  202 + String productGender = MapUtils.getString(product, "gender", "3");
  203 + String cover_1 = MapUtils.getString(product, "cover_1", "");
  204 + String cover_2 = MapUtils.getString(product, "cover_2", "");
  205 + String default_images = MapUtils.getString(product, "default_images", "");
  206 + default_images = getDefaultImages(cover_1, cover_2, default_images, productGender);
  207 + resource.replace("image", default_images);
  208 + resource.put("firstProductSkn", productSkn);
  209 + break;
  210 + }
  211 + }
  212 + }
  213 + }
  214 +
  215 + private List<Integer> getAllSknList(List<Map<String, Object>> validResources) {
  216 + List<Integer> sknList = Lists.newArrayList();
  217 + for (Map<String, Object> resource : validResources) {
  218 + int bannerType = MapUtils.getIntValue(resource, "bannerType", 1); // 默认1-直通车;2-主题精选
  219 + if (bannerType == 2) {
  220 + sknList.addAll(SearchConvertUtils.stringToIntList(MapUtils.getString(resource, "skn", ""), ","));
  221 + }
  222 + }
  223 + return sknList;
  224 + }
  225 +
  226 + private Map<Integer, Map<String, Object>> buildSknReturnInfoMap(List<Map<String, Object>> sknReturnInfoList) {
  227 + Map<Integer, Map<String, Object>> result = new HashMap<>();
  228 + for (Map<String, Object> sknReturnInfo : sknReturnInfoList) {
  229 + Integer productSkn = MapUtils.getIntValue(sknReturnInfo, "productSkn", 0);
  230 + if (result.containsKey(productSkn)) {
  231 + continue;
  232 + }
  233 + result.put(productSkn, sknReturnInfo);
  234 + }
  235 + return result;
  236 + }
  237 +
  238 + private static String getDefaultImages(String cover_1, String cover_2, String default_images, String productGender) {
  239 + if (("1".equals(productGender) && (StringUtils.isNotBlank(cover_1)))) {
  240 + return cover_1;
  241 + }
  242 + if (("2".equals(productGender) && (StringUtils.isNotBlank(cover_2)))) {
  243 + return cover_2;
  244 + }
  245 + return default_images;
  246 + }
164 } 247 }