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
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
--[[
    编码: WMS-40-23#2
    名称: 作业-出库-任务完成
    作者:HAN  
    日期:2025-1-29
 
    版本: V1.0
 
    场景:作业中的任务完成后触发这个脚本
          当前数据对象指针是 作业
          任务对象属性保存在 输入参数 InputParamter 
          需要判断一下这个任务完成是否可以关闭 作业
       
    函数: TaskFinish
 
    功能:
        源于巨星料箱库
        -- 根据任务类型判断是否结束作业
     
 
    更改记录:
 
--]]
 
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.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 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
        -- 作业完成
        nRet, strRetInfo = wms_op.SetFinish( strLuaDEID, operation )
        if ( nRet ~= 0 ) then
            lua.Stop( strLuaDEID, "设置作业编号='"..operation.code.."' 的作业完成失败!"..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 == "Pre_Alloc_Container" ) then
                if ( carry_cb_no ~= '' ) then
                    -- 【预分配容器】的状态要设置为 2 (到站台)
                    local strUpdateSql = "N_B_STATE = 2"
                    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 = 1"
                    nRet, strRetInfo = mobox.updateDataAttrByCondition( strLuaDEID, "Pre_Alloc_CNTR_Detail", strCondition, strUpdateSql )
                    if ( nRet ~= 0 ) then  
                        lua.Stop( strLuaDEID, "更新【配盘容器】信息失败!"..strRetInfo ) 
                        return
                    end
                end
            end
        elseif ( operation.op_def_name == '盘点出库') then  
            -- 【计划盘点容器】状态设置为 2
            local strUpdateSql = "N_B_STATE = 2"
            local strCondition = "S_OUT_OP_NO = '"..operation.code.."' AND S_CNTR_CODE = '"..operation.cntr_code.."'"
            nRet, strRetInfo = mobox.updateDataAttrByCondition( strLuaDEID, "CP_Count_Container", strCondition, strUpdateSql )
            if ( nRet ~= 0 ) then  
                lua.Stop( strLuaDEID, "更新【计划盘点容器】信息失败!"..strRetInfo ) 
                return
            end          
            local cp_cntr 
            nRet, cp_cntr = m3.GetDataObjByCondition( strLuaDEID, "CP_Count_Container", strCondition )
            if ( nRet ~= 0 ) then  
                lua.Stop( strLuaDEID, "获取【计划盘点容器】信息失败!"..cp_cntr ) 
                return
            end
            -- 更新【盘点容器货品明细】状态=1
            strUpdateSql = "N_B_STATE = 1"
            strCondition = "S_COUNT_NO = '"..cp_cntr.count_no.."' AND S_CNTR_CODE = '"..operation.cntr_code.."'"
            nRet, strRetInfo = mobox.updateDataAttrByCondition( strLuaDEID, "Count_CG_Detail", strCondition, strUpdateSql )
            if ( nRet ~= 0 ) then  
                lua.Stop( strLuaDEID, "更新【盘点容器货品明细】信息失败!"..strRetInfo ) 
                return
            end               
        elseif ( operation.op_def_name == '货品出库' ) then
            local carry_cb_no = lua.Get_StrAttrValue( operation.carry_cb_no )
            
            -- 【配盘】的状态要设置为 3 -- 出库完成
            if ( operation.carry_cb_cls == "Distribution_CNTR" ) then
                if ( carry_cb_no ~= '' ) then
                    local strUpdateSql = "N_B_STATE = 3"
                    local 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 = 1"
                    nRet, strRetInfo = mobox.updateDataAttrByCondition( strLuaDEID, "Distribution_CNTR_Detail", strCondition, strUpdateSql )
                    if ( nRet ~= 0 ) then  
                        lua.Stop( strLuaDEID, "更新【配盘明细】信息失败!"..strRetInfo ) 
                        return
                    end  
                end
            end                            
        elseif ( operation.op_def_name == '指定出库' ) then
            -- 更新【指定出库】对象
            if ( operation.bs_no ~= '' and operation.bs_type == "Specify_Outbound") then
                -- 2 表示指定出库容器 已经到站台
                local strUpdateSql = "N_B_STATE = 2"
                local 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.Stop( strLuaDEID, "更新【配盘明细】信息失败!"..strRetInfo ) 
                    return
                end    
 
                -- 更新【指定出库容器货品明细】状态=1
                strUpdateSql = "N_B_STATE = 1"
                strCondition = "S_SO_NO = '"..operation.bs_no.."' AND S_CNTR_CODE = '"..operation.cntr_code.."'"
                nRet, strRetInfo = mobox.updateDataAttrByCondition( strLuaDEID, "SO_CNTR_Detail", strCondition, strUpdateSql )
                if ( nRet ~= 0 ) then  
                    lua.Stop( strLuaDEID, "更新【指定出库容器货品明细】信息失败!"..strRetInfo ) 
                    return
                end  
 
                local specify_outbound 
                strCondition = "S_SO_NO = '"..operation.bs_no.."'"
                nRet, specify_outbound = m3.GetDataObjByCondition( strLuaDEID, "Specify_Outbound", strCondition )
                if ( nRet == 0 ) then 
                    -- 增加一个后台进程进行检查指定出库完成情况
                    local add_wfp = {
                                    wfp_type = 1,                  -- 触发数据对象事件(指定数据对象标识)
                                    cls = "Specify_Outbound",
                                    obj_id = specify_outbound.id,
                                    obj_name = "指定出库'"..operation.bs_no.."'-->状态检查",
                                    trigger_event = "状态检查"
                    }
                    nRet, strRetInfo = m3.AddSysWFP( strLuaDEID, add_wfp )
                    if ( nRet ~= 0 ) then 
                        lua.Stop( strLuaDEID, "AddSysWFP失败!"..strRetInfo ) 
                        return 
                    end   
                end                           
            end
        end
    end
end