Browse Source

针对B2B新增单据物料校验新增方法

hejq 7 years ago
parent
commit
bf729369f5

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

@@ -9,6 +9,7 @@ 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.Prod;
+import com.uas.ps.product.entity.ProductInfo;
 import com.uas.ps.product.entity.ProductSaler;
 import com.uas.ps.product.service.ProductService;
 import com.uas.ps.product.support.ProductBufferedLogger;
@@ -574,4 +575,16 @@ public class ProductController {
     public ModelMap getBusinessOpportunity(Long enUU, String pCmpCode, String pBrandEn) {
         return productService.getBusinessOpportunity(enUU, pCmpCode, pBrandEn);
     }
+
+    /**
+     * B2B 新增单据导入物料进行相关校验操作
+     *
+     * @param products 导入的物料信息
+     * @return
+     */
+    @HttpLog
+    @RequestMapping(value = "/checkImportProductList", method = RequestMethod.POST)
+    public Map<String, Object> checkImportProductList(@RequestBody List<ProductInfo> products) {
+        return productService.checkImportProductList(products);
+    }
 }

+ 106 - 0
src/main/java/com/uas/ps/product/entity/ProductInfo.java

@@ -0,0 +1,106 @@
+package com.uas.ps.product.entity;
+
+
+import com.uas.ps.entity.Product;
+
+import java.util.Date;
+
+/**
+ * 新增采购po批量导入物料信息
+ * 
+ * @author hejq
+ * @time 创建时间:2017年5月17日
+ */
+public class ProductInfo extends Product {
+
+	/**
+	 * 数量
+	 */
+	private Double amount;
+
+    /**
+     * 不含税单价
+     */
+    private Double unitPrice;
+
+	/**
+	 * 税率
+	 */
+	private Integer rate;
+
+	/**
+	 * 含税单价
+	 */
+	private Double rateprice;
+
+	/**
+	 * 不含税总额
+	 */
+	private Double totalprice;
+
+	/**
+	 * 交货日期
+	 */
+	private Date date;
+
+	/**
+	 * 备注
+	 */
+	private String remark;
+
+	public Double getAmount() {
+		return amount;
+	}
+
+	public void setAmount(Double amount) {
+		this.amount = amount;
+	}
+
+	public Integer getRate() {
+		return rate;
+	}
+
+	public void setRate(Integer rate) {
+		this.rate = rate;
+	}
+
+    public Double getUnitPrice() {
+        return unitPrice;
+    }
+
+    public void setUnitPrice(Double unitPrice) {
+        this.unitPrice = unitPrice;
+    }
+
+    public Double getRateprice() {
+		return rateprice;
+	}
+
+	public void setRateprice(Double rateprice) {
+		this.rateprice = rateprice;
+	}
+
+	public Double getTotalprice() {
+		return totalprice;
+	}
+
+	public void setTotalprice(Double totalprice) {
+		this.totalprice = totalprice;
+	}
+
+	public Date getDate() {
+		return date;
+	}
+
+	public void setDate(Date date) {
+		this.date = date;
+	}
+
+	public String getRemark() {
+		return remark;
+	}
+
+	public void setRemark(String remark) {
+		this.remark = remark;
+	}
+}

+ 28 - 0
src/main/java/com/uas/ps/product/repository/ProductDao.java

@@ -1,6 +1,7 @@
 package com.uas.ps.product.repository;
 
 import com.uas.ps.entity.Product;
+import org.springframework.data.domain.Pageable;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
 import org.springframework.data.jpa.repository.Modifying;
@@ -28,6 +29,16 @@ public interface ProductDao extends JpaSpecificationExecutor<Product>, JpaReposi
      */
     List<Product> findByEnUUAndCode(Long pr_enuu, String pr_code);
 
+    /**
+     * 精简查询字段,只返回id就行
+     *
+     * @param enUU 企业UU
+     * @param code 物料编号
+     * @return
+     */
+    @Query("select p.id from Product p where p.enUU = :enUU and p.code = :code")
+    List<Long> findIdByEnUUAndCode(@Param("enUU") long enUU, @Param("code") String code);
+
     /**
      * 查找企业下所有标准或非标物料
      * @param enUU
@@ -183,6 +194,17 @@ public interface ProductDao extends JpaSpecificationExecutor<Product>, JpaReposi
     @Deprecated
     List<Product> findByEnUUAndTitle(Long enUU, String title);
 
+    /**
+     * 精简查询字段,只返回id就行
+     *
+     * @param enUU 企业UU
+     * @param title 物料名称
+     * @param pageable 分页信息(默认只取一条数据,优化效率)
+     * @return
+     */
+    @Query("select p.id, p.code from Product p where p.enUU = :enUU and p.title = :title")
+    List<Object[]> findIdAndCodeByEnUUAndTitle(@Param("enUU") long enUU, @Param("title") String title, Pageable pageable);
+
     /**
      * 通过品牌和enuu查询所有信息
      *                      数量大时,速度会很慢  2018年7月11日 15:18:43  dongbw
@@ -249,6 +271,12 @@ public interface ProductDao extends JpaSpecificationExecutor<Product>, JpaReposi
     @Query("from Product p where p.enUU = :enUU and p.code in :codeSet")
     List<Product> findByEnUUAndCodeSet(@Param("enUU") Long enUU, @Param("codeSet") Set<String> codeSet);
 
+    /**
+     * 通过id批量查询物料信息
+     *
+     * @param idSet id数组
+     * @return
+     */
     @Query("from Product p where p.id in :idSet")
     List<Product> findByIdList(@Param("idSet") List<Long> idSet);
 }

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

@@ -3,6 +3,7 @@ package com.uas.ps.product.service;
 import com.uas.ps.core.page.PageInfo;
 import com.uas.ps.entity.Product;
 import com.uas.ps.product.entity.Prod;
+import com.uas.ps.product.entity.ProductInfo;
 import com.uas.ps.product.entity.ProductPrivateView;
 import com.uas.ps.product.entity.ProductSaler;
 import com.uas.ps.support.ResultMap;
@@ -379,4 +380,12 @@ public interface ProductService {
      * @return 物料page
      */
     Page<ProductPrivateView> findByPageInfo(PageInfo pageInfo, String keyword);
+
+    /**
+     * 批量校验导入物料信息
+     *
+     * @param products 物料
+     * @return
+     */
+    Map<String,Object> checkImportProductList(List<ProductInfo> products);
 }

+ 56 - 1
src/main/java/com/uas/ps/product/service/impl/ProductServiceImpl.java

@@ -24,6 +24,7 @@ import com.uas.ps.support.ResultMap;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.collections.map.HashedMap;
 import org.apache.log4j.Logger;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Sort;
@@ -1209,8 +1210,62 @@ public class ProductServiceImpl implements ProductService {
      */
     public int ordinalIndexOf(String str, String substr, int start, int n) {
         int pos = str.indexOf(substr, start);
-        while (--n > 0 && pos != -1)
+        while (--n > 0 && pos != -1) {
             pos = str.indexOf(substr, pos + 1);
+        }
         return pos;
     }
+
+    /**
+     * 批量校验导入物料信息
+     *
+     * @param products 物料
+     * @return
+     */
+    @Override
+    public Map<String, Object> checkImportProductList(List<ProductInfo> products) {
+        int success = 0;
+        for (ProductInfo productInfo : products) {
+            if (null != productInfo.getCode()) {
+                List<Long> idList = productDao.findIdByEnUUAndCode(productInfo.getEnUU(), productInfo.getCode());
+                if (!CollectionUtils.isEmpty(idList)) {
+                    productInfo.setId(idList.get(0));
+                    success++;
+                } else {
+                    List<Product> productList = new ArrayList<>();
+                    Product product = new Product();
+                    BeanUtils.copyProperties(productInfo, product, Product.class);
+                    productList.add(product);
+                    productList = updateB2bProdInfo(productList);
+                    productInfo.setId(productList.get(0).getId());
+                    success++;
+                }
+            } else {
+                PageInfo pageInfo = new PageInfo(1, 1);
+                List<Object[]> objects = productDao.findIdAndCodeByEnUUAndTitle(productInfo.getEnUU(), productInfo.getTitle(), pageInfo);
+                if (!CollectionUtils.isEmpty(objects)) {
+                    Object[] object = objects.get(0);
+                    productInfo.setId(Long.valueOf(object[0].toString()));
+                    productInfo.setCode(object[1].toString());
+                    success++;
+                } else {
+                    //生成随机编码
+                    SimpleDateFormat sdf = new SimpleDateFormat("yymmddhhmm_sss");
+                    productInfo.setCode("prod" + sdf.format(new Date()));
+                    List<Product> productList = new ArrayList<>();
+                    Product product = new Product();
+                    BeanUtils.copyProperties(productInfo, product, Product.class);
+                    productList.add(product);
+                    productList = updateB2bProdInfo(productList);
+                    productInfo.setCode(productList.get(0).getCode());
+                    productInfo.setId(productList.get(0).getId());
+                    success++;
+                }
+            }
+        }
+        Map<String, Object> map = new HashedMap();
+        map.put("products", products);
+        map.put("success", success);
+        return map;
+    }
 }