hulh 7 жил өмнө
parent
commit
411814f129

+ 4 - 0
pom.xml

@@ -30,6 +30,10 @@
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-actuator</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-configuration-processor</artifactId>
+        </dependency>
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-data-jpa</artifactId>

+ 20 - 0
src/main/java/com/uas/ps/product/UrlConfiguration.java

@@ -0,0 +1,20 @@
+package com.uas.ps.product;
+
+import com.uas.ps.properties.UrlProperties;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.client.RestTemplate;
+
+/**
+ * RestTemplate 配置类
+ * @author hulh
+ */
+@Configuration
+public class UrlConfiguration {
+
+    @Bean
+    public UrlProperties servletRegistrationUrl() {
+        return new UrlProperties();
+    }
+
+}

+ 6 - 3
src/main/java/com/uas/ps/product/service/impl/ProductServiceImpl.java

@@ -16,6 +16,7 @@ import com.uas.ps.product.repository.ProductMatchResultDao;
 import com.uas.ps.product.repository.ProductStoreStatusDao;
 import com.uas.ps.product.repository.ProductUsersDao;
 import com.uas.ps.product.service.ProductService;
+import com.uas.ps.properties.UrlProperties;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.poi.ss.usermodel.Cell;
 import org.apache.poi.ss.usermodel.Row;
@@ -51,6 +52,8 @@ public class ProductServiceImpl implements ProductService {
     @Autowired
     private RestTemplate restTemplate;
 
+    @Autowired
+    private UrlProperties urlProperties;
     /**
      * 保存物料
      *
@@ -151,10 +154,10 @@ public class ProductServiceImpl implements ProductService {
      */
     private int matchOne(Product product, Long enUU) {
         // 获取品牌
-        String brandUrl = "http://192.168.253.129:8080/platform-b2c/api/product/brand/byName/brand?name=" + product.getBrand();
+        String brandUrl = urlProperties.getB2cUrl() + "/api/product/brand/byName/brand?name=" + product.getBrand();
         BrandInfo brand = restTemplate.getForEntity(brandUrl, BrandInfo.class).getBody();
         if (brand.getUuid() != null) {
-            String componentUrl = "http://192.168.253.129:8080/platform-b2c/api/product/component/codeAndBrand/info?brandId="
+            String componentUrl = urlProperties.getB2cUrl() + "/api/product/component/codeAndBrand/info?brandId="
                     + brand.getId() + "&cmpCode=" + product.getCmpCode();
             ComponentInfo component = restTemplate.getForEntity(componentUrl, ComponentInfo.class).getBody();
             if (component != null) {
@@ -169,7 +172,7 @@ public class ProductServiceImpl implements ProductService {
             }
         }
         // 根据型号匹配
-        String codeUrl = "http://192.168.253.129:8080/platform-b2c/api/product/component/byCode?code=" + product.getpCmpCode();
+        String codeUrl = urlProperties.getB2cUrl() + "/api/product/component/byCode?code=" + product.getpCmpCode();
         String componentJson = restTemplate.getForEntity(codeUrl, String.class).getBody();
         List<ComponentInfo> componentInfoList = JSON.parseArray(componentJson, ComponentInfo.class);
         Set<ProductMatchResult> productMatchResults = convertComponentToResult(product.getId(), componentInfoList, enUU);

+ 21 - 0
src/main/java/com/uas/ps/properties/UrlProperties.java

@@ -0,0 +1,21 @@
+package com.uas.ps.properties;
+
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.stereotype.Component;
+
+/**
+ * Created by hulh on 2018/1/22.
+ */
+@Component
+@ConfigurationProperties(prefix = "url")
+public class UrlProperties {
+    private String b2cUrl;
+
+    public String getB2cUrl() {
+        return b2cUrl;
+    }
+
+    public void setB2cUrl(String b2cUrl) {
+        this.b2cUrl = b2cUrl;
+    }
+}

+ 2 - 1
src/main/resources/config/application-dev.properties

@@ -16,4 +16,5 @@ datasource.poolPreparedStatements=true
 datasource.timeBetweenLogStatsMillis=60000
 datasource.maxPoolPreparedStatementPerConnectionSize=20
 datasource.filters=stat,slf4j
-datasource.connectionProperties=druid.stat.mergeSql=false;druid.stat.slowSqlMillis=5000
+datasource.connectionProperties=druid.stat.mergeSql=false;druid.stat.slowSqlMillis=5000
+url.b2c-url=http://192.168.253.129:8080/platform-b2c