Browse Source

批量上架的基本方法格式

hulh 8 years ago
parent
commit
d88a258575

+ 10 - 0
src/main/java/com/uas/platform/b2c/prod/commodity/dao/GoodsDao.java

@@ -470,6 +470,16 @@ public interface GoodsDao extends JpaSpecificationExecutor<Goods>, JpaRepository
     @Query(value = "select g from Goods g where g.sourceId =:sourceId")
 	List<Goods> findBySourceId(@Param("sourceId") Long id);
 
+    /**
+     * 查询物料id和指定状态的商品
+     *
+     * @param id
+     * @param statusList
+     * @return
+     */
+    @Query(value = "select g from Goods g where g.productid =:productId and g.status in :status order by g.id desc")
+    List<Goods> findByProductIdInStatus(@Param("productId") Long id, @Param("status") List<Integer> statusList);
+
 	/**
 	 * 根据productId 获取goods
 	 *

+ 36 - 0
src/main/java/com/uas/platform/b2c/prod/commodity/service/impl/GoodsServiceImpl.java

@@ -1273,6 +1273,10 @@ public class GoodsServiceImpl implements GoodsService {
     @Override
     public ResultMap putOn(Long id) {
         Goods goods = goodsDao.findOne(id);
+        return putOnGoods(goods);
+    }
+
+    private ResultMap putOnGoods(Goods goods) {
         if (goods != null) {
             setGoodsDefault(goods);
             ResultMap resultMap = checkGoods(goods);
@@ -3133,4 +3137,36 @@ public class GoodsServiceImpl implements GoodsService {
         goodsDao.save(goodses);
         return String.valueOf(goodses.size());
     }
+
+    public ResultMap batchOnSale(List<Long> idList) {
+        Map<String, Object> result = new HashMap<>();
+        List<Integer> statusList = Arrays.asList(Status.AVAILABLE.value(), Status.UNAVAILABLE.value());
+        for (Long id : idList) {
+            Product aProduct = productDao.findOne(id);
+            if (aProduct == null) {
+                continue;
+            }
+            ProductDetail detail = productDetailDao.findByProductId(id);
+            if (detail != null) {
+                // 判断是否已有上架商品
+                List<Goods> goodsList = goodsDao.findByProductIdInStatus(id, statusList);
+                if (CollectionUtils.isEmpty(goodsList)) {
+                    // 生成Goods信息
+                    Goods goods = fillDataInGoods(detail);
+                    ResultMap resultMap = putOnGoods(goods);
+                }
+            }
+        }
+        return ResultMap.success(result);
+    }
+
+    /**
+     * 填充相应字段
+     * @param detail
+     * @return
+     */
+    private Goods fillDataInGoods(ProductDetail detail) {
+        Goods goods = new Goods();
+        return goods;
+    }
 }