Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
孙克
/
smf-core
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit a666a8fe
由
LN
编写于
2022-12-13 15:41:08 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
增加micron接口
1 个父辈
09e6b345
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
143 行增加
和
0 行删除
src/main/java/com/neotel/smfcore/common/utils/HttpHelper.java
src/main/java/com/neotel/smfcore/custom/micron/bean/MaterialInfo.java
src/main/java/com/neotel/smfcore/custom/micron/bean/MicronResult.java
src/main/java/com/neotel/smfcore/custom/micron/controller/MicronApiController.java
src/main/java/com/neotel/smfcore/common/utils/HttpHelper.java
查看文件 @
a666a8f
...
...
@@ -3,6 +3,8 @@ package com.neotel.smfcore.common.utils;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.neotel.smfcore.common.exception.ApiException
;
import
com.neotel.smfcore.custom.micron.bean.MicronResult
;
import
io.swagger.annotations.Api
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.val
;
import
org.apache.http.HttpEntity
;
...
...
@@ -10,6 +12,7 @@ import org.apache.http.NameValuePair;
import
org.apache.http.client.HttpClient
;
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.entity.StringEntity
;
...
...
@@ -64,6 +67,37 @@ public class HttpHelper {
}
}
public
static
String
getJson
(
String
url
)
throws
ApiException
{
HttpGet
httpGet
=
new
HttpGet
(
url
);
httpGet
.
addHeader
(
"Content-Type"
,
"application/json;charset=utf-8"
);
// 设置请求参数
// if (params != null && !params.isEmpty()) {
// ObjectMapper mapper = new ObjectMapper();
// try {
// String requestBody = mapper.writeValueAsString(params);
// httpGet.set(new StringEntity(requestBody,CONTENT_CHARSET));
// } catch (JsonProcessingException e) {
// throw new ApiException("Request params to [" + url + "] failed:" + e.getMessage());
// } catch (Exception e) {
// throw new ApiException("Request params to [" + url + "] failed:" + e.getMessage());
// }
// }
try
{
CloseableHttpClient
httpClient
=
HttpClients
.
createDefault
();
CloseableHttpResponse
response
=
httpClient
.
execute
(
httpGet
);
int
code
=
response
.
getStatusLine
().
getStatusCode
();
//System.out.println(response.getStatusLine().getStatusCode() + "\n");
HttpEntity
entity
=
response
.
getEntity
();
String
responseContent
=
EntityUtils
.
toString
(
entity
,
CONTENT_CHARSET
);
response
.
close
();
httpClient
.
close
();
return
responseContent
;
}
catch
(
Exception
e
){
throw
new
ApiException
(
"Request to ["
+
url
+
"] failed:"
+
e
.
getMessage
());
}
}
/**
* 向指定URL发送POST请求
...
...
@@ -108,6 +142,44 @@ public class HttpHelper {
}
}
public
static
MicronResult
getMicronJson
(
String
url
)
throws
ApiException
{
HttpGet
httpGet
=
new
HttpGet
(
url
);
httpGet
.
addHeader
(
"Content-Type"
,
"application/json;charset=utf-8"
);
// 设置请求参数
try
{
CloseableHttpClient
httpClient
=
HttpClients
.
createDefault
();
CloseableHttpResponse
response
=
httpClient
.
execute
(
httpGet
);
int
code
=
response
.
getStatusLine
().
getStatusCode
();
//System.out.println(response.getStatusLine().getStatusCode() + "\n");
HttpEntity
entity
=
response
.
getEntity
();
String
responseContent
=
EntityUtils
.
toString
(
entity
,
CONTENT_CHARSET
);
MicronResult
result
=
JsonUtil
.
toObj
(
responseContent
,
MicronResult
.
class
);
if
(
result
==
null
)
{
result
=
new
MicronResult
();
}
result
.
setHttpCode
(
code
);
response
.
close
();
httpClient
.
close
();
return
result
;
}
catch
(
Exception
e
)
{
throw
new
ApiException
(
"Request to ["
+
url
+
"] failed:"
+
e
.
getMessage
());
}
}
public
static
MicronResult
postMicronJson
(
String
url
,
Map
<
String
,
Object
>
params
)
throws
ApiException
{
try
{
String
responseContent
=
postJson
(
url
,
params
);
MicronResult
result
=
JsonUtil
.
toObj
(
responseContent
,
MicronResult
.
class
);
if
(
result
==
null
)
{
result
=
new
MicronResult
();
}
return
result
;
}
catch
(
Exception
e
)
{
throw
new
ApiException
(
"Request to ["
+
url
+
"] failed:"
+
e
.
getMessage
());
}
}
}
src/main/java/com/neotel/smfcore/custom/micron/bean/MaterialInfo.java
0 → 100644
查看文件 @
a666a8f
package
com
.
neotel
.
smfcore
.
custom
.
micron
.
bean
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
java.io.Serializable
;
@Data
@Slf4j
@AllArgsConstructor
@NoArgsConstructor
public
class
MaterialInfo
implements
Serializable
{
// "Label2DID": "<Label2DID>",
// "TowerID": "<TowerID>|null",
// "StorageBin": "<StorageBin>|null",
// "Qty": "<Label Qty>|<X-Ray Qty>",
// "X-RayCheck": "Yes|No|N/A",
// "ErrorCode": "0-Success|1-Rejected",
// "ErrorMessage": "N/A|<ErrorMessage>"
private
String
Label2DID
;
private
String
TowerID
;
private
String
StorageBin
;
private
Integer
Qty
;
private
String
XRayCheck
;
private
String
ErrorCode
;
private
String
ErrorMessage
;
// "Label2DID": "<Label2DID>",
// "FromTowerID": "<TowerID>",
// "FromStorageBin": "<StorageBin>",
// "Qty": "<Qty>",
private
String
FromTowerID
;
private
String
FromStorageBin
;
}
src/main/java/com/neotel/smfcore/custom/micron/bean/MicronResult.java
0 → 100644
查看文件 @
a666a8f
package
com
.
neotel
.
smfcore
.
custom
.
micron
.
bean
;
import
cn.hutool.core.util.ObjectUtil
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
java.io.Serializable
;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Slf4j
public
class
MicronResult
implements
Serializable
{
// {
// Status : <Success|Fail>
// Message : <Error Message>
// }
private
Integer
httpCode
=
0
;
private
String
status
;
private
String
message
;
public
boolean
isSuccess
()
{
if
(
ObjectUtil
.
isNotEmpty
(
status
)
&&
status
.
equals
(
"Success"
))
{
return
true
;
}
return
false
;
}
}
src/main/java/com/neotel/smfcore/custom/micron/controller/MicronApiController.java
0 → 100644
查看文件 @
a666a8f
此文件的差异被折叠,
点击展开。
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论