Showing
1 changed file
with
20 additions
and
48 deletions
@@ -193,7 +193,6 @@ public class ShopListServiceImpl implements IShopListService { | @@ -193,7 +193,6 @@ public class ShopListServiceImpl implements IShopListService { | ||
193 | if (productList == null || productList.isEmpty()) { | 193 | if (productList == null || productList.isEmpty()) { |
194 | return new ArrayList<Map<String, Object>>(); | 194 | return new ArrayList<Map<String, Object>>(); |
195 | } | 195 | } |
196 | - productList = this.sortListBySortField(productList); | ||
197 | 196 | ||
198 | List<Integer> yohoShopIds = new ArrayList<Integer>(); | 197 | List<Integer> yohoShopIds = new ArrayList<Integer>(); |
199 | List<Integer> globalBrandIds = new ArrayList<Integer>(); | 198 | List<Integer> globalBrandIds = new ArrayList<Integer>(); |
@@ -223,6 +222,7 @@ public class ShopListServiceImpl implements IShopListService { | @@ -223,6 +222,7 @@ public class ShopListServiceImpl implements IShopListService { | ||
223 | if (globalBrand != null && 1==(Integer)globalBrand.get("status")) { | 222 | if (globalBrand != null && 1==(Integer)globalBrand.get("status")) { |
224 | shop_info.put("tbl_brand", globalBrand); | 223 | shop_info.put("tbl_brand", globalBrand); |
225 | shop_info.put("yoho_shop", null); | 224 | shop_info.put("yoho_shop", null); |
225 | + shop_info.put("_score", map.getOrDefault("_score", 0)); | ||
226 | shops_info.add(shop_info); | 226 | shops_info.add(shop_info); |
227 | continue; | 227 | continue; |
228 | } | 228 | } |
@@ -232,62 +232,34 @@ public class ShopListServiceImpl implements IShopListService { | @@ -232,62 +232,34 @@ public class ShopListServiceImpl implements IShopListService { | ||
232 | if (yohoShopInfo != null && 1==(Integer)yohoShopInfo.get("status")) { | 232 | if (yohoShopInfo != null && 1==(Integer)yohoShopInfo.get("status")) { |
233 | shop_info.put("tbl_brand", null); | 233 | shop_info.put("tbl_brand", null); |
234 | shop_info.put("yoho_shop", yohoShopInfo); | 234 | shop_info.put("yoho_shop", yohoShopInfo); |
235 | + shop_info.put("_score", map.getOrDefault("_score", 0)); | ||
235 | shops_info.add(shop_info); | 236 | shops_info.add(shop_info); |
236 | continue; | 237 | continue; |
237 | } | 238 | } |
238 | } | 239 | } |
239 | } | 240 | } |
240 | - return shops_info; | ||
241 | - } | ||
242 | - | ||
243 | - private double getDouble(Object value) { | ||
244 | - if (value == null) { | ||
245 | - return 0; | ||
246 | - } | ||
247 | - if (value instanceof Float) { | ||
248 | - return ((Float) value).floatValue(); | ||
249 | - } | ||
250 | - if (value instanceof Integer) { | ||
251 | - return ((Integer) value); | ||
252 | - } | ||
253 | - if (value instanceof Long) { | ||
254 | - return ((Long) value); | ||
255 | - } | ||
256 | - if (value instanceof String) { | ||
257 | - return Double.valueOf(value.toString()); | ||
258 | - } | ||
259 | - if (value instanceof Double) { | ||
260 | - return Double.valueOf(value.toString()); | ||
261 | - } | ||
262 | - return 0; | ||
263 | - } | ||
264 | - | ||
265 | - private List<Map<String, Object>> sortListBySortField(List<Map<String, Object>> productList) { | ||
266 | - if (productList == null || productList.isEmpty()) { | ||
267 | - return productList; | ||
268 | - } | ||
269 | - // 再按照某个字段对商品排序 | ||
270 | - boolean asc = false; | ||
271 | - Collections.sort(productList, new Comparator<Map<String, Object>>() { | 241 | + Collections.sort(shops_info,new Comparator<Map<String, Object>>() { |
242 | + @SuppressWarnings("unchecked") | ||
243 | + @Override | ||
272 | public int compare(Map<String, Object> o1, Map<String, Object> o2) { | 244 | public int compare(Map<String, Object> o1, Map<String, Object> o2) { |
273 | - try { | ||
274 | - double value1 = getDouble(o1.get("_score")); | ||
275 | - double value2 = getDouble(o2.get("_score")); | ||
276 | - if (value1 == value2) { | ||
277 | - return 0; | ||
278 | - } | ||
279 | - if (asc) { | ||
280 | - return value1 - value2 > 0 ? 1 : -1; | ||
281 | - } else { | ||
282 | - return value1 - value2 > 0 ? -1 : 1; | ||
283 | - } | ||
284 | - } catch (Exception e) { | ||
285 | - logger.error(e.getMessage(), e); | 245 | + float score1 = (float)o1.getOrDefault("_score", 0); |
246 | + float score2 = (float)o2.getOrDefault("_score", 0); | ||
247 | + if(score1>score2){ | ||
286 | return -1; | 248 | return -1; |
287 | } | 249 | } |
250 | + if(score1<score2){ | ||
251 | + return 1; | ||
252 | + } | ||
253 | + Map<String, Object> yoho_shop1 = (Map<String, Object>)o1.get("yoho_shop"); | ||
254 | + Map<String, Object> yoho_shop2 = (Map<String, Object>)o2.get("yoho_shop"); | ||
255 | + if(yoho_shop2==null || yoho_shop2==null){ | ||
256 | + return 0; | ||
257 | + } | ||
258 | + int shop_type1 = (Integer)yoho_shop1.getOrDefault("shop_type", Integer.MAX_VALUE); | ||
259 | + int shop_type2 = (Integer) yoho_shop2.getOrDefault("shop_type", Integer.MAX_VALUE); | ||
260 | + return shop_type1 - shop_type2; | ||
288 | } | 261 | } |
289 | }); | 262 | }); |
290 | - return productList; | 263 | + return shops_info; |
291 | } | 264 | } |
292 | - | ||
293 | } | 265 | } |
-
Please register or login to post a comment