|
|
package com.yoho.search.consumer.index.increment;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.HashSet;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Set;
|
|
|
import java.util.UUID;
|
|
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.amqp.core.Message;
|
|
|
import org.springframework.amqp.rabbit.core.ChannelAwareMessageListener;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.rabbitmq.client.Channel;
|
...
|
...
|
@@ -24,39 +8,36 @@ import com.yoho.search.base.utils.ConvertUtils; |
|
|
import com.yoho.search.base.utils.EventReportEnum;
|
|
|
import com.yoho.search.base.utils.ISearchConstants;
|
|
|
import com.yoho.search.consumer.common.CostStatistics;
|
|
|
import com.yoho.search.consumer.index.common.IYohoIndexService;
|
|
|
import com.yoho.search.consumer.index.increment.bulks.StorageSkuIndexBulkService;
|
|
|
import com.yoho.search.consumer.index.increment.rule.AbstractStorageRelatedMqListener;
|
|
|
import com.yoho.search.consumer.service.base.GoodsService;
|
|
|
import com.yoho.search.consumer.service.base.Product15DaySalesNumService;
|
|
|
import com.yoho.search.consumer.service.base.ProductService;
|
|
|
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;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.amqp.core.Message;
|
|
|
import org.springframework.amqp.rabbit.core.ChannelAwareMessageListener;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
@Component
|
|
|
public class GoodsMqListener extends AbstractMqListener implements ChannelAwareMessageListener {
|
|
|
public class GoodsMqListener extends AbstractStorageRelatedMqListener implements ChannelAwareMessageListener {
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(GoodsMqListener.class);
|
|
|
@Autowired
|
|
|
private IYohoIndexService indexService;
|
|
|
@Autowired
|
|
|
private GoodsService goodsService;
|
|
|
@Autowired
|
|
|
private StorageService storageService;
|
|
|
@Autowired
|
|
|
private StorageSkuIndexBulkService storageSkuIndexService;
|
|
|
@Autowired
|
|
|
private Product15DaySalesNumService product15DaySalesNumService;
|
|
|
@Autowired
|
|
|
private StorageSkuLogicService storageSkuLogicService;
|
|
|
@Autowired
|
|
|
private ProductService productService;
|
|
|
@Autowired
|
|
|
private ProductGoodsLogicService productGoodsLogicService;
|
|
|
|
|
|
public void onMessage(Message message, Channel channel) throws Exception {
|
...
|
...
|
@@ -172,46 +153,11 @@ public class GoodsMqListener extends AbstractMqListener implements ChannelAwareM |
|
|
logger.info("[model=GoodsMqListener_UpdateIndexNew][step=genGoodsList][productId={}][cost={}]", productId, costStatistics.getCost());
|
|
|
|
|
|
// 第三步、组装库存数据
|
|
|
this.fillProductStorage(productId, indexData);
|
|
|
this.fillStorageNumAndSizeInfo(productId, indexData);
|
|
|
logger.info("[model=GoodsMqListener_UpdateIndexNew][step=fillProductStorage][productId={}][cost={}]", productId, costStatistics.getCost());
|
|
|
|
|
|
// 第四步:更新索引
|
|
|
this.updateProductIndexWithDataMap(indexData, productId, key, begin);
|
|
|
logger.info("[model=GoodsMqListener_UpdateIndexNew][step=updateProductIndexWithDataMap][productId={}][cost={}]", productId, costStatistics.getCost());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 更新库存
|
|
|
*
|
|
|
* @param productId
|
|
|
* @param indexData
|
|
|
*/
|
|
|
private void fillProductStorage(Integer productId, Map<String, Object> indexData) {
|
|
|
// 第三步、更新库存
|
|
|
List<Storage> storageList = storageService.getStoragesByProductId(productId);
|
|
|
if (storageList.isEmpty()) {
|
|
|
indexData.put("storageNum", null);
|
|
|
indexData.put("isSoonSoldOut", null);
|
|
|
indexData.put("isSoldOut", null);
|
|
|
indexData.put("soldOut", null);
|
|
|
indexData.put("sizeIds", null);
|
|
|
} else {
|
|
|
int storageNum = 0;
|
|
|
Set<String> sizeSet = new HashSet<String>();
|
|
|
for (Storage stor : storageList) {
|
|
|
storageNum += stor.getStorageNum();
|
|
|
if (stor.getGoodsDimensionId() != null) {
|
|
|
sizeSet.add(stor.getGoodsDimensionId() + "");
|
|
|
}
|
|
|
}
|
|
|
indexData.put("storageNum", storageNum);
|
|
|
indexData.put("isSoonSoldOut", storageNum <= 2 ? "Y" : "N");
|
|
|
indexData.put("isSoldOut", storageNum == 0 ? "Y" : "N");
|
|
|
indexData.put("soldOut", storageNum == 0 ? 0 : 1);
|
|
|
if (!sizeSet.isEmpty()) {
|
|
|
indexData.put("sizeIds", StringUtils.join(sizeSet, ","));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|