Authored by wangnan9279

拼团购 fix

... ... @@ -77,30 +77,29 @@ public class CollageService extends BaseService {
List<Integer> productSknList = new ArrayList<>(searchResult.getResultList().size());
List<Map<String, Object>> collageIndexResultList = getIndexMap(searchResult.getResultList(), productSknList);
List<Map<String, Object>> sknInfoList = sknReturnInfoCacheBean.queryProductListBySkn(productSknList, productSknList.size());
if (CollectionUtils.isEmpty(sknInfoList)) {
return searchApiResult.setCode(500);
}
Map<Integer, Map<String, Object>> sknInfoMap = new LinkedHashMap<>(sknInfoList.size());
sknInfoList.forEach(p -> sknInfoMap.put(MapUtils.getInteger(p, "product_skn"), p));
collageIndexResultList.forEach(p -> {
Integer productSkn = MapUtils.getInteger(p, "product_skn");
Map<String, Object> sknMap = sknInfoMap.get(productSkn);
p.put("product_name", MapUtils.getString(sknMap, "product_name", ""));
p.put("sales_price", MapUtils.getDoubleValue(sknMap, "sales_price"));
p.put("market_price", MapUtils.getDoubleValue(sknMap, "market_price"));
p.put("sales_num", MapUtils.getIntValue(sknMap, "sales_num"));
p.put("default_images", MapUtils.getString(sknMap, "default_images"));
});
Map<Map<String, Object>, Integer> salesNumSknInfoMap = collageIndexResultList.stream().collect(Collectors.toMap(p -> p, p -> MapUtils.getInteger(p, "sales_num")));
Map<Map<String, Object>, Integer> finalMap = new LinkedHashMap<>(salesNumSknInfoMap.size());
salesNumSknInfoMap.entrySet().stream().sorted(Map.Entry.comparingByValue()).forEachOrdered(e -> finalMap.put(e.getKey(), e.getValue()));
List<Map<String, Object>> finalList = new ArrayList<>(finalMap.size());
Iterator iterator = finalMap.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry entry = (Map.Entry) iterator.next();
finalList.add((Map<String, Object>) entry.getKey());
List<Map<String, Object>> finalList = new ArrayList<>();
if (CollectionUtils.isNotEmpty(sknInfoList)) {
Map<Integer, Map<String, Object>> sknInfoMap = new LinkedHashMap<>(sknInfoList.size());
sknInfoList.forEach(p -> sknInfoMap.put(MapUtils.getInteger(p, "product_skn"), p));
collageIndexResultList.forEach(p -> {
Integer productSkn = MapUtils.getInteger(p, "product_skn");
Map<String, Object> sknMap = sknInfoMap.get(productSkn);
p.put("product_name", MapUtils.getString(sknMap, "product_name", ""));
p.put("sales_price", MapUtils.getDoubleValue(sknMap, "sales_price"));
p.put("market_price", MapUtils.getDoubleValue(sknMap, "market_price"));
p.put("sales_num", MapUtils.getIntValue(sknMap, "sales_num"));
p.put("default_images", MapUtils.getString(sknMap, "default_images"));
});
Map<Map<String, Object>, Integer> salesNumSknInfoMap = collageIndexResultList.stream().collect(Collectors.toMap(p -> p, p -> MapUtils.getInteger(p, "sales_num")));
Map<Map<String, Object>, Integer> finalMap = new LinkedHashMap<>(salesNumSknInfoMap.size());
salesNumSknInfoMap.entrySet().stream().sorted(Map.Entry.comparingByValue()).forEachOrdered(e -> finalMap.put(e.getKey(), e.getValue()));
Iterator iterator = finalMap.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry entry = (Map.Entry) iterator.next();
finalList.add((Map<String, Object>) entry.getKey());
}
Collections.reverse(finalList);
}
Collections.reverse(finalList);
// 4.构造返回结果并加入缓存
JSONObject dataMap = new JSONObject();
dataMap.put("total", searchResult.getTotal());
... ...