1
Jianw
9 天以前 70f29da38121b9a467841253e3268feb5df02902
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
--[[
    编码: WMS-40-22#3
    名称: 作业-出库-启动
    作者: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获取)
 
    功能:
        -- 这是适合 [Picking AS/RS]->[Station] 的搬运模式的作业启动程序
 
    更改说明:
 
--]]
 
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
    --判断作业容器是否存在?
    if  ( operation_obj.cntr_code == nil or operation_obj.cntr_code == '' ) then
        lua.Stop( strLuaDEID, "容器号不能为空!" )
        return          
    end    
 
    -- 如果料箱不在立库的存储区、作业不启动()
    local cntr
    nRet, cntr = wms_cntr.GetInfo( strLuaDEID, operation_obj.cntr_code )
    if ( nRet ~= 0 ) then 
        lua.Stop( strLuaDEID, "获取容器号'"..operation_obj.cntr_code.."'的容器失败!" )
        return
    end
    local loc
    nRet, loc = wms_wh.GetLocInfo( cntr.position )
    if ( nRet ~= 0 ) then
        lua.Stop( strLuaDEID, "获取货位'"..cntr.position.."'信息失败!" )
        return                
    end
    local area
    nRet, area = wms_wh.GetAreaInfo( loc.area_code )
    if nRet ~= 0 then
        lua.Stop( strLuaDEID, "获取库区'"..loc.area_code.."'信息失败!" )
        return                
    end
    if area.type ~= AREA_TYPE.Storage_Area then return end
 
    -- 如果作业启动要锁容器的
    if ( operation_obj.lock_cntr == 'Y' ) then
        -- 判断容器是否已经有锁(直接内存判断)
        local lock_state, op_code
        nRet, lock_state, op_code = wms.wms_IsLockedCntr( operation_obj.cntr_code )
        if ( nRet ~= 0 ) then 
            lua.Stop( strLuaDEID, '获取容器锁状态失败!'..lock_state )
            return
        end
        -- 4 是盘点锁,有盘点锁可以继续
        if ( lock_state ~= 0 and lock_state ~= 4 ) then 
            lua.Stop( strLuaDEID, "作业'"..operation_obj.code.."'由于容器'"..operation_obj.cntr_code.."'被锁定无法启动!" )
            return 
        end
    end
    
    -- 同时判断一下容器的货位信息是否和原来的一样
    if ( cntr.position ~= operation_obj.start_loc_code ) then
        local strCondition = "S_CODE = '"..operation_obj.code.."'"
        local strUpdateSql = "S_START_LOC = '"..loc.code.."', S_START_AREA = '"..loc.area_code.."', S_START_WH = '"..loc.wh_code.."'"
        nRet, strRetInfo = mobox.updateDataAttrByCondition( strLuaDEID, "Operation", strCondition, strUpdateSql )
        if ( nRet ~= 0 ) then  
            lua.Stop( strLuaDEID, "更新【作业】信息失败!"..strRetInfo ) 
            return
        end  
        operation_obj.start_wh_code = loc.wh_code
        operation_obj.start_area_code = loc.area_code
        operation_obj.start_loc_code = loc.code           
    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 = TASK_TYPE.Out_Picking
    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  = operation_obj.end_wh_code
    task.end_area_code  = operation_obj.end_area_code
    task.end_loc_code  = ''
    task.schedule_type = SCHEDULE_SYS_TYPE.Grace                -- 国自系统
    
    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
 
    -- 给出库的容器加锁 2 -- 出库锁
    if ( operation_obj.lock_cntr == 'Y' ) then
        nRet, strRetInfo = wms.wms_LockCntr( operation_obj.cntr_code, 2, operation_obj.code )
        if ( nRet ~= 0 ) then
            lua.Stop( strLuaDEID, "作业启动时给容器'"..operation_obj.cntr_code.."'加出库锁失败!" )
            return               
        end 
    end
    -- 出库的起点货位加出库锁
    nRet, strRetInfo = wms.wms_LockLocation(strLuaDEID, task.start_loc_code, LOCK_TYPE.Outbound, task.code, task.op_code, task.op_name )
    if nRet ~= 0 then 
        wms.wms_AbortCntrLockTrans( operation_obj.code )         
        lua.Stop( strLuaDEID, "作业启动时 wms_LockLocation 失败!"..strRetInfo )
        return          
    end 
    wms.wms_CommitCntrLockTrans( operation_obj.code )     
end