--[[
|
编码: WMS-38-06
|
名称: 任务-行按钮-设置任务完成
|
作者:HAN
|
日期:2025-1-29
|
|
|
级别:固定 (说明本段代码在项目中不太会变化)
|
|
函数: SetTaskFinish
|
|
功能:
|
强制设置任务完成
|
|
更改记录:
|
|
--]]
|
wms_task = require( "wms_task" )
|
external_api = require ( "prj_api")
|
|
function SetTaskFinish ( strLuaDEID )
|
local nRet, strRetInfo
|
|
-- step1 获取当前点中的任务
|
nRet, objs = m3.GetSysDataJson( strLuaDEID )
|
if ( nRet ~=0 ) then
|
lua.Stop( strLuaDEID, objs )
|
return
|
end
|
local nCount = #objs
|
if (nCount == 0) then return end
|
|
local task = m3.KeyValueAttrsToObjAttr( objs[1].attrs )
|
|
-- 检查一下脚本里用到的task属性是否在datajson中,没有要提示一下
|
if ( task.S_CODE == nil ) then
|
lua.Stop( strLuaDEID, "在任务显示Grid中必须要有任务编码属性 S_CODE!" )
|
return
|
end
|
if ( task.S_CODE == '' ) then
|
lua.Stop( strLuaDEID, "任务编码不能为空!" )
|
return
|
end
|
|
-- 检查一下任务的起始货位是否和容器绑定,如果绑定要先解绑
|
-- 获取任务中的容器编码和起始货位编码
|
-- V2.0
|
local strCondition = "S_CODE = '"..task.S_CODE.."'"
|
local id
|
nRet, id, strRetInfo = mobox.getDataObjAttrByKeyAttr( strLuaDEID, "Task", strCondition, "S_CNTR_CODE","S_START_LOC","S_OP_CODE" )
|
if ( nRet ~= 0 ) then
|
lua.Stop( strLuaDEID, "获取【任务】属性失败! "..id )
|
return
|
end
|
if ( strRetInfo == '' ) then
|
lua.Stop( strLuaDEID, "任务编码'"..task.S_CODE.."'不存在!" )
|
return
|
end
|
local attrs = json.decode( strRetInfo )
|
local cntr_code = attrs[1].value
|
local start_loc_code = attrs[2].value
|
local op_code = lua.Get_StrAttrValue( attrs[3].value )
|
|
-- 这里需要调用外部接口告诉 WCS 任务取消
|
nRet, strRetInfo = external_api.Task_Cancel( strLuaDEID, cntr_code, task.S_CODE )
|
if ( nRet ~= 0 ) then
|
lua.Stop( strLuaDEID, "料箱号 = "..cntr_code.." 的作业取消失败, WCS无法取消任务!"..strRetInfo )
|
return
|
end
|
|
-- 获取容器绑定的货位
|
local loc_code = wms_wh.GetLocCodeByCNTR( strLuaDEID, cntr_code )
|
if ( loc_code ~= "") then
|
if ( start_loc_code ~= loc_code ) then
|
lua.Stop( strLuaDEID, "容器'"..cntr_code.."'绑定的货位和任务起始货位不一致!" )
|
return
|
end
|
local loc
|
nRet, loc = wms_wh.GetLocInfo( loc_code)
|
if ( nRet ~= 0 ) then
|
lua.Stop( strLuaDEID, "WMS_GetLocInfo失败! "..loc )
|
return
|
end
|
|
nRet, strRetInfo = wms_wh.Loc_Container_Unbinding( strLuaDEID, loc.code, cntr_code, "绑定解绑方法-人工", "强制完成" )
|
if ( nRet ~= 0 ) then
|
lua.Stop( strLuaDEID, '货位容器绑定失败!'..strRetInfo )
|
return
|
end
|
end
|
|
-- 强制任务完成
|
nRet, strRetInfo = wms.wms_TaskFinish( strLuaDEID, task.S_CODE )
|
if ( nRet ~= 0 ) then
|
lua.Stop( strLuaDEID, "任务编码='"..task.S_CODE.."'的任务设置完成失败!"..strRetInfo )
|
return
|
end
|
|
-- 增加 任务动作 对象
|
local task_action = m3.AllocObject(strLuaDEID,"Task_Action")
|
|
task_action.task_code = task.S_CODE
|
task_action.action_code = 10
|
task_action.action = "强制完成"
|
task_action.eq_code = "system"
|
task_action.eq_type_name = '系统强制完成'
|
nRet, strRetInfo = m3.CreateDataObj( strLuaDEID, task_action )
|
if ( nRet ~= 0 ) then
|
lua.Stop( strLuaDEID, '创建【任务动作】对象失败!'..strRetInfo )
|
return
|
end
|
|
-- 设置作业 N_TASK_STATE = 2 说明这个作业不能取消
|
if ( op_code ~= '') then
|
strCondition = "S_CODE = '"..op_code.."'"
|
mobox.addProcSQL3( "Operation", strCondition, "N_TASK_STATE = 2")
|
end
|
|
local strAction = '[{"action_type":"refresh_cur_row","value":""}]'
|
nRet, strRetInfo = mobox.setAction(strLuaDEID, strAction)
|
if ( nRet ~= 0 ) then
|
lua.Stop( strLuaDEID, "setAction错误: "..strRetInfo)
|
return
|
end
|
end
|