|
|
package com.yoho.search.service.scene.general;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.yoho.search.base.utils.SearchConvertUtils;
|
|
|
import com.yoho.search.base.utils.SearchCollectionUtils;
|
|
|
import com.yoho.search.common.SearchDynamicConfigService;
|
|
|
import com.yoho.search.common.SearchRequestParams;
|
|
|
import com.yoho.search.common.utils.ABUserPartitionUtils;
|
|
|
import com.yoho.search.service.base.SknReturnInfoBaseService;
|
|
|
import com.yoho.search.service.helper.SearchCommonHelper;
|
|
|
import com.yoho.search.service.index.CsSearchResourceFuzzyIndexBaseService;
|
|
|
import com.yoho.search.service.index.CsSearchResourceIndexBaseService;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.collections.MapUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
...
|
...
|
@@ -31,7 +34,8 @@ public class CsSearchResourceService { |
|
|
private CsSearchResourceIndexBaseService csSearchResourceIndexBaseService;
|
|
|
@Autowired
|
|
|
private CsSearchResourceFuzzyIndexBaseService searchResourceFuzzyIndexBaseService;
|
|
|
|
|
|
@Autowired
|
|
|
private SknReturnInfoBaseService sknReturnInfoBaseService;
|
|
|
@Autowired
|
|
|
private SearchCommonHelper searchCommonHelper;
|
|
|
@Autowired
|
...
|
...
|
@@ -65,7 +69,7 @@ public class CsSearchResourceService { |
|
|
return resourceType == 2 || (salesCategoryId != null && categoryIdList.contains(salesCategoryId));
|
|
|
}).collect(Collectors.toList());
|
|
|
|
|
|
//4、分页截取
|
|
|
//5、分页截取
|
|
|
int page = MapUtils.getIntValue(paramMap, "page", 1);
|
|
|
int pageSize = MapUtils.getIntValue(paramMap, "viewNum", 10);
|
|
|
List productList = productListData.getJSONArray("product_list");
|
...
|
...
|
@@ -116,7 +120,6 @@ public class CsSearchResourceService { |
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
//处理UFO首页的资源位直通车
|
|
|
public List<Map<String, Object>> queryUfoCsSearchResource(JSONObject productListData, int page, int viewNum) {
|
|
|
try {
|
...
|
...
|
@@ -143,6 +146,8 @@ public class CsSearchResourceService { |
|
|
if (CollectionUtils.isEmpty(subResourceList)) {
|
|
|
return new ArrayList<>();
|
|
|
}
|
|
|
//处理主题精选类型 6.9.21版本新增
|
|
|
buildThemeResourceType(subResourceList);
|
|
|
int[] index = new int[countPerSize];
|
|
|
index[0] = viewNum * 1 / 4;
|
|
|
index[1] = viewNum * 3 / 4;
|
...
|
...
|
@@ -161,4 +166,82 @@ public class CsSearchResourceService { |
|
|
return searchResourceFuzzyIndexBaseService.queryFuzzySearchResourcesByKeyWord(keyword, contain_xixuan);
|
|
|
}
|
|
|
|
|
|
// 处理主题精选类型,配置的skn列表中找出一个有效的skn,取出图片,设置firstProductSkn
|
|
|
private void buildThemeResourceType(List<Map<String, Object>> validResources) {
|
|
|
// 取出配置的所有skn
|
|
|
List<Integer> allSknList = getAllSknList(validResources);
|
|
|
if (CollectionUtils.isEmpty(allSknList)) {
|
|
|
return;
|
|
|
}
|
|
|
// 查询商品索引信息
|
|
|
List<Map<String, Object>> sknReturnInfoList = sknReturnInfoBaseService.queryProductListBySkn(allSknList, allSknList.size());
|
|
|
if (CollectionUtils.isEmpty(sknReturnInfoList)) {
|
|
|
return;
|
|
|
}
|
|
|
// 构造skn map
|
|
|
Map<Integer, Map<String, Object>> sknReturnInfoMap = buildSknReturnInfoMap(sknReturnInfoList);
|
|
|
// 构建最终的主体精选resource
|
|
|
buildFianlThemeResource(validResources, sknReturnInfoMap);
|
|
|
}
|
|
|
|
|
|
private void buildFianlThemeResource(List<Map<String, Object>> validResources, Map<Integer, Map<String, Object>> sknReturnInfoMap) {
|
|
|
if (CollectionUtils.isEmpty(validResources) || sknReturnInfoMap.isEmpty()) {
|
|
|
return;
|
|
|
}
|
|
|
for (Map<String, Object> resource : validResources) {
|
|
|
int bannerType = MapUtils.getIntValue(resource, "bannerType", 1); // 默认1-直通车;2-主题精选
|
|
|
if (bannerType == 2) {
|
|
|
// 取出默认图、firstProductSkn
|
|
|
List<Integer> sknList = SearchConvertUtils.stringToIntList(MapUtils.getString(resource, "skn", ""), ",");
|
|
|
Map<String, Object> product;
|
|
|
for (Integer productSkn : sknList) {
|
|
|
product = sknReturnInfoMap.get(productSkn);
|
|
|
if (product == null) {
|
|
|
continue;
|
|
|
}
|
|
|
String productGender = MapUtils.getString(product, "gender", "3");
|
|
|
String cover_1 = MapUtils.getString(product, "cover_1", "");
|
|
|
String cover_2 = MapUtils.getString(product, "cover_2", "");
|
|
|
String default_images = MapUtils.getString(product, "default_images", "");
|
|
|
default_images = getDefaultImages(cover_1, cover_2, default_images, productGender);
|
|
|
resource.replace("image", default_images);
|
|
|
resource.put("firstProductSkn", productSkn);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private List<Integer> getAllSknList(List<Map<String, Object>> validResources) {
|
|
|
List<Integer> sknList = Lists.newArrayList();
|
|
|
for (Map<String, Object> resource : validResources) {
|
|
|
int bannerType = MapUtils.getIntValue(resource, "bannerType", 1); // 默认1-直通车;2-主题精选
|
|
|
if (bannerType == 2) {
|
|
|
sknList.addAll(SearchConvertUtils.stringToIntList(MapUtils.getString(resource, "skn", ""), ","));
|
|
|
}
|
|
|
}
|
|
|
return sknList;
|
|
|
}
|
|
|
|
|
|
private Map<Integer, Map<String, Object>> buildSknReturnInfoMap(List<Map<String, Object>> sknReturnInfoList) {
|
|
|
Map<Integer, Map<String, Object>> result = new HashMap<>();
|
|
|
for (Map<String, Object> sknReturnInfo : sknReturnInfoList) {
|
|
|
Integer productSkn = MapUtils.getIntValue(sknReturnInfo, "productSkn", 0);
|
|
|
if (result.containsKey(productSkn)) {
|
|
|
continue;
|
|
|
}
|
|
|
result.put(productSkn, sknReturnInfo);
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
private static String getDefaultImages(String cover_1, String cover_2, String default_images, String productGender) {
|
|
|
if (("1".equals(productGender) && (StringUtils.isNotBlank(cover_1)))) {
|
|
|
return cover_1;
|
|
|
}
|
|
|
if (("2".equals(productGender) && (StringUtils.isNotBlank(cover_2)))) {
|
|
|
return cover_2;
|
|
|
}
|
|
|
return default_images;
|
|
|
}
|
|
|
} |
...
|
...
|
|