Browse Source

批量修改

Hu Jie 7 years ago
parent
commit
63dcfa3d13

+ 6 - 1
src/main/java/com/uas/platform/b2c/prod/commodity/service/GoodsService.java

@@ -52,7 +52,12 @@ public interface GoodsService {
      */
     Goods updateAvailableDays(Goods goods, GoodsHistory.OperateType operateType, Long... param);
 
-
+    /**
+     * 设置上架商品基本属性
+     *
+     * @param goods 商品信息
+     */
+    void setGoodsDefault(Goods goods);
 
     /**
      * 根据uuid查找货物信息

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

@@ -36,28 +36,9 @@ import com.uas.platform.b2c.prod.commodity.dao.PCBDao;
 import com.uas.platform.b2c.prod.commodity.dao.ProductDao;
 import com.uas.platform.b2c.prod.commodity.dao.ProductDetailDao;
 import com.uas.platform.b2c.prod.commodity.dao.ProductPrivateDao;
-import com.uas.platform.b2c.prod.commodity.model.Goods;
-import com.uas.platform.b2c.prod.commodity.model.GoodsFilter;
-import com.uas.platform.b2c.prod.commodity.model.GoodsHistory;
+import com.uas.platform.b2c.prod.commodity.model.*;
 import com.uas.platform.b2c.prod.commodity.model.GoodsHistory.OperateType;
-import com.uas.platform.b2c.prod.commodity.model.GoodsInfo;
-import com.uas.platform.b2c.prod.commodity.model.GoodsModifyInfo;
-import com.uas.platform.b2c.prod.commodity.model.GoodsPriceInfo;
-import com.uas.platform.b2c.prod.commodity.model.GoodsQtyPrice;
-import com.uas.platform.b2c.prod.commodity.model.GoodsSimple;
-import com.uas.platform.b2c.prod.commodity.model.ModifyInfo;
-import com.uas.platform.b2c.prod.commodity.model.Product;
-import com.uas.platform.b2c.prod.commodity.model.ProductAttachSubmit;
-import com.uas.platform.b2c.prod.commodity.model.ProductDetail;
-import com.uas.platform.b2c.prod.commodity.model.ProductPrivate;
-import com.uas.platform.b2c.prod.commodity.model.V_ProductPrivate;
-import com.uas.platform.b2c.prod.commodity.service.GoodsHistoryService;
-import com.uas.platform.b2c.prod.commodity.service.GoodsPriceInfoService;
-import com.uas.platform.b2c.prod.commodity.service.GoodsService;
-import com.uas.platform.b2c.prod.commodity.service.ProductAttachService;
-import com.uas.platform.b2c.prod.commodity.service.ProductPrivateService;
-import com.uas.platform.b2c.prod.commodity.service.ProductService;
-import com.uas.platform.b2c.prod.commodity.service.V_ProductPrivateService;
+import com.uas.platform.b2c.prod.commodity.service.*;
 import com.uas.platform.b2c.prod.commodity.status.ModifyInfoStatus;
 import com.uas.platform.b2c.prod.commodity.type.ModifyConstant;
 import com.uas.platform.b2c.prod.commodity.util.GoodsUtil;
@@ -203,6 +184,9 @@ public class GoodsServiceImpl implements GoodsService {
     @Autowired
     private ComponentDao componentDao;
 
+    @Autowired
+    private InOutboundDetailService inOutboundDetailService;
+
     @Autowired
     private ProductPrivateDao productPrivateDao;
 
@@ -239,6 +223,9 @@ public class GoodsServiceImpl implements GoodsService {
     @Autowired
     private JdbcTemplate jdbcTemplate;
 
+    @Autowired
+    private CommodityInOutboundService commodityInOutboundService;
+
     private final ProductDao productDao;
 
     @Autowired
@@ -594,7 +581,8 @@ public class GoodsServiceImpl implements GoodsService {
      *
      * @param goods
      */
-    private void setGoodsDefault(Goods goods) {
+    @Override
+    public void setGoodsDefault(Goods goods) {
         if (StringUtils.isEmpty(goods.getBatchCode())) {
             String batchCode = EncodingRulesConstant.BATCH.replace("_TIMESTAP_NUMBER",
                     createNumberService.getTimeNumber("product$goods", 8));
@@ -1635,6 +1623,38 @@ public class GoodsServiceImpl implements GoodsService {
         if(nowGoods.getProductid() != null) {
             Product product = productDao.findOne(nowGoods.getProductid());
             if(product != null) {
+                if (!nowGoods.getSpec().equals(oldGoods.getSpec())) {
+                    product.setSpec(oldGoods.getSpec());
+                }
+                if (!nowGoods.getPackaging().equals(oldGoods.getPackaging())) {
+                    product.setPackaging(oldGoods.getPackaging());
+                }
+                if (!nowGoods.getMinPackQty().equals(oldGoods.getMinPackQty())) {
+                    product.setMinPackQty(oldGoods.getMinPackQty());
+                }
+                if (!product.getErpReserve().equals(oldGoods.getReserve())) {
+                    product.setErpReserve(oldGoods.getReserve());
+                    InOutboundDetail inOutboundDetail = new InOutboundDetail(product);
+                    Double qty = NumberUtil.sub(oldGoods.getReserve(), product.getErpReserve());
+                    if (NumberUtil.compare(qty, DoubleConstant.zero) != 0) {
+                        //做出入库记录
+                        inOutboundDetail.setQty(qty);
+                        inOutboundDetail.setPrice(oldGoods.getCostPrice());
+                    }
+                    Set<InOutboundDetail> set = new HashSet<>();
+                    set.add(inOutboundDetail);
+                    if (CollectionUtils.isNotEmpty(set)) {
+                        Map<String, Set<InOutboundDetail>> inOutMap = inOutboundDetailService.initInOutboundDetailByQty(set);
+                        Set<String> stringSet = inOutMap.keySet();
+                        for (String type : stringSet) {
+                            CommodityInOutbound commodityInOutbound = commodityInOutboundService.produceCommodityInOutbound(inOutMap.get(type), type);
+                            if (commodityInOutbound != null) {
+                                commodityInOutboundService.save(commodityInOutbound);
+                            }
+                        }
+                    }
+                }
+                productDao.save(product);
                 if (StringConstant.ERP.equals(product.getSourceApp())) {
                     List<Goods> goodses = goodsDao.findByProductId(product.getId());
                     Double reserve = productService.getGoodsReserveByErpReserve(product.getErpReserve(), goodses);

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

@@ -532,13 +532,22 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 		if (CollectionUtils.isEmpty(batchList)) {
 			return result;
 		}
+		List<Long> productIds = new ArrayList<>(batchList.size());
 		List<String> batchCodes = new ArrayList<>();
 		for (ReleaseProductByBatch aBatch : batchList) {
+			if (!StringUtilB2C.isEmpty(aBatch.getBatchCode()) && RegexConstant.isNumber(aBatch.getBatchCode())) {
+				productIds.add(Long.parseLong(aBatch.getBatchCode()));
+				continue;
+			}
 			if (!StringUtilB2C.isEmpty(aBatch.getBatchCode())) {
 				batchCodes.add(aBatch.getBatchCode());
 			}
 		}
-
+		List<Product> products = new ArrayList<>();
+		if (CollectionUtils.isNotEmpty(productIds)) {
+			products = productDao.findProductInIds(productIds);
+		}
+		Product newProduct = null;
 		List<Goods> goodses = new ArrayList<>();
 		if (CollectionUtils.isNotEmpty(batchCodes)) {
 			goodses = goodsService.findGoodsByBatchCodes(batchCodes);
@@ -547,49 +556,90 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 		List<GoodsHistory> goodsHistoryList = new ArrayList<>();
 		for (ReleaseProductByBatch aBatch : batchList) {
 			newGoods = null;
-			for (Goods goods : goodses) {
-				if (goods.getBatchCode().equals(aBatch.getBatchCode())) {
-					aBatch.setB2cBranden(goods.getBrandNameEn());
-					aBatch.setBrandNameEn(goods.getBrandNameEn());
-					aBatch.setKindName(goods.getKindNameCn());
-					aBatch.setB2cCode(goods.getCode());
-					aBatch.setCode(goods.getCode());
-					aBatch.setCurrency(goods.getCurrencyName());
-					if (goods.getUuid() == null) {
-						aBatch.setReleaseCode(ReleaseStatus.failure.value());
-						aBatch.setReleaseStatus(ReleaseStatus.failure.getPhrase());
+			if (!RegexConstant.isNumber(aBatch.getBatchCode())) {
+				for (Goods goods : goodses) {
+					if (goods.getBatchCode().equals(aBatch.getBatchCode())) {
+						aBatch.setB2cBranden(goods.getBrandNameEn());
+						aBatch.setBrandNameEn(goods.getBrandNameEn());
+						aBatch.setKindName(goods.getKindNameCn());
+						aBatch.setB2cCode(goods.getCode());
+						aBatch.setCode(goods.getCode());
+						aBatch.setCurrency(goods.getCurrencyName());
+						if (goods.getUuid() == null) {
+							aBatch.setReleaseCode(ReleaseStatus.failure.value());
+							aBatch.setReleaseStatus(ReleaseStatus.failure.getPhrase());
+						}
+						fillInGoods(goods, aBatch);
+						newGoods = goods;
+						break;
 					}
-					fillInGoods(goods, aBatch);
-					newGoods = goods;
-					break;
 				}
-			}
-			if (newGoods == null) {
-				newGoods = new Goods();
-				TradeDeliveryDelayTime delayTime = getDelayTime(aBatch);
-				newGoods.setGoodsByReleaseProductByBatch(aBatch, delayTime);
-				goodsHistoryList.add(goodsHistoryService.converTGoodsHist(newGoods, GoodsHistory.OperateType.Publish.getPhrase(), false));
-			}
-			ResultMap resultMap = goodsService.updateGoods(newGoods);
-			if (resultMap.isSuccess()) {
-				Goods goods1 = (Goods) resultMap.getData();
-				if (Status.REMOVED.value() == aBatch.getStatus() && Status.REMOVED.value() != goods1.getStatus()) {
-					ResultMap offMap = goodsService.offShelfGoodsByProvider(newGoods.getBatchCode(), null, false);
-					if (offMap.isSuccess()) {
-						result++;
+				if (newGoods == null) {
+					newGoods = new Goods();
+					TradeDeliveryDelayTime delayTime = getDelayTime(aBatch);
+					newGoods.setGoodsByReleaseProductByBatch(aBatch, delayTime);
+					goodsHistoryList.add(goodsHistoryService.converTGoodsHist(newGoods, GoodsHistory.OperateType.Publish.getPhrase(), false));
+				}
+				ResultMap resultMap = goodsService.updateGoods(newGoods);
+				if (resultMap.isSuccess()) {
+					Goods goods1 = (Goods) resultMap.getData();
+					if (Status.REMOVED.value() == aBatch.getStatus() && Status.REMOVED.value() != goods1.getStatus()) {
+						ResultMap offMap = goodsService.offShelfGoodsByProvider(newGoods.getBatchCode(), null, false);
+						if (offMap.isSuccess()) {
+							result++;
+						} else {
+							aBatch.setErrmsg(offMap.getMessage());
+							aBatch.setReleaseCode(ReleaseStatus.lack_info.value());
+							aBatch.setReleaseStatus(ReleaseStatus.lack_info.getPhrase());
+						}
 					} else {
-						aBatch.setErrmsg(offMap.getMessage());
-						aBatch.setReleaseCode(ReleaseStatus.lack_info.value());
-						aBatch.setReleaseStatus(ReleaseStatus.lack_info.getPhrase());
+						result++;
 					}
 				} else {
-					result++;
+					aBatch.setErrmsg(resultMap.getMessage());
+					aBatch.setReleaseCode(ReleaseStatus.lack_info.value());
+					aBatch.setReleaseStatus(ReleaseStatus.lack_info.getPhrase());
 				}
 			} else {
-				aBatch.setErrmsg(resultMap.getMessage());
-				aBatch.setReleaseCode(ReleaseStatus.lack_info.value());
-				aBatch.setReleaseStatus(ReleaseStatus.lack_info.getPhrase());
+				for (Product product : products) {
+					if (product.getId().equals(Long.parseLong(aBatch.getBatchCode()))) {
+						aBatch.setB2cCode(product.getPcmpcode());
+						aBatch.setProductNum(product.getProdNum());
+						aBatch.setBrandNameEn(product.getBrand());
+						aBatch.setKindName(product.getProdName());
+						aBatch.setCurrency(product.getCurrency());
+						aBatch.setProductNum(product.getProdNum());
+						InOutboundDetail inOutboundDetail = new InOutboundDetail(newProduct);
+						fillInProduct(product, aBatch, inOutboundDetail);
+						newProduct = product;
+						Set<InOutboundDetail> set = new HashSet<>();
+						set.add(inOutboundDetail);
+						if (CollectionUtils.isNotEmpty(set)) {
+							Map<String, Set<InOutboundDetail>> inOutMap = inOutboundDetailService.initInOutboundDetailByQty(set);
+							Set<String> stringSet = inOutMap.keySet();
+							for (String type : stringSet) {
+								CommodityInOutbound commodityInOutbound = commodityInOutboundService.produceCommodityInOutbound(inOutMap.get(type), type);
+								if (commodityInOutbound != null) {
+									commodityInOutboundService.save(commodityInOutbound);
+								}
+							}
+						}
+						productDao.save(newProduct);
+						result++;
+					}
+				}
+				if (StringUtils.isEmpty(newProduct)) {
+					aBatch.setErrmsg("物料SKU码有误");
+					aBatch.setReleaseCode(ReleaseStatus.lack_info.value());
+					aBatch.setReleaseStatus(ReleaseStatus.lack_info.getPhrase());
+				} else {
+					Goods needGoods = new Goods();
+					needGoods.setProductInfo(newProduct);
+					goodsService.setGoodsDefault(needGoods);
+					goodsDao.save(needGoods);
+				}
 			}
+
 		}
 		return result;
 	}
@@ -711,6 +761,43 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 		goods.setStatus(aBatch.getStatus());
 	}
 
+	private void fillInProduct(Product product, ReleaseProductByBatch aBatch, InOutboundDetail inOutboundDetail) {
+		if (!StringUtils.isEmpty(aBatch.getSpec())) {
+			product.setSpec(aBatch.getSpec());
+		}
+		if (!StringUtils.isEmpty(aBatch.getPackaging())) {
+			product.setPackaging(aBatch.getPackaging());
+		}
+		if (!StringUtils.isEmpty(aBatch.getSelfMinDelivery())) {
+			product.setMinDelivery(aBatch.getSelfMinDelivery());
+		}
+		if (!StringUtils.isEmpty(aBatch.getSelfMaxDelivery())) {
+			product.setMaxDelivery(aBatch.getSelfMaxDelivery());
+		}
+		if (!StringUtils.isEmpty(aBatch.getBreakUp())) {
+			product.setBreakUp(aBatch.getBreakUp());
+		}
+		if (!StringUtils.isEmpty(aBatch.getMinPackage())) {
+			product.setMinPackQty(aBatch.getMinPackage());
+		} else {
+			product.setMinPackQty(1d);
+		}
+		if (!StringUtils.isEmpty(aBatch.getCostPrice())) {
+			product.setPrice(aBatch.getCostPrice());
+		}
+		if (!StringUtils.isEmpty(aBatch.getReserve())) {
+			product.setErpReserve(aBatch.getReserve());
+			Double qty = NumberUtil.sub(aBatch.getReserve(), product.getErpReserve());
+			if (NumberUtil.compare(qty, DoubleConstant.zero) != 0) {
+				//做出入库记录
+				product.setErpReserve(aBatch.getReserve());
+				inOutboundDetail = new InOutboundDetail(product);
+				inOutboundDetail.setQty(qty);
+				inOutboundDetail.setPrice(aBatch.getCostPrice());
+			}
+		}
+	}
+
 	private StoreIn getModifyStoreInfo(Object value, StoreIn self, StoreIn consignment) {
 		List<String> sellList = Arrays.asList("自营", "寄售");
 		if (StringUtils.isEmpty(value) || !sellList.contains(StringUtilB2C.getStr(value))) {