Showing
3 changed files
with
47 additions
and
42 deletions
@@ -33,6 +33,7 @@ import com.yoho.search.consumer.service.base.StorageService; | @@ -33,6 +33,7 @@ import com.yoho.search.consumer.service.base.StorageService; | ||
33 | import com.yoho.search.consumer.service.bo.ProductGoodsBO; | 33 | import com.yoho.search.consumer.service.bo.ProductGoodsBO; |
34 | import com.yoho.search.consumer.service.bo.StorageSkuBO; | 34 | import com.yoho.search.consumer.service.bo.StorageSkuBO; |
35 | import com.yoho.search.consumer.service.logic.StorageSkuLogicService; | 35 | import com.yoho.search.consumer.service.logic.StorageSkuLogicService; |
36 | +import com.yoho.search.consumer.service.logic.productIndex.ProductGoodsLogicService; | ||
36 | import com.yoho.search.core.es.utils.IgnoreSomeException; | 37 | import com.yoho.search.core.es.utils.IgnoreSomeException; |
37 | import com.yoho.search.dal.model.Goods; | 38 | import com.yoho.search.dal.model.Goods; |
38 | import com.yoho.search.dal.model.Storage; | 39 | import com.yoho.search.dal.model.Storage; |
@@ -55,6 +56,8 @@ public class GoodsMqListener extends AbstractMqListener implements ChannelAwareM | @@ -55,6 +56,8 @@ public class GoodsMqListener extends AbstractMqListener implements ChannelAwareM | ||
55 | private StorageSkuLogicService storageSkuLogicService; | 56 | private StorageSkuLogicService storageSkuLogicService; |
56 | @Autowired | 57 | @Autowired |
57 | private ProductService productService; | 58 | private ProductService productService; |
59 | + @Autowired | ||
60 | + private ProductGoodsLogicService productGoodsLogicService; | ||
58 | 61 | ||
59 | public void onMessage(Message message, Channel channel) throws Exception { | 62 | public void onMessage(Message message, Channel channel) throws Exception { |
60 | try { | 63 | try { |
@@ -157,22 +160,7 @@ public class GoodsMqListener extends AbstractMqListener implements ChannelAwareM | @@ -157,22 +160,7 @@ public class GoodsMqListener extends AbstractMqListener implements ChannelAwareM | ||
157 | ProductGoodsBO productGoodsBO = productGoodsBOList.get(0); | 160 | ProductGoodsBO productGoodsBO = productGoodsBOList.get(0); |
158 | String goodsListJsonArrayStr = productGoodsBO.getGoodsList(); | 161 | String goodsListJsonArrayStr = productGoodsBO.getGoodsList(); |
159 | JSONArray goodsListJsonArray = JSONArray.parseArray(goodsListJsonArrayStr); | 162 | JSONArray goodsListJsonArray = JSONArray.parseArray(goodsListJsonArrayStr); |
160 | - for (int i = 0; i < goodsListJsonArray.size(); i++) { | ||
161 | - JSONObject jsonObject = goodsListJsonArray.getJSONObject(i); | ||
162 | - //去除无库存和非正常状态的 | ||
163 | - if (!jsonObject.containsKey("status")||!jsonObject.get("status").toString().equals("1")) { | ||
164 | - continue; | ||
165 | - } | ||
166 | - if (!jsonObject.containsKey("storage_num")||((Integer)jsonObject.get("storage_num"))<1) { | ||
167 | - continue; | ||
168 | - } | ||
169 | - if (jsonObject.containsKey("color_id")) { | ||
170 | - colorIdSet.add(jsonObject.get("color_id").toString()); | ||
171 | - } | ||
172 | - if (jsonObject.containsKey("color_name")) { | ||
173 | - colorNameSet.add(jsonObject.get("color_name").toString()); | ||
174 | - } | ||
175 | - } | 163 | + productGoodsLogicService.getColorSet(goodsListJsonArray, colorIdSet, colorNameSet);//获取有库存且状态正常的color |
176 | indexData.put("goodsList", goodsListJsonArray); | 164 | indexData.put("goodsList", goodsListJsonArray); |
177 | indexData.put("colorIds", StringUtils.join(colorIdSet, ",")); | 165 | indexData.put("colorIds", StringUtils.join(colorIdSet, ",")); |
178 | indexData.put("colorNames", StringUtils.join(colorNameSet, ",")); | 166 | indexData.put("colorNames", StringUtils.join(colorNameSet, ",")); |
@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject; | @@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject; | ||
5 | import com.yoho.search.consumer.service.base.StorageService; | 5 | import com.yoho.search.consumer.service.base.StorageService; |
6 | import com.yoho.search.consumer.service.bo.ProductGoodBO; | 6 | import com.yoho.search.consumer.service.bo.ProductGoodBO; |
7 | import com.yoho.search.consumer.service.bo.ProductGoodsBO; | 7 | import com.yoho.search.consumer.service.bo.ProductGoodsBO; |
8 | +import com.yoho.search.consumer.service.bo.ProductIndexBO; | ||
8 | import com.yoho.search.dal.GoodsCoverImageMapper; | 9 | import com.yoho.search.dal.GoodsCoverImageMapper; |
9 | import com.yoho.search.dal.GoodsMapper; | 10 | import com.yoho.search.dal.GoodsMapper; |
10 | import com.yoho.search.dal.ProductColorMapper; | 11 | import com.yoho.search.dal.ProductColorMapper; |
@@ -12,6 +13,7 @@ import com.yoho.search.dal.model.Goods; | @@ -12,6 +13,7 @@ import com.yoho.search.dal.model.Goods; | ||
12 | import com.yoho.search.dal.model.GoodsCoverImage; | 13 | import com.yoho.search.dal.model.GoodsCoverImage; |
13 | import com.yoho.search.dal.model.ProductColor; | 14 | import com.yoho.search.dal.model.ProductColor; |
14 | import com.yoho.search.dal.model.Storage; | 15 | import com.yoho.search.dal.model.Storage; |
16 | + | ||
15 | import org.apache.commons.collections.CollectionUtils; | 17 | import org.apache.commons.collections.CollectionUtils; |
16 | import org.apache.commons.lang3.StringUtils; | 18 | import org.apache.commons.lang3.StringUtils; |
17 | import org.springframework.beans.factory.annotation.Autowired; | 19 | import org.springframework.beans.factory.annotation.Autowired; |
@@ -19,8 +21,10 @@ import org.springframework.stereotype.Component; | @@ -19,8 +21,10 @@ import org.springframework.stereotype.Component; | ||
19 | 21 | ||
20 | import java.util.ArrayList; | 22 | import java.util.ArrayList; |
21 | import java.util.HashMap; | 23 | import java.util.HashMap; |
24 | +import java.util.HashSet; | ||
22 | import java.util.List; | 25 | import java.util.List; |
23 | import java.util.Map; | 26 | import java.util.Map; |
27 | +import java.util.Set; | ||
24 | 28 | ||
25 | /** | 29 | /** |
26 | * Created by wangnan on 2016/6/30. | 30 | * Created by wangnan on 2016/6/30. |
@@ -147,4 +151,29 @@ public class ProductGoodsLogicService { | @@ -147,4 +151,29 @@ public class ProductGoodsLogicService { | ||
147 | return productGoodsBOs; | 151 | return productGoodsBOs; |
148 | } | 152 | } |
149 | 153 | ||
154 | + | ||
155 | + /** | ||
156 | + * 获取有库存且状态正常的color | ||
157 | + * @param goodsListJsonArray | ||
158 | + * @param colorIdSet | ||
159 | + * @param colorNameSet | ||
160 | + */ | ||
161 | + public void getColorSet(JSONArray goodsListJsonArray,Set<String> colorIdSet,Set<String> colorNameSet){ | ||
162 | + for (int i = 0; i < goodsListJsonArray.size(); i++) { | ||
163 | + JSONObject jsonObject = goodsListJsonArray.getJSONObject(i); | ||
164 | + //去除无库存和非正常状态的 | ||
165 | + if (!jsonObject.containsKey("status")||!jsonObject.get("status").toString().equals("1")) { | ||
166 | + continue; | ||
167 | + } | ||
168 | + if (!jsonObject.containsKey("storage_num")||((Integer)jsonObject.get("storage_num"))<1) { | ||
169 | + continue; | ||
170 | + } | ||
171 | + if (jsonObject.containsKey("color_id")) { | ||
172 | + colorIdSet.add(jsonObject.get("color_id").toString()); | ||
173 | + } | ||
174 | + if (jsonObject.containsKey("color_name")) { | ||
175 | + colorNameSet.add(jsonObject.get("color_name").toString()); | ||
176 | + } | ||
177 | + } | ||
178 | + } | ||
150 | } | 179 | } |
1 | package com.yoho.search.consumer.service.logic.viewBuilder; | 1 | package com.yoho.search.consumer.service.logic.viewBuilder; |
2 | 2 | ||
3 | -import com.alibaba.fastjson.JSONArray; | ||
4 | -import com.alibaba.fastjson.JSONObject; | ||
5 | -import com.yoho.search.consumer.service.bo.ProductGoodsBO; | ||
6 | -import com.yoho.search.consumer.service.bo.ProductIndexBO; | ||
7 | -import com.yoho.search.consumer.service.logic.tools.MapGenerator; | 3 | +import java.util.HashSet; |
4 | +import java.util.List; | ||
5 | +import java.util.Map; | ||
6 | +import java.util.Set; | ||
8 | 7 | ||
9 | import org.apache.commons.lang.StringUtils; | 8 | import org.apache.commons.lang.StringUtils; |
10 | import org.springframework.beans.factory.annotation.Autowired; | 9 | import org.springframework.beans.factory.annotation.Autowired; |
11 | import org.springframework.stereotype.Component; | 10 | import org.springframework.stereotype.Component; |
12 | 11 | ||
13 | -import java.util.HashSet; | ||
14 | -import java.util.List; | ||
15 | -import java.util.Map; | ||
16 | -import java.util.Set; | 12 | +import com.alibaba.fastjson.JSONArray; |
13 | +import com.yoho.search.consumer.service.bo.ProductGoodsBO; | ||
14 | +import com.yoho.search.consumer.service.bo.ProductIndexBO; | ||
15 | +import com.yoho.search.consumer.service.logic.productIndex.ProductGoodsLogicService; | ||
16 | +import com.yoho.search.consumer.service.logic.tools.MapGenerator; | ||
17 | 17 | ||
18 | /** | 18 | /** |
19 | * Created by wangnan on 2017/1/6. | 19 | * Created by wangnan on 2017/1/6. |
@@ -23,6 +23,9 @@ public class ProductGoodsBuilder implements ViewBuilder{ | @@ -23,6 +23,9 @@ public class ProductGoodsBuilder implements ViewBuilder{ | ||
23 | @Autowired | 23 | @Autowired |
24 | private MapGenerator mapGenerator; | 24 | private MapGenerator mapGenerator; |
25 | 25 | ||
26 | + @Autowired | ||
27 | + private ProductGoodsLogicService productGoodsLogicService; | ||
28 | + | ||
26 | /** | 29 | /** |
27 | * 构建ProductGoods | 30 | * 构建ProductGoods |
28 | */ | 31 | */ |
@@ -41,25 +44,10 @@ public class ProductGoodsBuilder implements ViewBuilder{ | @@ -41,25 +44,10 @@ public class ProductGoodsBuilder implements ViewBuilder{ | ||
41 | productIndexBO.setColorNames(""); | 44 | productIndexBO.setColorNames(""); |
42 | continue; | 45 | continue; |
43 | } | 46 | } |
44 | - JSONArray goodsListJsonArray = JSONArray.parseArray(goodsListJsonArrayStr); | ||
45 | colorIdSet = new HashSet<String>(); | 47 | colorIdSet = new HashSet<String>(); |
46 | colorNameSet = new HashSet<String>(); | 48 | colorNameSet = new HashSet<String>(); |
47 | - for (int i = 0; i < goodsListJsonArray.size(); i++) { | ||
48 | - JSONObject jsonObject = goodsListJsonArray.getJSONObject(i); | ||
49 | - //去除无库存和非正常状态的 | ||
50 | - if (!jsonObject.containsKey("status")||!jsonObject.get("status").toString().equals("1")) { | ||
51 | - continue; | ||
52 | - } | ||
53 | - if (!jsonObject.containsKey("storage_num")||((Integer)jsonObject.get("storage_num"))<1) { | ||
54 | - continue; | ||
55 | - } | ||
56 | - if (jsonObject.containsKey("color_id")) { | ||
57 | - colorIdSet.add(jsonObject.get("color_id").toString()); | ||
58 | - } | ||
59 | - if (jsonObject.containsKey("color_name")) { | ||
60 | - colorNameSet.add(jsonObject.get("color_name").toString()); | ||
61 | - } | ||
62 | - } | 49 | + JSONArray goodsListJsonArray = JSONArray.parseArray(goodsListJsonArrayStr); |
50 | + productGoodsLogicService.getColorSet(goodsListJsonArray, colorIdSet, colorNameSet);//获取有库存且状态正常的color | ||
63 | productIndexBO.setColorIds(StringUtils.join(colorIdSet, ",")); | 51 | productIndexBO.setColorIds(StringUtils.join(colorIdSet, ",")); |
64 | productIndexBO.setColorNames(StringUtils.join(colorNameSet, ",")); | 52 | productIndexBO.setColorNames(StringUtils.join(colorNameSet, ",")); |
65 | 53 |
-
Please register or login to post a comment