Browse Source

增加出入库的逻辑

yujia 7 years ago
parent
commit
3ff13ea9ef
18 changed files with 639 additions and 399 deletions
  1. 8 0
      src/main/java/com/uas/platform/b2c/core/utils/StringUtilB2C.java
  2. 4 8
      src/main/java/com/uas/platform/b2c/external/erp/commodity/service/impl/ProductDetailERPServiceImpl.java
  3. 5 0
      src/main/java/com/uas/platform/b2c/prod/commodity/constant/StringConstant.java
  4. 46 0
      src/main/java/com/uas/platform/b2c/prod/commodity/controller/CommodityInOutboundController.java
  5. 13 2
      src/main/java/com/uas/platform/b2c/prod/commodity/dao/V_ProductPrivateDao.java
  6. 58 37
      src/main/java/com/uas/platform/b2c/prod/commodity/model/Goods.java
  7. 0 8
      src/main/java/com/uas/platform/b2c/prod/commodity/model/GoodsHistory.java
  8. 12 0
      src/main/java/com/uas/platform/b2c/prod/commodity/model/ModifyInfo.java
  9. 23 0
      src/main/java/com/uas/platform/b2c/prod/commodity/model/Product.java
  10. 11 0
      src/main/java/com/uas/platform/b2c/prod/commodity/service/CommodityInOutboundService.java
  11. 6 0
      src/main/java/com/uas/platform/b2c/prod/commodity/service/GoodsService.java
  12. 9 1
      src/main/java/com/uas/platform/b2c/prod/commodity/service/ProductPrivateService.java
  13. 28 0
      src/main/java/com/uas/platform/b2c/prod/commodity/service/V_ProductPrivateService.java
  14. 78 1
      src/main/java/com/uas/platform/b2c/prod/commodity/service/impl/CommodityInOutboundServiceImpl.java
  15. 255 339
      src/main/java/com/uas/platform/b2c/prod/commodity/service/impl/GoodsServiceImpl.java
  16. 17 2
      src/main/java/com/uas/platform/b2c/prod/commodity/service/impl/ProductPrivateServiceImpl.java
  17. 65 0
      src/main/java/com/uas/platform/b2c/prod/commodity/service/impl/V_ProductPrivateServiceImpl.java
  18. 1 1
      src/main/resources/prod/sys.properties

+ 8 - 0
src/main/java/com/uas/platform/b2c/core/utils/StringUtilB2C.java

@@ -418,5 +418,13 @@ public class StringUtilB2C {
 		return String.valueOf(new Random().nextInt(max) % (max - min + 1) + min);
 	}
 
+	public static String valueOf(Object oj) {
+		if (oj == null) {
+			return "";
+		} else {
+			return oj.toString();
+		}
+	}
+
 
 }

+ 4 - 8
src/main/java/com/uas/platform/b2c/external/erp/commodity/service/impl/ProductDetailERPServiceImpl.java

@@ -17,13 +17,14 @@ import com.uas.platform.b2c.prod.commodity.model.Product;
 import com.uas.platform.b2c.prod.commodity.model.ProductDetail;
 import com.uas.platform.b2c.prod.commodity.service.GoodsService;
 import com.uas.platform.core.logging.BufferedLoggerManager;
+import org.apache.log4j.Logger;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.util.CollectionUtils;
+
 import java.math.BigDecimal;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.List;
-import org.apache.log4j.Logger;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.util.CollectionUtils;
 
 /**
  * 针对ERP物料交易详情接口
@@ -99,11 +100,6 @@ public class ProductDetailERPServiceImpl implements ProductDetailERPService {
         for (ProductDetailERP productDetailERP : productDetailERPList) {
             List<Product> products = productDao.getProductByEnUUAndProdNum(enuu, productDetailERP.getCode());// 获取对应商城物料信息
             if (!CollectionUtils.isEmpty(products)) {
-//                ProductDetail productDetail = productDetailDao.findByProductId(products.get(0).getId());// 获取商城物料信息
-//                if (productDetail == null) {// 如果物料交易详情为空,新增物料交易详情
-//                    productDetail = new ProductDetail();
-//                    productDetail.setProductId(products.get(0).getId());
-//                }
 
                 if (products.get(0).getCmpUuId() != null) {// 如果为标准器件,更新在售商品信息
                     Double b2cReserve = goodsDao.getSumReserveByEnUUAndUuidAndStatus(enuu, products.get(0).getCmpUuId(), Status.AVAILABLE.value());

+ 5 - 0
src/main/java/com/uas/platform/b2c/prod/commodity/constant/StringConstant.java

@@ -37,6 +37,11 @@ public class StringConstant {
      */
     public static final String RMB = "RMB";
 
+    /**
+     * 美金
+     */
+    public static final String USD = "USD";
+
     /**
      * 无物料
      */

+ 46 - 0
src/main/java/com/uas/platform/b2c/prod/commodity/controller/CommodityInOutboundController.java

@@ -0,0 +1,46 @@
+package com.uas.platform.b2c.prod.commodity.controller;
+
+import com.uas.platform.b2c.prod.commodity.service.CommodityInOutboundService;
+import com.uas.platform.b2c.prod.commodity.type.InOutBoundType;
+import com.uas.platform.b2c.trade.support.ResultMap;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * description
+ *
+ * @author yuj 2018-08-21 13:09
+ */
+@RestController
+@RequestMapping(value = "/CommodityInOutbound")
+public class CommodityInOutboundController {
+
+    private final CommodityInOutboundService commodityInOutboundService;
+
+    @Autowired
+    public CommodityInOutboundController(CommodityInOutboundService commodityInOutboundService) {
+        this.commodityInOutboundService = commodityInOutboundService;
+    }
+
+    /**
+     * 其他入库动作,传入入库明细,生成入库信息
+     * 传入物料id,数量
+     * @return
+     */
+    @RequestMapping(value = "/inBound/other", method = RequestMethod.POST)
+    public ResultMap inBound(@RequestBody String detail) {
+        return commodityInOutboundService.inOutBound(detail, InOutBoundType.OTHER_INBOUND);
+    }
+
+    /**
+     * 其他出库, 根据出库明细
+     * @return
+     */
+    @RequestMapping(value = "/outBound/other", method = RequestMethod.POST)
+    public ResultMap outBound(@RequestBody String detail) {
+        return commodityInOutboundService.inOutBound(detail, InOutBoundType.OTHER_OUTBOUND);
+    }
+}

+ 13 - 2
src/main/java/com/uas/platform/b2c/prod/commodity/dao/V_ProductPrivateDao.java

@@ -22,8 +22,7 @@ public interface V_ProductPrivateDao extends JpaRepository<V_ProductPrivate, Lon
      * @return list
      */
     @Query(value = "select p from V_ProductPrivate p where p.pcmpcode=:pcmpcode and p.pbranden=:pbranden and p.enUU=:enUU and p.standard=:standard and p.b2cEnabled=:enabled")
-    List<V_ProductPrivate> findProductByPcmpcodeAndPbrandenAndEnUUAndStandard(@Param("pcmpcode") String pcmpcode, @Param("pbranden") String pbranden,
-                                                                              @Param("enUU") Long enUU, @Param("standard") Integer standard, @Param("enabled") Integer enabled);
+    List<V_ProductPrivate> findProductByPcmpcodeAndPbrandenAndEnUUAndStandard(@Param("pcmpcode") String pcmpcode, @Param("pbranden") String pbranden, @Param("enUU") Long enUU, @Param("standard") Integer standard, @Param("enabled") Integer enabled);
 
     /**
      * 获取指定id列表的产品
@@ -61,4 +60,16 @@ public interface V_ProductPrivateDao extends JpaRepository<V_ProductPrivate, Lon
     @Query(value = "select 1 from v$product$private pp where " +
             "pp.pr_enuu=:enUU and pp.pr_pcmpcode is not null and pp.pr_pbranden is not null and pp.pr_b2cenabled = 1 limit 1", nativeQuery = true)
     Integer hasValidProduct(@Param("enUU") Long enUU);
+
+
+    /**
+     * 根据器件型号,品牌 、enuu获取物料信息,包含启用或未启用的信息
+     *
+     * @param pcmpcode the pcmpcode 器件型号
+     * @param pbranden the pbranden 器件品牌
+     * @param enUU     the en uu enuu
+     * @return list
+     */
+    @Query(value = "select p from V_ProductPrivate p where p.pcmpcode=:pcmpcode and p.pbranden=:pbranden and p.enUU=:enUU order by p.b2cEnabled desc")
+    List<V_ProductPrivate> findProductByPcmpcodeAndPbrandenAndEnUU(@Param("pcmpcode") String pcmpcode, @Param("pbranden") String pbranden, @Param("enUU") Long enUU);
 }

+ 58 - 37
src/main/java/com/uas/platform/b2c/prod/commodity/model/Goods.java

@@ -721,6 +721,20 @@ public class Goods implements Serializable {
 		this.status = status;
 	}
 
+	public void setStatus() {
+		if (this.autoPublish) {
+			if (StringUtils.isEmpty(this.packaging) || StringUtils.isEmpty(this.produceDate) || (this.minBuyQty == null) || (this.minPackQty == null) || (this.b2cMinDelivery == null) || (this.b2cMaxDelivery == null) || StringUtils.isEmpty(this.qtyPrice)) {
+				//做未上架处理
+				this.status = Status.NO_SHELVE.value();
+			} else {
+				//如果信息填写全,默认上架
+				this.status = (NumberUtil.compare(this.getReserve(), this.getMinBuyQty()) > -1) ? Status.AVAILABLE.value() : Status.UNAVAILABLE.value();
+			}
+		} else {
+			this.status = Status.NO_SHELVE.value();
+		}
+	}
+
 	public String getProduceDate() {
 		return produceDate;
 	}
@@ -739,7 +753,7 @@ public class Goods implements Serializable {
 
 	public void setReserve(Goods goods) {
 		if(NumberUtil.compare(this.reserve, goods.getReserve()) != 0) {
-			this.lastReserve = goods.getReserve();
+			this.lastReserve = this.reserve;
 		}
 		if(this.lastReserve == null) {
 			this.lastReserve = goods.getReserve();
@@ -919,10 +933,10 @@ public class Goods implements Serializable {
 	}
 
 	public void setTaxRate() {
-		if (this.getCurrencyName().contains("RMB".toUpperCase()) && this.getRmbTaxRate() == null) {
+		if (this.getCurrencyName().contains(StringConstant.RMB) && this.getRmbTaxRate() == null) {
 			this.setRmbTaxRate(0.17);
 		}
-		if (this.getCurrencyName().contains("USD".toUpperCase()) && this.getUsdTaxRate() == null) {
+		if (this.getCurrencyName().contains(StringConstant.USD) && this.getUsdTaxRate() == null) {
 			this.setUsdTaxRate((double) 0);
 		}
 	}
@@ -1127,6 +1141,13 @@ public class Goods implements Serializable {
         if(StringUtils.isEmpty(this.img)) {
             this.img = product.getCmpImg();
         }
+        if (StringUtils.isEmpty(this.attach)) {
+			this.attach = product.getAttachment();
+		}
+		this.packaging = product.getPackaging();
+		this.minPackQty = product.getMinPackQty();
+        this.reserve = product.getErpReserve() == null ? 0 : product.getErpReserve();
+
     }
 
 	/**************************************************************************
@@ -1147,7 +1168,7 @@ public class Goods implements Serializable {
 		if (CollectionUtils.isEmpty(prices) && StringUtils.hasText(qtyPrice)) {
 			return FastjsonUtils.fromJsonArray(qtyPrice, GoodsQtyPrice.class);
 		} else {
-			return prices;
+			return new ArrayList<>();
 		}
 	}
 
@@ -1163,7 +1184,7 @@ public class Goods implements Serializable {
 	 */
 	public void setWithOutTaxRMBPrice() {
 		if (!CollectionUtils.isEmpty(this.prices)) {
-			if (this.currencyName.contains("RMB")) {
+			if (this.currencyName.contains(StringConstant.RMB)) {
 				for (GoodsQtyPrice price : prices) {
 					BigDecimal taxNum = new BigDecimal(this.getRmbTaxRate() + 1);
 					if (price.getRMBPrice() == null) {
@@ -1183,7 +1204,7 @@ public class Goods implements Serializable {
 	 */
 	public void setWithOutTaxUSDPrice() {
 		if (!CollectionUtils.isEmpty(this.prices)) {
-			if (this.currencyName.contains("USD")) {
+			if (this.currencyName.contains(StringConstant.USD)) {
 				for (GoodsQtyPrice price : prices) {
 					BigDecimal taxNum = new BigDecimal(this.getUsdTaxRate() + 1);
 					if (price.getUSDPrice() == null) {
@@ -1576,7 +1597,7 @@ public class Goods implements Serializable {
 	}
 
 	public Goods setPerQty() {
-		this.perQty = (this.breakUp != null && this.breakUp) ? 1d : this.minPackQty;
+		this.perQty = (this.breakUp == null || this.breakUp) ? 1d : this.minPackQty;
 		return this;
 	}
 
@@ -1775,12 +1796,19 @@ public class Goods implements Serializable {
 		if (releaseProductByBatch.getSelfMaxDelivery() != null) {
 			this.maxDelivery = releaseProductByBatch.getSelfMaxDelivery();
 			this.minDelivery = releaseProductByBatch.getSelfMinDelivery();
-			if (deliveryDelayTime == null) {
-				this.b2cMaxDelivery = releaseProductByBatch.getSelfMaxDelivery();
-				this.b2cMinDelivery = releaseProductByBatch.getSelfMinDelivery();
-			} else {
-				this.b2cMaxDelivery = (short)(releaseProductByBatch.getSelfMaxDelivery() + deliveryDelayTime.getMaxTime());
-				this.b2cMinDelivery = (short)(releaseProductByBatch.getSelfMinDelivery() + deliveryDelayTime.getMinTime());
+			if (this.minDelivery == null) {
+				this.minDelivery = this.maxDelivery;
+			}
+			if (this.maxDelivery == null) {
+				this.maxDelivery = this.minDelivery;
+			}
+			this.b2cMaxDelivery = this.maxDelivery;
+			this.b2cMinDelivery = this.minDelivery;
+			if (this.minDelivery != null) {
+				if (deliveryDelayTime != null) {
+					this.b2cMaxDelivery = (short)(this.b2cMaxDelivery + deliveryDelayTime.getMaxTime());
+					this.b2cMinDelivery = (short)(this.b2cMinDelivery + deliveryDelayTime.getMinTime());
+				}
 			}
 		}
 		this.maxPriceRMB = releaseProductByBatch.getMaxPriceRMB();
@@ -1796,13 +1824,10 @@ public class Goods implements Serializable {
 		this.perQty = releaseProductByBatch.getBreakUp() ? 1 : releaseProductByBatch.getMinPackage();
 		this.spec = releaseProductByBatch.getSpec();
 		this.attach = releaseProductByBatch.getAttach();
-		if (StringUtils.isEmpty(this.packaging) || StringUtils.isEmpty(this.produceDate) || (this.minBuyQty == null) || (this.minPackQty == null) || (this.b2cMinDelivery == null) || (this.b2cMaxDelivery == null) || StringUtils.isEmpty(this.qtyPrice)) {
-			//做未上架处理
-			this.status = Status.NO_SHELVE.value();
-		} else {
-			//如果信息填写全,默认上架
-			this.status = (NumberUtil.compare(this.getReserve(), this.getMinBuyQty()) > -1) ? Status.AVAILABLE.value() : Status.UNAVAILABLE.value();
+		if (this.autoPublish == null) {
+			this.autoPublish = Boolean.TRUE;
 		}
+		this.setStatus();
 		return this;
 	}
 
@@ -1867,15 +1892,21 @@ public class Goods implements Serializable {
 		if (IntegerConstant.NO_INT == ignoreImport || releaseProductByBatch.getSelfMinDelivery() != null) {
 			this.maxDelivery = releaseProductByBatch.getSelfMaxDelivery();
 			this.minDelivery = releaseProductByBatch.getSelfMinDelivery();
-			if (releaseProductByBatch.getSelfMinDelivery() != null) {
-				if (deliveryDelayTime == null) {
-					this.b2cMaxDelivery = releaseProductByBatch.getSelfMaxDelivery();
-					this.b2cMinDelivery = releaseProductByBatch.getSelfMinDelivery();
-				} else {
-					this.b2cMaxDelivery = (short)(releaseProductByBatch.getSelfMaxDelivery() + deliveryDelayTime.getMaxTime());
-					this.b2cMinDelivery = (short)(releaseProductByBatch.getSelfMinDelivery() + deliveryDelayTime.getMinTime());
+			if (this.minDelivery == null) {
+				this.minDelivery = this.maxDelivery;
+			}
+			if (this.maxDelivery == null) {
+				this.maxDelivery = this.minDelivery;
+			}
+			this.b2cMaxDelivery = this.maxDelivery;
+			this.b2cMinDelivery = this.minDelivery;
+			if (this.minDelivery != null) {
+				if (deliveryDelayTime != null) {
+					this.b2cMaxDelivery = (short)(this.b2cMaxDelivery + deliveryDelayTime.getMaxTime());
+					this.b2cMinDelivery = (short)(this.b2cMinDelivery + deliveryDelayTime.getMinTime());
 				}
 			}
+
 		}
 		if (IntegerConstant.NO_INT == ignoreImport || StringUtils.isEmpty(this.breakUp)) {
 			this.breakUp = releaseProductByBatch.getBreakUp();
@@ -1888,17 +1919,7 @@ public class Goods implements Serializable {
 		if (this.autoPublish == null) {
 			this.autoPublish = Boolean.TRUE;
 		}
-		if (this.autoPublish) {
-			if (StringUtils.isEmpty(this.packaging) || StringUtils.isEmpty(this.produceDate) || (this.minBuyQty == null) || (this.minPackQty == null) || (this.b2cMinDelivery == null) || (this.b2cMaxDelivery == null) || StringUtils.isEmpty(this.qtyPrice)) {
-				//做未上架处理
-				this.status = Status.NO_SHELVE.value();
-			} else {
-				//如果信息填写全,默认上架
-				this.status = (NumberUtil.compare(this.getReserve(), this.getMinBuyQty()) > -1) ? Status.AVAILABLE.value() : Status.UNAVAILABLE.value();
-			}
-		} else {
-			this.status = Status.NO_SHELVE.value();
-		}
+		this.setStatus();
 
 		return this;
 	}

+ 0 - 8
src/main/java/com/uas/platform/b2c/prod/commodity/model/GoodsHistory.java

@@ -1065,14 +1065,6 @@ public class GoodsHistory {
 		this.productid = goods.getProductid();
 		this.standprodid = goods.getStandprodid();
 		this.lastReserve = goods.getLastReserve();
-		this.b2cDeliveryDemMaxTime = goods.getB2cDeliveryDemMaxTime();
-		this.b2cDeliveryDemMinTime = goods.getB2cDeliveryDemMinTime();
-		this.b2cDeliveryHKMaxTime = goods.getB2cDeliveryHKMaxTime();
-		this.b2cDeliveryHKMinTime = goods.getB2cDeliveryHKMinTime();
-		this.selfDeliveryDemMaxTime = goods.getSelfDeliveryDemMaxTime();
-		this.selfDeliveryDemMinTime = goods.getSelfDeliveryDemMinTime();
-		this.selfDeliveryHKMaxTime = goods.getSelfDeliveryHKMaxTime();
-		this.selftDeliveryHKMinTime = goods.getSelfDeliveryHKMinTime();
 		this.maxDelivery = goods.getMaxDelivery();
 		this.minDelivery = goods.getMinDelivery();
 		this.b2cMaxDelivery = goods.getB2cMaxDelivery();

+ 12 - 0
src/main/java/com/uas/platform/b2c/prod/commodity/model/ModifyInfo.java

@@ -119,4 +119,16 @@ public class ModifyInfo {
     public void setBatchCode(String batchCode) {
         this.batchCode = batchCode;
     }
+
+    public ModifyInfo() {
+    }
+
+    public ModifyInfo(String modifyField, String batchCode, String before, String after, Short type) {
+        this.modifyField = modifyField;
+        this.batchCode = batchCode;
+        this.modifyField = modifyField;
+        this.before = before;
+        this.after = after;
+        this.type = type;
+    }
 }

+ 23 - 0
src/main/java/com/uas/platform/b2c/prod/commodity/model/Product.java

@@ -1032,4 +1032,27 @@ public class Product {
 		// 产品导入默认可销售
 		this.isSale = ((short) 1);
 	}
+
+	public void setByGoods(Goods goods) {
+		this.minPackQty = goods.getMinPackQty();
+		this.cmpImg = goods.getImg();
+		this.enUU = SystemSession.getUser().getEnterprise().getUu();
+		this.brand = goods.getBrandNameEn();
+		this.cmpCode = goods.getCode();
+		this.cmpUuId = goods.getUuid();
+		this.kind = goods.getKindNameCn();
+		this.kindid = goods.getKindUuid();
+		this.pcmpcode = goods.getCode();
+		this.pbrand = goods.getBrandNameCn();
+		this.pbranden = goods.getBrandNameEn();
+		this.pbrandid = goods.getBrandid();
+		this.pbranduuid = goods.getBranduuid();
+		this.standard = (goods.getUuid() == null ? 0 : 1);
+		this.createTime = new Date(System.currentTimeMillis());
+		this.produceDate = goods.getProduceDate();
+		this.spec = goods.getSpec();
+		this.prodName = goods.getKindNameCn();
+		// 产品导入默认可销售
+		this.isSale = ((short) 1);
+	}
 }

+ 11 - 0
src/main/java/com/uas/platform/b2c/prod/commodity/service/CommodityInOutboundService.java

@@ -2,6 +2,7 @@ package com.uas.platform.b2c.prod.commodity.service;
 
 import com.uas.platform.b2c.prod.commodity.model.CommodityInOutbound;
 import com.uas.platform.b2c.prod.commodity.model.InOutboundDetail;
+import com.uas.platform.b2c.trade.support.ResultMap;
 
 import java.util.List;
 import java.util.Set;
@@ -34,4 +35,14 @@ public interface CommodityInOutboundService {
      * @return
      */
     CommodityInOutbound produceCommodityInOutbound(Set<InOutboundDetail> details, String type);
+
+
+    /**
+     * 入库动作,传入入库明细,生成入库信息
+     * @param detail 传入的明细
+     * @param type 其他出库,还是其他出库
+     * @return ResultMap
+     * @return
+     */
+    ResultMap inOutBound(String detail, String type);
 }

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

@@ -799,4 +799,10 @@ public interface GoodsService {
      * @return List<Goods>
      */
     List<Goods> findByProductids(List<Long> ids);
+
+    /**
+     * 将在售产品关联到物料,如果物料信息不存在,生成对应的物料信息
+     * @param goods 物料信息
+     */
+    void bindGoodsToProduct(Goods goods);
 }

+ 9 - 1
src/main/java/com/uas/platform/b2c/prod/commodity/service/ProductPrivateService.java

@@ -32,7 +32,15 @@ public interface ProductPrivateService {
      * @param productPrivates 需要保存的信息
      * @return  List<ProductPrivate>
      */
-    List<ProductPrivate> saveProductPrivate(List<ProductPrivate> productPrivates);
+    List<ProductPrivate> saveProductPrivates(List<ProductPrivate> productPrivates);
+
+
+    /**
+     * 保存
+     * @param productPrivate 需要保存的信息
+     * @return  List<ProductPrivate>
+     */
+    ProductPrivate saveProductPrivate(ProductPrivate productPrivate);
 
     /**
      * 根据给定的物料主键,创建私有信息

+ 28 - 0
src/main/java/com/uas/platform/b2c/prod/commodity/service/V_ProductPrivateService.java

@@ -0,0 +1,28 @@
+package com.uas.platform.b2c.prod.commodity.service;
+
+import com.uas.platform.b2c.prod.commodity.model.V_ProductPrivate;
+
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Created by yujia on 2018/8/21.
+ */
+public interface V_ProductPrivateService {
+
+    /**
+     * 根据品牌、型号、企业enuu 获取物料信息,按照b2cenabled降序排列
+     * @param pcmpcode 型号
+     * @param pbranden 品牌
+     * @param enUU 企业enuu
+     * @return
+     */
+    List<V_ProductPrivate> findProductByPcmpcodeAndPbrandenAndEnUU(String pcmpcode, String pbranden, Long enUU);
+
+    /**
+     * 根据物料信息获取对象
+     * @param prids 物料ids
+     * @return
+     */
+    List<V_ProductPrivate> findByProductIds(Set<Long> prids);
+}

+ 78 - 1
src/main/java/com/uas/platform/b2c/prod/commodity/service/impl/CommodityInOutboundServiceImpl.java

@@ -1,15 +1,25 @@
 package com.uas.platform.b2c.prod.commodity.service.impl;
 
+import com.uas.platform.b2c.core.utils.NumberUtil;
+import com.uas.platform.b2c.core.utils.StringUtilB2C;
+import com.uas.platform.b2c.prod.commodity.constant.DoubleConstant;
 import com.uas.platform.b2c.prod.commodity.dao.CommodityInOutboundDao;
 import com.uas.platform.b2c.prod.commodity.model.CommodityInOutbound;
 import com.uas.platform.b2c.prod.commodity.model.InOutboundDetail;
+import com.uas.platform.b2c.prod.commodity.model.V_ProductPrivate;
 import com.uas.platform.b2c.prod.commodity.service.CommodityInOutboundService;
+import com.uas.platform.b2c.prod.commodity.service.V_ProductPrivateService;
 import com.uas.platform.b2c.prod.product.common.service.CreateNumberService;
+import com.uas.platform.b2c.trade.support.CodeType;
+import com.uas.platform.b2c.trade.support.ResultMap;
+import com.uas.platform.core.exception.IllegalOperatorException;
+import com.uas.platform.core.util.serializer.FlexJsonUtils;
 import org.apache.commons.collections.CollectionUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
@@ -25,10 +35,13 @@ public class CommodityInOutboundServiceImpl implements CommodityInOutboundServic
 
     private final CreateNumberService createNumberService;
 
+    private final V_ProductPrivateService v_ProductPrivateService;
+
     @Autowired
-    public CommodityInOutboundServiceImpl(CommodityInOutboundDao commodityInOutboundDao, CreateNumberService createNumberService) {
+    public CommodityInOutboundServiceImpl(CommodityInOutboundDao commodityInOutboundDao, CreateNumberService createNumberService, V_ProductPrivateService v_productPrivateService) {
         this.commodityInOutboundDao = commodityInOutboundDao;
         this.createNumberService = createNumberService;
+        v_ProductPrivateService = v_productPrivateService;
     }
 
     /**
@@ -84,4 +97,68 @@ public class CommodityInOutboundServiceImpl implements CommodityInOutboundServic
             return null;
         }
     }
+
+    /**
+     * 入库动作,传入入库明细,生成入库信息
+     *
+     * @param detail 传入的明细
+     * @param type   其他出库,还是其他出库
+     * @return
+     */
+    @Override
+    public ResultMap inOutBound(String detail, String type) {
+        if (StringUtilB2C.isEmpty(detail)) {
+            return new ResultMap(CodeType.NO_INFO, "传入的信息为空");
+        } else {
+            List<InOutboundDetail> detaiList = null;
+            try {
+                detaiList = FlexJsonUtils.fromJsonArray(detail, InOutboundDetail.class);
+            } catch (Exception e) {
+                e.printStackTrace();
+                return new ResultMap(CodeType.NO_INFO, "信息格式不正确");
+            }
+            Set<Long> prids = new HashSet<>();
+            for (InOutboundDetail inOutboundDetail : detaiList) {
+                if (inOutboundDetail.getProductId() == null) {
+                    throw new IllegalArgumentException("传入物料信息缺失");
+                }
+                if (NumberUtil.compare(inOutboundDetail.getQty(), DoubleConstant.zero) < 1) {
+                    throw new IllegalArgumentException("传入数量缺失");
+                }
+                prids.add(inOutboundDetail.getProductId());
+            }
+            String inOutboundId = createNumberService.generateOrderNumber(com.uas.platform.b2c.core.constant.EncodingRulesConstant.INOUTBOUND_NUM, "trade$commodity_in_outbound", 8);
+            CommodityInOutbound inOutbound = new CommodityInOutbound(type);
+            inOutbound.setInOutId(inOutboundId);
+            Short i = 1;
+            if (CollectionUtils.isNotEmpty(prids)) {
+                List<V_ProductPrivate> v_productPrivates = v_ProductPrivateService.findByProductIds(prids);
+                for (InOutboundDetail inOutboundDetail : detaiList) {
+                    inOutboundDetail.setDetno(i++);
+                    inOutboundDetail.setCommodityInOutbound(inOutbound);
+                    for (V_ProductPrivate v_productPrivate : v_productPrivates) {
+                        if (inOutboundDetail.getProductId().longValue() == v_productPrivate.getId().longValue()) {
+                            inOutboundDetail.setBrandCn(v_productPrivate.getPbrand());
+                            inOutboundDetail.setBrandEn(v_productPrivate.getPbranden());
+                            inOutboundDetail.setBrandId(v_productPrivate.getPbrandid());
+                            inOutboundDetail.setBranduuid(v_productPrivate.getPbranduuid());
+                            inOutboundDetail.setCmpCode(v_productPrivate.getPcmpcode());
+                            inOutboundDetail.setCmpuuid(v_productPrivate.getCmpUuId());
+                            inOutboundDetail.setKindId(v_productPrivate.getKindid());
+                            inOutboundDetail.setKindName(v_productPrivate.getKind());
+                            inOutboundDetail.setSpec(v_productPrivate.getSpec());
+                        }
+                    }
+                }
+            } else {
+                throw new IllegalOperatorException("没有需要操作的信息");
+            }
+            Set<InOutboundDetail> details = new HashSet<>();
+            details.addAll(detaiList);
+            inOutbound.setInOutboundDetails(details);
+            CommodityInOutbound commodityInOutbound = commodityInOutboundDao.save(inOutbound);
+            //如果入库,需要
+            return ResultMap.success(commodityInOutbound);
+        }
+    }
 }

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

@@ -238,6 +238,9 @@ public class GoodsServiceImpl implements GoodsService {
     @Autowired
     private ProductAttachService productAttachService;
 
+    @Autowired
+    private V_ProductPrivateService v_productPrivateService;
+
     private final Logger logger = Logger.getLogger(getClass());
 
     @Autowired
@@ -265,80 +268,32 @@ public class GoodsServiceImpl implements GoodsService {
         if (goods == null) {
             throw new IllegalOperatorException("商品信息Goods不能为空");
         }
-        if (goods.getTag() == null) {
-            throw new IllegalOperatorException("自定义标签信息为空");
-        }
-        if (goods.getTag().length() > 20) {
-            throw new IllegalOperatorException("自定义标签的信息超过约定的20个字符");
-        }
-//        if(!PatternUtil.matchChineseAndEnglish(goods.getTag())) {
-//            throw new IllegalOperatorException("自定义标签的信息只能包含中文和英文");
-//        }
-        /*if (goods.getPackaging() == null) {
-            throw new IllegalOperatorException("包装信息为空");
-        }*/
-//        if (goods.getPackaging().length() > 10) {
-//            throw new IllegalOperatorException("包装信息操作约定的10个字符");
-//        }
-//        if (!PatternUtil.matchChineseAndEnglish(goods.getPackaging())) {
-//            throw new IllegalOperatorException("包装信息只能包含中文和英文");
-//        }
         if (!StringUtils.isEmpty(goods.getSpec())) {
                 String spec = com.uas.platform.b2c.fa.payment.utils.StringUtils.cutOutStringIgnoreEncode(goods.getSpec().toString(), UploadConstant.SPEC_MAX_BYTE);
                 goods.setSpec(spec);
         }
-        if (StringUtils.isEmpty(goods.getProduceDate())) {
-            throw new IllegalOperatorException("型号" + goods.getCode()+"品牌" + goods.getBrandNameEn() +"的产品生产日期为空");
-        } else {
-            if (goods.getProduceDate().length() > 12) {
-                throw new IllegalOperatorException("产品生产日期不能超过12个字符");
-            }
-        }
-
-        if (goods.getOriginal() == null) {
-            throw new IllegalOperatorException("必须选择库存类型");
-        }
         if (goods.getCurrencyName() == null) {
             throw new IllegalOperatorException("必须选择一种币别");
         }
-        if ("RMB".equals(goods.getCurrencyName()) && goods.getTax() != (short) 17) {
-            goods.setTax((short) 17);
-        }
-        if (!"RMB".equals(goods.getCurrencyName())) {
-            goods.setTax((short) 0);
-        }
-        if (goods.getReserve() < 0 || goods.getReserve() > 999999999) {
+        if (NumberUtil.compare(goods.getReserve(), DoubleConstant.zero) < 0 || NumberUtil.compare(goods.getReserve(), DoubleConstant.maxReserve) > 0) {
             throw new IllegalOperatorException("库存数量必须在1~99999999之间");
         }
-        if (goods.getMinPackQty() < 1 || goods.getMinPackQty() > 999999) {
+        if ((NumberUtil.compare(goods.getMinPackQty(), DoubleConstant.minReserve) < 0) || NumberUtil.compare(goods.getMinPackQty(), DoubleConstant.maxMinPackageQty) > 0) {
             throw new IllegalOperatorException("最小包装量必须在1~999999之间");
         }
-//        if (goods.getMinBuyQty() < 1 || (NumberUtil.compare(goods.getMinBuyQty(), goods.getReserve()) > 0)) {
-//            throw new IllegalOperatorException("最小起订量必须在1~" + goods.getReserve() + "之间");
-//        }
         if (!goods.getBreakUp()) {
-            if (goods.getMinBuyQty() % goods.getMinPackQty() != 0) {
-                throw new IllegalOperatorException("最小起订量必须为最小包装量的整数倍");
+            if (goods.getMinPackQty() != null) {
+                if (goods.getMinBuyQty() % goods.getMinPackQty() != 0) {
+                    throw new IllegalOperatorException("最小起订量必须为最小包装量的整数倍");
+                }
             }
         }
 
-        // 验证交货周期信息
-        validDeliveryTime(goods);
-
         //验证分段价格的有效性。
         ResultMap resultMap = validFragmentPrice(goods);
         if (resultMap.getCode() != CodeType.OK.code()) {
             return resultMap;
         }
-
-        // 检验分段价格是否有效
-        for (GoodsQtyPrice price : goods.getPrices()) {
-            if (price == null || (price.getRMBPrice() == null && price.getUSDPrice() == null)) {
-                throw new IllegalOperatorException(
-                        "[com.uas.platform.b2c.prod.commodity.service.impl.GoodsServiceImpl.checkGoods] "
-                                + "分段价格中人民币价格和美元价格不能同时为空");
-            }
-        }
         if (goods.getProductid() == null) {
             throw new IllegalOperatorException("型号" + goods.getCode() + "品牌" + goods.getBrandNameEn() +"的物料库信息丢失");
         }
@@ -367,12 +322,12 @@ public class GoodsServiceImpl implements GoodsService {
             if (NumberUtil.compare(end, price.getStart()) > -1) {
                 throw new IllegalOperatorException("分段价格中存在前一个分段结束值大于等于分段起始值");
             }
-            if (currencyName.contains("USD")) {
+            if (currencyName.contains(StringConstant.USD)) {
                 if (price.getUSDPrice() == null || price.getUSDPrice() < 0) {
                     throw new IllegalOperatorException("库存的币别信息包含美金,而分段价格中的美金价格不存在或小于0");
                 }
             }
-            if (currencyName.contains("RMB")) {
+            if (currencyName.contains(StringConstant.RMB)) {
                 if (price.getRMBPrice() == null || price.getRMBPrice() < 0) {
                     throw new IllegalOperatorException("库存的币别信息包含人民币,而分段价格中的人民币价格不存在或小于0");
                 }
@@ -589,8 +544,6 @@ public class GoodsServiceImpl implements GoodsService {
         }
         goods.setCreatedDate(new Date());
         goods.setUpdateDate(goods.getCreatedDate());
-        goods.setReserve(goods);
-        goods.setPerQty();
         goods.setEnUU(SystemSession.getUser().getEnterprise().getUu());
         goods.setEnterpriseName(SystemSession.getUser().getEnterprise().getEnName());
         if (StringUtils.isEmpty(goods.getPublisherName())) {
@@ -598,20 +551,63 @@ public class GoodsServiceImpl implements GoodsService {
             goods.setPublisherUU(SystemSession.getUser().getUserUU());
             goods.setPublishPhone(SystemSession.getUser().getUserTel());
         }
-        if (NumberUtil.compare(goods.getReserve(), goods.getMinBuyQty()) == -1) {
-            goods.setStatus(Status.UNAVAILABLE.value());
+        if (goods.getBreakUp() == null) {
+            goods.setBreakUp(Boolean.TRUE);
+        }
+        if (goods.getAutoPublish() == null) {
+            goods.setAutoPublish(Boolean.TRUE);
+        }
+        if (StringUtils.isEmpty(goods.getUnit())) {
+            goods.setUnit(StringConstant.UNIT);
+        }
+        if (goods.getReturnInWeek() == null) {
+            goods.setReturnInWeek(ShortConstant.NO_SHORT);
+        }
+        if (goods.getProductid() == null) {
+            bindGoodsToProduct(goods);
+        }
+        Product product = productDao.findOne(goods.getProductid());
+        if (product == null) {
+            bindGoodsToProduct(goods);
+            product = productDao.findOne(goods.getProductid());
+        }
+
+        //如果信息未被填充
+        if (StringUtils.isEmpty(goods.getCode())) {
+            goods.setProductInfo(product);
+        }
+
+        if (StringUtils.isEmpty(goods.getImg())) {
+            String cmpUuId = product.getCmpUuId();
+            if (!StringUtils.isEmpty(cmpUuId)) {
+                Component component = componentDao.findByUuid(cmpUuId);
+                if (component != null) {
+                    goods.setImg(component.getImg());
+                }
+            }
+        }
+        goods.setReserve(goods);
+        if (NumberUtil.compare(goods.getMinPackQty(), DoubleConstant.zero) < 1) {
+            goods.setMinPackQty(DoubleConstant.minReserve);
+            goods.setMinBuyQty();
+        }
+        goods.setPerQty();
+        goods.setStatus();
+        if (goods.getAutoPublish()) {
+            if (NumberUtil.compare(goods.getReserve(), goods.getMinBuyQty()) == -1) {
+                goods.setStatus(Status.UNAVAILABLE.value());
+            } else {
+                goods.setStatus(Status.AVAILABLE.value());
+            }
         } else {
-            goods.setStatus(Status.AVAILABLE.value());
+            goods.setStatus(Status.NO_SHELVE.value());
         }
         // 设置货到香港,货到大陆的延长时间
-        setB2CDelayTime(goods);
+        if (goods.getMinDelivery() != null || goods.getMaxDelivery() != null) {
+            setB2CDelayTime(goods);
+        }
         // 设置默认税率
         goods.setTaxRate();
-
-        if (goods.getReturnInWeek() == null) {
-            // 若无设置,默认不支持7天无理由退货
-            goods.setReturnInWeek((short) 0);
-        }
         // 若B2C上架的商品必须有发布人姓名和发布人联系电话
         if (goods.getSourceId() == null) {
             if (goods.getPublisherName() == null || goods.getPublishPhone() == null) {
@@ -626,77 +622,14 @@ public class GoodsServiceImpl implements GoodsService {
         goods.setMaxPriceRMB(GoodsUtil.getMaxPriceRMB(goods.getPrices()));
         goods.setMinPriceUSD(GoodsUtil.getMinPriceUSD(goods.getPrices()));
         goods.setMaxPriceUSD(GoodsUtil.getMaxPriceUSD(goods.getPrices()));
-        if (StringUtils.isEmpty(goods.getUnit())) {
-            goods.setUnit(StringConstant.UNIT);
-        }
-        if (StringUtils.isEmpty(goods.getImg())) {
-            Long goodsProductid = goods.getProductid();
-            if (goodsProductid != null) {
-                Product product = productDao.findOne(goodsProductid);
-                if (product != null) {
-                    if (StringUtils.isEmpty(product.getCmpImg())) {
-                        String cmpUuId = product.getCmpUuId();
-                        if (!StringUtils.isEmpty(cmpUuId)) {
-                            Component component = componentDao.findByUuid(cmpUuId);
-                            if (component != null) {
-                                goods.setImg(component.getImg());
-                            }
-                        }
-                    } else {
-                        goods.setImg(product.getCmpImg());
-                    }
 
-                }
-            }
-
-        }
         if (!StringUtils.isEmpty(goods.getStoreid())) {
             StoreIn storeIn = storeInDao.findByUuid(goods.getStoreid());
-            if (storeIn.getStatus() == StoreStatus.OPENED) {
-                goods.setStoreName(storeIn.getStoreName());
-            } else {
+            if (storeIn == null || storeIn.getStatus() != StoreStatus.OPENED) {
                 throw new IllegalOperatorException("该公司还为开店铺,不能选择自营销售");
-            }
-        }
-        if (goods.getProductid() != null) {
-            Product product = productDao.findOne(goods.getProductid());
-            if (product == null) {
-                throw new IllegalOperatorException("器件" + goods.getCode() + "品牌" + goods.getBrandNameEn() + "关联的物料库信息丢失");
-            }
-            List<Goods> goodses = goodsDao.findRepeatGoodsInProductId(goods.getProductid(), goods.getProduceDate(), goods.getPackaging(), goods.getMinPackQty(), goods.getMinBuyQty(), goods.getMaxDelivery(), goods.getMinDelivery(), goods.getUnit());
-            if (!CollectionUtils.isEmpty(goodses)) {
-                for (Goods goods1 : goodses) {
-                    if (!goods1.getId().equals(goods.getId())
-                            && GoodsUtil.compareWithQtyPrice(goods1.getPrices(), goods.getPrices(), goods.getCurrencyName())) {
-                        throw new IllegalOperatorException("该物料已存在(包装、日期、最小包装量、最小起订量、交期、单位、价格)相同的信息");
-                    }
-                }
-            }
-            //判断自定义标签是否重复
-            if (StringUtils.isEmpty(goods.getTag())) {
-                throw new IllegalArgumentException("自定义标签信息为空");
-            }
-            if (goods.getProductid() == null) {
-                throw new IllegalOperatorException("传入的产品信息缺失,请重新操作");
-            }
-            List<Goods> goodsList = goodsDao.findGoodsByProductidAndTag(goods.getProductid(), goods.getTag());
-            if ((goods.getId() == null) && (goodsList.size() > 0)) {
-                throw new IllegalOperatorException("该产品下已存在相同的自定义标签");
             } else {
-                for (Goods goods1 : goodsList) {
-                    if (goods.getTag().equals(goods1.getTag())
-                            && (goods1.getId().longValue() != goods.getId().longValue())) {
-                        throw new IllegalOperatorException("该产品下已存在相同的自定义标签");
-                    }
-                }
-            }
-
-            //如果信息未被填充
-            if (StringUtils.isEmpty(goods.getCode())) {
-                goods.setProductInfo(product);
+                goods.setStoreName(storeIn.getStoreName());
             }
-        } else {
-            throw new IllegalOperatorException("器件" + goods.getCode() + "品牌" + goods.getBrandNameEn() + "关联的物料库信息丢失");
         }
     }
 
@@ -753,7 +686,6 @@ public class GoodsServiceImpl implements GoodsService {
         if (resultMap.getCode() != CodeType.OK.code()) {
             return null;
         }
-//		updateGoodTransactional(goods);
         GoodsHistory goodsHistory = goodsHistoryService.converTGoodsHist(goods, GoodsHistory.OperateType.Publish.getPhrase(), false);
         //仅保存商品信息,不上架
         if (goods.getId() == null || goods.getSold() == null) {
@@ -761,11 +693,6 @@ public class GoodsServiceImpl implements GoodsService {
         }
         Goods backGoods = goodsDao.save(goods);
         goodsHistoryDao.save(goodsHistory);
-        // TODO huxz 添加或修改商品价格信息
-        if (goods.getUuid() != null) {
-//            saveOrUpdatePriceInfos(goods, deviceInfo);
-            updateComponentTradeInfos(goods.getUuid());
-        }
         return backGoods;
     }
 
@@ -985,61 +912,61 @@ public class GoodsServiceImpl implements GoodsService {
 
     @Override
     public void updateComponentTradeInfos(final String uuid) {
-        final Runnable updateComponentRunnable = new Runnable() {
-
-            @Override
-            public void run() {
-                Date startDate = new Date();
-                SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-                Component component = componentDao.findByUuid(uuid);
-                if (component != null) {
-                    Double totalReserve = goodsDao.findTotalReserveByUuid(uuid, Status.AVAILABLE.value());
-                    component.setReserve(totalReserve);
-                    // 设置最小最大价格
-                    Double minPriceRMB = goodsDao.findMinPriceRMBByUuid(uuid, Status.AVAILABLE.value());
-                    component.setMinPriceRMB(minPriceRMB != null ? minPriceRMB : 0);
-                    Double maxPriceRMB = goodsDao.findMaxPriceRMBByUuid(uuid, Status.AVAILABLE.value());
-                    component.setMaxPriceRMB(maxPriceRMB != null ? maxPriceRMB : 0);
-                    Double minPriceUSD = goodsDao.findMinPriceUSDByUuid(uuid, Status.AVAILABLE.value());
-                    component.setMinPriceUSD(minPriceUSD != null ? minPriceUSD : 0);
-                    Double maxPriceUSD = goodsDao.findMaxPriceUSDByUuid(uuid, Status.AVAILABLE.value());
-                    component.setMaxPriceUSD(maxPriceUSD != null ? maxPriceUSD : 0);
-                    // 设置最小购买量
-                    Double minBuyQty = goodsDao.findMinBuyQtyByUuid(uuid, Status.AVAILABLE.value());
-                    component.setMinBuyQty(minBuyQty != null ? minBuyQty : 0);
-                    // 设置最小最大发布周期
-                    Short minDemDelivery = goodsDao.findMinDemDeliveryByUuid(uuid, Status.AVAILABLE.value());
-                    component.setMinDemDelivery(minDemDelivery != null ? minDemDelivery : 0);
-                    Short maxDemDelivery = goodsDao.findMaxDemDeliveryByUuid(uuid, Status.AVAILABLE.value());
-                    component.setMaxDemDelivery(maxDemDelivery != null ? maxDemDelivery : 0);
-                    Short minHKDelivery = goodsDao.findMinHKDeliveryByUuid(uuid, Status.AVAILABLE.value());
-                    component.setMinHKDelivery(minHKDelivery != null ? minHKDelivery : 0);
-                    Short maxHKDelivery = goodsDao.findMaxHKDeliveryByUuid(uuid, Status.AVAILABLE.value());
-                    component.setMaxHKDelivery(maxHKDelivery != null ? maxHKDelivery : 0);
-                    // 剩余样品数
-                    Double availableSampleQty = goodsDao.findAvailableSampleQtyByUuid(uuid, Status.AVAILABLE.value());
-                    component.setSampleQty(availableSampleQty != null ? availableSampleQty : 0);
-                    //已申请的样品数
-                    Double applyedSampleQty = goodsDao.findApplyedSampleQty(uuid, Status.AVAILABLE.value());
-                    component.setApplySampleQty(applyedSampleQty != null ? applyedSampleQty : 0);
-                    // 现货
-                    Double originalQty = goodsDao.findOriginalQtyByUuid(uuid, Status.AVAILABLE.value());
-                    component.setOriginalQty(originalQty != null ? originalQty : 0);
-                    // 呆滞库存
-                    Double inactionStockQty = goodsDao.findInactionStockQtyByUuid(uuid, Status.AVAILABLE.value());
-                    component.setInactionStockQty(inactionStockQty != null ? inactionStockQty : 0);
-                    componentDao.save(component);
-                }
-                Date endDate = new Date();
-                System.out.println(uuid + " execute time " + formatter.format(startDate) + " -> " + formatter.format(endDate) +
-                        ", using mill seconds: " + (endDate.getTime() - startDate.getTime()));
-            }
-        };
-        try {
-            executor.submitTask(updateComponentRunnable);
-        } catch (InterruptedException e) {
-            e.printStackTrace();
-        }
+//        final Runnable updateComponentRunnable = new Runnable() {
+//
+//            @Override
+//            public void run() {
+//                Date startDate = new Date();
+//                SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+//                Component component = componentDao.findByUuid(uuid);
+//                if (component != null) {
+//                    Double totalReserve = goodsDao.findTotalReserveByUuid(uuid, Status.AVAILABLE.value());
+//                    component.setReserve(totalReserve);
+//                    // 设置最小最大价格
+//                    Double minPriceRMB = goodsDao.findMinPriceRMBByUuid(uuid, Status.AVAILABLE.value());
+//                    component.setMinPriceRMB(minPriceRMB != null ? minPriceRMB : 0);
+//                    Double maxPriceRMB = goodsDao.findMaxPriceRMBByUuid(uuid, Status.AVAILABLE.value());
+//                    component.setMaxPriceRMB(maxPriceRMB != null ? maxPriceRMB : 0);
+//                    Double minPriceUSD = goodsDao.findMinPriceUSDByUuid(uuid, Status.AVAILABLE.value());
+//                    component.setMinPriceUSD(minPriceUSD != null ? minPriceUSD : 0);
+//                    Double maxPriceUSD = goodsDao.findMaxPriceUSDByUuid(uuid, Status.AVAILABLE.value());
+//                    component.setMaxPriceUSD(maxPriceUSD != null ? maxPriceUSD : 0);
+//                    // 设置最小购买量
+//                    Double minBuyQty = goodsDao.findMinBuyQtyByUuid(uuid, Status.AVAILABLE.value());
+//                    component.setMinBuyQty(minBuyQty != null ? minBuyQty : 0);
+//                    // 设置最小最大发布周期
+//                    Short minDemDelivery = goodsDao.findMinDemDeliveryByUuid(uuid, Status.AVAILABLE.value());
+//                    component.setMinDemDelivery(minDemDelivery != null ? minDemDelivery : 0);
+//                    Short maxDemDelivery = goodsDao.findMaxDemDeliveryByUuid(uuid, Status.AVAILABLE.value());
+//                    component.setMaxDemDelivery(maxDemDelivery != null ? maxDemDelivery : 0);
+//                    Short minHKDelivery = goodsDao.findMinHKDeliveryByUuid(uuid, Status.AVAILABLE.value());
+//                    component.setMinHKDelivery(minHKDelivery != null ? minHKDelivery : 0);
+//                    Short maxHKDelivery = goodsDao.findMaxHKDeliveryByUuid(uuid, Status.AVAILABLE.value());
+//                    component.setMaxHKDelivery(maxHKDelivery != null ? maxHKDelivery : 0);
+//                    // 剩余样品数
+//                    Double availableSampleQty = goodsDao.findAvailableSampleQtyByUuid(uuid, Status.AVAILABLE.value());
+//                    component.setSampleQty(availableSampleQty != null ? availableSampleQty : 0);
+//                    //已申请的样品数
+//                    Double applyedSampleQty = goodsDao.findApplyedSampleQty(uuid, Status.AVAILABLE.value());
+//                    component.setApplySampleQty(applyedSampleQty != null ? applyedSampleQty : 0);
+//                    // 现货
+//                    Double originalQty = goodsDao.findOriginalQtyByUuid(uuid, Status.AVAILABLE.value());
+//                    component.setOriginalQty(originalQty != null ? originalQty : 0);
+//                    // 呆滞库存
+//                    Double inactionStockQty = goodsDao.findInactionStockQtyByUuid(uuid, Status.AVAILABLE.value());
+//                    component.setInactionStockQty(inactionStockQty != null ? inactionStockQty : 0);
+//                    componentDao.save(component);
+//                }
+//                Date endDate = new Date();
+//                System.out.println(uuid + " execute time " + formatter.format(startDate) + " -> " + formatter.format(endDate) +
+//                        ", using mill seconds: " + (endDate.getTime() - startDate.getTime()));
+//            }
+//        };
+//        try {
+//            executor.submitTask(updateComponentRunnable);
+//        } catch (InterruptedException e) {
+//            e.printStackTrace();
+//        }
     }
 
 	/**
@@ -1360,33 +1287,25 @@ public class GoodsServiceImpl implements GoodsService {
     public ResultMap updateGoods(Goods goods) {
         Goods resultGoods = null;
         Long enUU = SystemSession.getUser().getEnterprise().getUu();
-        Goods nowGoods = goodsDao.findByBatchCode(goods.getBatchCode());
-        if (nowGoods == null) {
-            return new ResultMap(CodeType.NO_INFO.code(), "您提交的批次号无效");
-        }
-        // 检查身份
-        if (!nowGoods.getEnUU().equals(enUU)) {
-            return new ResultMap(CodeType.NOT_PERMIT.code(), "您提交的批次号不属于您当前登陆公司");
-        }
-        if (nowGoods.getSourceId() != null) {
-            return new ResultMap(CodeType.NOT_PERMIT.code(), "该库存的信息属于UAS上架,平台不能修改。");
-        }
-        if (StringUtils.isEmpty(goods.getTag())) {
-            return new ResultMap(CodeType.NOT_PERMIT.code(), "产品自定义标签必须填写");
-        }
-        if ((!StringUtils.isEmpty(goods.getAttach())) && StringUtils.isEmpty(nowGoods.getAttach())) {
-            productAttachService.submit(goods.getProductid(), goods.getAttach());
-        }
-        ResultMap resultMap = compareGoodsIfModifyProductInfo(goods, nowGoods);
-        if (resultMap.getCode() == CodeType.OK.code()) {
-            nowGoods = goodsDao.findByBatchCode(nowGoods.getBatchCode());
-        } else if (resultMap.getCode() != CodeType.OK.code()) {
-            return resultMap;
+        if (!StringUtils.isEmpty(goods.getBatchCode())) {
+            Goods nowGoods = goodsDao.findByBatchCode(goods.getBatchCode());
+            if (nowGoods == null) {
+                return new ResultMap(CodeType.NOT_PERMIT.code(), "找不到对应的在售信息");
+            }
+            // 检查身份
+            if (!nowGoods.getEnUU().equals(enUU)) {
+                return new ResultMap(CodeType.NOT_PERMIT.code(), "您提交的批次号不属于您当前登陆公司");
+            }
+            if (nowGoods.getSourceId() != null) {
+                return new ResultMap(CodeType.NOT_PERMIT.code(), "该库存的信息属于UAS上架,平台不能修改。");
+            }
+            // 比较两个goods编辑信息
+            compareGoodsWithModify(nowGoods, goods);
+            resultGoods = updateGoods(nowGoods, goods);
+        } else {
+            //根据物料信息,生成在售产品
+            publish(goods, "NORMAL");
         }
-        // 比较两个goods编辑信息
-        compareGoodsWithModify(nowGoods, goods);
-        resultGoods = updateGoods(nowGoods, goods);
-        updateComponentTradeInfos(nowGoods.getUuid());
         return ResultMap.success(resultGoods);
     }
 
@@ -1426,156 +1345,86 @@ public class GoodsServiceImpl implements GoodsService {
         String beforeImg = beforeGoods.getImg();
         String afterImg = afterGoods.getImg();
         if (StringUtils.isEmpty(beforeImg) && StringUtils.hasText(afterImg)) {
-            ModifyInfo info = new ModifyInfo();
-            info.setModifyField(ModifyConstant.MODIFY_IMG.getPhrase());
-            info.setBefore(StringConstant.DEFAULT_IMG);
-            info.setAfter(StringConstant.NEW_IMG);
-            info.setType(ModifyInfo.TYPE_BASIC);
-            info.setBatchCode(beforeGoods.getBatchCode());
+            ModifyInfo info = new ModifyInfo(ModifyConstant.MODIFY_IMG.getPhrase(), beforeGoods.getBatchCode(), StringConstant.DEFAULT_IMG, StringConstant.NEW_IMG, ModifyInfo.TYPE_BASIC);
             infoList.add(info);
         }
         if (StringUtils.hasText(beforeImg) && !beforeImg.equals(afterImg)) {
-            ModifyInfo info = new ModifyInfo();
-            info.setModifyField(ModifyConstant.MODIFY_IMG.getPhrase());
-            info.setBefore(StringConstant.OLD_IMG);
-            info.setAfter(StringConstant.NEW_IMG);
-            info.setType(ModifyInfo.TYPE_BASIC);
-            info.setBatchCode(beforeGoods.getBatchCode());
+            ModifyInfo info = new ModifyInfo(ModifyConstant.MODIFY_IMG.getPhrase(), beforeGoods.getBatchCode(), StringConstant.OLD_IMG, StringConstant.NEW_IMG, ModifyInfo.TYPE_BASIC);
             infoList.add(info);
         }
         String beforePackage = beforeGoods.getPackaging();
         String afterPackage = afterGoods.getPackaging();
-        if (!beforePackage.equals(afterPackage)) {
-            ModifyInfo info = new ModifyInfo();
-            info.setModifyField(ModifyConstant.MODIFY_PACKAGE.getPhrase());
-            info.setBefore(beforePackage);
-            info.setAfter(afterPackage);
-            info.setType(ModifyInfo.TYPE_BASIC);
-            info.setBatchCode(beforeGoods.getBatchCode());
+        if (!StringUtilB2C.equals(beforePackage, afterPackage)) {
+            ModifyInfo info = new ModifyInfo(ModifyConstant.MODIFY_PACKAGE.getPhrase(),beforeGoods.getBatchCode(), beforePackage, afterPackage, ModifyInfo.TYPE_BASIC);
             infoList.add(info);
         }
         String beforeProduce = beforeGoods.getProduceDate();
         String afterProduce = afterGoods.getProduceDate();
-        if (!beforeProduce.equals(afterProduce)) {
-            ModifyInfo info = new ModifyInfo();
-            info.setModifyField(ModifyConstant.MODIFY_PRODUCE_DATE.getPhrase());
-            info.setBefore(beforeProduce);
-            info.setAfter(afterProduce);
-            info.setType(ModifyInfo.TYPE_BASIC);
-            info.setBatchCode(beforeGoods.getBatchCode());
+        if (!StringUtilB2C.equals(beforeProduce, afterProduce)) {
+            ModifyInfo info = new ModifyInfo(ModifyConstant.MODIFY_PRODUCE_DATE.getPhrase(), beforeGoods.getBatchCode(), StringUtilB2C.valueOf(beforeProduce), StringUtilB2C.valueOf(beforeProduce),  ModifyInfo.TYPE_BASIC);
             infoList.add(info);
         }
         Boolean beforeBreak = beforeGoods.getBreakUp();
         Boolean afterBreak = afterGoods.getBreakUp();
         if (!beforeBreak.equals(afterBreak)) {
-            ModifyInfo info = new ModifyInfo();
-            info.setModifyField(ModifyConstant.MODIFY_BREAK_UP.getPhrase());
-            info.setBefore(beforeBreak.toString());
-            info.setAfter(afterBreak.toString());
-            info.setType(ModifyInfo.TYPE_SALE);
-            info.setBatchCode(beforeGoods.getBatchCode());
+            ModifyInfo info = new ModifyInfo(ModifyConstant.MODIFY_BREAK_UP.getPhrase(),beforeGoods.getBatchCode(), StringUtilB2C.valueOf(beforeBreak),StringUtilB2C.valueOf(afterBreak), ModifyInfo.TYPE_SALE);
             infoList.add(info);
         }
         Double beforeReserve = beforeGoods.getReserve();
         Double afterReserve = afterGoods.getReserve();
         if (!beforeReserve.equals(afterReserve)) {
-            ModifyInfo info = new ModifyInfo();
-            info.setModifyField(ModifyConstant.MODIFY_RESERVE.getPhrase());
-            info.setBefore(beforeReserve.toString());
-            info.setAfter(afterReserve.toString());
-//            info.setType(ModifyInfo.TYPE_SALE);
-            info.setBatchCode(beforeGoods.getBatchCode());
+            ModifyInfo info = new ModifyInfo(ModifyConstant.MODIFY_RESERVE.getPhrase(), beforeGoods.getBatchCode(), StringUtilB2C.valueOf(beforeReserve), StringUtilB2C.valueOf(afterReserve), ModifyInfo.TYPE_SALE);
             infoList.add(info);
         }
         Double beforePackQty = beforeGoods.getMinPackQty();
         Double afterPackQty = afterGoods.getMinPackQty();
-        if (!beforePackQty.equals(afterPackQty)) {
-            ModifyInfo info = new ModifyInfo();
-            info.setModifyField(ModifyConstant.MODIFY_PACKAGE_QTY.getPhrase());
-            info.setBefore(beforePackQty.toString());
-            info.setAfter(afterPackQty.toString());
-            info.setType(ModifyInfo.TYPE_BASIC);
-            info.setBatchCode(beforeGoods.getBatchCode());
+        if (NumberUtil.compare(beforePackQty, afterPackQty) != 0) {
+            ModifyInfo info = new ModifyInfo(ModifyConstant.MODIFY_PACKAGE_QTY.getPhrase(), beforeGoods.getBatchCode(), StringUtilB2C.valueOf(beforePackQty), StringUtilB2C.valueOf(afterPackQty), ModifyInfo.TYPE_BASIC);
             infoList.add(info);
         }
         Double beforeBuyQty = beforeGoods.getMinBuyQty();
         Double afterBuyQty = afterGoods.getMinBuyQty();
-        if (!beforeBuyQty.equals(afterBuyQty)) {
-            ModifyInfo info = new ModifyInfo();
-            info.setModifyField(ModifyConstant.MODIFY_BUY_QTY.getPhrase());
-            info.setBefore(beforeBuyQty.toString());
-            info.setAfter(afterBuyQty.toString());
-            info.setType(ModifyInfo.TYPE_SALE);
-            info.setBatchCode(beforeGoods.getBatchCode());
+        if (NumberUtil.compare(beforeBuyQty, afterBuyQty) != 0) {
+            ModifyInfo info = new ModifyInfo(ModifyConstant.MODIFY_BUY_QTY.getPhrase(), beforeGoods.getBatchCode(), StringUtilB2C.valueOf(beforeBuyQty), StringUtilB2C.valueOf(afterBuyQty), ModifyInfo.TYPE_SALE);
             infoList.add(info);
         }
         Short beforeMinDelivery = beforeGoods.getMinDelivery();
         Short afterMinDelivery = afterGoods.getMinDelivery();
-        if (!beforeMinDelivery.equals(afterMinDelivery)) {
-            ModifyInfo info = new ModifyInfo();
-            info.setModifyField(ModifyConstant.MODIFY_MIN_DELIVERY.getPhrase());
-            info.setBefore(beforeMinDelivery.toString());
-            info.setAfter(afterMinDelivery.toString());
-            info.setType(ModifyInfo.TYPE_SALE);
-            info.setBatchCode(beforeGoods.getBatchCode());
+        if (!StringUtilB2C.equals(StringUtilB2C.valueOf(beforeMinDelivery), StringUtilB2C.valueOf(afterMinDelivery))) {
+            ModifyInfo info = new ModifyInfo(ModifyConstant.MODIFY_MIN_DELIVERY.getPhrase(), beforeGoods.getBatchCode(), StringUtilB2C.valueOf(beforeMinDelivery), StringUtilB2C.valueOf(afterMinDelivery), ModifyInfo.TYPE_SALE);
             infoList.add(info);
         }
         Integer beforeGoodsStatus = beforeGoods.getStatus();
         Integer afterGoodsStatus = afterGoods.getStatus();
         if (!beforeGoodsStatus.equals(afterGoodsStatus)) {
-            ModifyInfo info = new ModifyInfo();
-            info.setModifyField(ModifyConstant.MODIFY_GOODS_STATUS.getPhrase());
-            info.setBefore(Status.valueStringOf(beforeGoodsStatus));
-            info.setAfter(Status.valueStringOf(afterGoodsStatus));
-            info.setType(ModifyInfo.TYPE_SALE);
-            info.setBatchCode(beforeGoods.getBatchCode());
+            ModifyInfo info = new ModifyInfo(ModifyConstant.MODIFY_GOODS_STATUS.getPhrase(), beforeGoods.getBatchCode(), Status.valueStringOf(beforeGoodsStatus), Status.valueStringOf(afterGoodsStatus), ModifyInfo.TYPE_SALE);
             infoList.add(info);
         }
         Short beforeMaxDelivery = beforeGoods.getMaxDelivery();
         Short afterMaxDelivery = afterGoods.getMaxDelivery();
-        if (!beforeMaxDelivery.equals(afterMaxDelivery)) {
-            ModifyInfo info = new ModifyInfo();
-            info.setModifyField(ModifyConstant.MODIFY_MAX_DELIVERY.getPhrase());
-            info.setBefore(beforeMaxDelivery.toString());
-            info.setAfter(afterMaxDelivery.toString());
-            info.setType(ModifyInfo.TYPE_SALE);
-            info.setBatchCode(beforeGoods.getBatchCode());
+        if (!StringUtilB2C.equals(StringUtilB2C.valueOf(beforeMaxDelivery), StringUtilB2C.valueOf(afterMaxDelivery))) {
+            ModifyInfo info = new ModifyInfo(ModifyConstant.MODIFY_MAX_DELIVERY.getPhrase(), beforeGoods.getBatchCode(), StringUtilB2C.valueOf(beforeMaxDelivery), StringUtilB2C.valueOf(afterMaxDelivery), ModifyInfo.TYPE_SALE);
             infoList.add(info);
         }
+
         Integer beforeSale = sysConf.getStoreid().equals(beforeGoods.getStoreid()) ? IntegerConstant.B2C_SALE : IntegerConstant.SELF_SALE;
         String beforeStore = beforeSale.toString();
         String afterStore = afterGoods.getSelfSale();
         if (!beforeStore.equals(afterStore)) {
-            ModifyInfo info = new ModifyInfo();
-            info.setModifyField(ModifyConstant.MODIFY_SALE_METHOD.getPhrase());
+            ModifyInfo info = new ModifyInfo(ModifyConstant.MODIFY_SALE_METHOD.getPhrase(),beforeGoods.getBatchCode(), StringConstant.SALE_SELF, StringConstant.CONSIGNMENT, ModifyInfo.TYPE_SALE);
             if (beforeStore.equals(IntegerConstant.B2C_SALE.toString())) {
                 info.setBefore(StringConstant.CONSIGNMENT);
                 info.setAfter(StringConstant.SALE_SELF);
-            } else {
-                info.setBefore(StringConstant.SALE_SELF);
-                info.setAfter(StringConstant.CONSIGNMENT);
             }
-            info.setType(ModifyInfo.TYPE_SALE);
-            info.setBatchCode(beforeGoods.getBatchCode());
             infoList.add(info);
         }
         if (beforeGoods.getCurrencyName().equals(afterGoods.getCurrencyName())) {
             if (!GoodsUtil.compareWithQtyPrice(beforeGoods.getPrices(), afterGoods.getPrices(), beforeGoods.getCurrencyName())) {
                 // 生成分段数量修改记录
-                ModifyInfo qtyInfo = new ModifyInfo();
-                qtyInfo.setModifyField(ModifyConstant.MODIFY_QTY_NUMBER.getPhrase());
-                qtyInfo.setBefore(analyzeQtyNumber(beforeGoods.getPrices()));
-                qtyInfo.setAfter(analyzeQtyNumber(afterGoods.getPrices()));
-                qtyInfo.setType(ModifyInfo.TYPE_SALE);
-                qtyInfo.setBatchCode(beforeGoods.getBatchCode());
+                ModifyInfo qtyInfo = new ModifyInfo(ModifyConstant.MODIFY_QTY_NUMBER.getPhrase(), beforeGoods.getBatchCode(), analyzeQtyNumber(beforeGoods.getPrices()), analyzeQtyNumber(afterGoods.getPrices()), ModifyInfo.TYPE_SALE);
                 infoList.add(qtyInfo);
                 // 生成分段价格修改记录
-                ModifyInfo priceInfo = new ModifyInfo();
-                priceInfo.setModifyField(ModifyConstant.MODIFY_QTY_PRICE.getPhrase());
-                priceInfo.setBefore(analyzeQtyPrice(beforeGoods.getPrices()));
-                priceInfo.setAfter(analyzeQtyPrice(afterGoods.getPrices()));
-                priceInfo.setType(ModifyInfo.TYPE_SALE);
-                priceInfo.setBatchCode(beforeGoods.getBatchCode());
+                ModifyInfo priceInfo = new ModifyInfo(ModifyConstant.MODIFY_QTY_PRICE.getPhrase(), beforeGoods.getBatchCode(), analyzeQtyPrice(beforeGoods.getPrices()), analyzeQtyPrice(afterGoods.getPrices()), ModifyInfo.TYPE_SALE);
                 infoList.add(priceInfo);
             }
         }
@@ -1742,10 +1591,6 @@ public class GoodsServiceImpl implements GoodsService {
     public Goods updateGoods(Goods nowGoods, Goods oldGoods) {
         nowGoods.setMaxDelivery(oldGoods.getMaxDelivery());
         nowGoods.setMinDelivery(oldGoods.getMinDelivery());
-        nowGoods.setSelfDeliveryDemMaxTime(oldGoods.getSelfDeliveryDemMaxTime());
-        nowGoods.setSelfDeliveryDemMinTime(oldGoods.getSelfDeliveryDemMinTime());
-        nowGoods.setSelfDeliveryHKMaxTime(oldGoods.getSelfDeliveryHKMaxTime());
-        nowGoods.setSelfDeliveryHKMinTime(oldGoods.getSelfDeliveryHKMinTime());
         nowGoods.setTag(oldGoods.getTag());
         //判断是否切换了销售方式
         Boolean isChangeSaleType = false;
@@ -1822,6 +1667,7 @@ public class GoodsServiceImpl implements GoodsService {
                 nowGoods.setStatus((NumberUtil.compare(nowGoods.getReserve(), nowGoods.getMinBuyQty()) > -1) ? Status.AVAILABLE.value() : Status.UNAVAILABLE.value());
             }
         } else {
+            nowGoods.setAutoPublish(Boolean.FALSE);
             nowGoods.setStatus(Status.NO_SHELVE.value());
         }
 
@@ -1846,8 +1692,6 @@ public class GoodsServiceImpl implements GoodsService {
         List<Cart> cartList = cartService.updateCartByGoods(nowGoods);
         //更新浏览历史
         List<GoodsBrowsingHistory> browsingHistories = browsingHistoryService.updateGoodsBrowsingHistoryByGoods(nowGoods);
-//		ProductStandardPutOnInfo putOnInfo = productStandardPutOnInfoService.updateProductStandardPutOnInfoByGoods(nowGoods);
-//		Product product = productService.updateProduct(putOnInfo);
 		updateGoodsRelateInfo(orders, cartList, browsingHistories, null, null, history, nowGoods);
 		if (null != goodsHistory) {
             goodsHistoryService.save(goodsHistory);
@@ -1869,10 +1713,6 @@ public class GoodsServiceImpl implements GoodsService {
         Goods resultGoods = null;
         nowGoods.setMaxDelivery(oldGoods.getMaxDelivery());
         nowGoods.setMinDelivery(oldGoods.getMinDelivery());
-        nowGoods.setSelfDeliveryDemMaxTime(oldGoods.getSelfDeliveryDemMaxTime());
-        nowGoods.setSelfDeliveryDemMinTime(oldGoods.getSelfDeliveryDemMinTime());
-        nowGoods.setSelfDeliveryHKMaxTime(oldGoods.getSelfDeliveryHKMaxTime());
-        nowGoods.setSelfDeliveryHKMinTime(oldGoods.getSelfDeliveryHKMinTime());
         nowGoods.setTag(oldGoods.getTag());
         //判断是否切换了销售方式
         Boolean isChangeSaleType = false;
@@ -2177,32 +2017,34 @@ public class GoodsServiceImpl implements GoodsService {
      */
     @Override
     public void setB2CDelayTime(Goods goods) {
+        if (goods.getMaxDelivery() == null && goods.getMinDelivery() == null) {
+            return ;
+        } else if ((goods.getMaxDelivery() != null) || (goods.getMinDelivery() != null)) {
+            if (goods.getMaxDelivery() == null) {
+                goods.setMaxDelivery(goods.getMinDelivery());
+            }
+            if (goods.getMinDelivery() == null) {
+                goods.setMinDelivery(goods.getMaxDelivery());
+            }
+        }
+        TradeDeliveryDelayTime deliveryDelayTime = null;
         if (goods.getStoreid().equals(sysConf.getStoreid())) { //如果是库存寄售
-            if (goods.getCurrencyName().indexOf("RMB") > -1) {
+            if (goods.getCurrencyName().indexOf(StringConstant.RMB) > -1) {
                 List<TradeDeliveryDelayTime> delayTime3 = tradeDeliveryDelayTimeDao.getByType(3);
                 if (CollectionUtils.isEmpty(delayTime3)) {
                     throw new IllegalOperatorException("请联系商城,您供应商交货延长时间 国内发往国内没设置。");
                 }
-                goods.setB2cDeliveryDemMaxTime((short) (delayTime3.get(0).getMaxTime() + Short.valueOf(goods.getSelfDeliveryDemMaxTime() == null ? 0 : goods.getSelfDeliveryDemMaxTime())));
-                goods.setB2cDeliveryDemMinTime((short) (delayTime3.get(0).getMinTime() + Short.valueOf(goods.getSelfDeliveryDemMinTime() == null ? 0 : goods.getSelfDeliveryDemMinTime())));
-                goods.setB2cMaxDelivery((short) (delayTime3.get(0).getMaxTime() + Short.valueOf(goods.getMaxDelivery() == null ? 0 : goods.getMaxDelivery())));
-                goods.setB2cMinDelivery((short) (delayTime3.get(0).getMinTime() + Short.valueOf(goods.getMinDelivery() == null ? 0 : goods.getMinDelivery())));
-            }
-            if (goods.getCurrencyName().indexOf("USD") > -1) {
+                deliveryDelayTime = delayTime3.get(0);
+            }else {
                 List<TradeDeliveryDelayTime> delayTime1 = tradeDeliveryDelayTimeDao.getByType(2);
                 if (CollectionUtils.isEmpty(delayTime1)) {
                     throw new IllegalOperatorException("请联系商城,您供应商交货延长时间 国外发往国外没设置。");
                 }
-                goods.setB2cDeliveryHKMaxTime((short) (delayTime1.get(0).getMaxTime() + Short.valueOf(goods.getSelfDeliveryHKMaxTime() == null ? 0 : goods.getSelfDeliveryHKMaxTime())));
-                goods.setB2cDeliveryHKMinTime((short) (delayTime1.get(0).getMinTime() + Short.valueOf(goods.getSelfDeliveryHKMinTime() == null ? 0 : goods.getSelfDeliveryHKMinTime())));
-                goods.setB2cMaxDelivery((short) (delayTime1.get(0).getMaxTime() + Short.valueOf(goods.getMaxDelivery() == null ? 0 : goods.getMaxDelivery())));
-                goods.setB2cMinDelivery((short) (delayTime1.get(0).getMinTime() + Short.valueOf(goods.getMinDelivery() == null ? 0 : goods.getMinDelivery())));
+                deliveryDelayTime = delayTime1.get(0);
             }
+            goods.setB2cMaxDelivery((short) (deliveryDelayTime.getMaxTime() + Short.valueOf(goods.getMaxDelivery() == null ? 0 : goods.getMaxDelivery())));
+            goods.setB2cMinDelivery((short) (deliveryDelayTime.getMinTime() + Short.valueOf(goods.getMinDelivery() == null ? 0 : goods.getMinDelivery())));
         } else { //如果是店铺自营
-            goods.setB2cDeliveryDemMaxTime(goods.getSelfDeliveryDemMaxTime());
-            goods.setB2cDeliveryDemMinTime(goods.getSelfDeliveryDemMinTime());
-            goods.setB2cDeliveryHKMaxTime(goods.getSelfDeliveryHKMaxTime());
-            goods.setB2cDeliveryHKMinTime(goods.getSelfDeliveryHKMinTime());
             goods.setB2cMaxDelivery(goods.getMaxDelivery());
             goods.setB2cMinDelivery(goods.getMinDelivery());
         }
@@ -2924,13 +2766,13 @@ public class GoodsServiceImpl implements GoodsService {
     }
 
     public static void validDeliveryTime(Goods goods) {
-        if (goods.getCurrencyName().indexOf("RMB") > -1) {
-            if ((goods.getB2cDeliveryDemMaxTime() == null || goods.getB2cDeliveryDemMinTime() == null) && (goods.getMaxDelivery() == null || goods.getMinDelivery() == null)) {
+        if (goods.getCurrencyName().indexOf(StringConstant.RMB) > -1) {
+            if ((goods.getMaxDelivery() == null || goods.getMinDelivery() == null)) {
                 throw new IllegalOperatorException("产品包含人民币,但是大陆交期为空");
             }
         }
-        if (goods.getCurrencyName().indexOf("USD") > -1) {
-            if ((goods.getB2cDeliveryHKMaxTime() == null || goods.getB2cDeliveryHKMinTime() == null) && (goods.getMaxDelivery() == null || goods.getMinDelivery() == null)) {
+        if (goods.getCurrencyName().indexOf(StringConstant.USD) > -1) {
+            if ((goods.getMaxDelivery() == null || goods.getMinDelivery() == null)) {
                 throw new IllegalOperatorException("产品包含美金,但是香港交期为空");
             }
         }
@@ -4359,4 +4201,78 @@ public class GoodsServiceImpl implements GoodsService {
             return new ArrayList<>();
         }
     }
+
+    /**
+     * 将在售产品关联到物料,如果物料信息不存在,生成对应的物料信息
+     *
+     * @param goods 物料信息
+     */
+    @Override
+    public void bindGoodsToProduct(Goods goods) {
+        if (goods == null || StringUtils.isEmpty(goods.getCode()) || StringUtils.isEmpty(goods.getBrandNameEn()) ) {
+            throw new IllegalOperatorException("在售信息为空或在售信息的型号或品牌为空");
+        }
+        List<V_ProductPrivate> v_productPrivates = v_productPrivateService.findProductByPcmpcodeAndPbrandenAndEnUU(goods.getCode(), goods.getBrandNameEn(), goods.getEnUU());
+        if (CollectionUtils.isNotEmpty(v_productPrivates)) {
+            V_ProductPrivate v_productPrivate = v_productPrivates.get(0);
+            goods.setProductid(v_productPrivate.getId());
+            if (IntegerConstant.YES_INT != v_productPrivate.getB2cEnabled()) {
+                ProductPrivate productPrivate = productPrivateService.findByPrId(v_productPrivate.getId());
+                productPrivate.setB2cEnabled(com.uas.platform.b2c.core.constant.IntegerConstant.YES_SHORT);
+                productPrivate.setBatchCount(com.uas.platform.b2c.core.constant.IntegerConstant.YES_SHORT);
+                productPrivateService.saveProductPrivate(productPrivate);
+            }
+        } else {
+            // 如果没有物料信息,则声称对应的物料
+            Product  product = new Product();
+            product.setByGoods(goods);
+            if (StringUtils.isEmpty(product.getProduceDate())) {
+                product.setProduceDate(StringConstant.DEFAULT_PRODUCEDATE);
+            }
+            List<Brand> brandList = brandDao.findByName(goods.getBrandNameEn());
+            if (CollectionUtils.isEmpty(brandList)) {
+                product.setStandard(IntegerConstant.NO_INT);
+            } else {
+                List<Component> components = componentDao.findByBrandidAndCode(brandList.get(0).getId(), goods.getCode());
+                if (CollectionUtils.isNotEmpty(components)) {
+                    Component component = components.get(0);
+                    if (component != null) {
+                        product.setStandard(IntegerConstant.YES_INT);
+                        if (StringUtilB2C.isEmpty(goods.getAttach())) {
+                            goods.setAttach(component.getAttach());
+                        }
+                        if (StringUtils.isEmpty(goods.getImg())) {
+                            goods.setImg(component.getImg());
+                        }
+                        if (StringUtils.isEmpty(goods.getSpec())) {
+                            goods.setSpec(component.getDescription());
+                        }
+                        product.setCmpUuId(component.getUuid());
+                        product.setPcmpcode(component.getCode());
+                        product.setPbranden(component.getBrand().getNameEn());
+                        product.setPbrand(component.getBrand().getNameCn());
+                        product.setPbrandid(component.getBrandid());
+                        product.setPbranduuid(component.getBrand().getUuid());
+                        product.setKind(component.getKind().getNameCn());
+                        product.setKindid(component.getKindid());
+                        goods.setCode(component.getCode());
+                        goods.setBrandNameCn(product.getPbrand());
+                        goods.setBrandNameEn(product.getPbranden());
+                        goods.setBrandid(product.getPbrandid());
+                        goods.setBranduuid(product.getPbranduuid());
+                        goods.setUuid(product.getCmpUuId());
+                        goods.setKindNameCn(product.getKind());
+                        goods.setKindUuid(product.getKindid());
+                    }
+
+                }
+            }
+
+            Product product1 = productService.save(product);
+            ProductPrivate productPrivate = new ProductPrivate(product1.getId());
+            productPrivate.setBatchCount(IntegerConstant.YES_INT);
+            productPrivateDao.save(productPrivate);
+            goods.setProductid(product1.getId());
+        }
+    }
 }

+ 17 - 2
src/main/java/com/uas/platform/b2c/prod/commodity/service/impl/ProductPrivateServiceImpl.java

@@ -67,7 +67,7 @@ public class ProductPrivateServiceImpl implements ProductPrivateService {
      * @return List<ProductPrivate>
      */
     @Override
-    public List<ProductPrivate> saveProductPrivate(List<ProductPrivate> productPrivates) {
+    public List<ProductPrivate> saveProductPrivates(List<ProductPrivate> productPrivates) {
         if (CollectionUtils.isNotEmpty(productPrivates)) {
             productPrivateDao.save(productPrivates);
         }
@@ -112,10 +112,25 @@ public class ProductPrivateServiceImpl implements ProductPrivateService {
             }
         }
         if (CollectionUtils.isNotEmpty(productPrivates)) {
-            List<ProductPrivate> productPrivates1 = saveProductPrivate(productPrivates);
+            List<ProductPrivate> productPrivates1 = saveProductPrivates(productPrivates);
             return productPrivates1;
         } else {
             return Collections.emptyList();
         }
     }
+
+    /**
+     * 保存
+     *
+     * @param productPrivate 需要保存的信息
+     * @return List<ProductPrivate>
+     */
+    @Override
+    public ProductPrivate saveProductPrivate(ProductPrivate productPrivate) {
+        if (productPrivate == null) {
+            return null;
+        } else {
+            return productPrivateDao.save(productPrivate);
+        }
+    }
 }

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

@@ -0,0 +1,65 @@
+package com.uas.platform.b2c.prod.commodity.service.impl;
+
+import com.uas.platform.b2c.core.utils.StringUtilB2C;
+import com.uas.platform.b2c.prod.commodity.dao.V_ProductPrivateDao;
+import com.uas.platform.b2c.prod.commodity.model.V_ProductPrivate;
+import com.uas.platform.b2c.prod.commodity.service.V_ProductPrivateService;
+import org.apache.commons.collections.CollectionUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * description
+ *
+ * @author yuj 2018-08-21 11:25
+ */
+@Service
+public class V_ProductPrivateServiceImpl implements V_ProductPrivateService {
+
+    private final V_ProductPrivateDao v_ProductPrivateDao;
+
+    @Autowired
+    public V_ProductPrivateServiceImpl(V_ProductPrivateDao v_ProductPrivateDao) {
+        this.v_ProductPrivateDao = v_ProductPrivateDao;
+    }
+
+    /**
+     * 根据品牌、型号、企业enuu 获取物料信息,按照b2cenabled降序排列
+     *
+     * @param pcmpcode 型号
+     * @param pbranden 品牌
+     * @param enUU     企业enuu
+     * @return
+     */
+    @Override
+    public List<V_ProductPrivate> findProductByPcmpcodeAndPbrandenAndEnUU(String pcmpcode, String pbranden, Long enUU) {
+        if (StringUtilB2C.isEmpty(pcmpcode) || StringUtilB2C.isEmpty(pbranden) || enUU == null) {
+            return new ArrayList<>();
+        } else {
+            List<V_ProductPrivate> v_productPrivates = v_ProductPrivateDao.findProductByPcmpcodeAndPbrandenAndEnUU(pcmpcode, pbranden, enUU);
+            return v_productPrivates;
+        }
+    }
+
+    /**
+     * 根据物料信息获取对象
+     *
+     * @param prids 物料ids
+     * @return
+     */
+    @Override
+    public List<V_ProductPrivate> findByProductIds(Set<Long> prids) {
+        if (CollectionUtils.isNotEmpty(prids)) {
+            return new ArrayList<>();
+        } else {
+            List<Long> list = new ArrayList<>();
+            list.addAll(prids);
+            List<V_ProductPrivate> productPrivates = v_ProductPrivateDao.findProductInId(list);
+            return productPrivates;
+        }
+    }
+}

+ 1 - 1
src/main/resources/prod/sys.properties

@@ -14,7 +14,7 @@ enUU=10042875
 adminUU=1000002821
 adminName=\u5218\u840C\u51B0
 storeid = 33069557578d44e69bd91ad12d28a8d4
-enName=\u6DF1\u5733\u5E02\u4F18\u8F6F\u5546\u57CE\u79D1\u6280\u6709\u9650\u516C\u53F8
+enName=\u6DF1\u5733\u4F18\u8F6F\u5546\u57CE\u79D1\u6280\u6709\u9650\u516C\u53F8
 
 # YesPay config
 yes_gateway=https://openapi.ysepay.com/gateway.do