hulh пре 8 година
родитељ
комит
0a2f41f72c

+ 357 - 0
src/main/java/com/uas/ps/component/entity/ComponentInfo.java

@@ -0,0 +1,357 @@
+package com.uas.ps.component.entity;
+
+import com.uas.ps.brand.entity.BrandInfo;
+import com.uas.ps.kind.entity.KindInfo;
+
+/**
+ * 器件简要信息
+ * @author hulh
+ */
+public class ComponentInfo {
+    /**
+     * 序列号
+     */
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * id
+     */
+    private Long id;
+
+    /**
+     * 器件的uuid
+     */
+    private String uuid;
+
+    /**
+     * 版本
+     */
+    private Short version;
+
+    /**
+     * 原厂型号
+     */
+    private String code;
+
+    /**
+     * 类目id
+     */
+    private Long kindid;
+
+    /**
+     * 器件的类目
+     */
+    private KindInfo kind;
+
+    /**
+     * 品牌id
+     */
+    private Long brandid;
+
+    /**
+     * 器件的品牌
+     */
+    private BrandInfo brand;
+
+    /**
+     * 器件规格
+     */
+    private String encapsulation;
+
+    /**
+     * 器件的标准单位
+     */
+    private String unit;
+
+    /**
+     * 单重(g)
+     */
+    private Float weight;
+
+    /**
+     * 搜索排序权重
+     */
+    private Double searchWeight;
+
+    /**
+     * 附件id
+     */
+    private String attach;
+
+    /**
+     * 图片path
+     */
+    private String img;
+
+    /**
+     * 以下为器件的库存交易属性,由器件对应的上架商品发生变化时,更新反应到器件
+     */
+
+    /**
+     * 器件的库存
+     */
+    private Double reserve;
+
+    /**
+     * 器件的库存类型
+     */
+    private Short reserveType;
+
+    /**
+     * 器件的最低单价
+     */
+    private Double minPrice;
+
+    /**
+     * 器件的最高单价
+     */
+    private Double maxPrice;
+
+    /**
+     * 器件的最小起订量
+     */
+    private Double minBuyQty;
+
+    /**
+     * 器件最小送货周期
+     */
+    private Short minDelivery;
+
+    /**
+     * 器件最大送货周期
+     */
+    private Short maxDelivery;
+
+    /**
+     * 交易订单数 - 来自订单表中统计订单数
+     */
+    private Double orderNumber;
+
+    /**
+     * 交易数量 - 来自订单表中统计交易数量
+     */
+    private Double orderQty;
+
+    /**
+     * 样品数量汇总
+     */
+    private Double sampleQty;
+
+    /**
+     * 现货数量
+     */
+    private Double originalQty;
+
+    /**
+     * 呆滞库存数量
+     */
+    private Double inactionStockQty;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getUuid() {
+        return uuid;
+    }
+
+    public void setUuid(String uuid) {
+        this.uuid = uuid;
+    }
+
+    public Short getVersion() {
+        return version;
+    }
+
+    public void setVersion(Short version) {
+        this.version = version;
+    }
+
+    public String getCode() {
+        return code;
+    }
+
+    public void setCode(String code) {
+        this.code = code;
+    }
+
+    public Long getKindid() {
+        return kindid;
+    }
+
+    public void setKindid(Long kindid) {
+        this.kindid = kindid;
+    }
+
+    public KindInfo getKind() {
+        return kind;
+    }
+
+    public void setKind(KindInfo kind) {
+        this.kind = kind;
+    }
+
+    public Long getBrandid() {
+        return brandid;
+    }
+
+    public void setBrandid(Long brandid) {
+        this.brandid = brandid;
+    }
+
+    public BrandInfo getBrand() {
+        return brand;
+    }
+
+    public void setBrand(BrandInfo brand) {
+        this.brand = brand;
+    }
+
+    public String getEncapsulation() {
+        return encapsulation;
+    }
+
+    public void setEncapsulation(String encapsulation) {
+        this.encapsulation = encapsulation;
+    }
+
+    public String getUnit() {
+        return unit;
+    }
+
+    public void setUnit(String unit) {
+        this.unit = unit;
+    }
+
+    public Float getWeight() {
+        return weight;
+    }
+
+    public void setWeight(Float weight) {
+        this.weight = weight;
+    }
+
+    public Double getSearchWeight() {
+        return searchWeight;
+    }
+
+    public void setSearchWeight(Double searchWeight) {
+        this.searchWeight = searchWeight;
+    }
+
+    public String getAttach() {
+        return attach;
+    }
+
+    public void setAttach(String attach) {
+        this.attach = attach;
+    }
+
+    public String getImg() {
+        return img;
+    }
+
+    public void setImg(String img) {
+        this.img = img;
+    }
+
+    public Double getReserve() {
+        return reserve;
+    }
+
+    public void setReserve(Double reserve) {
+        this.reserve = reserve;
+    }
+
+    public Short getReserveType() {
+        return reserveType;
+    }
+
+    public void setReserveType(Short reserveType) {
+        this.reserveType = reserveType;
+    }
+
+    public Double getMinPrice() {
+        return minPrice;
+    }
+
+    public void setMinPrice(Double minPrice) {
+        this.minPrice = minPrice;
+    }
+
+    public Double getMaxPrice() {
+        return maxPrice;
+    }
+
+    public void setMaxPrice(Double maxPrice) {
+        this.maxPrice = maxPrice;
+    }
+
+    public Double getMinBuyQty() {
+        return minBuyQty;
+    }
+
+    public void setMinBuyQty(Double minBuyQty) {
+        this.minBuyQty = minBuyQty;
+    }
+
+    public Short getMinDelivery() {
+        return minDelivery;
+    }
+
+    public void setMinDelivery(Short minDelivery) {
+        this.minDelivery = minDelivery;
+    }
+
+    public Short getMaxDelivery() {
+        return maxDelivery;
+    }
+
+    public void setMaxDelivery(Short maxDelivery) {
+        this.maxDelivery = maxDelivery;
+    }
+
+    public Double getOrderNumber() {
+        return orderNumber;
+    }
+
+    public void setOrderNumber(Double orderNumber) {
+        this.orderNumber = orderNumber;
+    }
+
+    public Double getOrderQty() {
+        return orderQty;
+    }
+
+    public void setOrderQty(Double orderQty) {
+        this.orderQty = orderQty;
+    }
+
+    public Double getSampleQty() {
+        return sampleQty;
+    }
+
+    public void setSampleQty(Double sampleQty) {
+        this.sampleQty = sampleQty;
+    }
+
+    public Double getOriginalQty() {
+        return originalQty;
+    }
+
+    public void setOriginalQty(Double originalQty) {
+        this.originalQty = originalQty;
+    }
+
+    public Double getInactionStockQty() {
+        return inactionStockQty;
+    }
+
+    public void setInactionStockQty(Double inactionStockQty) {
+        this.inactionStockQty = inactionStockQty;
+    }
+}

+ 86 - 0
src/main/java/com/uas/ps/kind/entity/KindInfo.java

@@ -0,0 +1,86 @@
+package com.uas.ps.kind.entity;
+
+/**
+ * 类目简要信息
+ * @author hulh
+ */
+public class KindInfo {
+
+    /**
+     * id
+     */
+    private Long id;
+
+    /**
+     * 类目名称
+     */
+    private String nameCn;
+
+    /**
+     * 英文名
+     */
+    private String nameEn;
+
+    /**
+     * 是否为叶子类目 1是 0否
+     */
+    private Short isLeaf;
+
+    /**
+     * 父节点id
+     */
+    private Long parentid;
+
+    /**
+     * 类目的层级,从1开始,1、2、3、4
+     */
+    private Short level;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getNameCn() {
+        return nameCn;
+    }
+
+    public void setNameCn(String nameCn) {
+        this.nameCn = nameCn;
+    }
+
+    public String getNameEn() {
+        return nameEn;
+    }
+
+    public void setNameEn(String nameEn) {
+        this.nameEn = nameEn;
+    }
+
+    public Short getIsLeaf() {
+        return isLeaf;
+    }
+
+    public void setIsLeaf(Short isLeaf) {
+        this.isLeaf = isLeaf;
+    }
+
+    public Long getParentid() {
+        return parentid;
+    }
+
+    public void setParentid(Long parentid) {
+        this.parentid = parentid;
+    }
+
+    public Short getLevel() {
+        return level;
+    }
+
+    public void setLevel(Short level) {
+        this.level = level;
+    }
+}

+ 11 - 4
src/main/java/com/uas/ps/product/controller/ProductController.java

@@ -17,10 +17,7 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.ModelMap;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.*;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -121,6 +118,16 @@ public class ProductController {
         return productService.match(enUU, userUU, type);
     }
 
+    /**
+     * 匹配选中的列表
+     * @param idList
+     * @return
+     */
+    @RequestMapping(value = "/match/selected", method = RequestMethod.POST)
+    public ModelMap matchSelected(@RequestParam Long enUU, @RequestBody List<Long> idList) {
+        return productService.batchMatch(enUU, idList);
+    }
+
     /**
      * 分配个人物料
      *

+ 19 - 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 com.uas.ps.product.entity.Prod;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
 import org.springframework.data.jpa.repository.Modifying;
@@ -26,6 +27,14 @@ public interface ProductDao extends JpaSpecificationExecutor<Product>, JpaReposi
      */
     List<Product> findByEnUUAndCode(Long pr_enuu, String pr_code);
 
+    /**
+     * 查找企业下所有标准或非标物料
+     * @param enUU
+     * @param standard
+     * @return
+     */
+    List<Product> findByEnUUAndStandard(Long enUU, Short standard);
+
     /**
      * 根据物料所属enUU、来源app和下载状态查询物料
      * @param enUU 物料企业UU
@@ -69,6 +78,16 @@ public interface ProductDao extends JpaSpecificationExecutor<Product>, JpaReposi
      */
     List<Product> findByTitleAndPCmpCodeAndPBrandAndEnUU(String title, String cmpcode, String brand, Long enUU);
 
+    /**
+     * 根据以下字段查询物料
+     *
+     * @param pcmpcode  物料型号
+     * @param pbranden  物料品牌
+     * @param enUU      企业uu
+     * @return
+     */
+    List<Product> findProductByPcmpcodeAndPbrandenAndEnUU(String pcmpcode, String pbranden, Long enUU);
+
 //    /**
 //     * 通过uu查询非标准器件进行存储
 //     *

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

@@ -5,6 +5,7 @@ import com.uas.ps.product.entity.Prod;
 import com.uas.ps.product.entity.ProductSaler;
 import org.apache.poi.ss.usermodel.Workbook;
 import org.springframework.ui.ModelMap;
+import org.springframework.web.bind.annotation.RequestBody;
 
 import java.util.List;
 
@@ -111,4 +112,12 @@ public interface ProductService {
      * @return
      */
     ModelMap releaseByWorkbook(Workbook workbook, Long enUU, Long userUU);
+
+    /**
+     * 匹配选中的物料
+     * @param enUU
+     * @param idList
+     * @return
+     */
+    ModelMap batchMatch(Long enUU, List<Long> idList);
 }

+ 52 - 54
src/main/java/com/uas/ps/product/service/impl/ProductServiceImpl.java

@@ -2,9 +2,11 @@ package com.uas.ps.product.service.impl;
 
 import com.alibaba.fastjson.JSONObject;
 import com.uas.ps.brand.entity.BrandInfo;
+import com.uas.ps.component.entity.ComponentInfo;
 import com.uas.ps.entity.Product;
 import com.uas.ps.entity.ProductUsers;
 import com.uas.ps.entity.Status;
+import com.uas.ps.kind.entity.KindInfo;
 import com.uas.ps.product.ProductConstant;
 import com.uas.ps.product.entity.Constant;
 import com.uas.ps.product.entity.Prod;
@@ -92,77 +94,73 @@ public class ProductServiceImpl implements ProductService {
     @Override
     public ModelMap match(Long enUU, Long userUU, String matchtype) {
         ModelMap map = new ModelMap();
-        //TODO
-//        boolean flag = true;
-//        ProductStoreStatus status = productStoreStatusDao.findByEnuu(enUU);
-//        if (status != null) {
-//            if (status.getStatus().equals(Status.RUNNING.value())) {// 有人正在操作这张单据,不能进行操作
-//                map.put("error", "当前有人正在进行匹配操作,无法进行匹配");
-//                flag = false;
-//            } else {
-//                status.setStatus(Status.RUNNING.value());
-//                status = productStoreStatusDao.save(status);
-//            }
-//        } else {
-//            ProductStoreStatus stroestatus = new ProductStoreStatus();
-//            stroestatus.setDate(new Date());
-//            stroestatus.setEnuu(enUU);
-//            stroestatus.setUseruu(userUU);
-//            stroestatus.setStatus(Status.RUNNING.value());
-//            status = productStoreStatusDao.save(stroestatus);
-//        }
-//        String num = null;
-//        if (flag) {
-//            if (matchtype.equals("sale")) {
-//                num = productDao.updateResultByEnuuForSale(enUU);
-////                logger.log("产品匹配", "一键匹配了产品信息", "大小" + num);
-//            } else if (matchtype.equals("purc")) {
-//                num = productDao.updateResultByEnuuForPurc(enUU);
-////                logger.log("物料匹配", "一键匹配了物料信息", "大小" + num);
-//            } else if (matchtype.equals("all")) {
-//                num = productDao.updateResultByEnuu(enUU);
-////                logger.log("物料匹配", "一键匹配了产品(物料)信息", "大小" + num);
-//            }
-//            if (null == num) {
-//                map.put("size", 0);
-//            } else {
-//                map.put("size", num);
-//            }
-//            status.setStatus(Status.FINISH.value());
-//            productStoreStatusDao.save(status);
-//        }
+        int success = 0;
+        List<Product> nonStandardList = productDao.findByEnUUAndStandard(enUU, ProductConstant.NON_STANDARD);
+        for (Product product : nonStandardList) {
+            success += matchOne(product, enUU);
+        }
+        map.put("success", success);
+        return map;
+    }
+
+    /**
+     * 批量匹配
+     * @param   enUU
+     * @param   idList
+     */
+    @Override
+    public ModelMap batchMatch(Long enUU, List<Long> idList) {
+        ModelMap map = new ModelMap();
+        int success = 0;
+        for (Long id : idList) {
+            Product product = productDao.findOne(id);
+            success += matchOne(product, enUU);
+        }
+        map.put("success", success);
         return map;
     }
 
     /**
      * 单个物料匹配
-     * @param product
+     * @param   product
+     * @param   enUU
      */
-    private void matchOne(Product product) {
+    private int matchOne(Product product, Long enUU) {
+        BrandInfo brand;
+        ComponentInfo component;
+        List<Product> standardList;
         // 获取品牌
-        String brandUrl = "";
-        BrandInfo result = restTemplate.getForEntity(brandUrl, BrandInfo.class).getBody();
-        if (result.getUuid() != null) {
-            String componentUrl = "";
-            JSONObject component = restTemplate.getForEntity(componentUrl, JSONObject.class).getBody();
+        String brandUrl = "http://10.1.51.89:8080/platform-b2c/api/product/brand/byName/brand?name=" + product.getpBrandEn();
+        brand = restTemplate.getForEntity(brandUrl, BrandInfo.class).getBody();
+        if (brand.getUuid() != null) {
+            String componentUrl = "http://10.1.51.89:8080/platform-b2c/api/product/component/codeAndBrand/info?brandId="
+                    + brand.getId() + "&cmpCode=" + product.getpCmpCode();
+            component = restTemplate.getForEntity(componentUrl, ComponentInfo.class).getBody();
             if (component != null) {
                 // 更新物料信息
-                updateProductByComponent(product, result, component);
+                updateProductByComponent(product, brand, component);
+                standardList = productDao.findProductByPcmpcodeAndPbrandenAndEnUU(product.getpCmpCode(), product.getpBrand(), enUU);
+                if (!CollectionUtils.isEmpty(standardList)) {
+                    // TODO 已有标准产品,该如何处理
+                }
+                productDao.save(product);
+                return 1;
             }
         }
+        return 0;
     }
 
-    private void updateProductByComponent(Product product, BrandInfo brandInfo, JSONObject component) {
-        product.setCmpUuid(component.getString("uuid"));
+    private void updateProductByComponent(Product product, BrandInfo brandInfo, ComponentInfo component) {
+        product.setCmpUuid(component.getUuid());
+        product.setCmpImg(component.getImg());
+        product.setpCmpCode(component.getCode());
         product.setpBrandId(brandInfo.getId());
         product.setpBrand(brandInfo.getNameCn());
         product.setpBrandEn(brandInfo.getNameEn());
         product.setpBrandUuid(brandInfo.getUuid());
-        product.setCmpImg(component.getString("img"));
-        product.setKind("");
-        product.setKindEn("");
-        product.setKindId(2L);
-        product.setpCmpCode("");
+        product.setKind(component.getKind().getNameCn());
+        product.setKindEn(component.getKind().getNameEn());
+        product.setKindId(component.getKindid());
         product.setStandard(ProductConstant.STANDARD);
     }