From 19898bd66dec87b500b200d5d50961d0fb538ce5 Mon Sep 17 00:00:00 2001 From: wsz <w1832984788@outlook.com> Date: 星期五, 20 六月 2025 15:54:16 +0800 Subject: [PATCH] WMS-01-22 WMS-01-23 --- lua_code/Lua/01-Container/WMS-01-23.lua | 253 +++++++++++++++++++++++++++++++ lua_code/Lua/01-Container/WMS-01-22.lua | 197 ++++++++++++++++++++++++ 2 files changed, 450 insertions(+), 0 deletions(-) diff --git a/lua_code/Lua/01-Container/WMS-01-22.lua b/lua_code/Lua/01-Container/WMS-01-22.lua new file mode 100644 index 0000000..94b168a --- /dev/null +++ b/lua_code/Lua/01-Container/WMS-01-22.lua @@ -0,0 +1,197 @@ +--[[ + 缂栫爜: WMS-01-22 + 鍚嶇О: + 浣滆�锛�+ 鏃ユ湡锛�025-06-18 + + 鍑芥暟锛�emptyBoxQuery + 鍔熻兘: 闇�浣跨敤MBC鐧诲綍锛屽彇寰梞ac鍦板潃锛岀劧鍚庝粠鏈哄彴鍙栧緱瀵瑰簲鐨�瀛樺偍鍖�濡�S1 骞惰缃埌鏌ヨ鏉′欢涓幓 + + 鏇存敼璁板綍: + +--]] + + +local json = require("json") +local mobox = require("OILua_JavelinExt") +local lua = require("oi_base_func") +local m3 = require("oi_base_mobox") + + +--[[ +鍥哄畾-閿欒鎹曡幏澶勭悊 +鍦╟ore_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, "鏌ヨ鐧诲綍浜簃ac鍦板潃涓虹┖锛�) + 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 diff --git a/lua_code/Lua/01-Container/WMS-01-23.lua b/lua_code/Lua/01-Container/WMS-01-23.lua new file mode 100644 index 0000000..eea2ea2 --- /dev/null +++ b/lua_code/Lua/01-Container/WMS-01-23.lua @@ -0,0 +1,253 @@ +--- +--- Created by wsz. +--- DateTime: 2025/6/19 涓嬪崍4:23 +--- + +--[[ + 缂栫爜: WMS-01-23 + 鍚嶇О: + 浣滆�锛�+ 鏃ユ湡锛�025-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, "鏌ヨ鐧诲綍浜簃ac鍦板潃涓虹┖锛�) + 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. 鍙栧緱鎸囧畾搴撳尯涓媋ll 绌哄鍣�鐨勮揣浣� 杩斿洖 涓虹┖ {} 鍒楄〃鍨媡able 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. 鍙栧緱鎸囧畾璐т綅涓�鍏ㄤ綋 绌哄鍣�杩斿洖 涓虹┖ {} 鍒楄〃鍨媡able 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 \ No newline at end of file -- Gitblit v1.9.1