소스 검색

save component's information separately when it has no goods or all goods are invalid

sunyj 8 년 전
부모
커밋
c18f71a504
1개의 변경된 파일29개의 추가작업 그리고 3개의 파일을 삭제
  1. 29 3
      mall-search/src/main/java/com/uas/search/dao/GoodsDao.java

+ 29 - 3
mall-search/src/main/java/com/uas/search/dao/GoodsDao.java

@@ -1,9 +1,9 @@
 package com.uas.search.dao;
 
 import com.uas.search.model.*;
+import com.uas.search.util.CollectionUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Repository;
-import com.uas.search.util.CollectionUtils;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -106,10 +106,15 @@ public class GoodsDao {
         if (component == null || component.getUuid() == null) {
             return null;
         }
-        List<TradeGoods> tradeGoodsesList = tradeGoodsDao.findByCmpUuid(component.getUuid());
         List<Goods> goodsesList = new ArrayList<>();
+        List<TradeGoods> tradeGoodsesList = tradeGoodsDao.findByCmpUuid(component.getUuid());
+        boolean hasValidGoods = false;
         if (!CollectionUtils.isEmpty(tradeGoodsesList)) {
             for (TradeGoods tradeGoods : tradeGoodsesList) {
+                // 判断器件下是否有状态有效的批次
+                if (!hasValidGoods && isValidStatus(tradeGoods.getStatus())) {
+                    hasValidGoods = true;
+                }
                 Store store = null;
                 Products products = null;
                 if (tradeGoods.getStoreId() != null) {
@@ -120,9 +125,30 @@ public class GoodsDao {
                 }
                 goodsesList.add(new Goods(tradeGoods, store, component, products));
             }
-        } else {
+        }
+
+        // 器件下没有状态有效的批次(可能没有批次,或者批次状态全都无效)时,另外保存一份不含批次信息的器件数据
+        if (!hasValidGoods) {
             goodsesList.add(new Goods(null, null, component, null));
         }
         return goodsesList;
     }
+
+    /**
+     * 是否为有效状态
+     *
+     * @param status 状态
+     * @return true 有效;false 无效
+     */
+    private boolean isValidStatus(Long status) {
+        if (status == null) {
+            return false;
+        }
+        for (Long validStatus : TradeGoods.VALID_STATUS) {
+            if (validStatus.longValue() == status.longValue()) {
+                return true;
+            }
+        }
+        return false;
+    }
 }