Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
孙克
/
smf-core
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit 13048cf2
由
LN
编写于
2025-06-27 20:42:06 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
中车1568锡膏料仓对接
1 个父辈
f658cf32
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
359 行增加
和
0 行删除
src/main/java/com/neotel/smfcore/custom/zhongcheSp1568/ZhongCheSPApi.java
src/main/java/com/neotel/smfcore/custom/zhongcheSp1568/ZhongCheSPApi.java
0 → 100644
查看文件 @
13048cf
package
com
.
neotel
.
smfcore
.
custom
.
zhongcheSp1568
;
import
cn.hutool.core.util.ObjectUtil
;
import
com.neotel.smfcore.common.exception.ApiException
;
import
com.neotel.smfcore.common.exception.ValidateException
;
import
com.neotel.smfcore.common.utils.DateUtil
;
import
com.neotel.smfcore.common.utils.HttpHelper
;
import
com.neotel.smfcore.common.utils.JsonUtil
;
import
com.neotel.smfcore.core.api.bean.CodeValidateParam
;
import
com.neotel.smfcore.core.api.listener.BaseSmfApiListener
;
import
com.neotel.smfcore.core.barcode.service.manager.IBarcodeManager
;
import
com.neotel.smfcore.core.barcode.service.manager.IComponentManager
;
import
com.neotel.smfcore.core.barcode.service.po.Barcode
;
import
com.neotel.smfcore.core.barcode.service.po.Component
;
import
com.neotel.smfcore.core.storage.service.manager.IStoragePosManager
;
import
com.neotel.smfcore.core.storage.service.po.StoragePos
;
import
com.neotel.smfcore.core.system.service.po.DataLog
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
@Service
@Slf4j
public
class
ZhongCheSPApi
extends
BaseSmfApiListener
{
@Autowired
private
IStoragePosManager
storagePosManager
;
@Autowired
private
IComponentManager
componentManager
;
@Autowired
private
IBarcodeManager
barcodeManager
;
// api:
// name: sp1568
// inCheckUrl: http://ip:port/ims-integrate/api/getImsData
// outNotifyUrl: http://ip:port/ims-integrate/api/updateImsData
// inNotifyUrl: http://ip:port/ims-integrate/api/updateImsData
// taskNotifyUrl: http://ip:port/ims-integrate/api/updateImsData
@Override
public
boolean
isForThisApi
(
String
apiName
)
{
return
apiName
!=
null
&&
apiName
.
equalsIgnoreCase
(
"sp1568"
);
}
@Override
public
Barcode
canPutInAfterResolve
(
String
inCheckUrl
,
CodeValidateParam
params
,
Barcode
barcode
)
throws
ValidateException
{
if
(
ObjectUtil
.
isEmpty
(
inCheckUrl
)
||
barcode
==
null
||
ObjectUtil
.
isEmpty
(
barcode
.
getPartNumber
()))
{
return
barcode
;
}
// {
// "docType": "GET_MES_SR_MSG",
// "condition": [
// {
// "columnName": "mtrl_code",
// "symbol": "eq",
// "value": "prod_code001"
// }
// ]
// }
//
// {
// "resultCode": "0000",
// "resultMsg": "",
// "resultData": [
// {
// "mtrl_code": "MAT20250001",
// "org_code": "ORG1001",
// "sr_type": 1,
// "temp_dpart": 24,
// "temp_times": 3,
// "temp_over_dpart": 30,
// "temp_over_dpart_type": 2,
// "stir_dpart": 5,
// "vi_l_lim": 100,
// "vi_h_lim": 200,
// "open_dpart": 8,
// "cool_dpart": 60,
// "src_model": 1,
// "must_stir_dpart": 15
// }
// ]
// }
try
{
// 构建请求数据
Map
<
String
,
Object
>
request
=
new
HashMap
<>();
request
.
put
(
"docType"
,
"GET_MES_SR_MSG"
);
// 构建查询条件
List
<
Map
<
String
,
Object
>>
conditionList
=
new
ArrayList
<>();
Map
<
String
,
Object
>
condition
=
new
HashMap
<>();
condition
.
put
(
"columnName"
,
"mtrl_code"
);
condition
.
put
(
"symbol"
,
"eq"
);
condition
.
put
(
"value"
,
barcode
.
getPartNumber
());
conditionList
.
add
(
condition
);
request
.
put
(
"condition"
,
conditionList
);
log
.
info
(
"canPutInAfterResolve, url="
+
inCheckUrl
+
",发送数据="
+
JsonUtil
.
toJsonStr
(
request
));
String
result
=
HttpHelper
.
postJson
(
inCheckUrl
,
request
);
log
.
info
(
"canPutInAfterResolve, url="
+
inCheckUrl
+
",收到数据="
+
result
);
// 解析响应
Map
<
String
,
Object
>
response
=
JsonUtil
.
toMap
(
result
);
if
(
response
!=
null
)
{
String
resultCode
=
(
String
)
response
.
get
(
"resultCode"
);
if
(
"0000"
.
equals
(
resultCode
))
{
Object
resultDataObj
=
response
.
get
(
"resultData"
);
if
(
resultDataObj
instanceof
List
)
{
List
<
Object
>
resultDataList
=
(
List
<
Object
>)
resultDataObj
;
if
(!
resultDataList
.
isEmpty
())
{
Map
<
String
,
Object
>
materialData
=
(
Map
<
String
,
Object
>)
resultDataList
.
get
(
0
);
// 保存物料配置信息到component
// 锡膏类型
String
pn
=
materialData
.
get
(
"sr_type"
).
toString
();
if
(
ObjectUtil
.
isEmpty
(
pn
))
{
log
.
error
(
"canPutInAfterResolve 失败,resultCode: "
+
resultCode
+
", sr_type为空: "
);
throw
new
ValidateException
(
"smfcore.mesApi.inCheck.error"
,
"MES查询失败["
+
resultCode
+
"]: sr_type为空"
);
}
if
(
barcode
.
getPartNumber
()!=
pn
){
barcode
.
setPartNumber
(
pn
);
barcodeManager
.
save
(
barcode
);
}
// 根据物料编码查找或创建Component
Component
component
=
componentManager
.
findOneByPN
(
barcode
.
getPartNumber
());
if
(
component
==
null
)
{
// 如果未找到,创建新的Component
component
=
new
Component
();
component
.
setPartNumber
(
barcode
.
getPartNumber
());
component
.
setName
(
barcode
.
getPartNumber
());
// 使用物料编码作为名称
component
.
setAmount
(
1
);
log
.
info
(
"创建新的Component,物料编码: "
+
barcode
.
getPartNumber
());
}
// 回温时间(小时)
Object
tempDpart
=
materialData
.
get
(
"temp_dpart"
);
if
(
tempDpart
!=
null
)
{
int
warmTimeHours
=
Integer
.
parseInt
(
tempDpart
.
toString
());
component
.
setWarmTime
(
warmTimeHours
*
60
);
// 转换为分钟保存
// component.updateAppendData("temp_dpart", tempDpart.toString());
}
// 回温超时(分钟)
Object
tempOverDpart
=
materialData
.
get
(
"temp_over_dpart"
);
if
(
tempOverDpart
!=
null
)
{
component
.
updateAppendData
(
"temp_over_dpart"
,
tempOverDpart
.
toString
());
}
// 搅拌时间(分钟)
Object
stirDpart
=
materialData
.
get
(
"stir_dpart"
);
if
(
stirDpart
!=
null
)
{
int
mixTimeMinutes
=
Integer
.
parseInt
(
stirDpart
.
toString
());
component
.
setMixTime
(
mixTimeMinutes
*
60
);
// 转换为秒保存
component
.
updateAppendData
(
"stir_dpart"
,
stirDpart
.
toString
());
}
// 最小冷冻时间(分钟)
Object
coolDpart
=
materialData
.
get
(
"cool_dpart"
);
if
(
coolDpart
!=
null
)
{
component
.
updateAppendData
(
"cool_dpart"
,
coolDpart
.
toString
());
}
// 保存其他可能有用的配置信息
Object
tempTimes
=
materialData
.
get
(
"temp_times"
);
if
(
tempTimes
!=
null
)
{
component
.
updateAppendData
(
"temp_times"
,
tempTimes
.
toString
());
}
Object
viLLim
=
materialData
.
get
(
"vi_l_lim"
);
if
(
viLLim
!=
null
)
{
component
.
updateAppendData
(
"vi_l_lim"
,
viLLim
.
toString
());
}
Object
viHLim
=
materialData
.
get
(
"vi_h_lim"
);
if
(
viHLim
!=
null
)
{
component
.
updateAppendData
(
"vi_h_lim"
,
viHLim
.
toString
());
}
Object
openDpart
=
materialData
.
get
(
"open_dpart"
);
if
(
openDpart
!=
null
)
{
component
.
updateAppendData
(
"open_dpart"
,
openDpart
.
toString
());
}
Object
srcModel
=
materialData
.
get
(
"src_model"
);
if
(
srcModel
!=
null
)
{
component
.
updateAppendData
(
"src_model"
,
srcModel
.
toString
());
}
Object
mustStirDpart
=
materialData
.
get
(
"must_stir_dpart"
);
if
(
mustStirDpart
!=
null
)
{
component
.
updateAppendData
(
"must_stir_dpart"
,
mustStirDpart
.
toString
());
}
// 保存Component到数据库
component
=
componentManager
.
save
(
component
);
log
.
info
(
"canPutInAfterResolve 成功获取并保存物料配置到Component,物料编码: "
+
barcode
.
getPartNumber
()+
",回温时间="
+
component
.
getWarmTime
()+
",搅拌时间="
+
component
.
getMixTime
());
}
}
return
barcode
;
}
else
{
String
resultMsg
=
(
String
)
response
.
get
(
"resultMsg"
);
log
.
error
(
"canPutInAfterResolve 失败,resultCode: "
+
resultCode
+
", resultMsg: "
+
resultMsg
);
throw
new
ValidateException
(
"smfcore.mesApi.inCheck.error"
,
"MES查询失败["
+
resultCode
+
"]:"
+
resultMsg
);
}
}
else
{
log
.
error
(
"canPutInAfterResolve 响应解析失败"
);
throw
new
ValidateException
(
"smfcore.mesApi.inCheck.error"
,
"MES响应解析失败"
);
}
}
catch
(
ApiException
apiException
)
{
log
.
error
(
"canPutInAfterResolve, url="
+
inCheckUrl
+
" apiException: "
+
apiException
.
toString
());
throw
new
ValidateException
(
"smfcore.mesApi.inCheck.error"
,
"MES接口调用异常:"
+
apiException
.
getMessage
());
}
catch
(
Exception
exception
)
{
log
.
error
(
"canPutInAfterResolve, url="
+
inCheckUrl
+
" exception: "
+
exception
.
toString
());
throw
new
ValidateException
(
"smfcore.mesApi.inCheck.error"
,
"MES验证异常:"
+
exception
.
getMessage
());
}
}
@Override
public
void
inTaskStatusChange
(
String
inNotifyUrl
,
DataLog
task
){
TaskStatusChange
(
inNotifyUrl
,
task
);
}
@Override
public
void
outTaskStatusChange
(
String
outNotifyUrl
,
DataLog
task
){
TaskStatusChange
(
outNotifyUrl
,
task
);
}
@Override
public
void
otherTaskStatusChange
(
String
taskNotifyUrl
,
DataLog
task
)
{
TaskStatusChange
(
taskNotifyUrl
,
task
);
}
public
boolean
TaskStatusChange
(
String
url
,
DataLog
task
)
{
if
(
ObjectUtil
.
isEmpty
(
url
))
{
return
false
;
}
// {
// "docType": "UPDATE_RS_MSG",
// "updateType": "UPDATE",
// "data": [
// {
// "zzzc_rs_type": "HW_BEGIN",
// "lpn": "LPN20250001",
// "mtrl_code": "MAT20250001",
// "rs_qty": 10,
// "zzzc_rs_date": "2025-04-29 09:00:00"
// } ]
// }
//
//
// {
// "resultCode": "0000",
// "resultMsg": "",
// "resultData": [
// {
// "org_code": "G100",
// "lpn": "LPN20250001"
// }
// ]
// }
Barcode
barcode
=
barcodeManager
.
get
(
task
.
getBarcode
());
String
rsType
=
null
;
if
(
task
.
isCheckOutTask
())
{
// 领用 - 暂不支持,需要根据业务逻辑确定具体的操作类型
log
.
warn
(
"TaskStatusChange: 领用操作暂不支持,需要进一步确认业务逻辑"
);
return
false
;
}
else
if
(
task
.
isPutInTask
())
{
StoragePos
pos
=
storagePosManager
.
getByPosName
(
task
.
getPosName
());
if
(!
pos
.
isWarmPos
())
{
// 入库到冷藏区
rsType
=
"LC"
;
// 冷藏
}
}
else
if
(
task
.
isRewarmTakingTask
())
{
// 回温取料 - 可能是回温开始
rsType
=
"HW_BEGIN"
;
// 回温开始
}
else
if
(
task
.
isRewarmPuttingTask
())
{
// 回温放料 - 可能是回温结束
rsType
=
"HW_END"
;
// 回温结束
}
else
if
(
task
.
isMixTask
()){
// 搅拌结束: JB_END
rsType
=
"JB_END"
;
// 搅拌结束
}
// 可以根据具体业务需求添加搅拌相关的逻辑
// 搅拌开始: JB_BEGIN
// 搅拌结束: JB_END
if
(
rsType
==
null
)
{
log
.
warn
(
"TaskStatusChange: 未找到对应的操作类型,task类型: "
+
task
.
getType
());
return
false
;
}
try
{
// 构建请求数据使用Map
Map
<
String
,
Object
>
request
=
new
HashMap
<>();
request
.
put
(
"docType"
,
"UPDATE_RS_MSG"
);
request
.
put
(
"updateType"
,
"UPDATE"
);
// 构建data数组
List
<
Map
<
String
,
Object
>>
dataList
=
new
ArrayList
<>();
Map
<
String
,
Object
>
dataItem
=
new
HashMap
<>();
dataItem
.
put
(
"zzzc_rs_type"
,
rsType
);
dataItem
.
put
(
"lpn"
,
barcode
.
getBarcode
());
// 使用条码作为LPN
dataItem
.
put
(
"mtrl_code"
,
barcode
.
getPartNumber
());
// 使用条码中的物料编码
dataItem
.
put
(
"rs_qty"
,
barcode
.
getAmount
());
// 默认数量为1,可根据实际业务调整
// 格式化时间为 YYYY-MM-DD HH:mm:ss
String
time
=
DateUtil
.
toDateString
(
task
.
getUpdateDate
(),
"yyyy-MM-dd HH:mm:ss"
);
dataItem
.
put
(
"zzzc_rs_date"
,
time
);
// 如果是冷藏操作,需要传生产日期
if
(
"LC"
.
equals
(
rsType
)&&
ObjectUtil
.
isNotEmpty
(
barcode
.
getProduceDate
()))
{
// 这里需要根据实际业务获取生产日期,暂时使用当前日期
dataItem
.
put
(
"mf_date"
,
DateUtil
.
toDateString
(
barcode
.
getProduceDate
(),
"yyyy-MM-dd HH:mm:ss"
));
}
dataList
.
add
(
dataItem
);
request
.
put
(
"data"
,
dataList
);
log
.
info
(
"TaskStatusChange, url="
+
url
+
",发送数据="
+
JsonUtil
.
toJsonStr
(
request
));
String
result
=
HttpHelper
.
postJson
(
url
,
request
);
log
.
info
(
"TaskStatusChange, url="
+
url
+
",收到数据="
+
result
);
// 解析响应使用Map
Map
<
String
,
Object
>
response
=
JsonUtil
.
toMap
(
result
);
if
(
response
!=
null
)
{
String
resultCode
=
(
String
)
response
.
get
(
"resultCode"
);
if
(
"0000"
.
equals
(
resultCode
))
{
log
.
info
(
"TaskStatusChange 成功,resultCode: "
+
resultCode
);
return
true
;
}
else
{
String
resultMsg
=
(
String
)
response
.
get
(
"resultMsg"
);
log
.
error
(
"TaskStatusChange 失败,resultCode: "
+
resultCode
+
", resultMsg: "
+
resultMsg
);
return
false
;
}
}
else
{
log
.
error
(
"TaskStatusChange 响应解析失败"
);
return
false
;
}
}
catch
(
ApiException
apiException
)
{
log
.
error
(
"TaskStatusChange, url="
+
url
+
" apiException: "
+
apiException
.
toString
());
}
catch
(
Exception
exception
)
{
log
.
error
(
"TaskStatusChange, url="
+
url
+
" exception: "
+
exception
.
toString
());
}
return
false
;
}
}
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论