1
Jianw
10 天以前 f6f5e6b632d6649386a380558d84003f3de7ec6c
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
--[[
    编码: WMS-01-22
    名称: 空料箱入库
    作者:HAN   
    日期:2025-7-1 
    入口函数: Import
    来源:
         巨星,国科料箱库
 
    功能说明:
        导入格式如下
        |--料箱类型--|--料格类型--|--库区--|--数量--|
 
    变更历史:
 
--]]
wms_base = require ("wms_base")
wms_wh   = require ("wms_wh")
 
function Import(strLuaDEID)
    local nRet, strRetInfo, strNo
    -- 获取导入的数据, 返回 [{"attr":"xx","value":""},...]
    local row_data = {}
    nRet, row_data = m3.GetSysDataJson(strLuaDEID)
    if (nRet ~= 0 or strRetInfo == '') then 
        lua.Stop( strLuaDEID, "无法获取导入数据!")
        return
    end
 
    local row_attrs
    local n, nCount, nRows
  
    -- 导入是可分多页分批导入, 因此每次的起始行不一样
    nRet, strRetInfo = mobox.getGlobalAttrValue( strLuaDEID, "start_row" )
    if ( nRet ~= 0 ) then
        mobox.error( strLuaDEID, "获取批量导入全局参数 start_row 失败!"..strRetInfo )
        return
    end    
    local nStartRow = tonumber( strRetInfo )
    -- 步骤1 获取从excel导入的一行数据
    local cntr, area, loc
    nRow = nStartRow
    for row = 1, #row_data do
        row_attrs = row_data[row]
        nCount = #row_attrs
 
        num = 1
        ctd_code = ''
        cell_type = ''
        area_code = ''
 
        for n = 1, nCount do
            strAttr = row_attrs[n].attr
            strValue = row_attrs[n].value
            if (strAttr ~= '') then
                if (strAttr == "容器类型") then
                    ctd_code = strValue
                elseif (strAttr == "料格类型") then
                    cell_type = strValue
                elseif (strAttr == "库区") then
                    area_code = strValue
                elseif (strAttr == "数量") then
                    num = lua.Get_NumAttrValue( strValue ) 
                end
            end
        end
 
        if ctd_code == '' then
            lua.Stop( strLuaDEID, "第"..nRow.."行缺少容器类型!" )
            return
        end
 
        if cell_type == '' then
            lua.Stop( strLuaDEID, "第"..nRow.."行缺少料格类型!" )
            return
        end  
        
        if area_code == '' then
            lua.Stop( strLuaDEID, "第"..nRow.."行缺少库区!" )
            return
        end  
 
        nRet, area = wms_wh.GetAreaInfo( area_code )
        if (nRet ~= 0) then 
            lua.Stop( strLuaDEID, "从内存获取编码'"..area_code.."'的库区信息失败!, 库区不存在!" )
            return
        end        
 
        for n = 1, num do
            cntr = m3.AllocObject(strLuaDEID,"Container")  
            cntr.ctd_code = ctd_code
            cntr.type = "Cell_Box"
            cntr.spec = cell_type
 
            nRet, cntr = m3.CreateDataObj( strLuaDEID, cntr )
            if nRet ~= 0 then
                lua.Stop( strLuaDEID, cntr )
                return
            end     
            -- 分配一个库区的空货位绑定空料箱
            strCondition = "S_AREA_CODE = '"..area_code.."' AND N_CURRENT_NUM = 0 AND N_LOCK_STATE = 0 AND C_ENABLE = 'Y'"
            nRet, loc = m3.GetDataObjByCondition( strLuaDEID, "Location", strCondition, "N_POS_WEIGHT" )
            if ( nRet ~= 0 ) then  
                lua.Stop( strLuaDEID, "获取【Location】信息失败!"..cp_cntr ) 
                return
            end  
 
            nRet, strRetInfo = wms_wh.Loc_Container_Binding( strLuaDEID, loc.code, cntr.code, "绑定解绑方法-系统",  "测试用" )
            if ( nRet ~= 0 ) then 
                lua.Stop( strLuaDEID, '货位容器绑定失败!'..strRetInfo )
                return
            end 
        end
    end
end