Browse Source

新增物料增加入库功能,goods增加最新包装量

hejq 7 years ago
parent
commit
b11afcb805

+ 1 - 0
src/main/java/com/uas/platform/b2c/prod/commodity/model/Goods.java

@@ -1685,6 +1685,7 @@ public class Goods implements Serializable {
 		goods.setPackaging(product.getPackaging());
 		goods.setProduceDate(product.getProduceDate());
 		goods.setUuid(product.getCmpUuId());
+		goods.setMinPackQty(product.getMinPackQty());
 		return goods;
 	}
 

+ 56 - 15
src/main/java/com/uas/platform/b2c/prod/commodity/service/impl/ProductServiceImpl.java

@@ -2441,6 +2441,8 @@ public class ProductServiceImpl implements ProductService {
         }
         Product productInfo = new Product();
         CommodityInOutbound inOutbound = null;
+        // 是否需要增加出入库记录
+        boolean needAddInventory = false;
         // 物料存在,更新
         List<V_ProductPrivate> existProducts = v_productPrivateDao.findProductByPcmpcodeAndPbrandenAndEnUU(product.getCmpCode(), product.getBrand(), enUU);
         if (CollectionUtils.isNotEmpty(existProducts)) {
@@ -2451,10 +2453,16 @@ public class ProductServiceImpl implements ProductService {
         } else {
             // 物料不存在,新增操作
             productInfo = product;
-            inOutbound = recordInventory(product, null);
+            needAddInventory = true;
         }
         if (null == productInfo.getStandard()) {
-            productInfo.setStandard(IntegerConstant.NO_SHORT);
+            // 判断传入的数据是否是标准的
+            ResultMap criterionResultMap = checkCriterion(product);
+            if (Objects.equals(CodeType.ERROR.code(), criterionResultMap.getCode())) {
+                productInfo.setStandard(IntegerConstant.NO_SHORT);
+            } else {
+                productInfo.setStandard(IntegerConstant.YES_SHORT);
+            }
         }
         if (StringUtilB2C.isEmpty(productInfo.getProdNum())) {
             String code = "PNUM" + createNumberService.getTimeNumber("trade$product_import_num", 8);
@@ -2471,6 +2479,50 @@ public class ProductServiceImpl implements ProductService {
         // 设置库存信息
         assignmentGoods(goods, productInfo);
         // 保存到商城私有库
+        addToPrivate(productInfo, product);
+        if (needAddInventory) {
+            inOutbound = initCommodityInOut(productInfo);
+        }
+        // 保存出入库信息
+        if (null != inOutbound) {
+            for (InOutboundDetail detail : inOutbound.getInOutboundDetails()) {
+                detail.setCommodityInOutbound(inOutbound);
+            }
+            inOutbound = commodityInOutboundDao.save(inOutbound);
+            logger.info("出入库历史", "卖家中心单个物料上传进行入库操作", inOutbound.getType(), "", inOutbound.getId());
+        }
+        // 添加到个人物料库
+        bindToPerson(productInfo, userUU, enUU);
+        return ResultMap.success();
+    }
+
+    /**
+     * 新增库存记录
+     *
+     * @param productInfo 物料信息
+     * @return CommodityInOutbound
+     */
+    private CommodityInOutbound initCommodityInOut(Product productInfo) {
+        CommodityInOutbound inOutbound = new CommodityInOutbound(InOutBoundType.OTHER_INBOUND);
+        Goods goods = new Goods();
+        goods = Goods.productConvertGoods(goods, productInfo);
+        goods.setReserve(productInfo.getErpReserve());
+        goods = goodsDao.save(goods);
+        logger.info("上架商品库存操作", "卖家中心单个物料上传进行入库操作", "增加库存: " + productInfo.getErpReserve(), goods.getCode(), goods.getId());
+        InOutboundDetail inOutboundDetail = new InOutboundDetail(productInfo);
+        Set<InOutboundDetail> detailSet = new HashSet<>();
+        detailSet.add(inOutboundDetail);
+        inOutbound.setInOutboundDetails(detailSet);
+        return inOutbound;
+    }
+
+    /**
+     * 保存到商城私有库
+     *
+     * @param productInfo
+     * @param product
+     */
+    private void addToPrivate(Product productInfo, Product product) {
         List<ProductPrivate> productPrivates = productPrivateDao.findByPrId(productInfo.getId());
         if (CollectionUtils.isEmpty(productPrivates)) {
             ProductPrivate productPrivate = new ProductPrivate(productInfo.getId());
@@ -2484,17 +2536,6 @@ public class ProductServiceImpl implements ProductService {
                 productPrivateDao.save(productPrivate);
             }
         }
-        // 保存出入库信息
-        if (null != inOutbound) {
-            for (InOutboundDetail detail : inOutbound.getInOutboundDetails()) {
-                detail.setCommodityInOutbound(inOutbound);
-            }
-            inOutbound = commodityInOutboundDao.save(inOutbound);
-            logger.info("出入库历史", "卖家中心单个物料上传进行入库操作", inOutbound.getType(), "", inOutbound.getId());
-        }
-        // 添加到个人物料库
-        bindToPerson(productInfo, userUU, enUU);
-        return ResultMap.success();
     }
 
     /**
@@ -2584,7 +2625,7 @@ public class ProductServiceImpl implements ProductService {
         String type;
         CommodityInOutbound inOutbound;
         // 原库存不存在或者当前库存大于原库存,入库
-        if (null == existProduct || existProduct.getErpReserve() == null || product.getErpReserve() > existProduct.getErpReserve()) {
+        if (existProduct.getErpReserve() == null || product.getErpReserve() > existProduct.getErpReserve()) {
             type = InOutBoundType.OTHER_INBOUND;
             inOutbound = new CommodityInOutbound(type);
             goodsInventory(product.getErpReserve(), type, existProduct.getId());
@@ -2622,7 +2663,7 @@ public class ProductServiceImpl implements ProductService {
                 Goods goods = goodsList.get(0);
                 Double reserve = goods.getReserve() != null ? goods.getReserve() : 0D + addQty;
                 goods.setReserve(reserve);
-                goodsDao.save(goods);
+                goods = goodsDao.save(goods);
                 logger.info("上架商品库存操作", "卖家中心单个物料上传进行入库操作", "增加库存: " + addQty, goods.getCode(), goods.getId());
             } else if (InOutBoundType.OTHER_OUTBOUND.equals(type)) {
                 // 出库