--[[
|
编码: WMS-40-23
|
名称: 作业-成品出库-任务完成
|
作者:HAN
|
日期:2025-1-29
|
|
版本: V1.0
|
|
场景:作业中的任务完成后触发这个脚本
|
当前数据对象指针是 【作业】Operation
|
【任务】对象属性保存在输入参数 InputParamter
|
|
|
函数: TaskFinish
|
|
功能:
|
根据任务类型判断一下这个任务完成
|
--是否可以关闭【作业】
|
--如果是出库作业,当前完成的任务是AGV搬运任务,那么要创建下一个输送机搬运任务
|
更改记录:
|
|
|
--]]
|
wms_op = require( "wms_operation" )
|
|
function TaskFinish ( strLuaDEID )
|
local nRet, strRetInfo
|
local strErr = ''
|
|
lua.Debug( strLuaDEID, debug.getinfo(1), "TaskFinish", "Out" )
|
-- 获取 触发【作业】任务完成事件的场景参数
|
-- step1 获取任务信息
|
local task
|
nRet, task = m3.SysInputParamToDataObj( strLuaDEID, "Task")
|
if (nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), task ) end
|
|
-- step2 获取作业信息
|
local operation
|
nRet, operation = m3.GetSysCurEditDataObj( strLuaDEID, "Operation" )
|
if (nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), operation ) end
|
|
-- 判断任务类型
|
if ( task.type == wms_base.Get_nConst(strLuaDEID, "任务类型-AGV出库搬运") ) then
|
-- AGV 搬运完成后 马上创建一个{输送机搬运}任务
|
-- 创建输送机搬运任务
|
local new_task
|
|
new_task = m3.AllocObject(strLuaDEID,"Task")
|
new_task.sort_no = 2 -- 表示这个任务是作业里的第2个任务
|
new_task.op_code = operation.code -- 作业编码
|
new_task.op_name = operation.op_def_name
|
new_task.factory = operation.factory
|
new_task.type = wms_base.Get_nConst(strLuaDEID,"任务类型-输送机出库搬运") -- 任务类型
|
new_task.cntr_code = operation.cntr_code
|
new_task.eq_code = "S7_Line_01" -- 输送线设备编码
|
-- 起点
|
new_task.start_wh_code = task.end_wh_code
|
new_task.start_area_code = task.end_area_code
|
new_task.start_loc_code = task.end_loc_code
|
-- 终点 (到分拣口)
|
new_task.end_wh_code = operation.end_wh_code
|
new_task.end_area_code = operation.end_area_code
|
|
-- 确定分拣区
|
local sorting_area_code = ''
|
local sorting_arae_loc_list = wms_base.Get_Warehouse_FuncArea( strLuaDEID, operation.end_wh_code, "功能区类型-分拣" )
|
local nCountFA = #sorting_arae_loc_list
|
|
if ( nCountFA == 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "仓库:"..end_wh_code .."必须要定义一个'分拣'类型的功能区!" ) end
|
-- 在新兴的项目中库区的出库接驳区位只能是一个,如果有多个这里就要加均衡
|
if ( nCountFA ~= 1 ) then lua.Error( strLuaDEID, debug.getinfo(1), "仓库:"..end_wh_code .."只能定义一个'分拣'类型的功能区、位" ) end
|
if ( sorting_arae_loc_list[1].type ~= wms_base.Get_nConst(strLuaDEID, "基础类型-库区") ) then
|
lua.Error( strLuaDEID, debug.getinfo(1), "仓库:"..end_wh_code.."只能定义库区类型的'分拣'区" )
|
end
|
sorting_area_code = sorting_arae_loc_list[1].code
|
|
-- 获取分拣区可入库容量最大的货位
|
local loc_info
|
nRet, loc_info = wms_wh.GetAreaMostEmptyLoc( strLuaDEID, "Area", sorting_area_code )
|
if ( nRet == 1 ) then
|
lua.Warning( strLuaDEID, debug.getinfo(1), "获取分拣区'"..sorting_area_code.."'目前无空闲货位!" )
|
return
|
end
|
if ( nRet ~= 0 ) then
|
lua.Error( strLuaDEID, debug.getinfo(1), "获取分拣区'"..sorting_area_code.."'的最大可入库容量货位失败!"..loc_info )
|
end
|
|
new_task.end_loc_code = loc_info.code
|
new_task.schedule_type = wms_base.Get_nConst(strLuaDEID, "调度类型-输送机") -- 设置调度类型
|
|
lua.Debug( strLuaDEID, debug.getinfo(1), "task2", new_task )
|
|
nRet, new_task = m3.CreateDataObj(strLuaDEID, new_task)
|
if (nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1),"创建AGV任务失败!"..new_task) end
|
-- 任务中货位加锁
|
-- 把开始货位加出库锁,终点货位加入库锁
|
nRet, strRetInfo = wms_task.LockLocation( strLuaDEID, new_task, "锁类型-出库锁", "锁类型-入库锁" )
|
if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1),"wms_task.LockLocation失败!"..strRetInfo ) end
|
|
elseif ( task.type == wms_base.Get_nConst(strLuaDEID, "任务类型-输送机出库搬运") ) then
|
-- 输送机搬运完成后可以认为作业完成
|
nRet, strRetInfo = wms_op.SetFinish( strLuaDEID, operation.code )
|
if ( nRet ~= 0 ) then
|
lua.Error( strLuaDEID, debug.getinfo(1), "设置作业编号='"..operation.code.."' 的作业完成失败!"..strRetInfo )
|
end
|
else
|
lua.Error( strLuaDEID, debug.getinfo(1), "任务编号='"..task.code.."' 的任务类型不对!" )
|
end
|
end
|