Showing
1 changed file
with
13 additions
and
9 deletions
@@ -22,10 +22,7 @@ import org.slf4j.LoggerFactory; | @@ -22,10 +22,7 @@ import org.slf4j.LoggerFactory; | ||
22 | import org.springframework.beans.factory.annotation.Autowired; | 22 | import org.springframework.beans.factory.annotation.Autowired; |
23 | import org.springframework.stereotype.Component; | 23 | import org.springframework.stereotype.Component; |
24 | 24 | ||
25 | -import java.util.ArrayList; | ||
26 | -import java.util.Collections; | ||
27 | -import java.util.List; | ||
28 | -import java.util.Map; | 25 | +import java.util.*; |
29 | 26 | ||
30 | @Component | 27 | @Component |
31 | public class ActivityShopBrandListService extends AbstractPageComponent<ActivityShopBrandList> { | 28 | public class ActivityShopBrandListService extends AbstractPageComponent<ActivityShopBrandList> { |
@@ -99,22 +96,29 @@ public class ActivityShopBrandListService extends AbstractPageComponent<Activity | @@ -99,22 +96,29 @@ public class ActivityShopBrandListService extends AbstractPageComponent<Activity | ||
99 | //1、获取二层聚合的结果 | 96 | //1、获取二层聚合的结果 |
100 | List<AggKeyCountTwoLevel> aggKeyCountTwoLevelList = AggCommonHelper.getAggKeyCountTwoLevelList(aggregationMap, "shopAgg", "brandAgg"); | 97 | List<AggKeyCountTwoLevel> aggKeyCountTwoLevelList = AggCommonHelper.getAggKeyCountTwoLevelList(aggregationMap, "shopAgg", "brandAgg"); |
101 | //2、使用第一层聚合的总数量排序 | 98 | //2、使用第一层聚合的总数量排序 |
102 | - Collections.sort(aggKeyCountTwoLevelList, (o1, o2) -> ((o2.getFirstAggKeyCount().getCount()).compareTo((o1.getFirstAggKeyCount().getCount())))); | 99 | + //Collections.sort(aggKeyCountTwoLevelList, (o1, o2) -> ((o2.getFirstAggKeyCount().getCount()).compareTo((o1.getFirstAggKeyCount().getCount())))); |
103 | List<ActivityShopBrandList.ShopBrand> shopBrandList = new ArrayList<>(); | 100 | List<ActivityShopBrandList.ShopBrand> shopBrandList = new ArrayList<>(); |
101 | + Set<Integer> filterBrandIds = new HashSet<Integer>(); | ||
104 | for (AggKeyCountTwoLevel aggKeyCountTwoLevel: aggKeyCountTwoLevelList) { | 102 | for (AggKeyCountTwoLevel aggKeyCountTwoLevel: aggKeyCountTwoLevelList) { |
105 | AggKeyCount first = aggKeyCountTwoLevel.getFirstAggKeyCount(); | 103 | AggKeyCount first = aggKeyCountTwoLevel.getFirstAggKeyCount(); |
106 | List<AggKeyCount> secondList = aggKeyCountTwoLevel.getSecondAggKeyCountList(); | 104 | List<AggKeyCount> secondList = aggKeyCountTwoLevel.getSecondAggKeyCountList(); |
107 | //3、对第二层聚合结果排序 | 105 | //3、对第二层聚合结果排序 |
108 | - Collections.sort(secondList, (o1, o2) -> ((o2.getCount()).compareTo((o1.getCount())))); | 106 | + //Collections.sort(secondList, (o1, o2) -> ((o2.getCount()).compareTo((o1.getCount())))); |
109 | Integer shopId = first.getKey(); | 107 | Integer shopId = first.getKey(); |
110 | if(shopId.equals(0)){ | 108 | if(shopId.equals(0)){ |
111 | continue; | 109 | continue; |
112 | } | 110 | } |
113 | for (AggKeyCount brandAggKeyCount: secondList){ | 111 | for (AggKeyCount brandAggKeyCount: secondList){ |
114 | - if(!brandAggKeyCount.getKey().equals(0)){ | ||
115 | - shopBrandList.add(new ActivityShopBrandList.ShopBrand(shopId,brandAggKeyCount.getKey()));//取商品数最多的一个店铺即可,防止多品店的问题 | ||
116 | - break; | 112 | + Integer brandId = brandAggKeyCount.getKey(); |
113 | + if(brandId.equals(0)){ | ||
114 | + continue; | ||
117 | } | 115 | } |
116 | + if(filterBrandIds.contains(brandId)){ | ||
117 | + continue; | ||
118 | + } | ||
119 | + shopBrandList.add(new ActivityShopBrandList.ShopBrand(shopId,brandId));//取商品数最多的一个店铺即可,防止多品店的问题 | ||
120 | + filterBrandIds.add(brandId);//每个品牌只赋给一个店铺 | ||
121 | + break; | ||
118 | } | 122 | } |
119 | } | 123 | } |
120 | return new ActivityShopBrandList(shopBrandList); | 124 | return new ActivityShopBrandList(shopBrandList); |
-
Please register or login to post a comment