wsz
2025-06-20 19898bd66dec87b500b200d5d50961d0fb538ce5
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
--[[
    编码: WMS-40-20#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
    
    -- 作业的 ext_info 保留了入库巷道接驳口货位
    local to_loc    
    if ( operation_obj.op_def_name ~= '站台搬运' ) then
        if ( operation_obj.ext_data == nil or operation_obj.ext_data == "" ) then
            msg = '作业中的扩展属性应保存堆垛机接驳货位信息! '
            lua.Warning( strLuaDEID, debug.getinfo(1), msg )
            mobox.stopProgram( strLuaDEID, msg )
            return
        end
        nRet, to_loc = wms_wh.GetLocInfo( operation_obj.ext_data )
        if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "获取货位'"..operation_obj.ext_info.."'信息失败! "..to_loc ) end
    else
        nRet, to_loc = wms_wh.GetLocInfo( operation_obj.end_loc_code )
        if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "获取货位'"..operation_obj.end_loc_code.."'信息失败! "..to_loc ) end        
    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 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  = to_loc.wh_code
    task.end_area_code  = to_loc.area_code
    task.end_loc_code  = to_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
 
    -- 入库货位加入库锁 -- 本项目不考虑,因为前段任务为输送线
    -- 给入库的容器加锁 1 -- 入库锁
 
    if ( operation_obj.lock_cntr == 'Y' ) then
        nRet, strRetInfo = wms.wms_LockCntr( operation_obj.cntr_code, 1, operation_obj.code)
        if ( nRet ~= 0 ) then
            lua.Error( strLuaDEID, debug.getinfo(1), "给容器'"..operation_obj.cntr_code.."'加入库锁失败!")   
        end  
        wms.wms_CommitCntrLockTrans( operation_obj.code )     
    end    
 
end