wsz
2025-06-20 19898bd66dec87b500b200d5d50961d0fb538ce5
WMS-01-22 WMS-01-23
2个文件已添加
450 ■■■■■ 已修改文件
lua_code/Lua/01-Container/WMS-01-22.lua 197 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lua_code/Lua/01-Container/WMS-01-23.lua 253 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lua_code/Lua/01-Container/WMS-01-22.lua
New file
@@ -0,0 +1,197 @@
--[[
   编码: 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
lua_code/Lua/01-Container/WMS-01-23.lua
New file
@@ -0,0 +1,253 @@
---
--- 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