|
|
@@ -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;
|
|
|
+ }
|
|
|
}
|