1
Jianw
10 天以前 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
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
--[[
    编码: WMS-40-21#2
    名称: 作业-入库-任务完成
    作者:HAN  
    日期:2025-1-29
 
    版本: V1.0
 
    场景:作业中的任务完成后触发这个脚本
          当前数据对象指针是 作业
          任务对象属性保存在 输入参数 InputParamter 
          需要判断一下这个任务完成是否可以关闭 作业
 
          料箱入库 和 巨星入库都不会影响存储量因此可以共用这段代码
       
    函数: TaskFinish
 
    功能:
        -- 根据任务类型判断是否结束作业
        -- 如果是任务类型 = 输送线搬运 任务完成后要把作业设置为 "等待/6" 状态等WCS发出堆垛机请求后再生成堆垛机任务
 
    更改记录:
        V2.0 HAN 20250218
             -- 原来的“码盘入库”改为“初始入库”,新增的“码盘入库”用于真正的码盘操作
 
--]]
wms_op = require( "wms_operation" )
wms_pac = require( "wms_pac_cbg" )
 
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.Stop( strLuaDEID, "getInputParameter2 失败!" ) 
        return
    end
    
    -- 把 [{"attr":"xxx","value":""},...] 转换成 task json object
    local strObjJson
    nRet, strObjJson = mobox.objAttrsToLuaJson( "Task", input_paramters )
    if ( nRet ~= 0  ) then 
        lua.Stop( strLuaDEID, "objAttrsToLuaJson Task 失败!"..strObjJson ) 
        return
    end
    local success
    success, task = pcall( json.decode, strObjJson )
    if ( success == false ) then 
        lua.Stop( strLuaDEID, "objAttrsToLuaJson (task) 返回的的JSON格式不合法 !"..task ) 
        return
    end
    if ( task.start_wh_code == '') then 
        lua.Stop( strLuaDEID, "作业中起点仓库为空!")
        return
    end
 
    local strUpdateSql, strCondition
    local operation
 
    -- 料箱入库 不会产生库存量的变化(分拣回)
    nRet, operation = m3.GetSysCurEditDataObj( strLuaDEID, "Operation" )
    if (nRet ~= 0 ) then 
        lua.Stop( strLuaDEID, operation )
        return
    end 
    -- 判断任务类型
    if ( task.type == wms_base.Get_nConst(strLuaDEID, "任务类型-输送线入库搬运") ) then
        -- 创建堆垛机入库任务
        local new_task = m3.AllocObject(strLuaDEID,"Task")
 
        new_task.op_code = operation.code                            -- 作业编码
        new_task.source_sys = operation.source_sys                   -- 来源系统
        new_task.op_name = operation.op_def_name
        new_task.factory = operation.factory                         -- 工厂
        new_task.bs_type = operation.bs_type                        
        new_task.bs_no = operation.bs_no  
        new_task.type = wms_base.Get_nConst(strLuaDEID, "任务类型-堆垛机入库搬运") 
        new_task.cntr_code = task.cntr_code
        -- 起点
        new_task.start_wh_code = task.end_wh_code
        new_task.start_area_code  = task.end_area_code
        new_task.start_loc_code  = task.end_loc_code
        -- 终点
        new_task.end_wh_code  = operation.end_wh_code
        new_task.end_area_code  = operation.end_area_code
        new_task.end_loc_code  = operation.end_loc_code
        new_task.schedule_type = wms_base.Get_nConst(strLuaDEID, "调度类型-堆垛机") -- 设置调度类型
 
        nRet, new_task = m3.CreateDataObj(strLuaDEID, new_task)
        if (nRet ~= 0 ) then 
            lua.Stop( strLuaDEID, "创建堆垛机任务失败!"..new_task)
            return
        end
 
        if ( nRet ~= 0 ) then 
            lua.Stop( strLuaDEID, strRetInfo ) 
            return
        end 
    elseif ( task.type == wms_base.Get_nConst(strLuaDEID, "任务类型-堆垛机入库搬运") ) then
 
        nRet, strRetInfo = wms_op.SetFinish( strLuaDEID, operation )
        if ( nRet ~= 0 ) then
            lua.Stop( strLuaDEID, "设置作业编号='"..operation.code.."' 的作业完成失败!"..strRetInfo )
            return
        end   
 
        -- 根据不同的作业类型做不同的后处理
        if ( operation.op_def_name == '料箱入库' or 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 = 6"
                    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              
                end
            -- 如果携带的容器的业务类型 = 预分配容器
            elseif ( operation.carry_cb_cls == "Pre_Alloc_Container" ) then
                if ( carry_cb_no ~= '' ) then
                    strUpdateSql = "N_B_STATE = "..PAC_STATE.Finish
                    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 
                    local org_cntr 
                    nRet, org_cntr = m3.GetDataObjByCondition( strLuaDEID, "Pre_Alloc_Container", strCondition )
                    if ( nRet ~= 0 ) then  
                        lua.Stop( strLuaDEID, "获取【预分配容器】信息失败!"..strRetInfo ) 
                        return
                    end    
                    -- 预分配容器入库完成后
                    nRet, strRetInfo = wms_pac.After_PAC_Finish( strLuaDEID, carry_cb_no )        
                    if ( nRet ~= 0 ) then  
                        lua.Stop( strLuaDEID, "wms_pac.After_PAC_Finish 失败!"..strRetInfo ) 
                        return
                    end                         
                    -- 增加一个后台进程对组盘进行处理,触发配盘明细中的入库波次是否可以完成
                    local add_wfp = {
                        wfp_type = 1,
                        cls = "Pre_Alloc_Container",
                        obj_id = org_cntr.id,
                        obj_name = "预分配容器'"..carry_cb_no.."'-->入库后处理",
                        trigger_event = "入库后处理"
                    }
                    nRet, strRetInfo = m3.AddSysWFP( strLuaDEID, add_wfp )
                    if ( nRet ~= 0 ) then 
                        lua.Stop( strLuaDEID, "AddSysWFP失败!"..strRetInfo ) 
                        return 
                    end  
                end
            end
            
        elseif ( operation.op_def_name == '盘点回库') then  
            if ( operation.cc_no ~= '' and operation.cc_no ~= '') then  
                -- 4 已回库
                strUpdateSql = "N_B_STATE = 4"
                strCondition = "S_CC_NO = '"..operation.cc_no.."'"
                nRet, strRetInfo = mobox.updateDataAttrByCondition( strLuaDEID, "CP_Count_Container", strCondition, strUpdateSql )
                if ( nRet ~= 0 ) then  lua.Error( strLuaDEID, debug.getinfo(1), "更新【计划盘点容器】信息失败!"..strRetInfo ) end 
                
                local cc_cntr 
                nRet, cc_cntr = m3.GetDataObjByCondition( strLuaDEID, "CP_Count_Container", strCondition )
                if ( nRet ~= 0 ) then  lua.Error( strLuaDEID, debug.getinfo(1), "获取【计划盘点容器】信息失败!"..strRetInfo ) end   
                if ( cc_cntr.have_diff == "Y" ) then
                    --  容器设置禁用标签
                    strUpdateSql = "C_ENABLE = 'N'"
                    strCondition = "S_CODE = '"..cc_cntr.cntr_code.."'"
                    nRet, strRetInfo = mobox.updateDataAttrByCondition( strLuaDEID, "Container", strCondition, strUpdateSql )
                    if ( nRet ~= 0 ) then  lua.Error( strLuaDEID, debug.getinfo(1), "更新【容器】信息失败!"..strRetInfo ) end                     
                end                               
            end   
        elseif ( operation.op_def_name == '指定回库') then    
            -- 更新【指定出库】对象
            if ( operation.bs_no ~= '' and operation.bs_type == "Specify_Outbound") then
                -- 3 表示指定出库容器 已经回库
                strUpdateSql = "N_B_STATE = 4"
                strCondition = "S_SO_NO = '"..operation.bs_no.."' AND S_CNTR_CODE = '"..operation.cntr_code.."'"
                nRet, strRetInfo = mobox.updateDataAttrByCondition( strLuaDEID, "Specify_Outbound_CNTR", strCondition, strUpdateSql )
                if ( nRet ~= 0 ) then  
                    lua.Error( strLuaDEID, debug.getinfo(1), "更新【配盘明细】信息失败!"..strRetInfo ) 
                end     
            end 
        end
    end
end