Authored by hugufei

活动店铺推荐接口优化

... ... @@ -54,7 +54,15 @@ public class ActivityService {
}
private List<Integer> buildShopIds(List<ActivityShopBrand> shopBrandList, UserPersonalFactorRspNew userPersonalFactorRspNew) {
//1、计算店铺得分
//1、获取品牌-店铺的对应关系
Map<Integer, Integer> brandId2ShopIdMap = new HashMap<>();
for (ActivityShopBrand activityShopBrand : shopBrandList) {
brandId2ShopIdMap.put(activityShopBrand.getBrandId(), activityShopBrand.getShopId());
}
//2、获取实时推荐的品牌
List<Integer> recBrandIds = this.getRecBrandIds(userPersonalFactorRspNew);
//3、计算店铺得分并排序
List<Double> brandVector = userPersonalFactorRspNew.getBrandVector();
List<Double> brandVectorW2v = userPersonalFactorRspNew.getBrandVectorW2v();
if (brandVectorW2v != null && !brandVectorW2v.isEmpty()) {
... ... @@ -62,22 +70,27 @@ public class ActivityService {
} else {
this.calScore(shopBrandList, brandVectorW2v, true);
}
//2、实时推荐店铺加分
List<Integer> recBrandIds = this.getRecBrandIds(userPersonalFactorRspNew);
for (ActivityShopBrand shopBrand : shopBrandList) {
if (recBrandIds.contains(shopBrand.getBrandId())) {
shopBrand.setScore(shopBrand.getScore()+100);
}
}
//3、按得分排序
Collections.sort(shopBrandList, (o1, o2) -> (o2.getScore()).compareTo(o1.getScore()));
//4、截取shopId
List<Integer> shopIds = new ArrayList<>();
//4.1、先获取推荐品牌对应的店铺
for (Integer brandId : recBrandIds) {
Integer shopId = brandId2ShopIdMap.get(brandId);
if (shopId == null || shopIds.contains(shopId)) {
continue;
}
shopIds.add(shopId);
}
//4.2、再按向量得分排序补满50个
for (ActivityShopBrand shopBrand : shopBrandList) {
if (shopIds.size() >= 50) {
break;
}
shopIds.add(shopBrand.getShopId());
if (!shopIds.contains(shopBrand.getShopId())) {
shopIds.add(shopBrand.getShopId());
}
}
return shopIds;
}
... ... @@ -101,7 +114,7 @@ public class ActivityService {
* 按向量计算品牌得分
*/
private void calScore(List<ActivityShopBrand> shopBrandList, List<Double> userBrandVector, boolean isRnn) {
if(userBrandVector==null || userBrandVector.isEmpty()){
if (userBrandVector == null || userBrandVector.isEmpty()) {
return;
}
double userBrandVectorNorm = Word2VectorCalculator.getVectorListNorm(userBrandVector);
... ...