Browse Source

【奥维-赛力斯】

DINGYL 2 weeks ago
parent
commit
238f4752f6

+ 26 - 3
src/main/java/com/uas/eis/controller/SERESController.java

@@ -2,6 +2,11 @@ package com.uas.eis.controller;
 
 import com.uas.eis.core.config.SpObserver;
 import com.uas.eis.service.SERESService;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.EntityUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
@@ -26,7 +31,8 @@ public class SERESController {
     public Map<String, Object> getStock() throws IOException {
         SpObserver.putSp("AW_ZHJK");
         Map<String, Object> modelMap = new HashMap<String, Object>();
-        seresService.getToken();
+        String token=seresService.getToken();
+        modelMap.put("token",token);
         return modelMap;
     }
 
@@ -57,9 +63,26 @@ public class SERESController {
 
     @PostMapping("/erp/ZHJK/test")
     @ResponseBody
-    public Map<String, Object> test() throws Exception {
+    public Map<String, Object> test(@RequestBody String token) throws Exception {
         SpObserver.putSp("AW_ZHJK");
-        Map<String, Object> modelMap = seresService.test();
+        Map<String, Object> modelMap = seresService.test(token);
+        return modelMap;
+    }
+
+    @PostMapping("/erp/ZHJK/testToken")
+    @ResponseBody
+    public Map<String, Object> testToken() throws Exception {
+        Map<String, Object> modelMap =  new HashMap<String, Object>();
+                seresService.testToken();
+        modelMap.put("success", true);
+        return modelMap;
+    }
+
+    @PostMapping("/erp/ZHJK/testGetStock")
+    @ResponseBody
+    public Map<String, Object> testGetStock(@RequestBody String token) throws Exception {
+        Map<String, Object> modelMap =seresService.testGetStock(token);
+        modelMap.put("success", true);
         return modelMap;
     }
 

+ 18 - 0
src/main/java/com/uas/eis/entity/InventoryData.java

@@ -0,0 +1,18 @@
+package com.uas.eis.entity;
+
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class InventoryData {
+    /**
+     * 库存数据总条数
+     */
+    private Integer totalCount;
+
+    /**
+     * 库存数据列表集合
+     */
+    private List<InventoryItem> list;
+}

+ 126 - 0
src/main/java/com/uas/eis/entity/InventoryItem.java

@@ -0,0 +1,126 @@
+package com.uas.eis.entity;
+
+import lombok.Data;
+
+@Data
+public class InventoryItem {
+            /**
+             * 数据行序号
+             */
+            private Integer SerialNumber;
+
+            /**
+             * 库存所属工厂编码
+             */
+            private String FactoryCode;
+
+            /**
+             * 供应商唯一编码
+             */
+            private String SupplierCode;
+
+            /**
+             * 供应商名称
+             */
+            private String SupplierName;
+
+            /**
+             * 赛力斯侧的物料编码
+             */
+            private String MaterialCode;
+
+            /**
+             * 赛力斯侧的物料名称
+             */
+            private String MaterialName;
+
+            /**
+             * 工厂内合格库存(RDC+LOC)
+             */
+            private java.math.BigDecimal RDCLOCQualifiedStock;
+
+            /**
+             * 试制/变更/其他用途的合格库存
+             */
+            private java.math.BigDecimal InPlantQualifiedStock;
+
+            /**
+             * 线边可用的合格库存
+             */
+            private java.math.BigDecimal LineSideQualifiedStock;
+
+            /**
+             * 工厂内的不合格库存
+             */
+            private java.math.BigDecimal InPlantNonQualifiedStock;
+
+            /**
+             * VMI仓合格库存(RDC+LOC)
+             */
+            private java.math.BigDecimal VMIQualifiedStock;
+
+            /**
+             * VMI仓不合格库存
+             */
+            private java.math.BigDecimal VMINonQualifiedStock;
+
+            /**
+             * 工厂内待检库存
+             */
+            private java.math.BigDecimal PendingInspectionStock;
+
+            /**
+             * 工厂内冻结库存
+             */
+            private java.math.BigDecimal FrozenStock;
+
+            /**
+             * 堆场库存
+             */
+            private java.math.BigDecimal ContainerYardStock;
+
+            /**
+             * SCM系统中采购申请在途库存
+             */
+            private java.math.BigDecimal PRTransitStock;
+
+            /**
+             * SCM系统中采购订单在途库存
+             */
+            private java.math.BigDecimal POTransitStock;
+
+            /**
+             * SCM系统中POI拉动在途库存
+             */
+            private java.math.BigDecimal POITransitStock;
+
+            /**
+             * 可用库存小计
+             */
+            private java.math.BigDecimal AvailableStock;
+
+            /**
+             * 预留字段1
+             */
+            private String Attribute1;
+
+            /**
+             * 预留字段2
+             */
+            private String Attribute2;
+
+            /**
+             * 预留字段3
+             */
+            private String Attribute3;
+
+            /**
+             * 预留字段4
+             */
+            private String Attribute4;
+
+            /**
+             * 预留字段5
+             */
+            private String Attribute5;
+}

+ 26 - 0
src/main/java/com/uas/eis/entity/InventoryQueryResponse.java

@@ -0,0 +1,26 @@
+package com.uas.eis.entity;
+
+import lombok.Data;
+
+@Data
+public class InventoryQueryResponse {
+    /**
+     * 响应编码:0-成功 1-失败
+     */
+    private String code;
+
+    /**
+     * 响应信息
+     */
+    private String message;
+
+    /**
+     * 数据总数
+     */
+    private Integer counts;
+    /**
+     * 响应数据对象
+     */
+
+    private InventoryData data;
+}

+ 4 - 2
src/main/java/com/uas/eis/service/SERESService.java

@@ -7,7 +7,9 @@ import java.util.Map;
 public interface SERESService {
     Map<String,Object> getStock() throws IOException;
     Map<String,Object> getERPStock(String param) ;
-    void getToken() throws IOException;
+    String  getToken() throws IOException;
     Map<String,Object> saveAlert(String data) ;
-    Map<String,Object> test() throws Exception;
+    Map<String,Object> test(String token) throws Exception;
+    void testToken() throws IOException;
+    Map<String,Object> testGetStock(String token) throws Exception;
 }

+ 83 - 4
src/main/java/com/uas/eis/serviceImpl/SERESServiceImpl.java

@@ -8,6 +8,7 @@ import com.uas.eis.core.config.SeresConfig;
 import com.uas.eis.core.config.SpObserver;
 import com.uas.eis.dao.BaseDao;
 import com.uas.eis.dao.SqlRowList;
+import com.uas.eis.entity.InventoryQueryResponse;
 import com.uas.eis.entity.SeresStock;
 import com.uas.eis.entity.SeresStockDet;
 import com.uas.eis.service.SERESService;
@@ -21,7 +22,12 @@ import org.apache.http.util.EntityUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.MediaType;
 import org.springframework.stereotype.Service;
+import org.springframework.web.client.RestTemplate;
 
 
 import java.io.IOException;
@@ -33,6 +39,8 @@ public class SERESServiceImpl implements SERESService {
     private SeresConfig seresConfig;
     @Autowired
     private BaseDao baseDao;
+    @Autowired
+    private RestTemplate restTemplate;
 
     private final Logger logger = LoggerFactory.getLogger(this.getClass());
 
@@ -199,9 +207,10 @@ public class SERESServiceImpl implements SERESService {
     }
 
     @Override
-    public void getToken() throws IOException {
+    public String getToken() throws IOException {
         String token=getValidToken();
         logger.info("当前token {}",token);
+        return  token;
     }
 
     @Override
@@ -236,9 +245,8 @@ public class SERESServiceImpl implements SERESService {
     }
 
     @Override
-    public Map<String, Object> test() throws Exception {
+    public Map<String, Object> test(String token) throws Exception {
         Map<String, Object> modelMap = new HashMap<String, Object>();
-        String token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE3ODQwMTIzOTAsImlhdCI6MTc4NDAxMjM5MSwiaXNzIjoiMDAwMDAwMjQ0Ni1KVFRLSE9ONCIsImV4cCI6MTc4NDAxNTk4OS45NjN9.7hYCWCM22BJU6aNQfE2klllaTRwVnanBX-Tozt49WVg";
         String apiPath="/aito/DIS/INV_STOCK_STS/1.0.0";
         String fullUrl =  seresConfig.getUrl()  + apiPath;
         logger.info("fullUrl {}",fullUrl);
@@ -267,7 +275,7 @@ public class SERESServiceImpl implements SERESService {
             logger.info("reqBody {}", JSON.toJSONString(reqBody));
         }
         try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
-            logger.info("resp {}", response.getEntity());
+            logger.info("resp {}", response.getEntity().getContent());
             String respStr = EntityUtils.toString(response.getEntity(), "UTF-8");
             logger.info("respStr {}", respStr);
             return JSON.parseObject(respStr);
@@ -279,4 +287,75 @@ public class SERESServiceImpl implements SERESService {
             return modelMap;
         }
     }
+
+    @Override
+    public void testToken() throws IOException {
+        String token = getValidToken();
+        String fullUrl = "https://dis-api-test.seres.cn/aito/public/API_zsgsw/1.0.0";
+
+        CloseableHttpClient httpClient = HttpClients.createDefault();
+        HttpPost httpPost = new HttpPost(fullUrl);
+        // 鉴权头
+        httpPost.setHeader("Authorization", "Bearer " + token);
+        httpPost.setHeader("Content-Type", "application/json");
+
+        try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
+            String respStr = EntityUtils.toString(response.getEntity(), "UTF-8");
+            logger.info("resp {}", respStr);
+        } finally {
+            httpClient.close();
+        }
+    }
+    @Override
+    public Map<String, Object> testGetStock(String token) throws Exception {
+        logger.info("action :testGetStock");
+        Map<String, Object> modelMap =  new HashMap<String, Object>();
+
+        CloseableHttpClient httpClient = HttpClients.createDefault();
+        String apiPath="/aito/DIS/INV_STOCK_STS/1.0.0";
+        String fullUrl =  seresConfig.getUrl()  + apiPath;
+        HttpPost httpPost = new HttpPost(fullUrl);
+        logger.info("fullUrl {}",fullUrl);
+        HttpHeaders headers = new HttpHeaders();
+        headers.setContentType(MediaType.APPLICATION_JSON);
+        headers.set("Authorization", "Bearer " + token);
+        headers.set("SupplierCode", seresConfig.getClientCode());
+        JSONObject reqBody = new JSONObject();
+        //供应商编码
+        reqBody.put("SupplierCode", seresConfig.getClientCode());
+        //工厂编码
+        reqBody.put("FactoryCode", "");
+        //物料编码
+        reqBody.put("MaterialCode", "");
+        //页码
+        reqBody.put("Skip", 1);
+        //分页大小
+        reqBody.put("Take", 500);
+        if (reqBody != null) {
+            StringEntity entity = new StringEntity(JSON.toJSONString(reqBody), "UTF-8");
+            httpPost.setEntity(entity);
+
+            logger.info("reqBody {}", JSON.toJSONString(reqBody));
+        }
+        try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
+            String respJson = EntityUtils.toString(response.getEntity(), "UTF-8");
+            InventoryQueryResponse respObj = JSON.parseObject(respJson, InventoryQueryResponse.class);
+            logger.info("库存查询接口响应 code {} message {}", respObj.getCode(),respObj.getMessage());
+            modelMap.put("code",respObj.getCode());
+            modelMap.put("message",respObj.getMessage());
+            if(respObj.getData()!=null){
+                logger.info("库存查询接口响应 count {}", respObj.getData().getTotalCount());
+                if(respObj.getData().getList()!=null){
+                    modelMap.put("data",respObj.getData().getList());
+                    logger.info("库存查询接口响应 list size {}", respObj.getData().getList().size());
+                    if(respObj.getData().getList().size()>0){
+                        logger.info("库存查询接口响应 list size {}", respObj.getData().getList().get(0).toString());
+                    }
+                }
+            }
+        } finally {
+            httpClient.close();
+        }
+        return modelMap;
+    }
 }