Jelajahi Sumber

调整产品库后台获取逻辑。

yujia 7 tahun lalu
induk
melakukan
028e33a3da
24 mengubah file dengan 868 tambahan dan 252 penghapusan
  1. 5 0
      src/main/java/com/uas/platform/b2c/core/constant/EncodingRulesConstant.java
  2. 5 0
      src/main/java/com/uas/platform/b2c/prod/commodity/constant/StringConstant.java
  3. 2 2
      src/main/java/com/uas/platform/b2c/prod/commodity/controller/ReleaseProductByBatchController.java
  4. 13 0
      src/main/java/com/uas/platform/b2c/prod/commodity/dao/CommodityInOutboundDao.java
  5. 1 1
      src/main/java/com/uas/platform/b2c/prod/commodity/dao/GoodsDao.java
  6. 26 0
      src/main/java/com/uas/platform/b2c/prod/commodity/dao/InOutboundDetailDao.java
  7. 28 1
      src/main/java/com/uas/platform/b2c/prod/commodity/model/CommodityInOutbound.java
  8. 152 13
      src/main/java/com/uas/platform/b2c/prod/commodity/model/Goods.java
  9. 13 0
      src/main/java/com/uas/platform/b2c/prod/commodity/model/GoodsHistory.java
  10. 86 3
      src/main/java/com/uas/platform/b2c/prod/commodity/model/InOutboundDetail.java
  11. 11 0
      src/main/java/com/uas/platform/b2c/prod/commodity/model/ProductPrivate.java
  12. 12 0
      src/main/java/com/uas/platform/b2c/prod/commodity/model/V_ProductPrivate.java
  13. 37 0
      src/main/java/com/uas/platform/b2c/prod/commodity/service/CommodityInOutboundService.java
  14. 7 0
      src/main/java/com/uas/platform/b2c/prod/commodity/service/GoodsService.java
  15. 19 0
      src/main/java/com/uas/platform/b2c/prod/commodity/service/InOutboundDetailService.java
  16. 3 1
      src/main/java/com/uas/platform/b2c/prod/commodity/service/ProductService.java
  17. 87 0
      src/main/java/com/uas/platform/b2c/prod/commodity/service/impl/CommodityInOutboundServiceImpl.java
  18. 37 15
      src/main/java/com/uas/platform/b2c/prod/commodity/service/impl/GoodsServiceImpl.java
  19. 43 0
      src/main/java/com/uas/platform/b2c/prod/commodity/service/impl/InOutboundDetailServiceImpl.java
  20. 1 3
      src/main/java/com/uas/platform/b2c/prod/commodity/service/impl/ProductPrivateServiceImpl.java
  21. 123 114
      src/main/java/com/uas/platform/b2c/prod/commodity/service/impl/ProductServiceImpl.java
  22. 118 87
      src/main/java/com/uas/platform/b2c/prod/commodity/service/impl/ReleaseProductByBatchServiceImpl.java
  23. 39 0
      src/main/java/com/uas/platform/b2c/prod/commodity/type/InOutBoundType.java
  24. 0 12
      src/main/java/com/uas/platform/b2c/trade/presale/model/Cart.java

+ 5 - 0
src/main/java/com/uas/platform/b2c/core/constant/EncodingRulesConstant.java

@@ -200,4 +200,9 @@ public class EncodingRulesConstant {
 	 */
 	public static final String PRODUCTSTANDARDPUTONINFO_NUM = "PSPO_TIMESTAP_NUMBER";
 
+
+	/**
+	 * 出入库记录 编号 + 8位时间戳 + 8位编码
+	 */
+	public static final String INOUTBOUND_NUM = "IOB_NUMBER";
 }

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

@@ -41,4 +41,9 @@ public class StringConstant {
      * 无物料
      */
     public static final String DEFAULTPACKAGING = "无";
+
+    /**
+     * 在售产品默认的生辰日期
+     */
+    public static final String DEFAULT_PRODUCEDATE = "2018-08-20";
 }

+ 2 - 2
src/main/java/com/uas/platform/b2c/prod/commodity/controller/ReleaseProductByBatchController.java

@@ -253,7 +253,7 @@ public class ReleaseProductByBatchController {
      * @return
      */
     @RequestMapping(value = "/release/excel/pcb", method = RequestMethod.POST)
-    public ModelMap releasePCBByExcel(FileUpload uploadItem, String currency, Integer repeatImport) {
+    public ModelMap releasePCBByExcel(FileUpload uploadItem, String currency, Integer ignoreImport) {
         ModelMap map = new ModelMap();
         String fileName = uploadItem.getFile().getOriginalFilename();
         String suffix = fileName.substring(fileName.lastIndexOf(".") + 1);
@@ -269,7 +269,7 @@ public class ReleaseProductByBatchController {
                 throw new IllegalOperatorException("文件格式不正确!请上传.xls或.xlsx格式的文件");
             }
             // pcb都为店铺自营、非个人上传、属于PCB模块上传
-            map = releaseProductByBatchService.releaseByWorkbook(workbook, true, currency, IntegerConstant.NO_SHORT.intValue(), repeatImport, true);
+            map = releaseProductByBatchService.releaseByWorkbook(workbook, true, currency, IntegerConstant.NO_SHORT.intValue(), ignoreImport, true);
         } catch (IOException e) {
             e.printStackTrace();
         }

+ 13 - 0
src/main/java/com/uas/platform/b2c/prod/commodity/dao/CommodityInOutboundDao.java

@@ -0,0 +1,13 @@
+package com.uas.platform.b2c.prod.commodity.dao;
+
+import com.uas.platform.b2c.prod.commodity.model.CommodityInOutbound;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.stereotype.Repository;
+
+/**
+ * Created by yujia on 2018/8/20.
+ */
+@Repository
+public interface CommodityInOutboundDao extends JpaRepository<CommodityInOutbound, Long>, JpaSpecificationExecutor<CommodityInOutbound> {
+}

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

@@ -530,7 +530,7 @@ public interface GoodsDao extends JpaSpecificationExecutor<Goods>, JpaRepository
      * @param ids the id 来源id 的信息
      * @return list
      */
-    @Query(value = "select g from Goods g where g.productid in (:ids)")
+    @Query(value = "select g from Goods g where g.productid in (:ids) order by g.id desc")
     List<Goods> findByProductIds(@Param("ids") List<Long> ids);
 
     /**

+ 26 - 0
src/main/java/com/uas/platform/b2c/prod/commodity/dao/InOutboundDetailDao.java

@@ -0,0 +1,26 @@
+package com.uas.platform.b2c.prod.commodity.dao;
+
+import com.uas.platform.b2c.prod.commodity.model.InOutboundDetail;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Created by yujia on 2018/8/20.
+ */
+@Repository
+public interface InOutboundDetailDao extends JpaRepository<InOutboundDetail, Long>, JpaSpecificationExecutor<InOutboundDetail> {
+
+    /**
+     * 根据物料id获取出入库明细
+     * @param productIds
+     * @return
+     */
+    @Query(value = "select i from InOutboundDetail where i.productId in (:productIds)")
+    List<InOutboundDetail> findByProductId(@Param("productIds") Set<Long> productIds);
+}

+ 28 - 1
src/main/java/com/uas/platform/b2c/prod/commodity/model/CommodityInOutbound.java

@@ -1,5 +1,9 @@
 package com.uas.platform.b2c.prod.commodity.model;
 
+import com.uas.platform.b2c.core.support.SystemSession;
+import com.uas.platform.b2c.prod.commodity.type.InOutBoundType;
+import org.apache.commons.lang.StringUtils;
+
 import javax.persistence.*;
 import java.io.Serializable;
 import java.util.Date;
@@ -80,6 +84,9 @@ public class CommodityInOutbound implements Serializable {
     @Column(name = "cio_operator_user_name")
     private String operaterUserName;
 
+    /**
+     * 关联单号
+     */
     @Column(name = "cio_associate_orderid")
     private String associateOrderid;
 
@@ -87,7 +94,7 @@ public class CommodityInOutbound implements Serializable {
      * 订单明细
      */
     @OneToMany(mappedBy = "commodityInOutbound", cascade = {CascadeType.ALL}, fetch = FetchType.EAGER)
-    @OrderBy("iobd_detno")
+    @OrderBy("detno")
     private Set<InOutboundDetail> inOutboundDetails;
 
     public Long getId() {
@@ -193,4 +200,24 @@ public class CommodityInOutbound implements Serializable {
     public void setInOutboundDetails(Set<InOutboundDetail> inOutboundDetails) {
         this.inOutboundDetails = inOutboundDetails;
     }
+
+    public CommodityInOutbound() {
+    }
+
+    public CommodityInOutbound(String type) {
+        if (StringUtils.isNotEmpty(type)) {
+            this.opertatorType = type;
+            if (InOutBoundType.INBOUND == type || InOutBoundType.OTHER_INBOUND == type || InOutBoundType.PURCHASE_INBOUND == type) {
+                this.type = InOutBoundType.INBOUND;
+
+            } else if (InOutBoundType.OUTBOUND == type || InOutBoundType.OTHER_OUTBOUND == type || InOutBoundType.SELL_OUTBOUND == type) {
+                this.type = InOutBoundType.OUTBOUND;
+            }
+        }
+        this.enuu = SystemSession.getUser().getEnterprise().getUu();
+        this.enName = SystemSession.getUser().getEnterprise().getEnName();
+        this.createTime = new Date();
+        this.operaterUseruu = SystemSession.getUser().getUserUU();
+        this.operaterUserName = SystemSession.getUser().getUserName();
+    }
 }

+ 152 - 13
src/main/java/com/uas/platform/b2c/prod/commodity/model/Goods.java

@@ -1,10 +1,13 @@
 package com.uas.platform.b2c.prod.commodity.model;
 
 import com.alibaba.fastjson.annotation.JSONField;
+import com.uas.platform.b2c.core.constant.Status;
 import com.uas.platform.b2c.core.support.SystemSession;
 import com.uas.platform.b2c.core.utils.FastjsonUtils;
 import com.uas.platform.b2c.core.utils.NumberUtil;
 import com.uas.platform.b2c.prod.commodity.constant.DoubleConstant;
+import com.uas.platform.b2c.prod.commodity.constant.IntegerConstant;
+import com.uas.platform.b2c.prod.commodity.constant.StringConstant;
 import com.uas.platform.b2c.prod.product.brand.modal.BrandInfo;
 import com.uas.platform.b2c.trade.presale.model.TradeDeliveryDelayTime;
 import com.uas.platform.b2c.trade.support.CodeType;
@@ -535,6 +538,9 @@ public class Goods implements Serializable {
 	@Column(name = "go_spec", length = 4000)
 	private String spec;
 
+	@Column(name = "go_autopublish", columnDefinition = "TINYINT(1)")
+	private Boolean autoPublish;
+
 	@Transient
 	private ProductAttachSubmit productAttachSubmit;
 
@@ -765,6 +771,25 @@ public class Goods implements Serializable {
 		this.minPackQty = minPackQty;
 	}
 
+	/**
+	 * 调整最小包或最小起订量之后 对应数量要调整
+	 */
+	public void setMinBuyQty() {
+		if (this.breakUp) {
+			if(NumberUtil.compare(this.minBuyQty, this.minPackQty) < 0) {
+				this.minBuyQty = this.minPackQty;
+			}
+		} else {
+			Double remainder = this.minBuyQty % this.minPackQty;
+			if (NumberUtil.compare(remainder, DoubleConstant.zero) > 0) {
+				this.minBuyQty = NumberUtil.sub(this.minBuyQty, remainder);
+				if (NumberUtil.compare(this.minBuyQty, this.minPackQty) < 0) {
+					this.minBuyQty = this.minPackQty;
+				}
+			}
+		}
+	}
+
 	public String getBatchCode() {
 		return batchCode;
 	}
@@ -1463,6 +1488,15 @@ public class Goods implements Serializable {
 		this.sold = sold;
 	}
 
+	public Boolean getAutoPublish() {
+		return autoPublish;
+	}
+
+	public Goods setAutoPublish(Boolean autoPublish) {
+		this.autoPublish = autoPublish;
+		return this;
+	}
+
 	/**
 	 * 获取最大交期
 	 * @return
@@ -1706,8 +1740,7 @@ public class Goods implements Serializable {
 		this.productid = releaseProductByBatch.getProductid();
 		this.prodNum = releaseProductByBatch.getProductNum();
 		this.tag = StringUtils.isEmpty(releaseProductByBatch.getTag()) ? "类型1" : releaseProductByBatch.getTag();
-		this.unit = StringUtils.isEmpty(releaseProductByBatch.getUnit()) ? "PCS" : releaseProductByBatch.getUnit();
-		this.shipArea = releaseProductByBatch.getShipArea();
+		this.unit = StringUtils.isEmpty(releaseProductByBatch.getUnit()) ? StringConstant.UNIT : releaseProductByBatch.getUnit();
 		this.batchCode = "BT" + (Long.valueOf(releaseProductByBatch.getRelbatchid()) + releaseProductByBatch.getNum());
 		this.brandNameCn = releaseProductByBatch.getB2cBrandcn();
 		this.brandNameEn = releaseProductByBatch.getB2cBranden();
@@ -1720,10 +1753,12 @@ public class Goods implements Serializable {
 		this.enUU = SystemSession.getUser().getEnterprise().getUu();
 		this.img = releaseProductByBatch.getImg();
 		this.kindNameCn = releaseProductByBatch.getKindName();
+		this.kindUuid = releaseProductByBatch.getKindUuid();
 		this.minBuyQty = releaseProductByBatch.getMinBuyQty();
 		this.minPackQty = releaseProductByBatch.getMinPackage();
 		this.original = releaseProductByBatch.getOriginal();
-		this.produceDate = releaseProductByBatch.getProductDate();
+		this.shipArea = releaseProductByBatch.getShipArea();
+		this.produceDate = StringUtils.isEmpty(releaseProductByBatch.getProductDate()) ? StringConstant.DEFAULT_PRODUCEDATE : releaseProductByBatch.getProductDate();
 		this.publishPhone = releaseProductByBatch.getPublisherTel();
 		this.publisherName = releaseProductByBatch.getPublisherName();
 		this.publisherUU = releaseProductByBatch.getPublisherUu();
@@ -1733,19 +1768,20 @@ public class Goods implements Serializable {
 		this.lastReserve = releaseProductByBatch.getReserve();
 		this.returnInWeek = releaseProductByBatch.getReturnInWeek();
 		this.sampleQty = releaseProductByBatch.getSampleqty();
-		this.status = (NumberUtil.compare(releaseProductByBatch.getReserve(), releaseProductByBatch.getMinBuyQty()) > -1) ? 601 : 602;
 		this.updateDate = releaseProductByBatch.getCreateDate();
 		this.uuid = releaseProductByBatch.getComponentUuId();
 		this.rmbTaxRate = releaseProductByBatch.getRmbTaxRate();
 		this.usdTaxRate = releaseProductByBatch.getUsdTaxRate();
-		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 (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());
+			}
 		}
 		this.maxPriceRMB = releaseProductByBatch.getMaxPriceRMB();
 		this.minPriceRMB = releaseProductByBatch.getMinPriceRMB();
@@ -1754,13 +1790,116 @@ public class Goods implements Serializable {
 		this.batchid = releaseProductByBatch.getRelbatchid();
 		this.storeid = releaseProductByBatch.getStoreid();
 		this.storeName = releaseProductByBatch.getStoreName();
-		this.kindUuid = releaseProductByBatch.getKindUuid();
 		this.packaging = releaseProductByBatch.getPackaging();
 		this.encapsulation = releaseProductByBatch.getEncapsulation();
 		this.breakUp = releaseProductByBatch.getBreakUp();
 		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();
+		}
+		return this;
+	}
+
+	/**
+	 * 根据临时表更新goods信息
+	 * @param releaseProductByBatch
+	 * @return
+	 */
+	public Goods updateGoodsByReleaseProductByBatch(ReleaseProductByBatch releaseProductByBatch, TradeDeliveryDelayTime deliveryDelayTime, Integer ignoreImport) {
+		if (IntegerConstant.NO_INT == ignoreImport || org.apache.commons.lang.StringUtils.isNotEmpty(this.tag)) {
+			this.tag = StringUtils.isEmpty(releaseProductByBatch.getTag()) ? "类型1" : releaseProductByBatch.getTag();
+		}
+		if (IntegerConstant.NO_INT == ignoreImport || org.apache.commons.lang.StringUtils.isNotEmpty(this.unit)) {
+			this.unit = StringUtils.isEmpty(releaseProductByBatch.getUnit()) ? StringConstant.UNIT : releaseProductByBatch.getUnit();
+		}
+		this.brandNameCn = releaseProductByBatch.getB2cBrandcn();
+		this.brandNameEn = releaseProductByBatch.getB2cBranden();
+		this.brandid = releaseProductByBatch.getBrandId();
+		this.branduuid = releaseProductByBatch.getBranduuid();
+		this.code = releaseProductByBatch.getB2cCode();
+		this.uuid = releaseProductByBatch.getComponentUuId();
+		this.img = releaseProductByBatch.getImg();
+		if (IntegerConstant.NO_INT == ignoreImport || org.apache.commons.lang.StringUtils.isNotEmpty(this.kindNameCn) || releaseProductByBatch.getKindUuid() != null) {
+			this.kindNameCn = releaseProductByBatch.getKindName();
+			this.kindUuid = releaseProductByBatch.getKindUuid();
+		}
+		if (IntegerConstant.NO_INT == ignoreImport || this.minBuyQty == null) {
+			this.minBuyQty = releaseProductByBatch.getMinBuyQty();
+			this.minPackQty = releaseProductByBatch.getMinPackage();
+		}
+		if (IntegerConstant.NO_INT == ignoreImport || org.apache.commons.lang.StringUtils.isEmpty(this.produceDate)) {
+			this.produceDate = StringUtils.isEmpty(releaseProductByBatch.getProductDate()) ? StringConstant.DEFAULT_PRODUCEDATE : releaseProductByBatch.getProductDate();
+		}
+		if (IntegerConstant.NO_INT == ignoreImport || org.apache.commons.lang.StringUtils.isEmpty(this.qtyPrice)) {
+			this.qtyPrice = releaseProductByBatch.getQtyPrice();
+			this.rmbTaxRate = releaseProductByBatch.getRmbTaxRate();
+			this.usdTaxRate = releaseProductByBatch.getUsdTaxRate();
+			this.maxPriceRMB = releaseProductByBatch.getMaxPriceRMB();
+			this.minPriceRMB = releaseProductByBatch.getMinPriceRMB();
+			this.maxPriceUSD = releaseProductByBatch.getMaxPriceUSD();
+			this.minPriceUSD = releaseProductByBatch.getMinPriceUSD();
+		}
+		if (IntegerConstant.NO_INT == ignoreImport || org.apache.commons.lang.StringUtils.isEmpty(this.remark)) {
+			this.remark = releaseProductByBatch.getRemark();
+		}
+		if (IntegerConstant.NO_INT == ignoreImport || NumberUtil.compare(this.reserve, DoubleConstant.zero) < 1) {
+			this.reserve = releaseProductByBatch.getReserve();
+			this.lastReserve = releaseProductByBatch.getReserve();
+		}
+		if (IntegerConstant.NO_INT == ignoreImport || org.apache.commons.lang.StringUtils.isEmpty(this.packaging)) {
+			this.packaging = releaseProductByBatch.getPackaging();
+		}
+		if (IntegerConstant.NO_INT == ignoreImport || org.apache.commons.lang.StringUtils.isEmpty(this.encapsulation)) {
+			this.encapsulation = releaseProductByBatch.getEncapsulation();
+		}
+		if (IntegerConstant.NO_INT == ignoreImport || org.apache.commons.lang.StringUtils.isEmpty(this.spec)) {
+			this.spec = releaseProductByBatch.getSpec();
+		}
+		this.returnInWeek = releaseProductByBatch.getReturnInWeek();
+		this.sampleQty = releaseProductByBatch.getSampleqty();
+		this.updateDate = releaseProductByBatch.getCreateDate();
+		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 (IntegerConstant.NO_INT == ignoreImport || StringUtils.isEmpty(this.breakUp)) {
+			this.breakUp = releaseProductByBatch.getBreakUp();
+			this.perQty = releaseProductByBatch.getBreakUp() ? 1 : releaseProductByBatch.getMinPackage();
+		}
+		this.batchid = releaseProductByBatch.getRelbatchid();
+		this.storeid = releaseProductByBatch.getStoreid();
+		this.storeName = releaseProductByBatch.getStoreName();
+		this.attach = releaseProductByBatch.getAttach();
+		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();
+		}
+
 		return this;
 	}
 }

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

@@ -446,6 +446,9 @@ public class GoodsHistory {
 	@Column(name = "go_batchid")
 	private String batchid;
 
+	@Column(name = "go_autopublish", columnDefinition = "TINYINT(1)")
+	private Boolean autoPublish;
+
 	@Transient
 	private String enterpriseName;
 
@@ -1083,6 +1086,7 @@ public class GoodsHistory {
 		this.goid  = goods.getId();
 		this.batchid = goods.getBatchid();
 		this.attach = goods.getAttach();
+		this.autoPublish = goods.getAutoPublish();
     }
 
 	public Short getSelfDeliveryDemMinTime() {
@@ -1234,4 +1238,13 @@ public class GoodsHistory {
 		this.batchid = batchid;
 		return this;
 	}
+
+	public Boolean getAutoPublish() {
+		return autoPublish;
+	}
+
+	public GoodsHistory setAutoPublish(Boolean autoPublish) {
+		this.autoPublish = autoPublish;
+		return this;
+	}
 }

+ 86 - 3
src/main/java/com/uas/platform/b2c/prod/commodity/model/InOutboundDetail.java

@@ -16,42 +16,90 @@ public class InOutboundDetail implements Serializable {
     @Column(name = "id")
     private Long id;
 
+    /**
+     * 器件型号
+     */
     @Column(name = "iobd_cmpcode")
     private String cmpCode = "";
 
+    /**
+     * 器件的uuid
+     */
     @Column(name = "iobd_cmpuuid")
     private String cmpuuid = "";
 
+    /**
+     * 品牌英文名
+     */
     @Column(name = "iobd_branden")
     private String brandEn = "";
 
+    /**
+     * 品牌的中文名称
+     */
     @Column(name = "iobd_brandcn")
     private String brandCn = "";
 
+    /**
+     * 品牌的id
+     */
     @Column(name = "iobd_brandid")
-    private String brandId;
+    private Long brandId;
 
+    /**
+     * 品牌的uuid
+     */
+    @Column(name = "iobd_branduuid")
+    private String branduuid;
+
+    /**
+     * 类目名称
+     */
     @Column(name = "iobd_kind_name")
     private String kindName = "";
 
+    /**
+     * 类目id
+     */
     @Column(name = "iobd_kindid")
     private Long kindId;
 
+    /**
+     * 规格信息
+     */
     @Column(name = "iobd_spec")
     private String spec = "";
 
+    /**
+     * 出入库数量
+     */
     @Column(name = "iobd_qty")
     private Double qty;
 
+    /**
+     * 价格,出库对应卖出价,入库对应成本价
+     */
     @Column(name = "iobd_price")
     private Double price;
 
+    /**
+     * 出库明细的主键
+     */
     @Column(name = "iobd_ciobid")
     private Long ciobid;
 
+    /**
+     * 序号
+     */
     @Column(name = "iobd_detno")
     private Short detno;
 
+    /**
+     * 物料id
+     */
+    @Column(name = "iobc_productid")
+    private Long productId;
+
     @ManyToOne(cascade = {CascadeType.ALL}, optional = true)
     @JoinColumn(name = "iobd_ciobid", nullable = false)
     private CommodityInOutbound commodityInOutbound;
@@ -97,11 +145,11 @@ public class InOutboundDetail implements Serializable {
         this.brandCn = brandCn;
     }
 
-    public String getBrandId() {
+    public Long getBrandId() {
         return brandId;
     }
 
-    public void setBrandId(String brandId) {
+    public void setBrandId(Long brandId) {
         this.brandId = brandId;
     }
 
@@ -170,4 +218,39 @@ public class InOutboundDetail implements Serializable {
     public void setCommodityInOutbound(CommodityInOutbound commodityInOutbound) {
         this.commodityInOutbound = commodityInOutbound;
     }
+
+    public Long getProductId() {
+        return productId;
+    }
+
+    public InOutboundDetail setProductId(Long productId) {
+        this.productId = productId;
+        return this;
+    }
+
+    public String getBranduuid() {
+        return branduuid;
+    }
+
+    public InOutboundDetail setBranduuid(String branduuid) {
+        this.branduuid = branduuid;
+        return this;
+    }
+
+    public InOutboundDetail() {
+    }
+
+    public InOutboundDetail(Product product) {
+        this.brandCn = product.getPbrand();
+        this.brandEn = product.getPbranden();
+        this.brandId = product.getPbrandid();
+        this.branduuid = product.getPbranduuid();
+        this.kindId = product.getKindid();
+        this.kindName = product.getKind();
+        this.cmpCode = product.getPcmpcode();
+        this.cmpuuid = product.getCmpUuId();
+        this.spec = product.getSpec();
+        this.qty = product.getErpReserve();
+        this.price = product.getPrice();
+    }
 }

+ 11 - 0
src/main/java/com/uas/platform/b2c/prod/commodity/model/ProductPrivate.java

@@ -1,5 +1,7 @@
 package com.uas.platform.b2c.prod.commodity.model;
 
+import com.uas.platform.b2c.core.constant.IntegerConstant;
+
 import javax.persistence.*;
 
 /**
@@ -80,4 +82,13 @@ public class ProductPrivate {
         this.attach = attach;
         return this;
     }
+
+    public ProductPrivate() {
+    }
+
+    public ProductPrivate(Long productId) {
+        this.b2cEnabled = IntegerConstant.YES_SHORT;
+        this.prId = productId;
+        this.batchCount = IntegerConstant.NO_SHORT;
+    }
 }

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

@@ -299,6 +299,9 @@ public class V_ProductPrivate implements Serializable {
     @Transient
     private ProductAttachSubmit productAttachSubmit;
 
+    @Transient
+    private Goods goods;
+
     public Long getId() {
         return id;
     }
@@ -653,4 +656,13 @@ public class V_ProductPrivate implements Serializable {
         this.attach = attach;
         return this;
     }
+
+    public Goods getGoods() {
+        return goods;
+    }
+
+    public V_ProductPrivate setGoods(Goods goods) {
+        this.goods = goods;
+        return this;
+    }
 }

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

@@ -0,0 +1,37 @@
+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 java.util.List;
+import java.util.Set;
+
+/**
+ * Created by yujia on 2018/8/20.
+ */
+public interface CommodityInOutboundService {
+
+    /**
+     * 批量保存出入库记录
+     * @param commodityInOutbounds
+     * @return
+     */
+    List<CommodityInOutbound> save(List<CommodityInOutbound> commodityInOutbounds);
+
+
+    /**
+     * 单个保存出入库记录
+     * @param commodityInOutbound 出入库记录
+     * @return CommodityInOutbound
+     */
+    CommodityInOutbound save(CommodityInOutbound commodityInOutbound);
+
+
+    /**
+     * 根据出入库明细生成出入库记录
+     * @param details 明细信息
+     * @param type 出入库类型
+     * @return
+     */
+    CommodityInOutbound produceCommodityInOutbound(Set<InOutboundDetail> details, String type);
+}

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

@@ -792,4 +792,11 @@ public interface GoodsService {
      * @return  List<Goods>
      */
     List<Goods> findByBatchId(String batchid);
+
+    /**
+     * 根据ids获取物料信息
+     * @param ids 物料的ids
+     * @return List<Goods>
+     */
+    List<Goods> findByProductids(List<Long> ids);
 }

+ 19 - 0
src/main/java/com/uas/platform/b2c/prod/commodity/service/InOutboundDetailService.java

@@ -0,0 +1,19 @@
+package com.uas.platform.b2c.prod.commodity.service;
+
+import com.uas.platform.b2c.prod.commodity.model.InOutboundDetail;
+
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Created by yujia on 2018/8/20.
+ */
+public interface InOutboundDetailService {
+
+    /**
+     * 根据物料id获取出入库明细
+     * @param productIds
+     * @return
+     */
+    List<InOutboundDetail> findByProductId(Set<Long> productIds);
+}

+ 3 - 1
src/main/java/com/uas/platform/b2c/prod/commodity/service/ProductService.java

@@ -350,6 +350,8 @@ public interface ProductService {
      * 根据临时表的数据,更新物料的信息(包装数,包装方式、成本单价)
      * @param reList 临时表的id
      * @param ignoreImport 1表示忽略导入,0代表覆盖导入
+     * @param newInOutboundDetail 出入库明细
+     * @param inOutMap 出入库的map
      */
-    void updateProductsByReleaseProductByBatch(Set<ReleaseProductByBatch> reList, Integer ignoreImport);
+    void updateProductsByReleaseProductByBatch(Set<ReleaseProductByBatch> reList, Integer ignoreImport, Set<InOutboundDetail> newInOutboundDetail, Map<String, Set<InOutboundDetail>> inOutMap);
 }

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

@@ -0,0 +1,87 @@
+package com.uas.platform.b2c.prod.commodity.service.impl;
+
+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.service.CommodityInOutboundService;
+import com.uas.platform.b2c.prod.product.common.service.CreateNumberService;
+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-20 14:29
+ */
+@Service
+public class CommodityInOutboundServiceImpl implements CommodityInOutboundService {
+
+    private final CommodityInOutboundDao commodityInOutboundDao;
+
+    private final CreateNumberService createNumberService;
+
+    @Autowired
+    public CommodityInOutboundServiceImpl(CommodityInOutboundDao commodityInOutboundDao, CreateNumberService createNumberService) {
+        this.commodityInOutboundDao = commodityInOutboundDao;
+        this.createNumberService = createNumberService;
+    }
+
+    /**
+     * 批量保存出入库记录
+     *
+     * @param commodityInOutbounds
+     * @return
+     */
+    @Override
+    public List<CommodityInOutbound> save(List<CommodityInOutbound> commodityInOutbounds) {
+        if (CollectionUtils.isNotEmpty(commodityInOutbounds)) {
+            return commodityInOutboundDao.save(commodityInOutbounds);
+        } else {
+            return new ArrayList<>();
+        }
+    }
+
+    /**
+     * 单个保存出入库记录
+     *
+     * @param commodityInOutbound 出入库记录
+     * @return CommodityInOutbound
+     */
+    @Override
+    public CommodityInOutbound save(CommodityInOutbound commodityInOutbound) {
+        if (commodityInOutbound == null) {
+            return null;
+        } else {
+            return commodityInOutboundDao.save(commodityInOutbound);
+        }
+    }
+
+    /**
+     * 根据出入库明细生成出入库记录
+     * @param details 明细信息
+     * @param type 出入库类型
+     * @return
+     */
+    @Override
+    public CommodityInOutbound produceCommodityInOutbound(Set<InOutboundDetail> details, String type) {
+        if (CollectionUtils.isNotEmpty(details)) {
+            String inOutboundId = createNumberService.generateOrderNumber(com.uas.platform.b2c.core.constant.EncodingRulesConstant.INOUTBOUND_NUM, "trade$commodity_in_outbound", 8);
+            CommodityInOutbound inOutbound = new CommodityInOutbound(type);
+            Short detno = 1;
+            for (InOutboundDetail detail : details) {
+                detail.setDetno(detno++);
+                detail.setCommodityInOutbound(inOutbound);
+            }
+            inOutbound.setInOutId(inOutboundId);
+            inOutbound.setInOutboundDetails(details);
+            return inOutbound;
+        } else {
+            return null;
+        }
+    }
+}

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

@@ -1383,19 +1383,6 @@ public class GoodsServiceImpl implements GoodsService {
         } else if (resultMap.getCode() != CodeType.OK.code()) {
             return resultMap;
         }
-        List<Goods> tagInTheProdNums = goodsDao.findSameTagInTheProdNum(goods.getProdNum(), goods.getTag());
-        for (Goods tagInTheProdNum : tagInTheProdNums) {
-            if (goods.getTag().equals(tagInTheProdNum.getTag()) && (goods.getId().longValue() != tagInTheProdNum.getId().longValue())) {
-                return new ResultMap(CodeType.NOT_PERMIT.code(), "标签不能与该器件现有产品的标签重复");
-            }
-        }
-        List<Goods> repeatGoodsInProductId = goodsDao.findRepeatGoodsInProductId(goods.getProductid(), goods.getProduceDate(), goods.getPackaging(), goods.getMinPackQty(), goods.getMinBuyQty(), goods.getMaxDelivery(), goods.getMinDelivery(), goods.getUnit());
-        for (Goods goods1 : repeatGoodsInProductId) {
-            if (!goods1.getId().equals(goods.getId())
-                    && GoodsUtil.compareWithQtyPrice(goods1.getPrices(), goods.getPrices(), goods.getCurrencyName())) {
-                return new ResultMap(CodeType.SAVED.code(), "该物料已存在(包装、日期、最小包装量、最小起订量、交期、单位、价格)相同的信息");
-            }
-        }
         // 比较两个goods编辑信息
         compareGoodsWithModify(nowGoods, goods);
         resultGoods = updateGoods(nowGoods, goods);
@@ -1801,7 +1788,9 @@ public class GoodsServiceImpl implements GoodsService {
         }
 
         // 设置货到香港,货到大陆的延长时间
-        setB2CDelayTime(nowGoods);
+        if (nowGoods.getMaxDelivery() != null) {
+            setB2CDelayTime(nowGoods);
+        }
 
         nowGoods.setUpdateDate(new Date());
         nowGoods.setImg(oldGoods.getImg());
@@ -1824,6 +1813,7 @@ public class GoodsServiceImpl implements GoodsService {
         nowGoods.setMaxPriceRMB(GoodsUtil.getMaxPriceRMB(nowGoods.getPrices()));
         nowGoods.setMinPriceUSD(GoodsUtil.getMinPriceUSD(nowGoods.getPrices()));
         nowGoods.setMaxPriceUSD(GoodsUtil.getMaxPriceUSD(nowGoods.getPrices()));
+        nowGoods.setAutoPublish(oldGoods.getAutoPublish());
         if((nowGoods.getStatus().intValue() != Status.REMOVED.value()) && (nowGoods.getStatus().intValue() != Status.NO_SHELVE.value())) {
             if (NumberUtil.compare(nowGoods.getReserve(), nowGoods.getMinBuyQty()) > -1) {
                 nowGoods.setStatus(Status.AVAILABLE.value());
@@ -1841,7 +1831,6 @@ public class GoodsServiceImpl implements GoodsService {
         // 修改上下架状态并产生上下架历史
         GoodsHistory goodsHistory = null;
         if (!nowGoods.getStatus().equals(oldGoods.getStatus())) {
-            //nowGoods.setStatus(oldGoods.getStatus());
             // 如果是下架
             if (oldGoods.getStatus().equals(Status.REMOVED.value())) {
                 goodsHistory = goodsHistoryService.converTGoodsHist(nowGoods, OperateType.Down.getPhrase(), false);
@@ -4245,6 +4234,23 @@ public class GoodsServiceImpl implements GoodsService {
                 goods.setImg(product.getCmpImg());
                 goods.setUuid(product.getCmpUuId());
                 goods.setCode(product.getPcmpcode());
+                goods.setMinPackQty(product.getMinPackQty());
+                goods.setPackaging(product.getPackaging());
+                goods.setMinBuyQty();
+                if (goods.getAutoPublish() == null) {
+                    goods.setAutoPublish(Boolean.TRUE);
+                }
+                if (goods.getAutoPublish()) {
+                    if (StringUtils.isEmpty(goods.getPackaging()) || StringUtils.isEmpty(goods.getProduceDate()) || (goods.getMinBuyQty() == null) || (goods.getMinPackQty() == null) || (goods.getB2cMaxDelivery() == null) || (goods.getB2cMinDelivery() == null) || StringUtils.isEmpty(goods.getQtyPrice())) {
+                        //做未上架处理
+                        goods.setStatus(Status.NO_SHELVE.value());
+                    } else {
+                        //如果信息填写全,默认上架
+                        goods.setStatus((NumberUtil.compare(goods.getReserve(), goods.getMinBuyQty()) > -1) ? Status.AVAILABLE.value() : Status.UNAVAILABLE.value());
+                    }
+                } else {
+                    goods.setStatus(Status.NO_SHELVE.value());
+                }
                 GoodsHistory history = goodsHistoryService.converTGoodsHist(goods, GoodsHistory.OperateType.Update.getPhrase(), false);
                 list.add(history);
             }
@@ -4334,4 +4340,20 @@ public class GoodsServiceImpl implements GoodsService {
             return goodses;
         }
     }
+
+    /**
+     * 根据ids获取物料信息
+     *
+     * @param ids 物料的ids
+     * @return List<Goods>
+     */
+    @Override
+    public List<Goods> findByProductids(List<Long> ids) {
+        if (CollectionUtils.isNotEmpty(ids)) {
+            List<Goods> goodses = goodsDao.findByProductIds(ids);
+            return goodses;
+        } else {
+            return new ArrayList<>();
+        }
+    }
 }

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

@@ -0,0 +1,43 @@
+package com.uas.platform.b2c.prod.commodity.service.impl;
+
+import com.uas.platform.b2c.prod.commodity.model.InOutboundDetail;
+import com.uas.platform.b2c.prod.commodity.dao.InOutboundDetailDao;
+import com.uas.platform.b2c.prod.commodity.service.InOutboundDetailService;
+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-20 11:05
+ */
+@Service
+public class InOutboundDetailServiceImpl implements InOutboundDetailService {
+
+    private final InOutboundDetailDao inOutboundDetailDao;
+
+    @Autowired
+    public InOutboundDetailServiceImpl(InOutboundDetailDao inOutboundDetailDao) {
+        this.inOutboundDetailDao = inOutboundDetailDao;
+    }
+
+    /**
+     * 根据物料id获取出入库明细
+     *
+     * @param productIds
+     * @return
+     */
+    @Override
+    public List<InOutboundDetail> findByProductId(Set<Long> productIds) {
+        if (CollectionUtils.isEmpty(productIds)) {
+            return new ArrayList<>();
+        } else {
+            return inOutboundDetailDao.findByProductId(productIds);
+        }
+    }
+}

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

@@ -106,10 +106,8 @@ public class ProductPrivateServiceImpl implements ProductPrivateService {
                 }
             }
             if (!isExist) {
-                productPrivate = new ProductPrivate();
-                productPrivate.setPrId(productId);
+                productPrivate = new ProductPrivate(productId);
                 productPrivate.setBatchCount(batchCount);
-                productPrivate.setB2cEnabled(IntegerConstant.YES_SHORT);
                 productPrivates.add(productPrivate);
             }
         }

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

@@ -7,6 +7,7 @@ import com.uas.platform.b2c.advertise.ad.service.RecommendProductService;
 import com.uas.platform.b2c.common.account.dao.UserDao;
 import com.uas.platform.b2c.common.account.model.Enterprise;
 import com.uas.platform.b2c.common.account.service.EnterpriseService;
+import com.uas.platform.b2c.common.base.dao.CommonDao;
 import com.uas.platform.b2c.common.search.rpc.service.SearchService;
 import com.uas.platform.b2c.common.search.util.SPage;
 import com.uas.platform.b2c.core.config.SysConf;
@@ -23,6 +24,7 @@ import com.uas.platform.b2c.prod.commodity.constant.StringConstant;
 import com.uas.platform.b2c.prod.commodity.dao.*;
 import com.uas.platform.b2c.prod.commodity.model.*;
 import com.uas.platform.b2c.prod.commodity.service.*;
+import com.uas.platform.b2c.prod.commodity.type.InOutBoundType;
 import com.uas.platform.b2c.prod.commodity.type.ProductConstant;
 import com.uas.platform.b2c.prod.commodity.util.GoodsUtil;
 import com.uas.platform.b2c.prod.product.brand.dao.BrandDao;
@@ -227,6 +229,12 @@ public class ProductServiceImpl implements ProductService {
     @Autowired
     private ProductPrivateService productPrivateService;
 
+    @Autowired
+    private CommonDao commonDao;
+
+    @Autowired
+    private InOutboundDetailService inOutboundDetailService;
+
     private ConcurrentHashMap<String, Field> sortFields = new ConcurrentHashMap<String, Field>();
 
     @Override
@@ -235,88 +243,46 @@ public class ProductServiceImpl implements ProductService {
         if (StringUtils.isEmpty(type)) {
             type = "nStandard";
         }
-//        page.expression(PredicateUtils.eq("enUU", enuu, true));
-//        page.expression(PredicateUtils.isNotNull("pcmpcode"));
-//        page.expression(PredicateUtils.isNotNull("pbranden"));
-//        if (type.contains("standard")) {
-//           SPage<Long> ids = searchService.get
-//        } else if (type.contains("nonStandard")) {
-//            page.filter("standard", (short)0);
-//            page.filter("b2cEnabled", (short) 1);
-//        } else if (type.contains("all")) {
-//            SimpleExpression[] arr = new SimpleExpression[2];
-//            arr[0] = PredicateUtils.eq("b2cEnabled", (short) 1, false);
-//            arr[1] = PredicateUtils.eq("standard", (short) 1, false);
-//            LogicalExpression logicalExpression = PredicateUtils.and(arr);
-//            SimpleExpression standard = PredicateUtils.eq("standard", (short) 0, false);
-//            page.orExpression(standard);
-//            page.orExpression(logicalExpression);
-//            page.sorting("standard", Sort.Direction.DESC);
-//        }
-//
-//        if (StringUtils.hasText(keyword)) {
-//            SimpleExpression code = PredicateUtils.like("prodNum", keyword, true);
-//            SimpleExpression kind = PredicateUtils.like("kind", keyword, true);
-//            SimpleExpression brandEn = PredicateUtils.like("pbranden", keyword, true);
-//            SimpleExpression cmpCode = PredicateUtils.like("pcmpcode", keyword, true);
-//            SimpleExpression[] expressions4 = new SimpleExpression[]{code, kind, brandEn, cmpCode};
-//            LogicalExpression logicalExpression4 = PredicateUtils.or(expressions4);
-//            page.expression(logicalExpression4);
-//        }
-
-        // TODO 搜索用户个人物料搜索暂时未实现,之后完善
-//        if (!StringUtils.isEmpty(userUU)) {
-//            // 先查询userUU在当前企业 有哪些物料
-//            List<Long> ids = productPersonDao.findIdByEnuuAndUserUU(enuu, userUU);
-//
-//            if (CollectionUtils.isEmpty(ids)) {
-//                return null;
-//            } else {
-//                page.expression(PredicateUtils.in("id", ids, true));
-//            }
-//        }
-
         SPage<Long> ids = searchService.getProducts(enUU, keyword, page.getPageNumber(), page.getPageSize(), type);
-        if (null == ids) {
-            return null;
+        if (ids == null || CollectionUtils.isEmpty(ids.getContent())) {
+            return new PageImpl<V_ProductPrivate>(new ArrayList<>(), page, 0);
         }
-//        Page<V_ProductPrivate> productPage = v_productPrivateDao.findAll(new Specification<V_ProductPrivate>() {
-//            @Override
-//            public Predicate toPredicate(Root<V_ProductPrivate> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
-//                query.where(page.getPredicates(root, query, cb));
-//                return null;
-//            }
-//        }, page);
         List<Long> idList = ids.getContent();
         List<V_ProductPrivate> productList = v_productPrivateDao.findAll(idList);
+        List<ProductDetail> productDetails = productDetailDao.findByProductIds(idList);
+        userUU = SystemSession.getUser().getUserUU();
+        List<ProductAttachSubmit> productAttachSubmits = productAttachService.findByProductidsAndStatus(idList, Status.UNAUDIT.value());
+        List<Long> productIds = productPersonDao.findIdByEnuuAndUserUU(enUU, userUU);
+        List<Goods> goodsList = goodsService.findByProductids(idList);
         for (V_ProductPrivate product : productList) {
-            product.setAddProductPerson(false);
-            if ("ERP".equals(product.getSourceApp())) {
-                ProductDetail productDetail = productDetailDao.findByProductId(product.getId());
-                if (productDetail != null) {
+            // 设置ERP信息
+            for (ProductDetail productDetail : productDetails) {
+                if ((productDetail.getProductId() != null) && (productDetail.getProductId().longValue() == product.getId().longValue())) {
                     product.setProductDetail(productDetail);
+                    break;
                 }
             }
-            // 拿私有物料信息
-            ProductPrivate productPrivate = productPrivateService.findByPrId(product.getId());
-            if (null != productPrivate) {
-                product.setB2cEnabled(productPrivate.getB2cEnabled());
-                product.setBatchCount(productPrivate.getBatchCount());
-            }
-        }
-        userUU = SystemSession.getUser().getUserUU();
-        List<ProductAttachSubmit> productAttachSubmits = productAttachService.findByProductidsAndStatus(idList, Status.UNAUDIT.value());
-        List<Long> productIds = productPersonDao.findIdByEnuuAndUserUU(enUU, userUU);
-        for (V_ProductPrivate v_productPrivate : productList) {
+
+            // 设置是否关联到了个人
+            product.setAddProductPerson(false);
             for (Long productId : productIds) {
-                if (v_productPrivate.getId().equals(productId)) {
-                    v_productPrivate.setAddProductPerson(true);
+                if (product.getId().equals(productId)) {
+                    product.setAddProductPerson(true);
+                    break;
                 }
             }
 
+            // 设置规格书提交的信息
             for (ProductAttachSubmit attachSubmit : productAttachSubmits) {
-                if ((attachSubmit.getProductId() != null) && attachSubmit.getProductId().longValue() == v_productPrivate.getId().longValue()) {
-                    v_productPrivate.setProductAttachSubmit(attachSubmit);
+                if (product.getId().equals(attachSubmit.getProductId())) {
+                    product.setProductAttachSubmit(attachSubmit);
+                    break;
+                }
+            }
+
+            for (Goods goods : goodsList) {
+                if (product.getId().equals(goods.getProductid())) {
+                    product.setGoods(goods);
                     break;
                 }
             }
@@ -1930,45 +1896,38 @@ public class ProductServiceImpl implements ProductService {
                 if (id == null) {
                     return new ResultMap(CodeType.NOT_COMPLETE_INFO, "物料主键信息丢失");
                 }
-                Product persistProduct = productDao.findOne(id);
-                if (persistProduct == null) {
+                V_ProductPrivate productPrivate = v_productPrivateDao.findOne(id);
+                if (productPrivate == null) {
                     return new ResultMap(CodeType.NOT_EXiST, "数据库找不到对应的信息,请重新操作");
                 }
-                List<ProductPrivate> productPrivates = productPrivateDao.findByPrId(id);
-                if ((CollectionUtils.isNotEmpty(productPrivates)) && productPrivates.get(0).getB2cEnabled() != IntegerConstant.YES_SHORT) {
+                Product persistProduct = productDao.findOne(id);
+                if (productPrivate.getB2cEnabled() != IntegerConstant.YES_SHORT) {
                     return new ResultMap(CodeType.NOT_PERMIT, "该物料商城未启用,不能操作");
                 }
-                if (!StringUtilB2C.equals(persistProduct.getSpec() , product.getSpec())) {
-                    String spec = product.getSpec();
-                    ResultMap resultMap = StringUtilB2C.validateSpec(spec);
-                    if (resultMap.getCode() != CodeType.OK.code()) {
-                        return resultMap;
-                    } else {
-                        spec = (String) resultMap.getData();
-                        persistProduct.setSpec(spec);
-                    }
+                persistProduct.setMinPackQty(product.getMinPackQty());
+                persistProduct.setPackaging(product.getPackaging());
+                ResultMap specResultMap = StringUtilB2C.validateSpec(product.getSpec());
+                if (specResultMap.getCode() != CodeType.OK.code()) {
+                    return specResultMap;
+                } else {
+                    persistProduct.setSpec((String) specResultMap.getData());
                 }
-                if (persistProduct.getStandard() == IntegerConstant.NO_SHORT) {
-                    Component component = findBybrNameAndcmpCode(persistProduct.getPbranden(), persistProduct.getPcmpcode());
+                if (productPrivate.getStandard() == IntegerConstant.NO_SHORT) {
+                    Component component = findBybrNameAndcmpCode(productPrivate.getPbranden(), productPrivate.getPcmpcode());
                     if (component != null) {
                         //更新物料信息
                         updateProductByComponent(persistProduct, component);
-                        if ((!StringUtils.isEmpty(component.getAttach())) && (!StringUtils.isEmpty(attachUrl))) {
-                            return  new ResultMap(CodeType.NOT_PERMIT, "该物料已匹配为标准,规格书已存在,规格书不能修改");
-                        } else {
-                            if (!StringUtils.isEmpty(attachUrl)) {
-                                productAttachService.submit(persistProduct.getId(), attachUrl);
-                            }
-                            return new ResultMap(CodeType.OK.code(), "成功");
+                        if (!StringUtils.isEmpty(attachUrl) && StringUtils.isEmpty(component.getAttach())) {
+                            productAttachService.submit(productPrivate.getId(), attachUrl);
                         }
-
+                        return new ResultMap(CodeType.OK.code(), "成功");
                     } else {
                         //非标且找不到标准信息
                         String brand = "", code = "", kind = "";
                         if (!StringUtils.isEmpty(attachUrl)) {
-                            productAttachService.submit(persistProduct.getId(), attachUrl);
+                            productAttachService.submit(productPrivate.getId(), attachUrl);
                         }
-                        if (!StringUtilB2C.equals(persistProduct.getPbranden() , product.getPbranden())) {
+                        if (!StringUtilB2C.equals(productPrivate.getPbranden() , product.getPbranden())) {
                             brand = product.getPbranden();
                             ResultMap resultMap = StringUtilB2C.validateBrand(brand);
                             if (resultMap.getCode() != CodeType.OK.code()) {
@@ -1977,7 +1936,7 @@ public class ProductServiceImpl implements ProductService {
                                 brand = (String) resultMap.getData();
                             }
                         }
-                        if (!StringUtilB2C.equals(persistProduct.getPcmpcode() , product.getPcmpcode())) {
+                        if (!StringUtilB2C.equals(productPrivate.getPcmpcode() , product.getPcmpcode())) {
                             code = product.getPcmpcode();
                             ResultMap resultMap = StringUtilB2C.validateCmpCode(code);
                             if (resultMap.getCode() != CodeType.OK.code()) {
@@ -1986,23 +1945,19 @@ public class ProductServiceImpl implements ProductService {
                                 code = (String) resultMap.getData();
                             }
                         }
-                        if (!StringUtilB2C.equals(persistProduct.getKind() , product.getKind())) {
-                            kind = product.getKind();
-                            ResultMap resultMap = StringUtilB2C.validateKind(kind);
-                            if (resultMap.getCode() != CodeType.OK.code()) {
-                                return resultMap;
-                            } else {
-                                kind = (String) resultMap.getData();
-                                persistProduct.setKind(kind);
-                            }
+                        ResultMap kindResultMap = StringUtilB2C.validateKind(kind);
+                        if (kindResultMap.getCode() != CodeType.OK.code()) {
+                            return kindResultMap;
+                        } else {
+                            productPrivate.setKind((String) kindResultMap.getData());
                         }
                         //如果修改了品牌、或者型号,需要匹配看,是否为标准
                         if (!StringUtils.isEmpty(brand) || !StringUtils.isEmpty(code)) {
                             if (StringUtils.isEmpty(code)) {
-                                code = persistProduct.getPcmpcode();
+                                code = productPrivate.getPcmpcode();
                             }
                             if (StringUtils.isEmpty(brand)) {
-                                brand = persistProduct.getPbranden();
+                                brand = productPrivate.getPbranden();
                             }
                             List<Product> products = productDao.findByEnUUAndPcmpcodeAndPbrandenAndB2cEnabled(SystemSession.getUser().getEnterprise().getUu(), code, brand, IntegerConstant.YES_SHORT);
                             if (CollectionUtils.isNotEmpty(products)) {
@@ -2310,7 +2265,7 @@ public class ProductServiceImpl implements ProductService {
     @Override
     public void saveByJdbcTemplate(List<ReleaseProductByBatch> list) {
         if (CollectionUtils.isNotEmpty(list)) {
-            jdbcTemplate.batchUpdate("insert into products(pr_code,pr_cmpimg,pr_enuu,pr_brand,pr_cmpcode,pr_cmpuuid,pr_kind,pr_kindid,pr_pcmpcode,pr_pbrand,pr_pbranden,pr_pbrandid,pr_pbranduuid,pr_standard,pr_create_time,pr_spec,pr_title,pr_issale, pr_price, pr_minpack, pr_packaging) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
+            jdbcTemplate.batchUpdate("insert into products(pr_code,pr_cmpimg,pr_enuu,pr_brand,pr_cmpcode,pr_cmpuuid,pr_kind,pr_kindid,pr_pcmpcode,pr_pbrand,pr_pbranden,pr_pbrandid,pr_pbranduuid,pr_standard,pr_create_time,pr_spec,pr_title,pr_issale, pr_price, pr_minpack, pr_packaging, pr_reserve) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
                     list, list.size(), new ParameterizedPreparedStatementSetter<ReleaseProductByBatch>() {
 
                         @Override
@@ -2336,6 +2291,7 @@ public class ProductServiceImpl implements ProductService {
                             ps.setObject(19, t.getCostPrice());
                             ps.setObject(20, t.getMinPackage());
                             ps.setObject(21, t.getPackaging());
+                            ps.setObject(22, t.getReserve());
                         }
                     });
         } else {
@@ -2350,11 +2306,12 @@ public class ProductServiceImpl implements ProductService {
      *
      * @param reList       临时表的id
      * @param ignoreImport 1表示忽略导入,0代表覆盖导入
+     * @param newInOutboundDetail 需要确定的出入库
+     * @param inOutMap 出入库的map
      */
     @Override
-    public void updateProductsByReleaseProductByBatch(Set<ReleaseProductByBatch> reList, Integer ignoreImport) {
+    public void updateProductsByReleaseProductByBatch(Set<ReleaseProductByBatch> reList, Integer ignoreImport, Set<InOutboundDetail> newInOutboundDetail, Map<String, Set<InOutboundDetail>> inOutMap) {
         if (CollectionUtils.isNotEmpty(reList)) {
-            //忽略导入
             Set<Long> prIds = new HashSet<>();
             for (ReleaseProductByBatch productByBatch : reList) {
                 if (productByBatch.getProductid() != null) {
@@ -2363,12 +2320,64 @@ public class ProductServiceImpl implements ProductService {
             }
             if (CollectionUtils.isNotEmpty(prIds)) {
                 List<Product> products = productDao.findAll(prIds);
-                if (ignoreImport == IntegerConstant.YES_SHORT) {
-                    for (Product product : products) {
-
+                List<Product> freshProducts = new ArrayList<>();
+                InOutboundDetail detail = null;
+                for (Product product : products) {
+                    for (ReleaseProductByBatch productByBatch : reList) {
+                        if ((productByBatch.getId() != null) &&(productByBatch.getId().longValue() == product.getId().longValue()) ) {
+                            // ignoreImport 1表示忽略导入,0代表覆盖导入
+                            if (StringUtils.isEmpty(product.getPackaging()) || (ignoreImport == IntegerConstant.NO_SHORT)) {
+                                product.setPackaging(productByBatch.getPackaging());
+                            }
+                            if ((product.getMinPackQty() == null) || (ignoreImport == IntegerConstant.NO_SHORT)) {
+                                product.setMinPackQty(productByBatch.getMinPackage());
+                            }
+                            if ((product.getMinPackQty() == null) || (ignoreImport == IntegerConstant.NO_SHORT)) {
+                                product.setMinPackQty(productByBatch.getMinPackage());
+                            }
+                            if ((product.getKind() == null)  || (ignoreImport == IntegerConstant.NO_SHORT)) {
+                                product.setKind(productByBatch.getKindName());
+                                product.setKindid(productByBatch.getKindUuid());
+                            }
+                            if (StringUtils.isEmpty(product.getSpec()) || (ignoreImport == IntegerConstant.NO_SHORT)) {
+                                product.setSpec(productByBatch.getSpec());
+                            }
+                            if ((ignoreImport == IntegerConstant.NO_SHORT) || (NumberUtil.compare(product.getErpReserve(), DoubleConstant.zero) < 1)) {
+                                Double qty = productByBatch.getReserve();
+                                if (NumberUtil.compare(product.getErpReserve(), DoubleConstant.zero) > 0) {
+                                    qty = NumberUtil.sub(qty, product.getErpReserve());
+                                }
+                                if (NumberUtil.compare(qty, DoubleConstant.zero) != 0) {
+                                    //做出入库记录
+                                    product.setErpReserve(productByBatch.getReserve());
+                                    detail = new InOutboundDetail(product);
+                                    detail.setQty(qty);
+                                    detail.setPrice(productByBatch.getCostPrice());
+                                    newInOutboundDetail.add(detail);
+                                }
+                            }
+                            freshProducts.add(product);
+                        }
+                    }
+                }
+                productDao.save(freshProducts);
+                if (CollectionUtils.isNotEmpty(newInOutboundDetail)) {
+                    Set<InOutboundDetail> inBoundDetail = new HashSet<>();
+                    Set<InOutboundDetail> outBoundDetail = new HashSet<>();
+                    for (InOutboundDetail detail1 : newInOutboundDetail) {
+                        if (NumberUtil.compare(detail1.getQty(), DoubleConstant.zero) < 0) {
+                            detail1.setQty(Math.abs(detail1.getQty()));
+                            outBoundDetail.add(detail1);
+                        } else if (NumberUtil.compare(detail1.getQty(), DoubleConstant.zero) > 0) {
+                            inBoundDetail.add(detail1);
+                        }
+                    }
+                    if (CollectionUtils.isNotEmpty(inBoundDetail)) {
+                        inOutMap.put(InOutBoundType.OTHER_INBOUND, inBoundDetail);
+                    }
+                    if (CollectionUtils.isNotEmpty(outBoundDetail)) {
+                        inOutMap.put(InOutBoundType.OTHER_OUTBOUND, outBoundDetail);
                     }
-                } else {
-                    //覆盖导入
                 }
             }
         }

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

@@ -139,6 +139,9 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 	@Autowired
 	private TradeDeliveryDelayTimeService tradeDeliveryDelayTimeService;
 
+	@Autowired
+	private CommodityInOutboundService commodityInOutboundService;
+
 	private final Logger logger = Logger.getLogger(getClass());
 
 	/**
@@ -187,7 +190,6 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 	 */
 	@Override
 	public ModelMap releaseByWorkbook(Workbook workbook, Boolean selfSale, String currency, Integer isPerson, Integer ignoreImport, boolean isPcb) {
-		long l = System.currentTimeMillis();
 		// 是否上传个人物料
 		boolean isAPerson = false;
 		if (null != isPerson && isPerson.intValue() == IntegerConstant.YES_SHORT.intValue()) {
@@ -335,10 +337,12 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
                 success = releaseProductByBatchDao.getCountPublisherUuAndBatchAndReleaseCode(userUU, batch, ReleaseStatus.success.value());
             }
 		}
-		if (!isAPerson && !isPcb) {
+		if (!isAPerson) {
 			String publish = publishByBatch(batch, isPcb, ignoreImport);
 			modelMap.put("publish", publish);
-		}
+		} else {
+
+        }
 		modelMap.put("total", total);
 		modelMap.put("success", success);
 		modelMap.put("failure", failure);
@@ -1739,13 +1743,13 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 		if (isPcb) {
 			savePcbInfo(idSet, map);
 		}
-		Integer num = releaseToGoods(releaseProductByBatchList, ignoreImport);
+		Integer num = releaseToGoods(releaseProductByBatchList, ignoreImport, idSet);
 		String updateReleaseSql = "/*#mycat:db_type=master*/ update trade$releasebybatch set rel_releasecode = 101,rel_releasestatus = '已发布' where (rel_releasecode = 112 OR rel_releasecode = 113) and rel_batchid = '%s';";
 		final String updateRelease = String.format(updateReleaseSql, new Object[]{batch});
 		jdbcTemplate.execute(updateRelease);
 		ArrayList<Long> list = new ArrayList<>();
-		list.addAll((Set<Long>)map.get("prIds"));
-		afterPublishToGoodsDo(list, (Set<Long>)map.get("reIds"), batch);
+		list.addAll(idSet);
+		afterPublishToGoodsDo(list, batch);
 		return StringUtilB2C.getStr(num);
 	}
 
@@ -1754,9 +1758,10 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 	 * 临时表保存到goods信息
 	 * @param list 需要保存的信息
      * @param ignoreImport (1是忽略导入、2是覆盖导入)
+	 * @param idSet 物料id信息
 	 * @return
 	 */
-	public Integer releaseToGoods(List<ReleaseProductByBatch> list, Integer ignoreImport) {
+	public Integer releaseToGoods(List<ReleaseProductByBatch> list, Integer ignoreImport, Set<Long> idSet) {
 		if (CollectionUtils.isNotEmpty(list)) {
 			List<Goods> goodses = new ArrayList<>();
 			Goods goods = null;
@@ -1782,9 +1787,38 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 					throw new IllegalOperatorException("平台未设置供应商延长时间,请联系管理员");
 				}
 			}
-
+			List<Goods> goodlist = null;
+			if (CollectionUtils.isNotEmpty(idSet)) {
+				List<Long> prids = new ArrayList<>();
+				prids.addAll(idSet);
+				goodlist = goodsService.findByProductids(prids);
+			}
+			List<ReleaseProductByBatch> insertGoods = new ArrayList<>();
+			Set<Long> prids = new HashSet<>();
+			List<Goods> updateGoods = new ArrayList<>();
 			for (ReleaseProductByBatch releaseProductByBatch : list) {
 				if (releaseProductByBatch.getReleaseCode().intValue() == ReleaseStatus.success.value() || releaseProductByBatch.getReleaseCode().intValue() == ReleaseStatus.failure.value()) {
+                    Boolean isExist = false;
+					for (Goods goods1 : goodlist) {
+						if ((goods1.getProductid() != null) && (releaseProductByBatch.getProductid() != null) &&(goods1.getProductid().longValue() == releaseProductByBatch.getProductid().longValue())) {
+							//如果之前已经更新了该物料的在售产品,则不需要做调整(为了兼容一个物料包含多个在售产品的逻辑)
+                            //默认更新id最大的一条信息
+							if (!prids.contains(releaseProductByBatch.getProductid().longValue())) {
+                                isExist = true;
+								prids.add(releaseProductByBatch.getProductid());
+                                goods1.updateGoodsByReleaseProductByBatch(releaseProductByBatch, delayTime, ignoreImport);
+								updateGoods.add(goods1);
+                                break;
+							}
+						}
+					}
+					if (!isExist) {
+                        insertGoods.add(releaseProductByBatch);
+                    }
+				}
+			}
+			if (CollectionUtils.isNotEmpty(insertGoods)) {
+				for (ReleaseProductByBatch releaseProductByBatch : insertGoods) {
 					goods = new Goods();
 					goods.setGoodsByReleaseProductByBatch(releaseProductByBatch, delayTime);
 					goodses.add(goods);
@@ -1793,7 +1827,10 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 			if (CollectionUtils.isNotEmpty(goodses)) {
 				commonDao.save(goodses, Goods.class);
 			}
-			return goodses.size();
+			if (CollectionUtils.isNotEmpty(updateGoods)) {
+                goodsDao.save(updateGoods);
+            }
+			return (goodses.size() + updateGoods.size());
 		} else {
 			return 0;
 		}
@@ -1857,23 +1894,13 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 			return null;
 		}
 		Map<String, Object> map = new HashedMap();
+		Set<InOutboundDetail> newInOutboundDetail = new HashSet<>();
 		List<ReleaseProductByBatch> productsfromRelease = new ArrayList<>();
 		List<ProductPrivate> productPrivates = new ArrayList<>();
 		Set<Long> prIds = new HashSet<>();
-		Set<Long> reIds = new HashSet<>();
 		Set<ReleaseProductByBatch> updateProducts = new HashSet<>();
 		Map<String, List<PCBPropertyValue>> propertyMap = new HashedMap();
 
-		Long sizeProId = null;
-		Long colorProId = null;
-		Long thickCopperProId = null;
-		Long thickProId = null;
-		if (isPcb) {
-			sizeProId = propertyDao.findIdByLabelCn(SIZE);
-			colorProId = propertyDao.findIdByLabelCn(COLOR);
-			thickCopperProId = propertyDao.findIdByLabelCn(THICKCOPPER);
-			thickProId = propertyDao.findIdByLabelCn(THICK);
-		}
         String importNum = createNumberService.getTimeNumber("trade$product_import_num", 8, releaseProductByBatchList.size());
 		if (StringUtils.isEmpty(importNum)) {
 			throw new IllegalOperatorException("生成批次号失败");
@@ -1886,7 +1913,6 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 		    if (releaseProductByBatch.getReleaseCode().equals(ReleaseStatus.failure.value()) ||
                     releaseProductByBatch.getReleaseCode().equals(ReleaseStatus.success.value())) {
 				if (releaseProductByBatch.getProductid() == null) {
-					// releaseProductByBatch.getCode(); 在公有库生成
 					prodNum = "PNUM" + time + CreateNumberServiceImpl.formatIntToStr(++num, 8);
 					releaseProductByBatch.setProductNum(prodNum);
                     proNums.add(prodNum);
@@ -1895,13 +1921,11 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 					//对于已经存在于物料库的信息,如果规格信息已存在,则做更新
 					prIds.add(releaseProductByBatch.getProductid());
                     if (org.apache.commons.lang.StringUtils.isNotEmpty(releaseProductByBatch.getSpec()) || (releaseProductByBatch.getMinPackage() != null) || org.apache.commons.lang.StringUtils.isNotEmpty(releaseProductByBatch.getPackaging()) || (releaseProductByBatch.getCostPrice() != null)) {
-						reIds.add(releaseProductByBatch.getId());
 						updateProducts.add(releaseProductByBatch);
 					} else {
                         if (org.apache.commons.lang.StringUtils.isNotEmpty(releaseProductByBatch.getKindName())) {
                             //如果是非标,则可以填充,或者覆盖
                             if (org.apache.commons.lang.StringUtils.isNotEmpty(releaseProductByBatch.getComponentUuId())) {
-                                reIds.add(releaseProductByBatch.getId());
 								updateProducts.add(releaseProductByBatch);
                             }
                         }
@@ -1909,23 +1933,7 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 				}
 
 				if (isPcb) {
-					List<PCBPropertyValue> propertyValues = new ArrayList<>();
-					if (!StringUtils.isEmpty(releaseProductByBatch.getSizePcb())) {
-						PCBPropertyValue propertyValue = new PCBPropertyValue(sizeProId, releaseProductByBatch.getSizePcb());
-						propertyValues.add(propertyValue);
-					}
-					if (!StringUtils.isEmpty(releaseProductByBatch.getColor())) {
-						PCBPropertyValue propertyValue = new PCBPropertyValue(colorProId, releaseProductByBatch.getColor());
-						propertyValues.add(propertyValue);
-					}
-					if (!StringUtils.isEmpty(releaseProductByBatch.getThickCopper())) {
-						PCBPropertyValue propertyValue = new PCBPropertyValue(thickCopperProId, releaseProductByBatch.getThickCopper());
-						propertyValues.add(propertyValue);
-					}
-					if (!StringUtils.isEmpty(releaseProductByBatch.getThick())) {
-						PCBPropertyValue propertyValue = new PCBPropertyValue(thickProId, releaseProductByBatch.getThick());
-						propertyValues.add(propertyValue);
-					}
+					List<PCBPropertyValue> propertyValues = createPCBPropertyValue(releaseProductByBatch);
 					if (CollectionUtils.isNotEmpty(propertyValues)) {
 						propertyMap.put(SystemSession.getUser().getEnterprise().getUu().toString().concat(prodNum), propertyValues);
 					}
@@ -1933,14 +1941,12 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
             }
 		}
 		List<ReleaseProductByBatch> reList = new ArrayList<>();
+		InOutboundDetail detail = null;
 		if (productsfromRelease.size() != 0) {
             productService.saveByJdbcTemplate(productsfromRelease);
 			List<Product> productes = productService.findProductIdAndProdnumsByProdNums(proNums);
 			for (Product producte : productes) {
-				ProductPrivate productPrivate = new ProductPrivate();
-				productPrivate.setB2cEnabled(IntegerConstant.YES_SHORT);
-				productPrivate.setPrId(producte.getId());
-				productPrivate.setBatchCount(IntegerConstant.NO_SHORT);
+				ProductPrivate productPrivate = new ProductPrivate(producte.getId());
 				productPrivates.add(productPrivate);
 
 				prIds.add(producte.getId());
@@ -1951,6 +1957,11 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 						reList.add(releaseProductByBatch);
 					}
 				}
+
+				if (NumberUtil.compare(producte.getErpReserve(), DoubleConstant.zero) != 0) {
+					detail = new InOutboundDetail(producte);
+					newInOutboundDetail.add(detail);
+				}
 			}
 		}
 		//新生成的物料 要更新到临时表中
@@ -1962,11 +1973,16 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
             commonDao.save(productPrivates, ProductPrivate.class);
 		}
 		//将本次临时表中的数据更新到物料表中
-        if (CollectionUtils.isNotEmpty(reIds)) {
-            productService.updateProductsByReleaseProductByBatch(reIds, ignoreImport);
-        }
-		if (reIds.size() > 0) {
-			map.put("reIds", reIds);
+        if (CollectionUtils.isNotEmpty(updateProducts)) {
+			Map<String, Set<InOutboundDetail>> inOutMap = new HashedMap();
+            productService.updateProductsByReleaseProductByBatch(updateProducts, ignoreImport, newInOutboundDetail, inOutMap);
+			Set<String> stringSet = inOutMap.keySet();
+			for (String type : stringSet) {
+				CommodityInOutbound commodityInOutbound = commodityInOutboundService.produceCommodityInOutbound(inOutMap.get(type), type);
+				if (commodityInOutbound != null) {
+					commodityInOutboundService.save(commodityInOutbound);
+				}
+			}
 		}
 		map.put("prIds", prIds);
 		map.put("propertyvalues", propertyMap);
@@ -1989,30 +2005,45 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
             String res  = restTemplate.postForEntity(productServiceIp + "/product/assign/batch?userUU=" + SystemSession.getUser().getUserUU(), productIds, String.class).getBody();
         }
 		return "sucesss";
-//		User user = SystemSession.getUser();
-//		Enterprise enterprise = SystemSession.getUser().getEnterprise();
-//		final Object[] obj = new Object[]{enterprise.getUu(), user.getUserUU(), enterprise.getEnName(), batch};
-//		String sql = "/*#mycat:db_type=master*/ set @enuu = %s; set @useruu = %s; set @enName = '%s'; set @batch = '%s'; call RELEASE_TO_PRODUCT_PERSON_V1(@enuu, @useruu, @enName, @batch)";
-//		final String updateSql = String.format(sql, obj);
-//		jdbcTemplate.execute(new StatementCallback<String>() {
-//
-//			@Override
-//			public String doInStatement(Statement stmt) throws SQLException, DataAccessException {
-//				stmt.executeQuery(updateSql);
-//				ResultSet rs = stmt.getResultSet();
-//				if (null != rs) {
-//					rs.next();
-//					return rs.getString(1);
-//				}
-//				return "0";
-//			}
-//		});
+	}
+
+	/**
+	 * 根据批次上架临时表生成pcb的属性信息
+	 * @param releaseProductByBatch
+	 * @return
+	 */
+	public List<PCBPropertyValue> createPCBPropertyValue(ReleaseProductByBatch releaseProductByBatch) {
+		List<PCBPropertyValue> propertyValues = new ArrayList<>();
+		if (releaseProductByBatch == null) {
+			return propertyValues;
+		}
+		Long sizeProId = propertyDao.findIdByLabelCn(SIZE);
+		Long colorProId = propertyDao.findIdByLabelCn(COLOR);
+		Long thickCopperProId = propertyDao.findIdByLabelCn(THICKCOPPER);
+		Long thickProId = propertyDao.findIdByLabelCn(THICK);
+		if (!StringUtils.isEmpty(releaseProductByBatch.getSizePcb())) {
+			PCBPropertyValue propertyValue = new PCBPropertyValue(sizeProId, releaseProductByBatch.getSizePcb());
+			propertyValues.add(propertyValue);
+		}
+		if (!StringUtils.isEmpty(releaseProductByBatch.getColor())) {
+			PCBPropertyValue propertyValue = new PCBPropertyValue(colorProId, releaseProductByBatch.getColor());
+			propertyValues.add(propertyValue);
+		}
+		if (!StringUtils.isEmpty(releaseProductByBatch.getThickCopper())) {
+			PCBPropertyValue propertyValue = new PCBPropertyValue(thickCopperProId, releaseProductByBatch.getThickCopper());
+			propertyValues.add(propertyValue);
+		}
+		if (!StringUtils.isEmpty(releaseProductByBatch.getThick())) {
+			PCBPropertyValue propertyValue = new PCBPropertyValue(thickProId, releaseProductByBatch.getThick());
+			propertyValues.add(propertyValue);
+		}
+		return propertyValues;
 	}
 
 	/**
 	 * 批量发布之后,需要做的事情,内部使用线程,不需要让用户等结果
 	 */
-	public void afterPublishToGoodsDo(final List<Long> productIds, final Set<Long> reIds, String batchid) {
+	public void afterPublishToGoodsDo(final List<Long> productIds, String batchid) {
         if (CollectionUtils.isEmpty(productIds) || StringUtils.isEmpty(batchid)) {
 			return ;
 		}
@@ -2033,25 +2064,25 @@ public class ReleaseProductByBatchServiceImpl implements ReleaseProductByBatchSe
 				//创建物料的私有信息
 				productPrivateService.newProductPrivateIfNotExist(productIds);
 
-				if ((reIds != null) && (reIds.size() != 0)) {
-					List<ReleaseProductByBatch> productByBatches = releaseProductByBatchDao.findAll(reIds);
-					List<Long> prIds = new ArrayList<>();
-					for (ReleaseProductByBatch productByBatch : productByBatches) {
-						if (productByBatch.getProductid() != null) {
-							prIds.add(productByBatch.getProductid());
-						}
-					}
-					List<Product> products = productService.findByProductId(prIds);
-					for (Product product : products) {
-						for (ReleaseProductByBatch productByBatch : productByBatches) {
-							if ((productByBatch.getProductid() != null) && (product.getId().longValue() == productByBatch.getProductid().longValue())) {
-								product.setSpec(productByBatch.getSpec());
-							}
-						}
-					}
-					List<Goods> goodses = goodsDao.findByProductIds(prIds);
-					goodsService.updateSpecByProducts(products, goodses);
-				}
+//				if ((reIds != null) && (reIds.size() != 0)) {
+//					List<ReleaseProductByBatch> productByBatches = releaseProductByBatchDao.findAll(reIds);
+//					List<Long> prIds = new ArrayList<>();
+//					for (ReleaseProductByBatch productByBatch : productByBatches) {
+//						if (productByBatch.getProductid() != null) {
+//							prIds.add(productByBatch.getProductid());
+//						}
+//					}
+//					List<Product> products = productService.findByProductId(prIds);
+//					for (Product product : products) {
+//						for (ReleaseProductByBatch productByBatch : productByBatches) {
+//							if ((productByBatch.getProductid() != null) && (product.getId().longValue() == productByBatch.getProductid().longValue())) {
+//								product.setSpec(productByBatch.getSpec());
+//							}
+//						}
+//					}
+//					List<Goods> goodses = goodsDao.findByProductIds(prIds);
+//					goodsService.updateSpecByProducts(products, goodses);
+//				}
             }
 		};
 		try {

+ 39 - 0
src/main/java/com/uas/platform/b2c/prod/commodity/type/InOutBoundType.java

@@ -0,0 +1,39 @@
+package com.uas.platform.b2c.prod.commodity.type;
+
+/**
+ * 出入库类型
+ *
+ * @author yuj 2018-08-20 14:17
+ */
+public class InOutBoundType {
+
+    /**
+     * 入库
+     */
+    public static final String INBOUND = "INBOUND";
+
+    /**
+     * 出库
+     */
+    public static final String OUTBOUND = "OUTBOUND";
+
+    /**
+     * 其他入库
+     */
+    public static final String OTHER_INBOUND = "OTHER_INBOUND";
+
+    /**
+     * 其他出库
+     */
+    public static final String OTHER_OUTBOUND = "OTHER_OUTBOUND";
+
+    /**
+     * 采购入库
+     */
+    public static final String PURCHASE_INBOUND = "PURCHASE_INBOUND";
+
+    /**
+     * 销售出库
+     */
+    public static final String SELL_OUTBOUND = "SELL_OUTBOUND";
+}

+ 0 - 12
src/main/java/com/uas/platform/b2c/trade/presale/model/Cart.java

@@ -331,18 +331,6 @@ public class Cart {
 			if(NumberUtil.compare(this.number, goods.getMinBuyQty()) < 0) {
 				this.number = goods.getMinBuyQty();
 			}
-//			double times = NumberUtil.div(this.number, this.minPackQty);
-//			double qty1 = NumberUtil.mul(times, goods.getMinPackQty());
-//			if(NumberUtil.compare(qty1, goods.getMinBuyQty()) <= 0) {
-//				this.number = goods.getMinBuyQty();
-//			}else if(NumberUtil.compare(qty1, goods.getReserve()) <= 0) {
-//				this.number = qty1;
-//			}else {
-//				while (NumberUtil.compare(qty1, goods.getReserve()) > 0) {
-//					qty1 -= goods.getMinPackQty();
-//				}
-//				this.number = qty1;
-//			}
 		}
 	}