瀏覽代碼

spec、kind字段改为mall、b2b更新,erp仅提供初始化功能

wangyc 7 年之前
父節點
當前提交
573e918218

+ 5 - 0
src/main/java/com/uas/ps/product/controller/ProductController.java

@@ -8,6 +8,7 @@ import com.uas.ps.entity.Product;
 import com.uas.ps.entity.Status;
 import com.uas.ps.httplog.annotation.HttpLog;
 import com.uas.ps.product.data.MyJdbcTemplate;
+import com.uas.ps.product.entity.Constant;
 import com.uas.ps.product.entity.Prod;
 import com.uas.ps.product.entity.ProductSaler;
 import com.uas.ps.product.service.ProductService;
@@ -15,6 +16,7 @@ import com.uas.ps.product.support.ProductBufferedLogger;
 import com.uas.ps.product.sync.WaitSyncHelper;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.ui.ModelMap;
+import org.springframework.util.StringUtils;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
@@ -69,6 +71,7 @@ public class ProductController {
      * @throws UnsupportedEncodingException
      */
     @HttpLog
+    @Deprecated
     @RequestMapping(value = "/erp/save", method = RequestMethod.POST)
     public void saveProducts(@RequestParam("data") String data, Long enUU) throws UnsupportedEncodingException {
         String jsonStr = URLDecoder.decode(data, "UTF-8");
@@ -92,6 +95,7 @@ public class ProductController {
      * @throws UnsupportedEncodingException
      */
     @HttpLog
+    @Deprecated
     @RequestMapping(value = "/erp/update", method = RequestMethod.POST)
     public void updateProduct(@RequestParam("data") String data, @RequestParam("enUU") Long enUU) throws UnsupportedEncodingException {
         String jsonStr = URLDecoder.decode(data, "UTF-8");
@@ -155,6 +159,7 @@ public class ProductController {
                     e.printStackTrace();
                 }
             } else {
+                productService.updateMall(product, products.get(0));
                 resultProducts.add(products.get(0).getId());
             }
         }

+ 7 - 0
src/main/java/com/uas/ps/product/service/ProductService.java

@@ -22,6 +22,13 @@ public interface ProductService {
      */
     Product save(Product productInfo);
 
+    /**
+     * 商城更新物料信息
+     * @param productInfo 物料信息
+     * @return
+     */
+    Product updateMall(Product productInfo, Product product);
+
     /**
      * 批量保存产品 商城b2cenabled字段为1时才可见,所以需要设置
      *

+ 73 - 24
src/main/java/com/uas/ps/product/service/impl/ProductServiceImpl.java

@@ -12,6 +12,7 @@ import com.uas.ps.entity.ProductUsers;
 import com.uas.ps.entity.Status;
 import com.uas.ps.product.ProductConstant;
 import com.uas.ps.product.data.MyJdbcTemplate;
+import com.uas.ps.product.entity.Constant;
 import com.uas.ps.product.entity.Prod;
 import com.uas.ps.product.entity.ProductSaler;
 import com.uas.ps.product.repository.ProductDao;
@@ -21,15 +22,6 @@ import com.uas.ps.product.repository.ProductUsersDao;
 import com.uas.ps.product.service.ProductService;
 import com.uas.ps.product.sync.WaitSyncHelper;
 import com.uas.ps.properties.UrlProperties;
-import org.apache.commons.collections.CollectionUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.jdbc.core.BatchPreparedStatementSetter;
-import org.springframework.jdbc.core.ParameterizedPreparedStatementSetter;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-import org.springframework.ui.ModelMap;
-import org.springframework.web.client.RestTemplate;
-
 import java.sql.PreparedStatement;
 import java.sql.SQLException;
 import java.text.SimpleDateFormat;
@@ -38,6 +30,14 @@ import java.util.Date;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
+import org.apache.commons.collections.CollectionUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.jdbc.core.BatchPreparedStatementSetter;
+import org.springframework.jdbc.core.ParameterizedPreparedStatementSetter;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.ui.ModelMap;
+import org.springframework.web.client.RestTemplate;
 
 /**
  * @author sunyj
@@ -99,6 +99,19 @@ public class ProductServiceImpl implements ProductService {
         return product;
     }
 
+    @Override
+    public Product updateMall(Product productInfo, Product product) {
+        if (!StringUtils.isEmpty(productInfo.getSpec())) {
+            product.setSpec(product.getSpec());
+        }
+        String newkind = productInfo.getKind();
+        if ((product.getStandard() == Constant.NO) && !StringUtils.isEmpty(newkind)) {
+            product.setKind(newkind);
+            product.setTitle(newkind);
+        }
+        return productDao.save(product);
+    }
+
     @Override
     public List<Product> save(List<Product> products) {
         List<ProductPrivate> savePrivateList = new ArrayList<>();
@@ -124,16 +137,26 @@ public class ProductServiceImpl implements ProductService {
         for (Prod prod : prods) {
             prod.setPr_enuu(enUU);
             prod.setKind(prod.getPr_detail());
-            if (prod.getPr_orispeccode() == null) {// 如果原厂型号不存在,将规格赋值给原厂型号
+            if (prod.getPr_orispeccode() == null) { // 如果原厂型号不存在,将规格赋值给原厂型号
                 prod.setPr_orispeccode(prod.getPr_spec());
             }
             List<Product> prodResult = productDao.findByEnUUAndCode(prod.getPr_enuu(), prod.getPr_code());
-            if (CollectionUtils.isEmpty(prodResult)) {// 不存在的新上传上来的物料,新增
+            if (CollectionUtils.isEmpty(prodResult)) { // 不存在的新上传上来的物料,新增
                 products.add(prod.convert());
-            } else {// 物料库上已经存在的物料,修改
+            } else { // 物料库上已经存在的物料,修改
                 Product product = prod.convert();
-                product.setId(prodResult.get(0).getId());
-                product.setCode(prodResult.get(0).getCode());
+                // 如果已存在物料类目不为空,erp上传的类目就不用覆盖
+                Product existProduct = prodResult.get(0);
+                if (!StringUtils.isEmpty(existProduct.getKind())) {
+                    product.setTitle(existProduct.getKind());
+                    product.setKind(existProduct.getKind());
+                }
+                // 如果已存在物料规格不为空,erp上传的规格就不用覆盖
+                if (!StringUtils.isEmpty(existProduct.getSpec())) {
+                    product.setSpec(existProduct.getSpec());
+                }
+                product.setId(existProduct.getId());
+                product.setCode(existProduct.getCode());
                 products.add(product);
             }
         }
@@ -144,14 +167,24 @@ public class ProductServiceImpl implements ProductService {
     public Product convertProductOne(Prod prod, Long enUU) {
         prod.setPr_enuu(enUU);
         prod.setKind(prod.getPr_detail());
-        if (prod.getPr_orispeccode() == null) {// 如果原厂型号不存在,将规格赋值给原厂型号
+        if (prod.getPr_orispeccode() == null) { // 如果原厂型号不存在,将规格赋值给原厂型号
             prod.setPr_orispeccode(prod.getPr_spec());
         }
         List<Product> prodResult = productDao.findByEnUUAndCode(prod.getPr_enuu(), prod.getPr_code());
-        if (CollectionUtils.isEmpty(prodResult)) {// 不存在的新上传上来的物料,新增
+        if (CollectionUtils.isEmpty(prodResult)) { // 不存在的新上传上来的物料,新增
             return (prod.convert());
-        } else {// 物料库上已经存在的物料,修改
+        } else { // 物料库上已经存在的物料,修改
             Product product = prod.convert();
+            // 如果已存在物料类目不为空,erp上传的类目就不用覆盖
+            Product existProduct = prodResult.get(0);
+            if (!StringUtils.isEmpty(existProduct.getKind())) {
+                product.setTitle(existProduct.getKind());
+                product.setKind(existProduct.getKind());
+            }
+            // 如果已存在物料规格不为空,erp上传的规格就不用覆盖
+            if (!StringUtils.isEmpty(existProduct.getSpec())) {
+                product.setSpec(existProduct.getSpec());
+            }
             product.setId(prodResult.get(0).getId());
             product.setCode(prodResult.get(0).getCode());
             return product;
@@ -257,7 +290,14 @@ public class ProductServiceImpl implements ProductService {
             if (!CollectionUtils.isEmpty(products) && null == product.getId()) {
                 Product existedProd = products.get(0);
                 existedProd.setTitle(product.getTitle());
-                existedProd.setSpec(product.getSpec());
+                // 如果物料已存在,新上传物料存在规格、类目则更新已存在物料
+                if (!StringUtils.isEmpty(product.getSpec())) {
+                    existedProd.setSpec(product.getSpec());
+                }
+                if (!StringUtils.isEmpty(product.getTitle())) {
+                    existedProd.setKind(product.getTitle());
+                    existedProd.setTitle(product.getTitle());
+                }
                 existedProd.setCmpCode(product.getCmpCode());
                 existedProd.setUnit(product.getUnit());
                 existedProd.setBrand(product.getBrand());
@@ -448,20 +488,28 @@ public class ProductServiceImpl implements ProductService {
             if (null == product.getId()) {
                 newList.add(product);
             } else {
-                updateList.add(product);
-                ids.add(product.getId());
+                Product existProduct = productDao.findOne(product.getId());
+                // 如果物料已存在,且新上传物料存在类目、规格信息时,更新已存在物料字段
+                if (product != null) {
+                    if (StringUtils.isEmpty(product.getTitle()) && !StringUtils.isEmpty(existProduct.getKind())) {
+                        product.setTitle(existProduct.getKind());
+                        product.setTitle(existProduct.getKind());
+                    }
+
+                    if (StringUtils.isEmpty(product.getSpec()) && !StringUtils.isEmpty(existProduct.getSpec())) {
+                        product.setSpec(existProduct.getSpec());
+                    }
+                    updateList.add(product);
+                    ids.add(product.getId());
+                }
             }
         }
-//        long start = System.currentTimeMillis();
         if (!CollectionUtils.isEmpty(newList)) {
             List<Long> newIds = insertAndReturnKey(newList);
-//            System.out.println("插入新数据,数据量:" + newIds.size() + "耗时:" + (System.currentTimeMillis() - start));
-//            start = System.currentTimeMillis();
             ids.addAll(newIds);
         }
         if (!CollectionUtils.isEmpty(updateList)) {
             updateExisted(updateList);
-//            System.out.println("update数据,数据量:" + updateList.size() + "耗时:" + (System.currentTimeMillis() - start));
         }
         return ids;
     }
@@ -676,6 +724,7 @@ public class ProductServiceImpl implements ProductService {
         product.setKind(component.getKind().getNameCn());
         product.setKindEn(component.getKind().getNameEn());
         product.setKindId(component.getKindid());
+        product.setTitle(component.getKind().getNameCn());
         product.setStandard(ProductConstant.STANDARD);
     }