Authored by hugufei

活动模板店铺推荐一个品牌只能赋值给一个店铺

... ... @@ -22,10 +22,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.*;
@Component
public class ActivityShopBrandListService extends AbstractPageComponent<ActivityShopBrandList> {
... ... @@ -99,22 +96,29 @@ public class ActivityShopBrandListService extends AbstractPageComponent<Activity
//1、获取二层聚合的结果
List<AggKeyCountTwoLevel> aggKeyCountTwoLevelList = AggCommonHelper.getAggKeyCountTwoLevelList(aggregationMap, "shopAgg", "brandAgg");
//2、使用第一层聚合的总数量排序
Collections.sort(aggKeyCountTwoLevelList, (o1, o2) -> ((o2.getFirstAggKeyCount().getCount()).compareTo((o1.getFirstAggKeyCount().getCount()))));
//Collections.sort(aggKeyCountTwoLevelList, (o1, o2) -> ((o2.getFirstAggKeyCount().getCount()).compareTo((o1.getFirstAggKeyCount().getCount()))));
List<ActivityShopBrandList.ShopBrand> shopBrandList = new ArrayList<>();
Set<Integer> filterBrandIds = new HashSet<Integer>();
for (AggKeyCountTwoLevel aggKeyCountTwoLevel: aggKeyCountTwoLevelList) {
AggKeyCount first = aggKeyCountTwoLevel.getFirstAggKeyCount();
List<AggKeyCount> secondList = aggKeyCountTwoLevel.getSecondAggKeyCountList();
//3、对第二层聚合结果排序
Collections.sort(secondList, (o1, o2) -> ((o2.getCount()).compareTo((o1.getCount()))));
//Collections.sort(secondList, (o1, o2) -> ((o2.getCount()).compareTo((o1.getCount()))));
Integer shopId = first.getKey();
if(shopId.equals(0)){
continue;
}
for (AggKeyCount brandAggKeyCount: secondList){
if(!brandAggKeyCount.getKey().equals(0)){
shopBrandList.add(new ActivityShopBrandList.ShopBrand(shopId,brandAggKeyCount.getKey()));//取商品数最多的一个店铺即可,防止多品店的问题
break;
Integer brandId = brandAggKeyCount.getKey();
if(brandId.equals(0)){
continue;
}
if(filterBrandIds.contains(brandId)){
continue;
}
shopBrandList.add(new ActivityShopBrandList.ShopBrand(shopId,brandId));//取商品数最多的一个店铺即可,防止多品店的问题
filterBrandIds.add(brandId);//每个品牌只赋给一个店铺
break;
}
}
return new ActivityShopBrandList(shopBrandList);
... ...