1
Jianw
2025-07-09 88e26a2a960dbbc148332772448b79b9877102d8
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
--[[
    编码: WMS-40-23#3
    名称: 作业-出库作业-任务完成
    作者:HAN  
    日期:2025-1-29
 
    版本: V1.0
 
    场景:作业中的任务完成后触发这个脚本
          当前数据对象指针是 【作业】Operation
          【任务】对象属性保存在输入参数 InputParamter 
 
       
    函数: TaskFinish
 
    功能:
        -- 这是一个[Picking As/RS]->[Station]的作业
    
    更改记录:
 
--]]
wms_op = require( "wms_operation" )
 
function TaskFinish ( strLuaDEID ) 
    local nRet, strRetInfo
    local strErr = ''
 
    lua.DebugEx( strLuaDEID, "In Operation Task Finish ", "WMS-40-23#3" )
 
    -- 获取 触发【作业】任务完成事件的场景参数
    local task
    nRet, task = m3.SysInputParamToDataObj( strLuaDEID, "Task")
    if (nRet ~= 0 ) then 
        lua.Stop( strLuaDEID, debug.getinfo(1), task )
        return
    end 
    
    local operation
    nRet, operation = m3.GetSysCurEditDataObj( strLuaDEID, "Operation" )
    if (nRet ~= 0 ) then 
        lua.Stop( strLuaDEID, operation ) 
        return
    end 
 
    -- 判断任务类型
    if ( task.type == TASK_TYPE.Out_Picking ) then
        
        local strUpdateSql, strCondition
 
        nRet, strRetInfo = wms_op.SetFinish( strLuaDEID, operation )
        if ( nRet ~= 0 ) then
            lua.Stop( strLuaDEID, "设置作业编号='"..operation.code.."' 的作业完成失败!"..strRetInfo )
            return
        end
 
        -- 更新作业的 end_loc / Pickin车的位置是由 AGV确定的
        strUpdateSql = "S_END_WH = '"..task.end_wh_code.."', S_END_AREA = '"..task.end_area_code.."', S_END_LOC = '"..task.end_loc_code.."'"
        strCondition = "S_CODE = '"..task.op_code.."'"
        nRet, strRetInfo = mobox.updateDataAttrByCondition( strLuaDEID, "Operation", strCondition, strUpdateSql )
        if ( nRet ~= 0 ) then  
            lua.Stop( strLuaDEID, "更新【作业】信息失败!"..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 == "Distribution_CNTR" ) then
                -- 料箱出库到分拣区域
                -- 如果作业的配盘后料箱回库,需要设置配盘对象的状态 = 6
                if ( carry_cb_no ~= '' ) then
                    strUpdateSql = "N_B_STATE = "..DIST_CNTR_STATE.Out
                    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 = "..DC_DETAIL_STATE.CanDoPicking..", S_WH_CODE = '"..task.end_wh_code.."', S_AREA_CODE = '"..task.end_area_code.."', S_LOC_CODE = '"..task.end_loc_code.."'"
                    nRet, strRetInfo = mobox.updateDataAttrByCondition( strLuaDEID, "Distribution_CNTR_Detail", strCondition, strUpdateSql )
                    if ( nRet ~= 0 ) then  
                        lua.Stop( strLuaDEID, "更新【配盘明细】信息失败!"..strRetInfo ) 
                        return
                    end     
                end 
            elseif ( operation.carry_cb_cls == "Pre_Alloc_Container" ) then
                if ( carry_cb_no ~= '' ) then
                    -- 【预分配容器】的状态要设置为 2 (到站台)
                    local strUpdateSql = "N_B_STATE = "..PAC_STATE.Arrive_Station
                    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 = "..PAC_DETAIL_STATE.Palletizing
                    nRet, strRetInfo = mobox.updateDataAttrByCondition( strLuaDEID, "Pre_Alloc_CNTR_Detail", strCondition, strUpdateSql )
                    if ( nRet ~= 0 ) then  
                        lua.Stop( strLuaDEID, "更新【配盘容器】信息失败!"..strRetInfo ) 
                        return
                    end
                end
                    
            end
        end     
    else
        lua.Stop( strLuaDEID, "任务编号='"..task.code.."' 的任务类型不对!" )
        return
    end
end