skn下面所有skc状态为0,则skn状态为0 fix
Showing
2 changed files
with
39 additions
and
30 deletions
@@ -16,6 +16,7 @@ import com.yoho.search.consumer.service.logic.StorageSkuLogicService; | @@ -16,6 +16,7 @@ import com.yoho.search.consumer.service.logic.StorageSkuLogicService; | ||
16 | import com.yoho.search.core.es.utils.IgnoreSomeException; | 16 | import com.yoho.search.core.es.utils.IgnoreSomeException; |
17 | import com.yoho.search.dal.model.Goods; | 17 | import com.yoho.search.dal.model.Goods; |
18 | import com.yoho.search.dal.model.Product; | 18 | import com.yoho.search.dal.model.Product; |
19 | +import org.apache.commons.collections.CollectionUtils; | ||
19 | import org.apache.commons.lang.StringUtils; | 20 | import org.apache.commons.lang.StringUtils; |
20 | import org.slf4j.Logger; | 21 | import org.slf4j.Logger; |
21 | import org.slf4j.LoggerFactory; | 22 | import org.slf4j.LoggerFactory; |
@@ -79,7 +80,7 @@ public class GoodsMqListener extends AbstractStorageRelatedMqListener implements | @@ -79,7 +80,7 @@ public class GoodsMqListener extends AbstractStorageRelatedMqListener implements | ||
79 | //判断skn状态 | 80 | //判断skn状态 |
80 | Map<String, Object> indexData = new HashMap<String, Object>(); | 81 | Map<String, Object> indexData = new HashMap<String, Object>(); |
81 | Integer productId = goods.getProductId(); | 82 | Integer productId = goods.getProductId(); |
82 | - this.fillSknStatus(productId,indexData); | 83 | + this.fillSknStatus(productId, indexData); |
83 | this.updateProductIndexWithDataMap(indexData, productId, key, begin); | 84 | this.updateProductIndexWithDataMap(indexData, productId, key, begin); |
84 | 85 | ||
85 | // 2、删除数据库数据 | 86 | // 2、删除数据库数据 |
@@ -144,7 +145,7 @@ public class GoodsMqListener extends AbstractStorageRelatedMqListener implements | @@ -144,7 +145,7 @@ public class GoodsMqListener extends AbstractStorageRelatedMqListener implements | ||
144 | logger.info("[model=GoodsMqListener_UpdateIndexNew][step=fillProductStorage][productId={}][cost={}]", productId, costStatistics.getCost()); | 145 | logger.info("[model=GoodsMqListener_UpdateIndexNew][step=fillProductStorage][productId={}][cost={}]", productId, costStatistics.getCost()); |
145 | 146 | ||
146 | // 第三步,判断skn状态 | 147 | // 第三步,判断skn状态 |
147 | - this.fillSknStatus(productId,indexData); | 148 | + this.fillSknStatus(productId, indexData); |
148 | 149 | ||
149 | logger.info("[model=GoodsMqListener_UpdateIndexNew][step=fillSknStatus][productId={}][cost={}]", productId, costStatistics.getCost()); | 150 | logger.info("[model=GoodsMqListener_UpdateIndexNew][step=fillSknStatus][productId={}][cost={}]", productId, costStatistics.getCost()); |
150 | 151 | ||
@@ -155,12 +156,18 @@ public class GoodsMqListener extends AbstractStorageRelatedMqListener implements | @@ -155,12 +156,18 @@ public class GoodsMqListener extends AbstractStorageRelatedMqListener implements | ||
155 | } | 156 | } |
156 | 157 | ||
157 | 158 | ||
158 | - private void fillSknStatus(Integer productId,Map<String, Object> indexData) { | 159 | + /** |
160 | + * 如果skn下面所有skc的状态都是0,那skn的状态设为0,更新和删除都需要验证 | ||
161 | + */ | ||
162 | + private void fillSknStatus(Integer productId, Map<String, Object> indexData) { | ||
159 | List<Integer> ids = new ArrayList<>(); | 163 | List<Integer> ids = new ArrayList<>(); |
160 | ids.add(productId); | 164 | ids.add(productId); |
161 | - List<Goods> goodss = goodsService.getListByProductId(ids); | 165 | + List<Goods> goodsList = goodsService.getListByProductId(ids); |
166 | + if (CollectionUtils.isEmpty(goodsList)) { | ||
167 | + return; | ||
168 | + } | ||
162 | boolean sknInvalid = true; | 169 | boolean sknInvalid = true; |
163 | - for (Goods goods : goodss) { | 170 | + for (Goods goods : goodsList) { |
164 | if (goods.getStatus() == 1) { | 171 | if (goods.getStatus() == 1) { |
165 | sknInvalid = false; | 172 | sknInvalid = false; |
166 | } | 173 | } |
@@ -168,8 +175,9 @@ public class GoodsMqListener extends AbstractStorageRelatedMqListener implements | @@ -168,8 +175,9 @@ public class GoodsMqListener extends AbstractStorageRelatedMqListener implements | ||
168 | if (sknInvalid) { | 175 | if (sknInvalid) { |
169 | indexData.put("status", 0); | 176 | indexData.put("status", 0); |
170 | } else { | 177 | } else { |
178 | + //需要检查product表的status字段,如果为1才更新状态,为0则以product表的状态为准 | ||
171 | Product product = productService.getById(productId); | 179 | Product product = productService.getById(productId); |
172 | - if (product!=null&&product.getStatus() == 1) { | 180 | + if (product != null && product.getStatus() == 1) { |
173 | indexData.put("status", 1); | 181 | indexData.put("status", 1); |
174 | } | 182 | } |
175 | } | 183 | } |
@@ -6,7 +6,6 @@ import com.yoho.search.consumer.service.base.ProductService; | @@ -6,7 +6,6 @@ import com.yoho.search.consumer.service.base.ProductService; | ||
6 | import com.yoho.search.consumer.service.bo.ProductGoodsBO; | 6 | import com.yoho.search.consumer.service.bo.ProductGoodsBO; |
7 | import com.yoho.search.consumer.service.bo.ProductIndexBO; | 7 | import com.yoho.search.consumer.service.bo.ProductIndexBO; |
8 | import com.yoho.search.consumer.service.logic.productIndex.ProductGoodsLogicService; | 8 | import com.yoho.search.consumer.service.logic.productIndex.ProductGoodsLogicService; |
9 | -import com.yoho.search.dal.model.Product; | ||
10 | import org.apache.commons.lang.StringUtils; | 9 | import org.apache.commons.lang.StringUtils; |
11 | import org.springframework.beans.factory.annotation.Autowired; | 10 | import org.springframework.beans.factory.annotation.Autowired; |
12 | import org.springframework.stereotype.Component; | 11 | import org.springframework.stereotype.Component; |
@@ -28,7 +27,7 @@ public class ProductGoodsBuilder implements ViewBuilder { | @@ -28,7 +27,7 @@ public class ProductGoodsBuilder implements ViewBuilder { | ||
28 | private ProductService productService; | 27 | private ProductService productService; |
29 | 28 | ||
30 | /** | 29 | /** |
31 | - * 构建ProductGoods | 30 | + * 构建ProductIndex的ColorIds,ColorNames属性 |
32 | */ | 31 | */ |
33 | @Override | 32 | @Override |
34 | public void build(List<ProductIndexBO> productIndexBOs, List<Integer> ids, List<Integer> skns) { | 33 | public void build(List<ProductIndexBO> productIndexBOs, List<Integer> ids, List<Integer> skns) { |
@@ -39,29 +38,8 @@ public class ProductGoodsBuilder implements ViewBuilder { | @@ -39,29 +38,8 @@ public class ProductGoodsBuilder implements ViewBuilder { | ||
39 | for (ProductIndexBO productIndexBO : productIndexBOs) { | 38 | for (ProductIndexBO productIndexBO : productIndexBOs) { |
40 | ProductGoodsBO productGoodsBO = productGoodsesMap.get(productIndexBO.getProductId()); | 39 | ProductGoodsBO productGoodsBO = productGoodsesMap.get(productIndexBO.getProductId()); |
41 | if (productGoodsBO != null) { | 40 | if (productGoodsBO != null) { |
41 | + this.checkSknStatus(productIndexBO, productGoodsBO); | ||
42 | productIndexBO.setGoodsList(productGoodsBO.getGoodsList()); | 42 | productIndexBO.setGoodsList(productGoodsBO.getGoodsList()); |
43 | - | ||
44 | - //如果skn下面所有skc的状态都是0,那skn的状态设为0 | ||
45 | - JSONArray jsonArray = JSONArray.parseArray(productGoodsBO.getGoodsList()); | ||
46 | - boolean sknInvalid = true; | ||
47 | - for (int i = 0; i < jsonArray.size(); i++) { | ||
48 | - JSONObject jsonObject = (JSONObject) jsonArray.get(i); | ||
49 | - if (jsonObject.get("status") != null) { | ||
50 | - String status = jsonObject.get("status").toString(); | ||
51 | - if (status.equals("1")) { | ||
52 | - sknInvalid = false; | ||
53 | - } | ||
54 | - } | ||
55 | - } | ||
56 | - if (sknInvalid) { | ||
57 | - productIndexBO.setStatus(0); | ||
58 | - } else { | ||
59 | - Product product = productService.getById(productIndexBO.getProductId()); | ||
60 | - if (product.getStatus() == 1) { | ||
61 | - productIndexBO.setStatus(1); | ||
62 | - } | ||
63 | - } | ||
64 | - | ||
65 | String goodsListJsonArrayStr = productGoodsBO.getGoodsList(); | 43 | String goodsListJsonArrayStr = productGoodsBO.getGoodsList(); |
66 | if (goodsListJsonArrayStr == null || goodsListJsonArrayStr.length() < 3) { | 44 | if (goodsListJsonArrayStr == null || goodsListJsonArrayStr.length() < 3) { |
67 | productIndexBO.setColorIds(""); | 45 | productIndexBO.setColorIds(""); |
@@ -78,4 +56,27 @@ public class ProductGoodsBuilder implements ViewBuilder { | @@ -78,4 +56,27 @@ public class ProductGoodsBuilder implements ViewBuilder { | ||
78 | } | 56 | } |
79 | } | 57 | } |
80 | } | 58 | } |
59 | + | ||
60 | + /** | ||
61 | + * 如果skn下面所有skc的状态都是0,那skn的状态设为0 | ||
62 | + * 和增量不同之处:不存在status从0->1,只存在1->0 | ||
63 | + */ | ||
64 | + private void checkSknStatus(ProductIndexBO productIndexBO, ProductGoodsBO productGoodsBO) { | ||
65 | + JSONArray jsonArray = JSONArray.parseArray(productGoodsBO.getGoodsList()); | ||
66 | + if (jsonArray != null) { | ||
67 | + boolean sknInvalid = true; | ||
68 | + for (int i = 0; i < jsonArray.size(); i++) { | ||
69 | + JSONObject jsonObject = (JSONObject) jsonArray.get(i); | ||
70 | + if (jsonObject!=null&&jsonObject.get("status") != null) { | ||
71 | + String status = jsonObject.get("status").toString(); | ||
72 | + if (status.equals("1")) { | ||
73 | + sknInvalid = false; | ||
74 | + } | ||
75 | + } | ||
76 | + } | ||
77 | + if (sknInvalid) { | ||
78 | + productIndexBO.setStatus(0); | ||
79 | + } | ||
80 | + } | ||
81 | + } | ||
81 | } | 82 | } |
-
Please register or login to post a comment