Authored by wangnan9279

ufo fix size bug

... ... @@ -23,22 +23,31 @@ public class UfoSizeIndexBaseService {
private static final String SIZE_INDEX_NAME = ISearchConstants.INDEX_NAME_UFO_SIZE;
private Map<String, Object> getSizeMap(Map<String, Object> esMap) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("size_id", MapUtils.getIntValue(esMap, "id", 0));
map.put("size_name", MapUtils.getString(esMap, "sizeName", ""));
//map.put("sort_id", MapUtils.getIntValue(esMap, "sortId", 0));
//map.put("order_by", MapUtils.getIntValue(esMap, "id", 0));
return map;
}
public List<Map<String, Object>> getSizeListByIds(final Collection<?> sizeIds) {
List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>();
try {
List<Map<String, Object>> sizeEsMapList = searchCommonService.doMultiGetCommon(SIZE_INDEX_NAME, sizeIds);
this.sortByOrderBy(sizeEsMapList);
List<Map<String, Object>> tempResultList = new ArrayList<Map<String, Object>>();
for (Map<String, Object> sizeEsMap : sizeEsMapList) {
resultList.add(this.getSizeMap(sizeEsMap));
tempResultList.add(this.getSizeMap(sizeEsMap));
}
//根据sizeName去重,id用逗号拼起来
Map<String, Map<String, Object>> sizeMap = new LinkedHashMap<>();
for (Map<String, Object> map : tempResultList) {
String sizeName = MapUtils.getString(map, "size_name");
String sizeId = MapUtils.getString(map, "size_id");
if (sizeMap.containsKey(sizeName)) {
Map<String, Object> oldMap = sizeMap.get(sizeName);
String oldSizeIds = MapUtils.getString(oldMap, "size_id");
oldMap.put(sizeName, oldSizeIds + "," + sizeId);
} else {
sizeMap.put(sizeName, map);
}
}
for (Map.Entry<String, Map<String, Object>> entry : sizeMap.entrySet()) {
resultList.add(entry.getValue());
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
... ... @@ -46,19 +55,27 @@ public class UfoSizeIndexBaseService {
return resultList;
}
/**
* 构造返回结果
*/
private Map<String, Object> getSizeMap(Map<String, Object> esMap) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("size_id", MapUtils.getIntValue(esMap, "id", 0) + "");
map.put("size_name", MapUtils.getString(esMap, "sizeName", ""));
return map;
}
/**
* 按order_by排序
*/
private void sortByOrderBy(List<Map<String, Object>> sizeEsResults) {
// 按orderby排序
Collections.sort(sizeEsResults, new Comparator<Map<String, Object>>() {
@Override
public int compare(Map<String, Object> size1, Map<String, Object> size2) {
int orderBy1 = MapUtils.getIntValue(size1, "orderBy");
int orderBy2 = MapUtils.getIntValue(size2, "orderBy");
return (orderBy1 - orderBy2) * 1;
}
Collections.sort(sizeEsResults, (size1, size2) -> {
int orderBy1 = MapUtils.getIntValue(size1, "orderBy");
int orderBy2 = MapUtils.getIntValue(size2, "orderBy");
return (orderBy1 - orderBy2) * 1;
});
}
}
... ...