Browse Source

添加物料匹配的方法

hulh 8 years ago
parent
commit
0984c5eccf

+ 139 - 0
src/main/java/com/uas/ps/brand/entity/BrandInfo.java

@@ -0,0 +1,139 @@
+package com.uas.ps.brand.entity;
+
+import java.util.Date;
+
+/**
+ * 品牌简要信息
+ * @author hulh
+ */
+public class BrandInfo {
+
+    /**
+     * id
+     */
+    private Long id;
+
+    /**
+     * uuid
+     */
+    private String uuid;
+
+    /**
+     * 版本号
+     */
+    private Short version;
+
+    /**
+     * 品牌中文名称
+     */
+    private String nameCn;
+
+    /**
+     * 品牌英文名称
+     */
+    private String nameEn;
+
+    /**
+     * logo路径
+     */
+    private String logoUrl;
+
+    /**
+     * 权重,可用于排序
+     */
+    private Double weight;
+
+    private String vendor;
+
+    /**
+     * 创建时间
+     */
+    private Date createTime;
+
+    /**
+     * 英文品牌名首字母
+     */
+    private String inital;
+
+    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 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 String getLogoUrl() {
+        return logoUrl;
+    }
+
+    public void setLogoUrl(String logoUrl) {
+        this.logoUrl = logoUrl;
+    }
+
+    public Double getWeight() {
+        return weight;
+    }
+
+    public void setWeight(Double weight) {
+        this.weight = weight;
+    }
+
+    public String getVendor() {
+        return vendor;
+    }
+
+    public void setVendor(String vendor) {
+        this.vendor = vendor;
+    }
+
+    public Date getCreateTime() {
+        return createTime;
+    }
+
+    public void setCreateTime(Date createTime) {
+        this.createTime = createTime;
+    }
+
+    public String getInital() {
+        return inital;
+    }
+
+    public void setInital(String inital) {
+        this.inital = inital;
+    }
+
+}
+

+ 22 - 0
src/main/java/com/uas/ps/product/ProductConstant.java

@@ -0,0 +1,22 @@
+package com.uas.ps.product;
+
+/**
+ * 物料常量
+ * @author hulh
+ */
+public final class ProductConstant {
+
+    private ProductConstant() {
+
+    }
+
+    /**
+     * 标准
+     */
+    public static final Short STANDARD = 1;
+
+    /**
+     * 非准
+     */
+    public static final Short NON_STANDARD = 0;
+}

+ 39 - 0
src/main/java/com/uas/ps/product/service/impl/ProductServiceImpl.java

@@ -1,8 +1,11 @@
 package com.uas.ps.product.service.impl;
 
+import com.alibaba.fastjson.JSONObject;
+import com.uas.ps.brand.entity.BrandInfo;
 import com.uas.ps.entity.Product;
 import com.uas.ps.entity.ProductUsers;
 import com.uas.ps.entity.Status;
+import com.uas.ps.product.ProductConstant;
 import com.uas.ps.product.entity.Constant;
 import com.uas.ps.product.entity.Prod;
 import com.uas.ps.product.entity.ProductSaler;
@@ -19,6 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.ui.ModelMap;
 import org.springframework.util.CollectionUtils;
+import org.springframework.web.client.RestTemplate;
 
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
@@ -44,6 +48,9 @@ public class ProductServiceImpl implements ProductService {
     @Autowired
     private ProductStoreStatusDao productStoreStatusDao;
 
+    @Autowired
+    private RestTemplate restTemplate;
+
     /**
      * 保存物料
      *
@@ -127,6 +134,38 @@ public class ProductServiceImpl implements ProductService {
         return map;
     }
 
+    /**
+     * 单个物料匹配
+     * @param product
+     */
+    private void matchOne(Product product) {
+        // 获取品牌
+        String brandUrl = "";
+        BrandInfo result = restTemplate.getForEntity(brandUrl, BrandInfo.class).getBody();
+        if (result.getUuid() != null) {
+            String componentUrl = "";
+            JSONObject component = restTemplate.getForEntity(componentUrl, JSONObject.class).getBody();
+            if (component != null) {
+                // 更新物料信息
+                updateProductByComponent(product, result, component);
+            }
+        }
+    }
+
+    private void updateProductByComponent(Product product, BrandInfo brandInfo, JSONObject component) {
+        product.setCmpUuid(component.getString("uuid"));
+        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.setStandard(ProductConstant.STANDARD);
+    }
+
     @Override
     public ModelMap assignPersonalProduct(Long userUU, Long productId) {
         ModelMap map = new ModelMap();