Jelajahi Sumber

修改物料信息(规范)的接口

yujia 7 tahun lalu
induk
melakukan
a03aec5fa0

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

@@ -417,7 +417,7 @@ public class ProductController {
 	 * @Param attachUrl 规格书的url
 	 */
 	@RequestMapping(value = "/update/product", method = RequestMethod.POST)
-	public String updateProduct(@RequestBody String json, String attachUrl){
-		return productService.updateProduct(product);
+	public ResultMap updateProduct(@RequestBody String json, String attachUrl){
+		return productService.updateProduct(json, attachUrl);
 	}
 }

+ 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

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

@@ -533,6 +533,9 @@ public class Goods implements Serializable {
 	@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;
+	}
 }

+ 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;
+    }
 }

+ 9 - 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;
@@ -760,4 +761,12 @@ public interface GoodsService {
      * @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

@@ -2,6 +2,8 @@ package com.uas.platform.b2c.prod.commodity.service;
 
 import com.uas.platform.b2c.prod.commodity.model.ProductAttachSubmit;
 
+import java.util.List;
+
 /**
  * 物料规格书接口
  * Created by wangyc on 2018/6/26.
@@ -17,4 +19,13 @@ public interface ProductAttachService {
      * @return
      */
     ProductAttachSubmit submit(Long productId, String attach);
+
+
+    /**
+     * 物料上传规格书申请
+     * @param productids 物料id
+     * @param status 规格书
+     * @return
+     */
+    List<ProductAttachSubmit> findByProductidsAndStatus(List<Long> productids, Integer status);
 }

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

@@ -136,7 +136,7 @@ public interface ProductService {
 
 
     /**
-     * 修改非标物料的品牌、物料名称、型号、规格、规格书等信息
+     * 修改物料的品牌、物料名称、型号、规格、规格书等信息
      *
      * @param json 修改的物料信息
      * @param attachUrl 规格书的地址
@@ -283,4 +283,27 @@ public interface ProductService {
      */
     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);
 }

+ 117 - 69
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
@@ -2674,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
@@ -3916,7 +3928,7 @@ public class GoodsServiceImpl implements GoodsService {
 
     /**
      * 获取未发货前订单的库存数
-     * @param batchCode
+     * @param detail
      * @return
      */
     private Goods fillDataInGoods(ProductDetail detail) {
@@ -4213,4 +4225,40 @@ public class GoodsServiceImpl implements GoodsService {
             }
         }
     }
+
+    /**
+     * 根据产品更新在售产品
+     *
+     * @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 - 1
src/main/java/com/uas/platform/b2c/prod/commodity/service/impl/ProductAttachServiceImpl.java

@@ -10,11 +10,13 @@ import com.uas.platform.b2c.prod.commodity.service.ProductAttachService;
 import com.uas.platform.b2c.prod.product.component.dao.ComponentDao;
 import com.uas.platform.b2c.prod.product.component.modal.Component;
 import com.uas.platform.core.exception.IllegalOperatorException;
-import java.util.Date;
 import org.springframework.beans.factory.annotation.Autowired;
 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.
  *
@@ -89,4 +91,16 @@ 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);
+    }
 }

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

@@ -301,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) {
@@ -308,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());
     }
@@ -364,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())) {
@@ -375,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());
     }
@@ -1864,56 +1885,40 @@ public class ProductServiceImpl implements ProductService {
                 if (persistProduct == null) {
                     return new ResultMap(CodeType.NOT_EXiST, "数据库找不到对应的信息,请重新操作");
                 }
-                if (persistProduct.getB2cEnabled() != IntegerConstant.YES_SHORT) {
+                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) {
-                        persistProduct.setPcmpcode(component.getCode());
-                        persistProduct.setPbranden(component.getBrand().getNameEn());
-                        persistProduct.setPbrand(component.getBrand().getNameCn());
-                        persistProduct.setPbranduuid(component.getBrand().getUuid());
-                        persistProduct.setPbrandid(component.getBrandid());
-                        persistProduct.setCmpUuId(component.getUuid());
-                        persistProduct.setCmpImg(component.getImg());
-                        persistProduct.setKinden(component.getKind().getNameEn());
-                        persistProduct.setKind(component.getKind().getNameCn());
-                        persistProduct.setKindid(component.getKindid());
-                        String errorMsg = "该物料可以匹配为标准";
-                        if (!StringUtils.isEmpty(component.getAttach())) {
-                            List<ProductPrivate> privateList = productPrivateDao.findByPrId(persistProduct.getId());
-                            if (CollectionUtils.isNotEmpty(privateList)) {
-                                ProductPrivate productPrivate = privateList.get(0);
-                                productPrivate.setAttach(component.getAttach());
-                                errorMsg = ",且规格书已存在,不能修改";
-                            }
+                        //更新物料信息
+                        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(product.getSpec())) {
-                            //如果标准器件库存在规格信息,而用户又未填写,则需要填充对应的信息
-                            if (!StringUtils.isEmpty(component.getDescription())) {
-                                persistProduct.setSpec(component.getDescription());
-                            } else {
-                                persistProduct.setSpec(product.getSpec());
-                            }
-                        } else {
-                            if (!product.getSpec().equals(persistProduct.getSpec())) {
-                                persistProduct.setSpec(product.getSpec());
-                            }
-                        }
-                        productDao.save(persistProduct);
-                        //更新在售产品的信息
-                        goodsDao.updateGoodsByProduct(persistProduct.getPbrand(), persistProduct.getPbranden(), persistProduct.getPbrandid(), persistProduct.getPbranduuid(), persistProduct.getKind(), persistProduct.getKindid(), persistProduct.getCmpImg(), persistProduct.getCmpUuId(), persistProduct.getSpec(), persistProduct.getId());
-                        return ResultMap.success(errorMsg);
+
                     } else {
-                        String msg = "";
                         //非标且找不到标准信息
-                        String brand = "", code = "", kind = "", spec = "";
-                        ProductPrivate productPrivate = null;
+                        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);
@@ -1942,17 +1947,7 @@ public class ProductServiceImpl implements ProductService {
                                 persistProduct.setKind(kind);
                             }
                         }
-                        if (!StringUtilB2C.equals(persistProduct.getSpec() , product.getSpec())) {
-                            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 (!StringUtils.isEmpty(brand) || !StringUtils.isEmpty(code)) {
                             if (StringUtils.isEmpty(code)) {
                                 code = persistProduct.getPcmpcode();
@@ -1962,33 +1957,31 @@ public class ProductServiceImpl implements ProductService {
                             }
                             List<Product> products = productDao.findByEnUUAndPcmpcodeAndPbrandenAndB2cEnabled(SystemSession.getUser().getEnterprise().getUu(), code, brand, IntegerConstant.YES_SHORT);
                             if (CollectionUtils.isNotEmpty(products)) {
-                                return new ResultMap(CodeType.NOT_PERMIT, "该企业下已存在同品牌、同型号的企业。");
+                                return new ResultMap(CodeType.NOT_PERMIT, "该企业下已存在同品牌、同型号的物料。");
                             } else {
                                 Component component1 = findBybrNameAndcmpCode(brand, code);
                                 if (component1 != null) {
-                                    //TODO 转标准,规格信息设置、规格书设置
+                                    //根据器件更新物料信息
+                                    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);
                                 }
                             }
-                        }
-                        List<ProductPrivate> productPrivateList = productPrivateDao.findByPrId(persistProduct.getId());
-                        if (CollectionUtils.isNotEmpty(productPrivateList)) {
-                            productPrivate = productPrivateList.get(0);
-                            if (!StringUtils.isEmpty(productPrivate.getAttach())) {
-                                msg = "规格书已存在";
-                            }
+                        } else {
+                            //直接保存
+                            Product product1 = productDao.save(persistProduct);
+                            return ResultMap.success(product1);
                         }
                     }
                 } else {
                     //标准的信息,只能修改规格书、规格信息
-                    String msg = "";
-                    String updateAttachUrl = "";
-                    String spec = "";
                     Component component = null;
-                    Product product1 = null;
                     if (!StringUtilB2C.equals(product.getPbranden(), persistProduct.getPbranden())) {
                         return new ResultMap(CodeType.NOT_PERMIT, "标准物料,品牌不能修改");
                     }
@@ -1998,59 +1991,26 @@ public class ProductServiceImpl implements ProductService {
                     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());
                     }
-                    if (!StringUtils.isEmpty(attachUrl)) {
-                        List<ProductPrivate> productPrivates = productPrivateDao.findByPrId(persistProduct.getId());
-                        if (CollectionUtils.isNotEmpty(productPrivates)) {
-                            if (StringUtils.isEmpty(productPrivates.get(0).getAttach())) {
-                                if (component != null) {
-                                    if (StringUtils.isEmpty(component.getAttach())) {
-                                        productAttachService.submit(persistProduct.getId(), attachUrl);
-                                    } else {
-                                        msg = "规格书已经存在,不能上传";
-                                        updateAttachUrl = component.getAttach();
-                                        productPrivates.get(0).setAttach(updateAttachUrl);
-                                        productPrivateDao.save(productPrivates.get(0));
-                                    }
-                                } else {
-                                    productAttachService.submit(persistProduct.getId(), attachUrl);
-                                }
-                            } else {
-                                msg = "规格书已经存在,不能上传";
-                            }
-                        }
-                    }
-                    if (!StringUtilB2C.equals(product.getSpec(), persistProduct.getSpec())) {
-                        if (StringUtils.isEmpty(product.getSpec())) {
-                            if (!StringUtils.isEmpty(component.getSpec())) {
-                                spec = component.getSpec();
-                                persistProduct.setSpec(component.getSpec());
-                            } else {
-                                spec = product.getSpec();
-                                persistProduct.setSpec(product.getSpec());
-                            }
-                        } else {
-                            spec = product.getSpec();
-                            persistProduct.setSpec(product.getSpec());
+                    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);
                         }
-                        product1 = productDao.save(persistProduct);
-                    }
-
-
-                    //更新在售产品信息
-                    goodsService.updateGoodsByProduct(product1);
-                    if (StringUtils.isEmpty(msg)) {
-                        msg = "修改成功";
+                        return new ResultMap(CodeType.OK.code(), "成功");
                     }
-                    return new ResultMap(CodeType.OK.code(), msg, product1);
                 }
             } else {
                 return new ResultMap(CodeType.NOT_COMPLETE_INFO, "物料信息丢失,请重新操作");
             }
         }
-        return null;
     }
 
 
@@ -2080,5 +2040,124 @@ public class ProductServiceImpl implements ProductService {
             }
         }
     }
+
+    /**
+     * 更新物料信息根据标准器件
+     *
+     * @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("");
+            }
+        }
+    }
 }
 

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

@@ -112,6 +112,6 @@ public interface BrandDao extends JpaSpecificationExecutor<Brand>, JpaRepository
 	 * @param brandName
 	 * @return
 	 */
-	@Query(value = "select b from product$brand b where upper(b.br_name_cn) = upper(:brandName) or upper(b.br_name_en) = upper(:brandName)")
-	List<Brand> findByName(String brandName);
+	@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);
 }

+ 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;