Authored by gemingdan

update

... ... @@ -33,6 +33,7 @@ import com.yoho.search.consumer.service.base.StorageService;
import com.yoho.search.consumer.service.bo.ProductGoodsBO;
import com.yoho.search.consumer.service.bo.StorageSkuBO;
import com.yoho.search.consumer.service.logic.StorageSkuLogicService;
import com.yoho.search.consumer.service.logic.productIndex.ProductGoodsLogicService;
import com.yoho.search.core.es.utils.IgnoreSomeException;
import com.yoho.search.dal.model.Goods;
import com.yoho.search.dal.model.Storage;
... ... @@ -55,6 +56,8 @@ public class GoodsMqListener extends AbstractMqListener implements ChannelAwareM
private StorageSkuLogicService storageSkuLogicService;
@Autowired
private ProductService productService;
@Autowired
private ProductGoodsLogicService productGoodsLogicService;
public void onMessage(Message message, Channel channel) throws Exception {
try {
... ... @@ -157,22 +160,7 @@ public class GoodsMqListener extends AbstractMqListener implements ChannelAwareM
ProductGoodsBO productGoodsBO = productGoodsBOList.get(0);
String goodsListJsonArrayStr = productGoodsBO.getGoodsList();
JSONArray goodsListJsonArray = JSONArray.parseArray(goodsListJsonArrayStr);
for (int i = 0; i < goodsListJsonArray.size(); i++) {
JSONObject jsonObject = goodsListJsonArray.getJSONObject(i);
//去除无库存和非正常状态的
if (!jsonObject.containsKey("status")||!jsonObject.get("status").toString().equals("1")) {
continue;
}
if (!jsonObject.containsKey("storage_num")||((Integer)jsonObject.get("storage_num"))<1) {
continue;
}
if (jsonObject.containsKey("color_id")) {
colorIdSet.add(jsonObject.get("color_id").toString());
}
if (jsonObject.containsKey("color_name")) {
colorNameSet.add(jsonObject.get("color_name").toString());
}
}
productGoodsLogicService.getColorSet(goodsListJsonArray, colorIdSet, colorNameSet);//获取有库存且状态正常的color
indexData.put("goodsList", goodsListJsonArray);
indexData.put("colorIds", StringUtils.join(colorIdSet, ","));
indexData.put("colorNames", StringUtils.join(colorNameSet, ","));
... ...
... ... @@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
import com.yoho.search.consumer.service.base.StorageService;
import com.yoho.search.consumer.service.bo.ProductGoodBO;
import com.yoho.search.consumer.service.bo.ProductGoodsBO;
import com.yoho.search.consumer.service.bo.ProductIndexBO;
import com.yoho.search.dal.GoodsCoverImageMapper;
import com.yoho.search.dal.GoodsMapper;
import com.yoho.search.dal.ProductColorMapper;
... ... @@ -12,6 +13,7 @@ import com.yoho.search.dal.model.Goods;
import com.yoho.search.dal.model.GoodsCoverImage;
import com.yoho.search.dal.model.ProductColor;
import com.yoho.search.dal.model.Storage;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -19,8 +21,10 @@ import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* Created by wangnan on 2016/6/30.
... ... @@ -147,4 +151,29 @@ public class ProductGoodsLogicService {
return productGoodsBOs;
}
/**
* 获取有库存且状态正常的color
* @param goodsListJsonArray
* @param colorIdSet
* @param colorNameSet
*/
public void getColorSet(JSONArray goodsListJsonArray,Set<String> colorIdSet,Set<String> colorNameSet){
for (int i = 0; i < goodsListJsonArray.size(); i++) {
JSONObject jsonObject = goodsListJsonArray.getJSONObject(i);
//去除无库存和非正常状态的
if (!jsonObject.containsKey("status")||!jsonObject.get("status").toString().equals("1")) {
continue;
}
if (!jsonObject.containsKey("storage_num")||((Integer)jsonObject.get("storage_num"))<1) {
continue;
}
if (jsonObject.containsKey("color_id")) {
colorIdSet.add(jsonObject.get("color_id").toString());
}
if (jsonObject.containsKey("color_name")) {
colorNameSet.add(jsonObject.get("color_name").toString());
}
}
}
}
... ...
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 java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
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;
import com.alibaba.fastjson.JSONArray;
import com.yoho.search.consumer.service.bo.ProductGoodsBO;
import com.yoho.search.consumer.service.bo.ProductIndexBO;
import com.yoho.search.consumer.service.logic.productIndex.ProductGoodsLogicService;
import com.yoho.search.consumer.service.logic.tools.MapGenerator;
/**
* Created by wangnan on 2017/1/6.
... ... @@ -22,6 +22,9 @@ import java.util.Set;
public class ProductGoodsBuilder implements ViewBuilder{
@Autowired
private MapGenerator mapGenerator;
@Autowired
private ProductGoodsLogicService productGoodsLogicService;
/**
* 构建ProductGoods
... ... @@ -41,25 +44,10 @@ public class ProductGoodsBuilder implements ViewBuilder{
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("status")||!jsonObject.get("status").toString().equals("1")) {
continue;
}
if (!jsonObject.containsKey("storage_num")||((Integer)jsonObject.get("storage_num"))<1) {
continue;
}
if (jsonObject.containsKey("color_id")) {
colorIdSet.add(jsonObject.get("color_id").toString());
}
if (jsonObject.containsKey("color_name")) {
colorNameSet.add(jsonObject.get("color_name").toString());
}
}
JSONArray goodsListJsonArray = JSONArray.parseArray(goodsListJsonArrayStr);
productGoodsLogicService.getColorSet(goodsListJsonArray, colorIdSet, colorNameSet);//获取有库存且状态正常的color
productIndexBO.setColorIds(StringUtils.join(colorIdSet, ","));
productIndexBO.setColorNames(StringUtils.join(colorNameSet, ","));
... ...