Authored by wangnan

skn下面所有skc状态为0,则skn状态为0 fix

... ... @@ -16,6 +16,7 @@ import com.yoho.search.consumer.service.logic.StorageSkuLogicService;
import com.yoho.search.core.es.utils.IgnoreSomeException;
import com.yoho.search.dal.model.Goods;
import com.yoho.search.dal.model.Product;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -79,7 +80,7 @@ public class GoodsMqListener extends AbstractStorageRelatedMqListener implements
//判断skn状态
Map<String, Object> indexData = new HashMap<String, Object>();
Integer productId = goods.getProductId();
this.fillSknStatus(productId,indexData);
this.fillSknStatus(productId, indexData);
this.updateProductIndexWithDataMap(indexData, productId, key, begin);
// 2、删除数据库数据
... ... @@ -144,7 +145,7 @@ public class GoodsMqListener extends AbstractStorageRelatedMqListener implements
logger.info("[model=GoodsMqListener_UpdateIndexNew][step=fillProductStorage][productId={}][cost={}]", productId, costStatistics.getCost());
// 第三步,判断skn状态
this.fillSknStatus(productId,indexData);
this.fillSknStatus(productId, indexData);
logger.info("[model=GoodsMqListener_UpdateIndexNew][step=fillSknStatus][productId={}][cost={}]", productId, costStatistics.getCost());
... ... @@ -155,12 +156,18 @@ public class GoodsMqListener extends AbstractStorageRelatedMqListener implements
}
private void fillSknStatus(Integer productId,Map<String, Object> indexData) {
/**
* 如果skn下面所有skc的状态都是0,那skn的状态设为0,更新和删除都需要验证
*/
private void fillSknStatus(Integer productId, Map<String, Object> indexData) {
List<Integer> ids = new ArrayList<>();
ids.add(productId);
List<Goods> goodss = goodsService.getListByProductId(ids);
List<Goods> goodsList = goodsService.getListByProductId(ids);
if (CollectionUtils.isEmpty(goodsList)) {
return;
}
boolean sknInvalid = true;
for (Goods goods : goodss) {
for (Goods goods : goodsList) {
if (goods.getStatus() == 1) {
sknInvalid = false;
}
... ... @@ -168,8 +175,9 @@ public class GoodsMqListener extends AbstractStorageRelatedMqListener implements
if (sknInvalid) {
indexData.put("status", 0);
} else {
//需要检查product表的status字段,如果为1才更新状态,为0则以product表的状态为准
Product product = productService.getById(productId);
if (product!=null&&product.getStatus() == 1) {
if (product != null && product.getStatus() == 1) {
indexData.put("status", 1);
}
}
... ...
... ... @@ -6,7 +6,6 @@ import com.yoho.search.consumer.service.base.ProductService;
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.dal.model.Product;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
... ... @@ -28,7 +27,7 @@ public class ProductGoodsBuilder implements ViewBuilder {
private ProductService productService;
/**
* 构建ProductGoods
* 构建ProductIndex的ColorIds,ColorNames属性
*/
@Override
public void build(List<ProductIndexBO> productIndexBOs, List<Integer> ids, List<Integer> skns) {
... ... @@ -39,29 +38,8 @@ public class ProductGoodsBuilder implements ViewBuilder {
for (ProductIndexBO productIndexBO : productIndexBOs) {
ProductGoodsBO productGoodsBO = productGoodsesMap.get(productIndexBO.getProductId());
if (productGoodsBO != null) {
this.checkSknStatus(productIndexBO, productGoodsBO);
productIndexBO.setGoodsList(productGoodsBO.getGoodsList());
//如果skn下面所有skc的状态都是0,那skn的状态设为0
JSONArray jsonArray = JSONArray.parseArray(productGoodsBO.getGoodsList());
boolean sknInvalid = true;
for (int i = 0; i < jsonArray.size(); i++) {
JSONObject jsonObject = (JSONObject) jsonArray.get(i);
if (jsonObject.get("status") != null) {
String status = jsonObject.get("status").toString();
if (status.equals("1")) {
sknInvalid = false;
}
}
}
if (sknInvalid) {
productIndexBO.setStatus(0);
} else {
Product product = productService.getById(productIndexBO.getProductId());
if (product.getStatus() == 1) {
productIndexBO.setStatus(1);
}
}
String goodsListJsonArrayStr = productGoodsBO.getGoodsList();
if (goodsListJsonArrayStr == null || goodsListJsonArrayStr.length() < 3) {
productIndexBO.setColorIds("");
... ... @@ -78,4 +56,27 @@ public class ProductGoodsBuilder implements ViewBuilder {
}
}
}
/**
* 如果skn下面所有skc的状态都是0,那skn的状态设为0
* 和增量不同之处:不存在status从0->1,只存在1->0
*/
private void checkSknStatus(ProductIndexBO productIndexBO, ProductGoodsBO productGoodsBO) {
JSONArray jsonArray = JSONArray.parseArray(productGoodsBO.getGoodsList());
if (jsonArray != null) {
boolean sknInvalid = true;
for (int i = 0; i < jsonArray.size(); i++) {
JSONObject jsonObject = (JSONObject) jsonArray.get(i);
if (jsonObject!=null&&jsonObject.get("status") != null) {
String status = jsonObject.get("status").toString();
if (status.equals("1")) {
sknInvalid = false;
}
}
}
if (sknInvalid) {
productIndexBO.setStatus(0);
}
}
}
}
... ...