Authored by gemingdan

pi全量和增量统一处理colorIds、colorNames、goodsList,增加对库存和状态的过滤

... ... @@ -4,6 +4,7 @@ import com.yoho.search.consumer.service.bo.ProductIBO;
import com.yoho.search.consumer.service.bo.ProductIndexBO;
import com.yoho.search.consumer.service.logic.productIndex.ProductILogicService;
import com.yoho.search.consumer.service.logic.viewBuilder.GeneralDataBuilder;
import com.yoho.search.consumer.service.logic.viewBuilder.ProductColorsBuilder;
import com.yoho.search.consumer.service.logic.viewBuilder.ViewBuilder;
import com.yoho.search.dal.BrandMapper;
import com.yoho.search.dal.ProductMapper;
... ... @@ -11,6 +12,7 @@ import com.yoho.search.dal.ProductSortMapper;
import com.yoho.search.dal.model.Brand;
import com.yoho.search.dal.model.Product;
import com.yoho.search.dal.model.ProductSort;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -132,6 +134,9 @@ public class ProductIndexLogicService implements ApplicationContextAware {
List<Integer> skns = productIBOs.stream().map(ProductIBO::getProductSkn).collect(Collectors.toList());
generalDataBuilder.buildDataFromProductI(productIndexBOs, productIBOs);
viewBuilderList.stream().forEach(viewBuilder -> {
if(viewBuilder instanceof ProductColorsBuilder){
return;
}
viewBuilder.build(productIndexBOs, ids, skns);
});
return productIndexBOs;
... ...
... ... @@ -93,6 +93,10 @@ public class ProductGoodsLogicService {
// 构造product_good视图
List<ProductGoodBO> productGoodBOs = new ArrayList<>();
for (Goods g : goodss) {
//去除无库存和非正常状态的
if(storagesMap.get(g.getId()) == null || storagesMap.get(g.getId()) == 0 || 1 != g.getStatus()){
continue;
}
ProductGoodBO productGoodBO = new ProductGoodBO();
productGoodBO.setProduct_id(g.getProductId());
productGoodBO.setIsDefault(g.getIsDefault() == null ? "" : g.getIsDefault());
... ...
package com.yoho.search.consumer.service.logic.viewBuilder;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yoho.search.consumer.service.bo.ProductGoodsBO;
import com.yoho.search.consumer.service.bo.ProductIndexBO;
import com.yoho.search.consumer.service.logic.tools.MapGenerator;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* Created by wangnan on 2017/1/6.
... ... @@ -23,10 +29,33 @@ public class ProductGoodsBuilder implements ViewBuilder{
@Override
public void build(List<ProductIndexBO> productIndexBOs, List<Integer> ids, List<Integer> skns) {
Map<Integer, ProductGoodsBO> productGoodsesMap = mapGenerator.getProductGoodsesMap(ids);
Set<String> colorIdSet = null;
Set<String> colorNameSet = null;
for (ProductIndexBO productIndexBO : productIndexBOs) {
ProductGoodsBO productGoodsBO = productGoodsesMap.get(productIndexBO.getProductId());
if (productGoodsBO != null) {
productIndexBO.setGoodsList(productGoodsBO.getGoodsList());
String goodsListJsonArrayStr = productGoodsBO.getGoodsList();
if(goodsListJsonArrayStr==null||goodsListJsonArrayStr.length()<3){
productIndexBO.setColorIds("");
productIndexBO.setColorNames("");
continue;
}
JSONArray goodsListJsonArray = JSONArray.parseArray(goodsListJsonArrayStr);
colorIdSet = new HashSet<String>();
colorNameSet = new HashSet<String>();
for (int i = 0; i < goodsListJsonArray.size(); i++) {
JSONObject jsonObject = goodsListJsonArray.getJSONObject(i);
if (jsonObject.containsKey("color_id")) {
colorIdSet.add(jsonObject.get("color_id").toString());
}
if (jsonObject.containsKey("color_name")) {
colorNameSet.add(jsonObject.get("color_name").toString());
}
}
productIndexBO.setColorIds(StringUtils.join(colorIdSet, ","));
productIndexBO.setColorNames(StringUtils.join(colorNameSet, ","));
}
}
}
... ...