...
|
...
|
@@ -9,13 +9,14 @@ import com.yoho.search.dal.model.ActivityTag; |
|
|
import com.yoho.search.dal.model.Product;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.springframework.beans.BeansException;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* Created by wangnan on 2017/9/11.
|
...
|
...
|
@@ -28,21 +29,15 @@ public class ProductCustomizeTagBuilder implements IndexFieldBuilder { |
|
|
@Autowired
|
|
|
private ProductMapper productMapper;
|
|
|
|
|
|
@Override
|
|
|
public void build(List<ProductIndexBO> productIndexBOs, List<Integer> ids, List<Integer> sknList) {
|
|
|
List<Product> productList = productMapper.selectListByIds(ids);
|
|
|
if (CollectionUtils.isEmpty(productList)) {
|
|
|
return;
|
|
|
}
|
|
|
List<Integer> promotionIdList = productList.stream().map(Product::getIsPromotion).distinct().collect(Collectors.toList());
|
|
|
if (CollectionUtils.isEmpty(promotionIdList)) {
|
|
|
return;
|
|
|
}
|
|
|
List<ActivityTag> activityTagList = activityTagMapper.selectByIsPromotionIdList(promotionIdList);
|
|
|
private static Map<Integer, ActivityTag> activityTagsMap = new HashMap<>();
|
|
|
|
|
|
@PostConstruct
|
|
|
public void buildActivityTagsMap() throws BeansException {
|
|
|
activityTagsMap.clear();
|
|
|
List<ActivityTag> activityTagList = activityTagMapper.selectLists();
|
|
|
if (CollectionUtils.isEmpty(activityTagList)) {
|
|
|
return;
|
|
|
}
|
|
|
Map<Integer, ActivityTag> activityTagMap = new HashMap<>();
|
|
|
for (ActivityTag activityTag : activityTagList) {
|
|
|
String[] isPromotionIdArray = activityTag.getIsPromotionIds().split(",");
|
|
|
if (isPromotionIdArray.length == 0) {
|
...
|
...
|
@@ -50,12 +45,21 @@ public class ProductCustomizeTagBuilder implements IndexFieldBuilder { |
|
|
}
|
|
|
for (String promotionId : isPromotionIdArray) {
|
|
|
if (StringUtils.isNotBlank(promotionId)) {
|
|
|
activityTagMap.put(Integer.valueOf(promotionId), activityTag);
|
|
|
activityTagsMap.put(Integer.valueOf(promotionId), activityTag);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
@Override
|
|
|
public void build(List<ProductIndexBO> productIndexBOs, List<Integer> ids, List<Integer> sknList) {
|
|
|
List<Product> productList = productMapper.selectListByIds(ids);
|
|
|
if (CollectionUtils.isEmpty(productList)) {
|
|
|
return;
|
|
|
}
|
|
|
productIndexBOs.stream().forEach(productIndexBO -> {
|
|
|
ActivityTag activityTag = activityTagMap.get(productIndexBO.getIspromotion());
|
|
|
ActivityTag activityTag = activityTagsMap.get(productIndexBO.getIspromotion());
|
|
|
if (activityTag != null) {
|
|
|
JSONObject customizeTag = new JSONObject();
|
|
|
customizeTag.put("id", activityTag.getId());
|
...
|
...
|
@@ -67,4 +71,29 @@ public class ProductCustomizeTagBuilder implements IndexFieldBuilder { |
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
public JSONArray buildCustomizeTagByProductId(Integer productId) {
|
|
|
Product product = productMapper.selectByPrimaryKey(productId);
|
|
|
if (product == null) {
|
|
|
return new JSONArray(0);
|
|
|
}
|
|
|
Integer promotionId = product.getIsPromotion();
|
|
|
if (promotionId == null) {
|
|
|
return new JSONArray(0);
|
|
|
}
|
|
|
|
|
|
ActivityTag activityTag = activityTagsMap.get(promotionId);
|
|
|
if (activityTag != null) {
|
|
|
JSONObject customizeTag = new JSONObject();
|
|
|
customizeTag.put("id", activityTag.getId());
|
|
|
customizeTag.put("name", activityTag.getActivityName());
|
|
|
customizeTag.put("url", activityTag.getTagUrl());
|
|
|
JSONArray customizeTags = new JSONArray();
|
|
|
customizeTags.add(customizeTag);
|
|
|
|
|
|
return customizeTags;
|
|
|
}
|
|
|
return new JSONArray(0);
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|