--[[
|
编码: WMS-40-22#2
|
名称: 作业-出库-启动
|
作者:HAN
|
日期:2025-1-29
|
|
版本: V1.0
|
|
说明:该脚本和项目关联度较高,会根据项目不同而不同
|
|
函数: OperationStart
|
|
输入条件:
|
1) globa_attr 全局属性
|
{
|
factory:"0000" start_wh: start_area:"AL1-01" start_loc:"LL1-1001"
|
-- 作业信息
|
op_id: op_type: op_code: cntr_code:"TP20000001"
|
}
|
2) dataJson -- 后台匹配到的 作业定义属性
|
|
|
3) dataobj -- Operation 对象 (通过GetSysCurEditDataObj获取)
|
|
功能:
|
-- 根据start、end 两个货位创建 立库出库搬运任务
|
|
更改说明:
|
|
--]]
|
|
wms_op = require( "wms_operation" )
|
wms_wh = require( "wms_wh" )
|
|
function OperationStart ( strLuaDEID )
|
local nRet, strRetInfo, msg
|
|
-- 获取作业对象
|
local operation_obj = {}
|
nRet, operation_obj = m3.GetSysCurEditDataObj( strLuaDEID, "Operation" )
|
if (nRet ~= 0) then lua.Error( strLuaDEID, debug.getinfo(1), "获取作业对象属性失败!"..operation_obj ) end
|
--判断作业容器是否存在?
|
if ( operation_obj.cntr_code == nil or operation_obj.cntr_code == '' ) then
|
msg = "容器号不能为空!"
|
lua.Warning( strLuaDEID, debug.getinfo(1), msg )
|
mobox.stopProgram( strLuaDEID, msg )
|
return
|
end
|
|
-- 如果料箱不在立库的存储区
|
local cntr
|
nRet, cntr = wms_cntr.GetInfo( strLuaDEID, operation_obj.cntr_code )
|
if ( nRet ~= 0 ) then
|
msg = "获取容器号'"..operation_obj.cntr_code.."'的容器失败!"
|
lua.Warning( strLuaDEID, debug.getinfo(1), msg )
|
mobox.stopProgram( strLuaDEID, msg )
|
return
|
end
|
-- 如果容器不在料箱库的存储区域,不启动
|
local loc
|
nRet, loc = wms_wh.GetLocInfo( cntr.position )
|
if ( nRet ~= 0 ) then
|
msg = "获取货位'"..cntr.position.."'信息失败!"
|
lua.Warning( strLuaDEID, debug.getinfo(1), msg )
|
mobox.stopProgram( strLuaDEID, msg )
|
return
|
end
|
local storage_arae
|
nRet, storage_arae = wms_base.Get_sConst2( strLuaDEID, "料箱库存储区" )
|
if ( nRet ~= 0 ) then
|
lua.Stop( strLuaDEID, "系统无法获取常量'料箱库存储区'")
|
return
|
end
|
|
if ( loc.area_code ~= storage_arae ) then
|
msg = "作业'"..operation_obj.code.."'由于容器'"..operation_obj.cntr_code.."'目前不在立库的储藏区无法启动!"
|
lua.Warning( strLuaDEID, debug.getinfo(1), msg )
|
mobox.stopProgram( strLuaDEID, msg )
|
return
|
end
|
|
-- 如果作业启动要锁容器的
|
if ( operation_obj.lock_cntr == 'Y' ) then
|
-- 判断容器是否已经有锁(直接内存判断)
|
local lock_state, op_code
|
nRet, lock_state, op_code = wms.wms_IsLockedCntr( operation_obj.cntr_code )
|
if ( nRet ~= 0 ) then
|
msg = '获取容器锁状态失败!'..lock_state
|
lua.Warning( strLuaDEID, debug.getinfo(1), msg )
|
mobox.stopProgram( strLuaDEID, msg )
|
return
|
end
|
-- 4 是盘点锁,有盘点锁可以继续
|
if ( lock_state ~= 0 and lock_state ~= 4 ) then
|
msg = "作业'"..operation_obj.code.."'由于容器'"..operation_obj.cntr_code.."'被锁定无法启动!"
|
lua.Warning( strLuaDEID, debug.getinfo(1), msg )
|
mobox.stopProgram( strLuaDEID, msg )
|
return
|
end
|
end
|
|
-- 同时判断一下容器的货位信息是否和原来的一样
|
if ( cntr.position ~= operation_obj.start_loc_code ) then
|
local strCondition = "S_CODE = '"..operation_obj.code.."'"
|
local strUpdateSql = "S_START_LOC = '"..loc.code.."', S_START_AREA = '"..loc.area_code.."', S_START_WH = '"..loc.wh_code.."'"
|
nRet, strRetInfo = mobox.updateDataAttrByCondition( strLuaDEID, "Operation", strCondition, strUpdateSql )
|
if ( nRet ~= 0 ) then
|
lua.Error( strLuaDEID, debug.getinfo(1), "更新【作业】信息失败!"..strRetInfo )
|
end
|
operation_obj.start_wh_code = loc.wh_code
|
operation_obj.start_area_code = loc.area_code
|
operation_obj.start_loc_code = loc.code
|
end
|
|
-- 创建立库出库搬运任务
|
local task = m3.AllocObject(strLuaDEID,"Task")
|
|
-- 创建堆垛机搬运任务
|
task.op_code = operation_obj.code -- 作业编码
|
task.source_sys = operation_obj.source_sys -- 来源系统
|
task.op_name = operation_obj.op_def_name
|
task.factory = operation_obj.factory -- 工厂
|
task.bs_type = operation_obj.bs_type
|
task.bs_no = operation_obj.bs_no
|
task.type = wms_base.Get_nConst(strLuaDEID, "任务类型-立库出库搬运")
|
task.cntr_code = operation_obj.cntr_code
|
-- 起点
|
task.start_wh_code = operation_obj.start_wh_code
|
task.start_area_code = operation_obj.start_area_code
|
task.start_loc_code = operation_obj.start_loc_code
|
-- 终点
|
task.end_wh_code = operation_obj.end_wh_code
|
task.end_area_code = operation_obj.end_area_code
|
task.end_loc_code = operation_obj.end_loc_code
|
task.schedule_type = wms_base.Get_nConst(strLuaDEID, "调度类型-立库") -- 设置调度类型
|
|
if (task.op_code == nil or task.op_code == '' ) then
|
msg = "创建Task时作业编码不能为空!"
|
lua.Warning( strLuaDEID, debug.getinfo(1), msg )
|
mobox.stopProgram( strLuaDEID, msg )
|
return
|
end
|
nRet, task = m3.CreateDataObj(strLuaDEID, task)
|
if (nRet ~= 0 ) then
|
lua.Error( strLuaDEID, debug.getinfo(1),"创建立库出库任务失败!"..task)
|
end
|
|
-- 给出库的容器加锁 2 -- 出库锁
|
if ( operation_obj.lock_cntr == 'Y' ) then
|
nRet, strRetInfo = wms.wms_LockCntr( operation_obj.cntr_code, 2, operation_obj.code )
|
if ( nRet ~= 0 ) then
|
msg = "作业启动时给容器'"..operation_obj.cntr_code.."'加出库锁失败!"
|
lua.Warning( strLuaDEID, debug.getinfo(1), msg )
|
mobox.stopProgram( strLuaDEID, msg )
|
return
|
end
|
end
|
-- 出库的起点货位加出库锁
|
nRet, strRetInfo = wms.wms_LockLocation(strLuaDEID, task.start_loc_code, wms_base.Get_nConst( strLuaDEID, "锁类型-出库锁" ),
|
task.code, task.op_code, task.op_name )
|
if (nRet ~= 0) then
|
wms.wms_AbortCntrLockTrans( operation_obj.code )
|
msg = "作业启动时 wms_LockLocation 失败!"..strRetInfo
|
lua.Warning( strLuaDEID, debug.getinfo(1), msg )
|
mobox.stopProgram( strLuaDEID, msg )
|
return
|
end
|
wms.wms_CommitCntrLockTrans( operation_obj.code )
|
end
|