Showing
1 changed file
with
36 additions
and
19 deletions
@@ -23,22 +23,31 @@ public class UfoSizeIndexBaseService { | @@ -23,22 +23,31 @@ public class UfoSizeIndexBaseService { | ||
23 | 23 | ||
24 | private static final String SIZE_INDEX_NAME = ISearchConstants.INDEX_NAME_UFO_SIZE; | 24 | private static final String SIZE_INDEX_NAME = ISearchConstants.INDEX_NAME_UFO_SIZE; |
25 | 25 | ||
26 | - private Map<String, Object> getSizeMap(Map<String, Object> esMap) { | ||
27 | - Map<String, Object> map = new HashMap<String, Object>(); | ||
28 | - map.put("size_id", MapUtils.getIntValue(esMap, "id", 0)); | ||
29 | - map.put("size_name", MapUtils.getString(esMap, "sizeName", "")); | ||
30 | - //map.put("sort_id", MapUtils.getIntValue(esMap, "sortId", 0)); | ||
31 | - //map.put("order_by", MapUtils.getIntValue(esMap, "id", 0)); | ||
32 | - return map; | ||
33 | - } | ||
34 | 26 | ||
35 | public List<Map<String, Object>> getSizeListByIds(final Collection<?> sizeIds) { | 27 | public List<Map<String, Object>> getSizeListByIds(final Collection<?> sizeIds) { |
36 | List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>(); | 28 | List<Map<String, Object>> resultList = new ArrayList<Map<String, Object>>(); |
37 | try { | 29 | try { |
38 | List<Map<String, Object>> sizeEsMapList = searchCommonService.doMultiGetCommon(SIZE_INDEX_NAME, sizeIds); | 30 | List<Map<String, Object>> sizeEsMapList = searchCommonService.doMultiGetCommon(SIZE_INDEX_NAME, sizeIds); |
39 | this.sortByOrderBy(sizeEsMapList); | 31 | this.sortByOrderBy(sizeEsMapList); |
32 | + List<Map<String, Object>> tempResultList = new ArrayList<Map<String, Object>>(); | ||
40 | for (Map<String, Object> sizeEsMap : sizeEsMapList) { | 33 | for (Map<String, Object> sizeEsMap : sizeEsMapList) { |
41 | - resultList.add(this.getSizeMap(sizeEsMap)); | 34 | + tempResultList.add(this.getSizeMap(sizeEsMap)); |
35 | + } | ||
36 | + //根据sizeName去重,id用逗号拼起来 | ||
37 | + Map<String, Map<String, Object>> sizeMap = new LinkedHashMap<>(); | ||
38 | + for (Map<String, Object> map : tempResultList) { | ||
39 | + String sizeName = MapUtils.getString(map, "size_name"); | ||
40 | + String sizeId = MapUtils.getString(map, "size_id"); | ||
41 | + if (sizeMap.containsKey(sizeName)) { | ||
42 | + Map<String, Object> oldMap = sizeMap.get(sizeName); | ||
43 | + String oldSizeIds = MapUtils.getString(oldMap, "size_id"); | ||
44 | + oldMap.put(sizeName, oldSizeIds + "," + sizeId); | ||
45 | + } else { | ||
46 | + sizeMap.put(sizeName, map); | ||
47 | + } | ||
48 | + } | ||
49 | + for (Map.Entry<String, Map<String, Object>> entry : sizeMap.entrySet()) { | ||
50 | + resultList.add(entry.getValue()); | ||
42 | } | 51 | } |
43 | } catch (Exception e) { | 52 | } catch (Exception e) { |
44 | logger.error(e.getMessage(), e); | 53 | logger.error(e.getMessage(), e); |
@@ -46,19 +55,27 @@ public class UfoSizeIndexBaseService { | @@ -46,19 +55,27 @@ public class UfoSizeIndexBaseService { | ||
46 | return resultList; | 55 | return resultList; |
47 | } | 56 | } |
48 | 57 | ||
58 | + | ||
59 | + /** | ||
60 | + * 构造返回结果 | ||
61 | + */ | ||
62 | + private Map<String, Object> getSizeMap(Map<String, Object> esMap) { | ||
63 | + Map<String, Object> map = new HashMap<String, Object>(); | ||
64 | + map.put("size_id", MapUtils.getIntValue(esMap, "id", 0) + ""); | ||
65 | + map.put("size_name", MapUtils.getString(esMap, "sizeName", "")); | ||
66 | + return map; | ||
67 | + } | ||
68 | + | ||
69 | + /** | ||
70 | + * 按order_by排序 | ||
71 | + */ | ||
49 | private void sortByOrderBy(List<Map<String, Object>> sizeEsResults) { | 72 | private void sortByOrderBy(List<Map<String, Object>> sizeEsResults) { |
50 | - // 按orderby排序 | ||
51 | - Collections.sort(sizeEsResults, new Comparator<Map<String, Object>>() { | ||
52 | - @Override | ||
53 | - public int compare(Map<String, Object> size1, Map<String, Object> size2) { | ||
54 | - int orderBy1 = MapUtils.getIntValue(size1, "orderBy"); | ||
55 | - int orderBy2 = MapUtils.getIntValue(size2, "orderBy"); | ||
56 | - return (orderBy1 - orderBy2) * 1; | ||
57 | - } | 73 | + Collections.sort(sizeEsResults, (size1, size2) -> { |
74 | + int orderBy1 = MapUtils.getIntValue(size1, "orderBy"); | ||
75 | + int orderBy2 = MapUtils.getIntValue(size2, "orderBy"); | ||
76 | + return (orderBy1 - orderBy2) * 1; | ||
58 | }); | 77 | }); |
59 | } | 78 | } |
60 | 79 | ||
61 | 80 | ||
62 | - | ||
63 | - | ||
64 | } | 81 | } |
-
Please register or login to post a comment