--[[ 编码: WMS-01-22 名称: 作者: 日期:2025-06-18 函数: emptyBoxQuery 功能: 需要使用MBC登录,取得mac地址,然后从机台取得对应的 存储区 如 S1 并设置到查询条件中去 更改记录: --]] local json = require("json") local mobox = require("OILua_JavelinExt") local lua = require("oi_base_func") local m3 = require("oi_base_mobox") --[[ 固定-错误捕获处理 在core_main函数中配合 error(msg) 取得外抛出错误 ]] local ERR local luaDEID local function main() -- 取得查询表单数据 local loc, con = "","" do local nRet, attrs = m3.GetSysInputParameter(luaDEID) if type(attrs) == "table" then local parameter = m3.KeyValueAttrsToObjAttr(attrs) loc = lua.Get_StrAttrValue(parameter.S_POSITION) con = lua.Get_StrAttrValue(parameter.S_CODE) end end -- 登录人 local user do local nRet, strRetInfo = mobox.getCurUserInfo(luaDEID) print(type(strRetInfo)) print(strRetInfo) user = strRetInfo end -- mac地址 local mac do local nRet, strRetInfo = mobox.getUserInfo(user, 1, 1) print(nRet) print(type(strRetInfo)) -- 返回json 字符串 print(strRetInfo) 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 -- 查询条件 --do -- local filters = {} -- table.insert(filters, string.format(" %s = '%s' ", "S_BS_NO", "2025050602")) -- strCondition = table.concat(filters, " and ") --end -- 查询全部-统一处理 local nRet, strRetInfo = mobox.queryDataObjAttr(luaDEID, "Machine_Station", {}) print('type:' .. type(strRetInfo)) print('nRet:' .. nRet) print('data:' .. strRetInfo) 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 print(json.encode(kvmap)) area = kvmap[mac] end -- 在条件设置阶段直接的过滤目标数据 local constrlist do 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, con.S_ID ]] 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 ) if string.len(loc) > 0 then strCondition = strCondition .. string.format(" and loc.S_CODE = '%s' ",loc) end if string.len(con) > 0 then strCondition = strCondition .. string.format(" and con.S_CODE = '%s' ",con) end local nRet, strRetInfo = mobox.queryMultiTable(luaDEID, strAttrs, strTable, 2000, strCondition ) local luadata_conlist if #strRetInfo == 0 then luadata_conlist = {} else luadata_conlist = json.decode(strRetInfo) end local conlist = {} for _, item in ipairs(luadata_conlist) do local it = item[1] table.insert( conlist, "'" .. item[1] .. "'" ) end constrlist = table.concat(conlist , " , ") end local strCondition if #constrlist > 0 then strCondition = string.format(" S_CODE in (%s) ", constrlist ) else strCondition = " S_CODE is null " -- 达到查不到数据的目标 end local action = { { action_type = "set_query_condition", value = { condition = strCondition } } } local jsonstr = lua.table2str(action) print(jsonstr) do local nRet, strRetInfo = mobox.setAction(luaDEID, lua.table2str(action)) end end local function errorHandler(err) ERR = err lua.Debug(luaDEID, debug.getinfo(1), "err-捕获", err) return err end --[[ 入口函数 ]] function emptyBoxQuery(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