Browse Source

Merge remote-tracking branch 'origin/feature-201815-liusw' into feature-201815-liusw

wangyc 7 years ago
parent
commit
2278824751
24 changed files with 820 additions and 156 deletions
  1. 90 0
      src/main/java/com/uas/platform/b2c/core/utils/StringUtilB2C.java
  2. 12 1
      src/main/java/com/uas/platform/b2c/prod/commodity/controller/ProductController.java
  3. 17 0
      src/main/java/com/uas/platform/b2c/prod/commodity/dao/GoodsDao.java
  4. 12 0
      src/main/java/com/uas/platform/b2c/prod/commodity/dao/ProductAttachSubmitDao.java
  5. 7 0
      src/main/java/com/uas/platform/b2c/prod/commodity/dao/ProductDao.java
  6. 14 2
      src/main/java/com/uas/platform/b2c/prod/commodity/model/Goods.java
  7. 1 1
      src/main/java/com/uas/platform/b2c/prod/commodity/model/GoodsHistory.java
  8. 1 1
      src/main/java/com/uas/platform/b2c/prod/commodity/model/GoodsSimple.java
  9. 16 1
      src/main/java/com/uas/platform/b2c/prod/commodity/model/ProductPrivate.java
  10. 1 1
      src/main/java/com/uas/platform/b2c/prod/commodity/model/ReleaseProductByBatch.java
  11. 12 0
      src/main/java/com/uas/platform/b2c/prod/commodity/model/V_ProductPerson.java
  12. 12 0
      src/main/java/com/uas/platform/b2c/prod/commodity/model/V_ProductPrivate.java
  13. 16 0
      src/main/java/com/uas/platform/b2c/prod/commodity/service/GoodsService.java
  14. 11 0
      src/main/java/com/uas/platform/b2c/prod/commodity/service/ProductAttachService.java
  15. 43 1
      src/main/java/com/uas/platform/b2c/prod/commodity/service/ProductService.java
  16. 166 72
      src/main/java/com/uas/platform/b2c/prod/commodity/service/impl/GoodsServiceImpl.java
  17. 15 0
      src/main/java/com/uas/platform/b2c/prod/commodity/service/impl/ProductAttachServiceImpl.java
  18. 341 57
      src/main/java/com/uas/platform/b2c/prod/commodity/service/impl/ProductServiceImpl.java
  19. 12 5
      src/main/java/com/uas/platform/b2c/prod/product/brand/dao/BrandDao.java
  20. 5 7
      src/main/java/com/uas/platform/b2c/prod/product/component/dao/ComponentDao.java
  21. 3 4
      src/main/java/com/uas/platform/b2c/prod/product/component/modal/ComponentGoods.java
  22. 1 1
      src/main/java/com/uas/platform/b2c/trade/order/model/OrderDetail.java
  23. 1 1
      src/main/java/com/uas/platform/b2c/trade/order/model/PurchaseDetail.java
  24. 11 1
      src/main/java/com/uas/platform/b2c/trade/support/CodeType.java

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

@@ -2,12 +2,16 @@ package com.uas.platform.b2c.core.utils;
 
 import com.alibaba.fastjson.JSON;
 import com.uas.platform.b2c.logistics.model.Receipt;
+import com.uas.platform.b2c.prod.commodity.constant.UploadConstant;
 import com.uas.platform.b2c.trade.order.model.StatusHistory;
 import com.uas.platform.b2c.trade.order.model.StatusHistorySimpleInfo;
+import com.uas.platform.b2c.trade.support.CodeType;
+import com.uas.platform.b2c.trade.support.ResultMap;
 import com.uas.platform.core.model.Type;
 import org.apache.commons.collections.CollectionUtils;
 import org.springframework.util.StringUtils;
 
+import java.io.UnsupportedEncodingException;
 import java.util.*;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -20,6 +24,11 @@ import java.util.regex.Pattern;
  */
 public class StringUtilB2C {
 
+	/**
+	 * 验证产品型号
+	 */
+	private static final Pattern codePattern = Pattern.compile(RegexConstant.LetterAndDigitAndEnglishSpecialCharacter);
+
 	/**
 	 * 重新组装好的String
 	 * 
@@ -316,4 +325,85 @@ public class StringUtilB2C {
             return input;
 		}
 	}
+
+	/**
+	 * 验证产品规范的品牌
+	 * @param brand
+	 * @return
+	 */
+	public static ResultMap validateBrand(String brand) {
+		if (StringUtils.isEmpty(brand)) {
+			return new ResultMap(CodeType.NOT_PERMIT, "品牌不能为空");
+		} else {
+			if (brand.length() > 50) {
+				return new ResultMap(CodeType.NOT_PERMIT, "品牌不能超过50个字符");
+			} else {
+				brand = StringUtilB2C.toEnglish(StringUtilB2C.getStr(brand));
+				return ResultMap.success(brand);
+			}
+		}
+	}
+
+	/**
+	 * 验证产品规范的型号
+	 * @param cmpCode
+	 * @return
+	 */
+	public static ResultMap validateCmpCode(String cmpCode) {
+		if (!StringUtils.isEmpty(cmpCode)) {
+			String code = cmpCode.toString().trim();
+			Matcher matcher = codePattern.matcher(code);
+			if (!matcher.find()) {
+				return new ResultMap(CodeType.PARAMETER_ERROR, "不能输入中文或中文特殊字符");
+			}
+			try {
+				if (code.getBytes("GBK").length > 100) {
+					return new ResultMap(CodeType.PARAMETER_ERROR, "产品型号不能超过100字符");
+				}
+			} catch (UnsupportedEncodingException e) {
+				throw new RuntimeException(e + "指定字符集不支持");
+			}
+		} else {
+			return new ResultMap(CodeType.PARAMETER_ERROR, "产品型号不能为空");
+		}
+		cmpCode = StringUtilB2C.getStr(cmpCode);
+		return ResultMap.success(cmpCode);
+	}
+
+	/**
+	 * 验证产品规范的物料名称(类目)
+	 * @param kind
+	 * @return
+	 */
+	public static ResultMap validateKind(String kind) {
+		if (StringUtils.isEmpty(kind)) {
+			return new ResultMap(CodeType.PARAMETER_ERROR.code(), "物料名称(类目)不能为空");
+		} else {
+			try {
+				if (kind.toString().getBytes("GBK").length > 20) {
+					return new ResultMap(CodeType.PARAMETER_ERROR.code(), "物料名称(类目)不能超过20个字符");
+				}
+			} catch (UnsupportedEncodingException e) {
+				throw new RuntimeException(e + "指定字符集不支持");
+			}
+		}
+		kind = StringUtilB2C.getStr(kind);
+		return ResultMap.success(kind);
+	}
+
+	/**
+	 * 验证产品规范的物料名称(类目)
+	 * @param spec
+	 * @return
+	 */
+	public static ResultMap validateSpec(String spec) {
+		if (!StringUtils.isEmpty(spec)) {
+			String str = com.uas.platform.b2c.fa.payment.utils.StringUtils.cutOutStringIgnoreEncode(spec.toString(), UploadConstant.SPEC_MAX_BYTE);
+			return ResultMap.success(str);
+		} else {
+			return ResultMap.success("");
+		}
+	}
+
+
 }

+ 12 - 1
src/main/java/com/uas/platform/b2c/prod/commodity/controller/ProductController.java

@@ -245,7 +245,7 @@ public class ProductController {
 	}
 
     /**
-     * 保存对产品包装,包装数量,生产日期的修改
+     * 更新物料信息(品牌、物料名称(类目),型号、规格、规格书)
      *
      * @param product the product 修改的产品
      * @return the string
@@ -409,4 +409,15 @@ public class ProductController {
 	public ResultMap batchPutOn(Integer standard, String ids) {
 		return productService.batchPutOn(standard, ids);
 	}
+
+	/**
+	 * 更新物料信息(品牌、物料名称(类目),型号、规格、规格书)
+	 *
+	 * @param json 修改的产品
+	 * @Param attachUrl 规格书的url
+	 */
+	@RequestMapping(value = "/update/product", method = RequestMethod.POST)
+	public ResultMap updateProduct(@RequestBody String json, String attachUrl){
+		return productService.updateProduct(json, attachUrl);
+	}
 }

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

@@ -810,4 +810,21 @@ public interface GoodsDao extends JpaSpecificationExecutor<Goods>, JpaRepository
      */
     @Query(nativeQuery = true, value = "select * from trade$goods where br_name_uuid is not null and ki_name in (:kind) and go_status = 601 limit 0,8")
     List<Goods> findInKindNamesAndBrandIsNotNull(@Param("kind")List<String> kinds);
+
+    /**
+     * 根据物料信息更更新在售产品
+     * @param brandCn 中文品牌
+     * @param brandEn 英文品牌
+     * @param brandid 品牌id
+     * @param branduuid 品牌uuid
+     * @param kiName 类目
+     * @param kindId 类目id
+     * @param img 图片
+     * @param cmpUuid uuid
+     * @param spec 规格
+     * @param productid 物料的id
+     */
+    @Modifying
+    @Query(nativeQuery = true, value = "update trade$goods g set g.br_name_cn = :brandCn, g.br_name_en = :brandEn, g.br_name_id = :brandid, g.br_name_uuid = :branduuid, g.ki_name = :kiName, g.go_kind_uuid = :kindId, g.cmp_img = :img, g.cmp_uuid = :cmpUuid, g.go_spec = :spec where g.go_productid = :productid")
+    void updateGoodsByProduct(@Param("brandCn") String brandCn, @Param("brandEn") String brandEn, @Param("brandid") Long brandid, @Param("branduuid") String branduuid, @Param("kiName") String kiName, @Param("kindId") Long kindId, @Param("img") String img, @Param("cmpUuid") String cmpUuid, @Param("spec") String spec, @Param("productid") Long productid);
 }

+ 12 - 0
src/main/java/com/uas/platform/b2c/prod/commodity/dao/ProductAttachSubmitDao.java

@@ -3,8 +3,12 @@ package com.uas.platform.b2c.prod.commodity.dao;
 import com.uas.platform.b2c.prod.commodity.model.ProductAttachSubmit;
 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;
+
 /**
  * 物料规格书申请
  * Created by wangyc on 2018/6/26.
@@ -19,4 +23,12 @@ public interface ProductAttachSubmitDao extends JpaRepository<ProductAttachSubmi
      * @return
      */
     ProductAttachSubmit findByProductIdAndStatus(Long productId, Integer status);
+
+
+    /**
+     * 通过物料id和状态获取物料规格书申请
+     * @return
+     */
+    @Query(value = "select p from ProductAttachSubmit p where p.productId in (:productIds) and p.status = :status")
+    List<ProductAttachSubmit> findByProductIdsAndStatus(@Param("productIds") List<Long> productIds, @Param("status") Integer status);
 }

+ 7 - 0
src/main/java/com/uas/platform/b2c/prod/commodity/dao/ProductDao.java

@@ -123,6 +123,13 @@ public interface ProductDao extends JpaSpecificationExecutor<Product>, JpaReposi
      */
     List<Product> findByEnUUAndCmpUuId(Long enuu, String uuid);
 
+    /**
+     * 通过企业uu、标准器件uuid获取标准物料信息
+     * @param uuid 器件的uuid
+     * @return  List<Product>
+     */
+    List<Product> findByCmpUuId(String uuid);
+
     /**
      * 通过企业uu,标准器件uuid,来源获取物料信息
      * @param enuu 企业uu

+ 14 - 2
src/main/java/com/uas/platform/b2c/prod/commodity/model/Goods.java

@@ -77,7 +77,7 @@ public class Goods implements Serializable {
 	/**
 	 * 器件的附件URL
 	 */
-	@Transient
+	@Column(name = "cmp_attach")
 	private String attach;
 
 	/**
@@ -530,9 +530,12 @@ public class Goods implements Serializable {
 	/**
 	 * 规格信息
 	 */
-	@Column(name = "go_spec")
+	@Column(name = "go_spec", length = 4000)
 	private String spec;
 
+	@Transient
+	private ProductAttachSubmit productAttachSubmit;
+
 	@Transient
 	private String selfSale;
 
@@ -1686,4 +1689,13 @@ public class Goods implements Serializable {
 		this.spec = spec;
 		return this;
 	}
+
+	public ProductAttachSubmit getProductAttachSubmit() {
+		return productAttachSubmit;
+	}
+
+	public Goods setProductAttachSubmit(ProductAttachSubmit productAttachSubmit) {
+		this.productAttachSubmit = productAttachSubmit;
+		return this;
+	}
 }

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

@@ -412,7 +412,7 @@ public class GoodsHistory {
 	/**
 	 * 规格信息
 	 */
-	@Column(name = "go_spec")
+	@Column(name = "go_spec", length = 4000)
 	private String spec;
 
 	/**

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

@@ -224,7 +224,7 @@ public class GoodsSimple {
 	/**
 	 * 规格信息
 	 */
-	@Column(name ="go_spec")
+	@Column(name ="go_spec", length = 4000)
 	private String spec;
 
 	/**

+ 16 - 1
src/main/java/com/uas/platform/b2c/prod/commodity/model/ProductPrivate.java

@@ -32,7 +32,13 @@ public class ProductPrivate {
      * goods表信息中存在多少条数据
      */
     @Column(name = "pr_batchcount")
-    private Integer batchCount;
+    private Integer batchCount = 0;
+
+    /**
+     * 附件字段
+     */
+    @Column(name = "pr_attach")
+    private String attach = "";
 
     public Long getId() {
         return id;
@@ -65,4 +71,13 @@ public class ProductPrivate {
     public void setBatchCount(Integer batchCount) {
         this.batchCount = batchCount;
     }
+
+    public String getAttach() {
+        return attach;
+    }
+
+    public ProductPrivate setAttach(String attach) {
+        this.attach = attach;
+        return this;
+    }
 }

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

@@ -717,7 +717,7 @@ public class ReleaseProductByBatch implements Serializable {
 	}
 
 	/**
-	 * 交期赋值逻辑较为复杂,在调用类进行赋值
+	 * 规格信息
 	 * @param value
 	 */
 	public void setSpecByExcel(Object value) {

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

@@ -274,6 +274,9 @@ public class V_ProductPerson implements Serializable{
     @Column(name = "user_uu")
     private Long ppUserUU;
 
+    @Transient
+    private ProductAttachSubmit productAttachSubmit;
+
     /**
      * 该物料的所有替代物料
      */
@@ -607,4 +610,13 @@ public class V_ProductPerson implements Serializable{
     public void setProductReplaceList(List<ProductReplace> productReplaceList) {
         this.productReplaceList = productReplaceList;
     }
+
+    public ProductAttachSubmit getProductAttachSubmit() {
+        return productAttachSubmit;
+    }
+
+    public V_ProductPerson setProductAttachSubmit(ProductAttachSubmit productAttachSubmit) {
+        this.productAttachSubmit = productAttachSubmit;
+        return this;
+    }
 }

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

@@ -290,6 +290,9 @@ public class V_ProductPrivate implements Serializable {
     @Column(name = "pr_erpdown")
     private String erpDown;
 
+    @Transient
+    private ProductAttachSubmit productAttachSubmit;
+
     public Long getId() {
         return id;
     }
@@ -626,4 +629,13 @@ public class V_ProductPrivate implements Serializable {
         this.erpDown = erpDown;
         return this;
     }
+
+    public ProductAttachSubmit getProductAttachSubmit() {
+        return productAttachSubmit;
+    }
+
+    public V_ProductPrivate setProductAttachSubmit(ProductAttachSubmit productAttachSubmit) {
+        this.productAttachSubmit = productAttachSubmit;
+        return this;
+    }
 }

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

@@ -3,6 +3,7 @@ package com.uas.platform.b2c.prod.commodity.service;
 import com.uas.api.b2c_erp.seller.model.GoodsFUas;
 import com.uas.api.b2c_erp.seller.model.GoodsSimpleUas;
 import com.uas.platform.b2c.prod.commodity.model.*;
+import com.uas.platform.b2c.prod.product.component.modal.Component;
 import com.uas.platform.b2c.trade.order.model.Order;
 import com.uas.platform.b2c.trade.presale.model.Cart;
 import com.uas.platform.b2c.trade.presale.model.GoodsBrowsingHistory;
@@ -753,4 +754,19 @@ public interface GoodsService {
      * @return
      */
     Map<String, List<Goods>> getCmsPcb();
+
+    /**
+     * 根据产品更新在售产品
+     * @param product 产品信息
+     * @return
+     */
+    void updateGoodsByProduct(Product product);
+
+
+    /**
+     * 根据产品更新在售产品
+     * @param component 产品信息
+     * @return Component 根据标准器件更新物料
+     */
+    void updateGoodsByComponent(Component component);
 }

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

@@ -5,6 +5,8 @@ import com.uas.platform.b2c.trade.support.ResultMap;
 import com.uas.platform.core.model.PageParams;
 import org.springframework.data.domain.Page;
 
+import java.util.List;
+
 /**
  * 物料规格书接口
  * Created by wangyc on 2018/6/26.
@@ -37,6 +39,15 @@ public interface ProductAttachService {
      */
     ProductAttachSubmit submit(Long productId, String attach);
 
+
+    /**
+     * 物料上传规格书申请
+     * @param productids 物料id
+     * @param status 规格书
+     * @return
+     */
+    List<ProductAttachSubmit> findByProductidsAndStatus(List<Long> productids, Integer status);
+
     /**
      * 物料审核通过
      * @param submit 申请内容

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

@@ -2,10 +2,10 @@ package com.uas.platform.b2c.prod.commodity.service;
 
 import com.alibaba.fastjson.JSONObject;
 import com.uas.platform.b2c.prod.commodity.model.*;
+import com.uas.platform.b2c.prod.product.component.modal.Component;
 import com.uas.platform.b2c.trade.order.model.Purchase;
 import com.uas.platform.b2c.trade.support.ResultMap;
 import com.uas.platform.core.model.PageInfo;
-import com.uas.platform.core.model.PageParams;
 import org.springframework.data.domain.Page;
 
 import java.util.List;
@@ -134,6 +134,16 @@ public interface ProductService {
      */
     public String updateProduct(Product product);
 
+
+    /**
+     * 修改物料的品牌、物料名称、型号、规格、规格书等信息
+     *
+     * @param json 修改的物料信息
+     * @param attachUrl 规格书的地址
+     * @return the string
+     */
+    ResultMap updateProduct(String json, String attachUrl);
+
     /**
      * 根据库存信息 保存对产品包装,包装数量,生产日期的修改
      *
@@ -264,4 +274,36 @@ public interface ProductService {
      */
     Double getQtyInOrderToBeUpload(List<String> batches);
 
+
+    /**
+     * 根据品牌和型号标准器件
+     * @param brName
+     * @param cmpCode
+     * @return
+     */
+    Component findBybrNameAndcmpCode(String brName, String cmpCode);
+
+
+    /**
+     * 更新物料信息根据标准器件
+     * @param productid 物料id
+     * @param componentid 器件uuid
+     * @return
+     */
+    ResultMap updateProductByComponent(Long productid, String componentid);
+
+    /**
+     * 更新物料信息
+     * @param product 物料信息
+     * @param component 器件信息
+     * @return ResultMap
+     */
+    ResultMap updateProductByComponent(Product product, Component component);
+
+    /**
+     * 更新物料信息
+     * @param component 器件信息
+     * @return ResultMap
+     */
+    ResultMap updateProductByComponent(Component component);
 }

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

@@ -1,7 +1,5 @@
 package com.uas.platform.b2c.prod.commodity.service.impl;
 
-import static com.uas.platform.core.persistence.criteria.PredicateUtils.like;
-
 import com.alibaba.fastjson.JSONObject;
 import com.uas.api.b2c_erp.core.model.OperateErrorStatus;
 import com.uas.api.b2c_erp.seller.model.GoodsFUas;
@@ -19,46 +17,16 @@ import com.uas.platform.b2c.core.constant.ShortConstant;
 import com.uas.platform.b2c.core.constant.SplitChar;
 import com.uas.platform.b2c.core.constant.Status;
 import com.uas.platform.b2c.core.support.SystemSession;
-import com.uas.platform.b2c.core.utils.DoubleArith;
-import com.uas.platform.b2c.core.utils.FastjsonUtils;
-import com.uas.platform.b2c.core.utils.NumberUtil;
-import com.uas.platform.b2c.core.utils.RegexConstant;
-import com.uas.platform.b2c.core.utils.StringUtilB2C;
+import com.uas.platform.b2c.core.utils.*;
 import com.uas.platform.b2c.external.erp.commodity.util.ModelConverter;
 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.commodity.constant.UploadConstant;
-import com.uas.platform.b2c.prod.commodity.dao.GoodsDao;
-import com.uas.platform.b2c.prod.commodity.dao.GoodsHistoryDao;
-import com.uas.platform.b2c.prod.commodity.dao.GoodsModifyInfoDao;
-import com.uas.platform.b2c.prod.commodity.dao.GoodsSimpleDao;
-import com.uas.platform.b2c.prod.commodity.dao.PCBDao;
-import com.uas.platform.b2c.prod.commodity.dao.ProductDao;
-import com.uas.platform.b2c.prod.commodity.dao.ProductDetailDao;
-import com.uas.platform.b2c.prod.commodity.dao.ProductPrivateDao;
-import com.uas.platform.b2c.prod.commodity.dao.ProductStandardPutOnInfoDao;
-import com.uas.platform.b2c.prod.commodity.model.Goods;
-import com.uas.platform.b2c.prod.commodity.model.GoodsFilter;
-import com.uas.platform.b2c.prod.commodity.model.GoodsHistory;
+import com.uas.platform.b2c.prod.commodity.dao.*;
+import com.uas.platform.b2c.prod.commodity.model.*;
 import com.uas.platform.b2c.prod.commodity.model.GoodsHistory.OperateType;
-import com.uas.platform.b2c.prod.commodity.model.GoodsInfo;
-import com.uas.platform.b2c.prod.commodity.model.GoodsModifyInfo;
-import com.uas.platform.b2c.prod.commodity.model.GoodsPriceInfo;
-import com.uas.platform.b2c.prod.commodity.model.GoodsQtyPrice;
-import com.uas.platform.b2c.prod.commodity.model.GoodsSimple;
-import com.uas.platform.b2c.prod.commodity.model.ModifyInfo;
-import com.uas.platform.b2c.prod.commodity.model.Product;
-import com.uas.platform.b2c.prod.commodity.model.ProductDetail;
-import com.uas.platform.b2c.prod.commodity.model.ProductPrivate;
-import com.uas.platform.b2c.prod.commodity.model.ProductStandardPutOnInfo;
-import com.uas.platform.b2c.prod.commodity.model.V_ProductPrivate;
-import com.uas.platform.b2c.prod.commodity.service.GoodsHistoryService;
-import com.uas.platform.b2c.prod.commodity.service.GoodsPriceInfoService;
-import com.uas.platform.b2c.prod.commodity.service.GoodsService;
-import com.uas.platform.b2c.prod.commodity.service.ProductService;
-import com.uas.platform.b2c.prod.commodity.service.ProductStandardPutOnInfoService;
-import com.uas.platform.b2c.prod.commodity.service.ReleaseProductByBatchService;
+import com.uas.platform.b2c.prod.commodity.service.*;
 import com.uas.platform.b2c.prod.commodity.status.ModifyInfoStatus;
 import com.uas.platform.b2c.prod.commodity.type.ModifyConstant;
 import com.uas.platform.b2c.prod.commodity.util.GoodsUtil;
@@ -96,42 +64,14 @@ import com.uas.platform.b2c.trade.support.CodeType;
 import com.uas.platform.b2c.trade.support.ResultMap;
 import com.uas.platform.b2c.trade.util.BoundedExecutor;
 import com.uas.platform.core.exception.IllegalOperatorException;
-import com.uas.platform.core.model.Constant;
-import com.uas.platform.core.model.EncodingRulesConstant;
-import com.uas.platform.core.model.PageInfo;
-import com.uas.platform.core.model.PageParams;
-import com.uas.platform.core.model.Type;
+import com.uas.platform.core.model.*;
 import com.uas.platform.core.persistence.criteria.CriterionExpression;
 import com.uas.platform.core.persistence.criteria.CriterionExpression.Operator;
 import com.uas.platform.core.persistence.criteria.LogicalExpression;
 import com.uas.platform.core.persistence.criteria.PredicateUtils;
 import com.uas.platform.core.persistence.criteria.SimpleExpression;
 import com.uas.platform.core.util.StringUtil;
-import java.math.BigInteger;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Calendar;
-import java.util.Collections;
-import java.util.Date;
-import java.util.GregorianCalendar;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
-import javax.persistence.criteria.CriteriaBuilder;
-import javax.persistence.criteria.CriteriaQuery;
-import javax.persistence.criteria.Predicate;
-import javax.persistence.criteria.Root;
-import javax.servlet.http.HttpServletRequest;
+import com.uas.platform.core.util.serializer.FlexJsonUtils;
 import org.apache.commons.beanutils.ConvertUtils;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.collections.MapUtils;
@@ -155,6 +95,24 @@ import org.springframework.transaction.annotation.Transactional;
 import org.springframework.ui.ModelMap;
 import org.springframework.util.StringUtils;
 
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Predicate;
+import javax.persistence.criteria.Root;
+import javax.servlet.http.HttpServletRequest;
+import java.math.BigInteger;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.*;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import static com.uas.platform.core.persistence.criteria.PredicateUtils.like;
+
 
 /**
  * @author ChenHao
@@ -274,10 +232,12 @@ public class GoodsServiceImpl implements GoodsService {
     @Autowired
     private GoodsModifyInfoDao goodsModifyInfoDao;
 
+    private final ProductAttachService productAttachService;
+
     private final Logger logger = Logger.getLogger(getClass());
 
     @Autowired
-    public GoodsServiceImpl(KindService kindService, StoreInDao storeInDao, StoreInService storeInService, ProductStandardPutOnInfoDao productStandardPutOnInfoDao, ProductDao productDao, BrowsingHistoryService browsingHistoryService, RecommendProductService recommendProductService, BrandDao brandDao, KindInfoDao kindInfoDao) {
+    public GoodsServiceImpl(KindService kindService, StoreInDao storeInDao, StoreInService storeInService, ProductStandardPutOnInfoDao productStandardPutOnInfoDao, ProductDao productDao, BrowsingHistoryService browsingHistoryService, RecommendProductService recommendProductService, BrandDao brandDao, KindInfoDao kindInfoDao, ProductAttachService productAttachService) {
         this.kindService = kindService;
         this.storeInDao = storeInDao;
         this.storeInService = storeInService;
@@ -287,6 +247,7 @@ public class GoodsServiceImpl implements GoodsService {
         this.recommendProductService = recommendProductService;
         this.brandDao = brandDao;
         this.kindInfoDao = kindInfoDao;
+        this.productAttachService = productAttachService;
         ExecutorService executorService = Executors.newCachedThreadPool();
         executor = new BoundedExecutor(executorService, 1600);
     }
@@ -1410,6 +1371,15 @@ public class GoodsServiceImpl implements GoodsService {
         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()) {
+            em.refresh(nowGoods);
+        } 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())) {
@@ -1430,6 +1400,32 @@ public class GoodsServiceImpl implements GoodsService {
         return ResultMap.success(resultGoods);
     }
 
+
+    /**
+     * 比较是否修改了物料信息,如果修改了物料信息
+     * @param goodsFromFore 前端修改
+     * @param goodsFromSql 数据库获取的
+     * @return
+     */
+    public ResultMap compareGoodsIfModifyProductInfo(Goods goodsFromFore, Goods goodsFromSql) {
+        if (goodsFromFore == null || goodsFromSql == null) {
+            return new ResultMap(CodeType.OK, "信息未修改");
+        } else {
+            if ((!StringUtilB2C.equals(goodsFromFore.getSpec(), goodsFromSql.getSpec())) || (!StringUtilB2C.equals(goodsFromFore.getBrandNameEn(), goodsFromSql.getBrandNameEn())) || (!StringUtilB2C.equals(goodsFromFore.getCode(), goodsFromSql.getCode())) || (!StringUtilB2C.equals(goodsFromFore.getKindNameCn(), goodsFromSql.getKindNameCn()))) {
+                Product product = new Product();
+                product.setPbranden(goodsFromFore.getBrandNameEn());
+                product.setPcmpcode(goodsFromFore.getCode());
+                product.setId(goodsFromFore.getId());
+                product.setKind(goodsFromFore.getKindNameCn());
+                product.setSpec(goodsFromFore.getSpec());
+                ResultMap resultMap = productService.updateProduct(FlexJsonUtils.toJson(product), null);
+                return resultMap;
+            } else {
+                return new ResultMap(CodeType.OK, "物料未更新");
+            }
+        }
+    }
+
     /**
      * 比较两个Goods,得出修改后的信息
      * @param beforeGoods 原有的Goods
@@ -2534,7 +2530,10 @@ public class GoodsServiceImpl implements GoodsService {
                     }
                     componentMap.put(goods.getUuid(), component);
                 }
-                goods.setAttach(component.getAttach());
+                if (StringUtils.isEmpty(goods.getAttach())) {
+                    goods.setAttach(component.getAttach());
+                }
+
                 goods.setBrand(component.getBrand());
             }
         }
@@ -2600,7 +2599,7 @@ public class GoodsServiceImpl implements GoodsService {
             }
         }, pageInfo);
         for (Goods goods : goodsPage.getContent()) {
-            if (goods.getUuid() != null) {
+            if (StringUtils.isEmpty(goods.getAttach()) && (goods.getUuid() != null)) {
                 Component component = componentDao.findByUuid(goods.getUuid());
                 if (component != null) {
                     goods.setAttach(component.getAttach());
@@ -2671,13 +2670,29 @@ public class GoodsServiceImpl implements GoodsService {
             expressions.add(logicalExpression2);
         }
         pageInfo.setExpressions(expressions);
-        return goodsDao.findAll(new Specification<Goods>() {
+        Page<Goods> goodses = goodsDao.findAll(new Specification<Goods>() {
             @Override
             public Predicate toPredicate(Root<Goods> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
                 query.where(pageInfo.getPredicates(root, query, builder));
                 return null;
             }
         }, pageInfo);
+        List<Goods> goodses1 = goodses.getContent();
+        List<Long> list = new ArrayList<>();
+        for (Goods goods : goodses1) {
+            if (goods.getProductid() != null) {
+                list.add(goods.getProductid());
+            }
+        }
+        List<ProductAttachSubmit> attachSubmits = productAttachService.findByProductidsAndStatus(list, Status.UNAUDIT.value());
+        for (ProductAttachSubmit attachSubmit : attachSubmits) {
+            for (Goods goods : goodses1) {
+                if ((goods.getProductid() != null) && (attachSubmit.getProductId() != null) && (attachSubmit.getProductId().longValue() == goods.getProductid().longValue())) {
+                    goods.setProductAttachSubmit(attachSubmit);
+                }
+            }
+        }
+        return new PageImpl<Goods>(goodses1, pageInfo, goodses.getTotalElements());
     }
 
     @Override
@@ -3828,7 +3843,7 @@ public class GoodsServiceImpl implements GoodsService {
             }
             goods.setFrozen(getFrozenCount(goods.getBatchCode()));
         }
-        if (goods.getUuid() != null) {
+        if (StringUtils.isEmpty(goods.getAttach()) && goods.getUuid() != null) {
             Component component = componentDao.findByUuid(goods.getUuid());
             if (component != null) {
                 goods.setAttach(component.getAttach());
@@ -3913,7 +3928,7 @@ public class GoodsServiceImpl implements GoodsService {
 
     /**
      * 获取未发货前订单的库存数
-     * @param batchCode
+     * @param detail
      * @return
      */
     private Goods fillDataInGoods(ProductDetail detail) {
@@ -4167,4 +4182,83 @@ public class GoodsServiceImpl implements GoodsService {
         }
         return map;
     }
+
+
+    /**
+     * 根据产品更新在售产品
+     *
+     * @param product 产品信息
+     * @return
+     */
+    @Transactional
+    @Override
+    public void updateGoodsByProduct(Product product) {
+        if (product == null) {
+            return ;
+        } else {
+            List<GoodsHistory> list = new ArrayList<>();
+            List<ProductPrivate> productPrivates = productPrivateDao.findByPrId(product.getId());
+            ProductPrivate productPrivate = null;
+            if (CollectionUtils.isNotEmpty(productPrivates)) {
+                productPrivate = productPrivates.get(0);
+            }
+            List<Goods> goodses = goodsDao.findByProductId(product.getId());
+            for (Goods goods : goodses) {
+                goods.setSpec(product.getSpec());
+                goods.setAttach(productPrivate.getAttach());
+                goods.setBrandid(product.getPbrandid());
+                goods.setBrandNameCn(product.getPbrand());
+                goods.setBrandNameEn(product.getPbranden());
+                goods.setBranduuid(product.getPbranduuid());
+                goods.setKindUuid(product.getKindid());
+                goods.setKindNameCn(product.getKind());
+                goods.setImg(product.getCmpImg());
+                goods.setCode(product.getPcmpcode());
+                GoodsHistory history = goodsHistoryService.converTGoodsHist(goods, GoodsHistory.OperateType.Update.getPhrase(), false);
+                list.add(history);
+            }
+            if (CollectionUtils.isNotEmpty(goodses)) {
+                goodsDao.save(goodses);
+            }
+            if (CollectionUtils.isNotEmpty(list)) {
+                goodsHistoryService.save(list);
+            }
+        }
+    }
+
+    /**
+     * 根据产品更新在售产品
+     *
+     * @param component 产品信息
+     * @return Component 根据标准器件更新物料
+     */
+    @Override
+    public void updateGoodsByComponent(Component component) {
+        if (component == null) {
+            return ;
+        } else {
+            if ((!StringUtils.isEmpty(component.getAttach())) || (!StringUtils.isEmpty(component.getSpec()))) {
+                List<Goods> goodsList = goodsDao.findByUuid(component.getUuid());
+                List<Goods> goodsList1 = new ArrayList<>();
+                List<GoodsHistory> list = new ArrayList<>();
+                for (Goods goods : goodsList) {
+                    if (StringUtils.isEmpty(goods.getSpec()) || !StringUtilB2C.equals(component.getAttach(), goods.getAttach())) {
+                        if (StringUtils.isEmpty(goods.getSpec())) {
+                            goods.setSpec(component.getSpec());
+                        }
+                        goods.setAttach(component.getAttach());
+                        GoodsHistory history = goodsHistoryService.converTGoodsHist(goods, OperateType.Update.getPhrase(), false);
+                        list.add(history);
+                        goodsList1.add(goods);
+                    }
+                }
+                if (CollectionUtils.isNotEmpty(list)) {
+                    goodsHistoryService.save(list);
+                }
+                if (CollectionUtils.isNotEmpty(goodsList1)) {
+                    goodsDao.save(goodsList1);
+                }
+            }
+        }
+    }
 }

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

@@ -47,6 +47,9 @@ import org.springframework.data.jpa.domain.Specification;
 import org.springframework.stereotype.Service;
 import org.springframework.util.StringUtils;
 
+import java.util.Date;
+import java.util.List;
+
 /**
  * Created by wangyc on 2018/6/26.
  *
@@ -241,6 +244,18 @@ public class ProductAttachServiceImpl implements ProductAttachService {
         return submit;
     }
 
+    /**
+     * 物料上传规格书申请
+     *
+     * @param productids 物料id
+     * @param status    规格书
+     * @return
+     */
+    @Override
+    public List<ProductAttachSubmit> findByProductidsAndStatus(List<Long> productids, Integer status) {
+        return productAttachSubmitDao.findByProductIdsAndStatus(productids, status);
+    }
+
     @Override
     public ResultMap auditSuccess(ProductAttachSubmit submit) {
         ResultMap map = validateSubmit(submit);

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

@@ -17,46 +17,12 @@ 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.core.utils.StringUtilB2C;
 import com.uas.platform.b2c.prod.commodity.constant.DoubleConstant;
 import com.uas.platform.b2c.prod.commodity.constant.StringConstant;
-import com.uas.platform.b2c.prod.commodity.dao.GoodsDao;
-import com.uas.platform.b2c.prod.commodity.dao.GoodsHistoryDao;
-import com.uas.platform.b2c.prod.commodity.dao.MatchModelDao;
-import com.uas.platform.b2c.prod.commodity.dao.PCBDao;
-import com.uas.platform.b2c.prod.commodity.dao.ProductDao;
-import com.uas.platform.b2c.prod.commodity.dao.ProductDetailDao;
-import com.uas.platform.b2c.prod.commodity.dao.ProductMatchResultDao;
-import com.uas.platform.b2c.prod.commodity.dao.ProductModifyHistoryDao;
-import com.uas.platform.b2c.prod.commodity.dao.ProductPersonDao;
-import com.uas.platform.b2c.prod.commodity.dao.ProductPrivateDao;
-import com.uas.platform.b2c.prod.commodity.dao.ProductReplaceDao;
-import com.uas.platform.b2c.prod.commodity.dao.ProductStandardPutOnInfoDao;
-import com.uas.platform.b2c.prod.commodity.dao.ProductStoreStatusDao;
-import com.uas.platform.b2c.prod.commodity.dao.StockInOutHistDao;
-import com.uas.platform.b2c.prod.commodity.dao.V_ProductPersonDao;
-import com.uas.platform.b2c.prod.commodity.dao.V_ProductPrivateDao;
-import com.uas.platform.b2c.prod.commodity.model.Goods;
-import com.uas.platform.b2c.prod.commodity.model.GoodsHistory;
-import com.uas.platform.b2c.prod.commodity.model.GoodsQtyPrice;
-import com.uas.platform.b2c.prod.commodity.model.MatchModel;
-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.model.ProductMatchResult;
-import com.uas.platform.b2c.prod.commodity.model.ProductModifyHistory;
-import com.uas.platform.b2c.prod.commodity.model.ProductPerson;
-import com.uas.platform.b2c.prod.commodity.model.ProductPrivate;
-import com.uas.platform.b2c.prod.commodity.model.ProductReplace;
-import com.uas.platform.b2c.prod.commodity.model.ProductStandardPutOnInfo;
-import com.uas.platform.b2c.prod.commodity.model.ProductStoreStatus;
-import com.uas.platform.b2c.prod.commodity.model.StockInOutHist;
-import com.uas.platform.b2c.prod.commodity.model.UASBatchPutOnProperty;
-import com.uas.platform.b2c.prod.commodity.model.V_ProductPerson;
-import com.uas.platform.b2c.prod.commodity.model.V_ProductPrivate;
-import com.uas.platform.b2c.prod.commodity.service.GoodsHistoryService;
-import com.uas.platform.b2c.prod.commodity.service.GoodsService;
-import com.uas.platform.b2c.prod.commodity.service.ProductService;
-import com.uas.platform.b2c.prod.commodity.service.ReleaseProductByBatchService;
-import com.uas.platform.b2c.prod.commodity.service.UASBatchPutOnPropertyService;
+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.ProductConstant;
 import com.uas.platform.b2c.prod.commodity.util.GoodsUtil;
 import com.uas.platform.b2c.prod.product.brand.dao.BrandDao;
@@ -93,24 +59,7 @@ import com.uas.platform.core.model.Type;
 import com.uas.platform.core.persistence.criteria.LogicalExpression;
 import com.uas.platform.core.persistence.criteria.PredicateUtils;
 import com.uas.platform.core.persistence.criteria.SimpleExpression;
-import java.lang.reflect.Field;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import javax.persistence.criteria.CriteriaBuilder;
-import javax.persistence.criteria.CriteriaQuery;
-import javax.persistence.criteria.Predicate;
-import javax.persistence.criteria.Root;
+import com.uas.platform.core.util.serializer.FlexJsonUtils;
 import org.apache.commons.beanutils.ConvertUtils;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.log4j.Logger;
@@ -129,6 +78,17 @@ import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.StringUtils;
 import org.springframework.web.client.RestTemplate;
 
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Predicate;
+import javax.persistence.criteria.Root;
+import java.lang.reflect.Field;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+
 /**
  * Created by wangyc on 2017/5/26.
  */
@@ -257,6 +217,9 @@ public class ProductServiceImpl implements ProductService {
     @Autowired
     private SearchService searchService;
 
+    @Autowired
+    private ProductAttachService productAttachService;
+
     @Value("#{sys.productServiceIp}")
     private String productServiceIp;
 
@@ -338,6 +301,7 @@ public class ProductServiceImpl implements ProductService {
             }
         }
         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) {
             for (Long productId : productIds) {
@@ -345,6 +309,13 @@ public class ProductServiceImpl implements ProductService {
                     v_productPrivate.setAddProductPerson(true);
                 }
             }
+
+            for (ProductAttachSubmit attachSubmit : productAttachSubmits) {
+                if ((attachSubmit.getProductId() != null) && attachSubmit.getProductId().longValue() == v_productPrivate.getId().longValue()) {
+                    v_productPrivate.setProductAttachSubmit(attachSubmit);
+                    break;
+                }
+            }
         }
         return new PageImpl<V_ProductPrivate>(productList, page, ids.getTotalElement());
     }
@@ -401,7 +372,7 @@ public class ProductServiceImpl implements ProductService {
                 return null;
             }
         }, page);*/
-
+        List<Long> list = new ArrayList<>();
         List<V_ProductPerson> productList = productPage.getContent();
         for (V_ProductPerson product : productList) {
             if ("ERP".equals(product.getSourceApp())) {
@@ -412,6 +383,19 @@ public class ProductServiceImpl implements ProductService {
             }
             List<ProductReplace> productReplaceList = productReplaceDao.findByProductIdOrderByDetno(product.getId());
             product.setProductReplaceList(productReplaceList);
+            list.add(product.getId());
+        }
+        if (CollectionUtils.isNotEmpty(list)) {
+            List<ProductAttachSubmit> submits = productAttachService.findByProductidsAndStatus(list, Status.UNAUDIT.value());
+            for (ProductAttachSubmit productAttachSubmit : submits) {
+                for (V_ProductPerson product : productList) {
+                    if (product.getId().longValue() == productAttachSubmit.getProductId().longValue()) {
+                        product.setProductAttachSubmit(productAttachSubmit);
+                        break;
+                    }
+
+                }
+            }
         }
         return new PageImpl<V_ProductPerson>(productList, page, productPage.getTotalElements());
     }
@@ -1875,5 +1859,305 @@ public class ProductServiceImpl implements ProductService {
         }
 
     }
+
+
+    /**
+     * 修改非标物料的品牌、物料名称、型号、规格、规格书等信息
+     *
+     * @param json      修改的物料信息
+     * @param attachUrl 规格书的地址
+     * @return the string
+     */
+    @Transactional
+    @Override
+    public ResultMap updateProduct(String json, String attachUrl) {
+        if (StringUtils.isEmpty(json)) {
+            return new ResultMap(CodeType.NOT_COMPLETE_INFO, "信息不完善");
+        } else {
+            Product product = FlexJsonUtils.fromJson(json, Product.class);
+            //第一步 判断此产品是为非标
+            if (product != null) {
+                Long id = product.getId();
+                if (id == null) {
+                    return new ResultMap(CodeType.NOT_COMPLETE_INFO, "物料主键信息丢失");
+                }
+                Product persistProduct = productDao.findOne(id);
+                if (persistProduct == null) {
+                    return new ResultMap(CodeType.NOT_EXiST, "数据库找不到对应的信息,请重新操作");
+                }
+                List<ProductPrivate> productPrivates = productPrivateDao.findByPrId(id);
+                if ((CollectionUtils.isNotEmpty(productPrivates)) && productPrivates.get(0).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);
+                    }
+                }
+                if (persistProduct.getStandard() == IntegerConstant.NO_SHORT) {
+                    Component component = findBybrNameAndcmpCode(persistProduct.getPbranden(), persistProduct.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(), "成功");
+                        }
+
+                    } else {
+                        //非标且找不到标准信息
+                        String brand = "", code = "", kind = "";
+                        if (!StringUtils.isEmpty(attachUrl)) {
+                            productAttachService.submit(persistProduct.getId(), attachUrl);
+                        }
+                        if (!StringUtilB2C.equals(persistProduct.getPbranden() , product.getPbranden())) {
+                            brand = product.getPbranden();
+                            ResultMap resultMap = StringUtilB2C.validateBrand(brand);
+                            if (resultMap.getCode() != CodeType.OK.code()) {
+                                return resultMap;
+                            } else {
+                                brand = (String) resultMap.getData();
+                            }
+                        }
+                        if (!StringUtilB2C.equals(persistProduct.getPcmpcode() , product.getPcmpcode())) {
+                            code = product.getPcmpcode();
+                            ResultMap resultMap = StringUtilB2C.validateCmpCode(code);
+                            if (resultMap.getCode() != CodeType.OK.code()) {
+                                return resultMap;
+                            } else {
+                                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);
+                            }
+                        }
+                        //如果修改了品牌、或者型号,需要匹配看,是否为标准
+                        if (!StringUtils.isEmpty(brand) || !StringUtils.isEmpty(code)) {
+                            if (StringUtils.isEmpty(code)) {
+                                code = persistProduct.getPcmpcode();
+                            }
+                            if (StringUtils.isEmpty(brand)) {
+                                brand = persistProduct.getPbranden();
+                            }
+                            List<Product> products = productDao.findByEnUUAndPcmpcodeAndPbrandenAndB2cEnabled(SystemSession.getUser().getEnterprise().getUu(), code, brand, IntegerConstant.YES_SHORT);
+                            if (CollectionUtils.isNotEmpty(products)) {
+                                return new ResultMap(CodeType.NOT_PERMIT, "该企业下已存在同品牌、同型号的物料。");
+                            } else {
+                                Component component1 = findBybrNameAndcmpCode(brand, code);
+                                if (component1 != null) {
+                                    //根据器件更新物料信息
+                                    ResultMap resultMap = updateProductByComponent(persistProduct, component1);
+                                    return resultMap;
+                                } else {
+                                    persistProduct.setPbranden(brand);
+                                    persistProduct.setPbrand(brand);
+                                    persistProduct.setPcmpcode(code);
+                                    Product product1 = productDao.save(persistProduct);
+                                    goodsService.updateGoodsByProduct(product1);
+                                    return ResultMap.success(product1);
+                                }
+                            }
+                        } else {
+                            //直接保存
+                            Product product1 = productDao.save(persistProduct);
+                            return ResultMap.success(product1);
+                        }
+                    }
+                } else {
+                    //标准的信息,只能修改规格书、规格信息
+                    Component component = null;
+                    if (!StringUtilB2C.equals(product.getPbranden(), persistProduct.getPbranden())) {
+                        return new ResultMap(CodeType.NOT_PERMIT, "标准物料,品牌不能修改");
+                    }
+                    if (!StringUtilB2C.equals(product.getPcmpcode(), persistProduct.getPcmpcode())) {
+                        return new ResultMap(CodeType.NOT_PERMIT, "标准物料,型号不能修改");
+                    }
+                    if (!StringUtilB2C.equals(product.getKind(), persistProduct.getKind())) {
+                        return new ResultMap(CodeType.NOT_PERMIT, "标准物料,类目不能修改");
+                    }
+                    if (!StringUtilB2C.equals(product.getSpec(), persistProduct.getSpec())) {
+                        persistProduct.setSpec(product.getSpec());
+                    }
+                    if (persistProduct.getCmpUuId() != null) {
+                        component = componentDao.findByUuid(persistProduct.getCmpUuId());
+                    }
+                    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(), "成功");
+                    }
+                }
+            } else {
+                return new ResultMap(CodeType.NOT_COMPLETE_INFO, "物料信息丢失,请重新操作");
+            }
+        }
+    }
+
+
+    /**
+     * 根据品牌和型号找标准器件
+     *
+     * @param brName
+     * @param cmpCode
+     * @return
+     */
+    @Override
+    public Component findBybrNameAndcmpCode(String brName, String cmpCode) {
+        if (StringUtils.isEmpty(brName) || StringUtils.isEmpty(cmpCode)) {
+            return null;
+        } else {
+            List<Brand> brands = brandDao.findByName(brName);
+            if (CollectionUtils.isEmpty(brands)) {
+                return null;
+            } else {
+                Brand brand = brands.get(0);
+                List<Component> componentList = componentDao.findByCodeAndBrandid(cmpCode, brand.getId());
+                if (CollectionUtils.isEmpty(componentList)) {
+                    return null;
+                } else {
+                    return componentList.get(0);
+                }
+            }
+        }
+    }
+
+    /**
+     * 更新物料信息根据标准器件
+     *
+     * @param productid   物料id
+     * @param componentUuid 器件id
+     * @return
+     */
+    @Override
+    public ResultMap updateProductByComponent(Long productid, String componentUuid) {
+        if (productid == null) {
+            return new ResultMap(CodeType.NO_INFO, "物料主键缺失");
+        } else if(StringUtils.isEmpty(componentUuid)) {
+            return new ResultMap(CodeType.NO_INFO, "标准器件uuid缺失");
+        } else {
+            Component component = componentDao.findByUuid(componentUuid);
+            if (component == null) {
+                return new ResultMap(CodeType.NOT_EXiST, "找不到对应器件");
+            }
+            Product product = productDao.findOne(productid);
+            if (product == null) {
+                return new ResultMap(CodeType.NOT_EXiST, "找不到对应物料");
+            }
+            ResultMap resultMap = updateProductByComponent(product, component);
+
+            updateProductByComponent(component);
+            return resultMap;
+        }
+    }
+
+    /**
+     * 更新物料信息
+     *
+     * @param product   物料信息
+     * @param component 器件信息
+     * @return ResultMap
+     */
+    @Override
+    public ResultMap updateProductByComponent(Product product, Component component) {
+        if (product == null) {
+            return new ResultMap(CodeType.NOT_EXiST, "物料缺失");
+        }
+        if (component == null) {
+            return new ResultMap(CodeType.NOT_EXiST, "标准器件缺失");
+        } else {
+            //更新之前的标准器件
+            updateProductByComponent(component);
+        }
+        if (StringUtils.isEmpty(product.getSpec())) {
+            product.setSpec(component.getDescription());
+        }
+        product.setKind(component.getKind().getNameCn());
+        product.setKinden(component.getKind().getNameEn());
+        product.setKindid(component.getKindid());
+        product.setPbrand(component.getBrand().getNameCn());
+        product.setPbranden(component.getBrand().getNameEn());
+        product.setPbrandid(component.getBrandid());
+        product.setPbranduuid(component.getBrand().getUuid());
+        product.setCmpCode(component.getCode());
+        product.setCmpImg(component.getImg());
+        product.setCmpUuId(component.getUuid());
+        if (!StringUtils.isEmpty(component.getAttach())) {
+            List<ProductPrivate> privates = productPrivateDao.findByPrId(product.getId());
+            if (CollectionUtils.isNotEmpty(privates)) {
+                ProductPrivate productPrivate = privates.get(0);
+                productPrivate.setAttach(component.getAttach());
+                productPrivateDao.save(productPrivate);
+            }
+        }
+        Product product1 = productDao.save(product);
+        goodsService.updateGoodsByProduct(product1);
+        return ResultMap.success(product1);
+    }
+
+
+    /**
+     * 更新物料信息
+     *
+     * @param component 器件信息
+     * @return ResultMap
+     */
+    @Override
+    public ResultMap updateProductByComponent(Component component) {
+        if (component == null) {
+            return new ResultMap(CodeType.OK, "");
+        } else {
+            if ((!StringUtils.isEmpty(component.getSpec())) || (!StringUtils.isEmpty(component.getAttach()))) {
+                List<Product> productList = productDao.findByCmpUuId(component.getUuid());
+                List<ProductPrivate> productPrivatelist = new ArrayList<>();
+                List<Product> list = new ArrayList<>();
+                for (Product product : productList) {
+                    if (!StringUtils.isEmpty(component.getAttach())) {
+                        List<ProductPrivate> productPrivates = productPrivateDao.findByPrId(product.getId());
+                        if (CollectionUtils.isNotEmpty(productPrivates)) {
+                            ProductPrivate productPrivate = productPrivates.get(0);
+                            productPrivate.setAttach(component.getAttach());
+                            productPrivatelist.add(productPrivate);
+                        }
+                    }
+
+                    if (StringUtils.isEmpty(product.getSpec()) && !StringUtils.isEmpty(component.getSpec())) {
+                        product.setSpec(component.getSpec());
+                        list.add(product);
+                    }
+                }
+                if (CollectionUtils.isNotEmpty(productPrivatelist)) {
+                    productPrivateDao.save(productPrivatelist);
+                }
+                if (CollectionUtils.isNotEmpty(list)) {
+                    productDao.save(list);
+                }
+
+                goodsService.updateGoodsByComponent(component);
+                return ResultMap.success("");
+            } else {
+                return ResultMap.success("");
+            }
+        }
+    }
 }
 

+ 12 - 5
src/main/java/com/uas/platform/b2c/prod/product/brand/dao/BrandDao.java

@@ -1,8 +1,6 @@
 package com.uas.platform.b2c.prod.product.brand.dao;
 
-import java.util.List;
-
-import com.uas.platform.b2c.prod.product.brand.modal.BrandMostSimpleInfo;
+import com.uas.platform.b2c.prod.product.brand.modal.Brand;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Pageable;
 import org.springframework.data.jpa.repository.JpaRepository;
@@ -11,10 +9,10 @@ import org.springframework.data.jpa.repository.Modifying;
 import org.springframework.data.jpa.repository.Query;
 import org.springframework.data.repository.query.Param;
 import org.springframework.stereotype.Repository;
-
-import com.uas.platform.b2c.prod.product.brand.modal.Brand;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.util.List;
+
 /**
  * 品牌
  * 
@@ -107,4 +105,13 @@ public interface BrandDao extends JpaSpecificationExecutor<Brand>, JpaRepository
 	 */
 	@Query(nativeQuery = true , value = "select * from product$brand order by br_search_count desc LIMIT 2")
 	public List<Brand> findMostSearchBrands();
+
+
+	/**
+	 * 根据品牌名称获取品牌信息
+	 * @param brandName
+	 * @return
+	 */
+	@Query(value = "select * from product$brand b where upper(b.br_name_cn) = upper(:brandName) or upper(b.br_name_en) = upper(:brandName)", nativeQuery = true)
+	List<Brand> findByName(@Param("brandName") String brandName);
 }

+ 5 - 7
src/main/java/com/uas/platform/b2c/prod/product/component/dao/ComponentDao.java

@@ -1,16 +1,14 @@
 package com.uas.platform.b2c.prod.product.component.dao;
 
-import java.util.List;
-
-import javax.persistence.QueryHint;
-
+import com.uas.platform.b2c.prod.product.component.modal.Component;
 import org.springframework.data.jpa.repository.*;
 import org.springframework.data.repository.query.Param;
 import org.springframework.stereotype.Repository;
-
-import com.uas.platform.b2c.prod.product.component.modal.Component;
 import org.springframework.transaction.annotation.Transactional;
 
+import javax.persistence.QueryHint;
+import java.util.List;
+
 @Repository
 public interface ComponentDao extends JpaSpecificationExecutor<Component>, JpaRepository<Component, Long> {
 
@@ -57,7 +55,7 @@ public interface ComponentDao extends JpaSpecificationExecutor<Component>, JpaRe
 	 * @param brandid 品牌id
 	 * @return  器件信息
 	 */
-	@Query("select c from Component c where c.code = :code and c.brandid = :brandid")
+	@Query("select c from Component c where c.brandid = :brandid and upper(c.code) = upper(:code)")
 	@QueryHints({ @QueryHint(name = "org.hibernate.cacheable", value = "true") })
 	public List<Component> findByCodeAndBrandid(@Param("code") String code, @Param("brandid") Long brandid);
 

+ 3 - 4
src/main/java/com/uas/platform/b2c/prod/product/component/modal/ComponentGoods.java

@@ -1,13 +1,12 @@
 package com.uas.platform.b2c.prod.product.component.modal;
 
 import com.alibaba.fastjson.annotation.JSONField;
+import com.uas.platform.b2c.core.support.SystemSession;
+import com.uas.platform.b2c.core.utils.FastjsonUtils;
 import com.uas.platform.b2c.prod.commodity.model.Goods;
 import com.uas.platform.b2c.prod.commodity.model.GoodsQtyPrice;
-import com.uas.platform.b2c.prod.commodity.model.Product;
 import com.uas.platform.b2c.prod.product.brand.modal.BrandInfo;
 import com.uas.platform.b2c.prod.product.kind.model.KindInfo;
-import com.uas.platform.b2c.core.support.SystemSession;
-import com.uas.platform.b2c.core.utils.FastjsonUtils;
 import org.apache.commons.collections.CollectionUtils;
 import org.codehaus.jackson.annotate.JsonIgnore;
 import org.springframework.util.StringUtils;
@@ -264,7 +263,7 @@ public class ComponentGoods implements Serializable {
 	/**
 	 * 视图
 	 */
-	@Column(name = "go_spec")
+	@Column(name = "go_spec", length = 4000)
 	private String spec;
 
 	public Long getCmpId() {

+ 1 - 1
src/main/java/com/uas/platform/b2c/trade/order/model/OrderDetail.java

@@ -358,7 +358,7 @@ public class OrderDetail extends Document implements Serializable{
 	/**
 	 * 规格信息
 	 */
-	@Column(name = "go_spec")
+	@Column(name = "go_spec", length = 4000)
 	private String spec;
 	
 	/**

+ 1 - 1
src/main/java/com/uas/platform/b2c/trade/order/model/PurchaseDetail.java

@@ -333,7 +333,7 @@ public class PurchaseDetail extends Document {
 	/**
 	 * 规格字段
 	 */
-	@Column(name = "go_spec")
+	@Column(name = "go_spec", length = 4000)
 	private String spec;
 
 

+ 11 - 1
src/main/java/com/uas/platform/b2c/trade/support/CodeType.java

@@ -63,7 +63,17 @@ public enum CodeType {
 	/**
 	 * 无操作权限
 	 */
-	NO_AUTHORITY(13, "NO_AUTHORITY");
+	NO_AUTHORITY(13, "NO_AUTHORITY"),
+
+	/**
+	 * 信息已修改
+	 */
+	INFO_MODIFY(14, "INFO_MODIFY"),
+
+	/**
+	 * 信息未修改
+	 */
+	INFO_NO_MODIFY(15, "INFO_NO_MODIFY");
 
 	private int code;