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
--[[
    编码: JX-01-20
    名称: 空料箱导入
    作者:KUN    
    日期:2025-2-17  
    入口函数: Import
 
    功能说明:
        根据Excel导入的数据,创建Container表。
 
    变更历史:
--]]
 
wms_cntr = require("wms_container")
 
function Import(strLuaDEID)
    local nRet, strRetInfo
    local cntr_spec = {"A", "B", "C", "D", "", "E"} --料箱各个属性
 
    local row_data = {}
    nRet, row_data = m3.GetSysDataJson(strLuaDEID)
    if nRet ~= 0 or #row_data == 0 then
        lua.Error(strLuaDEID, debug.getinfo(1), "无法获取导入数据!")
        return
    end
 
    -- 导入是可分多页分批导入,因此每次的起始行不一样
    nRet, strRetInfo = mobox.getGlobalAttrValue(strLuaDEID, "start_row")
    if (nRet ~= 0) then
        mobox.error(strLuaDEID, "获取批量导入全局参数 start_row 失败!" .. strRetInfo)
        return
    end
    local nStartRow = tonumber(strRetInfo)
 
    local err_msg_list = {} 
    local str_err_msg
    local cntr
 
    -- 遍历每一行数据
    for row = 1, #row_data do
        local row_attrs = row_data[row]
        str_err_msg = ''
 
        -- 初始化容器对象
        cntr = m3.AllocObject(strLuaDEID, "Container")
        for n = 1, #row_attrs do
            local strAttr = row_attrs[n].attr
            local strValue = row_attrs[n].value
 
            if (strAttr ~= '') then
                if (strAttr == "料箱编码") then
                    if (strValue == '') then
                        str_err_msg = strAttr .. "不能为空!"
                        goto err_msg_process
                    end
                    cntr.code = strValue
                elseif (strAttr == "商品来源") then
                    if (strValue == '') then
                        str_err_msg = strAttr .. "不能为空!"
                        goto err_msg_process
                    end
                    cntr.source = strValue
                elseif (strAttr == "最大料格数量") then
                    cntr.max_cell_num = lua.StrToNumber(strValue)
                end
            end
        end
 
        -- 判断导入的数据是否完整
        if (cntr.source == "巨沃") then
            if (cntr.max_cell_num < 1 or cntr.max_cell_num > 6 or cntr.max_cell_num == 5) then
                str_err_msg = "料格数量不合法!"
                goto err_msg_process
            end
            cntr.type = 3 
            cntr.spec = cntr_spec[cntr.max_cell_num]
        else
            cntr.type = 2 
            cntr.spec = ""
            cntr.max_cell_num = 0
        end
 
        -- 创建Container表
        nRet, cntr = m3.CreateDataObj(strLuaDEID, cntr)
        if (nRet ~= 0) then
            str_err_msg = "创建Container对象失败!" .. cntr
            goto err_msg_process
        end
 
        ::err_msg_process::
        if ( str_err_msg ~= '' ) then
            table.insert(err_msg_list, {
                row_no = nStartRow + row - 1, 
                err_msg = str_err_msg
            })
        end
    end
 
    -- 返回导入结果
    local import_result = {
        result = {
            fail = err_msg_list
        }
    }
    mobox.returnValue(strLuaDEID, 1, lua.table2str(import_result))
end