storage表变动时,同时更新pi中的color信息
Showing
1 changed file
with
31 additions
and
0 deletions
@@ -17,6 +17,7 @@ import org.springframework.amqp.rabbit.core.ChannelAwareMessageListener; | @@ -17,6 +17,7 @@ import org.springframework.amqp.rabbit.core.ChannelAwareMessageListener; | ||
17 | import org.springframework.beans.factory.annotation.Autowired; | 17 | import org.springframework.beans.factory.annotation.Autowired; |
18 | import org.springframework.stereotype.Component; | 18 | import org.springframework.stereotype.Component; |
19 | 19 | ||
20 | +import com.alibaba.fastjson.JSONArray; | ||
20 | import com.alibaba.fastjson.JSONObject; | 21 | import com.alibaba.fastjson.JSONObject; |
21 | import com.rabbitmq.client.Channel; | 22 | import com.rabbitmq.client.Channel; |
22 | import com.yoho.error.event.SearchEvent; | 23 | import com.yoho.error.event.SearchEvent; |
@@ -26,11 +27,14 @@ import com.yoho.search.base.utils.ISearchConstants; | @@ -26,11 +27,14 @@ import com.yoho.search.base.utils.ISearchConstants; | ||
26 | import com.yoho.search.consumer.common.CostStatistics; | 27 | import com.yoho.search.consumer.common.CostStatistics; |
27 | import com.yoho.search.consumer.index.common.IYohoIndexService; | 28 | import com.yoho.search.consumer.index.common.IYohoIndexService; |
28 | import com.yoho.search.consumer.index.increment.bulks.StorageSkuIndexBulkService; | 29 | import com.yoho.search.consumer.index.increment.bulks.StorageSkuIndexBulkService; |
30 | +import com.yoho.search.consumer.service.base.GoodsService; | ||
29 | import com.yoho.search.consumer.service.base.Product15DaySalesNumService; | 31 | import com.yoho.search.consumer.service.base.Product15DaySalesNumService; |
30 | import com.yoho.search.consumer.service.base.ProductPoolDetailService; | 32 | import com.yoho.search.consumer.service.base.ProductPoolDetailService; |
31 | import com.yoho.search.consumer.service.base.ProductService; | 33 | import com.yoho.search.consumer.service.base.ProductService; |
32 | import com.yoho.search.consumer.service.base.StorageService; | 34 | import com.yoho.search.consumer.service.base.StorageService; |
35 | +import com.yoho.search.consumer.service.bo.ProductGoodsBO; | ||
33 | import com.yoho.search.consumer.service.logic.ProductIndexLogicService; | 36 | import com.yoho.search.consumer.service.logic.ProductIndexLogicService; |
37 | +import com.yoho.search.consumer.service.logic.productIndex.ProductGoodsLogicService; | ||
34 | import com.yoho.search.consumer.service.logic.productIndex.StorageUpdateTimeLogicService; | 38 | import com.yoho.search.consumer.service.logic.productIndex.StorageUpdateTimeLogicService; |
35 | import com.yoho.search.core.es.utils.IgnoreSomeException; | 39 | import com.yoho.search.core.es.utils.IgnoreSomeException; |
36 | import com.yoho.search.dal.model.Product; | 40 | import com.yoho.search.dal.model.Product; |
@@ -57,6 +61,10 @@ public class StorageMqListener extends AbstractMqListener implements ChannelAwar | @@ -57,6 +61,10 @@ public class StorageMqListener extends AbstractMqListener implements ChannelAwar | ||
57 | private ProductIndexLogicService productIndexLogicService; | 61 | private ProductIndexLogicService productIndexLogicService; |
58 | @Autowired | 62 | @Autowired |
59 | private StorageUpdateTimeLogicService storageUpdateTimeLogicService; | 63 | private StorageUpdateTimeLogicService storageUpdateTimeLogicService; |
64 | + @Autowired | ||
65 | + private GoodsService goodsService; | ||
66 | + @Autowired | ||
67 | + private ProductGoodsLogicService productGoodsLogicService; | ||
60 | 68 | ||
61 | @Override | 69 | @Override |
62 | public void onMessage(Message message, Channel channel) throws Exception { | 70 | public void onMessage(Message message, Channel channel) throws Exception { |
@@ -181,7 +189,30 @@ public class StorageMqListener extends AbstractMqListener implements ChannelAwar | @@ -181,7 +189,30 @@ public class StorageMqListener extends AbstractMqListener implements ChannelAwar | ||
181 | StorageUpdateTime storageUpdateTime = storageUpdateTimes.get(0); | 189 | StorageUpdateTime storageUpdateTime = storageUpdateTimes.get(0); |
182 | indexData.put("storageUpdateTime", storageUpdateTime.getStorageUpdateTime()); | 190 | indexData.put("storageUpdateTime", storageUpdateTime.getStorageUpdateTime()); |
183 | } | 191 | } |
192 | + //更新color相关信息 | ||
193 | + fillColor(indexData,productId); | ||
184 | this.updateProductIndexWithDataMap(indexData, productId, key, begin); | 194 | this.updateProductIndexWithDataMap(indexData, productId, key, begin); |
185 | } | 195 | } |
196 | + | ||
197 | + private void fillColor(Map<String, Object> indexData,Integer productId){ | ||
198 | + Set<String> colorIdSet = new HashSet<String>(); | ||
199 | + Set<String> colorNameSet = new HashSet<String>(); | ||
200 | + // 第一步:获取goodsList | ||
201 | + List<ProductGoodsBO> productGoodsBOList = goodsService.getProductGoodsByProductId(productId); | ||
202 | + // 第二步、组装goods数据 | ||
203 | + if (productGoodsBOList != null && productGoodsBOList.size() == 1) { | ||
204 | + ProductGoodsBO productGoodsBO = productGoodsBOList.get(0); | ||
205 | + String goodsListJsonArrayStr = productGoodsBO.getGoodsList(); | ||
206 | + JSONArray goodsListJsonArray = JSONArray.parseArray(goodsListJsonArrayStr); | ||
207 | + productGoodsLogicService.getColorSet(goodsListJsonArray, colorIdSet, colorNameSet);//获取有库存且状态正常的color | ||
208 | + indexData.put("goodsList", goodsListJsonArray); | ||
209 | + indexData.put("colorIds", StringUtils.join(colorIdSet, ",")); | ||
210 | + indexData.put("colorNames", StringUtils.join(colorNameSet, ",")); | ||
211 | + } else { | ||
212 | + indexData.put("goodsList", ""); | ||
213 | + indexData.put("colorIds", ""); | ||
214 | + indexData.put("colorNames", ""); | ||
215 | + } | ||
216 | + } | ||
186 | 217 | ||
187 | } | 218 | } |
-
Please register or login to post a comment