--[[
|
编码: 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
|