Commit 1aa037e4 LN

接口测试修改

1 个父辈 edd8a5ff
......@@ -6,31 +6,37 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.neotel.smfcore.common.exception.ApiException;
import com.neotel.smfcore.custom.micron1053.bean.MicronResult;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.config.CookieSpecs;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.TrustStrategy;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import org.apache.http.ssl.SSLContexts;
import org.apache.http.util.EntityUtils;
import org.apache.logging.log4j.util.Strings;
import org.springframework.util.CollectionUtils;
import javax.net.ssl.SSLContext;
import java.io.*;
import java.net.URI;
import java.net.URL;
import java.net.URLConnection;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.util.*;
import java.util.Map.Entry;
......@@ -152,6 +158,7 @@ public class HttpHelper {
public static String postJsonWithAuth(String url, Object params, String auth) throws ApiException {
HttpPost httpPost = new HttpPost(url);
httpPost.addHeader("Content-Type", "application/json;charset=utf-8");
if (auth != null && !auth.isEmpty()) {
httpPost.addHeader("Authorization", auth);
......@@ -162,14 +169,35 @@ public class HttpHelper {
ObjectMapper mapper = new ObjectMapper();
String requestBody = mapper.writeValueAsString(params);
httpPost.setEntity(new StringEntity(requestBody, CONTENT_CHARSET));
RequestConfig defaultConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.STANDARD).build();
httpPost.setConfig(defaultConfig);
} catch (JsonProcessingException e) {
throw new ApiException("Request params to [" + url + "] Json failed:" + e.getMessage());
log.error("Request params to [" + url + "] Json failed:" + e.getMessage());
throw new ApiException("smfcore.api.error","Request params to [" + url + "] Json failed:" + e.getMessage());
} catch (Exception e) {
throw new ApiException("Request params to [" + url + "] json exception:" + e.getMessage());
log.error("Request params to [" + url + "] json exception:" + e.getMessage());
throw new ApiException("smfcore.api.error","Request params to [" + url + "] json exception:" + e.getMessage());
}
}
try {
CloseableHttpClient httpClient = HttpClients.createDefault();
// try {
// CloseableHttpClient httpClient = HttpClients.createDefault();
// CloseableHttpResponse response = httpClient.execute(httpPost);
// HttpEntity entity = response.getEntity();
// String responseContent = EntityUtils.toString(entity, CONTENT_CHARSET);
// response.close();
// httpClient.close();
//
// log.info("postJsonWithAuth url=["+url+"] return= ["+responseContent+"]");
// return responseContent;
// } catch (Exception e) {
// log.error("Request to [" + url + "] failed:" + e.getMessage());
// throw new ApiException("Request to [" + url + "] failed:" + e.getMessage());
// }
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
try (CloseableHttpClient httpClient = httpClientBuilder.setSSLSocketFactory(getSslConnectionSocketFactory()).build()) {
CloseableHttpResponse response = httpClient.execute(httpPost);
HttpEntity entity = response.getEntity();
String responseContent = EntityUtils.toString(entity, CONTENT_CHARSET);
......@@ -179,8 +207,18 @@ public class HttpHelper {
log.info("postJsonWithAuth url=["+url+"] return= ["+responseContent+"]");
return responseContent;
} catch (Exception e) {
throw new ApiException("Request to [" + url + "] failed:" + e.getMessage());
log.error("Request to [" + url + "] failed:" + e.getMessage());
throw new ApiException("smfcore.api.error","Request to [" + url + "] failed:" + e.getMessage());
}
}/**
* 支持SSL
*
* @return SSLConnectionSocketFactory
*/
private static SSLConnectionSocketFactory getSslConnectionSocketFactory() throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
TrustStrategy acceptingTrustStrategy = (x509Certificates, s) -> true;
SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(null, acceptingTrustStrategy).build();
return new SSLConnectionSocketFactory(sslContext, new NoopHostnameVerifier());
}
/**
......
......@@ -161,12 +161,21 @@ public class Micron20031Api {
@Value("${micron.getTokenUrl:}")
public void seturl_GetToken(String url_getToken) {
public void setUrl_GetToken(String url_getToken) {
Micron20031Api.url_getToken = url_getToken;
}
private static String AUTH_TOKEN = "";
private static String api_AUTH_TOKEN = "Bearer 0f1a4408-7235-3f01-b671-f71491dc6bfa";
@Value("${micron.defToken:Bearer 0f1a4408-7235-3f01-b671-f71491dc6bfa}")
public void setApi_AUTH_TOKEN(String config) {
if(ObjectUtil.isNotEmpty(config)) {
Micron20031Api.api_AUTH_TOKEN = config;
}
}
private static String MATERIAL_TYPE = "SOLDER_PASTE";
......@@ -193,9 +202,14 @@ public class Micron20031Api {
public static String getAuthToken(){
String url = "https://boapi3testgtwy.micron.com/token";
if(ObjectUtil.isNotEmpty(url_getToken)){
url=url_getToken;
url=url_getToken;
if(ObjectUtil.isEmpty(url_getToken)){
//直接返回默认的token
return api_AUTH_TOKEN;
// url=url_getToken;
}
try {
Map<String,Object> dataMap = new HashMap<>();
dataMap.put("grant_type","client_credentials");
......@@ -208,9 +222,9 @@ public class Micron20031Api {
Object MaterialType = resultMap.get("MaterialType");
Object Message = resultMap.get("Message");
Object Status = resultMap.get("Status");
AUTH_TOKEN = "Bearer 03400c52-9b1d-3e10-b40c-a95fbfdcec67";
return AUTH_TOKEN;
api_AUTH_TOKEN="Bearer 0f1a4408-7235-3f01-b671-f71491dc6bfa";
// AUTH_TOKEN = "Bearer 03400c52-9b1d-3e10-b40c-a95fbfdcec67";
return api_AUTH_TOKEN;
} catch (ApiException e) {
log.error("checkUserRights Error", e);
......@@ -286,13 +300,22 @@ public class Micron20031Api {
log.info("调用MES接口 checkStockAvailable,参数:"+JsonUtil.toJsonStr(paramList));
String resultStr = HttpHelper.postJsonWithAuth(checkStockAvailableUrl, paramList, auth);
log.info("调用MES接口 checkStockAvailable 返回:" + resultStr);
List<MatOrderBean> orderBeanList = JsonUtil.toList(resultStr,MatOrderBean.class);
for (MatOrderBean matOrderBean : orderBeanList) {
Integer qty = pnMap.get(matOrderBean.getMicronPN());
if(qty != null){
matOrderBean.setStockRoomQty(qty);
List<Object> materials= getResult(resultStr,"materials");
List<MatOrderBean> orderBeanList =new ArrayList<>();
if(materials!=null) {
for (Object object :
materials) {
String str = JsonUtil.toJsonStr(object);
MatOrderBean matOrderBean = (MatOrderBean) JsonUtil.toObj(str, MatOrderBean.class);
Integer qty = pnMap.get(matOrderBean.getMicronPN());
if (qty != null) {
matOrderBean.setStockRoomQty(qty);
}
orderBeanList.add(matOrderBean);
}
}
return orderBeanList;
}
......@@ -337,21 +360,31 @@ public class Micron20031Api {
*/
public static List<DepositMatReqBean> getMatReqDetail(String matReqNo) throws ApiException {
//pnMap的key为pn, value为库存数量
String getMatReqDetailUrl = getUrl(api_GetMatReqDetail);;
String getMatReqDetailUrl = getUrl(api_GetMatReqDetail);
;
String auth = getAuthToken();
Map<String, Object> dataMap = new HashMap<>();
dataMap.put("MatReqNo", matReqNo);
dataMap.put("MaterialType", MATERIAL_TYPE);
log.info("调用MES接口 getMatReqDetail,参数:" + JsonUtil.toJsonStr(dataMap));
log.info("调用MES接口 getMatReqDetail [" + getMatReqDetailUrl + "],参数:" + JsonUtil.toJsonStr(dataMap));
String resultStr = HttpHelper.postJsonWithAuth(getMatReqDetailUrl, dataMap, auth);
log.info("调用MES接口 getMatReqDetail 返回:" + resultStr);
Map<String, Object> resultMap = JsonUtil.toMap(resultStr);
if (ObjectUtil.isEmpty(resultStr)) {
throw new ApiException("smfcore.api.returnNoData", "getMatReqDetail Failed to get data", new String[]{"getMatReqDetail"});
}
// Map<String, Object> resultMap = JsonUtil.toMap(resultStr);
List<DepositMatReqBean> beans = new ArrayList<>();
if (resultMap.containsKey("materialDocList")) {
beans = (List<DepositMatReqBean>) resultMap.get("materialDocList");
List<Object> materialDocList = getResult(resultStr, "materialDocList");
if (materialDocList != null) {
for (Object obj :
materialDocList) {
String str = JsonUtil.toJsonStr(obj);
DepositMatReqBean bean = (DepositMatReqBean) JsonUtil.toObj(str, DepositMatReqBean.class);
beans.add(bean);
}
}
// DepositMatReqBean depositMatReqBean = JsonUtil.toObj(resultStr,DepositMatReqBean.class);
return beans;
}
......@@ -538,12 +571,17 @@ public class Micron20031Api {
log.info("调用MES接口 GetEquipIDList,参数:"+JsonUtil.toJsonStr(dataMap));
String resultStr = HttpHelper.postJsonWithAuth(checkStockAvailableUrl, dataMap, auth);
log.info("调用MES接口 GetEquipIDList 返回:" + resultStr);
List<Map<String,String>> equipList = getResult(resultStr,"equipList");
List<Object> equipList = getResult(resultStr,"equipList");
if(equipList != null){
List<Map<String,String>> listMap = (List<Map<String,String>>)equipList;
for (Map<String, String> eqiup : listMap) {
equipIdList.add(eqiup.get("equipId"));
for (Object obj :
equipList) {
String str = JsonUtil.toJsonStr(obj);
Map<String,Object> map= JsonUtil.toMap(str);
if(map.containsKey("equipId")){
equipIdList.add(map.get("equipId").toString());
}
}
}
return equipIdList;
}
......@@ -592,42 +630,55 @@ public class Micron20031Api {
*/
public static void chkAuthoriseToDispatch(Barcode barcode, String mode, String username) throws ApiException {
String checkStockAvailableUrl = getUrl(api_ChkAuthoriseToDispatch);
if(ObjectUtil.isEmpty(checkStockAvailableUrl)){
if (ObjectUtil.isEmpty(checkStockAvailableUrl)) {
return;
}
String auth = getAuthToken();
Map<String,Object> dataMap = new HashMap<>();
dataMap.put("MicronPN",barcode.getPartNumber());
dataMap.put("LotNo",barcode.getBarcode());
dataMap.put("BatchNo",barcode.getBatch());
dataMap.put("SpoolStatus","NEW");
dataMap.put("Quantity",barcode.getAmount());
dataMap.put("Mode",mode);
dataMap.put("Username",username);
dataMap.put("MaterialType",MATERIAL_TYPE);
Map<String, Object> dataMap = new HashMap<>();
dataMap.put("MicronPN", barcode.getPartNumber());
dataMap.put("LotNo", barcode.getBarcode());
dataMap.put("BatchNo", barcode.getBatch());
dataMap.put("SpoolStatus", "NEW");
dataMap.put("Quantity", barcode.getAmount());
dataMap.put("Mode", mode);
dataMap.put("Username", username);
dataMap.put("MaterialType", MATERIAL_TYPE);
log.info("调用MES接口 ChkAuthoriseToDispatch,参数:"+JsonUtil.toJsonStr(dataMap));
log.info("调用MES接口 ChkAuthoriseToDispatch,参数:" + JsonUtil.toJsonStr(dataMap));
String resultStr = HttpHelper.postJsonWithAuth(checkStockAvailableUrl, dataMap, auth);
log.info("调用MES接口 ChkAuthoriseToDispatch 返回:" + resultStr);
getResult(resultStr,null);
String result = getResult(resultStr, "MicronPN");
}
private static <T> T getResult(String resultJson, String key) throws ApiException {
if(ObjectUtil.isEmpty(resultJson)){
return null;
if (ObjectUtil.isEmpty(resultJson)) {
return null;
}
Map<String,Object> resultMap = JsonUtil.toMap(resultJson);
Map<String, Object> resultMap = JsonUtil.toMap(resultJson);
Object resultStatus = resultMap.get("Status");
if(resultStatus != null && !resultStatus.toString().equalsIgnoreCase("PASS")){
if (resultStatus != null && !resultStatus.toString().equalsIgnoreCase("PASS")) {
String msg = resultMap.get("Message").toString();
throw new ApiException(msg);
throw new ApiException("smfcore.api.error", msg);
}
if(key != null && !key.isEmpty()){
if (key != null && !key.isEmpty()) {
Object value = resultMap.get(key);
if(value != null){
if (value != null) {
return (T) value;
} else {
try {
char[] cs = key.toCharArray();
char c = cs[0];
cs[0] = Character.isUpperCase(c) ? Character.toLowerCase(c) : Character.toUpperCase(c);
String newKey = String.valueOf(cs);
value = resultMap.get(newKey);
if (value != null) {
return (T) value;
}
} catch (Exception ex) {
}
}
}
return null;
......@@ -671,9 +722,17 @@ public class Micron20031Api {
log.info("调用MES接口 ReturnMaterial,参数:"+JsonUtil.toJsonStr(dataMap));
String resultStr = HttpHelper.postJsonWithAuth(checkStockAvailableUrl, dataMap, auth);
log.info("调用MES接口 ReturnMaterial 返回:" + resultStr);
if(ObjectUtil.isEmpty(resultStr)){
log.info("调用MES接口 ReturnMaterial 返回:" + resultStr+" ,返回数据为空,return null ");
return null;
}
log.info("调用MES接口 ReturnMaterial 返回:" + resultStr);
String expiredDateStr = getResult(resultStr,"ExpiredDate");
Date expiredDate = DateUtil.toDate(expiredDateStr.toString(),"MM-dd-yyyy");
barcode.setExpireDate(expiredDate);
if(ObjectUtil.isNotEmpty(expiredDateStr)) {
Date expiredDate = DateUtil.toDate(expiredDateStr.toString(), "MM-dd-yyyy");
barcode.setExpireDate(expiredDate);
}
return barcode;
}
......
......@@ -69,7 +69,8 @@ public class MicronSpApiListener extends BaseSmfApiListener {
@Override
public boolean canLogin(String loginCheckUrl, String userName, String pwd) throws ValidateException {
try {
return Micron20031Api.checkUserRights(userName);
return true;
// return Micron20031Api.checkUserRights(userName);
}catch (ValidateException e){
throw e;
}
......
......@@ -58,6 +58,11 @@ public class MicronSpLoadController {
InList inList = inListCache.getInList(matReqNo);
if (inList == null) {
List<DepositMatReqBean> beans = Micron20031Api.getMatReqDetail(matReqNo);
if(beans==null|| beans.size()<=0){
return ResultBean.newErrorResult(1,"smfcore.api.nodata","Failed to get data");
}
inList = new InList();
inList.setName(matReqNo);
List<InListItem> items = new ArrayList<>();
......
......@@ -56,7 +56,9 @@ public class MicronSpOrderController {
}
try {
List<MatOrderBean> stockResults = Micron20031Api.checkStockAvailable(pnVMap);
if(stockResults==null|| stockResults.size()<=0){
return ResultBean.newErrorResult(1,"smfcore.api.nodata","Failed to get data");
}
for (MatOrderBean bean :
stockResults) {
OrderInfoDto orderInfoDto = new OrderInfoDto(bean.getMicronPN(), 0, bean.getQuantity(), bean.getUnitOfMeasures());
......
......@@ -18,22 +18,22 @@ public class DepositMatReqBean{
* * //Input: MatReqNo, MaterialType
* * //Output: MatReqNo, Micron Part Number, Lot No, Quantity, UnitOfMeasures, MaterialType, Message, Status
*/
@JsonProperty("MicronPN")
@JsonProperty("micronPN")
private String micronPN;
@JsonProperty("LotNo")
@JsonProperty("lotNo")
private String lotNo;
@JsonProperty("Quantity")
@JsonProperty("quantity")
private Integer quantity;
@JsonProperty("UnitOfMeasures")
@JsonProperty("unitOfMeasures")
private String unitOfMeasures;
@JsonProperty("MaterialType")
@JsonProperty("materialType")
private String materialType;
@JsonProperty("MatReqNo")
@JsonProperty("matReqNo")
private String matReqNo;
@JsonProperty("Message")
@JsonProperty("message")
private String message;
@JsonProperty("Status")
@JsonProperty("status")
private String status;
}
......@@ -10,22 +10,22 @@ import lombok.Data;
@Data
public class MatOrderBean{
@JsonProperty("MicronPN")
@JsonProperty("micronPn")
private String micronPN;
@JsonProperty("UnitOfMeasures")
@JsonProperty("unitOfMeasures")
private String unitOfMeasures;
@JsonProperty("Quantity")
@JsonProperty("quantity")
private Integer quantity;
@JsonProperty("MaterialType")
@JsonProperty("materialType")
private String materialType;
private Integer stockRoomQty;
@JsonProperty("MatReqNo")
@JsonProperty("matReqNo")
private String matReqNo;
@JsonProperty("Message")
@JsonProperty("message")
private String message;
@JsonProperty("Status")
@JsonProperty("status")
private String status;
}
micron:
apiAddr: https://testapigtwy.micron.com/t/app.mfg/mmsil/v1/DEVL/SINGAPORE/
api_CheckUserRights: CheckUserRights
api_CheckStockAvailable: CheckStockAvailable
api_TriggerMatReqOrder: TriggerMatReqOrder
api_GetMatReqDetail: GetMatReqDetail
api_DepositCreateMA: DepositCreateMA
api_SendEmail: SendEmail
api_MATrackOut: MATrackOut
api_GetEquipIDList: GetEquipIDList
api_GetMicronPN: GetMicronPN
api_ChkAuthoriseToDispatch: ChkAuthoriseToDispatch
api_ReturnMaterial: ReturnMaterial
defToken: Bearer 0f1a4408-7235-3f01-b671-f71491dc6bfa
# getTokenUrl: https://boapi3testgtwy.micron.com/token
email:
to:
cc:
api:
# name: 20031
# loginCheckUrl: https://testapigtwy.micron.com/t/app.mfg/mmsil/v1/DEVL/SINGAPORE/CheckUserRights
# 登录相关配置
login:
......
server:
port: 8800
micron:
apiAddr: https://testapigtwy.micron.com/t/app.mfg/mmsil/v1/DEVL/SINGAPORE/
api_CheckUserRights: CheckUserRights
api_CheckStockAvailable: CheckStockAvailable
api_TriggerMatReqOrder: TriggerMatReqOrder
api_GetMatReqDetail: GetMatReqDetail
api_DepositCreateMA: DepositCreateMA
api_SendEmail: SendEmail
api_MATrackOut: MATrackOut
api_GetEquipIDList: GetEquipIDList
api_GetMicronPN: GetMicronPN
api_ChkAuthoriseToDispatch: ChkAuthoriseToDispatch
api_ReturnMaterial: ReturnMaterial
defToken: Bearer 0f1a4408-7235-3f01-b671-f71491dc6bfa
# getTokenUrl: https://boapi3testgtwy.micron.com/token
email:
to:
cc:
api:
name:
inCheckUrl:
outNotifyUrl:
inNotifyUrl:
hella:
#host: 127.0.0.1
#port: 3333
# name: 20031
# loginCheckUrl: https://testapigtwy.micron.com/t/app.mfg/mmsil/v1/DEVL/SINGAPORE/CheckUserRights
# 文件存储路径
file:
mac: ~/file/
......@@ -41,7 +52,7 @@ rsa:
app:
version: '@app.version@'
version: '3.5.150623'
type: ""
menu:
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!