Authored by wangnan9279

ufo推荐接口,加个try catch

... ... @@ -102,38 +102,43 @@ public class UfoProductListService {
@SearchCacheAble(cacheName = "UFO_RECOMMEND_LIST", cacheInMinute = 10)
public SearchApiResult recommendList(Map<String, String> paramMap) {
String query = MapUtils.getString(paramMap, "query");
Integer brandId = MapUtils.getInteger(paramMap, "brand");
Integer midSortId = MapUtils.getInteger(paramMap, "midSort");
Integer not_id = MapUtils.getInteger(paramMap, "not_id");
if (StringUtils.isBlank(query) || brandId == null || midSortId == null || not_id == null) {
return new SearchApiResult().setCode(400).setMessage("参数不合法,缺少必传参数");
}
//第一次查询
paramMap.put("viewNum", "100");
SearchApiResult searchApiResult = this.productList(paramMap);
if (searchApiResult.getData() == null) {
try {
String query = MapUtils.getString(paramMap, "query");
Integer brandId = MapUtils.getInteger(paramMap, "brand");
Integer midSortId = MapUtils.getInteger(paramMap, "midSort");
Integer not_id = MapUtils.getInteger(paramMap, "not_id");
if (StringUtils.isBlank(query) || brandId == null || midSortId == null || not_id == null) {
return new SearchApiResult().setCode(400).setMessage("参数不合法,缺少必传参数");
}
//第一次查询
paramMap.put("viewNum", "100");
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 (returnInfoList.size() < RECOMMEND_LIMIT) {
returnInfoList.stream().map(p -> MapUtils.getIntValue(p, "id")).forEach(id -> idList.add(id));
//可能的第二次查询,去掉query去查
paramMap.remove("query");
this.addReturnInfoList(paramMap, idList, returnInfoList);
}
if (returnInfoList.size() < RECOMMEND_LIMIT) {
//可能的第三次查询,去掉中分类去查
paramMap.remove("midSort");
this.addReturnInfoList(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);
}
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 (returnInfoList.size() < RECOMMEND_LIMIT) {
returnInfoList.stream().map(p -> MapUtils.getIntValue(p, "id")).forEach(id -> idList.add(id));
//可能的第二次查询,去掉query去查
paramMap.remove("query");
this.addReturnInfoList(paramMap, idList, returnInfoList);
}
if (returnInfoList.size() < RECOMMEND_LIMIT) {
//可能的第三次查询,去掉中分类去查
paramMap.remove("midSort");
this.addReturnInfoList(paramMap, idList, returnInfoList);
}
dataMap.put("total", returnInfoList.size());
return searchApiResult;
}
private void addReturnInfoList(Map<String, String> paramMap, Set<Integer> idList, List<Map<String, Object>> returnInfoList) {
... ...