Showing
1 changed file
with
35 additions
and
30 deletions
@@ -102,38 +102,43 @@ public class UfoProductListService { | @@ -102,38 +102,43 @@ public class UfoProductListService { | ||
102 | 102 | ||
103 | @SearchCacheAble(cacheName = "UFO_RECOMMEND_LIST", cacheInMinute = 10) | 103 | @SearchCacheAble(cacheName = "UFO_RECOMMEND_LIST", cacheInMinute = 10) |
104 | public SearchApiResult recommendList(Map<String, String> paramMap) { | 104 | public SearchApiResult recommendList(Map<String, String> paramMap) { |
105 | - String query = MapUtils.getString(paramMap, "query"); | ||
106 | - Integer brandId = MapUtils.getInteger(paramMap, "brand"); | ||
107 | - Integer midSortId = MapUtils.getInteger(paramMap, "midSort"); | ||
108 | - Integer not_id = MapUtils.getInteger(paramMap, "not_id"); | ||
109 | - if (StringUtils.isBlank(query) || brandId == null || midSortId == null || not_id == null) { | ||
110 | - return new SearchApiResult().setCode(400).setMessage("参数不合法,缺少必传参数"); | ||
111 | - } | ||
112 | - //第一次查询 | ||
113 | - paramMap.put("viewNum", "100"); | ||
114 | - SearchApiResult searchApiResult = this.productList(paramMap); | ||
115 | - if (searchApiResult.getData() == null) { | 105 | + try { |
106 | + String query = MapUtils.getString(paramMap, "query"); | ||
107 | + Integer brandId = MapUtils.getInteger(paramMap, "brand"); | ||
108 | + Integer midSortId = MapUtils.getInteger(paramMap, "midSort"); | ||
109 | + Integer not_id = MapUtils.getInteger(paramMap, "not_id"); | ||
110 | + if (StringUtils.isBlank(query) || brandId == null || midSortId == null || not_id == null) { | ||
111 | + return new SearchApiResult().setCode(400).setMessage("参数不合法,缺少必传参数"); | ||
112 | + } | ||
113 | + //第一次查询 | ||
114 | + paramMap.put("viewNum", "100"); | ||
115 | + SearchApiResult searchApiResult = this.productList(paramMap); | ||
116 | + if (searchApiResult.getData() == null) { | ||
117 | + return new SearchApiResult().setData(null).setCode(500); | ||
118 | + } | ||
119 | + JSONObject dataMap = (JSONObject) searchApiResult.getData(); | ||
120 | + dataMap.remove("page_total"); | ||
121 | + dataMap.remove("page_size"); | ||
122 | + dataMap.remove("page"); | ||
123 | + List<Map<String, Object>> returnInfoList = (List<Map<String, Object>>) dataMap.get(RETURN_LIST_NAME); | ||
124 | + Set<Integer> idList = new HashSet<>(); | ||
125 | + if (returnInfoList.size() < RECOMMEND_LIMIT) { | ||
126 | + returnInfoList.stream().map(p -> MapUtils.getIntValue(p, "id")).forEach(id -> idList.add(id)); | ||
127 | + //可能的第二次查询,去掉query去查 | ||
128 | + paramMap.remove("query"); | ||
129 | + this.addReturnInfoList(paramMap, idList, returnInfoList); | ||
130 | + } | ||
131 | + if (returnInfoList.size() < RECOMMEND_LIMIT) { | ||
132 | + //可能的第三次查询,去掉中分类去查 | ||
133 | + paramMap.remove("midSort"); | ||
134 | + this.addReturnInfoList(paramMap, idList, returnInfoList); | ||
135 | + } | ||
136 | + dataMap.put("total", returnInfoList.size()); | ||
137 | + return searchApiResult; | ||
138 | + } catch (Exception e) { | ||
139 | + logger.error(e.getMessage(), e); | ||
116 | return new SearchApiResult().setData(null).setCode(500); | 140 | return new SearchApiResult().setData(null).setCode(500); |
117 | } | 141 | } |
118 | - JSONObject dataMap = (JSONObject) searchApiResult.getData(); | ||
119 | - dataMap.remove("page_total"); | ||
120 | - dataMap.remove("page_size"); | ||
121 | - dataMap.remove("page"); | ||
122 | - List<Map<String, Object>> returnInfoList = (List<Map<String, Object>>) dataMap.get(RETURN_LIST_NAME); | ||
123 | - Set<Integer> idList = new HashSet<>(); | ||
124 | - if (returnInfoList.size() < RECOMMEND_LIMIT) { | ||
125 | - returnInfoList.stream().map(p -> MapUtils.getIntValue(p, "id")).forEach(id -> idList.add(id)); | ||
126 | - //可能的第二次查询,去掉query去查 | ||
127 | - paramMap.remove("query"); | ||
128 | - this.addReturnInfoList(paramMap, idList, returnInfoList); | ||
129 | - } | ||
130 | - if (returnInfoList.size() < RECOMMEND_LIMIT) { | ||
131 | - //可能的第三次查询,去掉中分类去查 | ||
132 | - paramMap.remove("midSort"); | ||
133 | - this.addReturnInfoList(paramMap, idList, returnInfoList); | ||
134 | - } | ||
135 | - dataMap.put("total", returnInfoList.size()); | ||
136 | - return searchApiResult; | ||
137 | } | 142 | } |
138 | 143 | ||
139 | private void addReturnInfoList(Map<String, String> paramMap, Set<Integer> idList, List<Map<String, Object>> returnInfoList) { | 144 | private void addReturnInfoList(Map<String, String> paramMap, Set<Integer> idList, List<Map<String, Object>> returnInfoList) { |
-
Please register or login to post a comment