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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
--[[
    编码: WMS-20-29#1
    名称: 点领用按钮后
    作者:HAN  
    日期:2025-1-29
 
    级别:项目
        来源巨星二期项目,选中多个入库单进行合并波次入库
        
    函数: ClickReceiveButton
 
    功能:
        -- 点击领用按钮
 
    更改记录:
        V3.0 HAN 20241231 改成后台线程来处理空料箱呼出计算,因为这个过程是一个比较长的事务,有并发锁表的风险
                          本次改进的目的就是将这些长事务统一交给后台一个线程排队处理
        V4.0 HAN 20250312 对选中的入库单进行检查如果已经有入库波次的不进行领用
--]]
 
wms_base = require ("wms_base")
 
function ClickReceiveButton ( strLuaDEID ) 
    local nRet, strRetInfo, n
    local data_json
 
    nRet, data_json = m3.GetSysDataJson( strLuaDEID )
    if (nRet ~= 0) then 
        lua.Stop( strLuaDEID, data_json ) 
        return
    end
    local nCount = #data_json
    if ( nCount == 0 ) then 
        mobox.setInfo( strLuaDEID, "必须选中一个入库单!" )
        return 
    end
    --V4.0 HAN 2025/3/12 
    local inbound_obj
    local checked_data_json = {}
    local msg = ''
    local factory = ''
    for n = 1, nCount do
        -- 获取入库单对象
        nRet, inbound_obj = m3.GetDataObject( strLuaDEID, "Inbound_Order", data_json[n].id ) 
        if ( nRet ~= 0 ) then 
            lua.Stop( strLuaDEID, inbound_obj ) 
            return
        end 
 
        factory = inbound_obj.factory
        -- 如果选择的出库单已经有出库波次号
        if ( inbound_obj.wave_no ~= '' or inbound_obj.b_state ~= 0 ) then
            msg = msg.."\r\n单号='"..inbound_obj.no.."'的入库单已经有入库波次!"
        else
            table.insert( checked_data_json, data_json[n] )
        end
    end    
    if ( #checked_data_json == 0 ) then
        mobox.setInfo( strLuaDEID, msg )
        return 
    end
 
    -- 获取输入界面中的工作台属性
    nRet, strRetInfo = mobox.getCurEditDataObjAttr( strLuaDEID, "S_STATION_NO" ) 
    if nRet ~= 0 then
        lua.Stop( strLuaDEID, strRetInfo )
        return
    end
    if strRetInfo == '' then
        mobox.setInfo( strLuaDEID, "必须选站台!" )
        return
    end
    local input_value = json.decode( strRetInfo ) 
    local station = lua.Get_StrAttrValue( input_value[1].value )
 
    if ( station == '' ) then
        mobox.setInfo( strLuaDEID, "必须选择一个工作站!" )
        return         
    end
    local strUserLogin, strUserName
    nRet, strUserLogin, strUserName = mobox.getCurUserInfo( strLuaDEID )
    if ( nRet ~= 0 ) then 
        mobox.setInfo( strLuaDEID,  "获取当前操作人员信息失败! "..strUserLogin )
        return 
    end  
 
    -- V4.0
    -- 如果有选中的入库单不符合要求,前端显示一下
    if ( msg ~= '' ) then 
        mobox.setInfo( strLuaDEID, msg )
    end
 
    -- 组织后台脚本执行的输入参数
    local paramter = {
        factory = factory,
        as_model = "stacker",               -- 自动化立库模式 stacker、agv、picking
        station = station,
        login = strUserLogin,
        user_name = strUserName,
        data_json = checked_data_json
        cntr_out_op_def = "料箱出库",
        cntr_back_op_def = "货品入库"             
    }  
 
    nRet, strRetInfo = mobox.addBackendScriptProc( "Inbound_Order","入库预分配料箱1#算法", lua.table2str( paramter ) )
    if ( nRet ~= 0 ) then 
        lua.Stop( strLuaDEID, strRetInfo ) 
        return
    end
 
    local data_json = {proc_id = strRetInfo}
    local action = 
    {
        {
            action_type = "wait",
            value = {
                time = 1,
                event = {
                    cls_name = "入库单",
                    event_name = "获取入库空料箱计算结果",
                    data_json = data_json
                }
            }
        },
    }
    nRet, strRetInfo = mobox.setAction( strLuaDEID, lua.table2str(action) )
    if ( nRet ~= 0 ) then 
        lua.Stop( strLuaDEID, "setAction失败! "..strRetInfo..' action = '..strAction ) 
        return
    end        
 
end