Authored by wangnan9279

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

@@ -22,10 +22,23 @@ public class UfoRecommendListController { @@ -22,10 +22,23 @@ public class UfoRecommendListController {
22 @Autowired 22 @Autowired
23 private UfoProductListService ufoProductListService; 23 private UfoProductListService ufoProductListService;
24 24
  25 + /**
  26 + * 详情页的商品推荐一(根据:名称、品类、品牌)
  27 + */
25 @RequestMapping(method = RequestMethod.GET, value = "/ufo/recommendList") 28 @RequestMapping(method = RequestMethod.GET, value = "/ufo/recommendList")
26 @ResponseBody 29 @ResponseBody
27 public SearchApiResult recommendList(HttpServletRequest request) { 30 public SearchApiResult recommendList(HttpServletRequest request) {
28 Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request); 31 Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
29 return ufoProductListService.recommendList(paramMap); 32 return ufoProductListService.recommendList(paramMap);
30 } 33 }
  34 +
  35 + /**
  36 + * 详情页的商品推荐二 (根据:系列、品牌)
  37 + */
  38 + @RequestMapping(method = RequestMethod.GET, value = "/ufo/recommendBySeriesBrandList")
  39 + @ResponseBody
  40 + public SearchApiResult recommendBySeriesBrandList(HttpServletRequest request) {
  41 + Map<String, String> paramMap = HttpServletRequestUtils.transParamType(request);
  42 + return ufoProductListService.recommendBySeriesBrandList(paramMap);
  43 + }
31 } 44 }
@@ -104,6 +104,7 @@ public class ProductIndexBaseService { @@ -104,6 +104,7 @@ public class ProductIndexBaseService {
104 productIndexIncludeFields.add(ProductIndexEsField.sellType); 104 productIndexIncludeFields.add(ProductIndexEsField.sellType);
105 productIndexIncludeFields.add(ProductIndexEsField.isUfo); 105 productIndexIncludeFields.add(ProductIndexEsField.isUfo);
106 productIndexIncludeFields.add(ProductIndexEsField.hasVideo); 106 productIndexIncludeFields.add(ProductIndexEsField.hasVideo);
  107 + productIndexIncludeFields.add(ProductIndexEsField.videoUrl);
107 108
108 } 109 }
109 110
@@ -46,6 +46,7 @@ public class UfoProductListService { @@ -46,6 +46,7 @@ public class UfoProductListService {
46 46
47 private static final String RETURN_LIST_NAME = "product_list"; 47 private static final String RETURN_LIST_NAME = "product_list";
48 private static final Integer RECOMMEND_LIMIT = 30; 48 private static final Integer RECOMMEND_LIMIT = 30;
  49 + private static final Integer RECOMMEND_BY_SERIES_BRAND_LIMIT = 30;
49 50
50 @SearchCacheAble(cacheName = "UFO_PRODUCT_LIST", cacheInMinute = CacheInMinute.Minute_UFO) 51 @SearchCacheAble(cacheName = "UFO_PRODUCT_LIST", cacheInMinute = CacheInMinute.Minute_UFO)
51 public SearchApiResult productList(Map<String, String> paramMap) { 52 public SearchApiResult productList(Map<String, String> paramMap) {
@@ -140,6 +141,47 @@ public class UfoProductListService { @@ -140,6 +141,47 @@ public class UfoProductListService {
140 } 141 }
141 } 142 }
142 143
  144 + @SearchCacheAble(cacheName = "UFO_RECOMMEND_BY_SERIES_BRAND_LIST", cacheInMinute = CacheInMinute.Minute_UFO)
  145 + public SearchApiResult recommendBySeriesBrandList(Map<String, String> paramMap) {
  146 + try {
  147 + Integer seriesId = MapUtils.getInteger(paramMap, "series");
  148 + Integer brandId = MapUtils.getInteger(paramMap, "brand");
  149 + Integer not_id = MapUtils.getInteger(paramMap, "not_id");
  150 + if (brandId == null || not_id == null) {
  151 + return new SearchApiResult().setCode(400).setMessage("参数不合法,缺少必传参数");
  152 + }
  153 + paramMap.put("viewNum", "100");
  154 + paramMap.put("order", "salesNum:desc");
  155 + //第一次查询 只过滤系列
  156 + if (seriesId != null) {
  157 + paramMap.remove("brand");
  158 + }
  159 + SearchApiResult searchApiResult = this.productList(paramMap);
  160 + if (searchApiResult.getData() == null) {
  161 + return new SearchApiResult().setData(null).setCode(500);
  162 + }
  163 + JSONObject dataMap = (JSONObject) searchApiResult.getData();
  164 + dataMap.remove("page_total");
  165 + dataMap.remove("page_size");
  166 + dataMap.remove("page");
  167 + List<Map<String, Object>> returnInfoList = (List<Map<String, Object>>) dataMap.get(RETURN_LIST_NAME);
  168 + Set<Integer> idList = new HashSet<>();
  169 + //如果数量不够 第二次查询 只过滤品牌
  170 + if (seriesId != null && returnInfoList.size() < RECOMMEND_BY_SERIES_BRAND_LIMIT) {
  171 + returnInfoList.stream().map(p -> MapUtils.getIntValue(p, "id")).forEach(id -> idList.add(id));
  172 + paramMap.remove("series");
  173 + paramMap.put("brand", brandId.toString());
  174 + this.addReturnInfoListForSeriesBrand(paramMap, idList, returnInfoList);
  175 + }
  176 + dataMap.put("total", returnInfoList.size());
  177 + return searchApiResult;
  178 + } catch (Exception e) {
  179 + logger.error(e.getMessage(), e);
  180 + return new SearchApiResult().setData(null).setCode(500);
  181 + }
  182 + }
  183 +
  184 +
143 private void addReturnInfoList(Map<String, String> paramMap, Set<Integer> idList, List<Map<String, Object>> returnInfoList) { 185 private void addReturnInfoList(Map<String, String> paramMap, Set<Integer> idList, List<Map<String, Object>> returnInfoList) {
144 SearchApiResult searchApiResult = this.productList(paramMap); 186 SearchApiResult searchApiResult = this.productList(paramMap);
145 if (searchApiResult.getData() == null) { 187 if (searchApiResult.getData() == null) {
@@ -163,5 +205,28 @@ public class UfoProductListService { @@ -163,5 +205,28 @@ public class UfoProductListService {
163 } 205 }
164 } 206 }
165 207
  208 + private void addReturnInfoListForSeriesBrand(Map<String, String> paramMap, Set<Integer> idList, List<Map<String, Object>> returnInfoList) {
  209 + SearchApiResult searchApiResult = this.productList(paramMap);
  210 + if (searchApiResult.getData() == null) {
  211 + return;
  212 + }
  213 + JSONObject dataMapSecond = (JSONObject) searchApiResult.getData();
  214 + List<Map<String, Object>> returnInfoListTemp = (List<Map<String, Object>>) dataMapSecond.get("product_list");
  215 + if (CollectionUtils.isEmpty(returnInfoListTemp)) {
  216 + return;
  217 + }
  218 + for (Map<String, Object> map : returnInfoListTemp) {
  219 + Integer id = MapUtils.getIntValue(map, "id");
  220 + if (idList.contains(id)) {
  221 + continue;
  222 + }
  223 + returnInfoList.add(map);
  224 + idList.add(id);
  225 + if (returnInfoList.size() >= RECOMMEND_BY_SERIES_BRAND_LIMIT) {
  226 + break;
  227 + }
  228 + }
  229 + }
  230 +
166 231
167 } 232 }