---
|
--- Created by wsz.
|
--- DateTime: 2025/6/19 下午4:23
|
---
|
|
--[[
|
编码: WMS-01-23
|
名称:
|
作者:
|
日期:2025-06-19
|
|
函数: emptyBoxFormQuery
|
功能: 空容器设置下拉项 | 初始化 、 loc值变化
|
|
更改记录:
|
|
--]]
|
|
local json = require("json")
|
local mobox = require("OILua_JavelinExt")
|
local lua = require("oi_base_func")
|
local m3 = require("oi_base_mobox")
|
|
------------------------------------------------------------------------------------------------------------------------
|
-- page 常量定义
|
local ERR
|
local luaDEID
|
|
|
------------------------------------------------------------------------------------------------------------------------
|
-- 独立方法区
|
local function deduplicate_array(arr)
|
local seen = {}
|
local result = {}
|
for _, v in ipairs(arr) do
|
if not seen[v] then
|
seen[v] = true
|
table.insert(result, v)
|
end
|
end
|
return result
|
end
|
|
|
------------------------------------------------------------------------------------------------------------------------
|
-- 1. 取得mac映射配置的库区 return area-code 注意此实现需要保证机台配置 mac-库区 1-1 且不可为空,不满足时准确不可保证
|
local function getMacArea()
|
-- 登录人
|
local user
|
do
|
local nRet, strRetInfo = mobox.getCurUserInfo(luaDEID)
|
user = strRetInfo
|
end
|
|
-- mac地址
|
local mac
|
do
|
local nRet, strRetInfo = mobox.getUserInfo(user, 1, 1)
|
|
if nRet == 0 then
|
local loginInfo = json.decode(strRetInfo)
|
mac = loginInfo.client_info.mac
|
else
|
mobox.setInfo(luaDEID, "查询登录人mac地址为空!")
|
error("查询mac地址为空", 0)
|
end
|
end
|
|
-- 库区
|
local area
|
do
|
local strCondition -- 查询条件
|
|
-- 查询全部-统一处理
|
local nRet, strRetInfo = mobox.queryDataObjAttr(luaDEID, "Machine_Station", {})
|
|
local kvmap = {}
|
for _, item in pairs(json.decode(strRetInfo)) do
|
local luadata = m3.KeyValueAttrsToObjAttr(item.attrs)
|
kvmap[luadata.S_MAC_ADDRESS] = luadata.S_STORAGE_AREA
|
end
|
|
area = kvmap[mac]
|
end
|
|
return area
|
end
|
|
-- 2. 取得指定库区下all 空容器 的货位 返回 为空 {} 列表型table location-code ,视 queryMultiTable 限制,可能为1000 或 2000 限制
|
local function getAllLocation(area)
|
|
local locList = {}
|
|
local strTable = [[
|
tn_container con
|
inner join tn_loc_container lc on lc.s_cntr_code = con.s_code
|
left join tn_inv_detail ind on lc.s_cntr_code = ind.s_cntr_code
|
inner join tn_location loc on loc.s_code = lc.s_loc_code
|
inner join tn_area area on loc.s_area_code = area.s_code
|
]]
|
|
local strAttrs = [[ loc.s_code ]]
|
|
local strCondition = string.format([[
|
(ind.S_CNTR_CODE is null or ind.F_QTY = 0)
|
and con.N_LOCK_STATE == 0
|
and area.S_CODE = '%s'
|
]], area)
|
|
local nRet, strRetInfo = mobox.queryMultiTable(luaDEID, strAttrs, strTable, 2000, strCondition)
|
|
local luadata_conlist = #strRetInfo == 0 and {} or json.decode(strRetInfo)
|
|
for _, item in ipairs(luadata_conlist) do
|
local it = item[1]
|
table.insert(locList, it)
|
end
|
|
-- 查询主体的原因,需要去重
|
locList = deduplicate_array(locList)
|
|
return locList
|
end
|
|
|
-- 3. 取得指定货位下 全体 空容器 返回 为空 {} 列表型table con-code ,视 queryMultiTable 限制,可能为1000 或 2000 限制
|
local function getContainer(area,loc)
|
|
local conList = {}
|
|
local strTable = [[
|
tn_container con
|
inner join tn_loc_container lc on lc.s_cntr_code = con.s_code
|
left join tn_inv_detail ind on lc.s_cntr_code = ind.s_cntr_code
|
inner join tn_location loc on loc.s_code = lc.s_loc_code
|
inner join tn_area area on loc.s_area_code = area.s_code
|
]]
|
|
local strAttrs = [[ con.s_code ]]
|
|
local strCondition = string.format([[
|
(ind.S_CNTR_CODE is null or ind.F_QTY = 0)
|
and con.N_LOCK_STATE == 0
|
and area.s_code = '%s'
|
]], area)
|
|
strCondition = loc == "" and strCondition or strCondition .. string.format(" and loc.s_code = '%s' ", loc)
|
|
|
local nRet, strRetInfo = mobox.queryMultiTable(luaDEID, strAttrs, strTable, 2000, strCondition)
|
|
local luadata_conlist = #strRetInfo == 0 and {} or json.decode(strRetInfo)
|
|
for _, item in ipairs(luadata_conlist) do
|
local it = item[1]
|
table.insert(conList, it)
|
end
|
|
return conList
|
end
|
|
-- 4. 取得页面输入的库位、容器 未输入|初始化时为 ""
|
local function getPagaInput()
|
local loc, con = "", ""
|
do
|
local nRet, parameter_attrs = m3.GetSysInputParameter(luaDEID)
|
-- 当初始化时 parameter_attrs 为 "" 空字串
|
if type(parameter_attrs) == "table" then
|
local parameter = m3.KeyValueAttrsToObjAttr(parameter_attrs)
|
if parameter ~= nil then
|
loc = lua.Get_StrAttrValue(parameter.S_POSITION)
|
con = lua.Get_StrAttrValue(parameter.S_CODE)
|
end
|
end
|
end
|
print(loc, "--", con)
|
return loc, con
|
end
|
|
|
-- 核心功能实现
|
local function main()
|
|
local area = getMacArea()
|
|
local loc, con = getPagaInput()
|
|
local action_dlgAttr = { action_type = "set_dlg_attr", value = {} }
|
--[[
|
1. loc= "" 时 需要全量 初始化 loc 和 con 仅 area 指定
|
2. loc有值时 设置con 为指定库位的数据
|
]]
|
|
if loc == "" then
|
print("库位未输入")
|
local locList = getAllLocation(area)
|
if #locList > 0 then
|
local action_input1 = {
|
attr = "S_POSITION",
|
choice_list = locList,
|
}
|
table.insert(action_dlgAttr.value, action_input1)
|
end
|
end
|
|
--
|
local conList = getContainer(area,loc)
|
if #conList > 0 then
|
local action_input2 = {
|
attr = "S_CODE",
|
choice_list = conList,
|
}
|
table.insert(action_dlgAttr.value, action_input2)
|
end
|
|
-- --------------------------------------------------------------------------
|
|
local action = { action_dlgAttr }
|
local strjson = json.encode(action)
|
local nRet, strRetInfo = mobox.setAction(luaDEID, strjson)
|
print(nRet)
|
print(strRetInfo)
|
if nRet ~= 0 then mobox.setInfo( luaDEID,"设置表单失败",5 ) end
|
|
end
|
|
------------------------------------------------------------------------------------------------------------------------
|
-----
|
local function errorHandler(err)
|
ERR = err
|
lua.Debug(luaDEID, debug.getinfo(1), "err-捕获", err)
|
return err
|
end
|
|
--[[ 入口函数 ]]
|
function emptyBoxFormQuery(strLuaDEID)
|
|
luaDEID = strLuaDEID
|
|
-- lua交换区数据记录
|
m3.PrintLuaDEInfo(strLuaDEID)
|
|
-- core_main 为目标函数,从第2个参数后均为core_main的传入参数
|
local success, result = xpcall(main, errorHandler)
|
|
if not success then
|
-- 函数执行失败时处理
|
print("发生错误", ERR)
|
lua.Error(strLuaDEID, debug.getinfo(1), ERR)
|
else
|
--函数成功时处理
|
end
|
end
|