|
|
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, ","));
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
...
|
...
|
|