fy36
2025-05-14 a37aca60ff9914b0abb710f04118b22420f4f398
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
--[[
    编码: WMS-40-21#1
    名称: 作业-成品入库-任务完成
    作者:HAN  
    日期:2025-1-29
 
    版本: V1.0
 
    场景:作业中的任务完成后触发这个脚本
          当前数据对象指针是 作业
          任务对象属性保存在 输入参数 InputParamter 
          需要判断一下这个任务完成是否可以关闭 作业
       
    函数: TaskFinish
 
    功能:
        1)根据任务类型判断是否结束作业
 
    更改记录:
 
 
--]]
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.Error( strLuaDEID, debug.getinfo(1), "getInputParameter2 失败!" ) end
    
    -- 把 [{"attr":"xxx","value":""},...] 转换成 task json object
    local strObjJson
    nRet, strObjJson = mobox.objAttrsToLuaJson( "Task", input_paramters )
    if ( nRet ~= 0  ) then lua.Error( strLuaDEID, debug.getinfo(1), "objAttrsToLuaJson Task 失败!"..strObjJson ) end
    local success
    success, task = pcall( json.decode, strObjJson )
    if ( success == false ) then lua.Error( strLuaDEID, debug.getinfo(1), "objAttrsToLuaJson (task) 返回的的JSON格式不合法 !"..task ) end
    if ( task.start_wh_code == '') then lua.Error( strLuaDEID, debug.getinfo(1), "作业中起点仓库为空!") end
 
    -- 判断任务类型
    if ( task.type == wms_base.Get_nConst(strLuaDEID, "任务类型-AGV入库搬运") ) then
        -- step2 获取作业信息
        local operation
        nRet, operation = m3.GetSysCurEditDataObj( strLuaDEID, "Operation" )
        if (nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), operation ) end 
 
        -- AGV 搬运完成后可以认为作业完成
        nRet, strRetInfo = wms_op.SetFinish( strLuaDEID, operation.code )
        if ( nRet ~= 0 ) then
            lua.Error( strLuaDEID, debug.getinfo(1), "设置作业编号='"..operation.code.."' 的作业完成失败!"..strRetInfo )
        end
    end
end