Authored by wangnan9279

列表返回视频 ufo详情页新推荐接口

... ... @@ -22,10 +22,23 @@ public class UfoRecommendListController {
@Autowired
private UfoProductListService ufoProductListService;
/**
* 详情页的商品推荐一(根据:名称、品类、品牌)
*/
@RequestMapping(method = RequestMethod.GET, value = "/ufo/recommendList")
@ResponseBody
public SearchApiResult recommendList(HttpServletRequest request) {
Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
return ufoProductListService.recommendList(paramMap);
}
/**
* 详情页的商品推荐二 (根据:系列、品牌)
*/
@RequestMapping(method = RequestMethod.GET, value = "/ufo/recommendBySeriesBrandList")
@ResponseBody
public SearchApiResult recommendBySeriesBrandList(HttpServletRequest request) {
Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
return ufoProductListService.recommendBySeriesBrandList(paramMap);
}
}
... ...
... ... @@ -104,6 +104,7 @@ public class ProductIndexBaseService {
productIndexIncludeFields.add(ProductIndexEsField.sellType);
productIndexIncludeFields.add(ProductIndexEsField.isUfo);
productIndexIncludeFields.add(ProductIndexEsField.hasVideo);
productIndexIncludeFields.add(ProductIndexEsField.videoUrl);
}
... ...
... ... @@ -46,6 +46,7 @@ public class UfoProductListService {
private static final String RETURN_LIST_NAME = "product_list";
private static final Integer RECOMMEND_LIMIT = 30;
private static final Integer RECOMMEND_BY_SERIES_BRAND_LIMIT = 30;
@SearchCacheAble(cacheName = "UFO_PRODUCT_LIST", cacheInMinute = CacheInMinute.Minute_UFO)
public SearchApiResult productList(Map<String, String> paramMap) {
... ... @@ -140,6 +141,47 @@ public class UfoProductListService {
}
}
@SearchCacheAble(cacheName = "UFO_RECOMMEND_BY_SERIES_BRAND_LIST", cacheInMinute = CacheInMinute.Minute_UFO)
public SearchApiResult recommendBySeriesBrandList(Map<String, String> paramMap) {
try {
Integer seriesId = MapUtils.getInteger(paramMap, "series");
Integer brandId = MapUtils.getInteger(paramMap, "brand");
Integer not_id = MapUtils.getInteger(paramMap, "not_id");
if (brandId == null || not_id == null) {
return new SearchApiResult().setCode(400).setMessage("参数不合法,缺少必传参数");
}
paramMap.put("viewNum", "100");
paramMap.put("order", "salesNum:desc");
//第一次查询 只过滤系列
if (seriesId != null) {
paramMap.remove("brand");
}
SearchApiResult searchApiResult = this.productList(paramMap);
if (searchApiResult.getData() == null) {
return new SearchApiResult().setData(null).setCode(500);
}
JSONObject dataMap = (JSONObject) searchApiResult.getData();
dataMap.remove("page_total");
dataMap.remove("page_size");
dataMap.remove("page");
List<Map<String, Object>> returnInfoList = (List<Map<String, Object>>) dataMap.get(RETURN_LIST_NAME);
Set<Integer> idList = new HashSet<>();
//如果数量不够 第二次查询 只过滤品牌
if (seriesId != null && returnInfoList.size() < RECOMMEND_BY_SERIES_BRAND_LIMIT) {
returnInfoList.stream().map(p -> MapUtils.getIntValue(p, "id")).forEach(id -> idList.add(id));
paramMap.remove("series");
paramMap.put("brand", brandId.toString());
this.addReturnInfoListForSeriesBrand(paramMap, idList, returnInfoList);
}
dataMap.put("total", returnInfoList.size());
return searchApiResult;
} catch (Exception e) {
logger.error(e.getMessage(), e);
return new SearchApiResult().setData(null).setCode(500);
}
}
private void addReturnInfoList(Map<String, String> paramMap, Set<Integer> idList, List<Map<String, Object>> returnInfoList) {
SearchApiResult searchApiResult = this.productList(paramMap);
if (searchApiResult.getData() == null) {
... ... @@ -163,5 +205,28 @@ public class UfoProductListService {
}
}
private void addReturnInfoListForSeriesBrand(Map<String, String> paramMap, Set<Integer> idList, List<Map<String, Object>> returnInfoList) {
SearchApiResult searchApiResult = this.productList(paramMap);
if (searchApiResult.getData() == null) {
return;
}
JSONObject dataMapSecond = (JSONObject) searchApiResult.getData();
List<Map<String, Object>> returnInfoListTemp = (List<Map<String, Object>>) dataMapSecond.get("product_list");
if (CollectionUtils.isEmpty(returnInfoListTemp)) {
return;
}
for (Map<String, Object> map : returnInfoListTemp) {
Integer id = MapUtils.getIntValue(map, "id");
if (idList.contains(id)) {
continue;
}
returnInfoList.add(map);
idList.add(id);
if (returnInfoList.size() >= RECOMMEND_BY_SERIES_BRAND_LIMIT) {
break;
}
}
}
}
... ...