--[[
|
编码: WMS-40-23#2
|
名称: 作业-出库-任务完成
|
作者:HAN
|
日期:2025-1-29
|
|
版本: V1.0
|
|
场景:作业中的任务完成后触发这个脚本
|
当前数据对象指针是 作业
|
任务对象属性保存在 输入参数 InputParamter
|
需要判断一下这个任务完成是否可以关闭 作业
|
|
函数: TaskFinish
|
|
功能:
|
源于巨星料箱库
|
-- 根据任务类型判断是否结束作业
|
|
|
更改记录:
|
|
--]]
|
|
wms_op = require( "wms_operation" )
|
|
function TaskFinish( strLuaDEID )
|
local nRet, strRetInfo
|
local strErr = ''
|
|
-- 获取 触发【作业】任务完成事件的场景参数
|
-- step1 获取任务信息
|
local task
|
local input_paramters
|
nRet, input_paramters = mobox.getInputParameter2(strLuaDEID)
|
if (nRet ~= 0) then
|
lua.Stop( strLuaDEID, "getInputParameter2 失败!" )
|
return
|
end
|
|
-- 把 [{"attr":"xxx","value":""},...] 转换成 task json object
|
local strObjJson
|
nRet, strObjJson = mobox.objAttrsToLuaJson( "Task", input_paramters )
|
if ( nRet ~= 0 ) then
|
lua.Stop( strLuaDEID, "objAttrsToLuaJson Task 失败!"..strObjJson )
|
return
|
end
|
local success
|
success, task = pcall( json.decode, strObjJson )
|
if ( success == false ) then
|
lua.Stop( strLuaDEID, "objAttrsToLuaJson (task) 返回的的JSON格式不合法 !"..task )
|
return
|
end
|
if ( task.start_wh_code == '') then
|
lua.Stop( strLuaDEID, "作业中起点仓库为空!")
|
return
|
end
|
|
local operation
|
nRet, operation = m3.GetSysCurEditDataObj( strLuaDEID, "Operation" )
|
if (nRet ~= 0 ) then
|
lua.Stop( strLuaDEID, operation )
|
return
|
end
|
|
if ( task.type == wms_base.Get_nConst(strLuaDEID, "任务类型-立库出库搬运") ) then
|
-- 作业完成
|
nRet, strRetInfo = wms_op.SetFinish( strLuaDEID, operation )
|
if ( nRet ~= 0 ) then
|
lua.Stop( strLuaDEID, "设置作业编号='"..operation.code.."' 的作业完成失败!"..strRetInfo )
|
return
|
end
|
|
if ( operation.op_def_name == '料箱出库') then
|
local carry_cb_no = lua.Get_StrAttrValue( operation.carry_cb_no )
|
|
if ( operation.carry_cb_cls == "Pre_Alloc_Container" ) then
|
if ( carry_cb_no ~= '' ) then
|
-- 【预分配容器】的状态要设置为 2 (到站台)
|
local strUpdateSql = "N_B_STATE = 2"
|
local strCondition = "S_PAC_NO = '"..carry_cb_no.."'"
|
nRet, strRetInfo = mobox.updateDataAttrByCondition( strLuaDEID, "Pre_Alloc_Container", strCondition, strUpdateSql )
|
if ( nRet ~= 0 ) then
|
lua.Stop( strLuaDEID, "更新【配盘容器】信息失败!"..strRetInfo )
|
return
|
end
|
-- 更新 【配盘明细】的状态设置为 1 (执行)
|
strUpdateSql = "N_B_STATE = 1"
|
nRet, strRetInfo = mobox.updateDataAttrByCondition( strLuaDEID, "Pre_Alloc_CNTR_Detail", strCondition, strUpdateSql )
|
if ( nRet ~= 0 ) then
|
lua.Stop( strLuaDEID, "更新【配盘容器】信息失败!"..strRetInfo )
|
return
|
end
|
end
|
end
|
elseif ( operation.op_def_name == '盘点出库') then
|
-- 【计划盘点容器】状态设置为 2
|
local strUpdateSql = "N_B_STATE = 2"
|
local strCondition = "S_OUT_OP_NO = '"..operation.code.."' AND S_CNTR_CODE = '"..operation.cntr_code.."'"
|
nRet, strRetInfo = mobox.updateDataAttrByCondition( strLuaDEID, "CP_Count_Container", strCondition, strUpdateSql )
|
if ( nRet ~= 0 ) then
|
lua.Stop( strLuaDEID, "更新【计划盘点容器】信息失败!"..strRetInfo )
|
return
|
end
|
local cp_cntr
|
nRet, cp_cntr = m3.GetDataObjByCondition( strLuaDEID, "CP_Count_Container", strCondition )
|
if ( nRet ~= 0 ) then
|
lua.Stop( strLuaDEID, "获取【计划盘点容器】信息失败!"..cp_cntr )
|
return
|
end
|
-- 更新【盘点容器货品明细】状态=1
|
strUpdateSql = "N_B_STATE = 1"
|
strCondition = "S_COUNT_NO = '"..cp_cntr.count_no.."' AND S_CNTR_CODE = '"..operation.cntr_code.."'"
|
nRet, strRetInfo = mobox.updateDataAttrByCondition( strLuaDEID, "Count_CG_Detail", strCondition, strUpdateSql )
|
if ( nRet ~= 0 ) then
|
lua.Stop( strLuaDEID, "更新【盘点容器货品明细】信息失败!"..strRetInfo )
|
return
|
end
|
elseif ( operation.op_def_name == '货品出库' ) then
|
local carry_cb_no = lua.Get_StrAttrValue( operation.carry_cb_no )
|
|
-- 【配盘】的状态要设置为 3 -- 出库完成
|
if ( operation.carry_cb_cls == "Distribution_CNTR" ) then
|
if ( carry_cb_no ~= '' ) then
|
local strUpdateSql = "N_B_STATE = 3"
|
local strCondition = "S_DC_NO = '"..carry_cb_no.."'"
|
nRet, strRetInfo = mobox.updateDataAttrByCondition( strLuaDEID, "Distribution_CNTR", strCondition, strUpdateSql )
|
if ( nRet ~= 0 ) then
|
lua.Stop( strLuaDEID, "更新【配盘】信息失败!"..strRetInfo )
|
return
|
end
|
-- 更新 【配盘明细】的状态设置为 1 (执行)
|
strUpdateSql = "N_B_STATE = 1"
|
nRet, strRetInfo = mobox.updateDataAttrByCondition( strLuaDEID, "Distribution_CNTR_Detail", strCondition, strUpdateSql )
|
if ( nRet ~= 0 ) then
|
lua.Stop( strLuaDEID, "更新【配盘明细】信息失败!"..strRetInfo )
|
return
|
end
|
end
|
end
|
elseif ( operation.op_def_name == '指定出库' ) then
|
-- 更新【指定出库】对象
|
if ( operation.bs_no ~= '' and operation.bs_type == "Specify_Outbound") then
|
-- 2 表示指定出库容器 已经到站台
|
local strUpdateSql = "N_B_STATE = 2"
|
local strCondition = "S_SO_NO = '"..operation.bs_no.."' AND S_CNTR_CODE = '"..operation.cntr_code.."'"
|
nRet, strRetInfo = mobox.updateDataAttrByCondition( strLuaDEID, "Specify_Outbound_CNTR", strCondition, strUpdateSql )
|
if ( nRet ~= 0 ) then
|
lua.Stop( strLuaDEID, "更新【配盘明细】信息失败!"..strRetInfo )
|
return
|
end
|
|
-- 更新【指定出库容器货品明细】状态=1
|
strUpdateSql = "N_B_STATE = 1"
|
strCondition = "S_SO_NO = '"..operation.bs_no.."' AND S_CNTR_CODE = '"..operation.cntr_code.."'"
|
nRet, strRetInfo = mobox.updateDataAttrByCondition( strLuaDEID, "SO_CNTR_Detail", strCondition, strUpdateSql )
|
if ( nRet ~= 0 ) then
|
lua.Stop( strLuaDEID, "更新【指定出库容器货品明细】信息失败!"..strRetInfo )
|
return
|
end
|
|
local specify_outbound
|
strCondition = "S_SO_NO = '"..operation.bs_no.."'"
|
nRet, specify_outbound = m3.GetDataObjByCondition( strLuaDEID, "Specify_Outbound", strCondition )
|
if ( nRet == 0 ) then
|
-- 增加一个后台进程进行检查指定出库完成情况
|
local add_wfp = {
|
wfp_type = 1, -- 触发数据对象事件(指定数据对象标识)
|
cls = "Specify_Outbound",
|
obj_id = specify_outbound.id,
|
obj_name = "指定出库'"..operation.bs_no.."'-->状态检查",
|
trigger_event = "状态检查"
|
}
|
nRet, strRetInfo = m3.AddSysWFP( strLuaDEID, add_wfp )
|
if ( nRet ~= 0 ) then
|
lua.Stop( strLuaDEID, "AddSysWFP失败!"..strRetInfo )
|
return
|
end
|
end
|
end
|
end
|
end
|
end
|