Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
孙克
/
smf-core
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit a666a8fe
由
LN
编写于
2022-12-13 15:41:08 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
增加micron接口
1 个父辈
09e6b345
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
425 行增加
和
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
package
com
.
neotel
.
smfcore
.
custom
.
micron
.
controller
;
import
com.google.common.base.Strings
;
import
com.google.common.collect.Lists
;
import
com.google.common.collect.Maps
;
import
com.neotel.smfcore.common.utils.HttpHelper
;
import
com.neotel.smfcore.core.api.listener.BaseSmfApiListener
;
import
com.neotel.smfcore.core.barcode.service.po.Barcode
;
import
com.neotel.smfcore.core.storage.service.manager.IStoragePosManager
;
import
com.neotel.smfcore.core.storage.service.po.Storage
;
import
com.neotel.smfcore.core.storage.service.po.StoragePos
;
import
com.neotel.smfcore.custom.micron.bean.MaterialInfo
;
import
com.neotel.smfcore.custom.micron.bean.MicronResult
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
java.util.Collection
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
@Controller
@RequestMapping
(
"/rest/api"
)
@Slf4j
public
class
MicronApiController
extends
BaseSmfApiListener
{
@Autowired
private
IStoragePosManager
storagePosManager
;
@RequestMapping
(
value
=
"/inventory-report"
)
@ResponseBody
public
Map
<
String
,
Object
>
inventoryReport
(
@RequestBody
Map
<
String
,
String
>
map
)
{
Map
<
String
,
Object
>
result
=
new
HashMap
<
String
,
Object
>();
try
{
String
TransactionID
=
map
.
get
(
"TransactionID"
);
String
TowerID
=
map
.
get
(
"TowerID"
);
log
.
info
(
"收到 PanaCIM 的getInventory 命令:TransactionID="
+
TransactionID
+
" TowerID="
+
TowerID
);
/**
* {
"ErrorCode":0,
"ReelBarCodes":
[{"JobID":"1234","Location":"0","Msd":false,"Msdlevel":"1","PartNo":"part123","Quantity":123,"ReelBarcode":"123456789","TowerID":"InoAuto A"},
{"JobID":"1234","Location":"0","Msd":false,"Msdlevel":"1","PartNo":"part321","Quantity":321,"ReelBarcode":"123456789","TowerID":"InoAuto B"},
{"JobID":"1234","Location":"0","Msd":false,"Msdlevel":"1","PartNo":"part213","Quantity":213,"ReelBarcode":"123456789","TowerID":"InoAuto C"}],
"TransactionID":"testme"
}
*/
Collection
<
Storage
>
allStorage
=
dataCache
.
getAllStorage
().
values
();
List
<
Storage
>
storageList
=
Lists
.
newArrayList
();
if
(
Strings
.
isNullOrEmpty
(
TowerID
)){
storageList
.
addAll
(
allStorage
);
}
else
{
for
(
Storage
storage
:
allStorage
)
{
if
(
storage
.
getName
().
equals
(
TowerID
)){
storageList
.
add
(
storage
);
break
;
}
}
}
List
ReelBarCodes
=
Lists
.
newArrayList
();
for
(
Storage
storage
:
storageList
)
{
List
<
StoragePos
>
poses
=
storagePosManager
.
findNotEmptyByStorageId
(
storage
.
getId
());
for
(
StoragePos
pos
:
poses
){
Barcode
barcode
=
pos
.
getBarcode
();
Map
<
String
,
Object
>
item
=
Maps
.
newHashMap
();
item
.
put
(
"TowerID"
,
TowerID
);
item
.
put
(
"JobID"
,
barcode
.
getLockName
());
item
.
put
(
"ReelBarcode"
,
barcode
.
getBarcode
());
item
.
put
(
"PartNo"
,
barcode
.
getPartNumber
());
item
.
put
(
"Quantity"
,
barcode
.
getAmount
());
item
.
put
(
"Msd"
,
false
);
item
.
put
(
"msdlevel"
,
""
);
item
.
put
(
"Location"
,
"0"
);
ReelBarCodes
.
add
(
item
);
}
}
result
.
put
(
"TransactionID"
,
TransactionID
);
result
.
put
(
"ErrorCode"
,
"0"
);
result
.
put
(
"ReelBarCodes"
,
ReelBarCodes
);
}
catch
(
Exception
e
)
{
log
.
error
(
"PanaCIM的指令 getInventory 出错"
,
e
);
result
.
put
(
"ErrorCode"
,
"200"
);
}
return
result
;
}
@Override
public
boolean
isForThisApi
(
String
apiName
)
{
return
apiName
!=
null
&&
apiName
.
equalsIgnoreCase
(
"Micron"
);
}
private
String
getUrl
(
String
apiName
){
return
apiName
;
}
public
boolean
validateMRB
(
String
mbrId
,
boolean
skipSap
)
{
//Validate if MBR (From Warehouse ) is valid
String
skipSapStr
=
skipSap
?
"YES"
:
"NO"
;
String
url
=
getUrl
(
String
.
format
(
"validate/mrb/{0}/{1}"
,
mbrId
,
skipSap
));
try
{
MicronResult
result
=
HttpHelper
.
getMicronJson
(
url
);
if
(
result
!=
null
&&
result
.
isSuccess
())
{
return
true
;
}
}
catch
(
Exception
e
)
{
log
.
error
(
url
+
"出错"
,
e
);
}
return
false
;
}
public
boolean
validateREQ
(
String
reqId
)
{
//Validate if REQ (From Outside Shelf) is valid
String
url
=
getUrl
(
String
.
format
(
"validate/req/{0}"
,
reqId
));
try
{
MicronResult
result
=
HttpHelper
.
getMicronJson
(
url
);
if
(
result
!=
null
&&
result
.
isSuccess
())
{
return
true
;
}
}
catch
(
Exception
e
)
{
log
.
error
(
url
+
"出错"
,
e
);
}
return
false
;
}
public
boolean
validateMCL
(
String
PurchaseOrder
,
String
PackagingSlip
,
boolean
skipSap
)
{
//Validate if MCL GR is valid
//validate/mcl/{PurchaseOrder}/{PackagingSlip}/{SkipSap}
// {PurchaseOrder}=<purchase order>,
// {PackagingSlip}=<packaging slide>,
// {SkipSAP}="YES|No"
String
skipSapStr
=
skipSap
?
"YES"
:
"NO"
;
String
url
=
getUrl
(
String
.
format
(
"validate/mcl/{0}/{1}/{2}"
,
PurchaseOrder
,
PackagingSlip
,
skipSapStr
));
try
{
MicronResult
result
=
HttpHelper
.
getMicronJson
(
url
);
if
(
result
!=
null
&&
result
.
isSuccess
())
{
return
true
;
}
}
catch
(
Exception
e
)
{
log
.
error
(
url
+
"出错"
,
e
);
}
return
false
;
}
public
boolean
validateMaterial
(
String
Label2DID
,
String
LoadingMode
)
{
//Validate the material before loading into the storage bin
//validate/material
// {
// "Label2DID" : "<2DID String that contains SAP P/N; S/N; Supplier..etc>",
// "LoadingMode" : "MBR|REQ|GR|MCL|RET|NPI"
// }
String
url
=
getUrl
(
String
.
format
(
"validate/material"
));
Map
<
String
,
Object
>
dataMap
=
new
HashMap
<
String
,
Object
>();
dataMap
.
put
(
"Label2DID"
,
Label2DID
);
dataMap
.
put
(
"LoadingMode"
,
LoadingMode
);
try
{
MicronResult
result
=
HttpHelper
.
postMicronJson
(
url
,
dataMap
);
if
(
result
!=
null
&&
result
.
isSuccess
())
{
return
true
;
}
}
catch
(
Exception
e
)
{
log
.
error
(
url
+
"出错"
,
e
);
}
return
false
;
}
public
boolean
loadReport
(
String
JobId
,
MaterialInfo
[]
materialInfos
)
{
//Update material storage location at rod or magazine slot level (One JobID per rod or slot).
//load-report
// {
// "JobId": "<job Id>",
// "Materials": [
// {
// "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>"
// }
//]
// }
String
url
=
getUrl
(
String
.
format
(
"load-report"
));
Map
<
String
,
Object
>
dataMap
=
new
HashMap
<
String
,
Object
>();
dataMap
.
put
(
"JobId"
,
JobId
);
dataMap
.
put
(
"Materials"
,
materialInfos
);
try
{
MicronResult
result
=
HttpHelper
.
postMicronJson
(
url
,
dataMap
);
if
(
result
!=
null
&&
result
.
isSuccess
())
{
return
true
;
}
}
catch
(
Exception
e
)
{
log
.
error
(
url
+
"出错"
,
e
);
}
return
false
;
}
public
boolean
dispatchList
(
String
Facility
,
String
DispatchType
)
{
//Get ready Pretask/LinePrep/RET list from Auto Kitting System
//dispatch-list/{Facility}/{DispatchType}
// {Facility} = "Grouping that need to align with KitView"
// {DispatchType}="PreTask|LinePrep|RET"
String
url
=
getUrl
(
String
.
format
(
"dispatch-list/{0}/{1}"
,
Facility
,
DispatchType
));
try
{
MicronResult
result
=
HttpHelper
.
getMicronJson
(
url
);
if
(
result
!=
null
&&
result
.
isSuccess
())
{
return
true
;
}
}
catch
(
Exception
e
)
{
log
.
error
(
url
+
"出错"
,
e
);
}
return
false
;
}
public
boolean
dispatchMaterial
(
String
DispatchType
,
String
Id
)
{
//Get dispatch Material list from Autokitting system to fullfil the Pretask or LinePrep
//dispatch-material/{DispatchType}/{Id}
// {DispatchType}="PreTask|LinePrep|RET"
// Id="<PretaskId>|<LinePrepId>|<RetId>"
String
url
=
getUrl
(
String
.
format
(
"dispatch-material/{0}/{1}"
,
DispatchType
,
Id
));
try
{
MicronResult
result
=
HttpHelper
.
getMicronJson
(
url
);
if
(
result
!=
null
&&
result
.
isSuccess
())
{
return
true
;
}
}
catch
(
Exception
e
)
{
log
.
error
(
url
+
"出错"
,
e
);
}
return
false
;
}
public
boolean
dispatchReport
(
String
JobId
,
String
dispatchType
,
MaterialInfo
[]
materialInfos
)
{
//Update dispatch information by Job Level
//dispatch-report
// "JobId": "<JobId>",
// "DispatchType": "PreTask|LinePrep|RET|Warehouse|Controlled",
// "Materials": [
// {
// "Label2DID": "<Label2DID>",
// "FromTowerID": "<TowerID>",
// "FromStorageBin": "<StorageBin>",
// "Qty": "<Qty>",
// }
//]
String
url
=
getUrl
(
String
.
format
(
"dispatch-report"
));
Map
<
String
,
Object
>
dataMap
=
new
HashMap
<
String
,
Object
>();
dataMap
.
put
(
"JobId"
,
JobId
);
dataMap
.
put
(
"DispatchType"
,
dispatchType
);
dataMap
.
put
(
"Materials"
,
materialInfos
);
try
{
MicronResult
result
=
HttpHelper
.
postMicronJson
(
url
,
dataMap
);
if
(
result
!=
null
&&
result
.
isSuccess
())
{
return
true
;
}
}
catch
(
Exception
e
)
{
log
.
error
(
url
+
"出错"
,
e
);
}
return
false
;
}
}
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论